Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
149 changes: 149 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ insta = { version = "1.43.1", features = ["json", "redactions"] }
rand = { version = "0.8.5"}
rand_core = { version = "0.6.4", features = ["getrandom"]}
threshold-signatures = { path = ".", features = ["test-utils"] }
statrs = { version = "0.18.0" }


[lib]
Expand Down Expand Up @@ -89,12 +90,12 @@ required-features = ["test-utils"]
[[bench]]
name = "advanced_robust_ecdsa"
harness = false
required-features = ["test-utils"]
required-features = ["test-utils", "statrs"]

[[bench]]
name = "advanced_ot_based_ecdsa"
harness = false
required-features = ["test-utils"]
required-features = ["test-utils", "statrs"]

[profile.test-release]
inherits = "release"
Expand Down
39 changes: 28 additions & 11 deletions benches/advanced_ot_based_ecdsa.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
#![allow(clippy::missing_panics_doc)]
use criterion::{criterion_group, Criterion};
use frost_secp256k1::VerifyingKey;
use rand::{Rng, RngCore};
use rand_core::SeedableRng;

mod bench_utils;
use crate::bench_utils::{
ot_ecdsa_prepare_presign, ot_ecdsa_prepare_sign, ot_ecdsa_prepare_triples,
run_simulated_protocol, PreparedOutputs, LATENCY, MAX_MALICIOUS, SAMPLE_SIZE,
analyze_received_sizes, ot_ecdsa_prepare_presign, ot_ecdsa_prepare_sign,
ot_ecdsa_prepare_triples, run_simulated_protocol, PreparedOutputs, LATENCY, MAX_MALICIOUS,
SAMPLE_SIZE,
};

use threshold_signatures::{
Expand Down Expand Up @@ -42,6 +44,7 @@ fn bench_triples(c: &mut Criterion) {
let max_malicious = *MAX_MALICIOUS;
let latency = *LATENCY;
let rounds = 8;
let mut sizes = Vec::with_capacity(*SAMPLE_SIZE);

let mut group = c.benchmark_group("triples");
group.sample_size(*SAMPLE_SIZE);
Expand All @@ -50,12 +53,18 @@ fn bench_triples(c: &mut Criterion) {
format!("ot_ecdsa_triples_advanced_MAX_MALICIOUS_{max_malicious}_PARTICIPANTS_{num}_LATENCY_{latency}"),
|b| {
b.iter_batched(
|| prepare_simulated_triples(num),
|| {
let preps = prepare_simulated_triples(num);
// collecting data sizes
sizes.push(preps.simulator.get_view_size());
preps
},
|preps| run_simulated_protocol(preps.participant, preps.protocol, preps.simulator, rounds),
criterion::BatchSize::SmallInput,
);
},
);
analyze_received_sizes(&mut sizes, true);
}

/// Benches the presigning protocol
Expand All @@ -64,6 +73,7 @@ fn bench_presign(c: &mut Criterion) {
let max_malicious = *MAX_MALICIOUS;
let latency = *LATENCY;
let rounds = 2;
let mut sizes = Vec::with_capacity(*SAMPLE_SIZE);

let mut rng = MockCryptoRng::seed_from_u64(42);
let preps = ot_ecdsa_prepare_triples(num, threshold(), &mut rng);
Expand All @@ -76,12 +86,18 @@ fn bench_presign(c: &mut Criterion) {
format!("ot_ecdsa_presign_advanced_MAX_MALICIOUS_{max_malicious}_PARTICIPANTS_{num}_LATENCY_{latency}"),
|b| {
b.iter_batched(
|| prepare_simulated_presign(&two_triples),
|| {
let preps = prepare_simulated_presign(&two_triples);
// collecting data sizes
sizes.push(preps.simulator.get_view_size());
preps
},
|preps| run_simulated_protocol(preps.participant, preps.protocol, preps.simulator, rounds),
criterion::BatchSize::SmallInput,
);
},
);
analyze_received_sizes(&mut sizes, true);
}

/// Benches the signing protocol
Expand All @@ -90,6 +106,7 @@ fn bench_sign(c: &mut Criterion) {
let max_malicious = *MAX_MALICIOUS;
let latency = *LATENCY;
let rounds = 1;
let mut sizes = Vec::with_capacity(*SAMPLE_SIZE);

let mut rng = MockCryptoRng::seed_from_u64(42);
let preps = ot_ecdsa_prepare_triples(num, threshold(), &mut rng);
Expand All @@ -106,21 +123,25 @@ fn bench_sign(c: &mut Criterion) {
format!("ot_ecdsa_sign_advanced_MAX_MALICIOUS_{max_malicious}_PARTICIPANTS_{num}_LATENCY_{latency}"),
|b| {
b.iter_batched(
|| prepare_simulated_sign(&result, pk),
|| {
let preps = prepare_simulated_sign(&result, pk);
// collecting data sizes
sizes.push(preps.simulator.get_view_size());
preps
},
|preps| run_simulated_protocol(preps.participant, preps.protocol, preps.simulator, rounds),
criterion::BatchSize::SmallInput,
);
},
);
analyze_received_sizes(&mut sizes, true);
}

criterion_group!(benches, bench_triples, bench_presign, bench_sign);
criterion::criterion_main!(benches);

/****************************** Helpers ******************************/
/// Used to simulate ot based ecdsa triples for benchmarking
/// # Panics
/// Would panic in case an abort happens stopping the entire benchmarking
fn prepare_simulated_triples(participant_num: usize) -> PreparedSimulatedTriples {
let mut rng = MockCryptoRng::seed_from_u64(42);

Expand Down Expand Up @@ -159,8 +180,6 @@ fn prepare_simulated_triples(participant_num: usize) -> PreparedSimulatedTriples
}

/// Used to simulate ot based ecdsa presignatures for benchmarking
/// # Panics
/// Would panic in case an abort happens stopping the entire benchmarking
fn prepare_simulated_presign(
two_triples: &[(Participant, Vec<(TripleShare, TriplePub)>)],
) -> PreparedSimulatedPresig {
Expand Down Expand Up @@ -203,8 +222,6 @@ fn prepare_simulated_presign(
}

/// Used to simulate ot based ecdsa signatures for benchmarking
/// # Panics
/// Would panic in case an abort happens stopping the entire benchmarking
pub fn prepare_simulated_sign(
result: &[(Participant, PresignOutput)],
pk: VerifyingKey,
Expand Down
Loading