From 4742cd46abbbe96579269e6b08abab49fd2f1ab5 Mon Sep 17 00:00:00 2001 From: LHerskind Date: Fri, 29 Sep 2023 16:31:49 +0000 Subject: [PATCH] refactor: remove unecessary findXIndex --- .../src/aztec-node/http_rpc_server.ts | 10 +------ .../aztec-node/src/aztec-node/server.ts | 27 ------------------- yarn-project/pxe/src/contract_tree/index.ts | 7 +++-- .../pxe/src/pxe_service/pxe_service.ts | 5 ++-- .../types/src/interfaces/state_provider.ts | 21 --------------- 5 files changed, 9 insertions(+), 61 deletions(-) diff --git a/yarn-project/aztec-node/src/aztec-node/http_rpc_server.ts b/yarn-project/aztec-node/src/aztec-node/http_rpc_server.ts index e1fb672952be..cd740d9c44fe 100644 --- a/yarn-project/aztec-node/src/aztec-node/http_rpc_server.ts +++ b/yarn-project/aztec-node/src/aztec-node/http_rpc_server.ts @@ -17,15 +17,7 @@ export function createAztecNodeRpcServer(node: AztecNode) { { Tx, L2BlockL2Logs }, false, // disable methods not part of the AztecNode interface - [ - 'start', - 'stop', - 'findContractIndex', - 'findCommitmentIndex', - 'getDataTreePath', - 'getL1ToL2MessageAndIndex', - 'getL1ToL2MessagesTreePath', - ], + ['start', 'stop', 'getDataTreePath', 'getL1ToL2MessageAndIndex', 'getL1ToL2MessagesTreePath'], ); return rpc; } diff --git a/yarn-project/aztec-node/src/aztec-node/server.ts b/yarn-project/aztec-node/src/aztec-node/server.ts index d95507b5b4a7..f1e3f3ad6078 100644 --- a/yarn-project/aztec-node/src/aztec-node/server.ts +++ b/yarn-project/aztec-node/src/aztec-node/server.ts @@ -264,15 +264,6 @@ export class AztecNodeService implements AztecNode { return committedDb.findLeafIndex(treeId, leafValue); } - /** - * Find the index of the given contract. - * @param leafValue - The value to search for. - * @returns The index of the given leaf in the contracts tree or undefined if not found. - */ - public async findContractIndex(leafValue: Buffer): Promise { - return await this.findLeafIndex(MerkleTreeId.CONTRACT_TREE, leafValue); - } - /** * Returns the sibling path for the given index in the contract tree. * @param leafIndex - The index of the leaf for which the sibling path is required. @@ -283,15 +274,6 @@ export class AztecNodeService implements AztecNode { return committedDb.getSiblingPath(MerkleTreeId.CONTRACT_TREE, leafIndex); } - /** - * Find the index of the given commitment. - * @param leafValue - The value to search for. - * @returns The index of the given leaf in the private data tree or undefined if not found. - */ - public async findCommitmentIndex(leafValue: Buffer): Promise { - return await this.findLeafIndex(MerkleTreeId.PRIVATE_DATA_TREE, leafValue); - } - /** * Returns the sibling path for the given index in the data tree. * @param leafIndex - The index of the leaf for which the sibling path is required. @@ -325,15 +307,6 @@ export class AztecNodeService implements AztecNode { return committedDb.getSiblingPath(MerkleTreeId.L1_TO_L2_MESSAGES_TREE, leafIndex); } - /** - * Find the index of the given nullifier. - * @param nullifier - The nullifier to search for. - * @returns The index of the given leaf in the nullifier tree or undefined if not found. - */ - public async findNullifierIndex(nullifier: Fr): Promise { - return await this.findLeafIndex(MerkleTreeId.NULLIFIER_TREE, nullifier.toBuffer()); - } - /** * Gets the storage value at the given contract slot. * @param contract - Address of the contract to query. diff --git a/yarn-project/pxe/src/contract_tree/index.ts b/yarn-project/pxe/src/contract_tree/index.ts index e450861d0860..e187e87f7c3d 100644 --- a/yarn-project/pxe/src/contract_tree/index.ts +++ b/yarn-project/pxe/src/contract_tree/index.ts @@ -24,7 +24,7 @@ import { } from '@aztec/circuits.js/abis'; import { ContractAbi, FunctionSelector } from '@aztec/foundation/abi'; import { assertLength } from '@aztec/foundation/serialize'; -import { AztecNode, ContractDao, PublicKey, StateInfoProvider } from '@aztec/types'; +import { AztecNode, ContractDao, MerkleTreeId, PublicKey, StateInfoProvider } from '@aztec/types'; /** * The ContractTree class represents a Merkle tree of functions for a particular contract. @@ -229,7 +229,10 @@ export class ContractTree { const root = await this.getFunctionTreeRoot(); const newContractData = new NewContractData(completeAddress.address, portalContract, root); const commitment = computeContractLeaf(this.wasm, newContractData); - this.contractIndex = await this.stateInfoProvider.findContractIndex(commitment.toBuffer()); + this.contractIndex = await this.stateInfoProvider.findLeafIndex( + MerkleTreeId.CONTRACT_TREE, + commitment.toBuffer(), + ); if (this.contractIndex === undefined) { throw new Error( `Failed to find contract at ${completeAddress.address} with portal ${portalContract} resulting in commitment ${commitment}.`, diff --git a/yarn-project/pxe/src/pxe_service/pxe_service.ts b/yarn-project/pxe/src/pxe_service/pxe_service.ts index 736e50437914..88efb0e5b30b 100644 --- a/yarn-project/pxe/src/pxe_service/pxe_service.ts +++ b/yarn-project/pxe/src/pxe_service/pxe_service.ts @@ -38,6 +38,7 @@ import { L2BlockL2Logs, L2Tx, LogType, + MerkleTreeId, NodeInfo, NotePreimage, PXE, @@ -212,14 +213,14 @@ export class PXEService implements PXE { // TODO(https://github.com/AztecProtocol/aztec-packages/issues/1386) // This can always be `uniqueSiloedNoteHash` once notes added from public also include nonces. const noteHashToLookUp = nonce.isZero() ? siloedNoteHash : uniqueSiloedNoteHash; - const index = await this.node.findCommitmentIndex(noteHashToLookUp.toBuffer()); + const index = await this.node.findLeafIndex(MerkleTreeId.PRIVATE_DATA_TREE, noteHashToLookUp.toBuffer()); if (index === undefined) { throw new Error('Note does not exist.'); } const wasm = await CircuitsWasm.get(); const siloedNullifier = siloNullifier(wasm, contractAddress, innerNullifier!); - const nullifierIndex = await this.node.findNullifierIndex(siloedNullifier); + const nullifierIndex = await this.node.findLeafIndex(MerkleTreeId.NULLIFIER_TREE, siloedNullifier.toBuffer()); if (nullifierIndex !== undefined) { throw new Error('The note has been destroyed.'); } diff --git a/yarn-project/types/src/interfaces/state_provider.ts b/yarn-project/types/src/interfaces/state_provider.ts index 7d82c16b35dd..07d6b787dc16 100644 --- a/yarn-project/types/src/interfaces/state_provider.ts +++ b/yarn-project/types/src/interfaces/state_provider.ts @@ -16,13 +16,6 @@ export interface StateInfoProvider { */ findLeafIndex(treeId: MerkleTreeId, leafValue: Buffer): Promise; - /** - * Find the index of the given contract. - * @param leafValue - The value to search for. - * @returns The index of the given leaf in the contracts tree or undefined if not found. - */ - findContractIndex(leafValue: Buffer): Promise; - /** * Returns the sibling path for the given index in the contract tree. * @param leafIndex - The index of the leaf for which the sibling path is required. @@ -30,13 +23,6 @@ export interface StateInfoProvider { */ getContractPath(leafIndex: bigint): Promise>; - /** - * Find the index of the given commitment. - * @param leafValue - The value to search for. - * @returns The index of the given leaf of undefined if not found. - */ - findCommitmentIndex(leafValue: Buffer): Promise; - /** * Returns the sibling path for the given index in the data tree. * @param leafIndex - The index of the leaf for which the sibling path is required. @@ -44,13 +30,6 @@ export interface StateInfoProvider { */ getDataTreePath(leafIndex: bigint): Promise>; - /** - * Find the index of the given nullifier. - * @param nullifier - The nullifier to search for. - * @returns The index of the given leaf of undefined if not found. - */ - findNullifierIndex(nullifier: Fr): Promise; - /** * Gets a confirmed/consumed L1 to L2 message for the given message key (throws if not found). * and its index in the merkle tree