Skip to content

Commit

Permalink
feat: add a cli option to print output hash instead
Browse files Browse the repository at this point in the history
  • Loading branch information
tdelabro committed Jan 9, 2025
1 parent 9407640 commit f151e66
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 15 deletions.
20 changes: 10 additions & 10 deletions Cargo.lock

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

33 changes: 31 additions & 2 deletions cli/Cargo.lock

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

3 changes: 2 additions & 1 deletion cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ version = "0.1.3"

[dependencies]
clap = { version = "4.4.4", features = ["derive"] }
starknet-core = "0.12.0"

swiftness_air = { path = "../crates/air", default-features = false, features = [
"std",
Expand Down Expand Up @@ -68,4 +69,4 @@ blake2s_160_lsb = [
blake2s_248_lsb = [
"swiftness_air/blake2s_248_lsb",
"swiftness_stark/blake2s_248_lsb",
]
]
15 changes: 13 additions & 2 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,24 @@ struct CairoVMVerifier {
/// Path to proof JSON file
#[clap(short, long)]
proof: PathBuf,
/// Whether to print the pedersen hash of the output instead of the full output.
#[clap(short = 'o', long, num_args=0..=1, default_missing_value = "true")]
print_output_hash: Option<bool>,
}

fn main() -> Result<(), Box<dyn std::error::Error>> {
let cli = CairoVMVerifier::parse();
let stark_proof = parse(std::fs::read_to_string(cli.proof)?)?.transform_to();
let security_bits = stark_proof.config.security_bits();
let result = stark_proof.verify::<Layout>(security_bits)?;
println!("{:?}", result);
let (program_hash, program_output) = stark_proof.verify::<Layout>(security_bits)?;

println!("program hash: {:#x}", program_hash);
if let Some(true) = cli.print_output_hash {
let hash = starknet_core::crypto::compute_hash_on_elements(&program_output);
println!("program output hash: {:#x}", hash);
} else {
println!("program output: {:x?}", program_output);
}

Ok(())
}

0 comments on commit f151e66

Please sign in to comment.