#![allow(clippy::indexing_slicing, clippy::missing_panics_doc)] use rand_core::SeedableRng; mod bench_utils; use bench_utils::prepare_dkg; use threshold_signatures::{ Ciphersuite, Element, ReconstructionThreshold, Scalar, confidential_key_derivation::ciphersuite::BLS12381SHA256, frost_ed25519::Ed25519Sha512, frost_secp256k1::Secp256K1Sha256, test_utils::{BenchConfig, MockCryptoRng, SimulationMetrics, bench_simulation, run_simulation}, }; fn main() { let config = BenchConfig::from_env(); let threshold = ReconstructionThreshold::from(config.threshold); let n = config.num_participants; println!("Protocol simulation: DKG"); println!( "Participants: {n}, threshold: {}, latency: {}ms, samples: {}", config.threshold, config.latency_ms(), config.samples ); println!(); config.warmup(&|| { run_dkg::(n, threshold, &config); }); bench_simulation( "secp256k1", &|| run_dkg::(n, threshold, &config), config.samples, ); bench_simulation( "ed25519", &|| run_dkg::(n, threshold, &config), config.samples, ); bench_simulation( "bls12381", &|| run_dkg::(n, threshold, &config), config.samples, ); } fn run_dkg( n: usize, threshold: ReconstructionThreshold, config: &BenchConfig, ) -> SimulationMetrics where Element: Send, Scalar: Send, { let mut rng = MockCryptoRng::seed_from_u64(42); let protocols = prepare_dkg::(n, threshold, &mut rng).protocols; let (results, metrics) = run_simulation(protocols, &config.latency); assert_eq!(results.len(), n); let first_pk = results[0].1.public_key; for (p, output) in &results { assert_eq!( output.public_key, first_pk, "Participant {p:?} has different public key" ); } metrics }