Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions yarn-project/simulator/src/public/avm/avm_context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<AvmSimulator>;
public provideSimulator?: (context: AvmContext) => Promise<AvmSimulatorInterface>;

/**
* Prepare a new AVM context that will be ready for an external/nested call
Expand Down
3 changes: 2 additions & 1 deletion yarn-project/simulator/src/public/avm/avm_simulator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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<string, OpcodeTally> = new Map();
Expand Down
Original file line number Diff line number Diff line change
@@ -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<any>; // Using any here to avoid importing AvmContractCallResult
executeBytecode(bytecode: Buffer): Promise<any>;
getBytecode(): Buffer | undefined;
}