From fef5f93c617640116bb0eea0fc64d7f230c7b763 Mon Sep 17 00:00:00 2001 From: Jean M <132435771+jeanmon@users.noreply.github.com> Date: Tue, 10 Dec 2024 14:58:50 +0100 Subject: [PATCH] chore(avm): Remove function selector from AvmExecutionEnvironment (#10532) --- .../circuit-types/src/simulation_error.ts | 5 ++- .../pxe/src/pxe_service/error_enriching.ts | 6 ++- yarn-project/simulator/src/avm/avm_context.ts | 5 +-- .../src/avm/avm_execution_environment.test.ts | 13 ++----- .../src/avm/avm_execution_environment.ts | 37 +++---------------- .../simulator/src/avm/avm_simulator.test.ts | 3 -- .../simulator/src/avm/avm_simulator.ts | 36 ++++++++++-------- yarn-project/simulator/src/avm/errors.ts | 26 ++++++------- .../simulator/src/avm/fixtures/index.ts | 1 - .../simulator/src/avm/journal/journal.ts | 5 ++- .../avm/opcodes/environment_getters.test.ts | 3 -- .../src/avm/opcodes/external_calls.ts | 14 ++----- .../simulator/src/common/debug_fn_name.ts | 20 ++++------ .../src/public/public_tx_simulator.ts | 7 +--- .../simulator/src/public/side_effect_trace.ts | 3 +- 15 files changed, 70 insertions(+), 114 deletions(-) diff --git a/yarn-project/circuit-types/src/simulation_error.ts b/yarn-project/circuit-types/src/simulation_error.ts index 3e84bbdb60e..b8d1b0be4bf 100644 --- a/yarn-project/circuit-types/src/simulation_error.ts +++ b/yarn-project/circuit-types/src/simulation_error.ts @@ -19,7 +19,7 @@ export interface FailingFunction { /** * The selector of the function that failed. */ - functionSelector: FunctionSelector; + functionSelector?: FunctionSelector; /** * The name of the function that failed. */ @@ -160,6 +160,7 @@ export class SimulationError extends Error { this.functionErrorStack.forEach(failingFunction => { if ( failingFunction.contractAddress.equals(contractAddress) && + !!failingFunction.functionSelector && failingFunction.functionSelector.equals(functionSelector) ) { failingFunction.functionName = functionName; @@ -175,7 +176,7 @@ export class SimulationError extends Error { const stackLines: string[] = [ ...functionCallStack.map(failingFunction => { return `at ${failingFunction.contractName ?? failingFunction.contractAddress.toString()}.${ - failingFunction.functionName ?? failingFunction.functionSelector.toString() + failingFunction.functionName ?? failingFunction.functionSelector?.toString() ?? 'unknown' }`; }), ...noirCallStack.map(errorLocation => diff --git a/yarn-project/pxe/src/pxe_service/error_enriching.ts b/yarn-project/pxe/src/pxe_service/error_enriching.ts index 99502bd361f..722dc06713b 100644 --- a/yarn-project/pxe/src/pxe_service/error_enriching.ts +++ b/yarn-project/pxe/src/pxe_service/error_enriching.ts @@ -20,7 +20,7 @@ export async function enrichSimulationError(err: SimulationError, db: PxeDatabas if (!mentionedFunctions.has(contractAddress.toString())) { mentionedFunctions.set(contractAddress.toString(), new Set()); } - mentionedFunctions.get(contractAddress.toString())!.add(functionSelector.toString()); + mentionedFunctions.get(contractAddress.toString())!.add(functionSelector?.toString() ?? ''); }); await Promise.all( @@ -89,7 +89,9 @@ export async function enrichPublicSimulationError( err.setNoirCallStack(parsedCallStack); } catch (err) { logger.warn( - `Could not resolve noir call stack for ${originalFailingFunction.contractAddress.toString()}:${originalFailingFunction.functionSelector.toString()}: ${err}`, + `Could not resolve noir call stack for ${originalFailingFunction.contractAddress.toString()}:${ + originalFailingFunction.functionName?.toString() ?? '' + }: ${err}`, ); } } diff --git a/yarn-project/simulator/src/avm/avm_context.ts b/yarn-project/simulator/src/avm/avm_context.ts index 50f20239994..2fa4dde5132 100644 --- a/yarn-project/simulator/src/avm/avm_context.ts +++ b/yarn-project/simulator/src/avm/avm_context.ts @@ -1,4 +1,4 @@ -import { type AztecAddress, FunctionSelector } from '@aztec/circuits.js'; +import { type AztecAddress } from '@aztec/circuits.js'; import { type Fr } from '@aztec/foundation/fields'; import { type AvmExecutionEnvironment } from './avm_execution_environment.js'; @@ -43,13 +43,12 @@ export class AvmContext { calldata: Fr[], allocatedGas: Gas, callType: 'CALL' | 'STATICCALL', - functionSelector: FunctionSelector = FunctionSelector.empty(), ): AvmContext { const deriveFn = callType === 'CALL' ? this.environment.deriveEnvironmentForNestedCall : this.environment.deriveEnvironmentForNestedStaticCall; - const newExecutionEnvironment = deriveFn.call(this.environment, address, calldata, functionSelector); + const newExecutionEnvironment = deriveFn.call(this.environment, address, calldata); const forkedWorldState = this.persistableState.fork(); const machineState = AvmMachineState.fromState(gasToGasLeft(allocatedGas)); return new AvmContext(forkedWorldState, newExecutionEnvironment, machineState); diff --git a/yarn-project/simulator/src/avm/avm_execution_environment.test.ts b/yarn-project/simulator/src/avm/avm_execution_environment.test.ts index cadbfc5a33a..475725cbc6b 100644 --- a/yarn-project/simulator/src/avm/avm_execution_environment.test.ts +++ b/yarn-project/simulator/src/avm/avm_execution_environment.test.ts @@ -1,4 +1,4 @@ -import { AztecAddress, FunctionSelector } from '@aztec/circuits.js'; +import { AztecAddress } from '@aztec/circuits.js'; import { Fr } from '@aztec/foundation/fields'; import { allSameExcept, initExecutionEnvironment } from './fixtures/index.js'; @@ -6,11 +6,10 @@ import { allSameExcept, initExecutionEnvironment } from './fixtures/index.js'; describe('Execution Environment', () => { const newAddress = AztecAddress.fromNumber(123456); const calldata = [new Fr(1n), new Fr(2n), new Fr(3n)]; - const selector = FunctionSelector.empty(); it('New call should fork execution environment correctly', () => { const executionEnvironment = initExecutionEnvironment(); - const newExecutionEnvironment = executionEnvironment.deriveEnvironmentForNestedCall(newAddress, calldata, selector); + const newExecutionEnvironment = executionEnvironment.deriveEnvironmentForNestedCall(newAddress, calldata); expect(newExecutionEnvironment).toEqual( allSameExcept(executionEnvironment, { @@ -21,13 +20,9 @@ describe('Execution Environment', () => { ); }); - it('New static call call should fork execution environment correctly', () => { + it('New static call should fork execution environment correctly', () => { const executionEnvironment = initExecutionEnvironment(); - const newExecutionEnvironment = executionEnvironment.deriveEnvironmentForNestedStaticCall( - newAddress, - calldata, - selector, - ); + const newExecutionEnvironment = executionEnvironment.deriveEnvironmentForNestedStaticCall(newAddress, calldata); expect(newExecutionEnvironment).toEqual( allSameExcept(executionEnvironment, { diff --git a/yarn-project/simulator/src/avm/avm_execution_environment.ts b/yarn-project/simulator/src/avm/avm_execution_environment.ts index d4ebe69608b..ead85afbfc4 100644 --- a/yarn-project/simulator/src/avm/avm_execution_environment.ts +++ b/yarn-project/simulator/src/avm/avm_execution_environment.ts @@ -1,4 +1,4 @@ -import { FunctionSelector, type GlobalVariables } from '@aztec/circuits.js'; +import { type GlobalVariables } from '@aztec/circuits.js'; import { type AztecAddress } from '@aztec/foundation/aztec-address'; import { Fr } from '@aztec/foundation/fields'; @@ -10,7 +10,6 @@ export class AvmExecutionEnvironment { constructor( public readonly address: AztecAddress, public readonly sender: AztecAddress, - public readonly functionSelector: FunctionSelector, // may be temporary (#7224) public readonly contractCallDepth: Fr, public readonly transactionFee: Fr, public readonly globals: GlobalVariables, @@ -18,16 +17,10 @@ export class AvmExecutionEnvironment { public readonly calldata: Fr[], ) {} - private deriveEnvironmentForNestedCallInternal( - targetAddress: AztecAddress, - calldata: Fr[], - functionSelector: FunctionSelector, - isStaticCall: boolean, - ) { + private deriveEnvironmentForNestedCallInternal(targetAddress: AztecAddress, calldata: Fr[], isStaticCall: boolean) { return new AvmExecutionEnvironment( /*address=*/ targetAddress, /*sender=*/ this.address, - functionSelector, this.contractCallDepth.add(Fr.ONE), this.transactionFee, this.globals, @@ -36,29 +29,11 @@ export class AvmExecutionEnvironment { ); } - public deriveEnvironmentForNestedCall( - targetAddress: AztecAddress, - calldata: Fr[], - functionSelector: FunctionSelector = FunctionSelector.empty(), - ): AvmExecutionEnvironment { - return this.deriveEnvironmentForNestedCallInternal( - targetAddress, - calldata, - functionSelector, - /*isStaticCall=*/ false, - ); + public deriveEnvironmentForNestedCall(targetAddress: AztecAddress, calldata: Fr[]): AvmExecutionEnvironment { + return this.deriveEnvironmentForNestedCallInternal(targetAddress, calldata, /*isStaticCall=*/ false); } - public deriveEnvironmentForNestedStaticCall( - targetAddress: AztecAddress, - calldata: Fr[], - functionSelector: FunctionSelector, - ): AvmExecutionEnvironment { - return this.deriveEnvironmentForNestedCallInternal( - targetAddress, - calldata, - functionSelector, - /*isStaticCall=*/ true, - ); + public deriveEnvironmentForNestedStaticCall(targetAddress: AztecAddress, calldata: Fr[]): AvmExecutionEnvironment { + return this.deriveEnvironmentForNestedCallInternal(targetAddress, calldata, /*isStaticCall=*/ true); } } diff --git a/yarn-project/simulator/src/avm/avm_simulator.test.ts b/yarn-project/simulator/src/avm/avm_simulator.test.ts index ef06934d7c5..8770a389c8d 100644 --- a/yarn-project/simulator/src/avm/avm_simulator.test.ts +++ b/yarn-project/simulator/src/avm/avm_simulator.test.ts @@ -160,7 +160,6 @@ describe('AVM simulator: transpiled Noir contracts', () => { const ephemeralTrees = await AvmEphemeralForest.create(worldStateDB.getMerkleInterface()); const persistableState = initPersistableStateManager({ worldStateDB, trace, merkleTrees: ephemeralTrees }); const environment = initExecutionEnvironment({ - functionSelector, calldata, globals, address: contractInstance.address, @@ -434,7 +433,6 @@ describe('AVM simulator: transpiled Noir contracts', () => { describe('Environment getters', () => { const address = AztecAddress.random(); const sender = AztecAddress.random(); - const functionSelector = FunctionSelector.random(); const transactionFee = Fr.random(); const chainId = Fr.random(); const version = Fr.random(); @@ -453,7 +451,6 @@ describe('AVM simulator: transpiled Noir contracts', () => { const env = initExecutionEnvironment({ address, sender, - functionSelector, transactionFee, globals, }); diff --git a/yarn-project/simulator/src/avm/avm_simulator.ts b/yarn-project/simulator/src/avm/avm_simulator.ts index 528347f6a9a..2f998dae352 100644 --- a/yarn-project/simulator/src/avm/avm_simulator.ts +++ b/yarn-project/simulator/src/avm/avm_simulator.ts @@ -1,10 +1,4 @@ -import { - type AztecAddress, - Fr, - type FunctionSelector, - type GlobalVariables, - MAX_L2_GAS_PER_ENQUEUED_CALL, -} from '@aztec/circuits.js'; +import { type AztecAddress, Fr, type GlobalVariables, MAX_L2_GAS_PER_ENQUEUED_CALL } from '@aztec/circuits.js'; import { type Logger, createLogger } from '@aztec/foundation/log'; import { strict as assert } from 'assert'; @@ -49,12 +43,14 @@ export class AvmSimulator { private tallyPrintFunction = () => {}; private tallyInstructionFunction = (_a: number, _b: string, _c: Gas) => {}; + // Test Purposes only: Logger will not have the proper function name. Use this constructor for testing purposes + // only. Otherwise, use build() below. constructor(private context: AvmContext, private instructionSet: InstructionSet = INSTRUCTION_SET()) { assert( context.machineState.gasLeft.l2Gas <= MAX_L2_GAS_PER_ENQUEUED_CALL, `Cannot allocate more than ${MAX_L2_GAS_PER_ENQUEUED_CALL} to the AVM for execution of an enqueued call`, ); - this.log = createLogger(`simulator:avm:core(f:${context.environment.functionSelector.toString()})`); + this.log = createLogger(`simulator:avm(calldata[0]: ${context.environment.calldata[0]})`); // TODO(palla/log): Should tallies be printed on debug, or only on trace? if (this.log.isLevelEnabled('debug')) { this.tallyPrintFunction = this.printOpcodeTallies; @@ -62,11 +58,20 @@ export class AvmSimulator { } } - public static create( + // Factory to have a proper function name in the logger. Retrieving the name is asynchronous and + // cannot be done as part of the constructor. + public static async build(context: AvmContext): Promise { + const simulator = new AvmSimulator(context); + const fnName = await context.persistableState.getPublicFunctionDebugName(context.environment); + simulator.log = createLogger(`simulator:avm(f:${fnName})`); + + return simulator; + } + + public static async create( stateManager: AvmPersistableStateManager, address: AztecAddress, sender: AztecAddress, - functionSelector: FunctionSelector, // may be temporary (#7224) transactionFee: Fr, globals: GlobalVariables, isStaticCall: boolean, @@ -76,7 +81,6 @@ export class AvmSimulator { const avmExecutionEnv = new AvmExecutionEnvironment( address, sender, - functionSelector, /*contractCallDepth=*/ Fr.zero(), transactionFee, globals, @@ -86,8 +90,7 @@ export class AvmSimulator { const avmMachineState = new AvmMachineState(allocatedGas); const avmContext = new AvmContext(stateManager, avmExecutionEnv, avmMachineState); - const instructionSet = INSTRUCTION_SET(); - return new AvmSimulator(avmContext, instructionSet); + return await AvmSimulator.build(avmContext); } /** @@ -98,11 +101,12 @@ export class AvmSimulator { if (!bytecode) { // revert, consuming all gas const message = `No bytecode found at: ${this.context.environment.address}. Reverting...`; + const fnName = await this.context.persistableState.getPublicFunctionDebugName(this.context.environment); const revertReason = new AvmRevertReason( message, /*failingFunction=*/ { contractAddress: this.context.environment.address, - functionSelector: this.context.environment.functionSelector, + functionName: fnName, }, /*noirCallStack=*/ [], ); @@ -176,7 +180,7 @@ export class AvmSimulator { const output = machineState.getOutput(); const reverted = machineState.getReverted(); - const revertReason = reverted ? revertReasonFromExplicitRevert(output, this.context) : undefined; + const revertReason = reverted ? await revertReasonFromExplicitRevert(output, this.context) : undefined; const results = new AvmContractCallResult(reverted, output, machineState.gasLeft, revertReason); this.log.debug(`Context execution results: ${results.toString()}`); @@ -190,7 +194,7 @@ export class AvmSimulator { throw err; } - const revertReason = revertReasonFromExceptionalHalt(err, this.context); + const revertReason = await revertReasonFromExceptionalHalt(err, this.context); // Note: "exceptional halts" cannot return data, hence []. const results = new AvmContractCallResult(/*reverted=*/ true, /*output=*/ [], machineState.gasLeft, revertReason); this.log.debug(`Context execution results: ${results.toString()}`); diff --git a/yarn-project/simulator/src/avm/errors.ts b/yarn-project/simulator/src/avm/errors.ts index a147aefe922..25a306fe09c 100644 --- a/yarn-project/simulator/src/avm/errors.ts +++ b/yarn-project/simulator/src/avm/errors.ts @@ -1,5 +1,5 @@ import { type FailingFunction, type NoirCallStack } from '@aztec/circuit-types'; -import { type AztecAddress, Fr, FunctionSelector, PUBLIC_DISPATCH_SELECTOR } from '@aztec/circuits.js'; +import { type AztecAddress, type Fr } from '@aztec/circuits.js'; import { ExecutionError } from '../common/errors.js'; import { type AvmContext } from './avm_context.js'; @@ -138,16 +138,9 @@ export class AvmRevertReason extends ExecutionError { } } -function createRevertReason(message: string, revertData: Fr[], context: AvmContext): AvmRevertReason { - // TODO(https://github.com/AztecProtocol/aztec-packages/issues/8985): Properly fix this. - // If the function selector is the public dispatch selector, we need to extract the actual function selector from the calldata. - // We should remove this because the AVM (or public protocol) shouldn't be aware of the public dispatch calling convention. - let functionSelector = context.environment.functionSelector; +async function createRevertReason(message: string, revertData: Fr[], context: AvmContext): Promise { // We drop the returnPc information. const internalCallStack = context.machineState.internalCallStack.map(entry => entry.callPc); - if (functionSelector.toField().equals(new Fr(PUBLIC_DISPATCH_SELECTOR)) && context.environment.calldata.length > 0) { - functionSelector = FunctionSelector.fromField(context.environment.calldata[0]); - } // If we are reverting due to the same error that we have been tracking, we use the nested error as the cause. let nestedError = undefined; @@ -160,11 +153,13 @@ function createRevertReason(message: string, revertData: Fr[], context: AvmConte message = context.machineState.collectedRevertInfo.recursiveRevertReason.message; } + const fnName = await context.persistableState.getPublicFunctionDebugName(context.environment); + return new AvmRevertReason( message, /*failingFunction=*/ { contractAddress: context.environment.address, - functionSelector: functionSelector, + functionName: fnName, }, /*noirCallStack=*/ [...internalCallStack, context.machineState.pc].map(pc => `0.${pc}`), /*options=*/ { cause: nestedError }, @@ -177,8 +172,11 @@ function createRevertReason(message: string, revertData: Fr[], context: AvmConte * @param haltingError - the lower-level error causing the exceptional halt * @param context - the context of the AVM execution used to extract the failingFunction and noirCallStack */ -export function revertReasonFromExceptionalHalt(haltingError: AvmExecutionError, context: AvmContext): AvmRevertReason { - return createRevertReason(haltingError.message, [], context); +export async function revertReasonFromExceptionalHalt( + haltingError: AvmExecutionError, + context: AvmContext, +): Promise { + return await createRevertReason(haltingError.message, [], context); } /** @@ -187,6 +185,6 @@ export function revertReasonFromExceptionalHalt(haltingError: AvmExecutionError, * @param revertData - output data of the explicit REVERT instruction * @param context - the context of the AVM execution used to extract the failingFunction and noirCallStack */ -export function revertReasonFromExplicitRevert(revertData: Fr[], context: AvmContext): AvmRevertReason { - return createRevertReason('Assertion failed: ', revertData, context); +export async function revertReasonFromExplicitRevert(revertData: Fr[], context: AvmContext): Promise { + return await createRevertReason('Assertion failed: ', revertData, context); } diff --git a/yarn-project/simulator/src/avm/fixtures/index.ts b/yarn-project/simulator/src/avm/fixtures/index.ts index 5711c9d9dc6..62080f3dd5e 100644 --- a/yarn-project/simulator/src/avm/fixtures/index.ts +++ b/yarn-project/simulator/src/avm/fixtures/index.ts @@ -64,7 +64,6 @@ export function initExecutionEnvironment(overrides?: Partial { + return await getPublicFunctionDebugName(this.worldStateDB, avmEnvironment.address, avmEnvironment.calldata); + } } function contractAddressIsCanonical(contractAddress: AztecAddress): boolean { diff --git a/yarn-project/simulator/src/avm/opcodes/environment_getters.test.ts b/yarn-project/simulator/src/avm/opcodes/environment_getters.test.ts index cd7c8fafab0..1ec8e0e0175 100644 --- a/yarn-project/simulator/src/avm/opcodes/environment_getters.test.ts +++ b/yarn-project/simulator/src/avm/opcodes/environment_getters.test.ts @@ -1,5 +1,4 @@ import { GasFees } from '@aztec/circuits.js'; -import { FunctionSelector as FunctionSelectorType } from '@aztec/foundation/abi'; import { AztecAddress } from '@aztec/foundation/aztec-address'; import { Fr } from '@aztec/foundation/fields'; @@ -14,7 +13,6 @@ import { EnvironmentVariable, GetEnvVar } from './environment_getters.js'; describe('Environment getters', () => { const address = AztecAddress.random(); const sender = AztecAddress.random(); - const functionSelector = FunctionSelectorType.random(); const transactionFee = Fr.random(); const chainId = Fr.random(); const version = Fr.random(); @@ -34,7 +32,6 @@ describe('Environment getters', () => { const env = initExecutionEnvironment({ address, sender, - functionSelector, transactionFee, globals, isStaticCall, diff --git a/yarn-project/simulator/src/avm/opcodes/external_calls.ts b/yarn-project/simulator/src/avm/opcodes/external_calls.ts index a5cb97ebc57..30284375e35 100644 --- a/yarn-project/simulator/src/avm/opcodes/external_calls.ts +++ b/yarn-project/simulator/src/avm/opcodes/external_calls.ts @@ -1,4 +1,4 @@ -import { Fr, FunctionSelector, Gas, PUBLIC_DISPATCH_SELECTOR } from '@aztec/circuits.js'; +import { Gas } from '@aztec/circuits.js'; import type { AvmContext } from '../avm_context.js'; import { type AvmContractCallResult } from '../avm_contract_call_result.js'; @@ -45,7 +45,6 @@ abstract class ExternalCall extends Instruction { const callAddress = memory.getAs(addrOffset); const calldata = memory.getSlice(argsOffset, calldataSize).map(f => f.toFr()); - const functionSelector = new Fr(PUBLIC_DISPATCH_SELECTOR); // If we are already in a static call, we propagate the environment. const callType = context.environment.isStaticCall ? 'STATICCALL' : this.type; @@ -62,15 +61,10 @@ abstract class ExternalCall extends Instruction { const allocatedGas = { l2Gas: allocatedL2Gas, daGas: allocatedDaGas }; context.machineState.consumeGas(allocatedGas); - const nestedContext = context.createNestedContractCallContext( - callAddress.toAztecAddress(), - calldata, - allocatedGas, - callType, - FunctionSelector.fromField(functionSelector), - ); + const aztecAddress = callAddress.toAztecAddress(); + const nestedContext = context.createNestedContractCallContext(aztecAddress, calldata, allocatedGas, callType); - const simulator = new AvmSimulator(nestedContext); + const simulator = await AvmSimulator.build(nestedContext); const nestedCallResults: AvmContractCallResult = await simulator.execute(); const success = !nestedCallResults.reverted; diff --git a/yarn-project/simulator/src/common/debug_fn_name.ts b/yarn-project/simulator/src/common/debug_fn_name.ts index b8d9647d6b7..aba0827b011 100644 --- a/yarn-project/simulator/src/common/debug_fn_name.ts +++ b/yarn-project/simulator/src/common/debug_fn_name.ts @@ -1,22 +1,16 @@ -import { type AztecAddress, Fr, FunctionSelector, PUBLIC_DISPATCH_SELECTOR } from '@aztec/circuits.js'; +import { type AztecAddress, type Fr, FunctionSelector } from '@aztec/circuits.js'; import { type WorldStateDB } from '../public/public_db_sources.js'; export async function getPublicFunctionDebugName( db: WorldStateDB, contractAddress: AztecAddress, - fn: FunctionSelector, calldata: Fr[], ): Promise { - if (fn.equals(FunctionSelector.fromField(new Fr(PUBLIC_DISPATCH_SELECTOR)))) { - // If the function is a dispatch, we need to look up the target function which - // is expected to be the first argument. - const targetFunction = - calldata[0] !== undefined - ? await db.getDebugFunctionName(contractAddress, FunctionSelector.fromField(calldata[0])) - : ``; - return `${targetFunction} (via dispatch)`; - } else { - return (await db.getDebugFunctionName(contractAddress, fn)) ?? `${contractAddress}:${fn}`; - } + // Public function is dispatched and therefore the target function is passed in the first argument. + const targetFunction = + calldata[0] !== undefined + ? await db.getDebugFunctionName(contractAddress, FunctionSelector.fromField(calldata[0])) + : ` (Contract Address: ${contractAddress})`; + return `${targetFunction} (via dispatch)`; } diff --git a/yarn-project/simulator/src/public/public_tx_simulator.ts b/yarn-project/simulator/src/public/public_tx_simulator.ts index b7aec9d43b7..b77ff48ae7d 100644 --- a/yarn-project/simulator/src/public/public_tx_simulator.ts +++ b/yarn-project/simulator/src/public/public_tx_simulator.ts @@ -264,8 +264,7 @@ export class PublicTxSimulator { ): Promise { const stateManager = context.state.getActiveStateManager(); const address = executionRequest.callContext.contractAddress; - const selector = executionRequest.callContext.functionSelector; - const fnName = await getPublicFunctionDebugName(this.worldStateDB, address, selector, executionRequest.args); + const fnName = await getPublicFunctionDebugName(this.worldStateDB, address, executionRequest.args); const availableGas = context.getGasLeftForPhase(phase); // Gas allocated to an enqueued call can be different from the available gas @@ -328,18 +327,16 @@ export class PublicTxSimulator { ): Promise { const address = executionRequest.callContext.contractAddress; const sender = executionRequest.callContext.msgSender; - const selector = executionRequest.callContext.functionSelector; this.log.verbose( `[AVM] Executing enqueued public call to external function ${fnName}@${address} with ${allocatedGas.l2Gas} allocated L2 gas.`, ); const timer = new Timer(); - const simulator = AvmSimulator.create( + const simulator = await AvmSimulator.create( stateManager, address, sender, - selector, transactionFee, this.globalVariables, executionRequest.callContext.isStaticCall, diff --git a/yarn-project/simulator/src/public/side_effect_trace.ts b/yarn-project/simulator/src/public/side_effect_trace.ts index 7d0db3bdc6b..47efe303a15 100644 --- a/yarn-project/simulator/src/public/side_effect_trace.ts +++ b/yarn-project/simulator/src/public/side_effect_trace.ts @@ -17,6 +17,7 @@ import { ContractStorageRead, ContractStorageUpdateRequest, EthAddress, + FunctionSelector, Gas, L1_TO_L2_MSG_TREE_HEIGHT, L2ToL1Message, @@ -535,7 +536,7 @@ function createPublicExecutionRequest(avmEnvironment: AvmExecutionEnvironment): const callContext = CallContext.from({ msgSender: avmEnvironment.sender, contractAddress: avmEnvironment.address, - functionSelector: avmEnvironment.functionSelector, + functionSelector: FunctionSelector.empty(), // TODO(#10563): Remove functionSelector in public call context isStaticCall: avmEnvironment.isStaticCall, }); return new PublicExecutionRequest(callContext, avmEnvironment.calldata);