From 7ec6080be775bd90fd0da771154696fdc5385947 Mon Sep 17 00:00:00 2001 From: sklppy88 Date: Thu, 8 Aug 2024 17:16:52 +0000 Subject: [PATCH 1/3] init --- yarn-project/aztec.js/src/index.ts | 1 + .../aztec.js/src/rpc_clients/pxe_client.ts | 2 + .../aztec.js/src/wallet/base_wallet.ts | 9 ++-- .../circuit-types/src/interfaces/pxe.ts | 15 ++---- yarn-project/circuit-types/src/mocks.ts | 14 ++++- .../src/notes/extended_note.test.ts | 12 ++++- .../circuit-types/src/notes/extended_note.ts | 52 +++++++++++++++++++ .../circuit-types/src/tx/tx_receipt.ts | 6 +-- .../src/e2e_crowdfunding_and_claim.test.ts | 16 +++--- .../pxe/src/pxe_http/pxe_http_server.ts | 2 + .../pxe/src/pxe_service/pxe_service.ts | 33 +++++++++--- 11 files changed, 120 insertions(+), 42 deletions(-) diff --git a/yarn-project/aztec.js/src/index.ts b/yarn-project/aztec.js/src/index.ts index 626f858ba381..99a9b7ad5505 100644 --- a/yarn-project/aztec.js/src/index.ts +++ b/yarn-project/aztec.js/src/index.ts @@ -102,6 +102,7 @@ export { EncryptedLogOutgoingBody, EventType, ExtendedNote, + ExtendedNoteWithNonce, FunctionCall, L1Actor, L1ToL2Message, diff --git a/yarn-project/aztec.js/src/rpc_clients/pxe_client.ts b/yarn-project/aztec.js/src/rpc_clients/pxe_client.ts index 54b2aa81a11a..49cb3211491e 100644 --- a/yarn-project/aztec.js/src/rpc_clients/pxe_client.ts +++ b/yarn-project/aztec.js/src/rpc_clients/pxe_client.ts @@ -2,6 +2,7 @@ import { AuthWitness, EncryptedNoteL2BlockL2Logs, ExtendedNote, + ExtendedNoteWithNonce, ExtendedUnencryptedL2Log, L2Block, LogId, @@ -45,6 +46,7 @@ export const createPXEClient = (url: string, fetch = makeFetch([1, 2, 3], false) FunctionSelector, EthAddress, ExtendedNote, + ExtendedNoteWithNonce, ExtendedUnencryptedL2Log, Fr, GrumpkinScalar, diff --git a/yarn-project/aztec.js/src/wallet/base_wallet.ts b/yarn-project/aztec.js/src/wallet/base_wallet.ts index 7a6d4ec81de7..350f13ffb2df 100644 --- a/yarn-project/aztec.js/src/wallet/base_wallet.ts +++ b/yarn-project/aztec.js/src/wallet/base_wallet.ts @@ -3,6 +3,7 @@ import { type EventMetadata, type EventType, type ExtendedNote, + type ExtendedNoteWithNonce, type GetUnencryptedLogsResponse, type IncomingNotesFilter, type L2Block, @@ -120,16 +121,12 @@ export abstract class BaseWallet implements Wallet { getTxReceipt(txHash: TxHash): Promise { return this.pxe.getTxReceipt(txHash); } - getIncomingNotes(filter: IncomingNotesFilter): Promise { + getIncomingNotes(filter: IncomingNotesFilter): Promise { return this.pxe.getIncomingNotes(filter); } - getOutgoingNotes(filter: OutgoingNotesFilter): Promise { + getOutgoingNotes(filter: OutgoingNotesFilter): Promise { return this.pxe.getOutgoingNotes(filter); } - // TODO(#4956): Un-expose this - getNoteNonces(note: ExtendedNote): Promise { - return this.pxe.getNoteNonces(note); - } getPublicStorageAt(contract: AztecAddress, storageSlot: Fr): Promise { return this.pxe.getPublicStorageAt(contract, storageSlot); } diff --git a/yarn-project/circuit-types/src/interfaces/pxe.ts b/yarn-project/circuit-types/src/interfaces/pxe.ts index efa100eac0d1..7b098a60d652 100644 --- a/yarn-project/circuit-types/src/interfaces/pxe.ts +++ b/yarn-project/circuit-types/src/interfaces/pxe.ts @@ -18,7 +18,7 @@ import { type AuthWitness } from '../auth_witness.js'; import { type L2Block } from '../l2_block.js'; import { type GetUnencryptedLogsResponse, type L1EventPayload, type LogFilter } from '../logs/index.js'; import { type IncomingNotesFilter } from '../notes/incoming_notes_filter.js'; -import { type ExtendedNote, type OutgoingNotesFilter } from '../notes/index.js'; +import { type ExtendedNote, type ExtendedNoteWithNonce, type OutgoingNotesFilter } from '../notes/index.js'; import { type NoteProcessorStats } from '../stats/stats.js'; import { type SimulatedTx, type Tx, type TxHash, type TxReceipt } from '../tx/index.js'; import { type TxEffect } from '../tx_effect.js'; @@ -235,23 +235,14 @@ export interface PXE { * @param filter - The filter to apply to the notes. * @returns The requested notes. */ - getIncomingNotes(filter: IncomingNotesFilter): Promise; + getIncomingNotes(filter: IncomingNotesFilter): Promise; /** * Gets outgoing notes of accounts registered in this PXE based on the provided filter. * @param filter - The filter to apply to the notes. * @returns The requested notes. */ - getOutgoingNotes(filter: OutgoingNotesFilter): 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. - * TODO(#4956): Un-expose this - */ - getNoteNonces(note: ExtendedNote): Promise; + getOutgoingNotes(filter: OutgoingNotesFilter): Promise; /** * Adds a note to the database. diff --git a/yarn-project/circuit-types/src/mocks.ts b/yarn-project/circuit-types/src/mocks.ts index 62bae58036f4..f5617a65f387 100644 --- a/yarn-project/circuit-types/src/mocks.ts +++ b/yarn-project/circuit-types/src/mocks.ts @@ -31,7 +31,7 @@ import { Fr } from '@aztec/foundation/fields'; import { type ContractInstanceWithAddress, SerializableContractInstance } from '@aztec/types/contracts'; import { EncryptedNoteTxL2Logs, EncryptedTxL2Logs, Note, UnencryptedTxL2Logs } from './logs/index.js'; -import { ExtendedNote } from './notes/index.js'; +import { ExtendedNote, ExtendedNoteWithNonce } from './notes/index.js'; import { PublicExecutionRequest } from './public_execution_request.js'; import { NestedProcessReturnValues, PublicSimulationOutput, SimulatedTx, Tx, TxHash } from './tx/index.js'; @@ -255,3 +255,15 @@ export const randomExtendedNote = ({ }: Partial = {}) => { return new ExtendedNote(note, owner, contractAddress, storageSlot, noteTypeId, txHash); }; + +export const randomExtendedNoteWithNonce = ({ + note = Note.random(), + owner = AztecAddress.random(), + contractAddress = AztecAddress.random(), + txHash = randomTxHash(), + storageSlot = Fr.random(), + noteTypeId = NoteSelector.random(), + nonce = Fr.random(), +}: Partial = {}) => { + return new ExtendedNoteWithNonce(note, owner, contractAddress, storageSlot, noteTypeId, txHash, nonce); +}; diff --git a/yarn-project/circuit-types/src/notes/extended_note.test.ts b/yarn-project/circuit-types/src/notes/extended_note.test.ts index 0b5f8c89edb6..33a9ed5b80bd 100644 --- a/yarn-project/circuit-types/src/notes/extended_note.test.ts +++ b/yarn-project/circuit-types/src/notes/extended_note.test.ts @@ -1,5 +1,5 @@ -import { randomExtendedNote } from '../mocks.js'; -import { ExtendedNote } from './extended_note.js'; +import { randomExtendedNote, randomExtendedNoteWithNonce } from '../mocks.js'; +import { ExtendedNote, ExtendedNoteWithNonce } from './extended_note.js'; describe('Extended Note', () => { it('convert to and from buffer', () => { @@ -8,3 +8,11 @@ describe('Extended Note', () => { expect(ExtendedNote.fromBuffer(buf)).toEqual(extendedNote); }); }); + +describe('Extended Note with nonce', () => { + it('convert to and from buffer', () => { + const extendedNote = randomExtendedNoteWithNonce(); + const buf = extendedNote.toBuffer(); + expect(ExtendedNoteWithNonce.fromBuffer(buf)).toEqual(extendedNote); + }); +}); diff --git a/yarn-project/circuit-types/src/notes/extended_note.ts b/yarn-project/circuit-types/src/notes/extended_note.ts index bf91e2dc49dd..8d0bda4ba0cd 100644 --- a/yarn-project/circuit-types/src/notes/extended_note.ts +++ b/yarn-project/circuit-types/src/notes/extended_note.ts @@ -57,3 +57,55 @@ export class ExtendedNote { return ExtendedNote.fromBuffer(Buffer.from(hex, 'hex')); } } + +export class ExtendedNoteWithNonce extends ExtendedNote { + constructor( + /** The note as emitted from the Noir contract. */ + note: Note, + /** The owner whose public key was used to encrypt the note. */ + owner: AztecAddress, + /** The contract address this note is created in. */ + contractAddress: AztecAddress, + /** The specific storage location of the note on the contract. */ + storageSlot: Fr, + /** The type identifier of the note on the contract. */ + noteTypeId: NoteSelector, + /** The hash of the tx the note was created in. */ + txHash: TxHash, + /** The nonce of the note. */ + public nonce: Fr, + ) { + super(note, owner, contractAddress, storageSlot, noteTypeId, txHash); + } + + override toBuffer(): Buffer { + return Buffer.concat([ + this.note.toBuffer(), + this.owner.toBuffer(), + this.contractAddress.toBuffer(), + this.storageSlot.toBuffer(), + this.noteTypeId.toBuffer(), + this.txHash.buffer, + this.nonce.toBuffer(), + ]); + } + + static override fromBuffer(buffer: Buffer | BufferReader) { + const reader = BufferReader.asReader(buffer); + + const note = Note.fromBuffer(reader); + const owner = AztecAddress.fromBuffer(reader); + const contractAddress = AztecAddress.fromBuffer(reader); + const storageSlot = Fr.fromBuffer(reader); + const noteTypeId = reader.readObject(NoteSelector); + const txHash = new TxHash(reader.readBytes(TxHash.SIZE)); + const nonce = Fr.fromBuffer(reader); + + return new this(note, owner, contractAddress, storageSlot, noteTypeId, txHash, nonce); + } + + static override fromString(str: string) { + const hex = str.replace(/^0x/, ''); + return ExtendedNoteWithNonce.fromBuffer(Buffer.from(hex, 'hex')); + } +} diff --git a/yarn-project/circuit-types/src/tx/tx_receipt.ts b/yarn-project/circuit-types/src/tx/tx_receipt.ts index 1543ef9fd46f..fbab2ab4b1c4 100644 --- a/yarn-project/circuit-types/src/tx/tx_receipt.ts +++ b/yarn-project/circuit-types/src/tx/tx_receipt.ts @@ -1,7 +1,7 @@ import { RevertCode } from '@aztec/circuits.js'; import { type Fr } from '@aztec/foundation/fields'; -import { type ExtendedNote } from '../notes/extended_note.js'; +import { type ExtendedNoteWithNonce } from '../notes/extended_note.js'; import { type PublicDataWrite } from '../public_data_write.js'; import { TxHash } from './tx_hash.js'; @@ -126,11 +126,11 @@ interface DebugInfo { * in the PXE which was used to submit the tx. You will not get notes of accounts which are not registered in * the PXE here even though they were created in this tx. */ - visibleIncomingNotes: ExtendedNote[]; + visibleIncomingNotes: ExtendedNoteWithNonce[]; /** * Notes created in this tx which were successfully decoded with the outgoing keys of accounts which are registered * in the PXE which was used to submit the tx. You will not get notes of accounts which are not registered in * the PXE here even though they were created in this tx. */ - visibleOutgoingNotes: ExtendedNote[]; + visibleOutgoingNotes: ExtendedNoteWithNonce[]; } diff --git a/yarn-project/end-to-end/src/e2e_crowdfunding_and_claim.test.ts b/yarn-project/end-to-end/src/e2e_crowdfunding_and_claim.test.ts index f88ba2311424..ae21d495205d 100644 --- a/yarn-project/end-to-end/src/e2e_crowdfunding_and_claim.test.ts +++ b/yarn-project/end-to-end/src/e2e_crowdfunding_and_claim.test.ts @@ -6,6 +6,7 @@ import { type CheatCodes, type DebugLogger, ExtendedNote, + type ExtendedNoteWithNonce, Fr, Note, type PXE, @@ -181,12 +182,7 @@ describe('e2e_crowdfunding_and_claim', () => { }; // Processes extended note such that it can be passed to a claim function of Claim contract - const processExtendedNote = async (extendedNote: ExtendedNote) => { - // TODO(#4956): Make fetching the nonce manually unnecessary - // To be able to perform the inclusion proof we need to fetch the nonce of the value note - const noteNonces = await pxe.getNoteNonces(extendedNote); - expect(noteNonces?.length).toEqual(1); - + const processExtendedNote = (extendedNote: ExtendedNoteWithNonce) => { return { header: { // eslint-disable-next-line camelcase @@ -195,7 +191,7 @@ describe('e2e_crowdfunding_and_claim', () => { storage_slot: extendedNote.storageSlot, // eslint-disable-next-line camelcase note_hash_counter: 0, // set as 0 as note is not transient - nonce: noteNonces[0], + nonce: extendedNote.nonce, }, value: extendedNote.note.items[0], // eslint-disable-next-line camelcase @@ -233,7 +229,7 @@ describe('e2e_crowdfunding_and_claim', () => { expect(notes!.length).toEqual(1); // Set the value note in a format which can be passed to claim function - valueNote = await processExtendedNote(notes![0]); + valueNote = processExtendedNote(notes![0]); } // 3) We claim the reward token via the Claim contract @@ -304,7 +300,7 @@ describe('e2e_crowdfunding_and_claim', () => { expect(notes!.length).toEqual(1); // Set the value note in a format which can be passed to claim function - const anotherDonationNote = await processExtendedNote(notes![0]); + const anotherDonationNote = processExtendedNote(notes![0]); // We create an unrelated pxe and wallet without access to the nsk_app that correlates to the npk_m specified in the proof note. let unrelatedWallet: AccountWallet; @@ -356,7 +352,7 @@ describe('e2e_crowdfunding_and_claim', () => { const receipt = await inclusionsProofsContract.methods.create_note(owner, 5n).send().wait({ debug: true }); const { visibleIncomingNotes } = receipt.debugInfo!; expect(visibleIncomingNotes.length).toEqual(1); - note = await processExtendedNote(visibleIncomingNotes![0]); + note = processExtendedNote(visibleIncomingNotes![0]); } // 3) Test the note was included diff --git a/yarn-project/pxe/src/pxe_http/pxe_http_server.ts b/yarn-project/pxe/src/pxe_http/pxe_http_server.ts index c4ab90e3a9d3..5390fb33355a 100644 --- a/yarn-project/pxe/src/pxe_http/pxe_http_server.ts +++ b/yarn-project/pxe/src/pxe_http/pxe_http_server.ts @@ -3,6 +3,7 @@ import { CompleteAddress, EncryptedNoteL2BlockL2Logs, ExtendedNote, + ExtendedNoteWithNonce, ExtendedUnencryptedL2Log, L2Block, LogId, @@ -48,6 +49,7 @@ export function createPXERpcServer(pxeService: PXE): JsonRpcServer { GrumpkinScalar, Note, ExtendedNote, + ExtendedNoteWithNonce, AuthWitness, L2Block, TxEffect, diff --git a/yarn-project/pxe/src/pxe_service/pxe_service.ts b/yarn-project/pxe/src/pxe_service/pxe_service.ts index 7b6ba12d62c0..31405b79c42f 100644 --- a/yarn-project/pxe/src/pxe_service/pxe_service.ts +++ b/yarn-project/pxe/src/pxe_service/pxe_service.ts @@ -5,7 +5,8 @@ import { EncryptedTxL2Logs, type EventMetadata, EventType, - ExtendedNote, + type ExtendedNote, + ExtendedNoteWithNonce, type FunctionCall, type GetUnencryptedLogsResponse, type IncomingNotesFilter, @@ -296,7 +297,7 @@ export class PXEService implements PXE { return await this.node.getPublicStorageAt(contract, slot, 'latest'); } - public async getIncomingNotes(filter: IncomingNotesFilter): Promise { + public async getIncomingNotes(filter: IncomingNotesFilter): Promise { const noteDaos = await this.db.getIncomingNotes(filter); // TODO(#6531): Refactor --> This type conversion is ugly but I decided to keep it this way for now because @@ -312,12 +313,20 @@ export class PXEService implements PXE { } owner = completeAddresses.address; } - return new ExtendedNote(dao.note, owner, dao.contractAddress, dao.storageSlot, dao.noteTypeId, dao.txHash); + return new ExtendedNoteWithNonce( + dao.note, + owner, + dao.contractAddress, + dao.storageSlot, + dao.noteTypeId, + dao.txHash, + dao.nonce, + ); }); return Promise.all(extendedNotes); } - public async getOutgoingNotes(filter: OutgoingNotesFilter): Promise { + public async getOutgoingNotes(filter: OutgoingNotesFilter): Promise { const noteDaos = await this.db.getOutgoingNotes(filter); // TODO(#6532): Refactor --> This type conversion is ugly but I decided to keep it this way for now because @@ -333,7 +342,15 @@ export class PXEService implements PXE { } owner = completeAddresses.address; } - return new ExtendedNote(dao.note, owner, dao.contractAddress, dao.storageSlot, dao.noteTypeId, dao.txHash); + return new ExtendedNoteWithNonce( + dao.note, + owner, + dao.contractAddress, + dao.storageSlot, + dao.noteTypeId, + dao.txHash, + dao.nonce, + ); }); return Promise.all(extendedNotes); } @@ -344,7 +361,7 @@ export class PXEService implements PXE { throw new Error(`Unknown account: ${note.owner.toString()}`); } - const nonces = await this.getNoteNonces(note); + const nonces = await this.#getNoteNonces(note); if (nonces.length === 0) { throw new Error(`Cannot find the note in tx: ${note.txHash}.`); } @@ -394,7 +411,7 @@ export class PXEService implements PXE { throw new Error(`Unknown account: ${note.owner.toString()}`); } - const nonces = await this.getNoteNonces(note); + const nonces = await this.#getNoteNonces(note); if (nonces.length === 0) { throw new Error(`Cannot find the note in tx: ${note.txHash}.`); } @@ -442,7 +459,7 @@ export class PXEService implements PXE { * @remarks More than a single nonce may be returned since there might be more than one nonce for a given note. * TODO(#4956): Un-expose this */ - public async getNoteNonces(note: ExtendedNote): Promise { + async #getNoteNonces(note: ExtendedNote): Promise { const tx = await this.node.getTxEffect(note.txHash); if (!tx) { throw new Error(`Unknown tx: ${note.txHash}`); From 4c33a500afb123bf7fc1b1aa67d91760679dad62 Mon Sep 17 00:00:00 2001 From: sklppy88 Date: Tue, 13 Aug 2024 15:11:03 +0000 Subject: [PATCH 2/3] addressing Jan's comments --- yarn-project/aztec.js/src/index.ts | 2 +- .../aztec.js/src/rpc_clients/pxe_client.ts | 4 ++-- .../aztec.js/src/wallet/base_wallet.ts | 6 ++--- .../circuit-types/src/interfaces/pxe.ts | 6 ++--- yarn-project/circuit-types/src/mocks.ts | 8 +++---- .../src/notes/extended_note.test.ts | 12 +++++----- .../circuit-types/src/notes/extended_note.ts | 4 ++-- .../circuit-types/src/tx/tx_receipt.ts | 6 ++--- .../src/e2e_crowdfunding_and_claim.test.ts | 24 +++++++++---------- .../pxe/src/pxe_http/pxe_http_server.ts | 4 ++-- .../pxe/src/pxe_service/pxe_service.ts | 10 ++++---- 11 files changed, 43 insertions(+), 43 deletions(-) diff --git a/yarn-project/aztec.js/src/index.ts b/yarn-project/aztec.js/src/index.ts index 99a9b7ad5505..cf7198dd956f 100644 --- a/yarn-project/aztec.js/src/index.ts +++ b/yarn-project/aztec.js/src/index.ts @@ -102,7 +102,7 @@ export { EncryptedLogOutgoingBody, EventType, ExtendedNote, - ExtendedNoteWithNonce, + UniqueNote, FunctionCall, L1Actor, L1ToL2Message, diff --git a/yarn-project/aztec.js/src/rpc_clients/pxe_client.ts b/yarn-project/aztec.js/src/rpc_clients/pxe_client.ts index 49cb3211491e..4e8424bf5eaf 100644 --- a/yarn-project/aztec.js/src/rpc_clients/pxe_client.ts +++ b/yarn-project/aztec.js/src/rpc_clients/pxe_client.ts @@ -2,7 +2,6 @@ import { AuthWitness, EncryptedNoteL2BlockL2Logs, ExtendedNote, - ExtendedNoteWithNonce, ExtendedUnencryptedL2Log, L2Block, LogId, @@ -16,6 +15,7 @@ import { TxHash, TxReceipt, UnencryptedL2BlockL2Logs, + UniqueNote, } from '@aztec/circuit-types'; import { AztecAddress, @@ -46,7 +46,7 @@ export const createPXEClient = (url: string, fetch = makeFetch([1, 2, 3], false) FunctionSelector, EthAddress, ExtendedNote, - ExtendedNoteWithNonce, + UniqueNote, ExtendedUnencryptedL2Log, Fr, GrumpkinScalar, diff --git a/yarn-project/aztec.js/src/wallet/base_wallet.ts b/yarn-project/aztec.js/src/wallet/base_wallet.ts index 350f13ffb2df..b4c1ebec8307 100644 --- a/yarn-project/aztec.js/src/wallet/base_wallet.ts +++ b/yarn-project/aztec.js/src/wallet/base_wallet.ts @@ -3,7 +3,6 @@ import { type EventMetadata, type EventType, type ExtendedNote, - type ExtendedNoteWithNonce, type GetUnencryptedLogsResponse, type IncomingNotesFilter, type L2Block, @@ -18,6 +17,7 @@ import { type TxExecutionRequest, type TxHash, type TxReceipt, + type UniqueNote, } from '@aztec/circuit-types'; import { type NoteProcessorStats } from '@aztec/circuit-types/stats'; import { @@ -121,10 +121,10 @@ export abstract class BaseWallet implements Wallet { getTxReceipt(txHash: TxHash): Promise { return this.pxe.getTxReceipt(txHash); } - getIncomingNotes(filter: IncomingNotesFilter): Promise { + getIncomingNotes(filter: IncomingNotesFilter): Promise { return this.pxe.getIncomingNotes(filter); } - getOutgoingNotes(filter: OutgoingNotesFilter): Promise { + getOutgoingNotes(filter: OutgoingNotesFilter): Promise { return this.pxe.getOutgoingNotes(filter); } getPublicStorageAt(contract: AztecAddress, storageSlot: Fr): Promise { diff --git a/yarn-project/circuit-types/src/interfaces/pxe.ts b/yarn-project/circuit-types/src/interfaces/pxe.ts index 7b098a60d652..3fb1dad58e83 100644 --- a/yarn-project/circuit-types/src/interfaces/pxe.ts +++ b/yarn-project/circuit-types/src/interfaces/pxe.ts @@ -18,7 +18,7 @@ import { type AuthWitness } from '../auth_witness.js'; import { type L2Block } from '../l2_block.js'; import { type GetUnencryptedLogsResponse, type L1EventPayload, type LogFilter } from '../logs/index.js'; import { type IncomingNotesFilter } from '../notes/incoming_notes_filter.js'; -import { type ExtendedNote, type ExtendedNoteWithNonce, type OutgoingNotesFilter } from '../notes/index.js'; +import { type ExtendedNote, type OutgoingNotesFilter, type UniqueNote } from '../notes/index.js'; import { type NoteProcessorStats } from '../stats/stats.js'; import { type SimulatedTx, type Tx, type TxHash, type TxReceipt } from '../tx/index.js'; import { type TxEffect } from '../tx_effect.js'; @@ -235,14 +235,14 @@ export interface PXE { * @param filter - The filter to apply to the notes. * @returns The requested notes. */ - getIncomingNotes(filter: IncomingNotesFilter): Promise; + getIncomingNotes(filter: IncomingNotesFilter): Promise; /** * Gets outgoing notes of accounts registered in this PXE based on the provided filter. * @param filter - The filter to apply to the notes. * @returns The requested notes. */ - getOutgoingNotes(filter: OutgoingNotesFilter): Promise; + getOutgoingNotes(filter: OutgoingNotesFilter): Promise; /** * Adds a note to the database. diff --git a/yarn-project/circuit-types/src/mocks.ts b/yarn-project/circuit-types/src/mocks.ts index f5617a65f387..c8734f769ef8 100644 --- a/yarn-project/circuit-types/src/mocks.ts +++ b/yarn-project/circuit-types/src/mocks.ts @@ -31,7 +31,7 @@ import { Fr } from '@aztec/foundation/fields'; import { type ContractInstanceWithAddress, SerializableContractInstance } from '@aztec/types/contracts'; import { EncryptedNoteTxL2Logs, EncryptedTxL2Logs, Note, UnencryptedTxL2Logs } from './logs/index.js'; -import { ExtendedNote, ExtendedNoteWithNonce } from './notes/index.js'; +import { ExtendedNote, UniqueNote } from './notes/index.js'; import { PublicExecutionRequest } from './public_execution_request.js'; import { NestedProcessReturnValues, PublicSimulationOutput, SimulatedTx, Tx, TxHash } from './tx/index.js'; @@ -256,7 +256,7 @@ export const randomExtendedNote = ({ return new ExtendedNote(note, owner, contractAddress, storageSlot, noteTypeId, txHash); }; -export const randomExtendedNoteWithNonce = ({ +export const randomUniqueNote = ({ note = Note.random(), owner = AztecAddress.random(), contractAddress = AztecAddress.random(), @@ -264,6 +264,6 @@ export const randomExtendedNoteWithNonce = ({ storageSlot = Fr.random(), noteTypeId = NoteSelector.random(), nonce = Fr.random(), -}: Partial = {}) => { - return new ExtendedNoteWithNonce(note, owner, contractAddress, storageSlot, noteTypeId, txHash, nonce); +}: Partial = {}) => { + return new UniqueNote(note, owner, contractAddress, storageSlot, noteTypeId, txHash, nonce); }; diff --git a/yarn-project/circuit-types/src/notes/extended_note.test.ts b/yarn-project/circuit-types/src/notes/extended_note.test.ts index 33a9ed5b80bd..25a2280b5278 100644 --- a/yarn-project/circuit-types/src/notes/extended_note.test.ts +++ b/yarn-project/circuit-types/src/notes/extended_note.test.ts @@ -1,5 +1,5 @@ -import { randomExtendedNote, randomExtendedNoteWithNonce } from '../mocks.js'; -import { ExtendedNote, ExtendedNoteWithNonce } from './extended_note.js'; +import { randomExtendedNote, randomUniqueNote } from '../mocks.js'; +import { ExtendedNote, UniqueNote } from './extended_note.js'; describe('Extended Note', () => { it('convert to and from buffer', () => { @@ -9,10 +9,10 @@ describe('Extended Note', () => { }); }); -describe('Extended Note with nonce', () => { +describe('Unique Note', () => { it('convert to and from buffer', () => { - const extendedNote = randomExtendedNoteWithNonce(); - const buf = extendedNote.toBuffer(); - expect(ExtendedNoteWithNonce.fromBuffer(buf)).toEqual(extendedNote); + const uniqueNote = randomUniqueNote(); + const buf = uniqueNote.toBuffer(); + expect(UniqueNote.fromBuffer(buf)).toEqual(uniqueNote); }); }); diff --git a/yarn-project/circuit-types/src/notes/extended_note.ts b/yarn-project/circuit-types/src/notes/extended_note.ts index 8d0bda4ba0cd..4b3184563d00 100644 --- a/yarn-project/circuit-types/src/notes/extended_note.ts +++ b/yarn-project/circuit-types/src/notes/extended_note.ts @@ -58,7 +58,7 @@ export class ExtendedNote { } } -export class ExtendedNoteWithNonce extends ExtendedNote { +export class UniqueNote extends ExtendedNote { constructor( /** The note as emitted from the Noir contract. */ note: Note, @@ -106,6 +106,6 @@ export class ExtendedNoteWithNonce extends ExtendedNote { static override fromString(str: string) { const hex = str.replace(/^0x/, ''); - return ExtendedNoteWithNonce.fromBuffer(Buffer.from(hex, 'hex')); + return UniqueNote.fromBuffer(Buffer.from(hex, 'hex')); } } diff --git a/yarn-project/circuit-types/src/tx/tx_receipt.ts b/yarn-project/circuit-types/src/tx/tx_receipt.ts index fbab2ab4b1c4..e784e938c9c0 100644 --- a/yarn-project/circuit-types/src/tx/tx_receipt.ts +++ b/yarn-project/circuit-types/src/tx/tx_receipt.ts @@ -1,7 +1,7 @@ import { RevertCode } from '@aztec/circuits.js'; import { type Fr } from '@aztec/foundation/fields'; -import { type ExtendedNoteWithNonce } from '../notes/extended_note.js'; +import { type UniqueNote } from '../notes/extended_note.js'; import { type PublicDataWrite } from '../public_data_write.js'; import { TxHash } from './tx_hash.js'; @@ -126,11 +126,11 @@ interface DebugInfo { * in the PXE which was used to submit the tx. You will not get notes of accounts which are not registered in * the PXE here even though they were created in this tx. */ - visibleIncomingNotes: ExtendedNoteWithNonce[]; + visibleIncomingNotes: UniqueNote[]; /** * Notes created in this tx which were successfully decoded with the outgoing keys of accounts which are registered * in the PXE which was used to submit the tx. You will not get notes of accounts which are not registered in * the PXE here even though they were created in this tx. */ - visibleOutgoingNotes: ExtendedNoteWithNonce[]; + visibleOutgoingNotes: UniqueNote[]; } diff --git a/yarn-project/end-to-end/src/e2e_crowdfunding_and_claim.test.ts b/yarn-project/end-to-end/src/e2e_crowdfunding_and_claim.test.ts index ae21d495205d..d143c627bb56 100644 --- a/yarn-project/end-to-end/src/e2e_crowdfunding_and_claim.test.ts +++ b/yarn-project/end-to-end/src/e2e_crowdfunding_and_claim.test.ts @@ -6,13 +6,13 @@ import { type CheatCodes, type DebugLogger, ExtendedNote, - type ExtendedNoteWithNonce, Fr, Note, type PXE, PackedValues, TxExecutionRequest, type TxHash, + type UniqueNote, computeSecretHash, deriveKeys, } from '@aztec/aztec.js'; @@ -181,22 +181,22 @@ describe('e2e_crowdfunding_and_claim', () => { ]); }; - // Processes extended note such that it can be passed to a claim function of Claim contract - const processExtendedNote = (extendedNote: ExtendedNoteWithNonce) => { + // Processes unique note such that it can be passed to a claim function of Claim contract + const processUniqueNote = (uniqueNote: UniqueNote) => { return { header: { // eslint-disable-next-line camelcase - contract_address: extendedNote.contractAddress, + contract_address: uniqueNote.contractAddress, // eslint-disable-next-line camelcase - storage_slot: extendedNote.storageSlot, + storage_slot: uniqueNote.storageSlot, // eslint-disable-next-line camelcase note_hash_counter: 0, // set as 0 as note is not transient - nonce: extendedNote.nonce, + nonce: uniqueNote.nonce, }, - value: extendedNote.note.items[0], + value: uniqueNote.note.items[0], // eslint-disable-next-line camelcase - npk_m_hash: extendedNote.note.items[1], - randomness: extendedNote.note.items[2], + npk_m_hash: uniqueNote.note.items[1], + randomness: uniqueNote.note.items[2], }; }; @@ -229,7 +229,7 @@ describe('e2e_crowdfunding_and_claim', () => { expect(notes!.length).toEqual(1); // Set the value note in a format which can be passed to claim function - valueNote = processExtendedNote(notes![0]); + valueNote = processUniqueNote(notes![0]); } // 3) We claim the reward token via the Claim contract @@ -300,7 +300,7 @@ describe('e2e_crowdfunding_and_claim', () => { expect(notes!.length).toEqual(1); // Set the value note in a format which can be passed to claim function - const anotherDonationNote = processExtendedNote(notes![0]); + const anotherDonationNote = processUniqueNote(notes![0]); // We create an unrelated pxe and wallet without access to the nsk_app that correlates to the npk_m specified in the proof note. let unrelatedWallet: AccountWallet; @@ -352,7 +352,7 @@ describe('e2e_crowdfunding_and_claim', () => { const receipt = await inclusionsProofsContract.methods.create_note(owner, 5n).send().wait({ debug: true }); const { visibleIncomingNotes } = receipt.debugInfo!; expect(visibleIncomingNotes.length).toEqual(1); - note = processExtendedNote(visibleIncomingNotes![0]); + note = processUniqueNote(visibleIncomingNotes![0]); } // 3) Test the note was included diff --git a/yarn-project/pxe/src/pxe_http/pxe_http_server.ts b/yarn-project/pxe/src/pxe_http/pxe_http_server.ts index 5390fb33355a..3a99d2b572a0 100644 --- a/yarn-project/pxe/src/pxe_http/pxe_http_server.ts +++ b/yarn-project/pxe/src/pxe_http/pxe_http_server.ts @@ -3,7 +3,6 @@ import { CompleteAddress, EncryptedNoteL2BlockL2Logs, ExtendedNote, - ExtendedNoteWithNonce, ExtendedUnencryptedL2Log, L2Block, LogId, @@ -17,6 +16,7 @@ import { TxHash, TxReceipt, UnencryptedL2BlockL2Logs, + UniqueNote, } from '@aztec/circuit-types'; import { FunctionSelector } from '@aztec/circuits.js'; import { NoteSelector } from '@aztec/foundation/abi'; @@ -49,7 +49,7 @@ export function createPXERpcServer(pxeService: PXE): JsonRpcServer { GrumpkinScalar, Note, ExtendedNote, - ExtendedNoteWithNonce, + UniqueNote, AuthWitness, L2Block, TxEffect, diff --git a/yarn-project/pxe/src/pxe_service/pxe_service.ts b/yarn-project/pxe/src/pxe_service/pxe_service.ts index 31405b79c42f..388acd20ea48 100644 --- a/yarn-project/pxe/src/pxe_service/pxe_service.ts +++ b/yarn-project/pxe/src/pxe_service/pxe_service.ts @@ -6,7 +6,6 @@ import { type EventMetadata, EventType, type ExtendedNote, - ExtendedNoteWithNonce, type FunctionCall, type GetUnencryptedLogsResponse, type IncomingNotesFilter, @@ -27,6 +26,7 @@ import { type TxHash, type TxReceipt, UnencryptedTxL2Logs, + UniqueNote, isNoirCallStackUnresolved, } from '@aztec/circuit-types'; import { @@ -297,7 +297,7 @@ export class PXEService implements PXE { return await this.node.getPublicStorageAt(contract, slot, 'latest'); } - public async getIncomingNotes(filter: IncomingNotesFilter): Promise { + public async getIncomingNotes(filter: IncomingNotesFilter): Promise { const noteDaos = await this.db.getIncomingNotes(filter); // TODO(#6531): Refactor --> This type conversion is ugly but I decided to keep it this way for now because @@ -313,7 +313,7 @@ export class PXEService implements PXE { } owner = completeAddresses.address; } - return new ExtendedNoteWithNonce( + return new UniqueNote( dao.note, owner, dao.contractAddress, @@ -326,7 +326,7 @@ export class PXEService implements PXE { return Promise.all(extendedNotes); } - public async getOutgoingNotes(filter: OutgoingNotesFilter): Promise { + public async getOutgoingNotes(filter: OutgoingNotesFilter): Promise { const noteDaos = await this.db.getOutgoingNotes(filter); // TODO(#6532): Refactor --> This type conversion is ugly but I decided to keep it this way for now because @@ -342,7 +342,7 @@ export class PXEService implements PXE { } owner = completeAddresses.address; } - return new ExtendedNoteWithNonce( + return new UniqueNote( dao.note, owner, dao.contractAddress, From f72da7d68866af961eb1c7054fec5a3a547b314f Mon Sep 17 00:00:00 2001 From: esau <152162806+sklppy88@users.noreply.github.com> Date: Tue, 13 Aug 2024 10:17:43 -0500 Subject: [PATCH 3/3] Update yarn-project/pxe/src/pxe_service/pxe_service.ts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Jan Beneš --- yarn-project/pxe/src/pxe_service/pxe_service.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/yarn-project/pxe/src/pxe_service/pxe_service.ts b/yarn-project/pxe/src/pxe_service/pxe_service.ts index 388acd20ea48..cdb96184d8da 100644 --- a/yarn-project/pxe/src/pxe_service/pxe_service.ts +++ b/yarn-project/pxe/src/pxe_service/pxe_service.ts @@ -457,7 +457,6 @@ export class PXEService implements PXE { * @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. - * TODO(#4956): Un-expose this */ async #getNoteNonces(note: ExtendedNote): Promise { const tx = await this.node.getTxEffect(note.txHash);