-
Notifications
You must be signed in to change notification settings - Fork 34
Hash-based signatures rust benchmarks #935
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
d8a8edb
initial dump
lockedloop e074e8c
fix CI
lockedloop 692eac8
Merge remote-tracking branch 'origin/main' into danilo/hash_based_sig…
lockedloop 4707eeb
limit warmup and measurement times
lockedloop e3b701c
move suffix extraction to the platform_diagnostics
lockedloop 6cc85be
allow for higher trees
lockedloop 563150c
make the hashsign benchmark faster
lockedloop 50b3586
add hashsign snapshot
lockedloop bc619fc
Merge remote-tracking branch 'origin/main' into danilo/hash_based_sig…
lockedloop 8763755
sneaking in benchmark speedups
lockedloop 84e0458
Merge remote-tracking branch 'origin/main' into danilo/hashsign-bench…
lockedloop b9f0c04
Merge branch 'danilo/hashsign-benchmarks' into danilo/hash_based_sig_…
lockedloop 0fd26fd
switch to bench_function in all benchmarks
lockedloop File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,152 @@ | ||
| use std::env; | ||
|
|
||
| use binius_examples::{ | ||
| ExampleCircuit, | ||
| circuits::hashsign::{HashBasedSigExample, Instance, Params}, | ||
| setup, | ||
| }; | ||
| use binius_frontend::compiler::CircuitBuilder; | ||
| use binius_utils::platform_diagnostics::PlatformDiagnostics; | ||
| use binius_verifier::{ | ||
| config::StdChallenger, | ||
| transcript::{ProverTranscript, VerifierTranscript}, | ||
| }; | ||
| use criterion::{BenchmarkId, Criterion, Throughput, criterion_group, criterion_main}; | ||
|
|
||
| fn bench_hashsign(c: &mut Criterion) { | ||
| // Parse parameters from environment variables or use defaults | ||
| let num_validators = env::var("HASHSIGN_VALIDATORS") | ||
| .ok() | ||
| .and_then(|s| s.parse::<usize>().ok()) | ||
| .unwrap_or(4); | ||
|
|
||
| let tree_height = env::var("HASHSIGN_TREE_HEIGHT") | ||
| .ok() | ||
| .and_then(|s| s.parse::<usize>().ok()) | ||
| .unwrap_or(13); | ||
|
|
||
| let spec = env::var("HASHSIGN_SPEC") | ||
| .ok() | ||
| .and_then(|s| s.parse::<u8>().ok()) | ||
| .unwrap_or(2); | ||
|
|
||
| // Gather and print comprehensive platform diagnostics | ||
| let diagnostics = PlatformDiagnostics::gather(); | ||
| diagnostics.print(); | ||
|
|
||
| // Print benchmark-specific parameters | ||
| println!("\nHashsign Benchmark Parameters:"); | ||
| println!(" Validators: {}", num_validators); | ||
| println!(" Tree height: {} (2^{} = {} slots)", tree_height, tree_height, 1 << tree_height); | ||
| println!(" Winternitz spec: {}", spec); | ||
| println!(" Message size: 32 bytes (fixed)"); | ||
| println!("=========================================\n"); | ||
|
|
||
| let params = Params { | ||
| num_validators, | ||
| tree_height, | ||
| spec, | ||
| }; | ||
| let instance = Instance {}; | ||
|
|
||
| // Setup phase - do this once outside the benchmark loop | ||
| let mut builder = CircuitBuilder::new(); | ||
| let example = HashBasedSigExample::build(params.clone(), &mut builder).unwrap(); | ||
| let circuit = builder.build(); | ||
| let cs = circuit.constraint_system().clone(); | ||
| let (verifier, prover) = setup(cs, 1).unwrap(); | ||
|
|
||
| // Create a witness once for proof size measurement | ||
| let mut filler = circuit.new_witness_filler(); | ||
| example | ||
| .populate_witness(instance.clone(), &mut filler) | ||
| .unwrap(); | ||
| circuit.populate_wire_witness(&mut filler).unwrap(); | ||
| let witness = filler.into_value_vec(); | ||
|
|
||
| let feature_suffix = diagnostics.get_feature_suffix(); | ||
| let bench_name = | ||
| format!("validators_{}_tree_{}_{}", num_validators, tree_height, feature_suffix); | ||
|
|
||
| // Measure witness generation time | ||
| { | ||
| let mut group = c.benchmark_group("hashsign_witness_generation"); | ||
| group.throughput(Throughput::Elements(num_validators as u64)); | ||
| group.warm_up_time(std::time::Duration::from_millis(100)); | ||
| group.measurement_time(std::time::Duration::from_secs(10)); | ||
| group.sample_size(10); | ||
|
|
||
| group.bench_function(BenchmarkId::from_parameter(&bench_name), |b| { | ||
| b.iter(|| { | ||
| let mut filler = circuit.new_witness_filler(); | ||
| example | ||
| .populate_witness(instance.clone(), &mut filler) | ||
| .unwrap(); | ||
| circuit.populate_wire_witness(&mut filler).unwrap(); | ||
| filler.into_value_vec() | ||
| }) | ||
| }); | ||
|
|
||
| group.finish(); | ||
| } | ||
|
|
||
| // Measure proof generation time | ||
| { | ||
| let mut group = c.benchmark_group("hashsign_proof_generation"); | ||
| group.throughput(Throughput::Elements(num_validators as u64)); | ||
| group.warm_up_time(std::time::Duration::from_millis(100)); | ||
| group.measurement_time(std::time::Duration::from_secs(10)); | ||
| group.sample_size(10); | ||
|
|
||
| group.bench_function(BenchmarkId::from_parameter(&bench_name), |b| { | ||
| b.iter(|| { | ||
| let mut prover_transcript = ProverTranscript::new(StdChallenger::default()); | ||
| prover | ||
| .prove(witness.clone(), &mut prover_transcript) | ||
| .unwrap(); | ||
| prover_transcript | ||
| }) | ||
| }); | ||
|
|
||
| group.finish(); | ||
| } | ||
|
|
||
| // Generate a proof for verification benchmarking and size measurement | ||
| let mut prover_transcript = ProverTranscript::new(StdChallenger::default()); | ||
| prover | ||
| .prove(witness.clone(), &mut prover_transcript) | ||
| .unwrap(); | ||
| let proof_bytes = prover_transcript.finalize(); | ||
| let proof_size = proof_bytes.len(); | ||
|
|
||
| // Measure proof verification time | ||
| { | ||
| let mut group = c.benchmark_group("hashsign_proof_verification"); | ||
| group.throughput(Throughput::Elements(num_validators as u64)); | ||
| group.warm_up_time(std::time::Duration::from_millis(100)); | ||
| group.measurement_time(std::time::Duration::from_secs(10)); | ||
| group.sample_size(10); | ||
|
|
||
| group.bench_function(BenchmarkId::from_parameter(&bench_name), |b| { | ||
| b.iter(|| { | ||
| let mut verifier_transcript = | ||
| VerifierTranscript::new(StdChallenger::default(), proof_bytes.clone()); | ||
| verifier | ||
| .verify(witness.public(), &mut verifier_transcript) | ||
| .unwrap(); | ||
| verifier_transcript.finalize().unwrap() | ||
| }) | ||
| }); | ||
|
|
||
| group.finish(); | ||
| } | ||
|
|
||
| // Report proof size | ||
| println!( | ||
| "\nHashsign proof size for {} validators (tree height {}): {} bytes", | ||
| num_validators, tree_height, proof_size | ||
| ); | ||
| } | ||
|
|
||
| criterion_group!(hashsign, bench_hashsign); | ||
| criterion_main!(hashsign); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Pseudo-Random Testing rule requires benchmarks to use
rand::rng()instead of seeded RNGs.StdChallenger::default()likely uses a seeded RNG rather than thread RNG. Replace withrand::rng()for proper randomness in benchmarks, reservingStdRng::seed_from_u64for reproducible tests only.Spotted by Diamond (based on custom rule: Monbijou Testing Patterns)

Is this helpful? React 👍 or 👎 to let us know.