From 9a4377a2daf68c0f6e6d466b0dbe2531c117b497 Mon Sep 17 00:00:00 2001 From: benesjan Date: Wed, 21 Aug 2024 11:53:23 +0000 Subject: [PATCH] fixes --- boxes/boxes/react/src/contracts/src/main.nr | 15 ++++++++------ boxes/boxes/react/src/hooks/useContract.tsx | 4 ++-- boxes/boxes/react/src/hooks/useNumber.tsx | 4 ++-- boxes/boxes/react/tests/node.test.ts | 8 ++++---- boxes/boxes/vanilla/src/contracts/src/main.nr | 15 ++++++++------ boxes/boxes/vanilla/src/index.ts | 8 ++++---- .../aztec-nr/aztec/src/keys/public_keys.nr | 20 ++++++++++++++++++- .../key_registry_contract/src/main.nr | 4 ++-- .../end-to-end/src/e2e_key_registry.test.ts | 14 ++++++++++--- 9 files changed, 62 insertions(+), 30 deletions(-) diff --git a/boxes/boxes/react/src/contracts/src/main.nr b/boxes/boxes/react/src/contracts/src/main.nr index 39984e28df70..d0fafea32505 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 7f3cb2bd7bbb..526f6e9eefa9 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(), + { inner: masterOutgoingViewingPublicKey.toNoirStruct() }, + { inner: masterIncomingViewingPublicKey.toNoirStruct() }, ).send({ contractAddressSalt: salt, }); diff --git a/boxes/boxes/react/src/hooks/useNumber.tsx b/boxes/boxes/react/src/hooks/useNumber.tsx index 602d91e89db6..26bfddb87250 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(), + { inner: masterOutgoingViewingPublicKey.toNoirStruct() }, + { inner: masterIncomingViewingPublicKey.toNoirStruct() }, ) .send() .wait(), diff --git a/boxes/boxes/react/tests/node.test.ts b/boxes/boxes/react/tests/node.test.ts index 65a3f2b6ff01..b60b04836ec1 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(), + { inner: masterOutgoingViewingPublicKey.toNoirStruct() }, + { inner: masterIncomingViewingPublicKey.toNoirStruct() }, ) .send({ contractAddressSalt: salt }) .deployed(); @@ -39,8 +39,8 @@ describe('BoxReact Contract Tests', () => { numberToSet, accountCompleteAddress.address, masterNullifierPublicKey.hash(), - masterOutgoingViewingPublicKey.toNoirStruct(), - masterIncomingViewingPublicKey.toNoirStruct(), + { inner: masterOutgoingViewingPublicKey.toNoirStruct() }, + { inner: masterIncomingViewingPublicKey.toNoirStruct() }, ) .send() .wait(); diff --git a/boxes/boxes/vanilla/src/contracts/src/main.nr b/boxes/boxes/vanilla/src/contracts/src/main.nr index 9d08c789e329..401a2c86989e 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 e9ee08284fae..fc80aa3879af 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(), + { inner: masterOutgoingViewingPublicKey.toNoirStruct() }, + { inner: masterIncomingViewingPublicKey.toNoirStruct() }, ) .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(), + { inner: masterOutgoingViewingPublicKey.toNoirStruct() }, + { inner: masterIncomingViewingPublicKey.toNoirStruct() }, ) .send() .wait(); 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 92f21b743ee1..f577251d263e 100644 --- a/noir-projects/aztec-nr/aztec/src/keys/public_keys.nr +++ b/noir-projects/aztec-nr/aztec/src/keys/public_keys.nr @@ -1,6 +1,6 @@ use dep::protocol_types::{ address::PublicKeysHash, constants::GENERATOR_INDEX__PUBLIC_KEYS_HASH, - hash::poseidon2_hash_with_separator, point::Point, + hash::poseidon2_hash_with_separator, point::{Point, POINT_LENGTH}, traits::{Deserialize, Serialize, Empty, is_empty, Hash} }; use crate::keys::constants::{NULLIFIER_INDEX, INCOMING_INDEX, OUTGOING_INDEX}; @@ -22,6 +22,12 @@ struct NpkM { inner: Point } +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 impl Hash for NpkM { fn hash(self) -> Field { @@ -39,6 +45,12 @@ impl ToPoint for IvpkM { } } +impl Serialize for IvpkM { + fn serialize(self) -> [Field; POINT_LENGTH] { + self.inner.serialize() + } +} + struct OvpkM { inner: Point } @@ -55,6 +67,12 @@ impl ToPoint for OvpkM { } } +impl Serialize for OvpkM { + fn serialize(self) -> [Field; POINT_LENGTH] { + self.inner.serialize() + } +} + struct TpkM { inner: Point } 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 06035ec0e503..8c0103537750 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 @@ -44,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 { @@ -57,7 +57,7 @@ contract KeyRegistry { // updating all keys at once costs the same as updating just one (unless setting public storage to its current // value is cheaper than changing it, e.g. EIP-2200). let mut current_keys = account_key_storage.read().public_keys; - current_keys.npk_m = NpkM { inner: new_npk_m }; + current_keys.npk_m = new_npk_m; account_key_storage.write(StoredKeys::new(current_keys)); } 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 c97dadd7d8ca..b3c0e429fc48 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(), { inner: Point.random().toNoirStruct() }, Fr.ZERO) .simulate(), ).rejects.toThrow(/unauthorized/); }); @@ -129,7 +129,11 @@ 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(), + { inner: firstNewMasterNullifierPublicKey.toNoirStruct() }, + Fr.ZERO, + ) .send() .wait(); // docs:end:key-rotation @@ -143,7 +147,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(), + { inner: secondNewMasterNullifierPublicKey.toNoirStruct() }, + Fr.ZERO, + ); await wallets[0] .setPublicAuthWit({ caller: wallets[1].getCompleteAddress().address, action }, true)