Skip to content

Commit 1faa085

Browse files
Cloning given to rng
1 parent 358354d commit 1faa085

File tree

3 files changed

+56
-56
lines changed

3 files changed

+56
-56
lines changed

benches/advanced_ot_based_ecdsa.rs

Lines changed: 52 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -41,24 +41,24 @@ fn participants_num() -> usize {
4141
*crate::MAX_MALICIOUS + 1
4242
}
4343

44-
// /// Benches the triples protocol
45-
// fn bench_triples(c: &mut Criterion) {
46-
// let num = participants_num();
47-
// let max_malicious = *MAX_MALICIOUS;
48-
// let mut group = c.benchmark_group("triples");
49-
// group.measurement_time(std::time::Duration::from_secs(200));
44+
/// Benches the triples protocol
45+
fn bench_triples(c: &mut Criterion) {
46+
let num = participants_num();
47+
let max_malicious = *MAX_MALICIOUS;
48+
let mut group = c.benchmark_group("triples");
49+
group.measurement_time(std::time::Duration::from_secs(200));
5050

51-
// group.bench_function(
52-
// format!("ot_ecdsa_triples_naive_MAX_MALICIOUS_{max_malicious}_PARTICIPANTS_{num}"),
53-
// |b| {
54-
// b.iter_batched(
55-
// || prepare_simulated_triples(participants_num()),
56-
// |(rparticipant, rprot, sprot)| run_simulated_protocol(rparticipant, rprot, sprot),
57-
// criterion::BatchSize::SmallInput,
58-
// );
59-
// },
60-
// );
61-
// }
51+
group.bench_function(
52+
format!("ot_ecdsa_triples_naive_MAX_MALICIOUS_{max_malicious}_PARTICIPANTS_{num}"),
53+
|b| {
54+
b.iter_batched(
55+
|| prepare_simulated_triples(participants_num()),
56+
|(rparticipant, rprot, sprot)| run_simulated_protocol(rparticipant, rprot, sprot),
57+
criterion::BatchSize::SmallInput,
58+
);
59+
},
60+
);
61+
}
6262

