Skip to content

Commit

Permalink
DBOracle.getMembershipWitness instead of DBOracle.getSiblingPath
Browse files Browse the repository at this point in the history
  • Loading branch information
benesjan committed Jan 7, 2025
1 parent 33e4857 commit d396bb3
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 24 deletions.
13 changes: 12 additions & 1 deletion yarn-project/pxe/src/simulator_oracle/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,18 @@ export class SimulatorOracle implements DBOracle {
return leafIndex;
}

public async getSiblingPath(blockNumber: number, treeId: MerkleTreeId, leafIndex: bigint): Promise<Fr[]> {
public async getMembershipWitness(blockNumber: number, treeId: MerkleTreeId, leafValue: Fr): Promise<Fr[]> {
const leafIndex = await this.findLeafIndex(blockNumber, treeId, leafValue);
if (!leafIndex) {
throw new Error(`Leaf value: ${leafValue} not found in ${MerkleTreeId[treeId]}`);
}

const siblingPath = await this.#getSiblingPath(blockNumber, treeId, leafIndex);

return [new Fr(leafIndex), ...siblingPath];
}

async #getSiblingPath(blockNumber: number, treeId: MerkleTreeId, leafIndex: bigint): Promise<Fr[]> {
switch (treeId) {
case MerkleTreeId.NULLIFIER_TREE:
return (await this.aztecNode.getNullifierSiblingPath(blockNumber, leafIndex)).toFields();
Expand Down
12 changes: 6 additions & 6 deletions yarn-project/simulator/src/client/db_oracle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,13 +150,13 @@ export interface DBOracle extends CommitmentsDB {
findLeafIndex(blockNumber: L2BlockNumber, treeId: MerkleTreeId, leafValue: Fr): Promise<bigint | undefined>;

/**
* Fetch the sibling path of the leaf in the respective tree
* @param blockNumber - The block number at which to get the sibling path.
* @param treeId - The id of the tree to search.
* @param leafIndex - The index of the leaf.
* @returns - The sibling path of the leaf.
* Fetches the index and sibling path of a leaf at a given block from a given tree.
* @param blockNumber - The block number at which to get the membership witness.
* @param treeId - Id of the tree to get the sibling path from.
* @param leafValue - The leaf value
* @returns The index and sibling path concatenated [index, sibling_path]
*/
getSiblingPath(blockNumber: number, treeId: MerkleTreeId, leafIndex: bigint): Promise<Fr[]>;
getMembershipWitness(blockNumber: number, treeId: MerkleTreeId, leafValue: Fr): Promise<Fr[]>;

/**
* Returns a nullifier membership witness for a given nullifier at a given block.
Expand Down
11 changes: 3 additions & 8 deletions yarn-project/simulator/src/client/view_data_oracle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {
type AuthWitness,
type AztecNode,
type CompleteAddress,
MerkleTreeId,
type MerkleTreeId,
type NoteStatus,
type NullifierMembershipWitness,
type PublicDataWitness,
Expand Down Expand Up @@ -72,13 +72,8 @@ export class ViewDataOracle extends TypedOracle {
* @param leafValue - The leaf value
* @returns The index and sibling path concatenated [index, sibling_path]
*/
public override async getMembershipWitness(blockNumber: number, treeId: MerkleTreeId, leafValue: Fr): Promise<Fr[]> {
const index = await this.db.findLeafIndex(blockNumber, treeId, leafValue);
if (!index) {
throw new Error(`Leaf value: ${leafValue} not found in ${MerkleTreeId[treeId]}`);
}
const siblingPath = await this.db.getSiblingPath(blockNumber, treeId, index);
return [new Fr(index), ...siblingPath];
public override getMembershipWitness(blockNumber: number, treeId: MerkleTreeId, leafValue: Fr): Promise<Fr[]> {
return this.db.getMembershipWitness(blockNumber, treeId, leafValue);
}

/**
Expand Down
9 changes: 0 additions & 9 deletions yarn-project/txe/src/txe_service/txe_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -334,15 +334,6 @@ export class TXEService {
return toForeignCallResult([toArray(witness.toFields())]);
}

async getSiblingPath(blockNumber: ForeignCallSingle, treeId: ForeignCallSingle, leafIndex: ForeignCallSingle) {
const result = await this.typedOracle.getSiblingPath(
fromSingle(blockNumber).toNumber(),
fromSingle(treeId).toNumber(),
fromSingle(leafIndex),
);
return toForeignCallResult([toArray(result)]);
}

async getNotes(
storageSlot: ForeignCallSingle,
numSelects: ForeignCallSingle,
Expand Down

0 comments on commit d396bb3

Please sign in to comment.