Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch protocol framework to manul #156

Draft
wants to merge 15 commits into
base: master
Choose a base branch
from
6 changes: 2 additions & 4 deletions synedrion/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ readme = "README.md"
categories = ["cryptography", "no-std"]

[dependencies]
manul = { path = "/Users/bogdan/wb/github/manul/manul" }
signature = { version = "2", default-features = false, features = ["alloc"] }
k256 = { version = "0.13", default-features = false, features = ["ecdsa", "arithmetic"] }
rand_core = { version = "0.6.4", default-features = false }
Expand All @@ -32,6 +33,7 @@ bincode = { version = "2.0.0-rc.3", default-features = false, features = ["serde
displaydoc = { version = "0.2", default-features = false }

[dev-dependencies]
manul = { path = "/Users/bogdan/wb/github/manul/manul", features = ["testing"] }
rand_chacha = "0.3"
serde_assert = "0.8"
tokio = { version = "1", features = ["rt", "sync", "time", "macros"] }
Expand All @@ -41,12 +43,8 @@ k256 = {version = "0.13", default-features = false, features = ["ecdsa", "arithm
impls = "1"
hex = { version = "0.4", default-features = false, features = ["alloc"] }

[features]
bench-internals = [] # makes some internal functions public to allow external benchmarks

[[bench]]
bench = true
name = "bench"
harness = false
required-features = ["bench-internals"]
path = "benches/bench.rs"
107 changes: 92 additions & 15 deletions synedrion/benches/bench.rs
Original file line number Diff line number Diff line change
@@ -1,36 +1,113 @@
use criterion::{criterion_group, criterion_main, Criterion};
use rand_core::OsRng;
use std::collections::BTreeSet;

use criterion::{criterion_group, criterion_main, BatchSize, Criterion};
use manul::{
session::signature::Keypair,
testing::{run_sync, BinaryFormat, TestSessionParams, TestSigner, TestVerifier},
};
use rand_core::OsRng;
use synedrion::{
bench_internals::{
key_init, key_refresh, presigning, signing, PresigningInputs, SigningInputs,
},
TestParams,
AuxGen, AuxInfo, KeyInit, KeyShare, Presigning, PresigningData, Signing, TestParams,
};

fn bench_happy_paths(c: &mut Criterion) {
let mut group = c.benchmark_group("happy path");

type Params = TestParams;
type SessionParams = TestSessionParams<BinaryFormat>;

let signers = (0..2).map(TestSigner::new).collect::<Vec<_>>();
let all_ids = signers
.iter()
.map(|signer| signer.verifying_key())
.collect::<BTreeSet<_>>();

group.bench_function("KeyGen, 2 parties", |b| {
b.iter(|| key_init::<Params>(&mut OsRng, 2))
group.bench_function("KeyInit, 2 parties", |b| {
b.iter_batched(
|| {
signers
.iter()
.map(|signer| {
let entry_point = KeyInit::<TestParams, TestVerifier>::new(
signer.verifying_key(),
all_ids.clone(),
)
.unwrap();
(signer.clone(), entry_point)
})
.collect::<Vec<_>>()
},
|entry_points| run_sync::<_, SessionParams>(&mut OsRng, entry_points).unwrap(),
BatchSize::SmallInput,
)
});

let presigning_inputs = PresigningInputs::new(&mut OsRng, 2);
let signing_inputs = SigningInputs::new(&mut OsRng, &presigning_inputs);
let key_shares = KeyShare::new_centralized(&mut OsRng, &all_ids, None);
let aux_infos = AuxInfo::new_centralized(&mut OsRng, &all_ids);
let presigning_datas = PresigningData::new_centralized(&mut OsRng, &key_shares, &aux_infos);
let message = [1u8; 32];

group.bench_function("Signing, 2 parties", |b| {
b.iter(|| signing::<Params>(&mut OsRng, &presigning_inputs, &signing_inputs))
b.iter_batched(
|| {
signers
.iter()
.map(|signer| {
let id = signer.verifying_key();
let entry_point = Signing::<TestParams, TestVerifier>::new(
message,
presigning_datas[&id].clone(),
key_shares[&id].clone(),
aux_infos[&id].clone(),
);
(signer.clone(), entry_point)
})
.collect::<Vec<_>>()
},
|entry_points| run_sync::<_, SessionParams>(&mut OsRng, entry_points).unwrap(),
BatchSize::LargeInput,
)
});

group.sample_size(10);
group.bench_function("Presigning, 2 parties", |b| {
b.iter(|| presigning::<Params>(&mut OsRng, &presigning_inputs))
b.iter_batched(
|| {
signers
.iter()
.map(|signer| {
let id = signer.verifying_key();
let entry_point = Presigning::<TestParams, TestVerifier>::new(
key_shares[&id].clone(),
aux_infos[&id].clone(),
);
(signer.clone(), entry_point)
})
.collect::<Vec<_>>()
},
|entry_points| run_sync::<_, SessionParams>(&mut OsRng, entry_points).unwrap(),
BatchSize::LargeInput,
)
});

group.bench_function("KeyRefresh, 2 parties", |b| {
b.iter(|| key_refresh::<Params>(&mut OsRng, 2))
group.sample_size(20);
group.bench_function("AuxGen, 2 parties", |b| {
b.iter_batched(
|| {
signers
.iter()
.map(|signer| {
let entry_point = AuxGen::<TestParams, TestVerifier>::new(
signer.verifying_key(),
all_ids.clone(),
)
.unwrap();
(signer.clone(), entry_point)
})
.collect::<Vec<_>>()
},
|entry_points| run_sync::<_, SessionParams>(&mut OsRng, entry_points).unwrap(),
BatchSize::SmallInput,
)
});

group.finish()
Expand Down
185 changes: 0 additions & 185 deletions synedrion/src/bench_internals.rs

This file was deleted.

11 changes: 3 additions & 8 deletions synedrion/src/cggmp21.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,8 @@ mod sigma;
pub use entities::{AuxInfo, KeyShare, KeyShareChange, PresigningData};
pub(crate) use entities::{PublicAuxInfo, SecretAuxInfo};
pub use params::{ProductionParams, SchemeParams, TestParams};
pub(crate) use protocols::{aux_gen, interactive_signing, key_gen, key_init, key_refresh};
pub use protocols::{
AuxGenError, AuxGenResult, InteractiveSigningError, InteractiveSigningProof,
InteractiveSigningResult, KeyGenError, KeyGenProof, KeyGenResult, KeyInitError, KeyInitResult,
KeyRefreshResult, PresigningError, PresigningProof, PresigningResult, SigningProof,
SigningResult,
AuxGen, AuxGenProtocol, InteractiveSigning, InteractiveSigningProtocol, KeyInit,
KeyInitProtocol, KeyRefresh, KeyRefreshProtocol, PrehashedMessage, Presigning,
PresigningProtocol, Signing, SigningProtocol,
};

#[cfg(feature = "bench-internals")]
pub(crate) use protocols::{presigning, signing};
Loading
Loading