Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
benesjan committed Aug 21, 2024
1 parent 7d2caf1 commit 9a4377a
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 30 deletions.
15 changes: 9 additions & 6 deletions boxes/boxes/react/src/contracts/src/main.nr
Original file line number Diff line number Diff line change
@@ -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)]
Expand All @@ -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);
Expand All @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions boxes/boxes/react/src/hooks/useContract.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
Expand Down
4 changes: 2 additions & 2 deletions boxes/boxes/react/src/hooks/useNumber.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
8 changes: 4 additions & 4 deletions boxes/boxes/react/tests/node.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
Expand Down
15 changes: 9 additions & 6 deletions boxes/boxes/vanilla/src/contracts/src/main.nr
Original file line number Diff line number Diff line change
@@ -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)]
Expand All @@ -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);
Expand All @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions boxes/boxes/vanilla/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
Expand Down
20 changes: 19 additions & 1 deletion noir-projects/aztec-nr/aztec/src/keys/public_keys.nr
Original file line number Diff line number Diff line change
@@ -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};
Expand All @@ -22,6 +22,12 @@ struct NpkM {
inner: Point
}

impl Serialize<POINT_LENGTH> 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 {
Expand All @@ -39,6 +45,12 @@ impl ToPoint for IvpkM {
}
}

impl Serialize<POINT_LENGTH> for IvpkM {
fn serialize(self) -> [Field; POINT_LENGTH] {
self.inner.serialize()
}
}

struct OvpkM {
inner: Point
}
Expand All @@ -55,6 +67,12 @@ impl ToPoint for OvpkM {
}
}

impl Serialize<POINT_LENGTH> for OvpkM {
fn serialize(self) -> [Field; POINT_LENGTH] {
self.inner.serialize()
}
}

struct TpkM {
inner: Point
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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));
}
Expand Down
14 changes: 11 additions & 3 deletions yarn-project/end-to-end/src/e2e_key_registry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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/);
});
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit 9a4377a

Please sign in to comment.