From 29101b137f702564e7092ddfb98d75d4e26f4b59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20N=C3=BA=C3=B1ez?= Date: Wed, 13 Sep 2023 12:39:32 +0200 Subject: [PATCH] Disable affected benchmarks * Removed benchmark for random polynomial with root (not much value as it's essentially benchmarking arkworks) * Commented recovery & refresh benchmarks for when #162 is solved --- tpke/benches/arkworks.rs | 73 -------------- tpke/benches/tpke.rs | 210 ++++++++++++++++++++------------------- 2 files changed, 106 insertions(+), 177 deletions(-) diff --git a/tpke/benches/arkworks.rs b/tpke/benches/arkworks.rs index dec8ee43..60459db0 100644 --- a/tpke/benches/arkworks.rs +++ b/tpke/benches/arkworks.rs @@ -14,7 +14,6 @@ use ark_ff::{BigInteger256, Field, One, UniformRand, Zero}; use criterion::{ black_box, criterion_group, criterion_main, BenchmarkId, Criterion, }; -use group_threshold_cryptography_pre_release::make_random_polynomial_with_root; use itertools::izip; use rand::prelude::StdRng; use rand_core::{RngCore, SeedableRng}; @@ -205,77 +204,6 @@ pub fn bench_product_of_pairings(c: &mut Criterion) { } } -pub fn bench_random_poly(c: &mut Criterion) { - let mut group = c.benchmark_group("random_polynomial_evaluation"); - group.sample_size(10); - - fn evaluate_polynomial(polynomial: &[Fr], x: &Fr) -> Fr { - let mut result = Fr::zero(); - let mut x_power = Fr::one(); - for coeff in polynomial { - result += *coeff * x_power; - x_power *= x; - } - result - } - - pub fn naive_make_random_polynomial_with_root( - threshold: usize, - root: &Fr, - rng: &mut impl RngCore, - ) -> Vec { - // [][threshold-1] - let mut d_i = (0..threshold - 1) - .map(|_| Fr::rand(rng)) - .collect::>(); - // [0..][threshold] - d_i.insert(0, Fr::zero()); - - // Now, we calculate d_i_0 - // This is the term that will "zero out" the polynomial at x_r, d_i(x_r) = 0 - let d_i_0 = Fr::zero() - evaluate_polynomial::(&d_i, root); - d_i[0] = d_i_0; - assert_eq!(evaluate_polynomial::(&d_i, root), Fr::zero()); - - debug_assert!(d_i.len() == threshold); - debug_assert!(evaluate_polynomial::(&d_i, root) == Fr::zero()); - d_i - } - - // Skipping t=1, because it results in a random polynomial with t-1=0 coefficients - for threshold in [2, 4, 8, 16, 32, 64] { - let rng = &mut StdRng::seed_from_u64(0); - let mut ark = { - let mut rng = rng.clone(); - move || { - black_box(make_random_polynomial_with_root::( - threshold - 1, - &Fr::zero(), - &mut rng, - )) - } - }; - let mut naive = { - let mut rng = rng.clone(); - move || { - black_box(naive_make_random_polynomial_with_root::( - threshold - 1, - &Fr::zero(), - &mut rng, - )) - } - }; - group.bench_function( - BenchmarkId::new("random_polynomial_ark", threshold), - |b| b.iter(|| ark()), - ); - group.bench_function( - BenchmarkId::new("random_polynomial_naive", threshold), - |b| b.iter(|| naive()), - ); - } -} - pub fn bench_dummy(_c: &mut Criterion) { // Does nothing on purpose, but is required to make criterion happy. } @@ -294,7 +222,6 @@ criterion_group!( // bench_final_exponentiation, // bench_pairing, // bench_product_of_pairings, - // bench_random_poly, ); criterion_main!(benches); diff --git a/tpke/benches/tpke.rs b/tpke/benches/tpke.rs index fad7741f..c122f7c9 100644 --- a/tpke/benches/tpke.rs +++ b/tpke/benches/tpke.rs @@ -470,108 +470,110 @@ pub fn bench_decryption_share_validity_checks(c: &mut Criterion) { } } -pub fn bench_recover_share_at_point(c: &mut Criterion) { - let mut group = c.benchmark_group("RECOVER SHARE"); - let rng = &mut StdRng::seed_from_u64(0); - let msg_size = MSG_SIZE_CASES[0]; - - for &shares_num in NUM_SHARES_CASES.iter() { - let mut setup = SetupSimple::new(shares_num, msg_size, rng); - let threshold = setup.shared.threshold; - let selected_participant = setup.contexts.pop().unwrap(); - let x_r = selected_participant - .public_decryption_contexts - .last() - .unwrap() - .domain; - let mut remaining_participants = setup.contexts; - for p in &mut remaining_participants { - p.public_decryption_contexts.pop(); - } - let domain_points = &remaining_participants[0] - .public_decryption_contexts - .iter() - .map(|ctxt| ctxt.domain) - .collect::>(); - let h = remaining_participants[0].public_decryption_contexts[0].h; - let share_updates = remaining_participants - .iter() - .map(|p| { - let deltas_i = prepare_share_updates_for_recovery::( - domain_points, - &h, - &x_r, - threshold, - rng, - ); - (p.index, deltas_i) - }) - .collect::>(); - let new_share_fragments: Vec<_> = remaining_participants - .iter() - .map(|p| { - // Current participant receives updates from other participants - let updates_for_participant: Vec<_> = share_updates - .values() - .map(|updates| *updates.get(p.index).unwrap()) - .collect(); - - // And updates their share - apply_updates_to_private_share::( - &p.private_key_share, - &updates_for_participant, - ) - }) - .collect(); - group.bench_function( - BenchmarkId::new( - "recover_share_from_updated_private_shares", - shares_num, - ), - |b| { - b.iter(|| { - let _ = black_box( - recover_share_from_updated_private_shares::( - &x_r, - domain_points, - &new_share_fragments, - ), - ); - }); - }, - ); - } -} - -pub fn bench_refresh_shares(c: &mut Criterion) { - let mut group = c.benchmark_group("REFRESH SHARES"); - let rng = &mut StdRng::seed_from_u64(0); - let msg_size = MSG_SIZE_CASES[0]; - - for &shares_num in NUM_SHARES_CASES.iter() { - let setup = SetupSimple::new(shares_num, msg_size, rng); - let threshold = setup.shared.threshold; - let polynomial = make_random_polynomial_with_root::( - threshold - 1, - &Fr::zero(), - rng, - ); - let p = setup.contexts[0].clone(); - group.bench_function( - BenchmarkId::new("refresh_private_key_share", shares_num), - |b| { - b.iter(|| { - black_box(refresh_private_key_share::( - &p.setup_params.h.into_group(), - &p.public_decryption_contexts[0].domain, - &polynomial, - &p.private_key_share, - )); - }); - }, - ); - } -} +// TODO: Relocate benchmark to ferveo/benches as part of #162, #163 +// pub fn bench_recover_share_at_point(c: &mut Criterion) { +// let mut group = c.benchmark_group("RECOVER SHARE"); +// let rng = &mut StdRng::seed_from_u64(0); +// let msg_size = MSG_SIZE_CASES[0]; + +// for &shares_num in NUM_SHARES_CASES.iter() { +// let mut setup = SetupSimple::new(shares_num, msg_size, rng); +// let threshold = setup.shared.threshold; +// let selected_participant = setup.contexts.pop().unwrap(); +// let x_r = selected_participant +// .public_decryption_contexts +// .last() +// .unwrap() +// .domain; +// let mut remaining_participants = setup.contexts; +// for p in &mut remaining_participants { +// p.public_decryption_contexts.pop(); +// } +// let domain_points = &remaining_participants[0] +// .public_decryption_contexts +// .iter() +// .map(|ctxt| ctxt.domain) +// .collect::>(); +// let h = remaining_participants[0].public_decryption_contexts[0].h; +// let share_updates = remaining_participants +// .iter() +// .map(|p| { +// let deltas_i = prepare_share_updates_for_recovery::( +// domain_points, +// &h, +// &x_r, +// threshold, +// rng, +// ); +// (p.index, deltas_i) +// }) +// .collect::>(); +// let new_share_fragments: Vec<_> = remaining_participants +// .iter() +// .map(|p| { +// // Current participant receives updates from other participants +// let updates_for_participant: Vec<_> = share_updates +// .values() +// .map(|updates| *updates.get(p.index).unwrap()) +// .collect(); + +// // And updates their share +// apply_updates_to_private_share::( +// &p.private_key_share, +// &updates_for_participant, +// ) +// }) +// .collect(); +// group.bench_function( +// BenchmarkId::new( +// "recover_share_from_updated_private_shares", +// shares_num, +// ), +// |b| { +// b.iter(|| { +// let _ = black_box( +// recover_share_from_updated_private_shares::( +// &x_r, +// domain_points, +// &new_share_fragments, +// ), +// ); +// }); +// }, +// ); +// } +// } + +// TODO: Relocate benchmark to ferveo/benches as part of #162, #163 +// pub fn bench_refresh_shares(c: &mut Criterion) { +// let mut group = c.benchmark_group("REFRESH SHARES"); +// let rng = &mut StdRng::seed_from_u64(0); +// let msg_size = MSG_SIZE_CASES[0]; + +// for &shares_num in NUM_SHARES_CASES.iter() { +// let setup = SetupSimple::new(shares_num, msg_size, rng); +// let threshold = setup.shared.threshold; +// let polynomial = make_random_polynomial_with_root::( +// threshold - 1, +// &Fr::zero(), +// rng, +// ); +// let p = setup.contexts[0].clone(); +// group.bench_function( +// BenchmarkId::new("refresh_private_key_share", shares_num), +// |b| { +// b.iter(|| { +// black_box(refresh_private_key_share::( +// &p.setup_params.h.into_group(), +// &p.public_decryption_contexts[0].domain, +// &polynomial, +// &p.private_key_share, +// )); +// }); +// }, +// ); +// } +// } criterion_group!( benches, @@ -581,8 +583,8 @@ criterion_group!( bench_share_encrypt_decrypt, bench_ciphertext_validity_checks, bench_decryption_share_validity_checks, - bench_recover_share_at_point, - bench_refresh_shares, + // bench_recover_share_at_point, + // bench_refresh_shares, ); criterion_main!(benches);