Skip to content

Commit

Permalink
Disable affected benchmarks
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
cygnusv committed Sep 13, 2023
1 parent 3b3ff48 commit 29101b1
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 177 deletions.
73 changes: 0 additions & 73 deletions tpke/benches/arkworks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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<E: Pairing>(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<E: Pairing>(
threshold: usize,
root: &Fr,
rng: &mut impl RngCore,
) -> Vec<Fr> {
// [][threshold-1]
let mut d_i = (0..threshold - 1)
.map(|_| Fr::rand(rng))
.collect::<Vec<_>>();
// [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::<E>(&d_i, root);
d_i[0] = d_i_0;
assert_eq!(evaluate_polynomial::<E>(&d_i, root), Fr::zero());

debug_assert!(d_i.len() == threshold);
debug_assert!(evaluate_polynomial::<E>(&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::<E>(
threshold - 1,
&Fr::zero(),
&mut rng,
))
}
};
let mut naive = {
let mut rng = rng.clone();
move || {
black_box(naive_make_random_polynomial_with_root::<E>(
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.
}
Expand All @@ -294,7 +222,6 @@ criterion_group!(
// bench_final_exponentiation,
// bench_pairing,
// bench_product_of_pairings,
// bench_random_poly,
);

criterion_main!(benches);
210 changes: 106 additions & 104 deletions tpke/benches/tpke.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Vec<_>>();
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::<E>(
domain_points,
&h,
&x_r,
threshold,
rng,
);
(p.index, deltas_i)
})
.collect::<HashMap<_, _>>();
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::<E>(
&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::<E>(
&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::<E>(
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::<E>(
&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::<Vec<_>>();
// 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::<E>(
// domain_points,
// &h,
// &x_r,
// threshold,
// rng,
// );
// (p.index, deltas_i)
// })
// .collect::<HashMap<_, _>>();
// 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::<E>(
// &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::<E>(
// &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::<E>(
// 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::<E>(
// &p.setup_params.h.into_group(),
// &p.public_decryption_contexts[0].domain,
// &polynomial,
// &p.private_key_share,
// ));
// });
// },
// );
// }
// }

criterion_group!(
benches,
Expand All @@ -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);

0 comments on commit 29101b1

Please sign in to comment.