-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
125 additions
and
1 deletion.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
); | ||
} | ||
} |