From b11911b9d664d37ba21edaee99d4e027e25a9d70 Mon Sep 17 00:00:00 2001 From: Santiago Palladino Date: Tue, 12 Mar 2024 16:02:48 -0300 Subject: [PATCH] Add getContractInstance public oracle call --- .../sequencer-client/src/simulator/public_executor.ts | 4 ++++ yarn-project/simulator/src/public/db.ts | 8 ++++++++ .../simulator/src/public/public_execution_context.ts | 9 +++++++++ 3 files changed, 21 insertions(+) diff --git a/yarn-project/sequencer-client/src/simulator/public_executor.ts b/yarn-project/sequencer-client/src/simulator/public_executor.ts index 9af59f7729be..44556483d27b 100644 --- a/yarn-project/sequencer-client/src/simulator/public_executor.ts +++ b/yarn-project/sequencer-client/src/simulator/public_executor.ts @@ -79,6 +79,10 @@ export class ContractsDataSourcePublicDB implements PublicContractsDB { return Promise.resolve(); } + public async getContractInstance(address: AztecAddress): Promise { + return this.instanceCache.get(address.toString()) ?? (await this.db.getContract(address)); + } + async getBytecode(address: AztecAddress, selector: FunctionSelector): Promise { const contract = await this.#getContract(address); return contract?.getPublicFunction(selector)?.bytecode; diff --git a/yarn-project/simulator/src/public/db.ts b/yarn-project/simulator/src/public/db.ts index 316b14d67525..fedbfe55c155 100644 --- a/yarn-project/simulator/src/public/db.ts +++ b/yarn-project/simulator/src/public/db.ts @@ -2,6 +2,7 @@ import { NullifierMembershipWitness } from '@aztec/circuit-types'; import { EthAddress, FunctionSelector, L1_TO_L2_MSG_TREE_HEIGHT } from '@aztec/circuits.js'; import { AztecAddress } from '@aztec/foundation/aztec-address'; import { Fr } from '@aztec/foundation/fields'; +import { ContractInstanceWithAddress } from '@aztec/types/contracts'; import { MessageLoadOracleInputs } from '../acvm/index.js'; @@ -65,6 +66,13 @@ export interface PublicContractsDB { * @returns The portal contract address or undefined if not found. */ getPortalContractAddress(address: AztecAddress): Promise; + + /** + * Returns a publicly deployed contract instance. + * @param address - Address of the contract. + * @returns The contract instance or undefined if not found. + */ + getContractInstance(address: AztecAddress): Promise; } /** Database interface for providing access to commitment tree, l1 to l2 message tree, and nullifier tree. */ diff --git a/yarn-project/simulator/src/public/public_execution_context.ts b/yarn-project/simulator/src/public/public_execution_context.ts index 8d332e8edb72..8b46099929b9 100644 --- a/yarn-project/simulator/src/public/public_execution_context.ts +++ b/yarn-project/simulator/src/public/public_execution_context.ts @@ -4,6 +4,7 @@ import { AztecAddress } from '@aztec/foundation/aztec-address'; import { EthAddress } from '@aztec/foundation/eth-address'; import { Fr } from '@aztec/foundation/fields'; import { createDebugLogger } from '@aztec/foundation/log'; +import { ContractInstance } from '@aztec/types/contracts'; import { TypedOracle, toACVMWitness } from '../acvm/index.js'; import { PackedArgsCache, SideEffectCounter } from '../common/index.js'; @@ -237,4 +238,12 @@ export class PublicExecutionContext extends TypedOracle { } return await this.commitmentsDb.getNullifierMembershipWitnessAtLatestBlock(nullifier); } + + public async getContractInstance(address: AztecAddress): Promise { + const instance = await this.contractsDb.getContractInstance(address); + if (!instance) { + throw new Error(`Contract instance at ${address} not found`); + } + return instance; + } }