Skip to content

Commit 8d1421c

Browse files
authored
feat: merge-train/fairies-v5 (#24673)
BEGIN_COMMIT_OVERRIDE fix(aztec-nr): reject infinity ephemeral key in message encryption (#24665) END_COMMIT_OVERRIDE
2 parents 22f88da + 188251d commit 8d1421c

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

noir-projects/aztec-nr/aztec/src/keys/ephemeral.nr

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ pub fn generate_positive_ephemeral_key_pair() -> (Scalar, EmbeddedCurvePoint) {
3737
let eph_sk = unsafe { generate_secret_key_for_positive_public_key() };
3838
let eph_pk = fixed_base_scalar_mul(eph_sk);
3939

40+
// The point at infinity has x = 0, which is not a valid x-coordinate on the curve, so the recipient could
41+
// never reconstruct the key from it and the message would be undecryptable.
42+
assert(!eph_pk.is_infinite(), "Ephemeral public key is the point at infinity");
4043
assert(get_sign_of_point(eph_pk), "Got an ephemeral public key with a negative y coordinate");
4144

4245
(eph_sk, eph_pk)
@@ -63,6 +66,7 @@ unconstrained fn generate_secret_key_for_positive_public_key() -> EmbeddedCurveS
6366
mod test {
6467
use crate::utils::point::get_sign_of_point;
6568
use super::generate_positive_ephemeral_key_pair;
69+
use std::test::OracleMock;
6670

6771
#[test]
6872
fn generate_positive_ephemeral_key_pair_produces_positive_keys() {
@@ -73,4 +77,11 @@ mod test {
7377
assert(get_sign_of_point(pk));
7478
}
7579
}
80+
81+
#[test(should_fail_with = "point at infinity")]
82+
unconstrained fn generate_positive_ephemeral_key_pair_rejects_zero_randomness() {
83+
// Making the randomness oracle return 0 emulates a malicious sender substituting eph_sk = 0.
84+
let _ = OracleMock::mock("aztec_misc_getRandomField").returns(0);
85+
let _ = generate_positive_ephemeral_key_pair();
86+
}
7687
}

0 commit comments

Comments
 (0)