Skip to content

Commit

Permalink
refactor: remove unecessary findXIndex
Browse files Browse the repository at this point in the history
  • Loading branch information
LHerskind committed Sep 29, 2023
1 parent c31946b commit 4742cd4
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 61 deletions.
10 changes: 1 addition & 9 deletions yarn-project/aztec-node/src/aztec-node/http_rpc_server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
27 changes: 0 additions & 27 deletions yarn-project/aztec-node/src/aztec-node/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<bigint | undefined> {
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.
Expand All @@ -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<bigint | undefined> {
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.
Expand Down Expand Up @@ -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<bigint | undefined> {
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.
Expand Down
7 changes: 5 additions & 2 deletions yarn-project/pxe/src/contract_tree/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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}.`,
Expand Down
5 changes: 3 additions & 2 deletions yarn-project/pxe/src/pxe_service/pxe_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import {
L2BlockL2Logs,
L2Tx,
LogType,
MerkleTreeId,
NodeInfo,
NotePreimage,
PXE,
Expand Down Expand Up @@ -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.');
}
Expand Down
21 changes: 0 additions & 21 deletions yarn-project/types/src/interfaces/state_provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,41 +16,20 @@ export interface StateInfoProvider {
*/
findLeafIndex(treeId: MerkleTreeId, leafValue: Buffer): Promise<bigint | undefined>;

/**
* 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<bigint | undefined>;

/**
* 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.
* @returns The sibling path for the leaf index.
*/
getContractPath(leafIndex: bigint): Promise<SiblingPath<typeof CONTRACT_TREE_HEIGHT>>;

/**
* 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<bigint | undefined>;

/**
* 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.
* @returns The sibling path for the leaf index.
*/
getDataTreePath(leafIndex: bigint): Promise<SiblingPath<typeof PRIVATE_DATA_TREE_HEIGHT>>;

/**
* 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<bigint | undefined>;

/**
* Gets a confirmed/consumed L1 to L2 message for the given message key (throws if not found).
* and its index in the merkle tree
Expand Down

0 comments on commit 4742cd4

Please sign in to comment.