Skip to content
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
13 changes: 2 additions & 11 deletions yarn-project/pxe/src/pxe_oracle_interface/pxe_oracle_interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,21 +150,12 @@ export class PXEOracleInterface implements ExecutionDataProvider {
}

// Only used in public.
public getL1ToL2LeafValue(_leafIndex: bigint): Promise<Fr | undefined> {
public getL1ToL2MessageHash(_leafIndex: bigint): Promise<Fr | undefined> {
throw new Error('Unimplemented in private!');
}

/**
* Gets the index of a commitment in the note hash tree.
* @param commitment - The commitment.
* @returns - The index of the commitment. Undefined if it does not exist in the tree.
*/
async getCommitmentIndex(commitment: Fr) {
return await this.#findLeafIndex('latest', MerkleTreeId.NOTE_HASH_TREE, commitment);
}

// We need this in public as part of the EXISTS calls - but isn't used in private
public getCommitmentValue(_leafIndex: bigint): Promise<Fr | undefined> {
public getNoteHash(_leafIndex: bigint): Promise<Fr | undefined> {
throw new Error('Unimplemented in private!');
}

Expand Down
19 changes: 6 additions & 13 deletions yarn-project/simulator/src/common/db_interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export interface PublicContractsDBInterface {
getDebugFunctionName(contractAddress: AztecAddress, selector: FunctionSelector): Promise<string | undefined>;
}

/** Database interface for providing access to commitment tree, l1 to l2 message tree, and nullifier tree. */
/** Database interface for providing access to note hash tree, l1 to l2 message tree, and nullifier tree. */
export interface CommitmentsDBInterface {
/**
* Fetches a message from the db, given its key.
Expand All @@ -81,23 +81,16 @@ export interface CommitmentsDBInterface {

/**
* @param leafIndex the leaf to look up
* @returns The l1 to l2 leaf value or undefined if not found.
* @returns The l1 to l2 leaf message hash or undefined if not found.
*/
getL1ToL2LeafValue(leafIndex: bigint): Promise<Fr | undefined>;
getL1ToL2MessageHash(leafIndex: bigint): Promise<Fr | undefined>;

/**
* Gets the index of a commitment in the note hash tree.
* @param commitment - The commitment.
* @returns - The index of the commitment. Undefined if it does not exist in the tree.
*/
getCommitmentIndex(commitment: Fr): Promise<bigint | undefined>;

/**
* Gets commitment in the note hash tree given a leaf index.
* Gets note hash in the note hash tree at the given leaf index.
* @param leafIndex - the leaf to look up.
* @returns - The commitment at that index. Undefined if leaf index is not found.
* @returns - The note hash at that index. Undefined if leaf index is not found.
*/
getCommitmentValue(leafIndex: bigint): Promise<Fr | undefined>;
getNoteHash(leafIndex: bigint): Promise<Fr | undefined>;

/**
* Gets the index of a nullifier in the nullifier tree.
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/simulator/src/public/avm/journal/journal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ export class AvmPersistableStateManager {
* @returns true if the note hash exists at the given leaf index, false otherwise
*/
public async checkNoteHashExists(contractAddress: AztecAddress, noteHash: Fr, leafIndex: Fr): Promise<boolean> {
const gotLeafValue = (await this.treesDB.getCommitmentValue(leafIndex.toBigInt())) ?? Fr.ZERO;
const gotLeafValue = (await this.treesDB.getNoteHash(leafIndex.toBigInt())) ?? Fr.ZERO;
const exists = gotLeafValue.equals(noteHash);
this.log.trace(
`noteHashes(${contractAddress})@${noteHash} ?? leafIndex: ${leafIndex} | gotLeafValue: ${gotLeafValue}, exists: ${exists}.`,
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/simulator/src/public/avm/test_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export function mockStorageReadWithMap(worldStateDB: PublicTreesDB, mockedStorag
}

export function mockNoteHashExists(worldStateDB: PublicTreesDB, _leafIndex: Fr, value?: Fr) {
(worldStateDB as jest.Mocked<PublicTreesDB>).getCommitmentValue.mockImplementation((index: bigint) => {
(worldStateDB as jest.Mocked<PublicTreesDB>).getNoteHash.mockImplementation((index: bigint) => {
if (index == _leafIndex.toBigInt()) {
return Promise.resolve(value);
} else {
Expand Down
6 changes: 3 additions & 3 deletions yarn-project/simulator/src/public/public_db_sources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -431,13 +431,13 @@ export class PublicTreesDB extends ForwardMerkleTree implements PublicStateDBInt
return leafValue;
}

public async getCommitmentValue(leafIndex: bigint): Promise<Fr | undefined> {
public async getNoteHash(leafIndex: bigint): Promise<Fr | undefined> {
const timer = new Timer();
const leafValue = await this.db.getLeafValue(MerkleTreeId.NOTE_HASH_TREE, leafIndex);
this.logger.debug(`[DB] Fetched commitment leaf value`, {
this.logger.debug(`[DB] Fetched note hash leaf value`, {
eventName: 'public-db-access',
duration: timer.ms(),
operation: 'get-commitment-leaf-value',
operation: 'get-note-hash',
} satisfies PublicDBAccessStats);
return leafValue;
}
Expand Down