From a6442a95cb8ecf80bf0b94c78546d56016cf2e73 Mon Sep 17 00:00:00 2001 From: SimonRastikian <43679791+SimonRastikian@users.noreply.github.com> Date: Thu, 26 Mar 2026 09:18:48 +0100 Subject: [PATCH 1/7] DKG benchmarks implementations --- crates/threshold-signatures/Cargo.toml | 5 + .../benches/advanced_dkg.rs | 150 ++++++++++++++++++ .../benches/bench_utils.rs | 37 +++++ 3 files changed, 192 insertions(+) create mode 100644 crates/threshold-signatures/benches/advanced_dkg.rs diff --git a/crates/threshold-signatures/Cargo.toml b/crates/threshold-signatures/Cargo.toml index 4ea405681..e89ba8c31 100644 --- a/crates/threshold-signatures/Cargo.toml +++ b/crates/threshold-signatures/Cargo.toml @@ -103,6 +103,11 @@ name = "ckd" harness = false required-features = ["test-utils"] +[[bench]] +name = "advanced_dkg" +harness = false +required-features = ["test-utils"] + [lints.clippy] mod_module_files = "deny" # We might revisit these exceptions in the future diff --git a/crates/threshold-signatures/benches/advanced_dkg.rs b/crates/threshold-signatures/benches/advanced_dkg.rs new file mode 100644 index 000000000..d87def372 --- /dev/null +++ b/crates/threshold-signatures/benches/advanced_dkg.rs @@ -0,0 +1,150 @@ +#![allow(clippy::indexing_slicing)] + +use criterion::{criterion_group, criterion_main, Criterion}; +use rand::seq::SliceRandom as _; +use rand_core::SeedableRng; + +mod bench_utils; +use crate::bench_utils::{ + analyze_received_sizes, prepare_dkg, PreparedOutputs, MAX_MALICIOUS, SAMPLE_SIZE, +}; + +use threshold_signatures::{ + confidential_key_derivation::ciphersuite::BLS12381SHA256, + frost_ed25519::Ed25519Sha512, + frost_secp256k1::Secp256K1Sha256, + keygen, Ciphersuite, Element, KeygenOutput, Scalar, + protocol::Protocol, + test_utils::{ + run_protocol_and_take_snapshots, run_simulated_protocol, MockCryptoRng, Simulator, + }, + ReconstructionLowerBound, +}; + +fn threshold() -> ReconstructionLowerBound { + ReconstructionLowerBound::from(*MAX_MALICIOUS + 1) +} + +fn participants_num() -> usize { + *MAX_MALICIOUS + 1 +} + +type PreparedSimulatedDkg = PreparedOutputs>; + +/// Benches the DKG protocol for Secp256k1 +fn bench_dkg_secp256k1(c: &mut Criterion) { + let num = participants_num(); + let max_malicious = *MAX_MALICIOUS; + let mut sizes = Vec::with_capacity(*SAMPLE_SIZE); + + let mut group = c.benchmark_group("dkg"); + group.sample_size(*SAMPLE_SIZE); + group.bench_function( + format!("dkg_secp256k1_MAX_MALICIOUS_{max_malicious}_PARTICIPANTS_{num}"), + |b| { + b.iter_batched( + || { + let preps = prepare_simulated_dkg::(threshold()); + sizes.push(preps.simulator.get_view_size()); + preps + }, + |preps| run_simulated_protocol(preps.participant, preps.protocol, preps.simulator), + criterion::BatchSize::SmallInput, + ); + }, + ); + analyze_received_sizes(&sizes, true); +} + +/// Benches the DKG protocol for Ed25519 +fn bench_dkg_ed25519(c: &mut Criterion) { + let num = participants_num(); + let max_malicious = *MAX_MALICIOUS; + let mut sizes = Vec::with_capacity(*SAMPLE_SIZE); + + let mut group = c.benchmark_group("dkg"); + group.sample_size(*SAMPLE_SIZE); + group.bench_function( + format!("dkg_ed25519_MAX_MALICIOUS_{max_malicious}_PARTICIPANTS_{num}"), + |b| { + b.iter_batched( + || { + let preps = prepare_simulated_dkg::(threshold()); + sizes.push(preps.simulator.get_view_size()); + preps + }, + |preps| run_simulated_protocol(preps.participant, preps.protocol, preps.simulator), + criterion::BatchSize::SmallInput, + ); + }, + ); + analyze_received_sizes(&sizes, true); +} + +/// Benches the DKG protocol for BLS12-381 +fn bench_dkg_bls12381(c: &mut Criterion) { + let num = participants_num(); + let max_malicious = *MAX_MALICIOUS; + let mut sizes = Vec::with_capacity(*SAMPLE_SIZE); + + let mut group = c.benchmark_group("dkg"); + group.sample_size(*SAMPLE_SIZE); + group.bench_function( + format!("dkg_bls12381_MAX_MALICIOUS_{max_malicious}_PARTICIPANTS_{num}"), + |b| { + b.iter_batched( + || { + let preps = prepare_simulated_dkg::(threshold()); + sizes.push(preps.simulator.get_view_size()); + preps + }, + |preps| run_simulated_protocol(preps.participant, preps.protocol, preps.simulator), + criterion::BatchSize::SmallInput, + ); + }, + ); + analyze_received_sizes(&sizes, true); +} + +criterion_group!(benches, bench_dkg_secp256k1, bench_dkg_ed25519, bench_dkg_bls12381); +criterion_main!(benches); + +/****************************** Helpers ******************************/ +/// Used to simulate DKG keygen for benchmarking +fn prepare_simulated_dkg( + threshold: ReconstructionLowerBound, +) -> PreparedSimulatedDkg +where + Element: Send, + Scalar: Send, +{ + let mut rng = MockCryptoRng::seed_from_u64(42); + let preps = prepare_dkg::(participants_num(), threshold, &mut rng); + let (_, protocolsnapshot) = run_protocol_and_take_snapshots(preps.protocols) + .expect("Running protocol with snapshot should not have issues"); + + // choose the real_participant at random + let real_participant = *preps + .participants + .choose(&mut rng) + .expect("participant list is not empty"); + + let real_protocol = keygen::( + &preps.participants, + real_participant, + threshold, + rng, + ) + .map(|p| Box::new(p) as Box>>) + .expect("Keygen should succeed"); + + // now preparing the simulator + let simulated_protocol = + Simulator::new(real_participant, protocolsnapshot).expect("Simulator should not be empty"); + + PreparedSimulatedDkg { + participant: real_participant, + protocol: real_protocol, + simulator: simulated_protocol, + } +} \ No newline at end of file diff --git a/crates/threshold-signatures/benches/bench_utils.rs b/crates/threshold-signatures/benches/bench_utils.rs index 0ddcbc84e..68a0df1fb 100644 --- a/crates/threshold-signatures/benches/bench_utils.rs +++ b/crates/threshold-signatures/benches/bench_utils.rs @@ -8,6 +8,7 @@ use rand_core::{CryptoRngCore, SeedableRng}; use std::{env, sync::LazyLock}; use threshold_signatures::{ + keygen, Ciphersuite, KeygenOutput, confidential_key_derivation::{ self as ckd, ciphersuite::{Field as _, Group as _}, @@ -593,3 +594,39 @@ pub struct PreparedCkdPackage { pub app_id: ckd::AppId, pub app_pk: ckd::ElementG1, } + +/********************* DKG *********************/ +/// Used to prepare DKG keygen protocols for benchmarking +pub fn prepare_dkg( + num_participants: usize, + threshold: ReconstructionLowerBound, + rng: &mut R, +) -> PreparedDkgPackage +where + threshold_signatures::Element: Send, + threshold_signatures::Scalar: Send, +{ + let participants = generate_participants_with_random_ids(num_participants, rng); + let mut protocols: Vec<( + Participant, + Box>>, + )> = Vec::with_capacity(num_participants); + + for p in &participants { + let rng_p = MockCryptoRng::seed_from_u64(rng.next_u64()); + let protocol = keygen::(&participants, *p, threshold, rng_p) + .map(|p| Box::new(p) as Box>>) + .expect("Keygen should succeed"); + protocols.push((*p, protocol)); + } + + PreparedDkgPackage { + protocols, + participants, + } +} + +pub struct PreparedDkgPackage { + pub protocols: Vec<(Participant, Box>>)>, + pub participants: Vec, +} From 52b0f4fe60b231065b85a299fc1b306ec546aa05 Mon Sep 17 00:00:00 2001 From: SimonRastikian <43679791+SimonRastikian@users.noreply.github.com> Date: Thu, 26 Mar 2026 13:06:11 +0100 Subject: [PATCH 2/7] cargo fmt --- .../benches/advanced_dkg.rs | 24 +++++++++---------- .../benches/bench_utils.rs | 10 ++++---- .../docs/benches/{model.md => results.md} | 0 3 files changed, 16 insertions(+), 18 deletions(-) rename crates/threshold-signatures/docs/benches/{model.md => results.md} (100%) diff --git a/crates/threshold-signatures/benches/advanced_dkg.rs b/crates/threshold-signatures/benches/advanced_dkg.rs index d87def372..a6a3b1ee3 100644 --- a/crates/threshold-signatures/benches/advanced_dkg.rs +++ b/crates/threshold-signatures/benches/advanced_dkg.rs @@ -13,12 +13,12 @@ use threshold_signatures::{ confidential_key_derivation::ciphersuite::BLS12381SHA256, frost_ed25519::Ed25519Sha512, frost_secp256k1::Secp256K1Sha256, - keygen, Ciphersuite, Element, KeygenOutput, Scalar, + keygen, protocol::Protocol, test_utils::{ run_protocol_and_take_snapshots, run_simulated_protocol, MockCryptoRng, Simulator, }, - ReconstructionLowerBound, + Ciphersuite, Element, KeygenOutput, ReconstructionLowerBound, Scalar, }; fn threshold() -> ReconstructionLowerBound { @@ -106,7 +106,12 @@ fn bench_dkg_bls12381(c: &mut Criterion) { analyze_received_sizes(&sizes, true); } -criterion_group!(benches, bench_dkg_secp256k1, bench_dkg_ed25519, bench_dkg_bls12381); +criterion_group!( + benches, + bench_dkg_secp256k1, + bench_dkg_ed25519, + bench_dkg_bls12381 +); criterion_main!(benches); /****************************** Helpers ******************************/ @@ -129,14 +134,9 @@ where .choose(&mut rng) .expect("participant list is not empty"); - let real_protocol = keygen::( - &preps.participants, - real_participant, - threshold, - rng, - ) - .map(|p| Box::new(p) as Box>>) - .expect("Keygen should succeed"); + let real_protocol = keygen::(&preps.participants, real_participant, threshold, rng) + .map(|p| Box::new(p) as Box>>) + .expect("Keygen should succeed"); // now preparing the simulator let simulated_protocol = @@ -147,4 +147,4 @@ where protocol: real_protocol, simulator: simulated_protocol, } -} \ No newline at end of file +} diff --git a/crates/threshold-signatures/benches/bench_utils.rs b/crates/threshold-signatures/benches/bench_utils.rs index 68a0df1fb..4abde0ea1 100644 --- a/crates/threshold-signatures/benches/bench_utils.rs +++ b/crates/threshold-signatures/benches/bench_utils.rs @@ -8,7 +8,6 @@ use rand_core::{CryptoRngCore, SeedableRng}; use std::{env, sync::LazyLock}; use threshold_signatures::{ - keygen, Ciphersuite, KeygenOutput, confidential_key_derivation::{ self as ckd, ciphersuite::{Field as _, Group as _}, @@ -22,13 +21,14 @@ use threshold_signatures::{ robust_ecdsa, Scalar, }, frost::eddsa, + keygen, participants::Participant, protocol::Protocol, test_utils::{ ecdsa_generate_rerandpresig_args, generate_participants_with_random_ids, run_keygen, MockCryptoRng, Simulator, }, - MaxMalicious, ReconstructionLowerBound, + Ciphersuite, KeygenOutput, MaxMalicious, ReconstructionLowerBound, }; // fix malicious number of participants @@ -607,10 +607,8 @@ where threshold_signatures::Scalar: Send, { let participants = generate_participants_with_random_ids(num_participants, rng); - let mut protocols: Vec<( - Participant, - Box>>, - )> = Vec::with_capacity(num_participants); + let mut protocols: Vec<(Participant, Box>>)> = + Vec::with_capacity(num_participants); for p in &participants { let rng_p = MockCryptoRng::seed_from_u64(rng.next_u64()); diff --git a/crates/threshold-signatures/docs/benches/model.md b/crates/threshold-signatures/docs/benches/results.md similarity index 100% rename from crates/threshold-signatures/docs/benches/model.md rename to crates/threshold-signatures/docs/benches/results.md From f6ca1769fe01e0d27cfb5f3976a1f971e9ef6c4c Mon Sep 17 00:00:00 2001 From: SimonRastikian <43679791+SimonRastikian@users.noreply.github.com> Date: Thu, 26 Mar 2026 13:15:51 +0100 Subject: [PATCH 3/7] cargo shear fix --- crates/threshold-signatures/README.md | 2 +- crates/threshold-signatures/src/ecdsa/README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/threshold-signatures/README.md b/crates/threshold-signatures/README.md index cc9b5d11a..1ef2ad1ea 100644 --- a/crates/threshold-signatures/README.md +++ b/crates/threshold-signatures/README.md @@ -219,7 +219,7 @@ MAX_MALICIOUS=15 LATENCY=100 SAMPLE_SIZE=20 cargo bench -- robust_ecdsa_presign_ ``` By default, the maximum number of malicious parties is 6, the latency is 0 milliseconds and the number of iterations is 15. -The detailed numbers and analysis can be found in the [docs/benches/model.md](docs/benches/model.md) documentation. +The detailed numbers and analysis can be found in the [docs/benches/results.md](docs/benches/results.md) documentation. In a nutshell, our results show that the Robust ECDSA scheme is better to deploy than the OT based ECDSA in terms of efficiency and network bandwidth. In fact, with 15 maximum malicious parties and 100 ms of latency, the Robust ECDSA offline phase is roughly **4.7 times** faster than the OT based ECDSA offline phase and transmits **130 times** less bytes over the network before completing. As for Ed25519 the online phase is relatively slow with the current implementation (which does not split the scheme into presign and sign) compared to the ECDSA. With 100ms of latency, the current implementation (no presigning) is roughly 3 times slower to serve a message signing request (online phase) than both of the ECDSA schemes due to the fact that it has 3 times more rounds. diff --git a/crates/threshold-signatures/src/ecdsa/README.md b/crates/threshold-signatures/src/ecdsa/README.md index 5508436da..b6314667b 100644 --- a/crates/threshold-signatures/src/ecdsa/README.md +++ b/crates/threshold-signatures/src/ecdsa/README.md @@ -36,7 +36,7 @@ See [`robust_ecdsa/README.md`](robust_ecdsa/README.md) for details. | **Threshold parameter** | `ReconstructionLowerBound` | `MaxMalicious` | | **Scaling** | Less efficient with many participants | Better efficiency and bandwidth | -See the [benchmark analysis](../../docs/benches/model.md) for detailed performance comparisons. +See the [benchmark analysis](../../docs/benches/results.md) for detailed performance comparisons. ## DKG From f12512a297554f3984597c4fdf536df422130a5c Mon Sep 17 00:00:00 2001 From: SimonRastikian <43679791+SimonRastikian@users.noreply.github.com> Date: Thu, 26 Mar 2026 13:45:03 +0100 Subject: [PATCH 4/7] Relaxing code --- .../benches/advanced_dkg.rs | 8 +-- .../benches/bench_utils.rs | 53 +++++-------------- 2 files changed, 17 insertions(+), 44 deletions(-) diff --git a/crates/threshold-signatures/benches/advanced_dkg.rs b/crates/threshold-signatures/benches/advanced_dkg.rs index a6a3b1ee3..6e4fec2b5 100644 --- a/crates/threshold-signatures/benches/advanced_dkg.rs +++ b/crates/threshold-signatures/benches/advanced_dkg.rs @@ -125,16 +125,16 @@ where { let mut rng = MockCryptoRng::seed_from_u64(42); let preps = prepare_dkg::(participants_num(), threshold, &mut rng); - let (_, protocolsnapshot) = run_protocol_and_take_snapshots(preps.protocols) + let participants: Vec<_> = preps.iter().map(|(p, _)| *p).collect(); + let (_, protocolsnapshot) = run_protocol_and_take_snapshots(preps) .expect("Running protocol with snapshot should not have issues"); // choose the real_participant at random - let real_participant = *preps - .participants + let real_participant = *participants .choose(&mut rng) .expect("participant list is not empty"); - let real_protocol = keygen::(&preps.participants, real_participant, threshold, rng) + let real_protocol = keygen::(&participants, real_participant, threshold, rng) .map(|p| Box::new(p) as Box>>) .expect("Keygen should succeed"); diff --git a/crates/threshold-signatures/benches/bench_utils.rs b/crates/threshold-signatures/benches/bench_utils.rs index 4abde0ea1..00d858675 100644 --- a/crates/threshold-signatures/benches/bench_utils.rs +++ b/crates/threshold-signatures/benches/bench_utils.rs @@ -166,8 +166,8 @@ pub fn ot_ecdsa_prepare_presign let key_packages = run_keygen(&participants, threshold, rng); let mut protocols: Vec<( - Participant, - Box>, + _, + Box>, )> = Vec::with_capacity(participants.len()); for (((p, keygen_out), share0), share1) in @@ -227,10 +227,7 @@ pub fn ot_ecdsa_prepare_sign( }) .collect::>(); - let mut protocols: Vec<( - Participant, - Box>, - )> = Vec::with_capacity(result.len()); + let mut protocols = Vec::with_capacity(result.len()); for (p, presignature) in result.clone() { let protocol = ot_based_ecdsa::sign::sign( @@ -288,10 +285,7 @@ pub fn robust_ecdsa_prepare_presign RobustECDSAPreparedPresig { let participants = generate_participants_with_random_ids(num_participants, rng); let key_packages = run_keygen(&participants, *MAX_MALICIOUS + 1, rng); - let mut protocols: Vec<( - Participant, - Box>, - )> = Vec::with_capacity(participants.len()); + let mut protocols: Vec<_> = Vec::with_capacity(participants.len()); for (p, keygen_out) in &key_packages { let rng_p = MockCryptoRng::seed_from_u64(rng.next_u64()); @@ -349,10 +343,7 @@ pub fn robust_ecdsa_prepare_sign( }) .collect::>(); - let mut protocols: Vec<( - Participant, - Box>, - )> = Vec::with_capacity(result.len()); + let mut protocols = Vec::with_capacity(result.len()); for (p, presignature) in result.clone() { let protocol = robust_ecdsa::sign::sign( @@ -389,10 +380,7 @@ pub fn ed25519_prepare_presign( ) -> FrostEd25519PreparedPresig { let participants = generate_participants_with_random_ids(num_participants, rng); let key_packages = run_keygen(&participants, *MAX_MALICIOUS + 1, rng); - let mut protocols: Vec<( - Participant, - Box>, - )> = Vec::with_capacity(participants.len()); + let mut protocols: Vec<_> = Vec::with_capacity(participants.len()); for (p, keygen_out) in &key_packages { let rng_p = MockCryptoRng::seed_from_u64(rng.next_u64()); @@ -429,10 +417,7 @@ pub fn ed25519_prepare_sign_v1( let coordinator_index = rng.gen_range(0..num_participants); let coordinator = participants[coordinator_index]; - let mut protocols: Vec<( - Participant, - Box>, - )> = Vec::with_capacity(participants.len()); + let mut protocols = Vec::with_capacity(participants.len()); let mut message: [u8; 32] = [0u8; 32]; rng.fill_bytes(&mut message); @@ -470,17 +455,14 @@ pub fn ed25519_prepare_sign_v2( ) -> FrostEd25519SigV2 { let num_participants = threshold.value(); // collect all participants - let participants: Vec = + let participants: Vec<_> = result.iter().map(|(participant, _)| *participant).collect(); // choose a coordinator at random let coordinator_index = rng.gen_range(0..num_participants); let coordinator = participants[coordinator_index]; - let mut protocols: Vec<( - Participant, - Box>, - )> = Vec::with_capacity(participants.len()); + let mut protocols = Vec::with_capacity(participants.len()); let mut message: [u8; 32] = [0u8; 32]; rng.fill_bytes(&mut message); @@ -546,10 +528,7 @@ pub fn prepare_ckd( let coordinator_index = rng.gen_range(0..num_participants); let coordinator = participants[coordinator_index]; - let mut protocols: Vec<( - Participant, - Box>, - )> = Vec::with_capacity(participants.len()); + let mut protocols = Vec::with_capacity(participants.len()); let mut app_id: [u8; 32] = [0u8; 32]; rng.fill_bytes(&mut app_id); @@ -607,7 +586,7 @@ where threshold_signatures::Scalar: Send, { let participants = generate_participants_with_random_ids(num_participants, rng); - let mut protocols: Vec<(Participant, Box>>)> = + let mut protocols = Vec::with_capacity(num_participants); for p in &participants { @@ -618,13 +597,7 @@ where protocols.push((*p, protocol)); } - PreparedDkgPackage { - protocols, - participants, - } + protocols } -pub struct PreparedDkgPackage { - pub protocols: Vec<(Participant, Box>>)>, - pub participants: Vec, -} +pub type PreparedDkgPackage = Vec<(Participant, Box>>)>; From 007ea065b20477831c2100d023fb7fe0cc43a0d0 Mon Sep 17 00:00:00 2001 From: SimonRastikian <43679791+SimonRastikian@users.noreply.github.com> Date: Fri, 27 Mar 2026 13:22:24 +0100 Subject: [PATCH 5/7] cargo fmt --- crates/threshold-signatures/benches/bench_utils.rs | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/crates/threshold-signatures/benches/bench_utils.rs b/crates/threshold-signatures/benches/bench_utils.rs index 00d858675..ebd67939d 100644 --- a/crates/threshold-signatures/benches/bench_utils.rs +++ b/crates/threshold-signatures/benches/bench_utils.rs @@ -165,10 +165,8 @@ pub fn ot_ecdsa_prepare_presign let key_packages = run_keygen(&participants, threshold, rng); - let mut protocols: Vec<( - _, - Box>, - )> = Vec::with_capacity(participants.len()); + let mut protocols: Vec<(_, Box>)> = + Vec::with_capacity(participants.len()); for (((p, keygen_out), share0), share1) in key_packages.clone().into_iter().zip(shares0).zip(shares1) @@ -455,8 +453,7 @@ pub fn ed25519_prepare_sign_v2( ) -> FrostEd25519SigV2 { let num_participants = threshold.value(); // collect all participants - let participants: Vec<_> = - result.iter().map(|(participant, _)| *participant).collect(); + let participants: Vec<_> = result.iter().map(|(participant, _)| *participant).collect(); // choose a coordinator at random let coordinator_index = rng.gen_range(0..num_participants); @@ -586,8 +583,7 @@ where threshold_signatures::Scalar: Send, { let participants = generate_participants_with_random_ids(num_participants, rng); - let mut protocols = - Vec::with_capacity(num_participants); + let mut protocols = Vec::with_capacity(num_participants); for p in &participants { let rng_p = MockCryptoRng::seed_from_u64(rng.next_u64()); From 99c5be1216748bf49e337d9b83a184cd7f490255 Mon Sep 17 00:00:00 2001 From: SimonRastikian <43679791+SimonRastikian@users.noreply.github.com> Date: Fri, 27 Mar 2026 15:10:29 +0100 Subject: [PATCH 6/7] Improving syntax --- crates/threshold-signatures/benches/advanced_dkg.rs | 4 ++-- .../benches/advanced_eddsa_frost_sign_v1.rs | 4 ++-- .../benches/advanced_eddsa_frost_sign_v2.rs | 8 ++++---- .../benches/advanced_ot_based_ecdsa.rs | 12 ++++++------ .../benches/advanced_robust_ecdsa.rs | 8 ++++---- crates/threshold-signatures/benches/ckd.rs | 4 ++-- crates/threshold-signatures/src/test_utils.rs | 2 +- .../src/test_utils/participant_simulation.rs | 4 ++-- .../threshold-signatures/src/test_utils/protocol.rs | 8 ++++---- .../threshold-signatures/src/test_utils/snapshot.rs | 4 ++-- 10 files changed, 29 insertions(+), 29 deletions(-) diff --git a/crates/threshold-signatures/benches/advanced_dkg.rs b/crates/threshold-signatures/benches/advanced_dkg.rs index 6e4fec2b5..094fdccbd 100644 --- a/crates/threshold-signatures/benches/advanced_dkg.rs +++ b/crates/threshold-signatures/benches/advanced_dkg.rs @@ -126,7 +126,7 @@ where let mut rng = MockCryptoRng::seed_from_u64(42); let preps = prepare_dkg::(participants_num(), threshold, &mut rng); let participants: Vec<_> = preps.iter().map(|(p, _)| *p).collect(); - let (_, protocolsnapshot) = run_protocol_and_take_snapshots(preps) + let (_, protocol_snapshot) = run_protocol_and_take_snapshots(preps) .expect("Running protocol with snapshot should not have issues"); // choose the real_participant at random @@ -140,7 +140,7 @@ where // now preparing the simulator let simulated_protocol = - Simulator::new(real_participant, protocolsnapshot).expect("Simulator should not be empty"); + Simulator::new(real_participant, protocol_snapshot).expect("Simulator should not be empty"); PreparedSimulatedDkg { participant: real_participant, diff --git a/crates/threshold-signatures/benches/advanced_eddsa_frost_sign_v1.rs b/crates/threshold-signatures/benches/advanced_eddsa_frost_sign_v1.rs index c870e2518..6fd4fd562 100644 --- a/crates/threshold-signatures/benches/advanced_eddsa_frost_sign_v1.rs +++ b/crates/threshold-signatures/benches/advanced_eddsa_frost_sign_v1.rs @@ -54,7 +54,7 @@ criterion_main!(benches); fn prepare_simulated_sign(threshold: ReconstructionLowerBound) -> PreparedSimulatedSig { let mut rng = MockCryptoRng::seed_from_u64(41); let preps = ed25519_prepare_sign_v1(threshold, &mut rng); - let (_, protocolsnapshot) = run_protocol_and_take_snapshots(preps.protocols) + let (_, protocol_snapshot) = run_protocol_and_take_snapshots(preps.protocols) .expect("Running protocol with snapshot should not have issues"); let participants: Vec = preps @@ -79,7 +79,7 @@ fn prepare_simulated_sign(threshold: ReconstructionLowerBound) -> PreparedSimula // now preparing the simulator let simulated_protocol = - Simulator::new(real_participant, protocolsnapshot).expect("Simulator should not be empty"); + Simulator::new(real_participant, protocol_snapshot).expect("Simulator should not be empty"); PreparedSimulatedSig { participant: real_participant, diff --git a/crates/threshold-signatures/benches/advanced_eddsa_frost_sign_v2.rs b/crates/threshold-signatures/benches/advanced_eddsa_frost_sign_v2.rs index d7e29cdca..cdbf367d9 100644 --- a/crates/threshold-signatures/benches/advanced_eddsa_frost_sign_v2.rs +++ b/crates/threshold-signatures/benches/advanced_eddsa_frost_sign_v2.rs @@ -85,7 +85,7 @@ fn prepare_simulate_presign(num_participants: usize) -> PreparedPresig { let mut rng = MockCryptoRng::seed_from_u64(42); let preps = ed25519_prepare_presign(num_participants, &mut rng); - let (_, protocolsnapshot) = run_protocol_and_take_snapshots(preps.protocols) + let (_, protocol_snapshot) = run_protocol_and_take_snapshots(preps.protocols) .expect("Running protocol with snapshot should not have issues"); // choose the real_participant at random @@ -117,7 +117,7 @@ fn prepare_simulate_presign(num_participants: usize) -> PreparedPresig { // now preparing the simulator let simulated_protocol = - Simulator::new(real_participant, protocolsnapshot).expect("Simulator should not be empty"); + Simulator::new(real_participant, protocol_snapshot).expect("Simulator should not be empty"); PreparedPresig { participant: real_participant, @@ -132,7 +132,7 @@ fn prepare_simulated_sign(threshold: ReconstructionLowerBound) -> PreparedSimula let preps = ed25519_prepare_presign(threshold.value(), &mut rng); let result = run_protocol(preps.protocols).expect("Prepare sign should not fail"); let preps = ed25519_prepare_sign_v2(&result, preps.key_packages, threshold, &mut rng); - let (_, protocolsnapshot) = run_protocol_and_take_snapshots(preps.protocols) + let (_, protocol_snapshot) = run_protocol_and_take_snapshots(preps.protocols) .expect("Running protocol with snapshot should not have issues"); let participants: Vec = preps @@ -157,7 +157,7 @@ fn prepare_simulated_sign(threshold: ReconstructionLowerBound) -> PreparedSimula // now preparing the simulator let simulated_protocol = - Simulator::new(real_participant, protocolsnapshot).expect("Simulator should not be empty"); + Simulator::new(real_participant, protocol_snapshot).expect("Simulator should not be empty"); PreparedSimulatedSig { participant: real_participant, diff --git a/crates/threshold-signatures/benches/advanced_ot_based_ecdsa.rs b/crates/threshold-signatures/benches/advanced_ot_based_ecdsa.rs index 7e1b3443d..1e1c0b101 100644 --- a/crates/threshold-signatures/benches/advanced_ot_based_ecdsa.rs +++ b/crates/threshold-signatures/benches/advanced_ot_based_ecdsa.rs @@ -140,7 +140,7 @@ fn prepare_simulated_triples(participant_num: usize) -> PreparedSimulatedTriples let mut rng = MockCryptoRng::seed_from_u64(42); let preps = ot_ecdsa_prepare_triples(participant_num, *RECONSTRUCTION_LOWER_BOUND, &mut rng); - let (_, protocolsnapshot) = run_protocol_and_take_snapshots(preps.protocols) + let (_, protocol_snapshot) = run_protocol_and_take_snapshots(preps.protocols) .expect("Running protocol with snapshot should not have issues"); // choose the real_participant at random @@ -170,7 +170,7 @@ fn prepare_simulated_triples(participant_num: usize) -> PreparedSimulatedTriples // now preparing the simulator let simulated_protocol = - Simulator::new(real_participant, protocolsnapshot).expect("Simulator should not be empty"); + Simulator::new(real_participant, protocol_snapshot).expect("Simulator should not be empty"); PreparedSimulatedTriples { participant: real_participant, protocol: real_protocol, @@ -184,7 +184,7 @@ fn prepare_simulated_presign( ) -> PreparedSimulatedPresig { let mut rng = MockCryptoRng::seed_from_u64(40); let preps = ot_ecdsa_prepare_presign(two_triples, *RECONSTRUCTION_LOWER_BOUND, &mut rng); - let (_, protocolsnapshot) = run_protocol_and_take_snapshots(preps.protocols) + let (_, protocol_snapshot) = run_protocol_and_take_snapshots(preps.protocols) .expect("Running protocol with snapshot should not have issues"); let mut rng = MockCryptoRng::seed_from_u64(41); @@ -211,7 +211,7 @@ fn prepare_simulated_presign( // now preparing the simulator let simulated_protocol = - Simulator::new(real_participant, protocolsnapshot).expect("Simulator should not be empty"); + Simulator::new(real_participant, protocol_snapshot).expect("Simulator should not be empty"); PreparedSimulatedPresig { participant: real_participant, @@ -228,7 +228,7 @@ pub fn prepare_simulated_sign( ) -> PreparedSimulatedSig { let mut rng = MockCryptoRng::seed_from_u64(40); let preps = ot_ecdsa_prepare_sign(result, threshold, pk, &mut rng); - let (_, protocolsnapshot) = run_protocol_and_take_snapshots(preps.protocols) + let (_, protocol_snapshot) = run_protocol_and_take_snapshots(preps.protocols) .expect("Running protocol with snapshot should not have issues"); // choose the real_participant at random @@ -251,7 +251,7 @@ pub fn prepare_simulated_sign( // now preparing the being the coordinator let simulated_protocol = - Simulator::new(real_participant, protocolsnapshot).expect("Simulator should not be empty"); + Simulator::new(real_participant, protocol_snapshot).expect("Simulator should not be empty"); PreparedSimulatedSig { participant: real_participant, protocol: real_protocol, diff --git a/crates/threshold-signatures/benches/advanced_robust_ecdsa.rs b/crates/threshold-signatures/benches/advanced_robust_ecdsa.rs index 9eb277fce..7980f235c 100644 --- a/crates/threshold-signatures/benches/advanced_robust_ecdsa.rs +++ b/crates/threshold-signatures/benches/advanced_robust_ecdsa.rs @@ -97,7 +97,7 @@ fn prepare_simulate_presign(num_participants: usize) -> PreparedPresig { let mut rng = MockCryptoRng::seed_from_u64(42); let preps = robust_ecdsa_prepare_presign(num_participants, &mut rng); - let (_, protocolsnapshot) = run_protocol_and_take_snapshots(preps.protocols) + let (_, protocol_snapshot) = run_protocol_and_take_snapshots(preps.protocols) .expect("Running protocol with snapshot should not have issues"); // choose the real_participant at random @@ -131,7 +131,7 @@ fn prepare_simulate_presign(num_participants: usize) -> PreparedPresig { // now preparing the simulator let simulated_protocol = - Simulator::new(real_participant, protocolsnapshot).expect("Simulator should not be empty"); + Simulator::new(real_participant, protocol_snapshot).expect("Simulator should not be empty"); PreparedPresig { participant: real_participant, @@ -148,7 +148,7 @@ fn prepare_simulated_sign( ) -> PreparedSimulatedSig { let mut rng = MockCryptoRng::seed_from_u64(41); let preps = robust_ecdsa_prepare_sign(result, max_malicious.into(), pk, &mut rng); - let (_, protocolsnapshot) = run_protocol_and_take_snapshots(preps.protocols) + let (_, protocol_snapshot) = run_protocol_and_take_snapshots(preps.protocols) .expect("Running protocol with snapshot should not have issues"); // collect all participants @@ -170,7 +170,7 @@ fn prepare_simulated_sign( // now preparing the simulator let simulated_protocol = - Simulator::new(real_participant, protocolsnapshot).expect("Simulator should not be empty"); + Simulator::new(real_participant, protocol_snapshot).expect("Simulator should not be empty"); PreparedSimulatedSig { participant: real_participant, diff --git a/crates/threshold-signatures/benches/ckd.rs b/crates/threshold-signatures/benches/ckd.rs index cf164a4ef..05e1fdc68 100644 --- a/crates/threshold-signatures/benches/ckd.rs +++ b/crates/threshold-signatures/benches/ckd.rs @@ -54,7 +54,7 @@ criterion_main!(benches); fn prepare_simulated_ckd(threshold: ReconstructionLowerBound) -> PreparedSimulatedCkd { let mut rng = MockCryptoRng::seed_from_u64(41); let preps = prepare_ckd(threshold, &mut rng); - let (_, protocolsnapshot) = run_protocol_and_take_snapshots(preps.protocols) + let (_, protocol_snapshot) = run_protocol_and_take_snapshots(preps.protocols) .expect("Running protocol with snapshot should not have issues"); let participants: Vec = preps @@ -79,7 +79,7 @@ fn prepare_simulated_ckd(threshold: ReconstructionLowerBound) -> PreparedSimulat // now preparing the simulator let simulated_protocol = - Simulator::new(real_participant, protocolsnapshot).expect("Simulator should not be empty"); + Simulator::new(real_participant, protocol_snapshot).expect("Simulator should not be empty"); PreparedSimulatedCkd { participant: real_participant, diff --git a/crates/threshold-signatures/src/test_utils.rs b/crates/threshold-signatures/src/test_utils.rs index 89e55cbb5..e9896f627 100644 --- a/crates/threshold-signatures/src/test_utils.rs +++ b/crates/threshold-signatures/src/test_utils.rs @@ -45,7 +45,7 @@ pub use protocol::{ run_protocol, run_protocol_and_take_snapshots, run_simulated_protocol, run_two_party_protocol, }; pub use sign::{check_one_coordinator_output, run_sign}; -pub use snapshot::ProtocolSnapshot; +pub use snapshot::protocol_snapshot; pub use test_generators::*; /// Checks that the list contains all None but one element diff --git a/crates/threshold-signatures/src/test_utils/participant_simulation.rs b/crates/threshold-signatures/src/test_utils/participant_simulation.rs index 6ef573c10..21faa5fed 100644 --- a/crates/threshold-signatures/src/test_utils/participant_simulation.rs +++ b/crates/threshold-signatures/src/test_utils/participant_simulation.rs @@ -1,6 +1,6 @@ use crate::participants::Participant; use crate::protocol::MessageData; -use crate::test_utils::snapshot::ProtocolSnapshot; +use crate::test_utils::snapshot::protocol_snapshot; pub struct Simulator { /// the `real_participant` we are simulating for @@ -10,7 +10,7 @@ pub struct Simulator { } impl Simulator { - pub fn new(real_participant: Participant, protocol_snap: ProtocolSnapshot) -> Option { + pub fn new(real_participant: Participant, protocol_snap: protocol_snapshot) -> Option { if protocol_snap.number_of_participants() <= 1 { return None; } diff --git a/crates/threshold-signatures/src/test_utils/protocol.rs b/crates/threshold-signatures/src/test_utils/protocol.rs index ce182472a..05db53c7f 100644 --- a/crates/threshold-signatures/src/test_utils/protocol.rs +++ b/crates/threshold-signatures/src/test_utils/protocol.rs @@ -1,7 +1,7 @@ use crate::errors::ProtocolError; use crate::participants::Participant; use crate::protocol::{Action, Protocol}; -use crate::test_utils::{ProtocolSnapshot, Simulator}; +use crate::test_utils::{protocol_snapshot, Simulator}; use std::collections::HashMap; use crate::participants::ParticipantList; @@ -27,7 +27,7 @@ pub fn run_protocol( /// Like [`run_protocol()`], except that it snapshots all the communication. pub fn run_protocol_and_take_snapshots( ps: Vec<(Participant, Box>)>, -) -> Result<(Vec<(Participant, T)>, ProtocolSnapshot), ProtocolError> { +) -> Result<(Vec<(Participant, T)>, protocol_snapshot), ProtocolError> { run_protocol_common(ps, true).map(|(v, snapshot)| (v, snapshot.unwrap())) } @@ -118,14 +118,14 @@ pub fn run_two_party_protocol( fn run_protocol_common( mut ps: Vec<(Participant, Box>)>, take_snapshots: bool, -) -> Result<(Vec<(Participant, T)>, Option), ProtocolError> { +) -> Result<(Vec<(Participant, T)>, Option), ProtocolError> { let indices: HashMap = ps.iter().enumerate().map(|(i, (p, _))| (*p, i)).collect(); let mut protocol_snapshots = { if take_snapshots { let participants: Vec<_> = ps.iter().map(|(p, _)| *p).collect(); - Some(ProtocolSnapshot::new_empty(participants)) + Some(protocol_snapshot::new_empty(participants)) } else { None } diff --git a/crates/threshold-signatures/src/test_utils/snapshot.rs b/crates/threshold-signatures/src/test_utils/snapshot.rs index 31b11d2b6..d8876af32 100644 --- a/crates/threshold-signatures/src/test_utils/snapshot.rs +++ b/crates/threshold-signatures/src/test_utils/snapshot.rs @@ -59,11 +59,11 @@ impl ParticipantSnapshot { /// Used to store the snapshot of all the messages sent during /// the communication rounds of a certain protocol -pub struct ProtocolSnapshot { +pub struct protocol_snapshot { snapshots: HashMap, } -impl ProtocolSnapshot { +impl protocol_snapshot { /// Creates an empty snapshot pub fn new_empty(participants: Vec) -> Self { let snapshots = participants From 67bb740c14a8808e4445eb81328fec7d4060dcaf Mon Sep 17 00:00:00 2001 From: SimonRastikian <43679791+SimonRastikian@users.noreply.github.com> Date: Fri, 27 Mar 2026 15:34:03 +0100 Subject: [PATCH 7/7] Fix: very stupid blind replace --- crates/threshold-signatures/src/test_utils.rs | 2 +- .../src/test_utils/participant_simulation.rs | 4 ++-- crates/threshold-signatures/src/test_utils/protocol.rs | 8 ++++---- crates/threshold-signatures/src/test_utils/snapshot.rs | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/crates/threshold-signatures/src/test_utils.rs b/crates/threshold-signatures/src/test_utils.rs index e9896f627..89e55cbb5 100644 --- a/crates/threshold-signatures/src/test_utils.rs +++ b/crates/threshold-signatures/src/test_utils.rs @@ -45,7 +45,7 @@ pub use protocol::{ run_protocol, run_protocol_and_take_snapshots, run_simulated_protocol, run_two_party_protocol, }; pub use sign::{check_one_coordinator_output, run_sign}; -pub use snapshot::protocol_snapshot; +pub use snapshot::ProtocolSnapshot; pub use test_generators::*; /// Checks that the list contains all None but one element diff --git a/crates/threshold-signatures/src/test_utils/participant_simulation.rs b/crates/threshold-signatures/src/test_utils/participant_simulation.rs index 21faa5fed..6ef573c10 100644 --- a/crates/threshold-signatures/src/test_utils/participant_simulation.rs +++ b/crates/threshold-signatures/src/test_utils/participant_simulation.rs @@ -1,6 +1,6 @@ use crate::participants::Participant; use crate::protocol::MessageData; -use crate::test_utils::snapshot::protocol_snapshot; +use crate::test_utils::snapshot::ProtocolSnapshot; pub struct Simulator { /// the `real_participant` we are simulating for @@ -10,7 +10,7 @@ pub struct Simulator { } impl Simulator { - pub fn new(real_participant: Participant, protocol_snap: protocol_snapshot) -> Option { + pub fn new(real_participant: Participant, protocol_snap: ProtocolSnapshot) -> Option { if protocol_snap.number_of_participants() <= 1 { return None; } diff --git a/crates/threshold-signatures/src/test_utils/protocol.rs b/crates/threshold-signatures/src/test_utils/protocol.rs index 05db53c7f..ce182472a 100644 --- a/crates/threshold-signatures/src/test_utils/protocol.rs +++ b/crates/threshold-signatures/src/test_utils/protocol.rs @@ -1,7 +1,7 @@ use crate::errors::ProtocolError; use crate::participants::Participant; use crate::protocol::{Action, Protocol}; -use crate::test_utils::{protocol_snapshot, Simulator}; +use crate::test_utils::{ProtocolSnapshot, Simulator}; use std::collections::HashMap; use crate::participants::ParticipantList; @@ -27,7 +27,7 @@ pub fn run_protocol( /// Like [`run_protocol()`], except that it snapshots all the communication. pub fn run_protocol_and_take_snapshots( ps: Vec<(Participant, Box>)>, -) -> Result<(Vec<(Participant, T)>, protocol_snapshot), ProtocolError> { +) -> Result<(Vec<(Participant, T)>, ProtocolSnapshot), ProtocolError> { run_protocol_common(ps, true).map(|(v, snapshot)| (v, snapshot.unwrap())) } @@ -118,14 +118,14 @@ pub fn run_two_party_protocol( fn run_protocol_common( mut ps: Vec<(Participant, Box>)>, take_snapshots: bool, -) -> Result<(Vec<(Participant, T)>, Option), ProtocolError> { +) -> Result<(Vec<(Participant, T)>, Option), ProtocolError> { let indices: HashMap = ps.iter().enumerate().map(|(i, (p, _))| (*p, i)).collect(); let mut protocol_snapshots = { if take_snapshots { let participants: Vec<_> = ps.iter().map(|(p, _)| *p).collect(); - Some(protocol_snapshot::new_empty(participants)) + Some(ProtocolSnapshot::new_empty(participants)) } else { None } diff --git a/crates/threshold-signatures/src/test_utils/snapshot.rs b/crates/threshold-signatures/src/test_utils/snapshot.rs index d8876af32..31b11d2b6 100644 --- a/crates/threshold-signatures/src/test_utils/snapshot.rs +++ b/crates/threshold-signatures/src/test_utils/snapshot.rs @@ -59,11 +59,11 @@ impl ParticipantSnapshot { /// Used to store the snapshot of all the messages sent during /// the communication rounds of a certain protocol -pub struct protocol_snapshot { +pub struct ProtocolSnapshot { snapshots: HashMap, } -impl protocol_snapshot { +impl ProtocolSnapshot { /// Creates an empty snapshot pub fn new_empty(participants: Vec) -> Self { let snapshots = participants