Skip to content

Commit

Permalink
Add getContractInstance public oracle call
Browse files Browse the repository at this point in the history
  • Loading branch information
spalladino committed Mar 12, 2024
1 parent 72013c0 commit b11911b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ export class ContractsDataSourcePublicDB implements PublicContractsDB {
return Promise.resolve();
}

public async getContractInstance(address: AztecAddress): Promise<ContractInstanceWithAddress | undefined> {
return this.instanceCache.get(address.toString()) ?? (await this.db.getContract(address));
}

async getBytecode(address: AztecAddress, selector: FunctionSelector): Promise<Buffer | undefined> {
const contract = await this.#getContract(address);
return contract?.getPublicFunction(selector)?.bytecode;
Expand Down
8 changes: 8 additions & 0 deletions yarn-project/simulator/src/public/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -65,6 +66,13 @@ export interface PublicContractsDB {
* @returns The portal contract address or undefined if not found.
*/
getPortalContractAddress(address: AztecAddress): Promise<EthAddress | undefined>;

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

/** Database interface for providing access to commitment tree, l1 to l2 message tree, and nullifier tree. */
Expand Down
9 changes: 9 additions & 0 deletions yarn-project/simulator/src/public/public_execution_context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -237,4 +238,12 @@ export class PublicExecutionContext extends TypedOracle {
}
return await this.commitmentsDb.getNullifierMembershipWitnessAtLatestBlock(nullifier);
}

public async getContractInstance(address: AztecAddress): Promise<ContractInstance> {
const instance = await this.contractsDb.getContractInstance(address);
if (!instance) {
throw new Error(`Contract instance at ${address} not found`);
}
return instance;
}
}

0 comments on commit b11911b

Please sign in to comment.