Skip to content

Commit

Permalink
Update round-based to v0.4
Browse files Browse the repository at this point in the history
Signed-off-by: Denis Varlakov <[email protected]>
  • Loading branch information
survived committed Nov 27, 2024
1 parent 18f5abb commit 81191c0
Show file tree
Hide file tree
Showing 11 changed files with 202 additions and 354 deletions.
37 changes: 4 additions & 33 deletions Cargo.lock

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

6 changes: 5 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ key-share = { version = "0.6", path = "key-share", default-features = false }

generic-ec = { version = "0.4.1", default-features = false }
generic-ec-zkp = { version = "0.4.1", default-features = false }
round-based = { version = "0.3", default-features = false }
round-based = { version = "0.4", default-features = false }

paillier-zk = "0.4.1"
udigest = { version = "0.2.1", default-features = false }
Expand Down Expand Up @@ -48,3 +48,7 @@ generic-tests = "0.1"
[patch.crates-io.hd-wallet]
git = "https://github.com/LFDT-Lockness/hd-wallet"
branch = "dt"

[patch.crates-io.round-based]
git = "https://github.com/LFDT-Lockness/round-based"
branch = "impr-sim"
2 changes: 1 addition & 1 deletion cggmp21/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ hex = { workspace = true, default-features = false, features = ["serde"] }
hd-wallet = { workspace = true, optional = true, features = ["std"] }

[dev-dependencies]
round-based = { workspace = true, features = ["derive", "dev"] }
round-based = { workspace = true, features = ["derive", "sim"] }

rand = { workspace = true }
rand_dev = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion cggmp21/src/signing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ pub struct PartialSignature<E: Curve> {
}

