Skip to content

Commit

Permalink
feat (aligned): get verification key commitment (yetanotherco#468)
Browse files Browse the repository at this point in the history
Co-authored-by: Mauro Toscano <[email protected]>
  • Loading branch information
taturosati and MauroToscano authored Jun 24, 2024
1 parent c3c67ec commit a370708
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 1 deletion.
1 change: 1 addition & 0 deletions batcher/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Empty file.
1 change: 1 addition & 0 deletions batcher/aligned/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ clap = { version = "4.5.4", features = ["derive"] }
lambdaworks-crypto = { version = "0.7.0", features = ["serde"] }
ethers = { version = "2.0", features = ["ws", "rustls"] }
aligned-batcher-lib = { path = "../aligned-batcher-lib"}
sha3 = { version = "0.10.8"}
32 changes: 31 additions & 1 deletion batcher/aligned/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@ use aligned_batcher_lib::types::{
};
use clap::Subcommand;
use ethers::utils::hex;
use sha3::{Digest, Keccak256};

use crate::errors::BatcherClientError;
use crate::types::AlignedVerificationData;
use crate::AlignedCommands::Submit;
use crate::AlignedCommands::VerifyProofOnchain;
use crate::AlignedCommands::GetVerificationKeyCommitment;

use clap::{Parser, ValueEnum};

Expand All @@ -49,6 +51,10 @@ pub enum AlignedCommands {
Submit(SubmitArgs),
#[clap(about = "Verify the proof was included in a verified batch on Ethereum")]
VerifyProofOnchain(VerifyProofOnchainArgs),

// GetVericiationKey, command name is get-vk-commitment
#[clap(about = "Create verification key for proving system", name = "get-vk-commitment")]
GetVerificationKeyCommitment(GetVerificationKeyCommitmentArgs),
}

#[derive(Parser, Debug)]
Expand Down Expand Up @@ -109,6 +115,15 @@ pub struct VerifyProofOnchainArgs {
chain: Chain,
}

#[derive(Parser, Debug)]
#[command(version, about, long_about = None)]
pub struct GetVerificationKeyCommitmentArgs {
#[arg(name = "File name", long = "input")]
input_file: PathBuf,
#[arg(name = "Output file", long = "output")]
output_file: Option<PathBuf>,
}

#[derive(Debug, Clone, ValueEnum)]
pub enum Chain {
Devnet,
Expand Down Expand Up @@ -170,7 +185,6 @@ async fn main() -> Result<(), errors::BatcherClientError> {
)
.await?;
}

VerifyProofOnchain(verify_inclusion_args) => {
let contract_address = match verify_inclusion_args.chain {
Chain::Devnet => "0x1613beB3B2C4f22Ee086B2b38C1476A3cE7f78E8",
Expand Down Expand Up @@ -222,6 +236,22 @@ async fn main() -> Result<(), errors::BatcherClientError> {
Err(err) => error!("Error while reading batch inclusion verification: {}", err),
}
}
GetVerificationKeyCommitment(args) => {
let content = read_file(args.input_file)?;

let mut hasher = Keccak256::new();
hasher.update(&content);
let hash: [u8; 32] = hasher.finalize().into();

info!("Commitment: {}", hex::encode(hash));
if let Some(output_file) = args.output_file {
let mut file = File::create(output_file.clone())
.map_err(|e| BatcherClientError::IoError(output_file.clone(), e))?;

file.write_all(hex::encode(hash).as_bytes())
.map_err(|e| BatcherClientError::IoError(output_file.clone(), e))?;
}
}
}

Ok(())
Expand Down

0 comments on commit a370708

Please sign in to comment.