sonobe/cli/src/settings.rs
cli/src/settings.rsRaw
1use ark_serialize::SerializationError;
2use clap::{Parser, ValueEnum};
3use solidity_verifiers::{Groth16Data, KzgData, NovaCyclefoldData, ProtocolData};
4use std::{env, fmt::Display, path::PathBuf};
5
6fn get_default_out_path() -> PathBuf {
7 let mut path = env::current_dir().unwrap();
8 path.push("verifier.sol");
9 path
10}
11
12#[derive(Debug, Copy, Clone, ValueEnum)]
13pub(crate) enum Protocol {
14 Groth16,
15 Kzg,
16 NovaCyclefold,
17}
18
19impl Display for Protocol {
20 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
21 write!(f, "{:?}", self)
22 }
23}
24
25// Would be nice to link this to the `Template` or `ProtocolData` traits.
26// Sadly, this requires Boxing with `dyn` or similar which would complicate the code more than is actually required.
27impl Protocol {
28 pub(crate) fn render(
29 &self,
30 data: &[u8],
31 pragma: Option<String>,
32 ) -> Result<Vec<u8>, SerializationError> {
33 match self {
34 Self::Groth16 => {
35 Ok(Groth16Data::deserialize_protocol_data(data)?.render_as_template(pragma))
36 }
37
38 Self::Kzg => Ok(KzgData::deserialize_protocol_data(data)?.render_as_template(pragma)),
39 Self::NovaCyclefold => {
40 Ok(NovaCyclefoldData::deserialize_protocol_data(data)?.render_as_template(pragma))
41 }
42 }
43 }
44}
45
46const ABOUT: &str = "A powerful Command-Line Interface (CLI) tool designed to simplify the generation of Solidity smart contracts that verify proofs of Zero Knowledge cryptographic protocols.
47";
48
49const LONG_ABOUT: &str = "
50 _____ ______ ______ ______ ______ ______ ______
51| |__| || |__| || |__| || |__| || |__| || |__| || |__| |
52| () || () || () || () || () || () || () |
53|______||______||______||______||______||______||______|
54 ______ ______
55| |__| | ____ _ _ _ _ _ | |__| |
56| () | / ___| ___ | (_) __| (_) |_ _ _ | () |
57|______| \\___ \\ / _ \\| | |/ _` | | __| | | | |______|
58 ______ ___) | (_) | | | (_| | | |_| |_| | ______
59| |__| | |____/ \\___/|_|_|\\__,_|_|\\__|\\__, | | |__| |
60| () | __ __ _ __ _ |___/ | () |
61|______| \\ \\ / /__ _ __(_)/ _(_) ___ _ __ |______|
62 ______ \\ \\ / / _ \\ '__| | |_| |/ _ \\ '__| ______
63| |__| | \\ V / __/ | | | _| | __/ | | |__| |
64| () | \\_/ \\___|_| |_|_| |_|\\___|_| | () |
65|______| |______|
66 ______ ______ ______ ______ ______ ______ ______
67| |__| || |__| || |__| || |__| || |__| || |__| || |__| |
68| () || () || () || () || () || () || () |
69|______||______||______||______||______||______||______|
70
71Welcome to Solidity Verifier, a powerful Command-Line Interface (CLI) tool designed to simplify the generation of Solidity smart contracts that verify proofs of Zero Knowledge cryptographic protocols.
72for Zero Knowledge protocols. This tool is developed by the collaborative efforts of the PSE (Privacy & Scaling Explorations) and 0XPARC teams.
73
74As an open-source project, Solidity Verifier is released under the GPL3 license.
75
76Solidity Verifier currently supports the generation of Solidity smart contracts for the verification of proofs in the following Zero Knowledge protocols:
77
78 Groth16:
79 Efficient and succinct zero-knowledge proof system.
80
81 KZG:
82 Uses the Kate-Zaverucha-Goldberg polynomial commitment scheme.
83
84 Nova + CycleFold Decider:
85 Implements the decider circuit verification for the Nova zero-knowledge proof system in conjunction with the CycleFold protocol optimization.
86";
87#[derive(Debug, Parser)]
88#[command(author = "0XPARC & PSE", version, about = ABOUT, long_about = Some(LONG_ABOUT))]
89#[command(propagate_version = true)]
90/// A tool to create Solidity Contracts which act as verifiers for the major Folding Schemes implemented
91/// within the `folding-schemes` repo.
92pub(crate) struct Cli {
93 #[command(flatten)]
94 pub verbosity: clap_verbosity_flag::Verbosity,
95
96 /// Selects the protocol for which we want to generate the Solidity Verifier contract.
97 #[arg(short = 'p', long, value_enum, rename_all = "lower")]
98 pub protocol: Protocol,
99
100 #[arg(short = 'o', long, default_value=get_default_out_path().into_os_string())]
101 /// Sets the output path for all the artifacts generated by the command.
102 pub out: PathBuf,
103
104 #[arg(short = 'd', long)]
105 /// Sets the input path for the file containing all the data required by the protocol chosen such that the verification contract can be generated.
106 pub protocol_data: PathBuf,
107
108 /// Selects the Solidity compiler version to be set in the Solidity Verifier contract artifact.
109 #[arg(long, default_value=None)]
110 pub pragma: Option<String>,
111}