From fbbd4f9a8a539afa851930d85316e41f8a0f035e Mon Sep 17 00:00:00 2001 From: guorong009 Date: Wed, 30 Jul 2025 14:48:31 +0800 Subject: [PATCH 01/16] chore: git ignore "*.csv" files --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 180183a..8211e55 100644 --- a/.gitignore +++ b/.gitignore @@ -17,4 +17,5 @@ bazel-* dist/ Dockerfile rust-project.json -tmp/ \ No newline at end of file +tmp/ +*.csv \ No newline at end of file From 1d3693710dd7a5d4234e404c3d26199d0128c618 Mon Sep 17 00:00:00 2001 From: guorong009 Date: Wed, 30 Jul 2025 14:48:53 +0800 Subject: [PATCH 02/16] feat: add "CustomMetrics" to "utils" --- utils/src/bench.rs | 55 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/utils/src/bench.rs b/utils/src/bench.rs index 46f7411..2bc7c15 100644 --- a/utils/src/bench.rs +++ b/utils/src/bench.rs @@ -1,5 +1,5 @@ use human_repr::{HumanCount, HumanDuration}; -use serde::Serialize; +use serde::{Deserialize, Serialize}; use serde_with::{serde_as, DurationNanoSeconds}; use std::{ fmt::Display, @@ -129,3 +129,56 @@ pub fn write_csv(out_path: &str, results: &[Metrics]) { table.with(Style::modern()); println!("{table}"); } + +#[serde_as] +#[derive(Serialize, Deserialize, Tabled)] +pub struct CustomMetrics { + #[tabled(display_with = "display_bytes")] + pub input_size: usize, + #[serde_as(as = "DurationNanoSeconds")] + #[tabled(display_with = "display_duration")] + pub proof_duration: Duration, + #[serde_as(as = "DurationNanoSeconds")] + #[tabled(display_with = "display_duration")] + pub verify_duration: Duration, + #[tabled(display_with = "display_bytes")] + pub proof_size: usize, + #[tabled(display_with = "display_bytes")] + pub proving_peak_memory: usize, + #[tabled(display_with = "display_bytes")] + pub preprocessing_size: usize, + #[tabled(display_with = "display_bytes")] + pub preprocessing_peak_memory: usize, +} + +impl CustomMetrics { + pub fn new(size: usize) -> Self { + CustomMetrics { + input_size: size, + proof_duration: Duration::default(), + verify_duration: Duration::default(), + proof_size: 0, + proving_peak_memory: 0, + preprocessing_size: 0, + preprocessing_peak_memory: 0, + } + } +} + +pub fn write_csv_custom(out_path: &str, results: &[CustomMetrics]) { + let mut out = csv::WriterBuilder::new().from_path(out_path).unwrap(); + + let mut all_metrics = Vec::new(); + + for metric in results { + out.serialize(&metric).expect("Could not serialize"); + out.flush().expect("Could not flush"); + all_metrics.push(metric); + } + + out.flush().expect("Could not flush"); + + let mut table = Table::new(&all_metrics); + table.with(Style::modern()); + println!("{table}"); +} From 0dd0feb4707ad704c0527410713039645ba45c79 Mon Sep 17 00:00:00 2001 From: guorong009 Date: Wed, 30 Jul 2025 14:49:13 +0800 Subject: [PATCH 03/16] feat: use CustomMetrics for binius benchmarks --- binius/src/bin/measure_lookup.rs | 36 +++++++++++++++++++---------- binius/src/bin/measure_no_lookup.rs | 36 +++++++++++++++++++---------- 2 files changed, 48 insertions(+), 24 deletions(-) diff --git a/binius/src/bin/measure_lookup.rs b/binius/src/bin/measure_lookup.rs index a383abc..486ab81 100644 --- a/binius/src/bin/measure_lookup.rs +++ b/binius/src/bin/measure_lookup.rs @@ -1,27 +1,39 @@ use anyhow::Error; use binius::bench::{prove, sha256_with_lookup_prepare, verify}; -use utils::bench::measure_peak_memory; +use std::time::Instant; +use utils::bench::{CustomMetrics, measure_peak_memory, write_csv_custom}; fn main() -> Result<(), Error> { + let csv_file = "sha2_binius_lookup.csv"; + + let input_num_bytes = 2048; + let metrics = benchmark_sha2(input_num_bytes)?; + + write_csv_custom(csv_file, &[metrics]); + + Ok(()) +} + +fn benchmark_sha2(num_bytes: usize) -> Result { + let mut metrics = CustomMetrics::new(num_bytes); + let allocator = bumpalo::Bump::new(); let ((constraint_system, args, witness, backend), peak_memory) = measure_peak_memory(|| sha256_with_lookup_prepare(&allocator)); + metrics.preprocessing_peak_memory = peak_memory; + metrics.preprocessing_size = 0; // TODO - println!( - "Preprocessing(lookup) peak memory: {} MB", - peak_memory as f32 / (1024.0 * 1024.0), - ); - + let start = Instant::now(); let ((cs, args, proof), peak_memory) = measure_peak_memory(|| prove(constraint_system, args, witness, backend)); + metrics.proof_duration = start.elapsed(); + metrics.proving_peak_memory = peak_memory; + metrics.proof_size = proof.get_proof_size(); - println!( - "Proving(lookup) peak memory: {} MB", - peak_memory as f32 / (1024.0 * 1024.0) - ); - + let start = Instant::now(); verify(cs, args, proof); + metrics.verify_duration = start.elapsed(); - Ok(()) + Ok(metrics) } diff --git a/binius/src/bin/measure_no_lookup.rs b/binius/src/bin/measure_no_lookup.rs index d4aebf1..a3a0370 100644 --- a/binius/src/bin/measure_no_lookup.rs +++ b/binius/src/bin/measure_no_lookup.rs @@ -1,27 +1,39 @@ use anyhow::Error; use binius::bench::{prove, sha256_no_lookup_prepare, verify}; -use utils::bench::measure_peak_memory; +use std::time::Instant; +use utils::bench::{CustomMetrics, measure_peak_memory, write_csv_custom}; fn main() -> Result<(), Error> { + let csv_file = "sha2_binius_no_lookup.csv"; + + let input_num_bytes = 2048; + let metrics = benchmark_sha2(input_num_bytes)?; + + write_csv_custom(csv_file, &[metrics]); + + Ok(()) +} + +fn benchmark_sha2(num_bytes: usize) -> Result { + let mut metrics = CustomMetrics::new(num_bytes); + let allocator = bumpalo::Bump::new(); let ((constraint_system, args, witness, backend), peak_memory) = measure_peak_memory(|| sha256_no_lookup_prepare(&allocator)); + metrics.preprocessing_peak_memory = peak_memory; + metrics.preprocessing_size = 0; // TODO - println!( - "Preprocessing(no lookup) peak memory: {} MB", - peak_memory as f32 / (1024.0 * 1024.0), - ); - + let start = Instant::now(); let ((cs, args, proof), peak_memory) = measure_peak_memory(|| prove(constraint_system, args, witness, backend)); + metrics.proof_duration = start.elapsed(); + metrics.proving_peak_memory = peak_memory; + metrics.proof_size = proof.get_proof_size(); - println!( - "Proving(no lookup) peak memory: {} MB", - peak_memory as f32 / (1024.0 * 1024.0) - ); - + let start = Instant::now(); verify(cs, args, proof); + metrics.verify_duration = start.elapsed(); - Ok(()) + Ok(metrics) } From 4a9a46fdb6adb607bf1c71f9d63b7416c0342ec8 Mon Sep 17 00:00:00 2001 From: guorong009 Date: Wed, 30 Jul 2025 15:11:32 +0800 Subject: [PATCH 04/16] feat: use CustomMetrics for plonky2 benchmark --- plonky2/src/bin/measure.rs | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/plonky2/src/bin/measure.rs b/plonky2/src/bin/measure.rs index d3e75a9..ec0abe5 100644 --- a/plonky2/src/bin/measure.rs +++ b/plonky2/src/bin/measure.rs @@ -1,19 +1,27 @@ use plonky2::{plonk::config::PoseidonGoldilocksConfig, util::serialization::Write}; -use plonky2_sha256::bench::{prove, sha256_no_lookup_prepare}; +use plonky2_sha256::bench::{prove, sha256_no_lookup_prepare, verify}; use plonky2_u32::gates::arithmetic_u32::{U32GateSerializer, U32GeneratorSerializer}; -use utils::bench::measure_peak_memory; +use std::time::Instant; +use utils::bench::{CustomMetrics, measure_peak_memory, write_csv_custom}; const D: usize = 2; type C = PoseidonGoldilocksConfig; fn main() { - let ((data, pw), peak_memory) = measure_peak_memory(|| sha256_no_lookup_prepare()); + let csv_file = "sha2_plonky2.csv"; - println!( - "Preprocessing peak memory: {} GB", - peak_memory as f32 / (1024.0 * 1024.0 * 1024.0), - ); + let input_num_bytes = 2048; + let metrics = benchmark_sha2(input_num_bytes); + + write_csv_custom(csv_file, &[metrics]); +} + +fn benchmark_sha2(num_bytes: usize) -> CustomMetrics { + let mut metrics = CustomMetrics::new(num_bytes); + + let ((data, pw), peak_memory) = measure_peak_memory(|| sha256_no_lookup_prepare()); + metrics.preprocessing_peak_memory = peak_memory; let gate_serializer = U32GateSerializer; let common_data_size = data.common.to_bytes(&gate_serializer).unwrap().len(); @@ -23,13 +31,18 @@ fn main() { .to_bytes(&generator_serializer, &data.common) .unwrap() .len(); + let verifier_data = data.verifier_data(); println!( "Common data size: {}B, Prover data size: {}B", common_data_size, prover_data_size ); + metrics.preprocessing_size = prover_data_size; // TODO + let start = Instant::now(); let (proof, peak_memory) = measure_peak_memory(|| prove(&data.prover_data(), pw)); + metrics.proof_duration = start.elapsed(); + metrics.proving_peak_memory = peak_memory; println!( "Proving peak memory: {} GB", @@ -39,4 +52,11 @@ fn main() { let mut buffer = Vec::new(); buffer.write_proof(&proof.proof).unwrap(); println!("Proof size: {} KB", buffer.len() as f32 / 1024.0); + metrics.proof_size = buffer.len(); + + let start = Instant::now(); + verify(&verifier_data, proof); + metrics.verify_duration = start.elapsed(); + + metrics } From fcf56346de99f061534588ff6d40bcc1dbdbfb23 Mon Sep 17 00:00:00 2001 From: guorong009 Date: Wed, 30 Jul 2025 15:21:22 +0800 Subject: [PATCH 05/16] feat: use CustomMetrics for plonky3-powdr benchmark --- plonky3-powdr/src/bin/measure.rs | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/plonky3-powdr/src/bin/measure.rs b/plonky3-powdr/src/bin/measure.rs index 1ab92ac..76b8f63 100644 --- a/plonky3-powdr/src/bin/measure.rs +++ b/plonky3-powdr/src/bin/measure.rs @@ -1,20 +1,42 @@ use sha::bench::{prepare_pipeline, prove, verify}; -use utils::bench::measure_peak_memory; +use std::time::Instant; +use utils::bench::{CustomMetrics, measure_peak_memory, write_csv_custom}; fn main() { - let (mut pipeline, peak_memory) = measure_peak_memory(|| prepare_pipeline()); + let csv_file = "sha2_plonky3_powdr.csv"; + + let input_num_bytes = 2048; + let metrics = benchmark_sha2(input_num_bytes); + + write_csv_custom(csv_file, &[metrics]); +} +fn benchmark_sha2(num_bytes: usize) -> CustomMetrics { + let mut metrics = CustomMetrics::new(num_bytes); + + let (mut pipeline, peak_memory) = measure_peak_memory(|| prepare_pipeline()); + metrics.preprocessing_peak_memory = peak_memory; println!( "Preprocessing peak memory: {} GB", peak_memory as f32 / (1024.0 * 1024.0 * 1024.0), ); + metrics.preprocessing_size = 0; // TODO + + let start = Instant::now(); let (_, peak_memory) = measure_peak_memory(|| prove(&mut pipeline)); + metrics.proof_duration = start.elapsed(); + metrics.proving_peak_memory = peak_memory; + metrics.proof_size = pipeline.proof().unwrap().len(); println!( "Proving peak memory: {} GB", peak_memory as f32 / (1024.0 * 1024.0 * 1024.0), ); + let start = Instant::now(); verify(pipeline); + metrics.verify_duration = start.elapsed(); + + metrics } From 9c0c01055ea91cc47f9bc3cd2f7d192c726d1ecf Mon Sep 17 00:00:00 2001 From: guorong009 Date: Wed, 30 Jul 2025 16:18:11 +0800 Subject: [PATCH 06/16] feat: use CustomMetrics for plonky3-sp1 benchmark --- plonky3-sp1/script/src/bin/measure.rs | 40 ++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/plonky3-sp1/script/src/bin/measure.rs b/plonky3-sp1/script/src/bin/measure.rs index e5013c9..aaf0665 100644 --- a/plonky3-sp1/script/src/bin/measure.rs +++ b/plonky3-sp1/script/src/bin/measure.rs @@ -1,10 +1,32 @@ use sp1_sdk::{ProverClient, SP1Stdin, include_elf}; -use utils::bench::measure_peak_memory; +use std::time::Instant; +use utils::bench::{CustomMetrics, measure_peak_memory, write_csv_custom}; /// The ELF (executable and linkable format) file for the Succinct RISC-V zkVM. pub const SHA_ELF: &[u8] = include_elf!("sha-program"); fn main() { + let csv_file = "sha2_plonky3_sp1.csv"; + + let input_num_bytes = 2048; + let metrics = benchmark_sha2(input_num_bytes); + + write_csv_custom(csv_file, &[metrics]); +} + +fn benchmark_sha2(input_num_bytes: usize) -> CustomMetrics { + let mut metrics = CustomMetrics::new(input_num_bytes); + + // Load the proving key and verifying key from the files. + let pk_bytes = std::fs::read("pk.bin").expect("Unable to read file"); + let pk: sp1_sdk::SP1ProvingKey = bincode::deserialize(&pk_bytes).unwrap(); + // Load the verifying key from the file. + let vk_bytes = std::fs::read("vk.bin").expect("Unable to read file"); + let vk: sp1_sdk::SP1VerifyingKey = bincode::deserialize(&vk_bytes).unwrap(); + // Load the proof from the file. + let proof_bytes = std::fs::read("proof.bin").expect("Unable to read file"); + let proof: sp1_sdk::SP1ProofWithPublicValues = bincode::deserialize(&proof_bytes).unwrap(); + // Setup the prover client. let client = ProverClient::from_env(); let stdin = SP1Stdin::new(); @@ -12,25 +34,35 @@ fn main() { // Setup the program for proving. let ((_, _), peak_memory) = measure_peak_memory(|| client.setup(SHA_ELF)); + metrics.preprocessing_peak_memory = peak_memory; println!( "Preprocessing peak memory: {} GB", peak_memory as f32 / (1024.0 * 1024.0 * 1024.0) ); - // Load the proving key and verifying key from the files. - let pk_bytes = std::fs::read("pk.bin").expect("Unable to read file"); - let pk: sp1_sdk::SP1ProvingKey = bincode::deserialize(&pk_bytes).unwrap(); + metrics.preprocessing_size = pk_bytes.len() + SHA_ELF.len(); // TODO // Generate the proof + let start = Instant::now(); let (_, peak_memory) = measure_peak_memory(|| { client .prove(&pk, &stdin) .run() .expect("failed to generate proof") }); + metrics.proof_duration = start.elapsed(); + metrics.proving_peak_memory = peak_memory; + metrics.proof_size = proof_bytes.len(); println!( "Proving peak memory: {} GB", peak_memory as f32 / (1024.0 * 1024.0 * 1024.0), ); + + // Verify the proof + let start = Instant::now(); + client.verify(&proof, &vk).expect("failed to verify proof"); + metrics.verify_duration = start.elapsed(); + + metrics } From 9e1c8eef1a691af5636ab8c9545a7ef8a57e0e14 Mon Sep 17 00:00:00 2001 From: guorong009 Date: Tue, 5 Aug 2025 23:01:17 +0800 Subject: [PATCH 07/16] chore: git ignore "*.json" files --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 9cbb6d2..187c565 100644 --- a/.gitignore +++ b/.gitignore @@ -18,4 +18,4 @@ dist/ Dockerfile rust-project.json tmp/ -*.csv +*.json From 91630e4ed817b9aafb3cf9f00506a6252e4cb0fb Mon Sep 17 00:00:00 2001 From: guorong009 Date: Tue, 5 Aug 2025 23:02:25 +0800 Subject: [PATCH 08/16] feat: update "CustomMetrics" as "SubMetrics" --- utils/src/bench.rs | 37 ++++++++----------------------------- 1 file changed, 8 insertions(+), 29 deletions(-) diff --git a/utils/src/bench.rs b/utils/src/bench.rs index 6efd641..7c93cc5 100644 --- a/utils/src/bench.rs +++ b/utils/src/bench.rs @@ -1,5 +1,5 @@ use human_repr::{HumanCount, HumanDuration}; -use serde::{Deserialize, Serialize}; +use serde::Serialize; use serde_with::{serde_as, DurationNanoSeconds}; use std::{ fmt::Display, @@ -131,16 +131,10 @@ pub fn write_csv(out_path: &str, results: &[Metrics]) { } #[serde_as] -#[derive(Serialize, Deserialize, Tabled)] -pub struct CustomMetrics { +#[derive(Serialize, Tabled)] +pub struct SubMetrics { #[tabled(display_with = "display_bytes")] pub input_size: usize, - #[serde_as(as = "DurationNanoSeconds")] - #[tabled(display_with = "display_duration")] - pub proof_duration: Duration, - #[serde_as(as = "DurationNanoSeconds")] - #[tabled(display_with = "display_duration")] - pub verify_duration: Duration, #[tabled(display_with = "display_bytes")] pub proof_size: usize, #[tabled(display_with = "display_bytes")] @@ -151,12 +145,10 @@ pub struct CustomMetrics { pub preprocessing_peak_memory: usize, } -impl CustomMetrics { +impl SubMetrics { pub fn new(size: usize) -> Self { - CustomMetrics { + SubMetrics { input_size: size, - proof_duration: Duration::default(), - verify_duration: Duration::default(), proof_size: 0, proving_peak_memory: 0, preprocessing_size: 0, @@ -165,20 +157,7 @@ impl CustomMetrics { } } -pub fn write_csv_custom(out_path: &str, results: &[CustomMetrics]) { - let mut out = csv::WriterBuilder::new().from_path(out_path).unwrap(); - - let mut all_metrics = Vec::new(); - - for metric in results { - out.serialize(&metric).expect("Could not serialize"); - out.flush().expect("Could not flush"); - all_metrics.push(metric); - } - - out.flush().expect("Could not flush"); - - let mut table = Table::new(&all_metrics); - table.with(Style::modern()); - println!("{table}"); +pub fn write_json_submetrics(output_path: &str, metrics: &SubMetrics) { + let json = serde_json::to_string_pretty(metrics).unwrap(); + std::fs::write(output_path, json).unwrap(); } From fa3f70499f820cf306d448279dfbfe9b568a692a Mon Sep 17 00:00:00 2001 From: guorong009 Date: Tue, 5 Aug 2025 23:03:05 +0800 Subject: [PATCH 09/16] feat: use SubMetrics for benchmarks --- binius/src/bin/measure_lookup.rs | 21 +++++++-------------- binius/src/bin/measure_no_lookup.rs | 21 +++++++-------------- plonky2/src/bin/measure.rs | 20 ++++++-------------- plonky3-powdr/src/bin/measure.rs | 19 ++++++------------- plonky3-sp1/script/src/bin/measure.rs | 22 +++++----------------- 5 files changed, 31 insertions(+), 72 deletions(-) diff --git a/binius/src/bin/measure_lookup.rs b/binius/src/bin/measure_lookup.rs index 486ab81..6ce466d 100644 --- a/binius/src/bin/measure_lookup.rs +++ b/binius/src/bin/measure_lookup.rs @@ -1,21 +1,20 @@ use anyhow::Error; -use binius::bench::{prove, sha256_with_lookup_prepare, verify}; -use std::time::Instant; -use utils::bench::{CustomMetrics, measure_peak_memory, write_csv_custom}; +use binius::bench::{prove, sha256_with_lookup_prepare}; +use utils::bench::{SubMetrics, measure_peak_memory, write_json_submetrics}; fn main() -> Result<(), Error> { - let csv_file = "sha2_binius_lookup.csv"; + let json_file = "sha2_binius_lookup_submetrics.json"; let input_num_bytes = 2048; let metrics = benchmark_sha2(input_num_bytes)?; - write_csv_custom(csv_file, &[metrics]); + write_json_submetrics(json_file, &metrics); Ok(()) } -fn benchmark_sha2(num_bytes: usize) -> Result { - let mut metrics = CustomMetrics::new(num_bytes); +fn benchmark_sha2(num_bytes: usize) -> Result { + let mut metrics = SubMetrics::new(num_bytes); let allocator = bumpalo::Bump::new(); @@ -24,16 +23,10 @@ fn benchmark_sha2(num_bytes: usize) -> Result { metrics.preprocessing_peak_memory = peak_memory; metrics.preprocessing_size = 0; // TODO - let start = Instant::now(); - let ((cs, args, proof), peak_memory) = + let ((_, _, proof), peak_memory) = measure_peak_memory(|| prove(constraint_system, args, witness, backend)); - metrics.proof_duration = start.elapsed(); metrics.proving_peak_memory = peak_memory; metrics.proof_size = proof.get_proof_size(); - let start = Instant::now(); - verify(cs, args, proof); - metrics.verify_duration = start.elapsed(); - Ok(metrics) } diff --git a/binius/src/bin/measure_no_lookup.rs b/binius/src/bin/measure_no_lookup.rs index a3a0370..300cd9b 100644 --- a/binius/src/bin/measure_no_lookup.rs +++ b/binius/src/bin/measure_no_lookup.rs @@ -1,21 +1,20 @@ use anyhow::Error; -use binius::bench::{prove, sha256_no_lookup_prepare, verify}; -use std::time::Instant; -use utils::bench::{CustomMetrics, measure_peak_memory, write_csv_custom}; +use binius::bench::{prove, sha256_no_lookup_prepare}; +use utils::bench::{SubMetrics, measure_peak_memory, write_json_submetrics}; fn main() -> Result<(), Error> { - let csv_file = "sha2_binius_no_lookup.csv"; + let json_file = "sha2_binius_no_lookup_submetrics.json"; let input_num_bytes = 2048; let metrics = benchmark_sha2(input_num_bytes)?; - write_csv_custom(csv_file, &[metrics]); + write_json_submetrics(json_file, &metrics); Ok(()) } -fn benchmark_sha2(num_bytes: usize) -> Result { - let mut metrics = CustomMetrics::new(num_bytes); +fn benchmark_sha2(num_bytes: usize) -> Result { + let mut metrics = SubMetrics::new(num_bytes); let allocator = bumpalo::Bump::new(); @@ -24,16 +23,10 @@ fn benchmark_sha2(num_bytes: usize) -> Result { metrics.preprocessing_peak_memory = peak_memory; metrics.preprocessing_size = 0; // TODO - let start = Instant::now(); - let ((cs, args, proof), peak_memory) = + let ((_, _, proof), peak_memory) = measure_peak_memory(|| prove(constraint_system, args, witness, backend)); - metrics.proof_duration = start.elapsed(); metrics.proving_peak_memory = peak_memory; metrics.proof_size = proof.get_proof_size(); - let start = Instant::now(); - verify(cs, args, proof); - metrics.verify_duration = start.elapsed(); - Ok(metrics) } diff --git a/plonky2/src/bin/measure.rs b/plonky2/src/bin/measure.rs index ec0abe5..caa91a9 100644 --- a/plonky2/src/bin/measure.rs +++ b/plonky2/src/bin/measure.rs @@ -1,24 +1,23 @@ use plonky2::{plonk::config::PoseidonGoldilocksConfig, util::serialization::Write}; -use plonky2_sha256::bench::{prove, sha256_no_lookup_prepare, verify}; +use plonky2_sha256::bench::{prove, sha256_no_lookup_prepare}; use plonky2_u32::gates::arithmetic_u32::{U32GateSerializer, U32GeneratorSerializer}; -use std::time::Instant; -use utils::bench::{CustomMetrics, measure_peak_memory, write_csv_custom}; +use utils::bench::{SubMetrics, measure_peak_memory, write_json_submetrics}; const D: usize = 2; type C = PoseidonGoldilocksConfig; fn main() { - let csv_file = "sha2_plonky2.csv"; + let json_file = "sha2_plonky2_submetrics.json"; let input_num_bytes = 2048; let metrics = benchmark_sha2(input_num_bytes); - write_csv_custom(csv_file, &[metrics]); + write_json_submetrics(json_file, &metrics); } -fn benchmark_sha2(num_bytes: usize) -> CustomMetrics { - let mut metrics = CustomMetrics::new(num_bytes); +fn benchmark_sha2(num_bytes: usize) -> SubMetrics { + let mut metrics = SubMetrics::new(num_bytes); let ((data, pw), peak_memory) = measure_peak_memory(|| sha256_no_lookup_prepare()); metrics.preprocessing_peak_memory = peak_memory; @@ -31,7 +30,6 @@ fn benchmark_sha2(num_bytes: usize) -> CustomMetrics { .to_bytes(&generator_serializer, &data.common) .unwrap() .len(); - let verifier_data = data.verifier_data(); println!( "Common data size: {}B, Prover data size: {}B", @@ -39,9 +37,7 @@ fn benchmark_sha2(num_bytes: usize) -> CustomMetrics { ); metrics.preprocessing_size = prover_data_size; // TODO - let start = Instant::now(); let (proof, peak_memory) = measure_peak_memory(|| prove(&data.prover_data(), pw)); - metrics.proof_duration = start.elapsed(); metrics.proving_peak_memory = peak_memory; println!( @@ -54,9 +50,5 @@ fn benchmark_sha2(num_bytes: usize) -> CustomMetrics { println!("Proof size: {} KB", buffer.len() as f32 / 1024.0); metrics.proof_size = buffer.len(); - let start = Instant::now(); - verify(&verifier_data, proof); - metrics.verify_duration = start.elapsed(); - metrics } diff --git a/plonky3-powdr/src/bin/measure.rs b/plonky3-powdr/src/bin/measure.rs index 76b8f63..3d9d3a1 100644 --- a/plonky3-powdr/src/bin/measure.rs +++ b/plonky3-powdr/src/bin/measure.rs @@ -1,18 +1,17 @@ -use sha::bench::{prepare_pipeline, prove, verify}; -use std::time::Instant; -use utils::bench::{CustomMetrics, measure_peak_memory, write_csv_custom}; +use sha::bench::{prepare_pipeline, prove}; +use utils::bench::{SubMetrics, measure_peak_memory, write_json_submetrics}; fn main() { - let csv_file = "sha2_plonky3_powdr.csv"; + let json_file = "sha2_plonky3_powdr_submetrics.json"; let input_num_bytes = 2048; let metrics = benchmark_sha2(input_num_bytes); - write_csv_custom(csv_file, &[metrics]); + write_json_submetrics(json_file, &metrics); } -fn benchmark_sha2(num_bytes: usize) -> CustomMetrics { - let mut metrics = CustomMetrics::new(num_bytes); +fn benchmark_sha2(num_bytes: usize) -> SubMetrics { + let mut metrics = SubMetrics::new(num_bytes); let (mut pipeline, peak_memory) = measure_peak_memory(|| prepare_pipeline()); metrics.preprocessing_peak_memory = peak_memory; @@ -23,9 +22,7 @@ fn benchmark_sha2(num_bytes: usize) -> CustomMetrics { metrics.preprocessing_size = 0; // TODO - let start = Instant::now(); let (_, peak_memory) = measure_peak_memory(|| prove(&mut pipeline)); - metrics.proof_duration = start.elapsed(); metrics.proving_peak_memory = peak_memory; metrics.proof_size = pipeline.proof().unwrap().len(); @@ -34,9 +31,5 @@ fn benchmark_sha2(num_bytes: usize) -> CustomMetrics { peak_memory as f32 / (1024.0 * 1024.0 * 1024.0), ); - let start = Instant::now(); - verify(pipeline); - metrics.verify_duration = start.elapsed(); - metrics } diff --git a/plonky3-sp1/script/src/bin/measure.rs b/plonky3-sp1/script/src/bin/measure.rs index aaf0665..1b7e630 100644 --- a/plonky3-sp1/script/src/bin/measure.rs +++ b/plonky3-sp1/script/src/bin/measure.rs @@ -1,31 +1,26 @@ use sp1_sdk::{ProverClient, SP1Stdin, include_elf}; -use std::time::Instant; -use utils::bench::{CustomMetrics, measure_peak_memory, write_csv_custom}; +use utils::bench::{SubMetrics, measure_peak_memory, write_json_submetrics}; /// The ELF (executable and linkable format) file for the Succinct RISC-V zkVM. pub const SHA_ELF: &[u8] = include_elf!("sha-program"); fn main() { - let csv_file = "sha2_plonky3_sp1.csv"; + let json_file = "sha2_plonky3_sp1_submetrics.json"; let input_num_bytes = 2048; let metrics = benchmark_sha2(input_num_bytes); - write_csv_custom(csv_file, &[metrics]); + write_json_submetrics(json_file, &metrics); } -fn benchmark_sha2(input_num_bytes: usize) -> CustomMetrics { - let mut metrics = CustomMetrics::new(input_num_bytes); +fn benchmark_sha2(input_num_bytes: usize) -> SubMetrics { + let mut metrics = SubMetrics::new(input_num_bytes); // Load the proving key and verifying key from the files. let pk_bytes = std::fs::read("pk.bin").expect("Unable to read file"); let pk: sp1_sdk::SP1ProvingKey = bincode::deserialize(&pk_bytes).unwrap(); - // Load the verifying key from the file. - let vk_bytes = std::fs::read("vk.bin").expect("Unable to read file"); - let vk: sp1_sdk::SP1VerifyingKey = bincode::deserialize(&vk_bytes).unwrap(); // Load the proof from the file. let proof_bytes = std::fs::read("proof.bin").expect("Unable to read file"); - let proof: sp1_sdk::SP1ProofWithPublicValues = bincode::deserialize(&proof_bytes).unwrap(); // Setup the prover client. let client = ProverClient::from_env(); @@ -43,14 +38,12 @@ fn benchmark_sha2(input_num_bytes: usize) -> CustomMetrics { metrics.preprocessing_size = pk_bytes.len() + SHA_ELF.len(); // TODO // Generate the proof - let start = Instant::now(); let (_, peak_memory) = measure_peak_memory(|| { client .prove(&pk, &stdin) .run() .expect("failed to generate proof") }); - metrics.proof_duration = start.elapsed(); metrics.proving_peak_memory = peak_memory; metrics.proof_size = proof_bytes.len(); @@ -59,10 +52,5 @@ fn benchmark_sha2(input_num_bytes: usize) -> CustomMetrics { peak_memory as f32 / (1024.0 * 1024.0 * 1024.0), ); - // Verify the proof - let start = Instant::now(); - client.verify(&proof, &vk).expect("failed to verify proof"); - metrics.verify_duration = start.elapsed(); - metrics } From 95d80a408c3112407b4f4c3a4732755b0e3db8b9 Mon Sep 17 00:00:00 2001 From: guorong009 Date: Tue, 5 Aug 2025 23:05:25 +0800 Subject: [PATCH 10/16] chore: cargo fmt --- guests/src/ecdsa.rs | 4 ++-- utils/src/bench.rs | 6 +++--- utils/src/bin/sign_ecdsa.rs | 2 +- utils/src/lib.rs | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/guests/src/ecdsa.rs b/guests/src/ecdsa.rs index cf0801b..f838d1a 100644 --- a/guests/src/ecdsa.rs +++ b/guests/src/ecdsa.rs @@ -1,7 +1,7 @@ use k256::{ - ecdsa::{signature::Verifier, Signature, VerifyingKey}, - elliptic_curve::sec1::EncodedPoint, Secp256k1, + ecdsa::{Signature, VerifyingKey, signature::Verifier}, + elliptic_curve::sec1::EncodedPoint, }; use serde::{Deserialize, Serialize}; diff --git a/utils/src/bench.rs b/utils/src/bench.rs index 7c93cc5..7a974fb 100644 --- a/utils/src/bench.rs +++ b/utils/src/bench.rs @@ -1,16 +1,16 @@ use human_repr::{HumanCount, HumanDuration}; use serde::Serialize; -use serde_with::{serde_as, DurationNanoSeconds}; +use serde_with::{DurationNanoSeconds, serde_as}; use std::{ fmt::Display, sync::{ - atomic::{AtomicBool, AtomicUsize, Ordering}, Arc, + atomic::{AtomicBool, AtomicUsize, Ordering}, }, thread, time::Duration, }; -use tabled::{settings::Style, Table, Tabled}; +use tabled::{Table, Tabled, settings::Style}; fn get_current_memory_usage() -> Result { unsafe { diff --git a/utils/src/bin/sign_ecdsa.rs b/utils/src/bin/sign_ecdsa.rs index 4f94cd3..da0ef8b 100644 --- a/utils/src/bin/sign_ecdsa.rs +++ b/utils/src/bin/sign_ecdsa.rs @@ -1,5 +1,5 @@ use k256::{ - ecdsa::{signature::Signer, Signature, SigningKey}, + ecdsa::{Signature, SigningKey, signature::Signer}, elliptic_curve::rand_core::OsRng, }; use std::{fs::File, io::Write}; diff --git a/utils/src/lib.rs b/utils/src/lib.rs index 08a88ca..e862fd4 100644 --- a/utils/src/lib.rs +++ b/utils/src/lib.rs @@ -1,6 +1,6 @@ use guests::ecdsa::EcdsaVerifyInput; -use k256::{ecdsa::Signature, elliptic_curve::sec1::EncodedPoint, Secp256k1}; -use rand::{rngs::StdRng, RngCore, SeedableRng}; +use k256::{Secp256k1, ecdsa::Signature, elliptic_curve::sec1::EncodedPoint}; +use rand::{RngCore, SeedableRng, rngs::StdRng}; use std::fs; use std::fs::File; use std::io::Write; From f3c4032544f7f28a66c761f8de0c483ce7d3f777 Mon Sep 17 00:00:00 2001 From: guorong009 Date: Wed, 6 Aug 2025 16:17:57 +0800 Subject: [PATCH 11/16] fix: compute "preprocessing_size" for plonky2 and plonky3-powdr --- plonky2/src/bin/measure.rs | 2 +- plonky3-powdr/src/bin/measure.rs | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/plonky2/src/bin/measure.rs b/plonky2/src/bin/measure.rs index caa91a9..cb9056b 100644 --- a/plonky2/src/bin/measure.rs +++ b/plonky2/src/bin/measure.rs @@ -35,7 +35,7 @@ fn benchmark_sha2(num_bytes: usize) -> SubMetrics { "Common data size: {}B, Prover data size: {}B", common_data_size, prover_data_size ); - metrics.preprocessing_size = prover_data_size; // TODO + metrics.preprocessing_size = prover_data_size + common_data_size; // TODO let (proof, peak_memory) = measure_peak_memory(|| prove(&data.prover_data(), pw)); metrics.proving_peak_memory = peak_memory; diff --git a/plonky3-powdr/src/bin/measure.rs b/plonky3-powdr/src/bin/measure.rs index 3d9d3a1..5e447fc 100644 --- a/plonky3-powdr/src/bin/measure.rs +++ b/plonky3-powdr/src/bin/measure.rs @@ -20,7 +20,10 @@ fn benchmark_sha2(num_bytes: usize) -> SubMetrics { peak_memory as f32 / (1024.0 * 1024.0 * 1024.0), ); - metrics.preprocessing_size = 0; // TODO + // Load the proving key and constants from the files. + let pk_bytes = std::fs::read("powdr-target/pkey.bin").expect("Unable to read file"); + let constants_bytes = std::fs::read("powdr-target/constants.bin").expect("Unable to read file"); + metrics.preprocessing_size = pk_bytes.len() + constants_bytes.len(); // TODO let (_, peak_memory) = measure_peak_memory(|| prove(&mut pipeline)); metrics.proving_peak_memory = peak_memory; From ae7b580ae7e5cf37864848700152fa3a6d9182ae Mon Sep 17 00:00:00 2001 From: guorong009 Date: Wed, 6 Aug 2025 16:39:15 +0800 Subject: [PATCH 12/16] fix: compute "preprocessing_size" in binius benchmarks --- binius/src/bin/measure_lookup.rs | 8 +++++++- binius/src/bin/measure_no_lookup.rs | 8 +++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/binius/src/bin/measure_lookup.rs b/binius/src/bin/measure_lookup.rs index 6ce466d..5ef5998 100644 --- a/binius/src/bin/measure_lookup.rs +++ b/binius/src/bin/measure_lookup.rs @@ -1,5 +1,6 @@ use anyhow::Error; use binius::bench::{prove, sha256_with_lookup_prepare}; +use binius_utils::SerializeBytes; use utils::bench::{SubMetrics, measure_peak_memory, write_json_submetrics}; fn main() -> Result<(), Error> { @@ -21,7 +22,12 @@ fn benchmark_sha2(num_bytes: usize) -> Result { let ((constraint_system, args, witness, backend), peak_memory) = measure_peak_memory(|| sha256_with_lookup_prepare(&allocator)); metrics.preprocessing_peak_memory = peak_memory; - metrics.preprocessing_size = 0; // TODO + + let mut buffer: Vec = Vec::new(); + let _ = constraint_system + .serialize(&mut buffer, binius_utils::SerializationMode::CanonicalTower) + .expect("Failed to serialize constraint system"); + metrics.preprocessing_size = buffer.len(); // TODO let ((_, _, proof), peak_memory) = measure_peak_memory(|| prove(constraint_system, args, witness, backend)); diff --git a/binius/src/bin/measure_no_lookup.rs b/binius/src/bin/measure_no_lookup.rs index 300cd9b..1b87a4e 100644 --- a/binius/src/bin/measure_no_lookup.rs +++ b/binius/src/bin/measure_no_lookup.rs @@ -1,5 +1,6 @@ use anyhow::Error; use binius::bench::{prove, sha256_no_lookup_prepare}; +use binius_utils::SerializeBytes; use utils::bench::{SubMetrics, measure_peak_memory, write_json_submetrics}; fn main() -> Result<(), Error> { @@ -21,7 +22,12 @@ fn benchmark_sha2(num_bytes: usize) -> Result { let ((constraint_system, args, witness, backend), peak_memory) = measure_peak_memory(|| sha256_no_lookup_prepare(&allocator)); metrics.preprocessing_peak_memory = peak_memory; - metrics.preprocessing_size = 0; // TODO + + let mut buffer: Vec = Vec::new(); + let _ = constraint_system + .serialize(&mut buffer, binius_utils::SerializationMode::CanonicalTower) + .expect("Failed to serialize constraint system"); + metrics.preprocessing_size = buffer.len(); // TODO let ((_, _, proof), peak_memory) = measure_peak_memory(|| prove(constraint_system, args, witness, backend)); From d322b0bc511b7466148764ac75aced2d57eb91e0 Mon Sep 17 00:00:00 2001 From: guorong009 Date: Wed, 6 Aug 2025 16:41:22 +0800 Subject: [PATCH 13/16] chore: add comments for "preprocessing_size" computation --- binius/src/bin/measure_lookup.rs | 2 +- binius/src/bin/measure_no_lookup.rs | 2 +- plonky2/src/bin/measure.rs | 2 +- plonky3-powdr/src/bin/measure.rs | 2 +- plonky3-sp1/script/src/bin/measure.rs | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/binius/src/bin/measure_lookup.rs b/binius/src/bin/measure_lookup.rs index 5ef5998..d2df8b9 100644 --- a/binius/src/bin/measure_lookup.rs +++ b/binius/src/bin/measure_lookup.rs @@ -27,7 +27,7 @@ fn benchmark_sha2(num_bytes: usize) -> Result { let _ = constraint_system .serialize(&mut buffer, binius_utils::SerializationMode::CanonicalTower) .expect("Failed to serialize constraint system"); - metrics.preprocessing_size = buffer.len(); // TODO + metrics.preprocessing_size = buffer.len(); // correct? let ((_, _, proof), peak_memory) = measure_peak_memory(|| prove(constraint_system, args, witness, backend)); diff --git a/binius/src/bin/measure_no_lookup.rs b/binius/src/bin/measure_no_lookup.rs index 1b87a4e..8fc9dbb 100644 --- a/binius/src/bin/measure_no_lookup.rs +++ b/binius/src/bin/measure_no_lookup.rs @@ -27,7 +27,7 @@ fn benchmark_sha2(num_bytes: usize) -> Result { let _ = constraint_system .serialize(&mut buffer, binius_utils::SerializationMode::CanonicalTower) .expect("Failed to serialize constraint system"); - metrics.preprocessing_size = buffer.len(); // TODO + metrics.preprocessing_size = buffer.len(); // correct? let ((_, _, proof), peak_memory) = measure_peak_memory(|| prove(constraint_system, args, witness, backend)); diff --git a/plonky2/src/bin/measure.rs b/plonky2/src/bin/measure.rs index cb9056b..f02cf01 100644 --- a/plonky2/src/bin/measure.rs +++ b/plonky2/src/bin/measure.rs @@ -35,7 +35,7 @@ fn benchmark_sha2(num_bytes: usize) -> SubMetrics { "Common data size: {}B, Prover data size: {}B", common_data_size, prover_data_size ); - metrics.preprocessing_size = prover_data_size + common_data_size; // TODO + metrics.preprocessing_size = prover_data_size + common_data_size; // correct? let (proof, peak_memory) = measure_peak_memory(|| prove(&data.prover_data(), pw)); metrics.proving_peak_memory = peak_memory; diff --git a/plonky3-powdr/src/bin/measure.rs b/plonky3-powdr/src/bin/measure.rs index 5e447fc..4832841 100644 --- a/plonky3-powdr/src/bin/measure.rs +++ b/plonky3-powdr/src/bin/measure.rs @@ -23,7 +23,7 @@ fn benchmark_sha2(num_bytes: usize) -> SubMetrics { // Load the proving key and constants from the files. let pk_bytes = std::fs::read("powdr-target/pkey.bin").expect("Unable to read file"); let constants_bytes = std::fs::read("powdr-target/constants.bin").expect("Unable to read file"); - metrics.preprocessing_size = pk_bytes.len() + constants_bytes.len(); // TODO + metrics.preprocessing_size = pk_bytes.len() + constants_bytes.len(); // correct? let (_, peak_memory) = measure_peak_memory(|| prove(&mut pipeline)); metrics.proving_peak_memory = peak_memory; diff --git a/plonky3-sp1/script/src/bin/measure.rs b/plonky3-sp1/script/src/bin/measure.rs index 1b7e630..f618eb2 100644 --- a/plonky3-sp1/script/src/bin/measure.rs +++ b/plonky3-sp1/script/src/bin/measure.rs @@ -35,7 +35,7 @@ fn benchmark_sha2(input_num_bytes: usize) -> SubMetrics { peak_memory as f32 / (1024.0 * 1024.0 * 1024.0) ); - metrics.preprocessing_size = pk_bytes.len() + SHA_ELF.len(); // TODO + metrics.preprocessing_size = pk_bytes.len() + SHA_ELF.len(); // correct? // Generate the proof let (_, peak_memory) = measure_peak_memory(|| { From 17347e035a22bf6ed548fd0c1007d41c219c796f Mon Sep 17 00:00:00 2001 From: guorong009 Date: Wed, 6 Aug 2025 16:54:23 +0800 Subject: [PATCH 14/16] fix: correct the "preprocessing_size" computations --- binius/src/bin/measure_lookup.rs | 2 +- binius/src/bin/measure_no_lookup.rs | 2 +- plonky2/src/bin/measure.rs | 2 +- plonky3-powdr/src/bin/measure.rs | 2 +- plonky3-sp1/script/src/bin/measure.rs | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/binius/src/bin/measure_lookup.rs b/binius/src/bin/measure_lookup.rs index d2df8b9..c81a651 100644 --- a/binius/src/bin/measure_lookup.rs +++ b/binius/src/bin/measure_lookup.rs @@ -27,7 +27,7 @@ fn benchmark_sha2(num_bytes: usize) -> Result { let _ = constraint_system .serialize(&mut buffer, binius_utils::SerializationMode::CanonicalTower) .expect("Failed to serialize constraint system"); - metrics.preprocessing_size = buffer.len(); // correct? + metrics.preprocessing_size = buffer.len(); let ((_, _, proof), peak_memory) = measure_peak_memory(|| prove(constraint_system, args, witness, backend)); diff --git a/binius/src/bin/measure_no_lookup.rs b/binius/src/bin/measure_no_lookup.rs index 8fc9dbb..5e9ee99 100644 --- a/binius/src/bin/measure_no_lookup.rs +++ b/binius/src/bin/measure_no_lookup.rs @@ -27,7 +27,7 @@ fn benchmark_sha2(num_bytes: usize) -> Result { let _ = constraint_system .serialize(&mut buffer, binius_utils::SerializationMode::CanonicalTower) .expect("Failed to serialize constraint system"); - metrics.preprocessing_size = buffer.len(); // correct? + metrics.preprocessing_size = buffer.len(); let ((_, _, proof), peak_memory) = measure_peak_memory(|| prove(constraint_system, args, witness, backend)); diff --git a/plonky2/src/bin/measure.rs b/plonky2/src/bin/measure.rs index f02cf01..dfc7f55 100644 --- a/plonky2/src/bin/measure.rs +++ b/plonky2/src/bin/measure.rs @@ -35,7 +35,7 @@ fn benchmark_sha2(num_bytes: usize) -> SubMetrics { "Common data size: {}B, Prover data size: {}B", common_data_size, prover_data_size ); - metrics.preprocessing_size = prover_data_size + common_data_size; // correct? + metrics.preprocessing_size = prover_data_size; let (proof, peak_memory) = measure_peak_memory(|| prove(&data.prover_data(), pw)); metrics.proving_peak_memory = peak_memory; diff --git a/plonky3-powdr/src/bin/measure.rs b/plonky3-powdr/src/bin/measure.rs index 4832841..d3d5385 100644 --- a/plonky3-powdr/src/bin/measure.rs +++ b/plonky3-powdr/src/bin/measure.rs @@ -23,7 +23,7 @@ fn benchmark_sha2(num_bytes: usize) -> SubMetrics { // Load the proving key and constants from the files. let pk_bytes = std::fs::read("powdr-target/pkey.bin").expect("Unable to read file"); let constants_bytes = std::fs::read("powdr-target/constants.bin").expect("Unable to read file"); - metrics.preprocessing_size = pk_bytes.len() + constants_bytes.len(); // correct? + metrics.preprocessing_size = pk_bytes.len() + constants_bytes.len(); let (_, peak_memory) = measure_peak_memory(|| prove(&mut pipeline)); metrics.proving_peak_memory = peak_memory; diff --git a/plonky3-sp1/script/src/bin/measure.rs b/plonky3-sp1/script/src/bin/measure.rs index f618eb2..7d6d302 100644 --- a/plonky3-sp1/script/src/bin/measure.rs +++ b/plonky3-sp1/script/src/bin/measure.rs @@ -35,7 +35,7 @@ fn benchmark_sha2(input_num_bytes: usize) -> SubMetrics { peak_memory as f32 / (1024.0 * 1024.0 * 1024.0) ); - metrics.preprocessing_size = pk_bytes.len() + SHA_ELF.len(); // correct? + metrics.preprocessing_size = pk_bytes.len() + SHA_ELF.len(); // Generate the proof let (_, peak_memory) = measure_peak_memory(|| { From 92ff67b93f5670908bb1b860b518840fc11fbecf Mon Sep 17 00:00:00 2001 From: guorong009 Date: Wed, 6 Aug 2025 16:57:39 +0800 Subject: [PATCH 15/16] fix: roll back change in plonky2 preprocessing_size computation --- plonky2/src/bin/measure.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plonky2/src/bin/measure.rs b/plonky2/src/bin/measure.rs index dfc7f55..49432c8 100644 --- a/plonky2/src/bin/measure.rs +++ b/plonky2/src/bin/measure.rs @@ -35,7 +35,7 @@ fn benchmark_sha2(num_bytes: usize) -> SubMetrics { "Common data size: {}B, Prover data size: {}B", common_data_size, prover_data_size ); - metrics.preprocessing_size = prover_data_size; + metrics.preprocessing_size = prover_data_size + common_data_size; let (proof, peak_memory) = measure_peak_memory(|| prove(&data.prover_data(), pw)); metrics.proving_peak_memory = peak_memory; From eef50ab38b4db8d763b6f0120d49677971b6becf Mon Sep 17 00:00:00 2001 From: guorong009 Date: Wed, 6 Aug 2025 17:52:39 +0800 Subject: [PATCH 16/16] fix: add PIL file size to "preprocessing_size" in plonky3-powdr --- plonky3-powdr/src/bin/measure.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plonky3-powdr/src/bin/measure.rs b/plonky3-powdr/src/bin/measure.rs index d3d5385..ac2cf46 100644 --- a/plonky3-powdr/src/bin/measure.rs +++ b/plonky3-powdr/src/bin/measure.rs @@ -23,7 +23,8 @@ fn benchmark_sha2(num_bytes: usize) -> SubMetrics { // Load the proving key and constants from the files. let pk_bytes = std::fs::read("powdr-target/pkey.bin").expect("Unable to read file"); let constants_bytes = std::fs::read("powdr-target/constants.bin").expect("Unable to read file"); - metrics.preprocessing_size = pk_bytes.len() + constants_bytes.len(); + let pil_bytes = std::fs::read("powdr-target/guest.pil").expect("Unable to read file"); + metrics.preprocessing_size = pk_bytes.len() + constants_bytes.len() + pil_bytes.len(); let (_, peak_memory) = measure_peak_memory(|| prove(&mut pipeline)); metrics.proving_peak_memory = peak_memory;