Skip to content

Commit

Permalink
core: prevent creating a zero identifier with deserialization (#797)
Browse files Browse the repository at this point in the history
* core: prevent creating a zero identifier with deserialization

* move test to file which is not copied to other ciphersuites

---------

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
conradoplg and mergify[bot] authored Dec 10, 2024
1 parent 7685ff3 commit d6c9f73
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion frost-core/src/identifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ where
/// Deserialize an Identifier from a serialized buffer.
/// Returns an error if it attempts to deserialize zero.
pub fn deserialize(bytes: &[u8]) -> Result<Self, Error<C>> {
Ok(Self(SerializableScalar::deserialize(bytes)?))
Self::new(SerializableScalar::deserialize(bytes)?.0)
}
}

Expand Down
9 changes: 9 additions & 0 deletions frost-secp256k1/src/tests/deserialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,12 @@ fn check_deserialize_identity() {
let r = <Secp256K1Sha256 as Ciphersuite>::Group::deserialize(&encoded_identity);
assert_eq!(r, Err(GroupError::MalformedElement));
}

// Test if deserializing the identifier 0 fails.
// https://github.com/ZcashFoundation/frost/issues/793
#[test]
fn check_zero_identifier_deserialization() {
let arr: [u8; 32] = [0; 32];
let r = Identifier::deserialize(&arr);
assert_eq!(r, Err(Error::FieldError(FieldError::InvalidZeroScalar)));
}

0 comments on commit d6c9f73

Please sign in to comment.