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

feat: expose getL2ToL1Membership on the pxe #11215

Merged
merged 1 commit into from
Jan 15, 2025
Merged
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
1 change: 1 addition & 0 deletions yarn-project/aztec.js/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export {
type L2AmountClaimWithRecipient,
type L2Claim,
type WrappedFieldLike,
type IntentAction,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

} from './utils/index.js';

export { NoteSelector } from '@aztec/foundation/abi';
Expand Down
3 changes: 3 additions & 0 deletions yarn-project/aztec.js/src/wallet/base_wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,4 +211,7 @@ export abstract class BaseWallet implements Wallet {
): Promise<[bigint, SiblingPath<typeof L1_TO_L2_MSG_TREE_HEIGHT>]> {
return this.pxe.getL1ToL2MembershipWitness(contractAddress, messageHash, secret);
}
getL2ToL1MembershipWitness(blockNumber: number, l2Tol1Message: Fr): Promise<[bigint, SiblingPath<number>]> {
return this.pxe.getL2ToL1MembershipWitness(blockNumber, l2Tol1Message);
}
}
10 changes: 10 additions & 0 deletions yarn-project/circuit-types/src/interfaces/pxe.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,11 @@ describe('PXESchema', () => {
expect(result).toEqual([expect.any(BigInt), expect.any(SiblingPath)]);
});

it('getL2ToL1MembershipWitness', async () => {
const result = await context.client.getL2ToL1MembershipWitness(42, Fr.random());
expect(result).toEqual([expect.any(BigInt), expect.any(SiblingPath)]);
});

it('addNote', async () => {
await context.client.addNote(ExtendedNote.random(), address);
});
Expand Down Expand Up @@ -423,6 +428,11 @@ class MockPXE implements PXE {
expect(secret).toBeInstanceOf(Fr);
return Promise.resolve([1n, SiblingPath.random(L1_TO_L2_MSG_TREE_HEIGHT)]);
}
getL2ToL1MembershipWitness(blockNumber: number, l2Tol1Message: Fr): Promise<[bigint, SiblingPath<number>]> {
expect(typeof blockNumber).toEqual('number');
expect(l2Tol1Message).toBeInstanceOf(Fr);
return Promise.resolve([1n, SiblingPath.random<number>(4)]);
}
addNote(note: ExtendedNote, scope?: AztecAddress | undefined): Promise<void> {
expect(note).toBeInstanceOf(ExtendedNote);
expect(scope).toEqual(this.address);
Expand Down
12 changes: 12 additions & 0 deletions yarn-project/circuit-types/src/interfaces/pxe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,14 @@ export interface PXE {
secret: Fr,
): Promise<[bigint, SiblingPath<typeof L1_TO_L2_MSG_TREE_HEIGHT>]>;

/**
* Gets the membership witness for a message that was emitted at a particular block
* @param blockNumber - The block number in which to search for the message
* @param l2Tol1Message - The message to search for
* @returns The membership witness for the message
*/
getL2ToL1MembershipWitness(blockNumber: number, l2Tol1Message: Fr): Promise<[bigint, SiblingPath<number>]>;

/**
* Adds a note to the database.
* @throws If the note hash of the note doesn't exist in the tree.
Expand Down Expand Up @@ -488,6 +496,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)])),
getL2ToL1MembershipWitness: z
.function()
.args(z.number(), schemas.Fr)
.returns(z.tuple([schemas.BigInt, SiblingPath.schema])),
addNote: z.function().args(ExtendedNote.schema, optional(schemas.AztecAddress)).returns(z.void()),
addNullifiedNote: z.function().args(ExtendedNote.schema).returns(z.void()),
getBlock: z
Expand Down
4 changes: 4 additions & 0 deletions yarn-project/pxe/src/pxe_service/pxe_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,10 @@ export class PXEService implements PXE {
return await getNonNullifiedL1ToL2MessageWitness(this.node, contractAddress, messageHash, secret);
}

public getL2ToL1MembershipWitness(blockNumber: number, l2Tol1Message: Fr): Promise<[bigint, SiblingPath<number>]> {
return this.node.getL2ToL1MessageMembershipWitness(blockNumber, l2Tol1Message);
}

public async addNote(note: ExtendedNote, scope?: AztecAddress) {
const owner = await this.db.getCompleteAddress(note.owner);
if (!owner) {
Expand Down
Loading