6363
/// Benches the presigning protocol
6464
fn bench_presign(c: &mut Criterion) {
@@ -126,39 +126,39 @@ fn prepare_triples(participant_num: usize) -> PreparedTriples {
126126
protocols
127127
}
128128

129-
// type PreparedSimulatedTriples = (
130-
// Participant,
131-
// Box<dyn Protocol<Output = Vec<(TripleShare, TriplePub)>>>,
132-
// Simulator,
133-
// );
134-
// fn prepare_simulated_triples(participant_num: usize) -> PreparedSimulatedTriples {
135-
// let mut protocols: Vec<(_, Box<dyn Protocol<Output = _>>)> =
136-
// Vec::with_capacity(participant_num);
137-
// let participants = generate_participants_with_random_ids(participant_num, &mut OsRng);
138-
139-
// let rngs = create_multiple_rngs(&participants);
140-
141-
// for (i, p) in participants.iter().enumerate() {
142-
// let protocol = generate_triple_many::<2>(&participants, p, threshold(), rngs[i].clone())
143-
// .expect("Triple generation should succeed");
144-
// protocols.push((p, Box::new(protocol)));
145-
// }
146-
// let (_, protocolsnapshot) = run_protocol_with_snapshots(protocols)
147-
// .expect("Running protocol with snapshot should not have issues");
148-
149-
// // now preparing the simulator
150-
// // choose the real_participant at random
151-
// let index_real_participant = OsRng.gen_range(0..participant_num);
152-
// let real_participant = participants[index_real_participant];
153-
// let simulated_protocol = Simulator::new(real_participant, protocolsnapshot)
154-
// .expect("Simulator should not be empty");
155-
// let real_protocol =
156-
// generate_triple_many::<2>(&participants, real_participant, threshold(), rngs[index_real_participant].clone())
157-
// .map(|prot| Box::new(prot) as Box<dyn Protocol<Output = Vec<(TripleShare, TriplePub)>>>)
158-
// .expect("The rerun of the triple generation should not but raising error");
159-
160-
// (real_participant, real_protocol, simulated_protocol)
161-
// }
129+
type PreparedSimulatedTriples = (
130+
Participant,
131+
Box<dyn Protocol<Output = Vec<(TripleShare, TriplePub)>>>,
132+
Simulator,
133+
);
134+
fn prepare_simulated_triples(participant_num: usize) -> PreparedSimulatedTriples {
135+
let mut protocols: Vec<(_, Box<dyn Protocol<Output = _>>)> =
136+
Vec::with_capacity(participant_num);
137+
let participants = generate_participants_with_random_ids(participant_num, &mut OsRng);
138+
139+
let rngs = create_multiple_rngs(&participants);
140+
141+
for (i, p) in participants.iter().enumerate() {
142+
let protocol = generate_triple_many::<2>(&participants, *p, threshold(), rngs[i].clone())
143+
.expect("Triple generation should succeed");
144+
protocols.push((*p, Box::new(protocol)));
145+
}
146+
let (_, protocolsnapshot) = run_protocol_with_snapshots(protocols)
147+
.expect("Running protocol with snapshot should not have issues");
148+
149+
// now preparing the simulator
150+
// choose the real_participant at random
151+
let index_real_participant = OsRng.gen_range(0..participant_num);
152+
let real_participant = participants[index_real_participant];
153+
let simulated_protocol = Simulator::new(real_participant, protocolsnapshot)
154+
.expect("Simulator should not be empty");
155+
let real_protocol =
156+
generate_triple_many::<2>(&participants, real_participant, threshold(), rngs[index_real_participant].clone())
157+
.map(|prot| Box::new(prot) as Box<dyn Protocol<Output = Vec<(TripleShare, TriplePub)>>>)
158+
.expect("The rerun of the triple generation should not but raising error");
159+
160+
(real_participant, real_protocol, simulated_protocol)
161+
}
162162

163163
// type PreparedPresig = (
164164
// Vec<(Participant, Box<dyn Protocol<Output = PresignOutput>>)>,
@@ -303,7 +303,7 @@ fn split_even_odd<T: Clone>(v: Vec<T>) -> (Vec<T>, Vec<T>) {
303303
(even, odd)
304304
}
305305

306-
criterion_group!(benches, bench_presign);
307-
// criterion_group!(benches, bench_triples, bench_presign);
306+
// criterion_group!(benches, bench_presign);
307+
criterion_group!(benches, bench_triples, bench_presign);
308308
// criterion_group!(benches, bench_triples, bench_presign, bench_sign);
309309
criterion::criterion_main!(benches);

src/ecdsa/ot_based_ecdsa/triples/generation.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ async fn do_generation_many<const N: usize>(
504504
participants: ParticipantList,
505505
me: Participant,
506506
threshold: usize,
507-
mut rng: impl CryptoRngCore + Send + Copy + 'static,
507+
mut rng: impl CryptoRngCore + Clone + Send + 'static,
508508
) -> Result<TripleGenerationOutputMany, ProtocolError> {
509509
assert!(N > 0);
510510

@@ -1104,7 +1104,7 @@ pub fn generate_triple_many<const N: usize>(
11041104
participants: &[Participant],
11051105
me: Participant,
11061106
threshold: usize,
1107-
rng: impl CryptoRngCore + Send + Copy + 'static,
1107+
rng: impl CryptoRngCore + Clone + Send + 'static,
11081108
) -> Result<impl Protocol<Output = TripleGenerationOutputMany>, InitializationError> {
11091109
if participants.len() < 2 {
11101110
return Err(InitializationError::NotEnoughParticipants {

src/ecdsa/ot_based_ecdsa/triples/multiplication.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ pub async fn multiplication_many<const N: usize>(
139139
me: Participant,
140140
av_iv: Vec<Scalar>,
141141
bv_iv: Vec<Scalar>,
142-
rng: impl CryptoRngCore + Send + Copy + 'static,
142+
rng: impl CryptoRngCore + Clone + Send + 'static,
143143
) -> Result<Vec<Scalar>, ProtocolError> {
144144
if N == 0 {
145145
return Err(ProtocolError::AssertionFailed(
@@ -159,7 +159,7 @@ pub async fn multiplication_many<const N: usize>(
159159
let fut = {
160160
let chan = comms.private_channel(me, p).child(i as u64);
161161
let order_key_other = hash(&(i, p))?;
162-
162+
let rng = rng.clone();
163163
async move {
164164
// Use a deterministic but random comparison function to decide who
165165
// is the sender and who is the receiver. This allows the batched

0 commit comments

Comments
 (0)