From 400a302aa8b87348533ed427251c3946dc90be2f Mon Sep 17 00:00:00 2001 From: benesjan Date: Tue, 9 Jul 2024 13:19:09 +0000 Subject: [PATCH] nicer naming --- .../aztec-nr/aztec/src/encrypted_logs/payload.nr | 14 ++++++++------ .../crates/types/src/scalar.nr | 2 +- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/noir-projects/aztec-nr/aztec/src/encrypted_logs/payload.nr b/noir-projects/aztec-nr/aztec/src/encrypted_logs/payload.nr index 37c853c90a0..50b77ed5b95 100644 --- a/noir-projects/aztec-nr/aztec/src/encrypted_logs/payload.nr +++ b/noir-projects/aztec-nr/aztec/src/encrypted_logs/payload.nr @@ -24,7 +24,7 @@ pub fn compute_encrypted_event_log( event: Event ) -> [u8; OB] where Event: EventInterface { // @todo Need to draw randomness from the full domain of Fq not only Fr - let eph_sk: Scalar = fr_to_private_key(unsafe_rand()); + let eph_sk: Scalar = fr_to_fq(unsafe_rand()); let eph_pk = eph_sk.derive_public_key(); // TODO: (#7177) This value needs to be populated! @@ -37,7 +37,7 @@ pub fn compute_encrypted_event_log( let incoming_header_ciphertext: [u8; 48] = header.compute_ciphertext(eph_sk, ivpk); let outgoing_Header_ciphertext: [u8; 48] = header.compute_ciphertext(eph_sk, ovpk); let incoming_body_ciphertext = EncryptedLogIncomingBody::from_event(event, randomness).compute_ciphertext(eph_sk, ivpk_app); - let outgoing_body_ciphertext: [u8; 176] = EncryptedLogOutgoingBody::new(eph_sk, recipient, ivpk_app).compute_ciphertext(fr_to_private_key(ovsk_app), eph_pk); + let outgoing_body_ciphertext: [u8; 176] = EncryptedLogOutgoingBody::new(eph_sk, recipient, ivpk_app).compute_ciphertext(fr_to_fq(ovsk_app), eph_pk); let mut encrypted_bytes: [u8; OB] = [0; OB]; // @todo We ignore the tags for now @@ -81,7 +81,7 @@ pub fn compute_encrypted_note_log( note: Note ) -> [u8; M] where Note: NoteInterface { // @todo Need to draw randomness from the full domain of Fq not only Fr - let eph_sk: Scalar = fr_to_private_key(unsafe_rand()); + let eph_sk: Scalar = fr_to_fq(unsafe_rand()); let eph_pk = eph_sk.derive_public_key(); // TODO: (#7177) This value needs to be populated! @@ -94,7 +94,7 @@ pub fn compute_encrypted_note_log( let incoming_header_ciphertext: [u8; 48] = header.compute_ciphertext(eph_sk, ivpk); let outgoing_Header_ciphertext: [u8; 48] = header.compute_ciphertext(eph_sk, ovpk); let incoming_body_ciphertext = EncryptedLogIncomingBody::from_note(note, storage_slot).compute_ciphertext(eph_sk, ivpk_app); - let outgoing_body_ciphertext: [u8; 176] = EncryptedLogOutgoingBody::new(eph_sk, recipient, ivpk_app).compute_ciphertext(fr_to_private_key(ovsk_app), eph_pk); + let outgoing_body_ciphertext: [u8; 176] = EncryptedLogOutgoingBody::new(eph_sk, recipient, ivpk_app).compute_ciphertext(fr_to_fq(ovsk_app), eph_pk); let mut encrypted_bytes: [u8; M] = [0; M]; // @todo We ignore the tags for now @@ -129,7 +129,9 @@ pub fn compute_encrypted_note_log( encrypted_bytes } -fn fr_to_private_key(r: Field) -> Scalar { +/// Converts a base field elememt to scalar field element. +/// This is fine because modulus of the base field is smaller than the modulus of the scalar field. +fn fr_to_fq(r: Field) -> Scalar { let r_bytes = r.to_be_bytes(32); let mut high_bytes = [0; 32]; @@ -155,7 +157,7 @@ fn compute_ivpk_app(ivpk: Point, contract_address: AztecAddress) -> Point { // for example user could define ivpk = infinity using the registry assert((ivpk.x != 0) & (ivpk.y != 0), "ivpk is infinite"); - let i = fr_to_private_key(poseidon2_hash([contract_address.to_field(), ivpk.x, ivpk.y, GENERATOR_INDEX__IVSK_M])); + let i = fr_to_fq(poseidon2_hash([contract_address.to_field(), ivpk.x, ivpk.y, GENERATOR_INDEX__IVSK_M])); let I = i.derive_public_key(); let embed_I = Point { x: I.x, y: I.y, is_infinite: false }; diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/scalar.nr b/noir-projects/noir-protocol-circuits/crates/types/src/scalar.nr index 5bb83e55a0e..9ef990e6c72 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/scalar.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/scalar.nr @@ -13,4 +13,4 @@ impl Serialize for Scalar { fn serialize(self) -> [Field; SCALAR_SIZE] { [self.hi, self.lo] } -} \ No newline at end of file +}