diff --git a/aztec/src/encrypted_logs/header.nr b/aztec/src/encrypted_logs/header.nr index 7d660e11..943a9636 100644 --- a/aztec/src/encrypted_logs/header.nr +++ b/aztec/src/encrypted_logs/header.nr @@ -32,15 +32,15 @@ impl EncryptedLogHeader { fn test_encrypted_log_header() { let address = AztecAddress::from_field(0xdeadbeef); let header = EncryptedLogHeader::new(address); - let secret = Scalar::new( - 0x00000000000000000000000000000000649e7ca01d9de27b21624098b897babd, - 0x0000000000000000000000000000000023b3127c127b1f29a7adff5cccf8fb06 - ); - let point = Point::new( - 0x2688431c705a5ff3e6c6f2573c9e3ba1c1026d2251d0dbbf2d810aa53fd1d186, - 0x1e96887b117afca01c00468264f4f80b5bb16d94c1808a448595f115556e5c8e, - false - ); + let secret = Scalar { + lo: 0x00000000000000000000000000000000649e7ca01d9de27b21624098b897babd, + hi: 0x0000000000000000000000000000000023b3127c127b1f29a7adff5cccf8fb06 + }; + let point = Point { + x: 0x2688431c705a5ff3e6c6f2573c9e3ba1c1026d2251d0dbbf2d810aa53fd1d186, + y: 0x1e96887b117afca01c00468264f4f80b5bb16d94c1808a448595f115556e5c8e, + is_infinite: false + }; let ciphertext = header.compute_ciphertext(secret, point); diff --git a/aztec/src/encrypted_logs/incoming_body.nr b/aztec/src/encrypted_logs/incoming_body.nr index c7052bbb..3caaaeb8 100644 --- a/aztec/src/encrypted_logs/incoming_body.nr +++ b/aztec/src/encrypted_logs/incoming_body.nr @@ -118,15 +118,15 @@ mod test { let storage_slot = 2; - let eph_sk = Scalar::new( - 0x00000000000000000000000000000000649e7ca01d9de27b21624098b897babd, - 0x0000000000000000000000000000000023b3127c127b1f29a7adff5cccf8fb06 - ); - let ivpk_app = Point::new( - 0x2688431c705a5ff3e6c6f2573c9e3ba1c1026d2251d0dbbf2d810aa53fd1d186, - 0x1e96887b117afca01c00468264f4f80b5bb16d94c1808a448595f115556e5c8e, - false - ); + let eph_sk = Scalar { + lo: 0x00000000000000000000000000000000649e7ca01d9de27b21624098b897babd, + hi: 0x0000000000000000000000000000000023b3127c127b1f29a7adff5cccf8fb06 + }; + let ivpk_app = Point { + x: 0x2688431c705a5ff3e6c6f2573c9e3ba1c1026d2251d0dbbf2d810aa53fd1d186, + y: 0x1e96887b117afca01c00468264f4f80b5bb16d94c1808a448595f115556e5c8e, + is_infinite: false + }; let body = EncryptedLogIncomingBody::from_note(note, storage_slot); @@ -217,16 +217,16 @@ mod test { fn test_encrypted_log_event_incoming_body() { let test_event = TestEvent { value0: 1, value1: 2, value2: 3 }; - let eph_sk = Scalar::new( - 0x00000000000000000000000000000000649e7ca01d9de27b21624098b897babd, - 0x0000000000000000000000000000000023b3127c127b1f29a7adff5cccf8fb06 - ); + let eph_sk = Scalar { + lo: 0x00000000000000000000000000000000649e7ca01d9de27b21624098b897babd, + hi: 0x0000000000000000000000000000000023b3127c127b1f29a7adff5cccf8fb06 + }; - let ivpk_app = Point::new( - 0x2688431c705a5ff3e6c6f2573c9e3ba1c1026d2251d0dbbf2d810aa53fd1d186, - 0x1e96887b117afca01c00468264f4f80b5bb16d94c1808a448595f115556e5c8e, - false - ); + let ivpk_app = Point { + x: 0x2688431c705a5ff3e6c6f2573c9e3ba1c1026d2251d0dbbf2d810aa53fd1d186, + y: 0x1e96887b117afca01c00468264f4f80b5bb16d94c1808a448595f115556e5c8e, + is_infinite: false + }; let randomness = 2; diff --git a/aztec/src/encrypted_logs/outgoing_body.nr b/aztec/src/encrypted_logs/outgoing_body.nr index c63a54ba..d3cc68d1 100644 --- a/aztec/src/encrypted_logs/outgoing_body.nr +++ b/aztec/src/encrypted_logs/outgoing_body.nr @@ -2,7 +2,6 @@ use dep::protocol_types::{ address::AztecAddress, scalar::Scalar, point::Point, constants::GENERATOR_INDEX__SYMMETRIC_KEY, hash::poseidon2_hash }; - use std::aes128::aes128_encrypt; use crate::keys::point_to_symmetric_key::point_to_symmetric_key; @@ -65,26 +64,27 @@ mod test { address::AztecAddress, traits::Empty, constants::GENERATOR_INDEX__NOTE_NULLIFIER, scalar::Scalar, point::Point, hash::poseidon2_hash }; + use std::embedded_curve_ops::fixed_base_scalar_mul as derive_public_key; use crate::context::PrivateContext; #[test] fn test_encrypted_log_outgoing_body() { - let eph_sk = Scalar::new( - 0x00000000000000000000000000000000d0d302ee245dfaf2807e604eec4715fe, - 0x000000000000000000000000000000000f096b423017226a18461115fa8d34bb - ); - let recipient_ivsk_app = Scalar::new( - 0x000000000000000000000000000000004828f8f95676ebb481df163f87fd4022, - 0x000000000000000000000000000000000f4d97c25d578f9348251a71ca17ae31 - ); - let sender_ovsk_app = Scalar::new( - 0x0000000000000000000000000000000074d2e28c6bc5176ac02cf7c7d36a444e, - 0x00000000000000000000000000000000089c6887cb1446d86c64e81afc78048b - ); - - let eph_pk = eph_sk.derive_public_key(); - let recipient_ivpk_app = recipient_ivsk_app.derive_public_key(); + let eph_sk = Scalar { + lo: 0x00000000000000000000000000000000d0d302ee245dfaf2807e604eec4715fe, + hi: 0x000000000000000000000000000000000f096b423017226a18461115fa8d34bb + }; + let recipient_ivsk_app = Scalar { + lo: 0x000000000000000000000000000000004828f8f95676ebb481df163f87fd4022, + hi: 0x000000000000000000000000000000000f4d97c25d578f9348251a71ca17ae31 + }; + let sender_ovsk_app = Scalar { + lo: 0x0000000000000000000000000000000074d2e28c6bc5176ac02cf7c7d36a444e, + hi: 0x00000000000000000000000000000000089c6887cb1446d86c64e81afc78048b + }; + + let eph_pk = derive_public_key(eph_sk); + let recipient_ivpk_app = derive_public_key(recipient_ivsk_app); let recipient = AztecAddress::from_field(0xdeadbeef); diff --git a/aztec/src/encrypted_logs/payload.nr b/aztec/src/encrypted_logs/payload.nr index d0dbde54..9141fcbe 100644 --- a/aztec/src/encrypted_logs/payload.nr +++ b/aztec/src/encrypted_logs/payload.nr @@ -2,7 +2,7 @@ use dep::protocol_types::{ address::AztecAddress, scalar::Scalar, point::{Point, pub_key_to_bytes}, constants::{GENERATOR_INDEX__IVSK_M, GENERATOR_INDEX__OVSK_M}, hash::poseidon2_hash }; - +use std::embedded_curve_ops::fixed_base_scalar_mul as derive_public_key; use std::field::bytes32_to_field; use crate::oracle::unsafe_rand::unsafe_rand; @@ -25,7 +25,7 @@ pub fn compute_encrypted_event_log( ) -> [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_fq(unsafe_rand()); - let eph_pk = eph_sk.derive_public_key(); + let eph_pk = derive_public_key(eph_sk); // TODO: (#7177) This value needs to be populated! let recipient = AztecAddress::from_field(0); @@ -82,7 +82,7 @@ pub fn compute_encrypted_note_log( ) -> [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_fq(unsafe_rand()); - let eph_pk = eph_sk.derive_public_key(); + let eph_pk = derive_public_key(eph_sk); // TODO: (#7177) This value needs to be populated! let recipient = AztecAddress::from_field(0); @@ -142,10 +142,10 @@ fn fr_to_fq(r: Field) -> Scalar { low_bytes[16 + i] = r_bytes[i + 16]; } - let low = bytes32_to_field(low_bytes); - let high = bytes32_to_field(high_bytes); + let lo = bytes32_to_field(low_bytes); + let hi = bytes32_to_field(high_bytes); - Scalar::new(low, high) + Scalar { lo, hi } } fn compute_ivpk_app(ivpk: Point, contract_address: AztecAddress) -> Point { @@ -158,12 +158,12 @@ fn compute_ivpk_app(ivpk: Point, contract_address: AztecAddress) -> Point { assert((ivpk.x != 0) & (ivpk.y != 0), "ivpk is infinite"); 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 I = derive_public_key(i); let embed_I = Point { x: I.x, y: I.y, is_infinite: false }; let embed_ivpk = Point { x: ivpk.x, y: ivpk.y, is_infinite: false }; let embed_result = embedded_curve_add(embed_I, embed_ivpk); - Point::new(embed_result.x, embed_result.y)*/ + Point { x: embed_result.x, embed_result.y)*/ } diff --git a/aztec/src/keys/getters.nr b/aztec/src/keys/getters.nr index f966b104..372e3a43 100644 --- a/aztec/src/keys/getters.nr +++ b/aztec/src/keys/getters.nr @@ -86,7 +86,7 @@ fn fetch_key_from_registry( let x_coordinate = x_coordinate_registry.get_value_in_private(header); let y_coordinate = y_coordinate_registry.get_value_in_private(header); - Point::new(x_coordinate, y_coordinate, false) + Point { x: x_coordinate, y: y_coordinate, is_infinite: false } } // Passes only when keys were not rotated - is expected to be called only when keys were not registered yet diff --git a/aztec/src/keys/point_to_symmetric_key.nr b/aztec/src/keys/point_to_symmetric_key.nr index caa31734..b3e1c544 100644 --- a/aztec/src/keys/point_to_symmetric_key.nr +++ b/aztec/src/keys/point_to_symmetric_key.nr @@ -19,15 +19,15 @@ pub fn point_to_symmetric_key(secret: Scalar, point: Point) -> [u8; 32] { #[test] fn check_point_to_symmetric_key() { // Value taken from "derive shared secret" test in encrypt_buffer.test.ts - let secret = Scalar::new( - 0x00000000000000000000000000000000649e7ca01d9de27b21624098b897babd, - 0x0000000000000000000000000000000023b3127c127b1f29a7adff5cccf8fb06 - ); - let point = Point::new( - 0x2688431c705a5ff3e6c6f2573c9e3ba1c1026d2251d0dbbf2d810aa53fd1d186, - 0x1e96887b117afca01c00468264f4f80b5bb16d94c1808a448595f115556e5c8e, - false - ); + let secret = Scalar { + lo: 0x00000000000000000000000000000000649e7ca01d9de27b21624098b897babd, + hi: 0x0000000000000000000000000000000023b3127c127b1f29a7adff5cccf8fb06 + }; + let point = Point { + x: 0x2688431c705a5ff3e6c6f2573c9e3ba1c1026d2251d0dbbf2d810aa53fd1d186, + y: 0x1e96887b117afca01c00468264f4f80b5bb16d94c1808a448595f115556e5c8e, + is_infinite: false + }; let key = point_to_symmetric_key(secret, point); // The following value gets updated when running encrypt_buffer.test.ts with AZTEC_GENERATE_TEST_DATA=1 diff --git a/aztec/src/keys/public_keys.nr b/aztec/src/keys/public_keys.nr index 9ad4c01e..ac53b760 100644 --- a/aztec/src/keys/public_keys.nr +++ b/aztec/src/keys/public_keys.nr @@ -96,10 +96,10 @@ impl Serialize for PublicKeys { impl Deserialize for PublicKeys { fn deserialize(serialized: [Field; PUBLIC_KEYS_LENGTH]) -> PublicKeys { PublicKeys { - npk_m: Point::new(serialized[0], serialized[1], serialized[2] as bool), - ivpk_m: Point::new(serialized[3], serialized[4], serialized[5] as bool), - ovpk_m: Point::new(serialized[6], serialized[7], serialized[8] as bool), - tpk_m: Point::new(serialized[9], serialized[10], serialized[11] as bool) + npk_m: Point { x:serialized[0], y:serialized[1], is_infinite: serialized[2] as bool }, + ivpk_m: Point { x:serialized[3], y: serialized[4], is_infinite: serialized[5] as bool }, + ovpk_m: Point { x:serialized[6], y: serialized[7], is_infinite: serialized[8] as bool }, + tpk_m: Point { x:serialized[9], y: serialized[10], is_infinite: serialized[11] as bool } } } } diff --git a/aztec/src/oracle/keys.nr b/aztec/src/oracle/keys.nr index d7bd87c0..92403bf9 100644 --- a/aztec/src/oracle/keys.nr +++ b/aztec/src/oracle/keys.nr @@ -12,10 +12,10 @@ fn get_public_keys_and_partial_address(address: AztecAddress) -> (PublicKeys, Pa let result = get_public_keys_and_partial_address_oracle_wrapper(address); let keys = PublicKeys { - npk_m: Point::new(result[0], result[1], result[2] as bool), - ivpk_m: Point::new(result[3], result[4], result[5] as bool), - ovpk_m: Point::new(result[6], result[7], result[8] as bool), - tpk_m: Point::new(result[9], result[10], result[11] as bool) + npk_m: Point { x: result[0], y: result[1], is_infinite: result[2] as bool }, + ivpk_m: Point { x: result[3], y: result[4], is_infinite: result[5] as bool }, + ovpk_m: Point { x: result[6], y: result[7], is_infinite: result[8] as bool }, + tpk_m: Point { x: result[9], y: result[10], is_infinite: result[11] as bool } }; let partial_address = PartialAddress::from_field(result[12]);