Skip to content

Commit

Permalink
Rename random polynomial function for refresh & recovery
Browse files Browse the repository at this point in the history
Technically, this helper function creates a random polynomial where the `root` parameter is a root of the polynomial, so `make_random_polynomial_with_root` is a better name.
  • Loading branch information
cygnusv committed Aug 31, 2023
1 parent b69442d commit a0d8946
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 9 deletions.
2 changes: 1 addition & 1 deletion ferveo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ mod test_dkg_full {
// Now, we're going to refresh the shares and check that the shared secret is the same

// Dealer computes a new random polynomial with constant term x_r = 0
let polynomial = make_random_polynomial_at::<E>(
let polynomial = make_random_polynomial_with_root::<E>(
dkg.dkg_params.security_threshold as usize,
&Fr::zero(),
rng,
Expand Down
7 changes: 4 additions & 3 deletions ferveo/src/refresh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ pub fn recover_share_from_updated_private_shares<E: Pairing>(
}
}

pub fn make_random_polynomial_at<E: Pairing>(
pub fn make_random_polynomial_with_root<E: Pairing>(
threshold: usize,
root: &E::ScalarField,
rng: &mut impl RngCore,
Expand All @@ -78,6 +78,7 @@ pub fn make_random_polynomial_at<E: Pairing>(
let d_i_0 = E::ScalarField::zero() - threshold_poly.evaluate(root);
threshold_poly[0] = d_i_0;

// Evaluating the polynomial at the root should result in 0
debug_assert!(threshold_poly.evaluate(root) == E::ScalarField::zero());
debug_assert!(threshold_poly.coeffs.len() == threshold);

Expand Down Expand Up @@ -120,7 +121,7 @@ mod tests_refresh {
type ScalarField = <E as Pairing>::ScalarField;

use crate::{
make_random_polynomial_at, prepare_share_updates_for_recovery,
make_random_polynomial_with_root, prepare_share_updates_for_recovery,
recover_share_from_updated_private_shares, refresh_private_key_share,
update_share_for_recovery,
};
Expand Down Expand Up @@ -359,7 +360,7 @@ mod tests_refresh {
// Now, we're going to refresh the shares and check that the shared secret is the same

// Dealer computes a new random polynomial with constant term x_r
let polynomial = make_random_polynomial_at::<E>(
let polynomial = make_random_polynomial_with_root::<E>(
threshold,
&ScalarField::zero(),
rng,
Expand Down
8 changes: 4 additions & 4 deletions tpke/benches/arkworks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ 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_at;
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 @@ -219,7 +219,7 @@ pub fn bench_random_poly(c: &mut Criterion) {
result
}

pub fn naive_make_random_polynomial_at<E: Pairing>(
pub fn naive_make_random_polynomial_with_root<E: Pairing>(
threshold: usize,
root: &Fr,
rng: &mut impl RngCore,
Expand Down Expand Up @@ -248,7 +248,7 @@ pub fn bench_random_poly(c: &mut Criterion) {
let mut ark = {
let mut rng = rng.clone();
move || {
black_box(make_random_polynomial_at::<E>(
black_box(make_random_polynomial_with_root::<E>(
threshold,
&Fr::zero(),
&mut rng,
Expand All @@ -258,7 +258,7 @@ pub fn bench_random_poly(c: &mut Criterion) {
let mut naive = {
let mut rng = rng.clone();
move || {
black_box(naive_make_random_polynomial_at::<E>(
black_box(naive_make_random_polynomial_with_root::<E>(
threshold,
&Fr::zero(),
&mut rng,
Expand Down
2 changes: 1 addition & 1 deletion tpke/benches/tpke.rs
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ pub fn bench_refresh_shares(c: &mut Criterion) {
let setup = SetupSimple::new(shares_num, msg_size, rng);
let threshold = setup.shared.threshold;
let polynomial =
make_random_polynomial_at::<E>(threshold, &Fr::zero(), rng);
make_random_polynomial_with_root::<E>(threshold, &Fr::zero(), rng);
let p = setup.contexts[0].clone();
group.bench_function(
BenchmarkId::new("refresh_private_key_share", shares_num),
Expand Down

0 comments on commit a0d8946

Please sign in to comment.