From 2dec0cc4bf5bc592443d65e3a9923fc2a4f076a3 Mon Sep 17 00:00:00 2001 From: esau <152162806+sklppy88@users.noreply.github.com> Date: Mon, 5 Feb 2024 12:35:45 -0600 Subject: [PATCH] feat: add aztec node to client execution and nuke state info provider #4320 (#4401) Resolves #4320 --- .../src/client/client_execution_context.ts | 14 +- .../src/client/private_execution.test.ts | 6 +- .../src/client/simulator.test.ts | 7 +- .../acir-simulator/src/client/simulator.ts | 6 +- .../client/unconstrained_execution.test.ts | 5 +- .../src/client/view_data_oracle.ts | 6 +- .../src/interfaces/aztec-node.ts | 149 +++++++++++++++- .../circuit-types/src/interfaces/index.ts | 1 - .../src/interfaces/state_info_provider.ts | 159 ------------------ .../pxe/src/pxe_service/pxe_service.ts | 2 +- yarn-project/pxe/src/simulator/index.ts | 8 +- .../pxe/src/simulator_oracle/index.ts | 35 ++-- 12 files changed, 196 insertions(+), 202 deletions(-) delete mode 100644 yarn-project/circuit-types/src/interfaces/state_info_provider.ts diff --git a/yarn-project/acir-simulator/src/client/client_execution_context.ts b/yarn-project/acir-simulator/src/client/client_execution_context.ts index 24e6ca33977..2e572d70405 100644 --- a/yarn-project/acir-simulator/src/client/client_execution_context.ts +++ b/yarn-project/acir-simulator/src/client/client_execution_context.ts @@ -1,4 +1,12 @@ -import { AuthWitness, FunctionL2Logs, L1NotePayload, Note, NoteStatus, UnencryptedL2Log } from '@aztec/circuit-types'; +import { + AuthWitness, + AztecNode, + FunctionL2Logs, + L1NotePayload, + Note, + NoteStatus, + UnencryptedL2Log, +} from '@aztec/circuit-types'; import { CallContext, ContractDeploymentData, @@ -66,9 +74,10 @@ export class ClientExecutionContext extends ViewDataOracle { private readonly noteCache: ExecutionNoteCache, protected readonly db: DBOracle, private readonly curve: Grumpkin, + private node: AztecNode, protected log = createDebugLogger('aztec:simulator:client_execution_context'), ) { - super(contractAddress, authWitnesses, db, undefined, log); + super(contractAddress, authWitnesses, db, node, log); } // We still need this function until we can get user-defined ordering of structs for fn arguments @@ -344,6 +353,7 @@ export class ClientExecutionContext extends ViewDataOracle { this.noteCache, this.db, this.curve, + this.node, ); const childExecutionResult = await executePrivateFunction( diff --git a/yarn-project/acir-simulator/src/client/private_execution.test.ts b/yarn-project/acir-simulator/src/client/private_execution.test.ts index f7a66112551..14ef6ca5419 100644 --- a/yarn-project/acir-simulator/src/client/private_execution.test.ts +++ b/yarn-project/acir-simulator/src/client/private_execution.test.ts @@ -1,4 +1,4 @@ -import { L1ToL2Message, Note, PackedArguments, TxExecutionRequest } from '@aztec/circuit-types'; +import { AztecNode, L1ToL2Message, Note, PackedArguments, TxExecutionRequest } from '@aztec/circuit-types'; import { AppendOnlyTreeSnapshot, CallContext, @@ -68,6 +68,8 @@ jest.setTimeout(60_000); describe('Private Execution test suite', () => { let oracle: MockProxy; + let node: MockProxy; + let acirSimulator: AcirSimulator; let header = Header.empty(); @@ -220,7 +222,7 @@ describe('Private Execution test suite', () => { }); oracle.getHeader.mockResolvedValue(header); - acirSimulator = new AcirSimulator(oracle); + acirSimulator = new AcirSimulator(oracle, node); }); describe('empty constructor', () => { diff --git a/yarn-project/acir-simulator/src/client/simulator.test.ts b/yarn-project/acir-simulator/src/client/simulator.test.ts index 7c5a3e830e2..ed7b3df1369 100644 --- a/yarn-project/acir-simulator/src/client/simulator.test.ts +++ b/yarn-project/acir-simulator/src/client/simulator.test.ts @@ -1,4 +1,4 @@ -import { Note } from '@aztec/circuit-types'; +import { AztecNode, Note } from '@aztec/circuit-types'; import { CompleteAddress } from '@aztec/circuits.js'; import { computeUniqueCommitment, siloCommitment } from '@aztec/circuits.js/abis'; import { ABIParameterVisibility, FunctionArtifactWithDebugMetadata, getFunctionArtifact } from '@aztec/foundation/abi'; @@ -14,6 +14,8 @@ import { AcirSimulator } from './simulator.js'; describe('Simulator', () => { let oracle: MockProxy; + let node: MockProxy; + let simulator: AcirSimulator; const ownerPk = GrumpkinScalar.fromString('2dcc5485a58316776299be08c78fa3788a1a7961ae30dc747fb1be17692a8d32'); const ownerCompleteAddress = CompleteAddress.fromPrivateKeyAndPartialAddress(ownerPk, Fr.random()); @@ -25,13 +27,14 @@ describe('Simulator', () => { beforeEach(() => { oracle = mock(); + node = mock(); oracle.getNullifierKeyPair.mockResolvedValue({ secretKey: ownerNullifierSecretKey, publicKey: ownerNullifierPublicKey, }); oracle.getCompleteAddress.mockResolvedValue(ownerCompleteAddress); - simulator = new AcirSimulator(oracle); + simulator = new AcirSimulator(oracle, node); }); describe('computeNoteHashAndNullifier', () => { diff --git a/yarn-project/acir-simulator/src/client/simulator.ts b/yarn-project/acir-simulator/src/client/simulator.ts index 514bf8b04ca..be2852dce69 100644 --- a/yarn-project/acir-simulator/src/client/simulator.ts +++ b/yarn-project/acir-simulator/src/client/simulator.ts @@ -32,7 +32,7 @@ export class AcirSimulator { private static solver: Promise; // ACVM's backend private log: DebugLogger; - constructor(private db: DBOracle) { + constructor(private db: DBOracle, private node: AztecNode) { this.log = createDebugLogger('aztec:simulator'); } @@ -107,6 +107,7 @@ export class AcirSimulator { new ExecutionNoteCache(), this.db, curve, + this.node, ); try { @@ -133,13 +134,12 @@ export class AcirSimulator { request: FunctionCall, entryPointArtifact: FunctionArtifactWithDebugMetadata, contractAddress: AztecAddress, - aztecNode?: AztecNode, ) { if (entryPointArtifact.functionType !== FunctionType.UNCONSTRAINED) { throw new Error(`Cannot run ${entryPointArtifact.functionType} function as constrained`); } - const context = new ViewDataOracle(contractAddress, [], this.db, aztecNode); + const context = new ViewDataOracle(contractAddress, [], this.db, this.node); try { return await executeUnconstrainedFunction( diff --git a/yarn-project/acir-simulator/src/client/unconstrained_execution.test.ts b/yarn-project/acir-simulator/src/client/unconstrained_execution.test.ts index c8c114b756c..68b7ba6764c 100644 --- a/yarn-project/acir-simulator/src/client/unconstrained_execution.test.ts +++ b/yarn-project/acir-simulator/src/client/unconstrained_execution.test.ts @@ -1,4 +1,4 @@ -import { FunctionCall, Note } from '@aztec/circuit-types'; +import { AztecNode, FunctionCall, Note } from '@aztec/circuit-types'; import { CompleteAddress, FunctionData, Header } from '@aztec/circuits.js'; import { FunctionSelector, encodeArguments } from '@aztec/foundation/abi'; import { AztecAddress } from '@aztec/foundation/aztec-address'; @@ -12,11 +12,12 @@ import { AcirSimulator } from './simulator.js'; describe('Unconstrained Execution test suite', () => { let oracle: ReturnType>; + let node: ReturnType>; let acirSimulator: AcirSimulator; beforeEach(() => { oracle = mock(); - acirSimulator = new AcirSimulator(oracle); + acirSimulator = new AcirSimulator(oracle, node); }); describe('private token contract', () => { diff --git a/yarn-project/acir-simulator/src/client/view_data_oracle.ts b/yarn-project/acir-simulator/src/client/view_data_oracle.ts index 14cc8ea4bfd..5edf08a504f 100644 --- a/yarn-project/acir-simulator/src/client/view_data_oracle.ts +++ b/yarn-project/acir-simulator/src/client/view_data_oracle.ts @@ -27,7 +27,7 @@ export class ViewDataOracle extends TypedOracle { /** List of transient auth witnesses to be used during this simulation */ protected readonly authWitnesses: AuthWitness[], protected readonly db: DBOracle, - protected readonly aztecNode: AztecNode | undefined, + protected readonly aztecNode: AztecNode, protected log = createDebugLogger('aztec:simulator:client_view_context'), ) { super(); @@ -230,10 +230,6 @@ export class ViewDataOracle extends TypedOracle { * @param numberOfElements - Number of elements to read from the starting storage slot. */ public async storageRead(startStorageSlot: Fr, numberOfElements: number) { - if (!this.aztecNode) { - throw new Error('Aztec node is undefined, cannot read storage.'); - } - const values = []; for (let i = 0n; i < numberOfElements; i++) { const storageSlot = new Fr(startStorageSlot.value + i); diff --git a/yarn-project/circuit-types/src/interfaces/aztec-node.ts b/yarn-project/circuit-types/src/interfaces/aztec-node.ts index 7fe374edea0..85809f4d5d2 100644 --- a/yarn-project/circuit-types/src/interfaces/aztec-node.ts +++ b/yarn-project/circuit-types/src/interfaces/aztec-node.ts @@ -1,22 +1,165 @@ -import { Header } from '@aztec/circuits.js'; +import { + ARCHIVE_HEIGHT, + CONTRACT_TREE_HEIGHT, + Header, + L1_TO_L2_MSG_TREE_HEIGHT, + NOTE_HASH_TREE_HEIGHT, + NULLIFIER_TREE_HEIGHT, + PUBLIC_DATA_TREE_HEIGHT, +} from '@aztec/circuits.js'; import { L1ContractAddresses } from '@aztec/ethereum'; import { AztecAddress } from '@aztec/foundation/aztec-address'; import { Fr } from '@aztec/foundation/fields'; import { ContractClassPublic } from '@aztec/types/contracts'; import { ContractData, ExtendedContractData } from '../contract_data.js'; +import { L1ToL2MessageAndIndex } from '../l1_to_l2_message.js'; import { L2Block } from '../l2_block.js'; import { L2Tx } from '../l2_tx.js'; import { GetUnencryptedLogsResponse, L2BlockL2Logs, LogFilter, LogType } from '../logs/index.js'; +import { MerkleTreeId } from '../merkle_tree_id.js'; +import { SiblingPath } from '../sibling_path/index.js'; import { Tx, TxHash } from '../tx/index.js'; import { SequencerConfig } from './configs.js'; -import { StateInfoProvider } from './state_info_provider.js'; +import { NullifierMembershipWitness } from './nullifier_tree.js'; +import { PublicDataWitness } from './public_data_tree.js'; + +/** Helper type for a specific L2 block number or the latest block number */ +type BlockNumber = number | 'latest'; /** * The aztec node. * We will probably implement the additional interfaces by means other than Aztec Node as it's currently a privacy leak */ -export interface AztecNode extends StateInfoProvider { +export interface AztecNode { + /** + * Find the index of the given leaf in the given tree. + * @param blockNumber - The block number at which to get the data or 'latest' for latest data + * @param treeId - The tree to search in. + * @param leafValue - The value to search for + * @returns The index of the given leaf in the given tree or undefined if not found. + */ + findLeafIndex(blockNumber: BlockNumber, treeId: MerkleTreeId, leafValue: Fr): Promise; + + /** + * Returns a sibling path for the given index in the contract tree. + * @param blockNumber - The block number at which to get the data. + * @param leafIndex - The index of the leaf for which the sibling path is required. + * @returns The sibling path for the leaf index. + */ + getContractSiblingPath( + blockNumber: BlockNumber, + leafIndex: bigint, + ): Promise>; + + /** + * Returns a sibling path for the given index in the nullifier tree. + * @param blockNumber - The block number at which to get the data. + * @param leafIndex - The index of the leaf for which the sibling path is required. + * @returns The sibling path for the leaf index. + */ + getNullifierSiblingPath( + blockNumber: BlockNumber, + leafIndex: bigint, + ): Promise>; + + /** + * Returns a sibling path for the given index in the note hash tree. + * @param blockNumber - The block number at which to get the data. + * @param leafIndex - The index of the leaf for which the sibling path is required. + * @returns The sibling path for the leaf index. + */ + getNoteHashSiblingPath( + blockNumber: BlockNumber, + leafIndex: bigint, + ): 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 + * @param messageKey - The message key. + * @returns The map containing the message and index. + */ + getL1ToL2MessageAndIndex(messageKey: Fr): Promise; + + /** + * Returns a sibling path for a leaf in the committed l1 to l2 data tree. + * @param blockNumber - The block number at which to get the data. + * @param leafIndex - Index of the leaf in the tree. + * @returns The sibling path. + */ + getL1ToL2MessageSiblingPath( + blockNumber: BlockNumber, + leafIndex: bigint, + ): Promise>; + + /** + * Returns a sibling path for a leaf in the committed historic blocks tree. + * @param blockNumber - The block number at which to get the data. + * @param leafIndex - Index of the leaf in the tree. + * @returns The sibling path. + */ + getArchiveSiblingPath(blockNumber: BlockNumber, leafIndex: bigint): Promise>; + + /** + * Returns a sibling path for a leaf in the committed public data tree. + * @param blockNumber - The block number at which to get the data. + * @param leafIndex - Index of the leaf in the tree. + * @returns The sibling path. + */ + getPublicDataSiblingPath( + blockNumber: BlockNumber, + leafIndex: bigint, + ): Promise>; + + /** + * Returns a nullifier membership witness for a given nullifier at a given block. + * @param blockNumber - The block number at which to get the data. + * @param nullifier - Nullifier we try to find witness for. + * @returns The nullifier membership witness (if found). + */ + getNullifierMembershipWitness( + blockNumber: BlockNumber, + nullifier: Fr, + ): Promise; + + /** + * Returns a low nullifier membership witness for a given nullifier at a given block. + * @param blockNumber - The block number at which to get the data. + * @param nullifier - Nullifier we try to find the low nullifier witness for. + * @returns The low nullifier membership witness (if found). + * @remarks Low nullifier witness can be used to perform a nullifier non-inclusion proof by leveraging the "linked + * list structure" of leaves and proving that a lower nullifier is pointing to a bigger next value than the nullifier + * we are trying to prove non-inclusion for. + */ + getLowNullifierMembershipWitness( + blockNumber: BlockNumber, + nullifier: Fr, + ): Promise; + + /** + * Returns a public data tree witness for a given leaf slot at a given block. + * @param blockNumber - The block number at which to get the data. + * @param leafSlot - The leaf slot we try to find the witness for. + * @returns The public data witness (if found). + * @remarks The witness can be used to compute the current value of the public data tree leaf. If the low leaf preimage corresponds to an + * "in range" slot, means that the slot doesn't exist and the value is 0. If the low leaf preimage corresponds to the exact slot, the current value + * is contained in the leaf preimage. + */ + getPublicDataTreeWitness(blockNumber: BlockNumber, leafSlot: Fr): Promise; + + /** + * Get a block specified by its number. + * @param number - The block number being requested. + * @returns The requested block. + */ + getBlock(number: number): Promise; + + /** + * Fetches the current block number. + * @returns The block number. + */ + getBlockNumber(): Promise; /** * Method to determine if the node is ready to accept transactions. * @returns - Flag indicating the readiness for tx submission. diff --git a/yarn-project/circuit-types/src/interfaces/index.ts b/yarn-project/circuit-types/src/interfaces/index.ts index 398c73d1218..f12dff9dfcd 100644 --- a/yarn-project/circuit-types/src/interfaces/index.ts +++ b/yarn-project/circuit-types/src/interfaces/index.ts @@ -1,4 +1,3 @@ -export * from './state_info_provider.js'; export * from './aztec-node.js'; export * from './pxe.js'; export * from './deployed-contract.js'; diff --git a/yarn-project/circuit-types/src/interfaces/state_info_provider.ts b/yarn-project/circuit-types/src/interfaces/state_info_provider.ts deleted file mode 100644 index d653a2284c8..00000000000 --- a/yarn-project/circuit-types/src/interfaces/state_info_provider.ts +++ /dev/null @@ -1,159 +0,0 @@ -import { - ARCHIVE_HEIGHT, - CONTRACT_TREE_HEIGHT, - Fr, - L1_TO_L2_MSG_TREE_HEIGHT, - NOTE_HASH_TREE_HEIGHT, - NULLIFIER_TREE_HEIGHT, - PUBLIC_DATA_TREE_HEIGHT, -} from '@aztec/circuits.js'; - -import { L1ToL2MessageAndIndex } from '../l1_to_l2_message.js'; -import { L2Block } from '../l2_block.js'; -import { MerkleTreeId } from '../merkle_tree_id.js'; -import { SiblingPath } from '../sibling_path/index.js'; -import { NullifierMembershipWitness } from './nullifier_tree.js'; -import { PublicDataWitness } from './public_data_tree.js'; - -/** Helper type for a specific L2 block number or the latest block number */ -type BlockNumber = number | 'latest'; - -/** - * Interface providing methods for retrieving information about content of the state trees. - */ -export interface StateInfoProvider { - /** - * Find the index of the given leaf in the given tree. - * @param blockNumber - The block number at which to get the data or 'latest' for latest data - * @param treeId - The tree to search in. - * @param leafValue - The value to search for - * @returns The index of the given leaf in the given tree or undefined if not found. - */ - findLeafIndex(blockNumber: BlockNumber, treeId: MerkleTreeId, leafValue: Fr): Promise; - - /** - * Returns a sibling path for the given index in the contract tree. - * @param blockNumber - The block number at which to get the data. - * @param leafIndex - The index of the leaf for which the sibling path is required. - * @returns The sibling path for the leaf index. - * TODO: https://github.com/AztecProtocol/aztec-packages/issues/3414 - */ - getContractSiblingPath( - blockNumber: BlockNumber, - leafIndex: bigint, - ): Promise>; - - /** - * Returns a sibling path for the given index in the nullifier tree. - * @param blockNumber - The block number at which to get the data. - * @param leafIndex - The index of the leaf for which the sibling path is required. - * @returns The sibling path for the leaf index. - * TODO: https://github.com/AztecProtocol/aztec-packages/issues/3414 - */ - getNullifierSiblingPath( - blockNumber: BlockNumber, - leafIndex: bigint, - ): Promise>; - - /** - * Returns a sibling path for the given index in the note hash tree. - * @param blockNumber - The block number at which to get the data. - * @param leafIndex - The index of the leaf for which the sibling path is required. - * @returns The sibling path for the leaf index. - * TODO: https://github.com/AztecProtocol/aztec-packages/issues/3414 - */ - getNoteHashSiblingPath( - blockNumber: BlockNumber, - leafIndex: bigint, - ): 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 - * @param messageKey - The message key. - * @returns The map containing the message and index. - */ - getL1ToL2MessageAndIndex(messageKey: Fr): Promise; - - /** - * Returns a sibling path for a leaf in the committed l1 to l2 data tree. - * @param blockNumber - The block number at which to get the data. - * @param leafIndex - Index of the leaf in the tree. - * @returns The sibling path. - * TODO: https://github.com/AztecProtocol/aztec-packages/issues/3414 - */ - getL1ToL2MessageSiblingPath( - blockNumber: BlockNumber, - leafIndex: bigint, - ): Promise>; - - /** - * Returns a sibling path for a leaf in the committed historic blocks tree. - * @param blockNumber - The block number at which to get the data. - * @param leafIndex - Index of the leaf in the tree. - * @returns The sibling path. - * TODO: https://github.com/AztecProtocol/aztec-packages/issues/3414 - */ - getArchiveSiblingPath(blockNumber: BlockNumber, leafIndex: bigint): Promise>; - - /** - * Returns a sibling path for a leaf in the committed public data tree. - * @param blockNumber - The block number at which to get the data. - * @param leafIndex - Index of the leaf in the tree. - * @returns The sibling path. - * TODO: https://github.com/AztecProtocol/aztec-packages/issues/3414 - */ - getPublicDataSiblingPath( - blockNumber: BlockNumber, - leafIndex: bigint, - ): Promise>; - - /** - * Returns a nullifier membership witness for a given nullifier at a given block. - * @param blockNumber - The block number at which to get the data. - * @param nullifier - Nullifier we try to find witness for. - * @returns The nullifier membership witness (if found). - */ - getNullifierMembershipWitness( - blockNumber: BlockNumber, - nullifier: Fr, - ): Promise; - - /** - * Returns a low nullifier membership witness for a given nullifier at a given block. - * @param blockNumber - The block number at which to get the data. - * @param nullifier - Nullifier we try to find the low nullifier witness for. - * @returns The low nullifier membership witness (if found). - * @remarks Low nullifier witness can be used to perform a nullifier non-inclusion proof by leveraging the "linked - * list structure" of leaves and proving that a lower nullifier is pointing to a bigger next value than the nullifier - * we are trying to prove non-inclusion for. - */ - getLowNullifierMembershipWitness( - blockNumber: BlockNumber, - nullifier: Fr, - ): Promise; - - /** - * Returns a public data tree witness for a given leaf slot at a given block. - * @param blockNumber - The block number at which to get the data. - * @param leafSlot - The leaf slot we try to find the witness for. - * @returns The public data witness (if found). - * @remarks The witness can be used to compute the current value of the public data tree leaf. If the low leaf preimage corresponds to an - * "in range" slot, means that the slot doesn't exist and the value is 0. If the low leaf preimage corresponds to the exact slot, the current value - * is contained in the leaf preimage. - */ - getPublicDataTreeWitness(blockNumber: BlockNumber, leafSlot: Fr): Promise; - - /** - * Get a block specified by its number. - * @param number - The block number being requested. - * @returns The requested block. - */ - getBlock(number: number): Promise; - - /** - * Fetches the current block number. - * @returns The block number. - */ - getBlockNumber(): Promise; -} diff --git a/yarn-project/pxe/src/pxe_service/pxe_service.ts b/yarn-project/pxe/src/pxe_service/pxe_service.ts index 09df2e57ebd..a90970194bf 100644 --- a/yarn-project/pxe/src/pxe_service/pxe_service.ts +++ b/yarn-project/pxe/src/pxe_service/pxe_service.ts @@ -575,7 +575,7 @@ export class PXEService implements PXE { this.log('Executing unconstrained simulator...'); try { - const result = await this.simulator.runUnconstrained(execRequest, functionArtifact, contractAddress, this.node); + const result = await this.simulator.runUnconstrained(execRequest, functionArtifact, contractAddress); this.log('Unconstrained simulation completed!'); return result; diff --git a/yarn-project/pxe/src/simulator/index.ts b/yarn-project/pxe/src/simulator/index.ts index 090acd2f5d2..cb6d4c0dd81 100644 --- a/yarn-project/pxe/src/simulator/index.ts +++ b/yarn-project/pxe/src/simulator/index.ts @@ -1,5 +1,5 @@ import { AcirSimulator } from '@aztec/acir-simulator'; -import { KeyStore, StateInfoProvider } from '@aztec/circuit-types'; +import { AztecNode, KeyStore } from '@aztec/circuit-types'; import { ContractDataOracle } from '../contract_data_oracle/index.js'; import { PxeDatabase } from '../database/pxe_database.js'; @@ -10,7 +10,7 @@ import { SimulatorOracle } from '../simulator_oracle/index.js'; */ export function getAcirSimulator( db: PxeDatabase, - stateInfoProvider: StateInfoProvider, + aztecNode: AztecNode, keyStore: KeyStore, contractDataOracle?: ContractDataOracle, ) { @@ -18,7 +18,7 @@ export function getAcirSimulator( contractDataOracle ?? new ContractDataOracle(db), db, keyStore, - stateInfoProvider, + aztecNode, ); - return new AcirSimulator(simulatorOracle); + return new AcirSimulator(simulatorOracle, aztecNode); } diff --git a/yarn-project/pxe/src/simulator_oracle/index.ts b/yarn-project/pxe/src/simulator_oracle/index.ts index 24e5f2208b3..d631a405cdf 100644 --- a/yarn-project/pxe/src/simulator_oracle/index.ts +++ b/yarn-project/pxe/src/simulator_oracle/index.ts @@ -1,12 +1,12 @@ import { DBOracle, KeyPair, MessageLoadOracleInputs } from '@aztec/acir-simulator'; import { + AztecNode, KeyStore, L2Block, MerkleTreeId, NoteStatus, NullifierMembershipWitness, PublicDataWitness, - StateInfoProvider, } from '@aztec/circuit-types'; import { AztecAddress, @@ -31,7 +31,7 @@ export class SimulatorOracle implements DBOracle { private contractDataOracle: ContractDataOracle, private db: PxeDatabase, private keyStore: KeyStore, - private stateInfoProvider: StateInfoProvider, + private aztecNode: AztecNode, private log = createDebugLogger('aztec:pxe:simulator_oracle'), ) {} @@ -127,10 +127,10 @@ export class SimulatorOracle implements DBOracle { * index of the message in the l1ToL2MessageTree */ async getL1ToL2Message(msgKey: Fr): Promise> { - const messageAndIndex = await this.stateInfoProvider.getL1ToL2MessageAndIndex(msgKey); + const messageAndIndex = await this.aztecNode.getL1ToL2MessageAndIndex(msgKey); const message = messageAndIndex.message; const index = messageAndIndex.index; - const siblingPath = await this.stateInfoProvider.getL1ToL2MessageSiblingPath('latest', index); + const siblingPath = await this.aztecNode.getL1ToL2MessageSiblingPath('latest', index); return new MessageLoadOracleInputs(message, index, siblingPath); } @@ -140,30 +140,29 @@ export class SimulatorOracle implements DBOracle { * @returns - The index of the commitment. Undefined if it does not exist in the tree. */ async getCommitmentIndex(commitment: Fr) { - return await this.stateInfoProvider.findLeafIndex('latest', MerkleTreeId.NOTE_HASH_TREE, commitment); + return await this.aztecNode.findLeafIndex('latest', MerkleTreeId.NOTE_HASH_TREE, commitment); } async getNullifierIndex(nullifier: Fr) { - return await this.stateInfoProvider.findLeafIndex('latest', MerkleTreeId.NULLIFIER_TREE, nullifier); + return await this.aztecNode.findLeafIndex('latest', MerkleTreeId.NULLIFIER_TREE, nullifier); } public async findLeafIndex(blockNumber: number, treeId: MerkleTreeId, leafValue: Fr): Promise { - return await this.stateInfoProvider.findLeafIndex(blockNumber, treeId, leafValue); + return await this.aztecNode.findLeafIndex(blockNumber, treeId, leafValue); } public async getSiblingPath(blockNumber: number, treeId: MerkleTreeId, leafIndex: bigint): Promise { - // @todo Doing a nasty workaround here because of https://github.com/AztecProtocol/aztec-packages/issues/3414 switch (treeId) { case MerkleTreeId.CONTRACT_TREE: - return (await this.stateInfoProvider.getContractSiblingPath(blockNumber, leafIndex)).toFields(); + return (await this.aztecNode.getContractSiblingPath(blockNumber, leafIndex)).toFields(); case MerkleTreeId.NULLIFIER_TREE: - return (await this.stateInfoProvider.getNullifierSiblingPath(blockNumber, leafIndex)).toFields(); + return (await this.aztecNode.getNullifierSiblingPath(blockNumber, leafIndex)).toFields(); case MerkleTreeId.NOTE_HASH_TREE: - return (await this.stateInfoProvider.getNoteHashSiblingPath(blockNumber, leafIndex)).toFields(); + return (await this.aztecNode.getNoteHashSiblingPath(blockNumber, leafIndex)).toFields(); case MerkleTreeId.PUBLIC_DATA_TREE: - return (await this.stateInfoProvider.getPublicDataSiblingPath(blockNumber, leafIndex)).toFields(); + return (await this.aztecNode.getPublicDataSiblingPath(blockNumber, leafIndex)).toFields(); case MerkleTreeId.ARCHIVE: - return (await this.stateInfoProvider.getArchiveSiblingPath(blockNumber, leafIndex)).toFields(); + return (await this.aztecNode.getArchiveSiblingPath(blockNumber, leafIndex)).toFields(); default: throw new Error('Not implemented'); } @@ -173,22 +172,22 @@ export class SimulatorOracle implements DBOracle { blockNumber: number, nullifier: Fr, ): Promise { - return this.stateInfoProvider.getNullifierMembershipWitness(blockNumber, nullifier); + return this.aztecNode.getNullifierMembershipWitness(blockNumber, nullifier); } public getLowNullifierMembershipWitness( blockNumber: number, nullifier: Fr, ): Promise { - return this.stateInfoProvider.getLowNullifierMembershipWitness(blockNumber, nullifier); + return this.aztecNode.getLowNullifierMembershipWitness(blockNumber, nullifier); } public async getBlock(blockNumber: number): Promise { - return await this.stateInfoProvider.getBlock(blockNumber); + return await this.aztecNode.getBlock(blockNumber); } public async getPublicDataTreeWitness(blockNumber: number, leafSlot: Fr): Promise { - return await this.stateInfoProvider.getPublicDataTreeWitness(blockNumber, leafSlot); + return await this.aztecNode.getPublicDataTreeWitness(blockNumber, leafSlot); } /** @@ -206,6 +205,6 @@ export class SimulatorOracle implements DBOracle { * @returns The block number. */ public async getBlockNumber(): Promise { - return await this.stateInfoProvider.getBlockNumber(); + return await this.aztecNode.getBlockNumber(); } }