|
3 | 3 |
|
4 | 4 | use criterion::{Criterion, criterion_group, criterion_main}; |
5 | 5 | use frost_secp256k1::VerifyingKey; |
6 | | -use rand::{Rng, RngCore, seq::SliceRandom as _}; |
| 6 | +use rand::{Rng, seq::SliceRandom as _}; |
7 | 7 | use rand_core::SeedableRng; |
8 | 8 |
|
9 | 9 | mod bench_utils; |
10 | 10 | use crate::bench_utils::{ |
11 | 11 | MAX_MALICIOUS, PreparedOutputs, RECONSTRUCTION_LOWER_BOUND, SAMPLE_SIZE, |
12 | 12 | analyze_received_sizes, ot_ecdsa_prepare_presign, ot_ecdsa_prepare_sign, |
13 | | - ot_ecdsa_prepare_triples, |
| 13 | + ot_ecdsa_prepare_triples, participant_rng, |
14 | 14 | }; |
15 | 15 |
|
16 | 16 | use threshold_signatures::{ |
@@ -58,7 +58,10 @@ fn bench_triples(c: &mut Criterion) { |
58 | 58 | |b| { |
59 | 59 | b.iter_batched( |
60 | 60 | || prepare_simulated_triples(&setup), |
61 | | - |preps| run_simulated_protocol(preps.participant, preps.protocol, preps.simulator), |
| 61 | + |preps| { |
| 62 | + run_simulated_protocol(preps.participant, preps.protocol, preps.simulator) |
| 63 | + .expect("simulated replay should complete") |
| 64 | + }, |
62 | 65 | criterion::BatchSize::SmallInput, |
63 | 66 | ); |
64 | 67 | }, |
@@ -86,7 +89,10 @@ fn bench_presign(c: &mut Criterion) { |
86 | 89 | |b| { |
87 | 90 | b.iter_batched( |
88 | 91 | || prepare_simulated_presign(&setup), |
89 | | - |preps| run_simulated_protocol(preps.participant, preps.protocol, preps.simulator), |
| 92 | + |preps| { |
| 93 | + run_simulated_protocol(preps.participant, preps.protocol, preps.simulator) |
| 94 | + .expect("simulated replay should complete") |
| 95 | + }, |
90 | 96 | criterion::BatchSize::SmallInput, |
91 | 97 | ); |
92 | 98 | }, |
@@ -117,7 +123,10 @@ fn bench_sign(c: &mut Criterion) { |
117 | 123 | |b| { |
118 | 124 | b.iter_batched( |
119 | 125 | || prepare_simulated_sign(&setup, *RECONSTRUCTION_LOWER_BOUND), |
120 | | - |preps| run_simulated_protocol(preps.participant, preps.protocol, preps.simulator), |
| 126 | + |preps| { |
| 127 | + run_simulated_protocol(preps.participant, preps.protocol, preps.simulator) |
| 128 | + .expect("simulated replay should complete") |
| 129 | + }, |
121 | 130 | criterion::BatchSize::SmallInput, |
122 | 131 | ); |
123 | 132 | }, |
@@ -149,15 +158,8 @@ fn setup_triples_snapshot(participant_num: usize) -> TriplesSetup { |
149 | 158 | .choose(&mut rng) |
150 | 159 | .expect("participant list is not empty"); |
151 | 160 |
|
152 | | - // recreate rng using by real_participant to generate triples |
153 | | - let mut rng_copy = MockCryptoRng::seed_from_u64(42); |
154 | | - for p in &preps.participants { |
155 | | - if *p == real_participant { |
156 | | - break; |
157 | | - } |
158 | | - rng_copy.next_u64(); |
159 | | - } |
160 | | - let real_participant_rng = MockCryptoRng::seed_from_u64(rng_copy.next_u64()); |
| 161 | + // rebuild the exact rng the real participant used during snapshot capture |
| 162 | + let real_participant_rng = participant_rng(&preps.seeds, real_participant); |
161 | 163 |
|
162 | 164 | let cached_simulator = Simulator::new(real_participant, &protocol_snapshot) |
163 | 165 | .expect("Simulator should not be empty"); |
|
0 commit comments