Skip to content

Commit

Permalink
Extract protocol running logic to manul
Browse files Browse the repository at this point in the history
  • Loading branch information
fjarri committed Nov 19, 2024
1 parent 844a7ea commit 90ccb70
Show file tree
Hide file tree
Showing 57 changed files with 3,108 additions and 6,547 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).


## [0.3.0] - in development

- Switch the protocol framework to `manul`. ([#156])


[#156]: https://github.com/entropyxyz/synedrion/pull/156


## [0.2.0] - 2024-11-17

- Signature and elliptic curve dependencies reset back to stable versions. (#[154])
Expand Down
8 changes: 3 additions & 5 deletions synedrion/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "synedrion"
authors = ['Entropy Cryptography <[email protected]>']
version = "0.2.0"
version = "0.3.0-dev"
edition = "2021"
license = "AGPL-3.0-or-later"
description = "Threshold signing library based on Canetti-Gennaro-Goldfeder-Makriyannis-Peled '21 scheme"
Expand All @@ -10,6 +10,7 @@ readme = "README.md"
categories = ["cryptography", "no-std"]

[dependencies]
manul = "0.1"
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 = { version = "0.1", features = ["dev"] }
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"
87 changes: 67 additions & 20 deletions synedrion/benches/bench.rs
Original file line number Diff line number Diff line change
@@ -1,36 +1,83 @@
use criterion::{criterion_group, criterion_main, Criterion};
use rand_core::OsRng;
use std::collections::BTreeSet;

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

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

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

group.bench_function("KeyGen, 2 parties", |b| {
b.iter(|| key_init::<Params>(&mut OsRng, 2))
});
let signers = (0..2).map(TestSigner::new).collect::<Vec<_>>();
let all_ids = signers
.iter()
.map(|signer| signer.verifying_key())
.collect::<BTreeSet<_>>();

let presigning_inputs = PresigningInputs::new(&mut OsRng, 2);
let signing_inputs = SigningInputs::new(&mut OsRng, &presigning_inputs);

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

let key_shares = KeyShare::new_centralized(&mut OsRng, &all_ids, None);
let aux_infos = AuxInfo::new_centralized(&mut OsRng, &all_ids);
let message = [1u8; 32];

group.sample_size(10);
group.bench_function("Presigning, 2 parties", |b| {
b.iter(|| presigning::<Params>(&mut OsRng, &presigning_inputs))
group.bench_function("InteractiveSigning, 2 parties", |b| {
b.iter_batched(
|| {
signers
.iter()
.map(|signer| {
let id = signer.verifying_key();
let entry_point = InteractiveSigning::<TestParams, TestVerifier>::new(
message,
key_shares[&id].clone(),
aux_infos[&id].clone(),
);
(*signer, 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(all_ids.clone()).unwrap();
(*signer, 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.

12 changes: 3 additions & 9 deletions synedrion/src/cggmp21.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,10 @@ mod params;
mod protocols;
mod sigma;

pub use entities::{AuxInfo, KeyShare, KeyShareChange, PresigningData};
pub use entities::{AuxInfo, KeyShare, KeyShareChange};
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,
};

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

0 comments on commit 90ccb70

Please sign in to comment.