Skip to content

Commit

Permalink
Fix missing type for nightly that wasn't caught
Browse files Browse the repository at this point in the history
In previous effort I made to catch all these.
  • Loading branch information
LLFourn committed Jul 12, 2023
1 parent 2bbac08 commit 66910ce
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
5 changes: 3 additions & 2 deletions ecdsa_fun/src/adaptor/encrypted_signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ secp256kfun::impl_fromstr_deserialize! {
name => "compressed secp256k1 point",
fn from_bytes(bytes: [u8;33]) -> Option<PointNonce> {
Point::from_bytes(bytes).and_then(|point| {
Scalar::from_bytes_mod_order(point.to_xonly_bytes()).public()
.non_zero().map(move |x_scalar| PointNonce { point, x_scalar } )
let x_scalar = Scalar::<Public, Zero>::from_bytes_mod_order(point.to_xonly_bytes()).public()
.non_zero()?;
Some(PointNonce { point, x_scalar })
})
}
}
Expand Down
4 changes: 2 additions & 2 deletions secp256kfun/src/proptest_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ impl<S: Secrecy> Arbitrary for Scalar<S, NonZero> {
// insert some pathological cases
1 => Just(Scalar::<S,_>::one()),
1 => Just(Scalar::<S,_>::minus_one()),
18 => any::<[u8;32]>().prop_filter_map("zero bytes not acceptable", |bytes| Scalar::from_bytes_mod_order(bytes).non_zero()),
18 => any::<[u8;32]>().prop_filter_map("zero bytes not acceptable", |bytes| Scalar::<S, Zero>::from_bytes_mod_order(bytes).non_zero()),
].boxed()
}
}
Expand All @@ -28,7 +28,7 @@ impl<S: Secrecy> Arbitrary for Scalar<S, Zero> {
1 => Just(Scalar::zero()),
1 => Just(Scalar::one().mark_zero()),
1 => Just(Scalar::minus_one().mark_zero()),
27 => any::<[u8;32]>().prop_map(|bytes| Scalar::from_bytes_mod_order(bytes)),
27 => any::<[u8;32]>().prop_map(|bytes| Scalar::<S, Zero>::from_bytes_mod_order(bytes)),
]
.boxed()
}
Expand Down
18 changes: 9 additions & 9 deletions secp256kfun/tests/against_c_lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ mod against_c_lib {

// Multiply a generator by scalar for both libraries and test equality
let (point_1, secp_pk_1) = {
let point_1 = g!({ Scalar::from_bytes_mod_order(s1) } * G)
let point_1 = g!({ Scalar::<Secret, Zero>::from_bytes_mod_order(s1) } * G)
.normalize().non_zero()
.unwrap();

Expand All @@ -32,7 +32,7 @@ mod against_c_lib {

// Multiply the resulting points by another scalar and test equality
{
let point_2 = g!({ Scalar::from_bytes_mod_order(s2) } * point_1)
let point_2 = g!({ Scalar::<Secret, Zero>::from_bytes_mod_order(s2) } * point_1)
.normalize().non_zero()
.unwrap();
let secp_pk_2 = {
Expand All @@ -49,11 +49,11 @@ mod against_c_lib {
#[test]
fn vartime_double_mul(scalar_H in any::<[u8;32]>(), y in any::<[u8;32]>(), x in any::<[u8;32]>()) {
let result = {
let H = g!({ Scalar::from_bytes_mod_order(scalar_H) } * G);
let H = g!({ Scalar::<Secret, Zero>::from_bytes_mod_order(scalar_H) } * G);
double_mul(
&Scalar::from_bytes_mod_order(x).public(),
&Scalar::<Secret, Zero>::from_bytes_mod_order(x).public(),
G,
&Scalar::from_bytes_mod_order(y).public(),
&Scalar::<Secret, Zero>::from_bytes_mod_order(y).public(),
&H,
)
.normalize().non_zero()
Expand All @@ -78,7 +78,7 @@ mod against_c_lib {
fn point_addition(scalar_1 in any::<[u8;32]>()) {
let secp_pk_1 =
PublicKey::from_secret_key(&*SECP, &SecretKey::from_slice(&scalar_1).unwrap());
let point_1 = g!({ Scalar::from_bytes_mod_order(scalar_1) } * G);
let point_1 = g!({ Scalar::<Secret, Zero>::from_bytes_mod_order(scalar_1) } * G);


prop_assert_eq!(
Expand All @@ -95,8 +95,8 @@ mod against_c_lib {

#[test]
fn scalar_ops(bytes_1 in any::<[u8;32]>(), bytes_2 in any::<[u8;32]>()) {
let scalar_1 = Scalar::from_bytes_mod_order(bytes_1);
let scalar_2 = Scalar::from_bytes_mod_order(bytes_2);
let scalar_1 = Scalar::<Secret, Zero>::from_bytes_mod_order(bytes_1);
let scalar_2 = Scalar::<Secret, Zero>::from_bytes_mod_order(bytes_2);
let sk_1 = &SecretKey::from_slice(&bytes_1).unwrap();

prop_assert_eq!(&scalar_1.to_bytes()[..], &sk_1[..]);
Expand All @@ -122,7 +122,7 @@ mod against_c_lib {
#[test]
fn scalar_negation(bytes in any::<[u8;32]>()) {
let sk = SecretKey::from_slice(&bytes).unwrap().negate();
let scalar = Scalar::from_bytes_mod_order(bytes);
let scalar = Scalar::<Secret, Zero>::from_bytes_mod_order(bytes);
prop_assert_eq!(&(-scalar).to_bytes()[..], &sk[..]);
}

Expand Down

0 comments on commit 66910ce

Please sign in to comment.