-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathethsign.rs
More file actions
143 lines (122 loc) · 4.36 KB
/
ethsign.rs
File metadata and controls
143 lines (122 loc) · 4.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
use std::env;
use binius_examples::{
ExampleCircuit,
circuits::ethsign::{EthSignExample, 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_ethsign_signatures(c: &mut Criterion) {
// Parse parameters from environment variables or use defaults
let n_signatures = env::var("ETHSIGN_SIGNATURES")
.ok()
.and_then(|s| s.parse::<usize>().ok())
.unwrap_or(1);
let max_msg_len_bytes = env::var("ETHSIGN_MSG_BYTES")
.ok()
.and_then(|s| s.parse::<u16>().ok())
.unwrap_or(67);
// Gather and print comprehensive platform diagnostics
let diagnostics = PlatformDiagnostics::gather();
diagnostics.print();
// Print benchmark-specific parameters
println!("\nEthSign Benchmark Parameters:");
println!(" Signatures: {}", n_signatures);
println!(" Max message length: {} bytes", max_msg_len_bytes);
println!("=========================================\n");
let params = Params {
n_signatures,
max_msg_len_bytes,
};
let instance = Instance {};
// Setup phase - do this once outside the benchmark loop
let mut builder = CircuitBuilder::new();
let example = EthSignExample::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!("sig_{}_msg_{}_{}", n_signatures, max_msg_len_bytes, feature_suffix);
// Measure witness generation time
{
let mut group = c.benchmark_group("ethsign_witness_generation");
group.throughput(Throughput::Elements(n_signatures as u64));
group.warm_up_time(std::time::Duration::from_secs(2));
group.measurement_time(std::time::Duration::from_secs(120));
group.sample_size(50);
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("ethsign_proof_generation");
group.throughput(Throughput::Elements(n_signatures as u64));
group.warm_up_time(std::time::Duration::from_secs(2));
group.measurement_time(std::time::Duration::from_secs(120));
group.sample_size(50);
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("ethsign_proof_verification");
group.throughput(Throughput::Elements(n_signatures as u64));
group.warm_up_time(std::time::Duration::from_secs(2));
group.measurement_time(std::time::Duration::from_secs(120));
group.sample_size(50);
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!(
"\nEthSign proof size for {} signatures, {} max bytes: {} bytes",
n_signatures, max_msg_len_bytes, proof_size
);
}
criterion_group!(ethsign, bench_ethsign_signatures);
criterion_main!(ethsign);