From 5168e57e2b981b8f5434040add634c75c0a08b53 Mon Sep 17 00:00:00 2001 From: sklppy88 Date: Sat, 7 Dec 2024 21:10:14 +0000 Subject: [PATCH] init --- .../aztec.js/src/wallet/base_wallet.ts | 7 ++--- .../circuit-types/src/interfaces/pxe.test.ts | 31 +++++++++++-------- .../circuit-types/src/interfaces/pxe.ts | 7 ++--- yarn-project/cli-wallet/src/cmds/add_note.ts | 2 +- .../src/composed/e2e_persistence.test.ts | 2 +- .../end-to-end/src/e2e_2_pxes.test.ts | 2 +- .../blacklist_token_contract_test.ts | 2 +- .../src/e2e_non_contract_account.test.ts | 2 +- .../pxe/src/pxe_service/pxe_service.ts | 12 +++++-- 9 files changed, 37 insertions(+), 30 deletions(-) diff --git a/yarn-project/aztec.js/src/wallet/base_wallet.ts b/yarn-project/aztec.js/src/wallet/base_wallet.ts index db69a1347ac..75579fc7ae5 100644 --- a/yarn-project/aztec.js/src/wallet/base_wallet.ts +++ b/yarn-project/aztec.js/src/wallet/base_wallet.ts @@ -122,11 +122,8 @@ export abstract class BaseWallet implements Wallet { getPublicStorageAt(contract: AztecAddress, storageSlot: Fr): Promise { return this.pxe.getPublicStorageAt(contract, storageSlot); } - addNote(note: ExtendedNote): Promise { - return this.pxe.addNote(note, this.getAddress()); - } - addNullifiedNote(note: ExtendedNote): Promise { - return this.pxe.addNullifiedNote(note); + deliverNote(note: ExtendedNote, isNullified?: boolean): Promise { + return this.pxe.deliverNote(note, isNullified, this.getAddress()); } getBlock(number: number): Promise { return this.pxe.getBlock(number); diff --git a/yarn-project/circuit-types/src/interfaces/pxe.test.ts b/yarn-project/circuit-types/src/interfaces/pxe.test.ts index ffeb3f57e9b..800e51ec8e9 100644 --- a/yarn-project/circuit-types/src/interfaces/pxe.test.ts +++ b/yarn-project/circuit-types/src/interfaces/pxe.test.ts @@ -196,13 +196,13 @@ describe('PXESchema', () => { expect(result).toEqual([expect.any(BigInt), expect.any(SiblingPath)]); }); - it('addNote', async () => { - await context.client.addNote(ExtendedNote.random(), address); - }); + // it('addNote', async () => { + // await context.client.addNote(ExtendedNote.random(), address); + // }); - it('addNullifiedNote', async () => { - await context.client.addNullifiedNote(ExtendedNote.random()); - }); + // it('addNullifiedNote', async () => { + // await context.client.addNullifiedNote(ExtendedNote.random()); + // }); it('getBlock', async () => { const result = await context.client.getBlock(1); @@ -423,15 +423,20 @@ class MockPXE implements PXE { expect(secret).toBeInstanceOf(Fr); return Promise.resolve([1n, SiblingPath.random(L1_TO_L2_MSG_TREE_HEIGHT)]); } - addNote(note: ExtendedNote, scope?: AztecAddress | undefined): Promise { + deliverNote(note: ExtendedNote, _isNullified?: boolean, scope?: AztecAddress): Promise { expect(note).toBeInstanceOf(ExtendedNote); expect(scope).toEqual(this.address); return Promise.resolve(); } - addNullifiedNote(note: ExtendedNote): Promise { - expect(note).toBeInstanceOf(ExtendedNote); - return Promise.resolve(); - } + // addNote(note: ExtendedNote, scope?: AztecAddress | undefined): Promise { + // expect(note).toBeInstanceOf(ExtendedNote); + // expect(scope).toEqual(this.address); + // return Promise.resolve(); + // } + // addNullifiedNote(note: ExtendedNote): Promise { + // expect(note).toBeInstanceOf(ExtendedNote); + // return Promise.resolve(); + // } getBlock(number: number): Promise { return Promise.resolve(L2Block.random(number)); } @@ -496,10 +501,10 @@ class MockPXE implements PXE { blocks: 1, }); } - getContractClassMetadata(id: Fr, includeArtifact: boolean = false): Promise<[ContractClassWithId | undefined, boolean, ContractArtifact | undefined]> { + getContractClassMetadata(id: Fr, _includeArtifact: boolean = false): Promise<[ContractClassWithId | undefined, boolean, ContractArtifact | undefined]> { throw new Error('Unimplemented'); } - getContractMetadata(address: AztecAddress): Promise<[ContractInstanceWithAddress | undefined, boolean, boolean]> { + getContractMetadata(_address: AztecAddress): Promise<[ContractInstanceWithAddress | undefined, boolean, boolean]> { throw new Error('Unimplemented'); } // getContractInstance(address: AztecAddress): Promise { diff --git a/yarn-project/circuit-types/src/interfaces/pxe.ts b/yarn-project/circuit-types/src/interfaces/pxe.ts index f6eb1008427..fbb492b8642 100644 --- a/yarn-project/circuit-types/src/interfaces/pxe.ts +++ b/yarn-project/circuit-types/src/interfaces/pxe.ts @@ -251,8 +251,6 @@ export interface PXE { * @param note - The note to add. * @param scope - The scope to add the note under. Currently optional. */ - addNote(note: ExtendedNote, scope?: AztecAddress): Promise; - /** * Adds a nullified note to the database. * @throws If the note hash of the note doesn't exist in the tree. @@ -261,7 +259,7 @@ export interface PXE { * which is undesirable. Instead, we are just adding the note to the database as nullified and the nullifier is set * to 0 in the db. */ - addNullifiedNote(note: ExtendedNote): Promise; + deliverNote(note: ExtendedNote, nullified?: boolean, scope?: AztecAddress): Promise; /** * Get the given block. @@ -487,8 +485,7 @@ export const PXESchema: ApiSchemaFor = { .function() .args(schemas.AztecAddress, schemas.Fr, schemas.Fr) .returns(z.tuple([schemas.BigInt, SiblingPath.schemaFor(L1_TO_L2_MSG_TREE_HEIGHT)])), - addNote: z.function().args(ExtendedNote.schema, optional(schemas.AztecAddress)).returns(z.void()), - addNullifiedNote: z.function().args(ExtendedNote.schema).returns(z.void()), + deliverNote: z.function().args(ExtendedNote.schema, optional(z.boolean()), optional(schemas.AztecAddress)).returns(z.void()), getBlock: z .function() .args(z.number()) diff --git a/yarn-project/cli-wallet/src/cmds/add_note.ts b/yarn-project/cli-wallet/src/cmds/add_note.ts index 94f7a80e1a5..1318f9c2b6b 100644 --- a/yarn-project/cli-wallet/src/cmds/add_note.ts +++ b/yarn-project/cli-wallet/src/cmds/add_note.ts @@ -26,5 +26,5 @@ export async function addNote( } const extendedNote = new ExtendedNote(note, address, contractAddress, storageField.slot, contractNote.id, txHash); - await wallet.addNote(extendedNote); + await wallet.deliverNote(extendedNote); } diff --git a/yarn-project/end-to-end/src/composed/e2e_persistence.test.ts b/yarn-project/end-to-end/src/composed/e2e_persistence.test.ts index df8cbcc47b0..e86be31cca9 100644 --- a/yarn-project/end-to-end/src/composed/e2e_persistence.test.ts +++ b/yarn-project/end-to-end/src/composed/e2e_persistence.test.ts @@ -337,6 +337,6 @@ async function addPendingShieldNoteToPXE( TokenBlacklistContract.notes.TransparentNote.id, txHash, ); - await wallet.addNote(extendedNote); + await wallet.deliverNote(extendedNote); // docs:end:pxe_add_note } diff --git a/yarn-project/end-to-end/src/e2e_2_pxes.test.ts b/yarn-project/end-to-end/src/e2e_2_pxes.test.ts index 654fbf24da1..98dcddc3069 100644 --- a/yarn-project/end-to-end/src/e2e_2_pxes.test.ts +++ b/yarn-project/end-to-end/src/e2e_2_pxes.test.ts @@ -271,7 +271,7 @@ describe('e2e_2_pxes', () => { { // We need to register the contract to be able to compute the note hash by calling compute_note_hash_and_optionally_a_nullifier(...) await pxeB.registerContract(testContract); - await pxeB.addNullifiedNote(note); + await pxeB.deliverNote(note, true); } // 5. Try fetching the nullified note diff --git a/yarn-project/end-to-end/src/e2e_blacklist_token_contract/blacklist_token_contract_test.ts b/yarn-project/end-to-end/src/e2e_blacklist_token_contract/blacklist_token_contract_test.ts index e2ca5a2fa64..4f6813d3cfe 100644 --- a/yarn-project/end-to-end/src/e2e_blacklist_token_contract/blacklist_token_contract_test.ts +++ b/yarn-project/end-to-end/src/e2e_blacklist_token_contract/blacklist_token_contract_test.ts @@ -164,7 +164,7 @@ export class BlacklistTokenContractTest { TokenBlacklistContract.notes.TransparentNote.id, txHash, ); - await this.wallets[accountIndex].addNote(extendedNote); + await this.wallets[accountIndex].deliverNote(extendedNote); } async applyMintSnapshot() { diff --git a/yarn-project/end-to-end/src/e2e_non_contract_account.test.ts b/yarn-project/end-to-end/src/e2e_non_contract_account.test.ts index 54e377ad4e9..d507f0b91e9 100644 --- a/yarn-project/end-to-end/src/e2e_non_contract_account.test.ts +++ b/yarn-project/end-to-end/src/e2e_non_contract_account.test.ts @@ -67,7 +67,7 @@ describe('e2e_non_contract_account', () => { TestContract.notes.TestNote.id, txHash, ); - await wallet.addNote(extendedNote); + await wallet.deliverNote(extendedNote); expect(await contract.methods.get_constant().simulate()).toEqual(value); }); diff --git a/yarn-project/pxe/src/pxe_service/pxe_service.ts b/yarn-project/pxe/src/pxe_service/pxe_service.ts index 017694f7df0..2adb02a02fe 100644 --- a/yarn-project/pxe/src/pxe_service/pxe_service.ts +++ b/yarn-project/pxe/src/pxe_service/pxe_service.ts @@ -328,7 +328,15 @@ export class PXEService implements PXE { return await getNonNullifiedL1ToL2MessageWitness(this.node, contractAddress, messageHash, secret); } - public async addNote(note: ExtendedNote, scope?: AztecAddress) { + public async deliverNote(note: ExtendedNote, nullified: boolean = false, scope?: AztecAddress,) { + if (!nullified) { + await this.#addNote(note, scope); + } else { + await this.#addNullifiedNote(note); + } + } + + async #addNote(note: ExtendedNote, scope?: AztecAddress) { const owner = await this.db.getCompleteAddress(note.owner); if (!owner) { throw new Error(`Unknown account: ${note.owner.toString()}`); @@ -382,7 +390,7 @@ export class PXEService implements PXE { } } - public async addNullifiedNote(note: ExtendedNote) { + async #addNullifiedNote(note: ExtendedNote) { const { data: nonces, l2BlockHash, l2BlockNumber } = await this.#getNoteNonces(note); if (nonces.length === 0) { throw new Error(`Cannot find the note in tx: ${note.txHash}.`);