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