diff --git a/yarn-project/simulator/src/public/avm/avm_context.ts b/yarn-project/simulator/src/public/avm/avm_context.ts index 40cbed5ee8df..a78242847bd2 100644 --- a/yarn-project/simulator/src/public/avm/avm_context.ts +++ b/yarn-project/simulator/src/public/avm/avm_context.ts @@ -5,7 +5,7 @@ import type { PublicPersistableStateManager } from '../state_manager/state_manag import type { AvmExecutionEnvironment } from './avm_execution_environment.js'; import { type Gas, gasToGasLeft } from './avm_gas.js'; import { AvmMachineState } from './avm_machine_state.js'; -import type { AvmSimulator } from './avm_simulator.js'; +import type { AvmSimulatorInterface } from './avm_simulator_interface.js'; /** * An execution context includes the information necessary to initiate AVM @@ -27,7 +27,7 @@ export class AvmContext { // This is needed to break a dependency cycle created by the CALL opcode, // which needs to create a new simulator but cannot depend directly on AvmSimulator. - public provideSimulator?: (ctx: this) => Promise; + public provideSimulator?: (context: AvmContext) => Promise; /** * Prepare a new AVM context that will be ready for an external/nested call diff --git a/yarn-project/simulator/src/public/avm/avm_simulator.ts b/yarn-project/simulator/src/public/avm/avm_simulator.ts index 29d4c61f709d..c36311ef64ce 100644 --- a/yarn-project/simulator/src/public/avm/avm_simulator.ts +++ b/yarn-project/simulator/src/public/avm/avm_simulator.ts @@ -13,6 +13,7 @@ import { AvmContractCallResult } from './avm_contract_call_result.js'; import { AvmExecutionEnvironment } from './avm_execution_environment.js'; import type { Gas } from './avm_gas.js'; import { AvmMachineState } from './avm_machine_state.js'; +import type { AvmSimulatorInterface } from './avm_simulator_interface.js'; import { AvmExecutionError, AvmRevertReason, @@ -32,7 +33,7 @@ type OpcodeTally = { gas: Gas; }; -export class AvmSimulator { +export class AvmSimulator implements AvmSimulatorInterface { private log: Logger; private bytecode: Buffer | undefined; private opcodeTallies: Map = new Map(); diff --git a/yarn-project/simulator/src/public/avm/avm_simulator_interface.ts b/yarn-project/simulator/src/public/avm/avm_simulator_interface.ts new file mode 100644 index 000000000000..cd06517fe112 --- /dev/null +++ b/yarn-project/simulator/src/public/avm/avm_simulator_interface.ts @@ -0,0 +1,8 @@ +/** + * Interface for AvmSimulator to break the circular dependency between avm_context.ts and avm_simulator.ts + */ +export interface AvmSimulatorInterface { + execute(): Promise; // Using any here to avoid importing AvmContractCallResult + executeBytecode(bytecode: Buffer): Promise; + getBytecode(): Buffer | undefined; +}