Skip to content

Commit 383e86e

Browse files
feat: add proving systems to help (#492)
1 parent 32a07de commit 383e86e

File tree

3 files changed

+40
-26
lines changed

3 files changed

+40
-26
lines changed

batcher/aligned-batcher-lib/src/types/mod.rs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use anyhow::anyhow;
21
use ethers::types::Address;
32
use lambdaworks_crypto::merkle_tree::{
43
merkle::MerkleTree, proof::Proof, traits::IsMerkleTreeBackend,
@@ -130,19 +129,6 @@ impl BatchInclusionData {
130129
}
131130
}
132131

133-
pub fn parse_proving_system(proving_system: &str) -> anyhow::Result<ProvingSystemId> {
134-
match proving_system {
135-
"GnarkPlonkBls12_381" => Ok(ProvingSystemId::GnarkPlonkBls12_381),
136-
"GnarkPlonkBn254" => Ok(ProvingSystemId::GnarkPlonkBn254),
137-
"Groth16Bn254" => Ok(ProvingSystemId::Groth16Bn254),
138-
"SP1" => Ok(ProvingSystemId::SP1),
139-
"Halo2IPA" => Ok(ProvingSystemId::Halo2IPA),
140-
"Halo2KZG" => Ok(ProvingSystemId::Halo2KZG),
141-
"Risc0" => Ok(ProvingSystemId::Risc0),
142-
_ => Err(anyhow!("Invalid proving system: {}, Available proving systems are: [GnarkPlonkBls12_381, GnarkPlonkBn254, Groth16Bn254, SP1, Halo2KZG, Halo2IPA]", proving_system))
143-
}
144-
}
145-
146132
#[cfg(test)]
147133
mod test {
148134
use super::*;

batcher/aligned/src/errors.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use ethers::signers::WalletError;
99
pub enum BatcherClientError {
1010
MissingParameter(String),
1111
InvalidUrl(url::ParseError, String),
12-
InvalidProvingSystem(String),
1312
ConnectionError(tokio_tungstenite::tungstenite::Error),
1413
IoError(PathBuf, io::Error),
1514
SerdeError(serde_json::Error),
@@ -57,9 +56,6 @@ impl fmt::Debug for BatcherClientError {
5756
BatcherClientError::InvalidUrl(err, url) => {
5857
write!(f, "Invalid URL \"{}\", {}", url, err)
5958
}
60-
BatcherClientError::InvalidProvingSystem(proving_system) => {
61-
write!(f, "Invalid proving system: {}", proving_system)
62-
}
6359
BatcherClientError::ConnectionError(e) => {
6460
write!(f, "Web Socket Connection error: {}", e)
6561
}

batcher/aligned/src/main.rs

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,16 @@ use tokio_tungstenite::connect_async;
2323
use tokio_tungstenite::tungstenite::Message;
2424
use tokio_tungstenite::{MaybeTlsStream, WebSocketStream};
2525

26-
use aligned_batcher_lib::types::{
27-
parse_proving_system, BatchInclusionData, ProvingSystemId, VerificationData,
28-
};
26+
use aligned_batcher_lib::types::{BatchInclusionData, ProvingSystemId, VerificationData};
2927
use clap::Subcommand;
3028
use ethers::utils::hex;
3129
use sha3::{Digest, Keccak256};
3230

3331
use crate::errors::BatcherClientError;
3432
use crate::types::AlignedVerificationData;
33+
use crate::AlignedCommands::GetVerificationKeyCommitment;
3534
use crate::AlignedCommands::Submit;
3635
use crate::AlignedCommands::VerifyProofOnchain;
37-
use crate::AlignedCommands::GetVerificationKeyCommitment;
3836

3937
use clap::{Parser, ValueEnum};
4038

@@ -53,7 +51,10 @@ pub enum AlignedCommands {
5351
VerifyProofOnchain(VerifyProofOnchainArgs),
5452

5553
// GetVericiationKey, command name is get-vk-commitment
56-
#[clap(about = "Create verification key for proving system", name = "get-vk-commitment")]
54+
#[clap(
55+
about = "Create verification key for proving system",
56+
name = "get-vk-commitment"
57+
)]
5758
GetVerificationKeyCommitment(GetVerificationKeyCommitmentArgs),
5859
}
5960

@@ -67,7 +68,7 @@ pub struct SubmitArgs {
6768
)]
6869
connect_addr: String,
6970
#[arg(name = "Proving system", long = "proving_system")]
70-
proving_system_flag: String,
71+
proving_system_flag: ProvingSystemArg,
7172
#[arg(name = "Proof file path", long = "proof")]
7273
proof_file_name: PathBuf,
7374
#[arg(name = "Public input file name", long = "public_input")]
@@ -130,6 +131,38 @@ pub enum Chain {
130131
Holesky,
131132
}
132133

134+
#[derive(Debug, Clone, ValueEnum)]
135+
pub enum ProvingSystemArg {
136+
#[clap(name = "GnarkPlonkBls12_381")]
137+
GnarkPlonkBls12_381,
138+
#[clap(name = "GnarkPlonkBn254")]
139+
GnarkPlonkBn254,
140+
#[clap(name = "Groth16Bn254")]
141+
Groth16Bn254,
142+
#[clap(name = "SP1")]
143+
SP1,
144+
#[clap(name = "Halo2KZG")]
145+
Halo2KZG,
146+
#[clap(name = "Halo2IPA")]
147+
Halo2IPA,
148+
#[clap(name = "Risc0")]
149+
Risc0,
150+
}
151+
152+
impl From<ProvingSystemArg> for ProvingSystemId {
153+
fn from(proving_system: ProvingSystemArg) -> Self {
154+
match proving_system {
155+
ProvingSystemArg::GnarkPlonkBls12_381 => ProvingSystemId::GnarkPlonkBls12_381,
156+
ProvingSystemArg::GnarkPlonkBn254 => ProvingSystemId::GnarkPlonkBn254,
157+
ProvingSystemArg::Groth16Bn254 => ProvingSystemId::Groth16Bn254,
158+
ProvingSystemArg::SP1 => ProvingSystemId::SP1,
159+
ProvingSystemArg::Halo2KZG => ProvingSystemId::Halo2KZG,
160+
ProvingSystemArg::Halo2IPA => ProvingSystemId::Halo2IPA,
161+
ProvingSystemArg::Risc0 => ProvingSystemId::Risc0,
162+
}
163+
}
164+
}
165+
133166
#[tokio::main]
134167
async fn main() -> Result<(), errors::BatcherClientError> {
135168
env_logger::Builder::from_env(Env::default().default_filter_or("info")).init();
@@ -324,8 +357,7 @@ async fn receive(
324357
}
325358

326359
fn verification_data_from_args(args: SubmitArgs) -> Result<VerificationData, BatcherClientError> {
327-
let proving_system = parse_proving_system(&args.proving_system_flag)
328-
.map_err(|_| BatcherClientError::InvalidProvingSystem(args.proving_system_flag))?;
360+
let proving_system = args.proving_system_flag.into();
329361

330362
// Read proof file
331363
let proof = read_file(args.proof_file_name)?;

0 commit comments

Comments
 (0)