Skip to content

Commit

Permalink
Initial benchmark for Fac proof
Browse files Browse the repository at this point in the history
  • Loading branch information
dvdplm committed Jan 8, 2025
1 parent bf9acac commit a6e4168
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 1 deletion.
27 changes: 27 additions & 0 deletions Cargo.lock

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

10 changes: 10 additions & 0 deletions synedrion/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ serde = { version = "1", default-features = false, features = ["derive"] }
serde-encoded-bytes = { version = "0.1", default-features = false, features = ["hex", "base64"] }
bincode = { version = "2.0.0-rc.3", default-features = false, features = ["serde", "alloc"] }
displaydoc = { version = "0.2", default-features = false }
criterion = { version = "0.5", optional = true }

[dev-dependencies]
manul = { version = "0.1", features = ["dev"] }
Expand All @@ -50,6 +51,10 @@ k256 = { version = "0.13", default-features = false, features = ["ecdsa", "arith
impls = "1"
hex = { version = "0.4", default-features = false, features = ["alloc"] }
test-log = { version = "0.2.16", default-features = false, features = ["trace", "color"] }
tracing-subscriber = "0.3.19"

[features]
private_benches = ["criterion"]

[[bench]]
bench = true
Expand All @@ -62,3 +67,8 @@ bench = true
name = "pow"
harness = false
path = "benches/pow.rs"

[[bench]]
bench = true
name = "fac_proof"
harness = false
26 changes: 26 additions & 0 deletions synedrion/benches/fac_proof.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#[cfg(feature = "private_benches")]
mod bench {
use criterion::{criterion_group, Criterion};
use rand::SeedableRng;
use synedrion::private_benches::*;
fn bench_fac_proof(c: &mut Criterion) {
let mut group = c.benchmark_group("fac proof");
group.sample_size(10);

let rng = rand_chacha::ChaCha8Rng::seed_from_u64(1234567890);
group.bench_function("prove", fac_proof_prove(rng));

let rng = rand_chacha::ChaCha8Rng::seed_from_u64(1234567890);
group.bench_function("verify", fac_proof_verify(rng));
}

criterion_group!(benches, bench_fac_proof);
}

// Running benchmarks without the test harness requires a main function at the top level, leading to
// this awkward setup where we get a magic criterion-main() when the feature is active and an empty
// main() when it's not.
#[cfg(feature = "private_benches")]
criterion::criterion_main!(bench::benches);
#[cfg(not(feature = "private_benches"))]
fn main() {}
5 changes: 4 additions & 1 deletion synedrion/src/cggmp21.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ mod interactive_signing;
mod key_init;
mod key_refresh;
mod params;
mod sigma;
pub(crate) mod sigma;

#[cfg(test)]
mod signing_malicious;
Expand All @@ -25,3 +25,6 @@ pub use interactive_signing::{InteractiveSigning, InteractiveSigningProtocol, Pr
pub use key_init::{KeyInit, KeyInitProtocol};
pub use key_refresh::{KeyRefresh, KeyRefreshProtocol};
pub use params::{ProductionParams, SchemeParams, TestParams};

#[cfg(feature = "private_benches")]
pub(crate) use params::PaillierProduction;
5 changes: 5 additions & 0 deletions synedrion/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,8 @@ pub use cggmp21::{
};
pub use curve::RecoverableSignature;
pub use www02::{DeriveChildKey, KeyResharing, KeyResharingProtocol, NewHolder, OldHolder, ThresholdKeyShare};

#[cfg(feature = "private_benches")]
#[allow(missing_docs)]
// Hack to expose internals for benchmarking purposes
pub mod private_benches;
53 changes: 53 additions & 0 deletions synedrion/src/private_benches/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
use criterion::{black_box, BatchSize, Bencher};
use rand_core::CryptoRngCore;

use crate::cggmp21::{sigma::FacProof, PaillierProduction, ProductionParams};
use crate::paillier::{PublicKeyPaillier, RPParams, SecretKeyPaillierWire};
use crate::SchemeParams;

/// Benchmark Fac-proof construction
pub fn fac_proof_prove<R: CryptoRngCore + Clone + 'static>(mut rng: R) -> impl FnMut(&mut Bencher<'_>) {
let mut rng2 = rng.clone();
move |b: &mut Bencher<'_>| {
b.iter_batched(
|| {
let sk = SecretKeyPaillierWire::<<ProductionParams as SchemeParams>::Paillier>::random(&mut rng)
.into_precomputed();

let setup = RPParams::random(&mut rng);

let aux: &[u8] = b"abcde";
(sk, setup, aux)
},
|(sk, setup, aux)| black_box(FacProof::<ProductionParams>::new(&mut rng2, &sk, &setup, &aux)),
BatchSize::SmallInput,
);
}
}

/// Benchmark Fac-proof verification
pub fn fac_proof_verify<R: CryptoRngCore + Clone + 'static>(mut rng: R) -> impl FnMut(&mut Bencher<'_>) {
type Paillier = <ProductionParams as SchemeParams>::Paillier;
move |b: &mut Bencher<'_>| {
b.iter_batched(
|| {
let sk = SecretKeyPaillierWire::<Paillier>::random(&mut rng).into_precomputed();

let setup = RPParams::random(&mut rng);

let aux: &[u8] = b"abcde";
let proof = FacProof::<ProductionParams>::new(&mut rng, &sk, &setup, &aux);
(proof, sk.public_key().clone(), setup, aux)
},
|(proof, pk0, setup, aux): (
FacProof<ProductionParams>,
PublicKeyPaillier<PaillierProduction>,
RPParams<PaillierProduction>,
&[u8],
)| {
proof.verify(&pk0, &setup, &aux);
},
BatchSize::SmallInput,
);
}
}

0 comments on commit a6e4168

Please sign in to comment.