diff --git a/boxes/boxes/react/src/contracts/src/main.nr b/boxes/boxes/react/src/contracts/src/main.nr index 39984e28df7..d0fafea3250 100644 --- a/boxes/boxes/react/src/contracts/src/main.nr +++ b/boxes/boxes/react/src/contracts/src/main.nr @@ -1,6 +1,9 @@ contract BoxReact { - use dep::aztec::prelude::{AztecAddress, PrivateMutable, Map, NoteInterface, NoteHeader, Point}; - use dep::aztec::encrypted_logs::encrypted_note_emission::encode_and_encrypt_note_with_keys; + use dep::aztec::{ + keys::public_keys::{IvpkM, OvpkM}, + prelude::{AztecAddress, PrivateMutable, Map, NoteInterface, NoteHeader, Point}, + encrypted_logs::encrypted_note_emission::encode_and_encrypt_note_with_keys + }; use dep::value_note::value_note::{ValueNote, VALUE_NOTE_LEN}; #[aztec(storage)] @@ -14,8 +17,8 @@ contract BoxReact { number: Field, owner: AztecAddress, owner_npk_m_hash: Field, - owner_ovpk_m: Point, - owner_ivpk_m: Point + owner_ovpk_m: OvpkM, + owner_ivpk_m: IvpkM ) { let numbers = storage.numbers; let mut new_number = ValueNote::new(number, owner_npk_m_hash); @@ -27,8 +30,8 @@ contract BoxReact { number: Field, owner: AztecAddress, owner_npk_m_hash: Field, - owner_ovpk_m: Point, - owner_ivpk_m: Point + owner_ovpk_m: OvpkM, + owner_ivpk_m: IvpkM ) { let numbers = storage.numbers; let mut new_number = ValueNote::new(number, owner_npk_m_hash); diff --git a/boxes/boxes/react/src/hooks/useContract.tsx b/boxes/boxes/react/src/hooks/useContract.tsx index 7f3cb2bd7bb..ef27dc32a3f 100644 --- a/boxes/boxes/react/src/hooks/useContract.tsx +++ b/boxes/boxes/react/src/hooks/useContract.tsx @@ -22,8 +22,8 @@ export function useContract() { Fr.random(), wallet.getCompleteAddress().address, masterNullifierPublicKey.hash(), - masterOutgoingViewingPublicKey.toNoirStruct(), - masterIncomingViewingPublicKey.toNoirStruct(), + masterOutgoingViewingPublicKey.toWrappedNoirStruct(), + masterIncomingViewingPublicKey.toWrappedNoirStruct(), ).send({ contractAddressSalt: salt, }); diff --git a/boxes/boxes/react/src/hooks/useNumber.tsx b/boxes/boxes/react/src/hooks/useNumber.tsx index 602d91e89db..6550e9e79ac 100644 --- a/boxes/boxes/react/src/hooks/useNumber.tsx +++ b/boxes/boxes/react/src/hooks/useNumber.tsx @@ -33,8 +33,8 @@ export function useNumber({ contract }: { contract: Contract }) { value, deployerWallet.getCompleteAddress().address, masterNullifierPublicKey.hash(), - masterOutgoingViewingPublicKey.toNoirStruct(), - masterIncomingViewingPublicKey.toNoirStruct(), + masterOutgoingViewingPublicKey.toWrappedNoirStruct(), + masterIncomingViewingPublicKey.toWrappedNoirStruct(), ) .send() .wait(), diff --git a/boxes/boxes/react/tests/node.test.ts b/boxes/boxes/react/tests/node.test.ts index 65a3f2b6ff0..34d3ef52ea3 100644 --- a/boxes/boxes/react/tests/node.test.ts +++ b/boxes/boxes/react/tests/node.test.ts @@ -21,8 +21,8 @@ describe('BoxReact Contract Tests', () => { Fr.random(), accountCompleteAddress.address, masterNullifierPublicKey.hash(), - masterOutgoingViewingPublicKey.toNoirStruct(), - masterIncomingViewingPublicKey.toNoirStruct(), + masterOutgoingViewingPublicKey.toWrappedNoirStruct(), + masterIncomingViewingPublicKey.toWrappedNoirStruct(), ) .send({ contractAddressSalt: salt }) .deployed(); @@ -39,8 +39,8 @@ describe('BoxReact Contract Tests', () => { numberToSet, accountCompleteAddress.address, masterNullifierPublicKey.hash(), - masterOutgoingViewingPublicKey.toNoirStruct(), - masterIncomingViewingPublicKey.toNoirStruct(), + masterOutgoingViewingPublicKey.toWrappedNoirStruct(), + masterIncomingViewingPublicKey.toWrappedNoirStruct(), ) .send() .wait(); diff --git a/boxes/boxes/vanilla/src/contracts/src/main.nr b/boxes/boxes/vanilla/src/contracts/src/main.nr index 9d08c789e32..401a2c86989 100644 --- a/boxes/boxes/vanilla/src/contracts/src/main.nr +++ b/boxes/boxes/vanilla/src/contracts/src/main.nr @@ -1,6 +1,9 @@ contract Vanilla { - use dep::aztec::prelude::{AztecAddress, PrivateMutable, Map, NoteInterface, NoteHeader, Point}; - use dep::aztec::encrypted_logs::encrypted_note_emission::encode_and_encrypt_note_with_keys; + use dep::aztec::{ + keys::public_keys::{IvpkM, OvpkM}, + prelude::{AztecAddress, PrivateMutable, Map, NoteInterface, NoteHeader, Point}, + encrypted_logs::encrypted_note_emission::encode_and_encrypt_note_with_keys + }; use dep::value_note::value_note::{ValueNote, VALUE_NOTE_LEN}; #[aztec(storage)] @@ -14,8 +17,8 @@ contract Vanilla { number: Field, owner: AztecAddress, owner_npk_m_hash: Field, - owner_ovpk_m: Point, - owner_ivpk_m: Point + owner_ovpk_m: OvpkM, + owner_ivpk_m: IvpkM ) { let numbers = storage.numbers; let mut new_number = ValueNote::new(number, owner_npk_m_hash); @@ -27,8 +30,8 @@ contract Vanilla { number: Field, owner: AztecAddress, owner_npk_m_hash: Field, - owner_ovpk_m: Point, - owner_ivpk_m: Point + owner_ovpk_m: OvpkM, + owner_ivpk_m: IvpkM ) { let numbers = storage.numbers; let mut new_number = ValueNote::new(number, owner_npk_m_hash); diff --git a/boxes/boxes/vanilla/src/index.ts b/boxes/boxes/vanilla/src/index.ts index e9ee08284fa..2b9d7e977a4 100644 --- a/boxes/boxes/vanilla/src/index.ts +++ b/boxes/boxes/vanilla/src/index.ts @@ -27,8 +27,8 @@ document.querySelector('#deploy').addEventListener('click', async ({ target }: a Fr.random(), wallet.getCompleteAddress().address, masterNullifierPublicKey.hash(), - masterOutgoingViewingPublicKey.toNoirStruct(), - masterIncomingViewingPublicKey.toNoirStruct(), + masterOutgoingViewingPublicKey.toWrappedNoirStruct(), + masterIncomingViewingPublicKey.toWrappedNoirStruct(), ) .send({ contractAddressSalt: Fr.random() }) .deployed(); @@ -51,8 +51,8 @@ document.querySelector('#set').addEventListener('submit', async (e: Event) => { parseInt(value), owner, masterNullifierPublicKey.hash(), - masterOutgoingViewingPublicKey.toNoirStruct(), - masterIncomingViewingPublicKey.toNoirStruct(), + masterOutgoingViewingPublicKey.toWrappedNoirStruct(), + masterIncomingViewingPublicKey.toWrappedNoirStruct(), ) .send() .wait(); diff --git a/noir-projects/aztec-nr/aztec/src/encrypted_logs/encrypted_event_emission.nr b/noir-projects/aztec-nr/aztec/src/encrypted_logs/encrypted_event_emission.nr index b3334c37c8f..90752c29467 100644 --- a/noir-projects/aztec-nr/aztec/src/encrypted_logs/encrypted_event_emission.nr +++ b/noir-projects/aztec-nr/aztec/src/encrypted_logs/encrypted_event_emission.nr @@ -1,16 +1,17 @@ use crate::{ context::PrivateContext, event::event_interface::EventInterface, - encrypted_logs::payload::compute_encrypted_event_log, keys::getters::get_current_public_keys, + encrypted_logs::payload::compute_encrypted_event_log, + keys::{getters::get_current_public_keys, public_keys::{OvpkM, IvpkM}}, oracle::logs_traits::LensForEncryptedEvent, oracle::unsafe_rand::unsafe_rand }; -use dep::protocol_types::{address::AztecAddress, point::Point, hash::sha256_to_field}; +use dep::protocol_types::{address::AztecAddress, hash::sha256_to_field}; unconstrained fn compute_unconstrained( contract_address: AztecAddress, randomness: Field, ovsk_app: Field, - ovpk: Point, - ivpk: Point, + ovpk: OvpkM, + ivpk: IvpkM, recipient: AztecAddress, event: Event ) -> ([u8; OB], Field) where Event: EventInterface, [u8; NB]: LensForEncryptedEvent { @@ -29,8 +30,8 @@ fn compute( contract_address: AztecAddress, randomness: Field, ovsk_app: Field, - ovpk: Point, - ivpk: Point, + ovpk: OvpkM, + ivpk: IvpkM, recipient: AztecAddress, event: Event ) -> ([u8; OB], Field) where Event: EventInterface, [u8; NB]: LensForEncryptedEvent { @@ -51,10 +52,10 @@ fn emit_with_keys( context: &mut PrivateContext, randomness: Field, event: Event, - ovpk: Point, - ivpk: Point, + ovpk: OvpkM, + ivpk: IvpkM, iv: AztecAddress, - inner_compute: fn(AztecAddress, Field, Field, Point, Point, AztecAddress, Event) -> ([u8; OB], Field) + inner_compute: fn(AztecAddress, Field, Field, OvpkM, IvpkM, AztecAddress, Event) -> ([u8; OB], Field) ) where Event: EventInterface, [u8; NB]: LensForEncryptedEvent { let contract_address: AztecAddress = context.this_address(); let ovsk_app: Field = context.request_ovsk_app(ovpk.hash()); @@ -116,10 +117,10 @@ pub fn encode_and_encrypt_event_with_randomness_unconstrained( context: &mut PrivateContext, - ovpk: Point, - ivpk: Point, + ovpk: OvpkM, + ivpk: IvpkM, recipient: AztecAddress -) -> fn[(&mut PrivateContext, Point, Point, AztecAddress)](Event) -> () where Event: EventInterface, [u8; NB]: LensForEncryptedEvent { +) -> fn[(&mut PrivateContext, OvpkM, IvpkM, AztecAddress)](Event) -> () where Event: EventInterface, [u8; NB]: LensForEncryptedEvent { | e: Event | { let randomness = unsafe_rand(); emit_with_keys(context, randomness, e, ovpk, ivpk, recipient, compute); @@ -128,10 +129,10 @@ pub fn encode_and_encrypt_event_with_keys( context: &mut PrivateContext, - ovpk: Point, - ivpk: Point, + ovpk: OvpkM, + ivpk: IvpkM, recipient: AztecAddress -) -> fn[(&mut PrivateContext, Point, Point, AztecAddress)](Event) -> () where Event: EventInterface, [u8; NB]: LensForEncryptedEvent { +) -> fn[(&mut PrivateContext, OvpkM, IvpkM, AztecAddress)](Event) -> () where Event: EventInterface, [u8; NB]: LensForEncryptedEvent { | e: Event | { let randomness = unsafe_rand(); emit_with_keys(context, randomness, e, ovpk, ivpk, recipient, compute_unconstrained); @@ -141,10 +142,10 @@ pub fn encode_and_encrypt_event_with_keys_unconstrained( context: &mut PrivateContext, randomness: Field, - ovpk: Point, - ivpk: Point, + ovpk: OvpkM, + ivpk: IvpkM, recipient: AztecAddress -) -> fn[(&mut PrivateContext, Field, Point, Point, AztecAddress)](Event) -> () where Event: EventInterface, [u8; NB]: LensForEncryptedEvent { +) -> fn[(&mut PrivateContext, Field, OvpkM, IvpkM, AztecAddress)](Event) -> () where Event: EventInterface, [u8; NB]: LensForEncryptedEvent { | e: Event | { emit_with_keys(context, randomness, e, ovpk, ivpk, recipient, compute); } @@ -153,10 +154,10 @@ pub fn encode_and_encrypt_event_with_keys_with_randomness( context: &mut PrivateContext, randomness: Field, - ovpk: Point, - ivpk: Point, + ovpk: OvpkM, + ivpk: IvpkM, recipient: AztecAddress -) -> fn[(&mut PrivateContext, Field, Point, Point, AztecAddress)](Event) -> () where Event: EventInterface, [u8; NB]: LensForEncryptedEvent { +) -> fn[(&mut PrivateContext, Field, OvpkM, IvpkM, AztecAddress)](Event) -> () where Event: EventInterface, [u8; NB]: LensForEncryptedEvent { | e: Event | { emit_with_keys(context, randomness, e, ovpk, ivpk, recipient, compute_unconstrained); } diff --git a/noir-projects/aztec-nr/aztec/src/encrypted_logs/encrypted_note_emission.nr b/noir-projects/aztec-nr/aztec/src/encrypted_logs/encrypted_note_emission.nr index 03f6eeaa9c9..542c0830e8d 100644 --- a/noir-projects/aztec-nr/aztec/src/encrypted_logs/encrypted_note_emission.nr +++ b/noir-projects/aztec-nr/aztec/src/encrypted_logs/encrypted_note_emission.nr @@ -1,7 +1,7 @@ use crate::{ context::PrivateContext, note::{note_emission::NoteEmission, note_interface::NoteInterface}, - keys::getters::get_current_public_keys, encrypted_logs::payload::compute_encrypted_note_log, - oracle::logs_traits::LensForEncryptedLog + keys::{getters::get_current_public_keys, public_keys::{OvpkM, IvpkM}}, + encrypted_logs::payload::compute_encrypted_note_log, oracle::logs_traits::LensForEncryptedLog }; use dep::protocol_types::{ hash::sha256_to_field, address::AztecAddress, point::Point, abis::note_hash::NoteHash, @@ -12,8 +12,8 @@ unconstrained fn compute_unconstrained ([u8; M], Field) where Note: NoteInterface, [Field; N]: LensForEncryptedLog { @@ -32,8 +32,8 @@ fn compute( contract_address: AztecAddress, storage_slot: Field, ovsk_app: Field, - ovpk: Point, - ivpk: Point, + ovpk: OvpkM, + ivpk: IvpkM, recipient: AztecAddress, note: Note ) -> ([u8; M], Field) where Note: NoteInterface, [Field; N]: LensForEncryptedLog { @@ -53,10 +53,10 @@ fn compute( fn emit_with_keys( context: &mut PrivateContext, note: Note, - ovpk: Point, - ivpk: Point, + ovpk: OvpkM, + ivpk: IvpkM, recipient: AztecAddress, - inner_compute: fn(AztecAddress, Field, Field, Point, Point, AztecAddress, Note) -> ([u8; M], Field) + inner_compute: fn(AztecAddress, Field, Field, OvpkM, IvpkM, AztecAddress, Note) -> ([u8; M], Field) ) where Note: NoteInterface, [Field; N]: LensForEncryptedLog { let note_header = note.get_header(); let note_hash_counter = note_header.note_hash_counter; @@ -107,10 +107,10 @@ pub fn encode_and_encrypt_note_unconstrained( context: &mut PrivateContext, - ovpk: Point, - ivpk: Point, + ovpk: OvpkM, + ivpk: IvpkM, recipient: AztecAddress -) -> fn[(&mut PrivateContext, Point, Point, AztecAddress)](NoteEmission) -> () where Note: NoteInterface, [Field; N]: LensForEncryptedLog { +) -> fn[(&mut PrivateContext, OvpkM, IvpkM, AztecAddress)](NoteEmission) -> () where Note: NoteInterface, [Field; N]: LensForEncryptedLog { | e: NoteEmission | { emit_with_keys(context, e.note, ovpk, ivpk, recipient, compute); } @@ -118,10 +118,10 @@ pub fn encode_and_encrypt_note_with_keys( context: &mut PrivateContext, - ovpk: Point, - ivpk: Point, + ovpk: OvpkM, + ivpk: IvpkM, recipient: AztecAddress -) -> fn[(&mut PrivateContext, Point, Point, AztecAddress)](NoteEmission) -> () where Note: NoteInterface, [Field; N]: LensForEncryptedLog { +) -> fn[(&mut PrivateContext, OvpkM, IvpkM, AztecAddress)](NoteEmission) -> () where Note: NoteInterface, [Field; N]: LensForEncryptedLog { | e: NoteEmission | { emit_with_keys(context, e.note, ovpk, ivpk, recipient, compute_unconstrained); } diff --git a/noir-projects/aztec-nr/aztec/src/encrypted_logs/header.nr b/noir-projects/aztec-nr/aztec/src/encrypted_logs/header.nr index 66fa4d22c43..f43c60b6b60 100644 --- a/noir-projects/aztec-nr/aztec/src/encrypted_logs/header.nr +++ b/noir-projects/aztec-nr/aztec/src/encrypted_logs/header.nr @@ -1,6 +1,6 @@ use dep::protocol_types::{address::AztecAddress, scalar::Scalar, point::Point}; -use crate::keys::point_to_symmetric_key::point_to_symmetric_key; +use crate::keys::{point_to_symmetric_key::point_to_symmetric_key, public_keys::ToPoint}; use std::aes128::aes128_encrypt; @@ -13,8 +13,8 @@ impl EncryptedLogHeader { EncryptedLogHeader { address } } - fn compute_ciphertext(self, secret: Scalar, point: Point) -> [u8; 48] { - let full_key = point_to_symmetric_key(secret, point); + fn compute_ciphertext(self, secret: Scalar, pk: T) -> [u8; 48] where T: ToPoint { + let full_key = point_to_symmetric_key(secret, pk.to_point()); let mut sym_key = [0; 16]; let mut iv = [0; 16]; @@ -36,10 +36,12 @@ fn test_encrypted_log_header_matches_noir() { lo: 0x00000000000000000000000000000000649e7ca01d9de27b21624098b897babd, hi: 0x0000000000000000000000000000000023b3127c127b1f29a7adff5cccf8fb06 }; - let point = Point { - x: 0x2688431c705a5ff3e6c6f2573c9e3ba1c1026d2251d0dbbf2d810aa53fd1d186, - y: 0x1e96887b117afca01c00468264f4f80b5bb16d94c1808a448595f115556e5c8e, - is_infinite: false + let point = crate::keys::public_keys::IvpkM { + inner: Point { + x: 0x2688431c705a5ff3e6c6f2573c9e3ba1c1026d2251d0dbbf2d810aa53fd1d186, + y: 0x1e96887b117afca01c00468264f4f80b5bb16d94c1808a448595f115556e5c8e, + is_infinite: false + } }; let ciphertext = header.compute_ciphertext(secret, point); diff --git a/noir-projects/aztec-nr/aztec/src/encrypted_logs/incoming_body.nr b/noir-projects/aztec-nr/aztec/src/encrypted_logs/incoming_body.nr index 9ad6eb71f0c..84077a2defb 100644 --- a/noir-projects/aztec-nr/aztec/src/encrypted_logs/incoming_body.nr +++ b/noir-projects/aztec-nr/aztec/src/encrypted_logs/incoming_body.nr @@ -3,7 +3,7 @@ use crate::event::event_interface::EventInterface; use dep::protocol_types::{scalar::Scalar, point::Point}; use std::aes128::aes128_encrypt; -use crate::keys::point_to_symmetric_key::point_to_symmetric_key; +use crate::keys::{point_to_symmetric_key::point_to_symmetric_key, public_keys::IvpkM}; struct EncryptedLogIncomingBody { plaintext: [u8; M] @@ -23,8 +23,8 @@ impl EncryptedLogIncomingBody { EncryptedLogIncomingBody { plaintext } } - pub fn compute_ciphertext(self, eph_sk: Scalar, ivpk: Point) -> [u8] { - let full_key = point_to_symmetric_key(eph_sk, ivpk); + pub fn compute_ciphertext(self, eph_sk: Scalar, ivpk: IvpkM) -> [u8] { + let full_key = point_to_symmetric_key(eph_sk, ivpk.to_point()); let mut sym_key = [0; 16]; let mut iv = [0; 16]; @@ -45,7 +45,7 @@ mod test { use crate::{ note::{note_header::NoteHeader, note_interface::NoteInterface}, encrypted_logs::incoming_body::EncryptedLogIncomingBody, event::event_interface::EventInterface, - context::PrivateContext + context::PrivateContext, keys::public_keys::IvpkM }; struct AddressNote { @@ -129,10 +129,12 @@ mod test { lo: 0x00000000000000000000000000000000649e7ca01d9de27b21624098b897babd, hi: 0x0000000000000000000000000000000023b3127c127b1f29a7adff5cccf8fb06 }; - let ivpk = Point { - x: 0x2688431c705a5ff3e6c6f2573c9e3ba1c1026d2251d0dbbf2d810aa53fd1d186, - y: 0x1e96887b117afca01c00468264f4f80b5bb16d94c1808a448595f115556e5c8e, - is_infinite: false + let ivpk = IvpkM { + inner: Point { + x: 0x2688431c705a5ff3e6c6f2573c9e3ba1c1026d2251d0dbbf2d810aa53fd1d186, + y: 0x1e96887b117afca01c00468264f4f80b5bb16d94c1808a448595f115556e5c8e, + is_infinite: false + } }; /// 1. `EncryptedLogIncomingBody::from_note` calls `note.to_be_bytes(storage_slot)` function which serializes @@ -236,10 +238,12 @@ mod test { hi: 0x0000000000000000000000000000000023b3127c127b1f29a7adff5cccf8fb06 }; - let ivpk = Point { - x: 0x2688431c705a5ff3e6c6f2573c9e3ba1c1026d2251d0dbbf2d810aa53fd1d186, - y: 0x1e96887b117afca01c00468264f4f80b5bb16d94c1808a448595f115556e5c8e, - is_infinite: false + let ivpk = IvpkM { + inner: Point { + x: 0x2688431c705a5ff3e6c6f2573c9e3ba1c1026d2251d0dbbf2d810aa53fd1d186, + y: 0x1e96887b117afca01c00468264f4f80b5bb16d94c1808a448595f115556e5c8e, + is_infinite: false + } }; let randomness = 2; diff --git a/noir-projects/aztec-nr/aztec/src/encrypted_logs/outgoing_body.nr b/noir-projects/aztec-nr/aztec/src/encrypted_logs/outgoing_body.nr index e396c4a3d38..96c35c68a75 100644 --- a/noir-projects/aztec-nr/aztec/src/encrypted_logs/outgoing_body.nr +++ b/noir-projects/aztec-nr/aztec/src/encrypted_logs/outgoing_body.nr @@ -4,16 +4,16 @@ use dep::protocol_types::{ }; use std::aes128::aes128_encrypt; -use crate::{keys::point_to_symmetric_key::point_to_symmetric_key, utils::point::point_to_bytes}; +use crate::{keys::public_keys::IvpkM, utils::point::point_to_bytes}; struct EncryptedLogOutgoingBody { eph_sk: Scalar, recipient: AztecAddress, - recipient_ivpk: Point, + recipient_ivpk: IvpkM, } impl EncryptedLogOutgoingBody { - pub fn new(eph_sk: Scalar, recipient: AztecAddress, recipient_ivpk: Point) -> Self { + pub fn new(eph_sk: Scalar, recipient: AztecAddress, recipient_ivpk: IvpkM) -> Self { Self { eph_sk, recipient, recipient_ivpk } } @@ -29,7 +29,7 @@ impl EncryptedLogOutgoingBody { let serialized_eph_sk_low = self.eph_sk.lo.to_be_bytes(32); let address_bytes = self.recipient.to_field().to_be_bytes(32); - let serialized_recipient_ivpk = point_to_bytes(self.recipient_ivpk); + let serialized_recipient_ivpk = point_to_bytes(self.recipient_ivpk.to_point()); for i in 0..32 { buffer[i] = serialized_eph_sk_high[i]; @@ -58,7 +58,7 @@ impl EncryptedLogOutgoingBody { } mod test { - use crate::encrypted_logs::outgoing_body::EncryptedLogOutgoingBody; + use crate::{encrypted_logs::outgoing_body::EncryptedLogOutgoingBody, keys::public_keys::IvpkM}; use dep::protocol_types::{ address::AztecAddress, traits::Empty, constants::GENERATOR_INDEX__NOTE_NULLIFIER, scalar::Scalar, point::Point, hash::poseidon2_hash_with_separator @@ -83,7 +83,7 @@ mod test { }; let eph_pk = derive_public_key(eph_sk); - let recipient_ivpk = derive_public_key(recipient_ivsk); + let recipient_ivpk = IvpkM { inner: derive_public_key(recipient_ivsk) }; let recipient = AztecAddress::from_field(0xdeadbeef); 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 37fc5e3b130..84c7a9eacbf 100644 --- a/noir-projects/aztec-nr/aztec/src/encrypted_logs/payload.nr +++ b/noir-projects/aztec-nr/aztec/src/encrypted_logs/payload.nr @@ -10,15 +10,16 @@ use crate::{ encrypted_logs::{ header::EncryptedLogHeader, incoming_body::EncryptedLogIncomingBody, outgoing_body::EncryptedLogOutgoingBody -} +}, + keys::public_keys::{OvpkM, IvpkM} }; pub fn compute_encrypted_event_log( contract_address: AztecAddress, randomness: Field, ovsk_app: Field, - ovpk: Point, - ivpk: Point, + ovpk: OvpkM, + ivpk: IvpkM, recipient: AztecAddress, event: Event ) -> [u8; OB] where Event: EventInterface { @@ -32,7 +33,7 @@ pub fn compute_encrypted_event_log let outgoing_body_ciphertext: [u8; 144] = EncryptedLogOutgoingBody::new(eph_sk, recipient, ivpk).compute_ciphertext(fr_to_fq(ovsk_app), eph_pk); let mut encrypted_bytes: [u8; OB] = [0; OB]; - // @todo We ignore the tags for now + // @todo We ignore the tags for now let eph_pk_bytes = point_to_bytes(eph_pk); for i in 0..32 { @@ -68,8 +69,8 @@ pub fn compute_encrypted_note_log( contract_address: AztecAddress, storage_slot: Field, ovsk_app: Field, - ovpk: Point, - ivpk: Point, + ovpk: OvpkM, + ivpk: IvpkM, recipient: AztecAddress, note: Note ) -> [u8; M] where Note: NoteInterface { @@ -83,7 +84,7 @@ pub fn compute_encrypted_note_log( let outgoing_body_ciphertext: [u8; 144] = EncryptedLogOutgoingBody::new(eph_sk, recipient, ivpk).compute_ciphertext(fr_to_fq(ovsk_app), eph_pk); let mut encrypted_bytes: [u8; M] = [0; M]; - // @todo We ignore the tags for now + // @todo We ignore the tags for now let eph_pk_bytes = point_to_bytes(eph_pk); for i in 0..32 { @@ -134,7 +135,10 @@ fn generate_ephemeral_key_pair() -> (Scalar, Point) { } mod test { - use crate::{encrypted_logs::payload::compute_encrypted_note_log, test::mocks::mock_note::MockNoteBuilder}; + use crate::{ + encrypted_logs::payload::compute_encrypted_note_log, keys::public_keys::{OvpkM, IvpkM}, + test::mocks::mock_note::MockNoteBuilder + }; use dep::protocol_types::{address::AztecAddress, point::Point}; use std::test::OracleMock; @@ -144,15 +148,19 @@ mod test { let contract_address = AztecAddress::from_field(0x10f48cd9eff7ae5b209c557c70de2e657ee79166868676b787e9417e19260e04); let storage_slot = 0x0fe46be583b71f4ab5b70c2657ff1d05cccf1d292a9369628d1a194f944e6599; let ovsk_app = 0x03a6513d6def49f41d20373d2cec894c23e7492794b08fc50c0e8a1bd2512612; - let ovpk_m = Point { - x: 0x1961448682803198631f299340e4206bb12809d4bebbf012b30f59af73ba1a15, - y: 0x133674060c3925142aceb4f1dcd9f9137d0217d37ff8729ee5ceaa6e2790353d, - is_infinite: false + let ovpk_m = OvpkM { + inner: Point { + x: 0x1961448682803198631f299340e4206bb12809d4bebbf012b30f59af73ba1a15, + y: 0x133674060c3925142aceb4f1dcd9f9137d0217d37ff8729ee5ceaa6e2790353d, + is_infinite: false + } }; - let ivpk_m = Point { - x: 0x260cd3904f6df16e974c29944fdc839e40fb5cf293f03df2eb370851d3a527bc, - y: 0x0eef2964fe6640e84c82b5d2915892409b38e9e25d39f68dd79edb725c55387f, - is_infinite: false + let ivpk_m = IvpkM { + inner: Point { + x: 0x260cd3904f6df16e974c29944fdc839e40fb5cf293f03df2eb370851d3a527bc, + y: 0x0eef2964fe6640e84c82b5d2915892409b38e9e25d39f68dd79edb725c55387f, + is_infinite: false + } }; let note_value = 0x301640ceea758391b2e161c92c0513f129020f4125256afdae2646ce31099f5c; diff --git a/noir-projects/aztec-nr/aztec/src/keys/public_keys.nr b/noir-projects/aztec-nr/aztec/src/keys/public_keys.nr index 4dff5713fca..119396cfcb9 100644 --- a/noir-projects/aztec-nr/aztec/src/keys/public_keys.nr +++ b/noir-projects/aztec-nr/aztec/src/keys/public_keys.nr @@ -1,35 +1,111 @@ use dep::protocol_types::{ address::PublicKeysHash, constants::GENERATOR_INDEX__PUBLIC_KEYS_HASH, - hash::poseidon2_hash_with_separator, point::Point, traits::{Deserialize, Serialize, Empty, is_empty} + hash::poseidon2_hash_with_separator, point::{Point, POINT_LENGTH}, + traits::{Deserialize, Serialize, Empty, is_empty, Hash} }; -use crate::keys::constants::{NUM_KEY_TYPES, NULLIFIER_INDEX, INCOMING_INDEX, OUTGOING_INDEX}; +use crate::keys::constants::{NULLIFIER_INDEX, INCOMING_INDEX, OUTGOING_INDEX}; global PUBLIC_KEYS_LENGTH: u32 = 12; struct PublicKeys { - npk_m: Point, - ivpk_m: Point, - ovpk_m: Point, - tpk_m: Point, + npk_m: NpkM, + ivpk_m: IvpkM, + ovpk_m: OvpkM, + tpk_m: TpkM, +} + +trait ToPoint { + fn to_point(self) -> Point; +} + +struct NpkM { + inner: Point +} + +impl ToPoint for NpkM { + fn to_point(self) -> Point { + self.inner + } +} + +impl Serialize for NpkM { + fn serialize(self) -> [Field; POINT_LENGTH] { + self.inner.serialize() + } +} + +// Note: If we store npk_m_hash directly we can remove this trait implementation. See #8091 +impl Hash for NpkM { + fn hash(self) -> Field { + self.inner.hash() + } +} + +struct IvpkM { + inner: Point +} + +impl ToPoint for IvpkM { + fn to_point(self) -> Point { + self.inner + } +} + +impl Serialize for IvpkM { + fn serialize(self) -> [Field; POINT_LENGTH] { + self.inner.serialize() + } +} + +struct OvpkM { + inner: Point +} + +impl Hash for OvpkM { + fn hash(self) -> Field { + self.inner.hash() + } +} + +impl ToPoint for OvpkM { + fn to_point(self) -> Point { + self.inner + } +} + +impl Serialize for OvpkM { + fn serialize(self) -> [Field; POINT_LENGTH] { + self.inner.serialize() + } +} + +struct TpkM { + inner: Point +} + +impl ToPoint for TpkM { + fn to_point(self) -> Point { + self.inner + } } impl Empty for PublicKeys { fn empty() -> Self { PublicKeys { - npk_m : Point::empty(), - ivpk_m : Point::empty(), - ovpk_m : Point::empty(), - tpk_m : Point::empty() + npk_m : NpkM { inner: Point::empty() }, + ivpk_m : IvpkM { inner: Point::empty() }, + ovpk_m : OvpkM { inner: Point::empty() }, + tpk_m : TpkM { inner: Point::empty() } } } } impl Eq for PublicKeys { fn eq(self, other: PublicKeys) -> bool { - ( self.npk_m == other.npk_m ) & - ( self.ivpk_m == other.ivpk_m ) & - ( self.ovpk_m == other.ovpk_m ) & - ( self.tpk_m == other.tpk_m ) + ( self.npk_m.inner == other.npk_m.inner ) & + ( self.ivpk_m.inner == other.ivpk_m.inner ) & + ( self.ovpk_m.inner == other.ovpk_m.inner ) & + ( self.tpk_m.inner == other.tpk_m.inner ) } } @@ -39,56 +115,27 @@ impl PublicKeys { if is_empty(self) { 0 } else { - poseidon2_hash_with_separator( - [ - self.npk_m.x, - self.npk_m.y, - self.npk_m.is_infinite as Field, - self.ivpk_m.x, - self.ivpk_m.y, - self.ivpk_m.is_infinite as Field, - self.ovpk_m.x, - self.ovpk_m.y, - self.ovpk_m.is_infinite as Field, - self.tpk_m.x, - self.tpk_m.y, - self.tpk_m.is_infinite as Field - ], - GENERATOR_INDEX__PUBLIC_KEYS_HASH as Field - ) + poseidon2_hash_with_separator(self.serialize(), GENERATOR_INDEX__PUBLIC_KEYS_HASH as Field) } ) } - - pub fn get_key_by_index(self, index: Field) -> Point { - assert(index as u8 < NUM_KEY_TYPES, "Invalid key index"); - if index == NULLIFIER_INDEX { - self.npk_m - } else if index == INCOMING_INDEX { - self.ivpk_m - } else if index == OUTGOING_INDEX { - self.ovpk_m - } else { - self.tpk_m - } - } } impl Serialize for PublicKeys { fn serialize(self) -> [Field; PUBLIC_KEYS_LENGTH] { [ - self.npk_m.x, - self.npk_m.y, - self.npk_m.is_infinite as Field, - self.ivpk_m.x, - self.ivpk_m.y, - self.ivpk_m.is_infinite as Field, - self.ovpk_m.x, - self.ovpk_m.y, - self.ovpk_m.is_infinite as Field, - self.tpk_m.x, - self.tpk_m.y, - self.tpk_m.is_infinite as Field + self.npk_m.inner.x, + self.npk_m.inner.y, + self.npk_m.inner.is_infinite as Field, + self.ivpk_m.inner.x, + self.ivpk_m.inner.y, + self.ivpk_m.inner.is_infinite as Field, + self.ovpk_m.inner.x, + self.ovpk_m.inner.y, + self.ovpk_m.inner.is_infinite as Field, + self.tpk_m.inner.x, + self.tpk_m.inner.y, + self.tpk_m.inner.is_infinite as Field ] } } @@ -96,10 +143,10 @@ impl Serialize for PublicKeys { impl Deserialize for PublicKeys { fn deserialize(serialized: [Field; PUBLIC_KEYS_LENGTH]) -> PublicKeys { PublicKeys { - 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 } + npk_m: NpkM { inner: Point { x:serialized[0], y:serialized[1], is_infinite: serialized[2] as bool } }, + ivpk_m: IvpkM { inner: Point { x:serialized[3], y: serialized[4], is_infinite: serialized[5] as bool } }, + ovpk_m: OvpkM { inner: Point { x:serialized[6], y: serialized[7], is_infinite: serialized[8] as bool } }, + tpk_m: TpkM { inner: Point { x:serialized[9], y: serialized[10], is_infinite: serialized[11] as bool } } } } } @@ -107,10 +154,10 @@ impl Deserialize for PublicKeys { #[test] fn compute_public_keys_hash() { let keys = PublicKeys { - npk_m: Point { x: 1, y: 2, is_infinite: false }, - ivpk_m: Point { x: 3, y: 4, is_infinite: false }, - ovpk_m: Point { x: 5, y: 6, is_infinite: false }, - tpk_m: Point { x: 7, y: 8, is_infinite: false } + npk_m: NpkM { inner: Point { x: 1, y: 2, is_infinite: false } }, + ivpk_m: IvpkM { inner: Point { x: 3, y: 4, is_infinite: false } }, + ovpk_m: OvpkM { inner: Point { x: 5, y: 6, is_infinite: false } }, + tpk_m: TpkM { inner: Point { x: 7, y: 8, is_infinite: false } } }; let actual = keys.hash(); @@ -132,21 +179,21 @@ fn compute_empty_hash() { #[test] fn test_public_keys_serialization() { let keys = PublicKeys { - npk_m: Point { x: 1, y: 2, is_infinite: false }, - ivpk_m: Point { x: 3, y: 4, is_infinite: false }, - ovpk_m: Point { x: 5, y: 6, is_infinite: false }, - tpk_m: Point { x: 7, y: 8, is_infinite: false } + npk_m: NpkM { inner: Point { x: 1, y: 2, is_infinite: false } }, + ivpk_m: IvpkM { inner: Point { x: 3, y: 4, is_infinite: false } }, + ovpk_m: OvpkM { inner: Point { x: 5, y: 6, is_infinite: false } }, + tpk_m: TpkM { inner: Point { x: 7, y: 8, is_infinite: false } } }; let serialized = keys.serialize(); let deserialized = PublicKeys::deserialize(serialized); - assert_eq(keys.npk_m.x, deserialized.npk_m.x); - assert_eq(keys.npk_m.y, deserialized.npk_m.y); - assert_eq(keys.ivpk_m.x, deserialized.ivpk_m.x); - assert_eq(keys.ivpk_m.y, deserialized.ivpk_m.y); - assert_eq(keys.ovpk_m.x, deserialized.ovpk_m.x); - assert_eq(keys.ovpk_m.y, deserialized.ovpk_m.y); - assert_eq(keys.tpk_m.x, deserialized.tpk_m.x); - assert_eq(keys.tpk_m.y, deserialized.tpk_m.y); + assert_eq(keys.npk_m.inner.x, deserialized.npk_m.inner.x); + assert_eq(keys.npk_m.inner.y, deserialized.npk_m.inner.y); + assert_eq(keys.ivpk_m.inner.x, deserialized.ivpk_m.inner.x); + assert_eq(keys.ivpk_m.inner.y, deserialized.ivpk_m.inner.y); + assert_eq(keys.ovpk_m.inner.x, deserialized.ovpk_m.inner.x); + assert_eq(keys.ovpk_m.inner.y, deserialized.ovpk_m.inner.y); + assert_eq(keys.tpk_m.inner.x, deserialized.tpk_m.inner.x); + assert_eq(keys.tpk_m.inner.y, deserialized.tpk_m.inner.y); } diff --git a/noir-projects/aztec-nr/aztec/src/oracle/keys.nr b/noir-projects/aztec-nr/aztec/src/oracle/keys.nr index 3955cce4832..0c4f3c5f579 100644 --- a/noir-projects/aztec-nr/aztec/src/oracle/keys.nr +++ b/noir-projects/aztec-nr/aztec/src/oracle/keys.nr @@ -1,4 +1,4 @@ -use crate::keys::PublicKeys; +use crate::keys::{PublicKeys, public_keys::{NpkM, IvpkM, OvpkM, TpkM}}; use dep::protocol_types::{address::{AztecAddress, PartialAddress}, point::Point}; #[oracle(getPublicKeysAndPartialAddress)] @@ -12,10 +12,10 @@ pub fn get_public_keys_and_partial_address(address: AztecAddress) -> (PublicKeys let result = get_public_keys_and_partial_address_oracle_wrapper(address); let keys = PublicKeys { - 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 } + npk_m: NpkM { inner: Point { x: result[0], y: result[1], is_infinite: result[2] as bool } }, + ivpk_m: IvpkM { inner: Point { x: result[3], y: result[4], is_infinite: result[5] as bool } }, + ovpk_m: OvpkM { inner: Point { x: result[6], y: result[7], is_infinite: result[8] as bool } }, + tpk_m: TpkM { inner: Point { x: result[9], y: result[10], is_infinite: result[11] as bool } } }; let partial_address = PartialAddress::from_field(result[12]); diff --git a/noir-projects/aztec-nr/aztec/src/test/helpers/keys.nr b/noir-projects/aztec-nr/aztec/src/test/helpers/keys.nr index a3666c8facc..be040f256ab 100644 --- a/noir-projects/aztec-nr/aztec/src/test/helpers/keys.nr +++ b/noir-projects/aztec-nr/aztec/src/test/helpers/keys.nr @@ -3,9 +3,11 @@ use dep::protocol_types::{ constants::CANONICAL_KEY_REGISTRY_ADDRESS, point::Point }; -use crate::test::helpers::cheatcodes; +use crate::{test::helpers::cheatcodes, keys::public_keys::ToPoint}; + +pub fn store_master_key(key_index: Field, address: AztecAddress, key: T) where T: ToPoint { + let key_point = key.to_point(); -pub fn store_master_key(key_index: Field, address: AztecAddress, key: Point) { let x_coordinate_map_slot = key_index * 2 + 1; let y_coordinate_map_slot = x_coordinate_map_slot + 1; let x_coordinate_derived_slot = derive_storage_slot_in_map(x_coordinate_map_slot, address); @@ -14,11 +16,11 @@ pub fn store_master_key(key_index: Field, address: AztecAddress, key: Point) { cheatcodes::direct_storage_write( CANONICAL_KEY_REGISTRY_ADDRESS, x_coordinate_derived_slot, - [key.x] + [key_point.x] ); cheatcodes::direct_storage_write( CANONICAL_KEY_REGISTRY_ADDRESS, y_coordinate_derived_slot, - [key.y] + [key_point.y] ); } diff --git a/noir-projects/aztec-nr/aztec/src/test/helpers/test_environment.nr b/noir-projects/aztec-nr/aztec/src/test/helpers/test_environment.nr index 5a1437572e1..b9c578f00fd 100644 --- a/noir-projects/aztec-nr/aztec/src/test/helpers/test_environment.nr +++ b/noir-projects/aztec-nr/aztec/src/test/helpers/test_environment.nr @@ -96,7 +96,7 @@ impl TestEnvironment { let selector = FunctionSelector::from_signature("constructor(Field,Field)"); let mut context = self.private_at(get_block_number()); - let args = [test_account.keys.ivpk_m.x, test_account.keys.ivpk_m.y]; + let args = [test_account.keys.ivpk_m.inner.x, test_account.keys.ivpk_m.inner.y]; let _ = context.call_private_function(address, selector, args); address diff --git a/noir-projects/noir-contracts/contracts/key_registry_contract/src/main.nr b/noir-projects/noir-contracts/contracts/key_registry_contract/src/main.nr index aee3fb26c4e..8c010353775 100644 --- a/noir-projects/noir-contracts/contracts/key_registry_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/key_registry_contract/src/main.nr @@ -2,7 +2,8 @@ contract KeyRegistry { use dep::authwit::auth::assert_current_call_valid_authwit_public; use dep::aztec::{ - keys::{PublicKeys, stored_keys::StoredKeys}, state_vars::{PublicMutable, Map}, + keys::{PublicKeys, stored_keys::StoredKeys, public_keys::NpkM}, + state_vars::{PublicMutable, Map}, protocol_types::{point::Point, address::{AztecAddress, PartialAddress}} }; @@ -43,7 +44,7 @@ contract KeyRegistry { } #[aztec(public)] - fn rotate_npk_m(account: AztecAddress, new_npk_m: Point, nonce: Field) { + fn rotate_npk_m(account: AztecAddress, new_npk_m: NpkM, nonce: Field) { if (!account.eq(context.msg_sender())) { assert_current_call_valid_authwit_public(&mut context, account); } else { diff --git a/noir-projects/noir-contracts/contracts/schnorr_single_key_account_contract/src/util.nr b/noir-projects/noir-contracts/contracts/schnorr_single_key_account_contract/src/util.nr index 8d15cc3211f..4f98c0183b1 100644 --- a/noir-projects/noir-contracts/contracts/schnorr_single_key_account_contract/src/util.nr +++ b/noir-projects/noir-contracts/contracts/schnorr_single_key_account_contract/src/util.nr @@ -6,8 +6,8 @@ pub fn recover_address(message_hash: Field, witness: AuthWitness) -> AztecAddres let message_bytes = message_hash.to_be_bytes(32); // In a single key account contract we re-used ivpk_m as signing key let verification = verify_signature_slice( - witness.keys.ivpk_m.x, - witness.keys.ivpk_m.y, + witness.keys.ivpk_m.inner.x, + witness.keys.ivpk_m.inner.y, witness.signature, message_bytes ); diff --git a/noir-projects/noir-contracts/contracts/test_contract/src/main.nr b/noir-projects/noir-contracts/contracts/test_contract/src/main.nr index 8220c47beec..703e0e7e9cb 100644 --- a/noir-projects/noir-contracts/contracts/test_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/test_contract/src/main.nr @@ -28,7 +28,7 @@ contract Test { use dep::aztec::{ context::inputs::private_context_inputs::PrivateContextInputs, - hash::{pedersen_hash, compute_secret_hash, ArgsHasher}, + hash::{pedersen_hash, compute_secret_hash, ArgsHasher}, keys::public_keys::IvpkM, note::{ lifecycle::{create_note, destroy_note_unsafe}, note_getter::{get_notes, view_notes}, note_getter_options::NoteStatus @@ -66,7 +66,7 @@ contract Test { fn get_master_incoming_viewing_public_key(address: AztecAddress) -> [Field; 2] { let ivpk_m = get_current_public_keys(&mut context, address).ivpk_m; - [ivpk_m.x, ivpk_m.y] + [ivpk_m.inner.x, ivpk_m.inner.y] } // Get the address of this contract (taken from the input context) @@ -405,27 +405,27 @@ contract Test { } #[aztec(private)] - fn compute_note_header_ciphertext(secret: Scalar, point: Point) -> [u8; 48] { - EncryptedLogHeader::new(context.this_address()).compute_ciphertext(secret, point) + fn compute_note_header_ciphertext(secret: Scalar, ivpk: IvpkM) -> [u8; 48] { + EncryptedLogHeader::new(context.this_address()).compute_ciphertext(secret, ivpk) } // 64 bytes + 32 * #fields + 16 = 112 bytes #[aztec(private)] fn compute_incoming_log_body_ciphertext( secret: Scalar, - point: Point, + ivpk: IvpkM, storage_slot: Field, value: Field ) -> [u8; 112] { let note = TestNote::new(value); - EncryptedLogIncomingBody::from_note(note, storage_slot).compute_ciphertext(secret, point).as_array() + EncryptedLogIncomingBody::from_note(note, storage_slot).compute_ciphertext(secret, ivpk).as_array() } #[aztec(private)] fn compute_outgoing_log_body_ciphertext( eph_sk: Scalar, recipient: AztecAddress, - recipient_ivpk: Point, + recipient_ivpk: IvpkM, ovsk_app: Scalar ) -> [u8; 144] { let eph_pk = derive_public_key(eph_sk); @@ -501,7 +501,7 @@ contract Test { #[aztec(private)] fn test_nullifier_key_freshness(address: AztecAddress, public_nullifying_key: Point) { - assert_eq(get_current_public_keys(&mut context, address).npk_m, public_nullifying_key); + assert_eq(get_current_public_keys(&mut context, address).npk_m.inner, public_nullifying_key); } // Purely exists for testing diff --git a/noir-projects/noir-contracts/contracts/test_log_contract/src/main.nr b/noir-projects/noir-contracts/contracts/test_log_contract/src/main.nr index 01a65af901b..e6c8f769b56 100644 --- a/noir-projects/noir-contracts/contracts/test_log_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/test_log_contract/src/main.nr @@ -1,6 +1,7 @@ contract TestLog { use dep::aztec::prelude::PrivateSet; use dep::aztec::protocol_types::{traits::Serialize, point::Point, scalar::Scalar, address::AztecAddress}; + use dep::aztec::keys::public_keys::IvpkM; use dep::value_note::value_note::ValueNote; use dep::aztec::encrypted_logs::incoming_body::EncryptedLogIncomingBody; use dep::aztec::event::event_interface::EventInterface; @@ -30,7 +31,7 @@ contract TestLog { #[aztec(private)] fn compute_incoming_log_body_ciphertext( secret: Scalar, - point: Point, + ivpk: IvpkM, randomness: Field, event_type_id: Field, preimage: [Field; 2] @@ -38,7 +39,7 @@ contract TestLog { EncryptedLogIncomingBody::from_event( ExampleEvent0 { value0: preimage[0], value1: preimage[1] }, randomness - ).compute_ciphertext(secret, point).as_array() + ).compute_ciphertext(secret, ivpk).as_array() } #[aztec(private)] diff --git a/noir-projects/noir-contracts/contracts/token_contract/src/types/balances_map.nr b/noir-projects/noir-contracts/contracts/token_contract/src/types/balances_map.nr index c90678f9abd..29578dcf513 100644 --- a/noir-projects/noir-contracts/contracts/token_contract/src/types/balances_map.nr +++ b/noir-projects/noir-contracts/contracts/token_contract/src/types/balances_map.nr @@ -6,7 +6,7 @@ use dep::aztec::{ note_getter::view_notes, note_getter_options::SortOrder, note_emission::{NoteEmission, OuterNoteEmission} }, - keys::getters::get_current_public_keys + keys::{getters::get_current_public_keys, public_keys::NpkM} }; use crate::types::{token_note::{TokenNote, OwnedNote}}; @@ -62,7 +62,7 @@ impl BalancesMap { pub fn add( self: Self, owner: AztecAddress, - owner_npk_m: Point, + owner_npk_m: NpkM, addend: U128 ) -> OuterNoteEmission where T: NoteInterface + OwnedNote + Eq { if addend == U128::from_integer(0) { @@ -80,7 +80,7 @@ impl BalancesMap { pub fn sub( self: Self, owner: AztecAddress, - owner_npk_m: Point, + owner_npk_m: NpkM, amount: U128 ) -> OuterNoteEmission where T: NoteInterface + OwnedNote + Eq { let subtracted = self.try_sub(owner, amount, MAX_NOTE_HASH_READ_REQUESTS_PER_CALL); @@ -95,10 +95,10 @@ impl BalancesMap { // (i.e. the sum of the value of nullified notes), but this subtracted amount may be more or less than the target // amount. // This may seem odd, but is unfortunately unavoidable due to the number of notes available and their amounts being - // unknown. What try_sub does is a best-effort attempt to consume as few notes as possible that add up to more than + // unknown. What try_sub does is a best-effort attempt to consume as few notes as possible that add up to more than // `target_amount`. // The `max_notes` parameter is used to fine-tune the number of constraints created by this function. The gate count - // scales relatively linearly with `max_notes`, but a lower `max_notes` parameter increases the likelihood of + // scales relatively linearly with `max_notes`, but a lower `max_notes` parameter increases the likelihood of // `try_sub` subtracting an amount smaller than `target_amount`. pub fn try_sub( self: Self, diff --git a/yarn-project/aztec.js/src/wallet/account_wallet.ts b/yarn-project/aztec.js/src/wallet/account_wallet.ts index 12f901c5d42..9eab8dd9866 100644 --- a/yarn-project/aztec.js/src/wallet/account_wallet.ts +++ b/yarn-project/aztec.js/src/wallet/account_wallet.ts @@ -179,7 +179,7 @@ export class AccountWallet extends BaseWallet { this, AztecAddress.fromBigInt(CANONICAL_KEY_REGISTRY_ADDRESS), this.getRotateNpkMAbi(), - [this.getAddress(), derivePublicKeyFromSecretKey(newNskM).toNoirStruct(), Fr.ZERO], + [this.getAddress(), derivePublicKeyFromSecretKey(newNskM).toWrappedNoirStruct(), Fr.ZERO], ); await interaction.send().wait(); @@ -274,12 +274,36 @@ export class AccountWallet extends BaseWallet { name: 'new_npk_m', type: { fields: [ - { name: 'x', type: { kind: 'field' } }, - { name: 'y', type: { kind: 'field' } }, - { name: 'is_infinite', type: { kind: 'boolean' } }, + { + name: 'inner', + type: { + fields: [ + { + name: 'x', + type: { + kind: 'field', + }, + }, + { + name: 'y', + type: { + kind: 'field', + }, + }, + { + name: 'is_infinite', + type: { + kind: 'boolean', + }, + }, + ], + kind: 'struct', + path: 'std::embedded_curve_ops::EmbeddedCurvePoint', + }, + }, ], kind: 'struct', - path: 'std::embedded_curve_ops::EmbeddedCurvePoint', + path: 'aztec::keys::public_keys::NpkM', }, visibility: 'private' as ABIParameterVisibility, }, diff --git a/yarn-project/circuits.js/src/types/public_keys.ts b/yarn-project/circuits.js/src/types/public_keys.ts index 1e73fdba099..be151aa9745 100644 --- a/yarn-project/circuits.js/src/types/public_keys.ts +++ b/yarn-project/circuits.js/src/types/public_keys.ts @@ -104,10 +104,10 @@ export class PublicKeys { return { // TODO(#6337): Directly dump account.publicKeys here /* eslint-disable camelcase */ - npk_m: this.masterNullifierPublicKey.toNoirStruct(), - ivpk_m: this.masterIncomingViewingPublicKey.toNoirStruct(), - ovpk_m: this.masterOutgoingViewingPublicKey.toNoirStruct(), - tpk_m: this.masterTaggingPublicKey.toNoirStruct(), + npk_m: this.masterNullifierPublicKey.toWrappedNoirStruct(), + ivpk_m: this.masterIncomingViewingPublicKey.toWrappedNoirStruct(), + ovpk_m: this.masterOutgoingViewingPublicKey.toWrappedNoirStruct(), + tpk_m: this.masterTaggingPublicKey.toWrappedNoirStruct(), /* eslint-enable camelcase */ }; } diff --git a/yarn-project/end-to-end/src/e2e_encryption.test.ts b/yarn-project/end-to-end/src/e2e_encryption.test.ts index afa5751e0d6..f3ff1e03632 100644 --- a/yarn-project/end-to-end/src/e2e_encryption.test.ts +++ b/yarn-project/end-to-end/src/e2e_encryption.test.ts @@ -73,7 +73,7 @@ describe('e2e_encryption', () => { const header = new EncryptedLogHeader(contract.address); const encrypted = await contract.methods - .compute_note_header_ciphertext(ephSecretKey, viewingPubKey.toNoirStruct()) + .compute_note_header_ciphertext(ephSecretKey, viewingPubKey.toWrappedNoirStruct()) .simulate(); expect(Buffer.from(encrypted.map((x: bigint) => Number(x)))).toEqual( header.computeCiphertext(ephSecretKey, viewingPubKey), @@ -99,7 +99,7 @@ describe('e2e_encryption', () => { const body = new EncryptedNoteLogIncomingBody(storageSlot, noteTypeId, note); const encrypted = await contract.methods - .compute_incoming_log_body_ciphertext(ephSecretKey, viewingPubKey.toNoirStruct(), storageSlot, value) + .compute_incoming_log_body_ciphertext(ephSecretKey, viewingPubKey.toWrappedNoirStruct(), storageSlot, value) .simulate(); expect(Buffer.from(encrypted.map((x: bigint) => Number(x)))).toEqual( @@ -124,7 +124,7 @@ describe('e2e_encryption', () => { const body = new EncryptedLogOutgoingBody(ephSk, recipientAddress, recipientIvpk); const encrypted = await contract.methods - .compute_outgoing_log_body_ciphertext(ephSk, recipientAddress, recipientIvpk.toNoirStruct(), senderOvskApp) + .compute_outgoing_log_body_ciphertext(ephSk, recipientAddress, recipientIvpk.toWrappedNoirStruct(), senderOvskApp) .simulate(); expect(Buffer.from(encrypted.map((x: bigint) => Number(x)))).toEqual(body.computeCiphertext(senderOvskApp, ephPk)); diff --git a/yarn-project/end-to-end/src/e2e_key_registry.test.ts b/yarn-project/end-to-end/src/e2e_key_registry.test.ts index c97dadd7d8c..82bd3303ee7 100644 --- a/yarn-project/end-to-end/src/e2e_key_registry.test.ts +++ b/yarn-project/end-to-end/src/e2e_key_registry.test.ts @@ -66,7 +66,7 @@ describe('Key Registry', () => { await expect( keyRegistry .withWallet(wallets[0]) - .methods.rotate_npk_m(wallets[1].getAddress(), Point.random().toNoirStruct(), Fr.ZERO) + .methods.rotate_npk_m(wallets[1].getAddress(), Point.random().toWrappedNoirStruct(), Fr.ZERO) .simulate(), ).rejects.toThrow(/unauthorized/); }); @@ -129,7 +129,7 @@ describe('Key Registry', () => { // docs:start:key-rotation await keyRegistry .withWallet(wallets[0]) - .methods.rotate_npk_m(wallets[0].getAddress(), firstNewMasterNullifierPublicKey.toNoirStruct(), Fr.ZERO) + .methods.rotate_npk_m(wallets[0].getAddress(), firstNewMasterNullifierPublicKey.toWrappedNoirStruct(), Fr.ZERO) .send() .wait(); // docs:end:key-rotation @@ -143,7 +143,11 @@ describe('Key Registry', () => { it(`rotates npk_m with authwit`, async () => { const action = keyRegistry .withWallet(wallets[1]) - .methods.rotate_npk_m(wallets[0].getAddress(), secondNewMasterNullifierPublicKey.toNoirStruct(), Fr.ZERO); + .methods.rotate_npk_m( + wallets[0].getAddress(), + secondNewMasterNullifierPublicKey.toWrappedNoirStruct(), + Fr.ZERO, + ); await wallets[0] .setPublicAuthWit({ caller: wallets[1].getCompleteAddress().address, action }, true) diff --git a/yarn-project/foundation/src/fields/point.ts b/yarn-project/foundation/src/fields/point.ts index 253173c6a3c..458252bd87a 100644 --- a/yarn-project/foundation/src/fields/point.ts +++ b/yarn-project/foundation/src/fields/point.ts @@ -226,6 +226,13 @@ export class Point { /* eslint-enable camelcase */ } + // Used for IvpkM, OvpkM, NpkM and TpkM. TODO(#8124): Consider removing this method. + toWrappedNoirStruct() { + /* eslint-disable camelcase */ + return { inner: this.toNoirStruct() }; + /* eslint-enable camelcase */ + } + /** * Check if two Point instances are equal by comparing their buffer values. * Returns true if the buffer values are the same, and false otherwise.