Skip to content

Commit

Permalink
Check num of commitments against min signers
Browse files Browse the repository at this point in the history
  • Loading branch information
natalieesk committed Jan 16, 2024
1 parent a1350ea commit db48fa2
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
6 changes: 3 additions & 3 deletions frost-core/src/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ pub(crate) fn sum_commitments<C: Ciphersuite>(
let mut group_commitment = vec![
CoefficientCommitment(<C::Group>::identity());
commitments
.get(0)
.first()
.ok_or(Error::IncorrectNumberOfCommitments)?
.0
.len()
Expand Down Expand Up @@ -407,7 +407,7 @@ where
/// element in the vector), or an error if the vector is empty.
pub(crate) fn verifying_key(&self) -> Result<VerifyingKey<C>, Error<C>> {
Ok(VerifyingKey::new(
self.0.get(0).ok_or(Error::MissingCommitment)?.0,
self.0.first().ok_or(Error::MissingCommitment)?.0,
))
}

Expand Down Expand Up @@ -614,7 +614,7 @@ fn evaluate_polynomial<C: Ciphersuite>(
}
value = value
+ *coefficients
.get(0)
.first()
.expect("coefficients must have at least one element");
value
}
Expand Down
6 changes: 5 additions & 1 deletion frost-core/src/keys/dkg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ pub(crate) fn compute_proof_of_knowledge<C: Ciphersuite, R: RngCore + CryptoRng>
let c_i = challenge::<C>(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 })
Expand Down Expand Up @@ -506,6 +506,10 @@ pub fn part3<C: Ciphersuite>(
commitment: commitment.clone(),
};

if secret_share.commitment.0.len() != round2_secret_package.min_signers {

Check failure on line 509 in frost-core/src/keys/dkg.rs

View workflow job for this annotation

GitHub Actions / build with default features

mismatched types

Check failure on line 509 in frost-core/src/keys/dkg.rs

View workflow job for this annotation

GitHub Actions / test on beta

mismatched types

Check failure on line 509 in frost-core/src/keys/dkg.rs

View workflow job for this annotation

GitHub Actions / test on beta

can't compare `usize` with `u16`

Check failure on line 509 in frost-core/src/keys/dkg.rs

View workflow job for this annotation

GitHub Actions / Clippy (stable) Results

can't compare `usize` with `u16`

error[E0277]: can't compare `usize` with `u16` --> frost-core/src/keys/dkg.rs:509:44 | 509 | if secret_share.commitment.0.len() != round2_secret_package.min_signers { | ^^ no implementation for `usize == u16` | = help: the trait `std::cmp::PartialEq<u16>` is not implemented for `usize` = help: the following other types implement trait `std::cmp::PartialEq<Rhs>`: <usize as std::cmp::PartialEq> <usize as std::cmp::PartialEq<serde_json::Value>>

Check failure on line 509 in frost-core/src/keys/dkg.rs

View workflow job for this annotation

GitHub Actions / Clippy (stable) Results

mismatched types

error[E0308]: mismatched types --> frost-core/src/keys/dkg.rs:509:47 | 509 | if secret_share.commitment.0.len() != round2_secret_package.min_signers { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `usize`, found `u16`

Check failure on line 509 in frost-core/src/keys/dkg.rs

View workflow job for this annotation

GitHub Actions / Clippy (stable) Results

can't compare `usize` with `u16`

error[E0277]: can't compare `usize` with `u16` --> frost-core/src/keys/dkg.rs:509:44 | 509 | if secret_share.commitment.0.len() != round2_secret_package.min_signers { | ^^ no implementation for `usize == u16` | = help: the trait `std::cmp::PartialEq<u16>` is not implemented for `usize` = help: the following other types implement trait `std::cmp::PartialEq<Rhs>`: <usize as std::cmp::PartialEq> <usize as std::cmp::PartialEq<serde_json::Value>>

Check failure on line 509 in frost-core/src/keys/dkg.rs

View workflow job for this annotation

GitHub Actions / Clippy (stable) Results

mismatched types

error[E0308]: mismatched types --> frost-core/src/keys/dkg.rs:509:47 | 509 | if secret_share.commitment.0.len() != round2_secret_package.min_signers { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `usize`, found `u16`

Check failure on line 509 in frost-core/src/keys/dkg.rs

View workflow job for this annotation

GitHub Actions / Check Rust doc

mismatched types

Check failure on line 509 in frost-core/src/keys/dkg.rs

View workflow job for this annotation

GitHub Actions / Check Rust doc

can't compare `usize` with `u16`
return Err(Error::IncorrectNumberOfCommitments);
}

// Verify the share. We don't need the result.
let _ = secret_share.verify()?;

Expand Down
2 changes: 1 addition & 1 deletion frost-core/src/tests/ciphersuite_generic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ fn check_aggregate_invalid_share_identifier_for_verifying_shares<C: Ciphersuite
.expect_err("should not work");
}

/// Test FROST signing with trusted dealer with a Ciphersuite.
/// Test FROST signing with DKG with a Ciphersuite.
pub fn check_sign_with_dkg<C: Ciphersuite + PartialEq, R: RngCore + CryptoRng>(
mut rng: R,
) -> (Vec<u8>, Signature<C>, VerifyingKey<C>)
Expand Down

0 comments on commit db48fa2

Please sign in to comment.