Fix warnings (#578)

* Use from_coefficients() instead of evaluate_polynomial() when computing a signing_share (#576)

* Refactor BindingFactor::deserialize into from_hex as it's only used for testing (#576)

* Remove BindingFactorList::iter() and use directly in vector test (#576)
This commit is contained in:
natalie 2023-11-16 17:18:40 +00:00 committed by GitHub
parent 99866a7902
commit 036b0ce3fe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 10 additions and 21 deletions

View File

@ -11,4 +11,4 @@
Test coverage checks are performed in the pipeline. This is cofigured here: `.github/workflows/coverage.yaml`
To run these locally:
1. Install coverage tool by running `cargo install cargo-llvm-cov`
2. Run `cargo llvm-cov --ignore-filename-regex '.*(tests).*|benches.rs|gencode|helpers.rs` (you may be asked if you want to install `llvm-tools-preview`, if so type `Y`)
2. Run `cargo llvm-cov --ignore-filename-regex '.*(tests).*|benches.rs|gencode|helpers.rs'` (you may be asked if you want to install `llvm-tools-preview`, if so type `Y`)

View File

@ -894,12 +894,12 @@ pub(crate) fn generate_secret_shares<C: Ciphersuite>(
}
for id in identifiers {
let value = evaluate_polynomial(*id, &coefficients);
let signing_share = SigningShare::from_coefficients(&coefficients, *id);
secret_shares.push(SecretShare {
header: Header::default(),
identifier: *id,
signing_share: SigningShare(value),
signing_share,
commitment: commitment.clone(),
});
}

View File

@ -421,13 +421,13 @@ pub fn part2<C: Ciphersuite>(
// > Each P_i securely sends to each other participant P_ a secret share (, f_i()),
// > deleting f_i and each share afterward except for (i, f_i(i)),
// > which they keep for themselves.
let value = evaluate_polynomial(ell, &secret_package.coefficients);
let signing_share = SigningShare::from_coefficients(&secret_package.coefficients, ell);
round2_packages.insert(
ell,
round2::Package {
header: Header::default(),
signing_share: SigningShare(value),
signing_share,
},
);
}

View File

@ -185,15 +185,6 @@ impl<C> BindingFactor<C>
where
C: Ciphersuite,
{
/// Deserializes [`BindingFactor`] from bytes.
pub fn deserialize(
bytes: <<C::Group as Group>::Field as Field>::Serialization,
) -> Result<Self, Error<C>> {
<<C::Group as Group>::Field>::deserialize(&bytes)
.map(|scalar| Self(scalar))
.map_err(|e| e.into())
}
/// Serializes [`BindingFactor`] to bytes.
pub fn serialize(&self) -> <<C::Group as Group>::Field as Field>::Serialization {
<<C::Group as Group>::Field>::serialize(&self.0)
@ -227,11 +218,6 @@ where
Self(binding_factors)
}
/// Return iterator through all factors.
pub fn iter(&self) -> impl Iterator<Item = (&Identifier<C>, &BindingFactor<C>)> {
self.0.iter()
}
/// Get the [`BindingFactor`] for the given identifier, or None if not found.
pub fn get(&self, key: &Identifier<C>) -> Option<&BindingFactor<C>> {
self.0.get(key)
@ -273,8 +259,11 @@ where
fn from_hex<T: AsRef<[u8]>>(hex: T) -> Result<Self, Self::Error> {
let v: Vec<u8> = FromHex::from_hex(hex).map_err(|_| "invalid hex")?;
match v.try_into() {
Ok(bytes) => Self::deserialize(bytes).map_err(|_| "malformed scalar encoding"),
Ok(bytes) => <<C::Group as Group>::Field>::deserialize(&bytes)
.map(|scalar| Self(scalar))
.map_err(|_| "malformed scalar encoding"),
Err(_) => Err("malformed scalar encoding"),
}
}

View File

@ -271,7 +271,7 @@ pub fn check_sign_with_test_vectors<C: Ciphersuite>(json_vectors: &Value) {
let binding_factor_list: frost::BindingFactorList<C> =
compute_binding_factor_list(&signing_package, &verifying_key, &[]);
for (identifier, binding_factor) in binding_factor_list.iter() {
for (identifier, binding_factor) in binding_factor_list.0.iter() {
assert_eq!(*binding_factor, binding_factors[identifier]);
}