Skip to content

Commit

Permalink
Fixed a test (#806)
Browse files Browse the repository at this point in the history
* Fixed a test

This test isn't running on CI, but Phuong has a PR that fixes that.

I confused the modulus of the field and the order of the curve. This is
still safe since it more hashes than the bitcoin network has ever run to
make our server crash and embarass us a little bit.

* Improved comment
  • Loading branch information
DavidM-D authored Aug 8, 2024
1 parent 805c9be commit e508d13
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions chain-signatures/crypto-shared/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ impl ScalarExt for Scalar {
/// Use cases are things that we know have been hashed
fn from_non_biased(hash: [u8; 32]) -> Self {
// This should never happen.
// The space of inputs is 2^256, the space of the field is ~2^256 - 2^32.
// This mean that you'd have to run 2^224 hashes to find a value that causes this to fail.
// The space of inputs is 2^256, the space of the field is ~2^256 - 2^129.
// This mean that you'd have to run 2^127 hashes to find a value that causes this to fail.
Scalar::from_bytes(hash).expect("Derived epsilon value falls outside of the field")
}
}
Expand All @@ -36,7 +36,9 @@ fn scalar_fails_as_expected() {
assert!(Scalar::from_bytes(too_high).is_none());

let mut not_too_high = [0xFF; 32];
not_too_high[27] = 0xFD;
// Order is of k256 is FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141
// [15]
not_too_high[15] = 0xFD;
assert!(Scalar::from_bytes(not_too_high).is_some());
}

Expand Down

0 comments on commit e508d13

Please sign in to comment.