From e1fb9bc953a5ea5c22304c0018f56f407163f101 Mon Sep 17 00:00:00 2001 From: natalie Date: Wed, 17 Jan 2024 13:18:27 +0000 Subject: [PATCH] Check num of commitments against min signers (#597) * Check num of commitments against min signers * Move incorrect number of commitments check to part2 in the DKG --- frost-core/src/keys.rs | 6 +++--- frost-core/src/keys/dkg.rs | 8 +++++++- frost-core/src/tests/ciphersuite_generic.rs | 2 +- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/frost-core/src/keys.rs b/frost-core/src/keys.rs index 542d5c0d..533cb13f 100644 --- a/frost-core/src/keys.rs +++ b/frost-core/src/keys.rs @@ -39,7 +39,7 @@ pub(crate) fn sum_commitments( let mut group_commitment = vec![ CoefficientCommitment(::identity()); commitments - .get(0) + .first() .ok_or(Error::IncorrectNumberOfCommitments)? .0 .len() @@ -407,7 +407,7 @@ where /// element in the vector), or an error if the vector is empty. pub(crate) fn verifying_key(&self) -> Result, Error> { Ok(VerifyingKey::new( - self.0.get(0).ok_or(Error::MissingCommitment)?.0, + self.0.first().ok_or(Error::MissingCommitment)?.0, )) } @@ -614,7 +614,7 @@ fn evaluate_polynomial( } value = value + *coefficients - .get(0) + .first() .expect("coefficients must have at least one element"); value } diff --git a/frost-core/src/keys/dkg.rs b/frost-core/src/keys/dkg.rs index 6dc4025a..fa370651 100644 --- a/frost-core/src/keys/dkg.rs +++ b/frost-core/src/keys/dkg.rs @@ -349,7 +349,7 @@ pub(crate) fn compute_proof_of_knowledge let c_i = challenge::(identifier, &commitment.verifying_key()?, &R_i) .ok_or(Error::DKGNotSupported)?; let a_i0 = *coefficients - .get(0) + .first() .expect("coefficients must have at least one element"); let mu_i = k + a_i0 * c_i.0; Ok(Signature { R: R_i, z: mu_i }) @@ -406,6 +406,12 @@ pub fn part2( return Err(Error::IncorrectNumberOfPackages); } + for package in round1_packages.values() { + if package.commitment.0.len() != secret_package.min_signers as usize { + return Err(Error::IncorrectNumberOfCommitments); + } + } + let mut round2_packages = BTreeMap::new(); for (sender_identifier, round1_package) in round1_packages { diff --git a/frost-core/src/tests/ciphersuite_generic.rs b/frost-core/src/tests/ciphersuite_generic.rs index b33ed6bf..4dd67317 100644 --- a/frost-core/src/tests/ciphersuite_generic.rs +++ b/frost-core/src/tests/ciphersuite_generic.rs @@ -360,7 +360,7 @@ fn check_aggregate_invalid_share_identifier_for_verifying_shares( mut rng: R, ) -> (Vec, Signature, VerifyingKey)