From b1114536ea6ca76f53edabc1ff07c4eba0aecb56 Mon Sep 17 00:00:00 2001 From: Simon Wicky Date: Tue, 7 May 2024 09:38:55 +0200 Subject: [PATCH] minor changes in coconut benchmarks --- common/nymcoconut/benches/benchmarks.rs | 70 ++++++++++++------------- common/nymcoconut/src/lib.rs | 2 +- common/nymcoconut/src/utils.rs | 16 ++---- 3 files changed, 41 insertions(+), 47 deletions(-) diff --git a/common/nymcoconut/benches/benchmarks.rs b/common/nymcoconut/benches/benchmarks.rs index 966e676f42..cc742cf478 100644 --- a/common/nymcoconut/benches/benchmarks.rs +++ b/common/nymcoconut/benches/benchmarks.rs @@ -33,6 +33,40 @@ fn multi_miller_pairing_affine(g11: &G1Affine, g21: &G2Affine, g12: &G1Affine, g )) } +#[allow(unused)] +fn bench_pairings(c: &mut Criterion) { + let mut rng = rand::thread_rng(); + + let g1 = G1Affine::generator(); + let g2 = G2Affine::generator(); + let r = Scalar::random(&mut rng); + let s = Scalar::random(&mut rng); + + let g11 = (g1 * r).to_affine(); + let g21 = (g2 * s).to_affine(); + let g21_prep = G2Prepared::from(g21); + + let g12 = (g1 * s).to_affine(); + let g22 = (g2 * r).to_affine(); + let g22_prep = G2Prepared::from(g22); + + c.bench_function("double pairing", |b| { + b.iter(|| double_pairing(&g11, &g21, &g12, &g22)) + }); + + c.bench_function("multi miller in affine", |b| { + b.iter(|| multi_miller_pairing_affine(&g11, &g21, &g12, &g22)) + }); + + c.bench_function("multi miller with prepared g2", |b| { + b.iter(|| multi_miller_pairing_with_prepared(&g11, &g21_prep, &g12, &g22_prep)) + }); + + c.bench_function("multi miller with semi-prepared g2", |b| { + b.iter(|| multi_miller_pairing_with_semi_prepared(&g11, &g21, &g12, &g22_prep)) + }); +} + #[allow(unused)] fn multi_miller_pairing_with_prepared( g11: &G1Affine, @@ -125,43 +159,9 @@ impl BenchCase { } } -#[allow(unused)] -fn bench_pairings(c: &mut Criterion) { - let mut rng = rand::thread_rng(); - - let g1 = G1Affine::generator(); - let g2 = G2Affine::generator(); - let r = Scalar::random(&mut rng); - let s = Scalar::random(&mut rng); - - let g11 = (g1 * r).to_affine(); - let g21 = (g2 * s).to_affine(); - let g21_prep = G2Prepared::from(g21); - - let g12 = (g1 * s).to_affine(); - let g22 = (g2 * r).to_affine(); - let g22_prep = G2Prepared::from(g22); - - c.bench_function("double pairing", |b| { - b.iter(|| double_pairing(&g11, &g21, &g12, &g22)) - }); - - c.bench_function("multi miller in affine", |b| { - b.iter(|| multi_miller_pairing_affine(&g11, &g21, &g12, &g22)) - }); - - c.bench_function("multi miller with prepared g2", |b| { - b.iter(|| multi_miller_pairing_with_prepared(&g11, &g21_prep, &g12, &g22_prep)) - }); - - c.bench_function("multi miller with semi-prepared g2", |b| { - b.iter(|| multi_miller_pairing_with_semi_prepared(&g11, &g21, &g12, &g22_prep)) - }); -} - fn bench_coconut(c: &mut Criterion) { let mut group = c.benchmark_group("benchmark-coconut"); - group.measurement_time(Duration::from_secs(100)); + group.measurement_time(Duration::from_secs(1000)); let case = BenchCase { num_authorities: 100, threshold_p: 0.7, diff --git a/common/nymcoconut/src/lib.rs b/common/nymcoconut/src/lib.rs index e2a3138b3a..df3cf67383 100644 --- a/common/nymcoconut/src/lib.rs +++ b/common/nymcoconut/src/lib.rs @@ -40,7 +40,7 @@ mod proofs; mod scheme; pub mod tests; mod traits; -mod utils; +pub mod utils; pub type Attribute = bls12_381::Scalar; pub type PrivateAttribute = Attribute; diff --git a/common/nymcoconut/src/utils.rs b/common/nymcoconut/src/utils.rs index 819156cb23..d12707408c 100644 --- a/common/nymcoconut/src/utils.rs +++ b/common/nymcoconut/src/utils.rs @@ -122,7 +122,7 @@ const G1_HASH_DOMAIN: &[u8] = b"QUUX-V01-CS02-with-BLS12381G1_XMD:SHA-256_SSWU_R // https://datatracker.ietf.org/doc/html/draft-irtf-cfrg-hash-to-curve-11#appendix-K.1 const SCALAR_HASH_DOMAIN: &[u8] = b"QUUX-V01-CS02-with-expander"; -pub(crate) fn hash_g1>(msg: M) -> G1Projective { +pub fn hash_g1>(msg: M) -> G1Projective { >>::hash_to_curve(msg, G1_HASH_DOMAIN) } @@ -137,7 +137,7 @@ pub fn hash_to_scalar>(msg: M) -> Scalar { output[0] } -pub(crate) fn try_deserialize_scalar_vec( +pub fn try_deserialize_scalar_vec( expected_len: u64, bytes: &[u8], err: CoconutError, @@ -161,23 +161,17 @@ pub(crate) fn try_deserialize_scalar_vec( Ok(out) } -pub(crate) fn try_deserialize_scalar(bytes: &[u8; 32], err: CoconutError) -> Result { +pub fn try_deserialize_scalar(bytes: &[u8; 32], err: CoconutError) -> Result { Into::>::into(Scalar::from_bytes(bytes)).ok_or(err) } -pub(crate) fn try_deserialize_g1_projective( - bytes: &[u8; 48], - err: CoconutError, -) -> Result { +pub fn try_deserialize_g1_projective(bytes: &[u8; 48], err: CoconutError) -> Result { Into::>::into(G1Affine::from_compressed(bytes)) .ok_or(err) .map(G1Projective::from) } -pub(crate) fn try_deserialize_g2_projective( - bytes: &[u8; 96], - err: CoconutError, -) -> Result { +pub fn try_deserialize_g2_projective(bytes: &[u8; 96], err: CoconutError) -> Result { Into::>::into(G2Affine::from_compressed(bytes)) .ok_or(err) .map(G2Projective::from)