Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: prevent underflow when generating Party::f #55

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions src/v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use num_traits::{One, Zero};
use polynomial::Polynomial;
use rand_core::{CryptoRng, RngCore};
use serde::{Deserialize, Serialize};
use std::cmp;

use crate::{
common::{Nonce, PolyCommitment, PublicNonce, Signature, SignatureShare},
Expand Down Expand Up @@ -71,13 +72,14 @@ impl Party {
threshold: u32,
rng: &mut RNG,
) -> Self {
let f_range = cmp::max(threshold, 1);
Self {
party_id,
key_ids: key_ids.to_vec(),
num_keys,
num_parties,
threshold,
f: VSS::random_poly(threshold - 1, rng),
f: VSS::random_poly(f_range - 1, rng),
private_keys: PrivKeyMap::new(),
group_key: Point::zero(),
nonce: Nonce::zero(),
Expand Down Expand Up @@ -623,7 +625,7 @@ pub mod test_helpers {

#[cfg(test)]
mod tests {
use crate::{traits::Aggregator, v2};
use crate::{traits::Aggregator, v2, vss::VSS};

use rand_core::OsRng;

Expand Down Expand Up @@ -683,4 +685,17 @@ mod tests {
}
}
}

#[test]
fn test_random_poly_0_threshold() {
let mut rng = OsRng::default();
// Ensure this doesn't cause an exception
VSS::random_poly(0, &mut rng);

let mut rng = OsRng;
let key_ids = [1, 2, 3];

// ensure no exception
v2::Party::new(0, &key_ids, 1, 1, 0, &mut rng);
}
}
Loading