Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: add note to deliver note #10482

Open
wants to merge 1 commit into
base: ek/refactor/pxe-cleanup/remove-get-outgoing-notes-from-interface
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions yarn-project/aztec.js/src/wallet/base_wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,8 @@ export abstract class BaseWallet implements Wallet {
getPublicStorageAt(contract: AztecAddress, storageSlot: Fr): Promise<any> {
return this.pxe.getPublicStorageAt(contract, storageSlot);
}
addNote(note: ExtendedNote): Promise<void> {
return this.pxe.addNote(note, this.getAddress());
}
addNullifiedNote(note: ExtendedNote): Promise<void> {
return this.pxe.addNullifiedNote(note);
deliverNote(note: ExtendedNote, isNullified?: boolean): Promise<void> {
return this.pxe.deliverNote(note, isNullified, this.getAddress());
}
getBlock(number: number): Promise<L2Block | undefined> {
return this.pxe.getBlock(number);
Expand Down
16 changes: 5 additions & 11 deletions yarn-project/circuit-types/src/interfaces/pxe.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,12 +203,9 @@ describe('PXESchema', () => {
expect(result).toEqual([expect.any(BigInt), expect.any(SiblingPath)]);
});

it('addNote', async () => {
await context.client.addNote(ExtendedNote.random(), address);
});

it('addNullifiedNote', async () => {
await context.client.addNullifiedNote(ExtendedNote.random());
it('deliverNote', async () => {
await context.client.deliverNote(ExtendedNote.random(), false, address);
await context.client.deliverNote(ExtendedNote.random(), true, address);
});

it('getBlock', async () => {
Expand Down Expand Up @@ -419,15 +416,12 @@ 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<void> {
deliverNote(note: ExtendedNote, isNullified: boolean = false, scope?: AztecAddress): Promise<void> {
expect(note).toBeInstanceOf(ExtendedNote);
expect(typeof isNullified).toBe('boolean');
expect(scope).toEqual(this.address);
return Promise.resolve();
}
addNullifiedNote(note: ExtendedNote): Promise<void> {
expect(note).toBeInstanceOf(ExtendedNote);
return Promise.resolve();
}
getBlock(number: number): Promise<L2Block | undefined> {
return Promise.resolve(L2Block.random(number));
}
Expand Down
22 changes: 9 additions & 13 deletions yarn-project/circuit-types/src/interfaces/pxe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,22 +246,16 @@ export interface PXE {
): Promise<[bigint, SiblingPath<typeof L1_TO_L2_MSG_TREE_HEIGHT>]>;

/**
* Adds a note to the database.
* @throws If the note hash of the note doesn't exist in the tree.
* @param note - The note to add.
* Delivers a previously created note to the database. This note can be non-nullified or nullified.
* @param note - The note to deliver.
* @param nullified - Whether or not the note we want to deliver is nullified. Currently optional.
* @param scope - The scope to add the note under. Currently optional.
*/
addNote(note: ExtendedNote, scope?: AztecAddress): Promise<void>;

/**
* Adds a nullified note to the database.
* @throws If the note hash of the note doesn't exist in the tree.
* @param note - The note to add.
* @dev We are not deriving a nullifier in this function since that would require having the nullifier secret key
* @dev When we deliver a nullified note, we are not deriving a nullifier in this function since that would require having the nullifier secret key
* 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<void>;
deliverNote(note: ExtendedNote, nullified?: boolean, scope?: AztecAddress): Promise<void>;

/**
* Get the given block.
Expand Down Expand Up @@ -503,8 +497,10 @@ export const PXESchema: ApiSchemaFor<PXE> = {
.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())
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/cli-wallet/src/cmds/add_note.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
2 changes: 1 addition & 1 deletion yarn-project/end-to-end/src/e2e_2_pxes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down
12 changes: 10 additions & 2 deletions yarn-project/pxe/src/pxe_service/pxe_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,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()}`);
Expand Down Expand Up @@ -392,7 +400,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}.`);
Expand Down
Loading