From 9ba5c229d1e0fe5917ecd2563d8b2612396e0da3 Mon Sep 17 00:00:00 2001 From: benesjan Date: Thu, 2 Nov 2023 11:26:42 +0000 Subject: [PATCH 1/3] feat: adding all the note nonce pairs in PXE.addNote --- .../pxe/src/pxe_service/pxe_service.ts | 62 ++++++++++--------- 1 file changed, 32 insertions(+), 30 deletions(-) diff --git a/yarn-project/pxe/src/pxe_service/pxe_service.ts b/yarn-project/pxe/src/pxe_service/pxe_service.ts index 8d8a9b69156..8a14d2ee75e 100644 --- a/yarn-project/pxe/src/pxe_service/pxe_service.ts +++ b/yarn-project/pxe/src/pxe_service/pxe_service.ts @@ -221,42 +221,44 @@ export class PXEService implements PXE { throw new Error('Unknown account.'); } - const [nonce] = await this.getNoteNonces(note); - if (!nonce) { + const nonces = await this.getNoteNonces(note); + if (nonces.length === 0) { throw new Error(`Cannot find the note in tx: ${note.txHash}.`); } - const { innerNoteHash, siloedNoteHash, uniqueSiloedNoteHash, innerNullifier } = - await this.simulator.computeNoteHashAndNullifier(note.contractAddress, nonce, note.storageSlot, note.note); + for (const nonce of nonces) { + const { innerNoteHash, siloedNoteHash, uniqueSiloedNoteHash, innerNullifier } = + await this.simulator.computeNoteHashAndNullifier(note.contractAddress, nonce, note.storageSlot, note.note); - // TODO(https://github.com/AztecProtocol/aztec-packages/issues/1386) - // This can always be `uniqueSiloedNoteHash` once notes added from public also include nonces. - const noteHashToLookUp = nonce.isZero() ? siloedNoteHash : uniqueSiloedNoteHash; - const index = await this.node.findLeafIndex(MerkleTreeId.NOTE_HASH_TREE, noteHashToLookUp); - if (index === undefined) { - throw new Error('Note does not exist.'); - } + // TODO(https://github.com/AztecProtocol/aztec-packages/issues/1386) + // This can always be `uniqueSiloedNoteHash` once notes added from public also include nonces. + const noteHashToLookUp = nonce.isZero() ? siloedNoteHash : uniqueSiloedNoteHash; + const index = await this.node.findLeafIndex(MerkleTreeId.NOTE_HASH_TREE, noteHashToLookUp); + if (index === undefined) { + throw new Error('Note does not exist.'); + } - const wasm = await CircuitsWasm.get(); - const siloedNullifier = siloNullifier(wasm, note.contractAddress, innerNullifier!); - const nullifierIndex = await this.node.findLeafIndex(MerkleTreeId.NULLIFIER_TREE, siloedNullifier); - if (nullifierIndex !== undefined) { - throw new Error('The note has been destroyed.'); - } + const wasm = await CircuitsWasm.get(); + const siloedNullifier = siloNullifier(wasm, note.contractAddress, innerNullifier!); + const nullifierIndex = await this.node.findLeafIndex(MerkleTreeId.NULLIFIER_TREE, siloedNullifier); + if (nullifierIndex !== undefined) { + throw new Error('The note has been destroyed.'); + } - await this.db.addNote( - new NoteDao( - note.note, - note.contractAddress, - note.storageSlot, - note.txHash, - nonce, - innerNoteHash, - siloedNullifier, - index, - publicKey, - ), - ); + await this.db.addNote( + new NoteDao( + note.note, + note.contractAddress, + note.storageSlot, + note.txHash, + nonce, + innerNoteHash, + siloedNullifier, + index, + publicKey, + ), + ); + } } public async getNoteNonces(note: ExtendedNote): Promise { From 03b916e0cb2a0fd4daaa038b15cb271aca08f0db Mon Sep 17 00:00:00 2001 From: benesjan Date: Thu, 2 Nov 2023 11:28:55 +0000 Subject: [PATCH 2/3] refactor: making getNoteNonces private --- yarn-project/pxe/src/pxe_service/pxe_service.ts | 8 +++++++- yarn-project/types/src/interfaces/pxe.ts | 8 -------- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/yarn-project/pxe/src/pxe_service/pxe_service.ts b/yarn-project/pxe/src/pxe_service/pxe_service.ts index 8a14d2ee75e..44fa8db2e41 100644 --- a/yarn-project/pxe/src/pxe_service/pxe_service.ts +++ b/yarn-project/pxe/src/pxe_service/pxe_service.ts @@ -261,7 +261,13 @@ export class PXEService implements PXE { } } - public async getNoteNonces(note: ExtendedNote): Promise { + /** + * Finds the nonce(s) for a given note. + * @param note - The note to find the nonces for. + * @returns The nonces of the note. + * @remarks More than a single nonce may be returned since there might be more than one nonce for a given note. + */ + private async getNoteNonces(note: ExtendedNote): Promise { const tx = await this.node.getTx(note.txHash); if (!tx) { throw new Error(`Unknown tx: ${note.txHash}`); diff --git a/yarn-project/types/src/interfaces/pxe.ts b/yarn-project/types/src/interfaces/pxe.ts index 5efef5b63ae..c7dd53a76b0 100644 --- a/yarn-project/types/src/interfaces/pxe.ts +++ b/yarn-project/types/src/interfaces/pxe.ts @@ -177,14 +177,6 @@ export interface PXE { */ addNote(note: ExtendedNote): Promise; - /** - * Finds the nonce(s) for a given note. - * @param note - The note to find the nonces for. - * @returns The nonces of the note. - * @remarks More than a single nonce may be returned since there might be more than one nonce for a given note. - */ - getNoteNonces(note: ExtendedNote): Promise; - /** * Get the given block. * @param number - The block number being requested. From b08e60579781f355b255c5c253523d0e67fa7d52 Mon Sep 17 00:00:00 2001 From: benesjan Date: Thu, 2 Nov 2023 12:06:12 +0000 Subject: [PATCH 3/3] fix --- yarn-project/aztec.js/src/wallet/base_wallet.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/yarn-project/aztec.js/src/wallet/base_wallet.ts b/yarn-project/aztec.js/src/wallet/base_wallet.ts index 2a1f5235b4e..48e259aeca1 100644 --- a/yarn-project/aztec.js/src/wallet/base_wallet.ts +++ b/yarn-project/aztec.js/src/wallet/base_wallet.ts @@ -80,9 +80,6 @@ export abstract class BaseWallet implements Wallet { addNote(note: ExtendedNote): Promise { return this.pxe.addNote(note); } - getNoteNonces(note: ExtendedNote): Promise { - return this.pxe.getNoteNonces(note); - } getBlock(number: number): Promise { return this.pxe.getBlock(number); }