/// ECDSA signature
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize, Debug)]
#[serde(bound = "")]
pub struct Signature<E: Curve> {
/// $r$ component of signature
Expand Down
3 changes: 1 addition & 2 deletions tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,13 @@ rand_dev = { workspace = true }

sha2 = { workspace = true }

round-based = { workspace = true, features = ["derive", "dev", "state-machine"] }
round-based = { workspace = true, features = ["derive", "sim", "state-machine"] }
generic-ec = { workspace = true, features = ["serde", "all-curves"] }

bpaf = "0.7"
include_dir = "0.7"
ciborium = "0.2"

tokio = { version = "1", features = ["macros"] }
futures = "0.3"

lazy_static = "1.4"
Expand Down
92 changes: 34 additions & 58 deletions tests/src/bin/measure_perf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@ use cggmp21::{
};
use rand::Rng;
use rand_dev::DevRng;
use round_based::simulation::Simulation;
use sha2::Sha256;

type E = generic_ec::curves::Secp256k1;
type D = sha2::Sha256;

struct Args {
n: Vec<u16>,
Expand Down Expand Up @@ -55,17 +53,16 @@ fn args() -> Args {
.to_options()
.run()
}
#[tokio::main(flavor = "current_thread")]
async fn main() {
fn main() {
let args = args();
if args.custom_sec_level {
do_becnhmarks::<CustomSecLevel>(args).await
do_becnhmarks::<CustomSecLevel>(args)
} else {
do_becnhmarks::<SecurityLevel128>(args).await
do_becnhmarks::<SecurityLevel128>(args)
}
}

async fn do_becnhmarks<L: SecurityLevel>(args: Args) {
fn do_becnhmarks<L: SecurityLevel>(args: Args) {
let mut rng = DevRng::new();

for n in args.n {
Expand All @@ -89,11 +86,7 @@ async fn do_becnhmarks<L: SecurityLevel>(args: Args) {
let eid: [u8; 32] = rng.gen();
let eid = ExecutionId::new(&eid);

let mut simulation =
Simulation::<cggmp21::keygen::msg::non_threshold::Msg<E, L, D>>::new();

let outputs = (0..n).map(|i| {
let party = simulation.add_party();
let outputs = round_based::simulation::run(n, |i, party| {
let mut party_rng = rng.fork();

let mut profiler = PerfProfiler::new();
Expand All @@ -108,11 +101,10 @@ async fn do_becnhmarks<L: SecurityLevel>(args: Args) {
let report = profiler.get_report().context("get perf report")?;
Ok::<_, anyhow::Error>((key_share, report))
}
});

let outputs = futures::future::try_join_all(outputs)
.await
.expect("non-threshold keygen failed");
})
.unwrap()
.expect_ok()
.into_vec();

if args.bench_non_threshold_keygen {
println!("Non-threshold DKG");
Expand All @@ -132,13 +124,7 @@ async fn do_becnhmarks<L: SecurityLevel>(args: Args) {
let eid: [u8; 32] = rng.gen();
let eid = ExecutionId::new(&eid);

let mut simulation =
Simulation::<cggmp21::keygen::msg::threshold::Msg<E, L, D>>::with_capacity(
(2 * n * n).into(),
);

let outputs = (0..n).map(|i| {
let party = simulation.add_party();
let outputs = round_based::simulation::run(n, |i, party| {
let mut party_rng = rng.fork();

let mut profiler = PerfProfiler::new();
Expand All @@ -154,11 +140,10 @@ async fn do_becnhmarks<L: SecurityLevel>(args: Args) {
let report = profiler.get_report().context("get perf report")?;
Ok::<_, anyhow::Error>((key_share, report))
}
});

let outputs = futures::future::try_join_all(outputs)
.await
.expect("threshold keygen failed");
})
.unwrap()
.expect_ok()
.into_vec();

println!("Threshold DKG");
println!("{}", outputs[0].1.clone().display_io(false));
Expand All @@ -174,12 +159,9 @@ async fn do_becnhmarks<L: SecurityLevel>(args: Args) {
let eid: [u8; 32] = rng.gen();
let eid = ExecutionId::new(&eid);

let mut simulation = Simulation::<cggmp21::key_refresh::AuxOnlyMsg<D, L>>::new();

let mut primes = cggmp21_tests::CACHED_PRIMES.iter::<L>();

let outputs = (0..n).map(|i| {
let party = simulation.add_party();
let outputs = round_based::simulation::run(n, |i, party| {
let mut party_rng = rng.fork();
let pregen = primes.next().expect("Can't get pregenerated prime");

Expand All @@ -194,11 +176,10 @@ async fn do_becnhmarks<L: SecurityLevel>(args: Args) {
let report = profiler.get_report().context("get perf report")?;
Ok::<_, anyhow::Error>((aux_data, report))
}
});

let outputs = futures::future::try_join_all(outputs)
.await
.expect("key refresh failed");
})
.unwrap()
.expect_ok()
.into_vec();

if args.bench_aux_data_gen {
println!("Auxiliary data generation protocol");
Expand Down Expand Up @@ -261,29 +242,24 @@ async fn do_becnhmarks<L: SecurityLevel>(args: Args) {
let message_to_sign = b"Dfns rules!";
let message_to_sign = DataToSign::digest::<Sha256>(message_to_sign);

use cggmp21::signing::msg::Msg;
let mut simulation = Simulation::<Msg<E, D>>::new();

let mut outputs = vec![];
for (i, share) in (0..).zip(&shares) {
let party = simulation.add_party();
let mut party_rng = rng.fork();
let perf_reports =
round_based::simulation::run_with_setup(&shares, |i, party, share| {
let mut party_rng = rng.fork();

let mut profiler = PerfProfiler::new();
let mut profiler = PerfProfiler::new();

outputs.push(async move {
let _signature = cggmp21::signing(eid, i, signers_indexes_at_keygen, share)
.set_progress_tracer(&mut profiler)
.sign(&mut party_rng, party, message_to_sign)
.await
.context("signing failed")?;
profiler.get_report().context("get perf report")
async move {
let _signature = cggmp21::signing(eid, i, signers_indexes_at_keygen, share)
.set_progress_tracer(&mut profiler)
.sign(&mut party_rng, party, message_to_sign)
.await
.context("signing failed")?;
profiler.get_report().context("get perf report")
}
})
}

let perf_reports = futures::future::try_join_all(outputs)
.await
.expect("signing failed");
.unwrap()
.expect_ok()
.into_vec();

println!("Signing protocol");
println!("{}", perf_reports[0].clone().display_io(false));
Expand Down
Loading

0 comments on commit 81191c0

Please sign in to comment.