From 568aca520e6b77f1b7fc5860705db23b28cbeb54 Mon Sep 17 00:00:00 2001 From: Manish Kumar Date: Wed, 31 Jul 2024 22:55:58 +0530 Subject: [PATCH] code cleaning and building/running script modified with rust flags for faster run --- hash/plonky2/bench/build.sh | 4 ++- hash/plonky2/bench/run.sh | 2 +- .../bench/src/bench/keccak256/keccak.rs | 33 +++++++++++-------- hash/plonky2/bench/src/bench/sha256/sha.rs | 2 ++ 4 files changed, 25 insertions(+), 16 deletions(-) diff --git a/hash/plonky2/bench/build.sh b/hash/plonky2/bench/build.sh index 749ad6c..7d27c85 100755 --- a/hash/plonky2/bench/build.sh +++ b/hash/plonky2/bench/build.sh @@ -4,5 +4,7 @@ rustup override set nightly # Build -cargo build +# RUSTFLAGS=-Ctarget-cpu=native cargo build +RUSTFLAGS=-Ctarget-cpu=native cargo build --release --bin plonky2_hash_benchmarks + diff --git a/hash/plonky2/bench/run.sh b/hash/plonky2/bench/run.sh index 9f1d247..8d21b7e 100755 --- a/hash/plonky2/bench/run.sh +++ b/hash/plonky2/bench/run.sh @@ -12,4 +12,4 @@ echo "HASH = $ZKBENCH_HASH_TYPE" echo "Input Size (Bytes) = $ZKBENCH_INPUT_SIZE_BYTES" # Run the benchmarks -./target/debug/plonky2_hash_benchmarks $ZKBENCH_HASH_TYPE $ZKBENCH_INPUT_SIZE_BYTES \ No newline at end of file +./target/release/plonky2_hash_benchmarks $ZKBENCH_HASH_TYPE $ZKBENCH_INPUT_SIZE_BYTES \ No newline at end of file diff --git a/hash/plonky2/bench/src/bench/keccak256/keccak.rs b/hash/plonky2/bench/src/bench/keccak256/keccak.rs index b287fa1..930059d 100644 --- a/hash/plonky2/bench/src/bench/keccak256/keccak.rs +++ b/hash/plonky2/bench/src/bench/keccak256/keccak.rs @@ -251,23 +251,28 @@ pub fn keccak_bench(size: usize) -> Result<()>{ for i in 0..256 { pw.set_bool_target(output_t[i], exptected_output_bits[i]); } - - println!("circuit size: {:?}", builder.num_gates()); + let circuit_size = builder.num_gates(); + let data = builder.build::(); - let now = Instant::now(); - let proof = data.prove(pw)?; - - println!("time = {:?}", now.elapsed()); - println!( - "degree = {}, degree_bits= {}", - data.common.degree(), - data.common.degree_bits() - ); - - data.verify(proof)?; - Ok(()) + let (proof_generation_time, proof) = { + let now = Instant::now(); + let proof = data.prove(pw)?; + (now.elapsed(), proof) + }; + let proof_size = proof.to_bytes().len(); + let (verification_time, verification_result) = { + let now = Instant::now(); + let res = data.verify(proof); + (now.elapsed(), res) + }; + + eprintln!("circuit size: {}", circuit_size); + eprintln!("proof generation time: {:?}", proof_generation_time); + eprintln!("verification time: {:?}", verification_time); + eprintln!("proof size: {:?}", proof_size); + verification_result } fn generate_data(size: usize) -> Vec { diff --git a/hash/plonky2/bench/src/bench/sha256/sha.rs b/hash/plonky2/bench/src/bench/sha256/sha.rs index 36e1b12..3a862de 100644 --- a/hash/plonky2/bench/src/bench/sha256/sha.rs +++ b/hash/plonky2/bench/src/bench/sha256/sha.rs @@ -227,6 +227,7 @@ pub fn sha256_bench(size: usize) -> Result<()> { let end = start.elapsed(); (end, proof) }; + let proof_size = proof.to_bytes().len(); let (verification_time, res) = { let start = std::time::Instant::now(); @@ -237,6 +238,7 @@ pub fn sha256_bench(size: usize) -> Result<()> { eprintln!("Proof Generation Time: {:?}", proof_time); eprintln!("Verification Time: {:?}", verification_time); + eprintln!("Proof size: {:?}", proof_size); res