@polygon-hermez/vm
Version:
An Ethereum VM implementation
101 lines (100 loc) • 2.59 kB
TypeScript
/// <reference types="bn.js" />
/// <reference types="node" />
import { Account, Address, BN } from 'ethereumjs-util';
import { StateManager } from '../state/index';
import { VmError } from '../exceptions';
import Memory from './memory';
import Stack from './stack';
import EEI from './eei';
import { Opcode, OpHandler } from './opcodes';
export interface InterpreterOpts {
pc?: number;
}
export interface RunState {
programCounter: number;
opCode: number;
memory: Memory;
memoryWordCount: BN;
highestMemCost: BN;
stack: Stack;
returnStack: Stack;
code: Buffer;
shouldDoJumpAnalysis: boolean;
validJumps: Uint8Array;
stateManager: StateManager;
eei: EEI;
messageGasLimit?: BN;
vcm?: any;
}
export interface InterpreterResult {
runState?: RunState;
exceptionError?: VmError;
evmSteps?: SimpleInterpreterStep[];
}
export interface InterpreterStep {
pc: number;
opcode: {
name: string;
fee: number;
dynamicFee?: BN;
isAsync: boolean;
};
gasLeft: BN;
gasRefund: BN;
stateManager: StateManager;
stack: BN[];
returnStack: BN[];
account: Account;
address: Address;
depth: number;
memory: Buffer;
memoryWordCount: BN;
codeAddress: Address;
}
export interface SimpleInterpreterStep {
pc: number;
opcode: {
name: string;
fee: number;
dynamicFee?: BN;
isAsync: boolean;
};
gasLeft: BN;
gasRefund: BN;
stack: BN[];
returnStack: BN[];
depth: number;
memory: Buffer;
memoryWordCount: BN;
codeAddress: Address;
callOpcodes?: SimpleInterpreterStep[];
counters?: any;
}
/**
* Parses and executes EVM bytecode.
*/
export default class Interpreter {
_vm: any;
_state: StateManager;
_runState: RunState;
_eei: EEI;
_evmStepAux: SimpleInterpreterStep | null;
private opDebuggers;
constructor(vm: any, eei: EEI);
run(code: Buffer, opts?: InterpreterOpts): Promise<InterpreterResult>;
/**
* Executes the opcode to which the program counter is pointing,
* reducing its base gas cost, and increments the program counter.
*/
runStep(): Promise<SimpleInterpreterStep>;
/**
* Get the handler function for an opcode.
*/
getOpHandler(opInfo: Opcode): OpHandler;
/**
* Get info for an opcode from VM's list of opcodes.
*/
lookupOpInfo(op: number): Opcode;
_runStepHook(dynamicFee: BN, gasLeft: BN): Promise<SimpleInterpreterStep>;
_getValidJumpDests(code: Buffer): Uint8Array;
}