Skip to content

Commit a370708

Browse files
feat (aligned): get verification key commitment (#468)
Co-authored-by: Mauro Toscano <[email protected]>
1 parent c3c67ec commit a370708

File tree

4 files changed

+33
-1
lines changed

4 files changed

+33
-1
lines changed

batcher/Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Whitespace-only changes.

batcher/aligned/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ clap = { version = "4.5.4", features = ["derive"] }
1616
lambdaworks-crypto = { version = "0.7.0", features = ["serde"] }
1717
ethers = { version = "2.0", features = ["ws", "rustls"] }
1818
aligned-batcher-lib = { path = "../aligned-batcher-lib"}
19+
sha3 = { version = "0.10.8"}

batcher/aligned/src/main.rs

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,13 @@ use aligned_batcher_lib::types::{
2828
};
2929
use clap::Subcommand;
3030
use ethers::utils::hex;
31+
use sha3::{Digest, Keccak256};
3132

3233
use crate::errors::BatcherClientError;
3334
use crate::types::AlignedVerificationData;
3435
use crate::AlignedCommands::Submit;
3536
use crate::AlignedCommands::VerifyProofOnchain;
37+
use crate::AlignedCommands::GetVerificationKeyCommitment;
3638

3739
use clap::{Parser, ValueEnum};
3840

@@ -49,6 +51,10 @@ pub enum AlignedCommands {
4951
Submit(SubmitArgs),
5052
#[clap(about = "Verify the proof was included in a verified batch on Ethereum")]
5153
VerifyProofOnchain(VerifyProofOnchainArgs),
54+
55+
// GetVericiationKey, command name is get-vk-commitment
56+
#[clap(about = "Create verification key for proving system", name = "get-vk-commitment")]
57+
GetVerificationKeyCommitment(GetVerificationKeyCommitmentArgs),
5258
}
5359

5460
#[derive(Parser, Debug)]
@@ -109,6 +115,15 @@ pub struct VerifyProofOnchainArgs {
109115
chain: Chain,
110116
}
111117

118+
#[derive(Parser, Debug)]
119+
#[command(version, about, long_about = None)]
120+
pub struct GetVerificationKeyCommitmentArgs {
121+
#[arg(name = "File name", long = "input")]
122+
input_file: PathBuf,
123+
#[arg(name = "Output file", long = "output")]
124+
output_file: Option<PathBuf>,
125+
}
126+
112127
#[derive(Debug, Clone, ValueEnum)]
113128
pub enum Chain {
114129
Devnet,
@@ -170,7 +185,6 @@ async fn main() -> Result<(), errors::BatcherClientError> {
170185
)
171186
.await?;
172187
}
173-
174188
VerifyProofOnchain(verify_inclusion_args) => {
175189
let contract_address = match verify_inclusion_args.chain {
176190
Chain::Devnet => "0x1613beB3B2C4f22Ee086B2b38C1476A3cE7f78E8",
@@ -222,6 +236,22 @@ async fn main() -> Result<(), errors::BatcherClientError> {
222236
Err(err) => error!("Error while reading batch inclusion verification: {}", err),
223237
}
224238
}
239+
GetVerificationKeyCommitment(args) => {
240+
let content = read_file(args.input_file)?;
241+
242+
let mut hasher = Keccak256::new();
243+
hasher.update(&content);
244+
let hash: [u8; 32] = hasher.finalize().into();
245+
246+
info!("Commitment: {}", hex::encode(hash));
247+
if let Some(output_file) = args.output_file {
248+
let mut file = File::create(output_file.clone())
249+
.map_err(|e| BatcherClientError::IoError(output_file.clone(), e))?;
250+
251+
file.write_all(hex::encode(hash).as_bytes())
252+
.map_err(|e| BatcherClientError::IoError(output_file.clone(), e))?;
253+
}
254+
}
225255
}
226256

227257
Ok(())

0 commit comments

Comments
 (0)