From 64ac1ec1d718e30f1ccf2fa392e9f5b8505d99b2 Mon Sep 17 00:00:00 2001 From: Jeffrey Wilcke Date: Fri, 16 Dec 2016 17:16:29 +0100 Subject: [PATCH] core, eth, internal, les: rename VM objects Renamed Environment to EVM and EVM to Interpreter. The rational behind this that the Environment used to be an interface and had multiple implementations across the code base. All of the logic implemented in the Environment is part of the EVM. The old EVM is actually the interpreter, which interprets the byte code. The old EVM is part of the EVM as a whole. --- accounts/abi/bind/backends/simulated.go | 2 +- core/state_processor.go | 2 +- core/state_transition.go | 6 +- core/vm/environment.go | 158 ++++++++++++------------ core/vm/gas_table.go | 46 +++---- core/vm/instructions.go | 130 +++++++++---------- core/vm/interface.go | 14 +-- core/vm/jump_table.go | 4 +- core/vm/logger.go | 6 +- core/vm/logger_test.go | 4 +- core/vm/runtime/env.go | 4 +- core/vm/runtime/runtime_test.go | 2 +- core/vm/vm.go | 24 ++-- core/vm/vm_jit.go | 6 +- eth/api.go | 4 +- eth/api_backend.go | 4 +- internal/ethapi/backend.go | 2 +- internal/ethapi/tracer.go | 2 +- internal/ethapi/tracer_test.go | 6 +- les/api_backend.go | 4 +- les/odr_test.go | 4 +- light/odr_test.go | 4 +- tests/util.go | 4 +- 23 files changed, 221 insertions(+), 221 deletions(-) diff --git a/accounts/abi/bind/backends/simulated.go b/accounts/abi/bind/backends/simulated.go index 06bd13cae2..7bff1a1253 100644 --- a/accounts/abi/bind/backends/simulated.go +++ b/accounts/abi/bind/backends/simulated.go @@ -229,7 +229,7 @@ func (b *SimulatedBackend) callContract(ctx context.Context, call ethereum.CallM evmContext := core.NewEVMContext(msg, block.Header(), b.blockchain) // Create a new environment which holds all relevant information // about the transaction and calling mechanisms. - vmenv := vm.NewEnvironment(evmContext, statedb, chainConfig, vm.Config{}) + vmenv := vm.NewEVM(evmContext, statedb, chainConfig, vm.Config{}) gaspool := new(core.GasPool).AddGas(common.MaxBig) ret, gasUsed, _, err := core.NewStateTransition(vmenv, msg, gaspool).TransitionDb() return ret, gasUsed, err diff --git a/core/state_processor.go b/core/state_processor.go index bc715cfc67..82a371a9e6 100644 --- a/core/state_processor.go +++ b/core/state_processor.go @@ -99,7 +99,7 @@ func ApplyTransaction(config *params.ChainConfig, bc *BlockChain, gp *GasPool, s context := NewEVMContext(msg, header, bc) // Create a new environment which holds all relevant information // about the transaction and calling mechanisms. - vmenv := vm.NewEnvironment(context, statedb, config, vm.Config{}) + vmenv := vm.NewEVM(context, statedb, config, vm.Config{}) // Apply the transaction to the current state (included in the env) _, gas, err := ApplyMessage(vmenv, msg, gp) if err != nil { diff --git a/core/state_transition.go b/core/state_transition.go index 81cd22abd2..38fbebfd95 100644 --- a/core/state_transition.go +++ b/core/state_transition.go @@ -57,7 +57,7 @@ type StateTransition struct { data []byte state vm.StateDB - env *vm.Environment + env *vm.EVM } // Message represents a message sent to a contract. @@ -106,7 +106,7 @@ func IntrinsicGas(data []byte, contractCreation, homestead bool) *big.Int { } // NewStateTransition initialises and returns a new state transition object. -func NewStateTransition(env *vm.Environment, msg Message, gp *GasPool) *StateTransition { +func NewStateTransition(env *vm.EVM, msg Message, gp *GasPool) *StateTransition { return &StateTransition{ gp: gp, env: env, @@ -127,7 +127,7 @@ func NewStateTransition(env *vm.Environment, msg Message, gp *GasPool) *StateTra // the gas used (which includes gas refunds) and an error if it failed. An error always // indicates a core error meaning that the message would always fail for that particular // state and would never be accepted within a block. -func ApplyMessage(env *vm.Environment, msg Message, gp *GasPool) ([]byte, *big.Int, error) { +func ApplyMessage(env *vm.EVM, msg Message, gp *GasPool) ([]byte, *big.Int, error) { st := NewStateTransition(env, msg, gp) ret, _, gasUsed, err := st.TransitionDb() diff --git a/core/vm/environment.go b/core/vm/environment.go index c39e1dbbe4..ffbc123c3f 100644 --- a/core/vm/environment.go +++ b/core/vm/environment.go @@ -58,10 +58,10 @@ type Context struct { Difficulty *big.Int // Provides information for DIFFICULTY } -// Environment provides information about external sources for the EVM +// EVM provides information about external sources for the EVM // -// The Environment should never be reused and is not thread safe. -type Environment struct { +// The EVM should never be reused and is not thread safe. +type EVM struct { // Context provides auxiliary blockchain related information Context // StateDB gives access to the underlying state @@ -76,7 +76,7 @@ type Environment struct { vmConfig Config // global (to this context) ethereum virtual machine // used throughout the execution of the tx. - evm Vm + interpreter EVMInterpreter // abort is used to abort the EVM calling operations // NOTE: must be set atomically abort int32 @@ -84,27 +84,27 @@ type Environment struct { quit chan struct{} } -// NewEnvironment retutrns a new EVM environment. -func NewEnvironment(ctx Context, statedb StateDB, chainConfig *params.ChainConfig, vmConfig Config) *Environment { - env := &Environment{ +// NewEVM retutrns a new EVM evmironment. +func NewEVM(ctx Context, statedb StateDB, chainConfig *params.ChainConfig, vmConfig Config) *EVM { + evm := &EVM{ Context: ctx, StateDB: statedb, vmConfig: vmConfig, chainConfig: chainConfig, } - env.evm = New(env, vmConfig) - return env + evm.interpreter = NewInterpreter(evm, vmConfig) + return evm } -func (env *Environment) init() { - env.quit = make(chan struct{}) +func (evm *EVM) init() { + evm.quit = make(chan struct{}) go func() { select { - case <-env.quit: + case <-evm.quit: return - case <-env.Context.Done(): - atomic.StoreInt32(&env.abort, 1) + case <-evm.Context.Done(): + atomic.StoreInt32(&evm.abort, 1) } }() } @@ -112,13 +112,13 @@ func (env *Environment) init() { // Call executes the contract associated with the addr with the given input as paramaters. It also handles any // necessary value transfer required and takes the necessary steps to create accounts and reverses the state in // case of an execution error or failed value transfer. -func (env *Environment) Call(caller ContractRef, addr common.Address, input []byte, gas, value *big.Int) (ret []byte, err error) { - if env.Depth == 0 { - env.init() - defer close(env.quit) +func (evm *EVM) Call(caller ContractRef, addr common.Address, input []byte, gas, value *big.Int) (ret []byte, err error) { + if evm.Depth == 0 { + evm.init() + defer close(evm.quit) } - if env.vmConfig.NoRecursion && env.Depth > 0 { + if evm.vmConfig.NoRecursion && evm.Depth > 0 { caller.ReturnGas(gas) return nil, nil @@ -126,12 +126,12 @@ func (env *Environment) Call(caller ContractRef, addr common.Address, input []by // Depth check execution. Fail if we're trying to execute above the // limit. - if env.Depth > int(params.CallCreateDepth.Int64()) { + if evm.Depth > int(params.CallCreateDepth.Int64()) { caller.ReturnGas(gas) return nil, ErrDepth } - if !env.Context.CanTransfer(env.StateDB, caller.Address(), value) { + if !evm.Context.CanTransfer(evm.StateDB, caller.Address(), value) { caller.ReturnGas(gas) return nil, ErrInsufficientBalance @@ -139,35 +139,35 @@ func (env *Environment) Call(caller ContractRef, addr common.Address, input []by var ( to Account - snapshot = env.StateDB.Snapshot() + snapshot = evm.StateDB.Snapshot() ) - if !env.StateDB.Exist(addr) { - if PrecompiledContracts[addr] == nil && env.ChainConfig().IsEIP158(env.BlockNumber) && value.BitLen() == 0 { + if !evm.StateDB.Exist(addr) { + if PrecompiledContracts[addr] == nil && evm.ChainConfig().IsEIP158(evm.BlockNumber) && value.BitLen() == 0 { caller.ReturnGas(gas) return nil, nil } - to = env.StateDB.CreateAccount(addr) + to = evm.StateDB.CreateAccount(addr) } else { - to = env.StateDB.GetAccount(addr) + to = evm.StateDB.GetAccount(addr) } - env.Transfer(env.StateDB, caller.Address(), to.Address(), value) + evm.Transfer(evm.StateDB, caller.Address(), to.Address(), value) // initialise a new contract and set the code that is to be used by the - // E The contract is a scoped environment for this execution context + // E The contract is a scoped evmironment for this execution context // only. contract := NewContract(caller, to, value, gas) - contract.SetCallCode(&addr, env.StateDB.GetCodeHash(addr), env.StateDB.GetCode(addr)) + contract.SetCallCode(&addr, evm.StateDB.GetCodeHash(addr), evm.StateDB.GetCode(addr)) defer contract.Finalise() - ret, err = env.EVM().Run(contract, input) + ret, err = evm.interpreter.Run(contract, input) // When an error was returned by the EVM or when setting the creation code // above we revert to the snapshot and consume any gas remaining. Additionally // when we're in homestead this also counts for code storage gas errors. if err != nil { contract.UseGas(contract.Gas) - env.StateDB.RevertToSnapshot(snapshot) + evm.StateDB.RevertToSnapshot(snapshot) } return ret, err } @@ -177,13 +177,13 @@ func (env *Environment) Call(caller ContractRef, addr common.Address, input []by // case of an execution error or failed value transfer. // // CallCode differs from Call in the sense that it executes the given address' code with the caller as context. -func (env *Environment) CallCode(caller ContractRef, addr common.Address, input []byte, gas, value *big.Int) (ret []byte, err error) { - if env.Depth == 0 { - env.init() - defer close(env.quit) +func (evm *EVM) CallCode(caller ContractRef, addr common.Address, input []byte, gas, value *big.Int) (ret []byte, err error) { + if evm.Depth == 0 { + evm.init() + defer close(evm.quit) } - if env.vmConfig.NoRecursion && env.Depth > 0 { + if evm.vmConfig.NoRecursion && evm.Depth > 0 { caller.ReturnGas(gas) return nil, nil @@ -191,33 +191,33 @@ func (env *Environment) CallCode(caller ContractRef, addr common.Address, input // Depth check execution. Fail if we're trying to execute above the // limit. - if env.Depth > int(params.CallCreateDepth.Int64()) { + if evm.Depth > int(params.CallCreateDepth.Int64()) { caller.ReturnGas(gas) return nil, ErrDepth } - if !env.CanTransfer(env.StateDB, caller.Address(), value) { + if !evm.CanTransfer(evm.StateDB, caller.Address(), value) { caller.ReturnGas(gas) - return nil, fmt.Errorf("insufficient funds to transfer value. Req %v, has %v", value, env.StateDB.GetBalance(caller.Address())) + return nil, fmt.Errorf("insufficient funds to transfer value. Req %v, has %v", value, evm.StateDB.GetBalance(caller.Address())) } var ( - snapshot = env.StateDB.Snapshot() - to = env.StateDB.GetAccount(caller.Address()) + snapshot = evm.StateDB.Snapshot() + to = evm.StateDB.GetAccount(caller.Address()) ) // initialise a new contract and set the code that is to be used by the - // E The contract is a scoped environment for this execution context + // E The contract is a scoped evmironment for this execution context // only. contract := NewContract(caller, to, value, gas) - contract.SetCallCode(&addr, env.StateDB.GetCodeHash(addr), env.StateDB.GetCode(addr)) + contract.SetCallCode(&addr, evm.StateDB.GetCodeHash(addr), evm.StateDB.GetCode(addr)) defer contract.Finalise() - ret, err = env.EVM().Run(contract, input) + ret, err = evm.interpreter.Run(contract, input) if err != nil { contract.UseGas(contract.Gas) - env.StateDB.RevertToSnapshot(snapshot) + evm.StateDB.RevertToSnapshot(snapshot) } return ret, err @@ -228,13 +228,13 @@ func (env *Environment) CallCode(caller ContractRef, addr common.Address, input // // DelegateCall differs from CallCode in the sense that it executes the given address' code with the caller as context // and the caller is set to the caller of the caller. -func (env *Environment) DelegateCall(caller ContractRef, addr common.Address, input []byte, gas *big.Int) (ret []byte, err error) { - if env.Depth == 0 { - env.init() - defer close(env.quit) +func (evm *EVM) DelegateCall(caller ContractRef, addr common.Address, input []byte, gas *big.Int) (ret []byte, err error) { + if evm.Depth == 0 { + evm.init() + defer close(evm.quit) } - if env.vmConfig.NoRecursion && env.Depth > 0 { + if evm.vmConfig.NoRecursion && evm.Depth > 0 { caller.ReturnGas(gas) return nil, nil @@ -242,39 +242,39 @@ func (env *Environment) DelegateCall(caller ContractRef, addr common.Address, in // Depth check execution. Fail if we're trying to execute above the // limit. - if env.Depth > int(params.CallCreateDepth.Int64()) { + if evm.Depth > int(params.CallCreateDepth.Int64()) { caller.ReturnGas(gas) return nil, ErrDepth } var ( - snapshot = env.StateDB.Snapshot() - to = env.StateDB.GetAccount(caller.Address()) + snapshot = evm.StateDB.Snapshot() + to = evm.StateDB.GetAccount(caller.Address()) ) // Iinitialise a new contract and make initialise the delegate values contract := NewContract(caller, to, caller.Value(), gas).AsDelegate() - contract.SetCallCode(&addr, env.StateDB.GetCodeHash(addr), env.StateDB.GetCode(addr)) + contract.SetCallCode(&addr, evm.StateDB.GetCodeHash(addr), evm.StateDB.GetCode(addr)) defer contract.Finalise() - ret, err = env.EVM().Run(contract, input) + ret, err = evm.interpreter.Run(contract, input) if err != nil { contract.UseGas(contract.Gas) - env.StateDB.RevertToSnapshot(snapshot) + evm.StateDB.RevertToSnapshot(snapshot) } return ret, err } // Create creates a new contract using code as deployment code. -func (env *Environment) Create(caller ContractRef, code []byte, gas, value *big.Int) (ret []byte, contractAddr common.Address, err error) { - if env.Depth == 0 { - env.init() - defer close(env.quit) +func (evm *EVM) Create(caller ContractRef, code []byte, gas, value *big.Int) (ret []byte, contractAddr common.Address, err error) { + if evm.Depth == 0 { + evm.init() + defer close(evm.quit) } - if env.vmConfig.NoRecursion && env.Depth > 0 { + if evm.vmConfig.NoRecursion && evm.Depth > 0 { caller.ReturnGas(gas) return nil, common.Address{}, nil @@ -282,37 +282,37 @@ func (env *Environment) Create(caller ContractRef, code []byte, gas, value *big. // Depth check execution. Fail if we're trying to execute above the // limit. - if env.Depth > int(params.CallCreateDepth.Int64()) { + if evm.Depth > int(params.CallCreateDepth.Int64()) { caller.ReturnGas(gas) return nil, common.Address{}, ErrDepth } - if !env.CanTransfer(env.StateDB, caller.Address(), value) { + if !evm.CanTransfer(evm.StateDB, caller.Address(), value) { caller.ReturnGas(gas) return nil, common.Address{}, ErrInsufficientBalance } // Create a new account on the state - nonce := env.StateDB.GetNonce(caller.Address()) - env.StateDB.SetNonce(caller.Address(), nonce+1) + nonce := evm.StateDB.GetNonce(caller.Address()) + evm.StateDB.SetNonce(caller.Address(), nonce+1) - snapshot := env.StateDB.Snapshot() + snapshot := evm.StateDB.Snapshot() contractAddr = crypto.CreateAddress(caller.Address(), nonce) - to := env.StateDB.CreateAccount(contractAddr) - if env.ChainConfig().IsEIP158(env.BlockNumber) { - env.StateDB.SetNonce(contractAddr, 1) + to := evm.StateDB.CreateAccount(contractAddr) + if evm.ChainConfig().IsEIP158(evm.BlockNumber) { + evm.StateDB.SetNonce(contractAddr, 1) } - env.Transfer(env.StateDB, caller.Address(), to.Address(), value) + evm.Transfer(evm.StateDB, caller.Address(), to.Address(), value) // initialise a new contract and set the code that is to be used by the - // E The contract is a scoped environment for this execution context + // E The contract is a scoped evmironment for this execution context // only. contract := NewContract(caller, to, value, gas) contract.SetCallCode(&contractAddr, crypto.Keccak256Hash(code), code) defer contract.Finalise() - ret, err = env.EVM().Run(contract, nil) + ret, err = evm.interpreter.Run(contract, nil) // check whether the max code size has been exceeded maxCodeSizeExceeded := len(ret) > params.MaxCodeSize @@ -324,7 +324,7 @@ func (env *Environment) Create(caller ContractRef, code []byte, gas, value *big. dataGas := big.NewInt(int64(len(ret))) dataGas.Mul(dataGas, params.CreateDataGas) if contract.UseGas(dataGas) { - env.StateDB.SetCode(contractAddr, ret) + evm.StateDB.SetCode(contractAddr, ret) } else { err = ErrCodeStoreOutOfGas } @@ -334,9 +334,9 @@ func (env *Environment) Create(caller ContractRef, code []byte, gas, value *big. // above we revert to the snapshot and consume any gas remaining. Additionally // when we're in homestead this also counts for code storage gas errors. if maxCodeSizeExceeded || - (err != nil && (env.ChainConfig().IsHomestead(env.BlockNumber) || err != ErrCodeStoreOutOfGas)) { + (err != nil && (evm.ChainConfig().IsHomestead(evm.BlockNumber) || err != ErrCodeStoreOutOfGas)) { contract.UseGas(contract.Gas) - env.StateDB.RevertToSnapshot(snapshot) + evm.StateDB.RevertToSnapshot(snapshot) // Nothing should be returned when an error is thrown. return nil, contractAddr, err @@ -351,8 +351,8 @@ func (env *Environment) Create(caller ContractRef, code []byte, gas, value *big. return ret, contractAddr, err } -// ChainConfig returns the environment's chain configuration -func (env *Environment) ChainConfig() *params.ChainConfig { return env.chainConfig } +// ChainConfig returns the evmironment's chain configuration +func (evm *EVM) ChainConfig() *params.ChainConfig { return evm.chainConfig } -// EVM returns the environments EVM -func (env *Environment) EVM() Vm { return env.evm } +// Interpreter returns the EVM interpreter +func (evm *EVM) Interpreter() EVMInterpreter { return evm.interpreter } diff --git a/core/vm/gas_table.go b/core/vm/gas_table.go index b9b6096550..b57bb9cc80 100644 --- a/core/vm/gas_table.go +++ b/core/vm/gas_table.go @@ -34,12 +34,12 @@ func memoryGasCost(mem *Memory, newMemSize *big.Int) *big.Int { } func makeGenericGasFunc(op OpCode) gasFunc { - return func(gt params.GasTable, env *Environment, contract *Contract, stack *Stack, mem *Memory, memorySize *big.Int) *big.Int { + return func(gt params.GasTable, env *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize *big.Int) *big.Int { return gasTable[op] } } -func gasCalldataCopy(gt params.GasTable, env *Environment, contract *Contract, stack *Stack, mem *Memory, memorySize *big.Int) *big.Int { +func gasCalldataCopy(gt params.GasTable, env *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize *big.Int) *big.Int { gas := memoryGasCost(mem, memorySize) gas.Add(gas, gasTable[CALLDATACOPY]) words := toWordSize(stack.Back(2)) @@ -47,7 +47,7 @@ func gasCalldataCopy(gt params.GasTable, env *Environment, contract *Contract, s return gas.Add(gas, words.Mul(words, params.CopyGas)) } -func gasSStore(gt params.GasTable, env *Environment, contract *Contract, stack *Stack, mem *Memory, memorySize *big.Int) *big.Int { +func gasSStore(gt params.GasTable, env *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize *big.Int) *big.Int { var ( y, x = stack.Back(1), stack.Back(0) val = env.StateDB.GetState(contract.Address(), common.BigToHash(x)) @@ -70,7 +70,7 @@ func gasSStore(gt params.GasTable, env *Environment, contract *Contract, stack * } func makeGasLog(n uint) gasFunc { - return func(gt params.GasTable, env *Environment, contract *Contract, stack *Stack, mem *Memory, memorySize *big.Int) *big.Int { + return func(gt params.GasTable, env *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize *big.Int) *big.Int { mSize := stack.Back(1) gas := new(big.Int).Add(memoryGasCost(mem, memorySize), params.LogGas) @@ -80,14 +80,14 @@ func makeGasLog(n uint) gasFunc { } } -func gasSha3(gt params.GasTable, env *Environment, contract *Contract, stack *Stack, mem *Memory, memorySize *big.Int) *big.Int { +func gasSha3(gt params.GasTable, env *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize *big.Int) *big.Int { gas := memoryGasCost(mem, memorySize) gas.Add(gas, gasTable[SHA3]) words := toWordSize(stack.Back(1)) return gas.Add(gas, words.Mul(words, params.Sha3WordGas)) } -func gasCodeCopy(gt params.GasTable, env *Environment, contract *Contract, stack *Stack, mem *Memory, memorySize *big.Int) *big.Int { +func gasCodeCopy(gt params.GasTable, env *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize *big.Int) *big.Int { gas := memoryGasCost(mem, memorySize) gas.Add(gas, gasTable[CODECOPY]) words := toWordSize(stack.Back(2)) @@ -95,7 +95,7 @@ func gasCodeCopy(gt params.GasTable, env *Environment, contract *Contract, stack return gas.Add(gas, words.Mul(words, params.CopyGas)) } -func gasExtCodeCopy(gt params.GasTable, env *Environment, contract *Contract, stack *Stack, mem *Memory, memorySize *big.Int) *big.Int { +func gasExtCodeCopy(gt params.GasTable, env *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize *big.Int) *big.Int { gas := memoryGasCost(mem, memorySize) gas.Add(gas, gt.ExtcodeCopy) words := toWordSize(stack.Back(3)) @@ -103,42 +103,42 @@ func gasExtCodeCopy(gt params.GasTable, env *Environment, contract *Contract, st return gas.Add(gas, words.Mul(words, params.CopyGas)) } -func gasMLoad(gt params.GasTable, env *Environment, contract *Contract, stack *Stack, mem *Memory, memorySize *big.Int) *big.Int { +func gasMLoad(gt params.GasTable, env *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize *big.Int) *big.Int { return new(big.Int).Add(gasTable[MLOAD], memoryGasCost(mem, memorySize)) } -func gasMStore8(gt params.GasTable, env *Environment, contract *Contract, stack *Stack, mem *Memory, memorySize *big.Int) *big.Int { +func gasMStore8(gt params.GasTable, env *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize *big.Int) *big.Int { return new(big.Int).Add(gasTable[MSTORE8], memoryGasCost(mem, memorySize)) } -func gasMStore(gt params.GasTable, env *Environment, contract *Contract, stack *Stack, mem *Memory, memorySize *big.Int) *big.Int { +func gasMStore(gt params.GasTable, env *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize *big.Int) *big.Int { return new(big.Int).Add(gasTable[MSTORE], memoryGasCost(mem, memorySize)) } -func gasCreate(gt params.GasTable, env *Environment, contract *Contract, stack *Stack, mem *Memory, memorySize *big.Int) *big.Int { +func gasCreate(gt params.GasTable, env *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize *big.Int) *big.Int { return new(big.Int).Add(gasTable[CREATE], memoryGasCost(mem, memorySize)) } -func gasBalance(gt params.GasTable, env *Environment, contract *Contract, stack *Stack, mem *Memory, memorySize *big.Int) *big.Int { +func gasBalance(gt params.GasTable, env *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize *big.Int) *big.Int { return gt.Balance } -func gasExtCodeSize(gt params.GasTable, env *Environment, contract *Contract, stack *Stack, mem *Memory, memorySize *big.Int) *big.Int { +func gasExtCodeSize(gt params.GasTable, env *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize *big.Int) *big.Int { return gt.ExtcodeSize } -func gasSLoad(gt params.GasTable, env *Environment, contract *Contract, stack *Stack, mem *Memory, memorySize *big.Int) *big.Int { +func gasSLoad(gt params.GasTable, env *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize *big.Int) *big.Int { return gt.SLoad } -func gasExp(gt params.GasTable, env *Environment, contract *Contract, stack *Stack, mem *Memory, memorySize *big.Int) *big.Int { +func gasExp(gt params.GasTable, env *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize *big.Int) *big.Int { expByteLen := int64((stack.data[stack.len()-2].BitLen() + 7) / 8) gas := big.NewInt(expByteLen) gas.Mul(gas, gt.ExpByte) return gas.Add(gas, gasTable[EXP]) } -func gasCall(gt params.GasTable, env *Environment, contract *Contract, stack *Stack, mem *Memory, memorySize *big.Int) *big.Int { +func gasCall(gt params.GasTable, env *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize *big.Int) *big.Int { gas := new(big.Int).Set(gt.Calls) transfersValue := stack.Back(2).BitLen() > 0 @@ -170,7 +170,7 @@ func gasCall(gt params.GasTable, env *Environment, contract *Contract, stack *St return gas.Add(gas, cg) } -func gasCallCode(gt params.GasTable, env *Environment, contract *Contract, stack *Stack, mem *Memory, memorySize *big.Int) *big.Int { +func gasCallCode(gt params.GasTable, env *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize *big.Int) *big.Int { gas := new(big.Int).Set(gt.Calls) if stack.Back(2).BitLen() > 0 { gas.Add(gas, params.CallValueTransferGas) @@ -189,11 +189,11 @@ func gasCallCode(gt params.GasTable, env *Environment, contract *Contract, stack return gas.Add(gas, cg) } -func gasReturn(gt params.GasTable, env *Environment, contract *Contract, stack *Stack, mem *Memory, memorySize *big.Int) *big.Int { +func gasReturn(gt params.GasTable, env *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize *big.Int) *big.Int { return new(big.Int).Add(gasTable[RETURN], memoryGasCost(mem, memorySize)) } -func gasSuicide(gt params.GasTable, env *Environment, contract *Contract, stack *Stack, mem *Memory, memorySize *big.Int) *big.Int { +func gasSuicide(gt params.GasTable, env *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize *big.Int) *big.Int { gas := new(big.Int) // EIP150 homestead gas reprice fork: if env.ChainConfig().IsEIP150(env.BlockNumber) { @@ -219,7 +219,7 @@ func gasSuicide(gt params.GasTable, env *Environment, contract *Contract, stack return gas } -func gasDelegateCall(gt params.GasTable, env *Environment, contract *Contract, stack *Stack, mem *Memory, memorySize *big.Int) *big.Int { +func gasDelegateCall(gt params.GasTable, env *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize *big.Int) *big.Int { gas := new(big.Int).Add(gt.Calls, memoryGasCost(mem, memorySize)) cg := callGas(gt, contract.Gas, gas, stack.data[stack.len()-1]) @@ -233,15 +233,15 @@ func gasDelegateCall(gt params.GasTable, env *Environment, contract *Contract, s return gas.Add(gas, cg) } -func gasPush(gt params.GasTable, env *Environment, contract *Contract, stack *Stack, mem *Memory, memorySize *big.Int) *big.Int { +func gasPush(gt params.GasTable, env *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize *big.Int) *big.Int { return GasFastestStep } -func gasSwap(gt params.GasTable, env *Environment, contract *Contract, stack *Stack, mem *Memory, memorySize *big.Int) *big.Int { +func gasSwap(gt params.GasTable, env *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize *big.Int) *big.Int { return GasFastestStep } -func gasDup(gt params.GasTable, env *Environment, contract *Contract, stack *Stack, mem *Memory, memorySize *big.Int) *big.Int { +func gasDup(gt params.GasTable, env *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize *big.Int) *big.Int { return GasFastestStep } diff --git a/core/vm/instructions.go b/core/vm/instructions.go index e4ba1139f3..2839b71098 100644 --- a/core/vm/instructions.go +++ b/core/vm/instructions.go @@ -26,25 +26,25 @@ import ( "github.com/ethereum/go-ethereum/params" ) -func opAdd(pc *uint64, env *Environment, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { +func opAdd(pc *uint64, env *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { x, y := stack.pop(), stack.pop() stack.push(U256(x.Add(x, y))) return nil, nil } -func opSub(pc *uint64, env *Environment, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { +func opSub(pc *uint64, env *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { x, y := stack.pop(), stack.pop() stack.push(U256(x.Sub(x, y))) return nil, nil } -func opMul(pc *uint64, env *Environment, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { +func opMul(pc *uint64, env *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { x, y := stack.pop(), stack.pop() stack.push(U256(x.Mul(x, y))) return nil, nil } -func opDiv(pc *uint64, env *Environment, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { +func opDiv(pc *uint64, env *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { x, y := stack.pop(), stack.pop() if y.Cmp(common.Big0) != 0 { stack.push(U256(x.Div(x, y))) @@ -54,7 +54,7 @@ func opDiv(pc *uint64, env *Environment, contract *Contract, memory *Memory, sta return nil, nil } -func opSdiv(pc *uint64, env *Environment, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { +func opSdiv(pc *uint64, env *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { x, y := S256(stack.pop()), S256(stack.pop()) if y.Cmp(common.Big0) == 0 { stack.push(new(big.Int)) @@ -75,7 +75,7 @@ func opSdiv(pc *uint64, env *Environment, contract *Contract, memory *Memory, st return nil, nil } -func opMod(pc *uint64, env *Environment, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { +func opMod(pc *uint64, env *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { x, y := stack.pop(), stack.pop() if y.Cmp(common.Big0) == 0 { stack.push(new(big.Int)) @@ -85,7 +85,7 @@ func opMod(pc *uint64, env *Environment, contract *Contract, memory *Memory, sta return nil, nil } -func opSmod(pc *uint64, env *Environment, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { +func opSmod(pc *uint64, env *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { x, y := S256(stack.pop()), S256(stack.pop()) if y.Cmp(common.Big0) == 0 { @@ -106,13 +106,13 @@ func opSmod(pc *uint64, env *Environment, contract *Contract, memory *Memory, st return nil, nil } -func opExp(pc *uint64, env *Environment, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { +func opExp(pc *uint64, env *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { base, exponent := stack.pop(), stack.pop() stack.push(math.Exp(base, exponent)) return nil, nil } -func opSignExtend(pc *uint64, env *Environment, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { +func opSignExtend(pc *uint64, env *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { back := stack.pop() if back.Cmp(big.NewInt(31)) < 0 { bit := uint(back.Uint64()*8 + 7) @@ -130,13 +130,13 @@ func opSignExtend(pc *uint64, env *Environment, contract *Contract, memory *Memo return nil, nil } -func opNot(pc *uint64, env *Environment, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { +func opNot(pc *uint64, env *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { x := stack.pop() stack.push(U256(x.Not(x))) return nil, nil } -func opLt(pc *uint64, env *Environment, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { +func opLt(pc *uint64, env *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { x, y := stack.pop(), stack.pop() if x.Cmp(y) < 0 { stack.push(big.NewInt(1)) @@ -146,7 +146,7 @@ func opLt(pc *uint64, env *Environment, contract *Contract, memory *Memory, stac return nil, nil } -func opGt(pc *uint64, env *Environment, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { +func opGt(pc *uint64, env *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { x, y := stack.pop(), stack.pop() if x.Cmp(y) > 0 { stack.push(big.NewInt(1)) @@ -156,7 +156,7 @@ func opGt(pc *uint64, env *Environment, contract *Contract, memory *Memory, stac return nil, nil } -func opSlt(pc *uint64, env *Environment, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { +func opSlt(pc *uint64, env *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { x, y := S256(stack.pop()), S256(stack.pop()) if x.Cmp(S256(y)) < 0 { stack.push(big.NewInt(1)) @@ -166,7 +166,7 @@ func opSlt(pc *uint64, env *Environment, contract *Contract, memory *Memory, sta return nil, nil } -func opSgt(pc *uint64, env *Environment, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { +func opSgt(pc *uint64, env *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { x, y := S256(stack.pop()), S256(stack.pop()) if x.Cmp(y) > 0 { stack.push(big.NewInt(1)) @@ -176,7 +176,7 @@ func opSgt(pc *uint64, env *Environment, contract *Contract, memory *Memory, sta return nil, nil } -func opEq(pc *uint64, env *Environment, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { +func opEq(pc *uint64, env *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { x, y := stack.pop(), stack.pop() if x.Cmp(y) == 0 { stack.push(big.NewInt(1)) @@ -186,7 +186,7 @@ func opEq(pc *uint64, env *Environment, contract *Contract, memory *Memory, stac return nil, nil } -func opIszero(pc *uint64, env *Environment, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { +func opIszero(pc *uint64, env *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { x := stack.pop() if x.Cmp(common.Big0) > 0 { stack.push(new(big.Int)) @@ -196,22 +196,22 @@ func opIszero(pc *uint64, env *Environment, contract *Contract, memory *Memory, return nil, nil } -func opAnd(pc *uint64, env *Environment, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { +func opAnd(pc *uint64, env *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { x, y := stack.pop(), stack.pop() stack.push(x.And(x, y)) return nil, nil } -func opOr(pc *uint64, env *Environment, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { +func opOr(pc *uint64, env *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { x, y := stack.pop(), stack.pop() stack.push(x.Or(x, y)) return nil, nil } -func opXor(pc *uint64, env *Environment, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { +func opXor(pc *uint64, env *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { x, y := stack.pop(), stack.pop() stack.push(x.Xor(x, y)) return nil, nil } -func opByte(pc *uint64, env *Environment, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { +func opByte(pc *uint64, env *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { th, val := stack.pop(), stack.pop() if th.Cmp(big.NewInt(32)) < 0 { byte := big.NewInt(int64(common.LeftPadBytes(val.Bytes(), 32)[th.Int64()])) @@ -221,7 +221,7 @@ func opByte(pc *uint64, env *Environment, contract *Contract, memory *Memory, st } return nil, nil } -func opAddmod(pc *uint64, env *Environment, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { +func opAddmod(pc *uint64, env *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { x, y, z := stack.pop(), stack.pop(), stack.pop() if z.Cmp(Zero) > 0 { add := x.Add(x, y) @@ -232,7 +232,7 @@ func opAddmod(pc *uint64, env *Environment, contract *Contract, memory *Memory, } return nil, nil } -func opMulmod(pc *uint64, env *Environment, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { +func opMulmod(pc *uint64, env *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { x, y, z := stack.pop(), stack.pop(), stack.pop() if z.Cmp(Zero) > 0 { mul := x.Mul(x, y) @@ -244,7 +244,7 @@ func opMulmod(pc *uint64, env *Environment, contract *Contract, memory *Memory, return nil, nil } -func opSha3(pc *uint64, env *Environment, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { +func opSha3(pc *uint64, env *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { offset, size := stack.pop(), stack.pop() hash := crypto.Keccak256(memory.Get(offset.Int64(), size.Int64())) @@ -252,12 +252,12 @@ func opSha3(pc *uint64, env *Environment, contract *Contract, memory *Memory, st return nil, nil } -func opAddress(pc *uint64, env *Environment, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { +func opAddress(pc *uint64, env *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { stack.push(common.Bytes2Big(contract.Address().Bytes())) return nil, nil } -func opBalance(pc *uint64, env *Environment, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { +func opBalance(pc *uint64, env *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { addr := common.BigToAddress(stack.pop()) balance := env.StateDB.GetBalance(addr) @@ -265,32 +265,32 @@ func opBalance(pc *uint64, env *Environment, contract *Contract, memory *Memory, return nil, nil } -func opOrigin(pc *uint64, env *Environment, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { +func opOrigin(pc *uint64, env *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { stack.push(env.Origin.Big()) return nil, nil } -func opCaller(pc *uint64, env *Environment, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { +func opCaller(pc *uint64, env *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { stack.push(contract.Caller().Big()) return nil, nil } -func opCallValue(pc *uint64, env *Environment, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { +func opCallValue(pc *uint64, env *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { stack.push(new(big.Int).Set(contract.value)) return nil, nil } -func opCalldataLoad(pc *uint64, env *Environment, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { +func opCalldataLoad(pc *uint64, env *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { stack.push(common.Bytes2Big(getData(contract.Input, stack.pop(), common.Big32))) return nil, nil } -func opCalldataSize(pc *uint64, env *Environment, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { +func opCalldataSize(pc *uint64, env *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { stack.push(big.NewInt(int64(len(contract.Input)))) return nil, nil } -func opCalldataCopy(pc *uint64, env *Environment, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { +func opCalldataCopy(pc *uint64, env *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { var ( mOff = stack.pop() cOff = stack.pop() @@ -300,20 +300,20 @@ func opCalldataCopy(pc *uint64, env *Environment, contract *Contract, memory *Me return nil, nil } -func opExtCodeSize(pc *uint64, env *Environment, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { +func opExtCodeSize(pc *uint64, env *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { addr := common.BigToAddress(stack.pop()) l := big.NewInt(int64(env.StateDB.GetCodeSize(addr))) stack.push(l) return nil, nil } -func opCodeSize(pc *uint64, env *Environment, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { +func opCodeSize(pc *uint64, env *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { l := big.NewInt(int64(len(contract.Code))) stack.push(l) return nil, nil } -func opCodeCopy(pc *uint64, env *Environment, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { +func opCodeCopy(pc *uint64, env *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { var ( mOff = stack.pop() cOff = stack.pop() @@ -325,7 +325,7 @@ func opCodeCopy(pc *uint64, env *Environment, contract *Contract, memory *Memory return nil, nil } -func opExtCodeCopy(pc *uint64, env *Environment, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { +func opExtCodeCopy(pc *uint64, env *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { var ( addr = common.BigToAddress(stack.pop()) mOff = stack.pop() @@ -338,12 +338,12 @@ func opExtCodeCopy(pc *uint64, env *Environment, contract *Contract, memory *Mem return nil, nil } -func opGasprice(pc *uint64, env *Environment, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { +func opGasprice(pc *uint64, env *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { stack.push(new(big.Int).Set(env.GasPrice)) return nil, nil } -func opBlockhash(pc *uint64, env *Environment, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { +func opBlockhash(pc *uint64, env *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { num := stack.pop() n := new(big.Int).Sub(env.BlockNumber, common.Big257) @@ -355,71 +355,71 @@ func opBlockhash(pc *uint64, env *Environment, contract *Contract, memory *Memor return nil, nil } -func opCoinbase(pc *uint64, env *Environment, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { +func opCoinbase(pc *uint64, env *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { stack.push(env.Coinbase.Big()) return nil, nil } -func opTimestamp(pc *uint64, env *Environment, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { +func opTimestamp(pc *uint64, env *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { stack.push(U256(new(big.Int).Set(env.Time))) return nil, nil } -func opNumber(pc *uint64, env *Environment, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { +func opNumber(pc *uint64, env *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { stack.push(U256(new(big.Int).Set(env.BlockNumber))) return nil, nil } -func opDifficulty(pc *uint64, env *Environment, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { +func opDifficulty(pc *uint64, env *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { stack.push(U256(new(big.Int).Set(env.Difficulty))) return nil, nil } -func opGasLimit(pc *uint64, env *Environment, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { +func opGasLimit(pc *uint64, env *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { stack.push(U256(new(big.Int).Set(env.GasLimit))) return nil, nil } -func opPop(pc *uint64, env *Environment, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { +func opPop(pc *uint64, env *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { stack.pop() return nil, nil } -func opMload(pc *uint64, env *Environment, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { +func opMload(pc *uint64, env *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { offset := stack.pop() val := common.BigD(memory.Get(offset.Int64(), 32)) stack.push(val) return nil, nil } -func opMstore(pc *uint64, env *Environment, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { +func opMstore(pc *uint64, env *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { // pop value of the stack mStart, val := stack.pop(), stack.pop() memory.Set(mStart.Uint64(), 32, common.BigToBytes(val, 256)) return nil, nil } -func opMstore8(pc *uint64, env *Environment, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { +func opMstore8(pc *uint64, env *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { off, val := stack.pop().Int64(), stack.pop().Int64() memory.store[off] = byte(val & 0xff) return nil, nil } -func opSload(pc *uint64, env *Environment, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { +func opSload(pc *uint64, env *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { loc := common.BigToHash(stack.pop()) val := env.StateDB.GetState(contract.Address(), loc).Big() stack.push(val) return nil, nil } -func opSstore(pc *uint64, env *Environment, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { +func opSstore(pc *uint64, env *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { loc := common.BigToHash(stack.pop()) val := stack.pop() env.StateDB.SetState(contract.Address(), loc, common.BigToHash(val)) return nil, nil } -func opJump(pc *uint64, env *Environment, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { +func opJump(pc *uint64, env *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { pos := stack.pop() if !contract.jumpdests.has(contract.CodeHash, contract.Code, pos) { nop := contract.GetOp(pos.Uint64()) @@ -428,7 +428,7 @@ func opJump(pc *uint64, env *Environment, contract *Contract, memory *Memory, st *pc = pos.Uint64() return nil, nil } -func opJumpi(pc *uint64, env *Environment, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { +func opJumpi(pc *uint64, env *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { pos, cond := stack.pop(), stack.pop() if cond.Cmp(common.BigTrue) >= 0 { if !contract.jumpdests.has(contract.CodeHash, contract.Code, pos) { @@ -441,26 +441,26 @@ func opJumpi(pc *uint64, env *Environment, contract *Contract, memory *Memory, s } return nil, nil } -func opJumpdest(pc *uint64, env *Environment, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { +func opJumpdest(pc *uint64, env *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { return nil, nil } -func opPc(pc *uint64, env *Environment, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { +func opPc(pc *uint64, env *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { stack.push(new(big.Int).SetUint64(*pc)) return nil, nil } -func opMsize(pc *uint64, env *Environment, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { +func opMsize(pc *uint64, env *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { stack.push(big.NewInt(int64(memory.Len()))) return nil, nil } -func opGas(pc *uint64, env *Environment, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { +func opGas(pc *uint64, env *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { stack.push(new(big.Int).Set(contract.Gas)) return nil, nil } -func opCreate(pc *uint64, env *Environment, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { +func opCreate(pc *uint64, env *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { var ( value = stack.pop() offset, size = stack.pop(), stack.pop() @@ -488,7 +488,7 @@ func opCreate(pc *uint64, env *Environment, contract *Contract, memory *Memory, return nil, nil } -func opCall(pc *uint64, env *Environment, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { +func opCall(pc *uint64, env *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { gas := stack.pop() // pop gas and value of the stack. addr, value := stack.pop(), stack.pop() @@ -520,7 +520,7 @@ func opCall(pc *uint64, env *Environment, contract *Contract, memory *Memory, st return nil, nil } -func opCallCode(pc *uint64, env *Environment, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { +func opCallCode(pc *uint64, env *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { gas := stack.pop() // pop gas and value of the stack. addr, value := stack.pop(), stack.pop() @@ -552,7 +552,7 @@ func opCallCode(pc *uint64, env *Environment, contract *Contract, memory *Memory return nil, nil } -func opDelegateCall(pc *uint64, env *Environment, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { +func opDelegateCall(pc *uint64, env *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { // if not homestead return an error. DELEGATECALL is not supported // during pre-homestead. if !env.ChainConfig().IsHomestead(env.BlockNumber) { @@ -573,18 +573,18 @@ func opDelegateCall(pc *uint64, env *Environment, contract *Contract, memory *Me return nil, nil } -func opReturn(pc *uint64, env *Environment, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { +func opReturn(pc *uint64, env *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { offset, size := stack.pop(), stack.pop() ret := memory.GetPtr(offset.Int64(), size.Int64()) return ret, nil } -func opStop(pc *uint64, env *Environment, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { +func opStop(pc *uint64, env *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { return nil, nil } -func opSuicide(pc *uint64, env *Environment, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { +func opSuicide(pc *uint64, env *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { balance := env.StateDB.GetBalance(contract.Address()) env.StateDB.AddBalance(common.BigToAddress(stack.pop()), balance) @@ -597,7 +597,7 @@ func opSuicide(pc *uint64, env *Environment, contract *Contract, memory *Memory, // make log instruction function func makeLog(size int) executionFunc { - return func(pc *uint64, env *Environment, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { + return func(pc *uint64, env *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { topics := make([]common.Hash, size) mStart, mSize := stack.pop(), stack.pop() for i := 0; i < size; i++ { @@ -613,7 +613,7 @@ func makeLog(size int) executionFunc { // make push instruction function func makePush(size uint64, bsize *big.Int) executionFunc { - return func(pc *uint64, env *Environment, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { + return func(pc *uint64, env *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { byts := getData(contract.Code, new(big.Int).SetUint64(*pc+1), bsize) stack.push(common.Bytes2Big(byts)) *pc += size @@ -623,7 +623,7 @@ func makePush(size uint64, bsize *big.Int) executionFunc { // make push instruction function func makeDup(size int64) executionFunc { - return func(pc *uint64, env *Environment, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { + return func(pc *uint64, env *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { stack.dup(int(size)) return nil, nil } @@ -633,7 +633,7 @@ func makeDup(size int64) executionFunc { func makeSwap(size int64) executionFunc { // switch n + 1 otherwise n would be swapped with n size += 1 - return func(pc *uint64, env *Environment, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { + return func(pc *uint64, env *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { stack.swap(int(size)) return nil, nil } diff --git a/core/vm/interface.go b/core/vm/interface.go index 918fde85fb..ea39cf8e15 100644 --- a/core/vm/interface.go +++ b/core/vm/interface.go @@ -22,8 +22,8 @@ import ( "github.com/ethereum/go-ethereum/common" ) -// Vm is the basic interface for an implementation of the EVM. -type Vm interface { +// EVMInterpreter is the basic interface for an implementation of the EVM. +type EVMInterpreter interface { // Run should execute the given contract with the input given in in // and return the contract execution return bytes or an error if it // failed. @@ -83,15 +83,15 @@ type Account interface { Value() *big.Int } -// CallContext provides a basic interface for the EVM calling conventions. The EVM Environment +// CallContext provides a basic interface for the EVM calling conventions. The EVM EVM // depends on this context being implemented for doing subcalls and initialising new EVM contracts. type CallContext interface { // Call another contract - Call(env *Environment, me ContractRef, addr common.Address, data []byte, gas, value *big.Int) ([]byte, error) + Call(env *EVM, me ContractRef, addr common.Address, data []byte, gas, value *big.Int) ([]byte, error) // Take another's contract code and execute within our own context - CallCode(env *Environment, me ContractRef, addr common.Address, data []byte, gas, value *big.Int) ([]byte, error) + CallCode(env *EVM, me ContractRef, addr common.Address, data []byte, gas, value *big.Int) ([]byte, error) // Same as CallCode except sender and value is propagated from parent to child scope - DelegateCall(env *Environment, me ContractRef, addr common.Address, data []byte, gas *big.Int) ([]byte, error) + DelegateCall(env *EVM, me ContractRef, addr common.Address, data []byte, gas *big.Int) ([]byte, error) // Create a new contract - Create(env *Environment, me ContractRef, data []byte, gas, value *big.Int) ([]byte, common.Address, error) + Create(env *EVM, me ContractRef, data []byte, gas, value *big.Int) ([]byte, common.Address, error) } diff --git a/core/vm/jump_table.go b/core/vm/jump_table.go index 5f78624393..8e49e9b64b 100644 --- a/core/vm/jump_table.go +++ b/core/vm/jump_table.go @@ -23,8 +23,8 @@ import ( ) type ( - executionFunc func(pc *uint64, env *Environment, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) - gasFunc func(params.GasTable, *Environment, *Contract, *Stack, *Memory, *big.Int) *big.Int + executionFunc func(pc *uint64, env *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) + gasFunc func(params.GasTable, *EVM, *Contract, *Stack, *Memory, *big.Int) *big.Int stackValidationFunc func(*Stack) error memorySizeFunc func(*Stack) *big.Int ) diff --git a/core/vm/logger.go b/core/vm/logger.go index 370d234aa0..221f06831d 100644 --- a/core/vm/logger.go +++ b/core/vm/logger.go @@ -45,7 +45,7 @@ type LogConfig struct { Limit int // maximum length of output, but zero means unlimited } -// StructLog is emitted to the Environment each cycle and lists information about the current internal state +// StructLog is emitted to the EVM each cycle and lists information about the current internal state // prior to the execution of the statement. type StructLog struct { Pc uint64 @@ -65,7 +65,7 @@ type StructLog struct { // Note that reference types are actual VM data structures; make copies // if you need to retain them beyond the current call. type Tracer interface { - CaptureState(env *Environment, pc uint64, op OpCode, gas, cost *big.Int, memory *Memory, stack *Stack, contract *Contract, depth int, err error) error + CaptureState(env *EVM, pc uint64, op OpCode, gas, cost *big.Int, memory *Memory, stack *Stack, contract *Contract, depth int, err error) error } // StructLogger is an EVM state logger and implements Tracer. @@ -94,7 +94,7 @@ func NewStructLogger(cfg *LogConfig) *StructLogger { // captureState logs a new structured log message and pushes it out to the environment // // captureState also tracks SSTORE ops to track dirty values. -func (l *StructLogger) CaptureState(env *Environment, pc uint64, op OpCode, gas, cost *big.Int, memory *Memory, stack *Stack, contract *Contract, depth int, err error) error { +func (l *StructLogger) CaptureState(env *EVM, pc uint64, op OpCode, gas, cost *big.Int, memory *Memory, stack *Stack, contract *Contract, depth int, err error) error { // check if already accumulated the specified number of logs if l.cfg.Limit != 0 && l.cfg.Limit <= len(l.logs) { return ErrTraceLimitReached diff --git a/core/vm/logger_test.go b/core/vm/logger_test.go index d8c43a0d2a..05db46e323 100644 --- a/core/vm/logger_test.go +++ b/core/vm/logger_test.go @@ -53,7 +53,7 @@ func (d dummyStateDB) GetAccount(common.Address) Account { func TestStoreCapture(t *testing.T) { var ( - env = NewEnvironment(Context{Context: context.TODO()}, nil, params.TestChainConfig, Config{EnableJit: false, ForceJit: false}) + env = NewEVM(Context{Context: context.TODO()}, nil, params.TestChainConfig, Config{EnableJit: false, ForceJit: false}) logger = NewStructLogger(nil) mem = NewMemory() stack = newstack() @@ -80,7 +80,7 @@ func TestStorageCapture(t *testing.T) { var ( ref = &dummyContractRef{} contract = NewContract(ref, ref, new(big.Int), new(big.Int)) - env = NewEnvironment(Context{Context: context.TODO()}, dummyStateDB{ref: ref}, params.TestChainConfig, Config{EnableJit: false, ForceJit: false}) + env = NewEVM(Context{Context: context.TODO()}, dummyStateDB{ref: ref}, params.TestChainConfig, Config{EnableJit: false, ForceJit: false}) logger = NewStructLogger(nil) mem = NewMemory() stack = newstack() diff --git a/core/vm/runtime/env.go b/core/vm/runtime/env.go index 678b0a55fa..51d7ba1dbd 100644 --- a/core/vm/runtime/env.go +++ b/core/vm/runtime/env.go @@ -26,7 +26,7 @@ import ( "github.com/ethereum/go-ethereum/core/vm" ) -func NewEnv(cfg *Config, state *state.StateDB) *vm.Environment { +func NewEnv(cfg *Config, state *state.StateDB) *vm.EVM { context := vm.Context{ Context: context.TODO(), CanTransfer: core.CanTransfer, @@ -42,5 +42,5 @@ func NewEnv(cfg *Config, state *state.StateDB) *vm.Environment { GasPrice: new(big.Int), } - return vm.NewEnvironment(context, cfg.State, cfg.ChainConfig, cfg.EVMConfig) + return vm.NewEVM(context, cfg.State, cfg.ChainConfig, cfg.EVMConfig) } diff --git a/core/vm/runtime/runtime_test.go b/core/vm/runtime/runtime_test.go index 88c76c7319..1e618b688a 100644 --- a/core/vm/runtime/runtime_test.go +++ b/core/vm/runtime/runtime_test.go @@ -56,7 +56,7 @@ func TestDefaults(t *testing.T) { } } -func TestEnvironment(t *testing.T) { +func TestEVM(t *testing.T) { defer func() { if r := recover(); r != nil { t.Fatalf("crashed with: %v", r) diff --git a/core/vm/vm.go b/core/vm/vm.go index a7cf98a954..e5d5b19920 100644 --- a/core/vm/vm.go +++ b/core/vm/vm.go @@ -29,9 +29,9 @@ import ( "github.com/ethereum/go-ethereum/params" ) -// Config are the configuration options for the EVM +// Config are the configuration options for the Interpreter type Config struct { - // Debug enabled debugging EVM options + // Debug enabled debugging Interpreter options Debug bool // EnableJit enabled the JIT VM EnableJit bool @@ -39,26 +39,26 @@ type Config struct { ForceJit bool // Tracer is the op code logger Tracer Tracer - // NoRecursion disabled EVM call, callcode, + // NoRecursion disabled Interpreter call, callcode, // delegate call and create. NoRecursion bool // Disable gas metering DisableGasMetering bool } -// EVM is used to run Ethereum based contracts and will utilise the +// Interpreter is used to run Ethereum based contracts and will utilise the // passed environment to query external sources for state information. -// The EVM will run the byte code VM or JIT VM based on the passed +// The Interpreter will run the byte code VM or JIT VM based on the passed // configuration. -type EVM struct { - env *Environment +type Interpreter struct { + env *EVM cfg Config gasTable params.GasTable } -// New returns a new instance of the EVM. -func New(env *Environment, cfg Config) *EVM { - return &EVM{ +// NewInterpreter returns a new instance of the Interpreter. +func NewInterpreter(env *EVM, cfg Config) *Interpreter { + return &Interpreter{ env: env, cfg: cfg, gasTable: env.ChainConfig().GasTable(env.BlockNumber), @@ -66,7 +66,7 @@ func New(env *Environment, cfg Config) *EVM { } // Run loops and evaluates the contract's code with the given input data -func (evm *EVM) Run(contract *Contract, input []byte) (ret []byte, err error) { +func (evm *Interpreter) Run(contract *Contract, input []byte) (ret []byte, err error) { evm.env.Depth++ defer func() { evm.env.Depth-- }() @@ -112,7 +112,7 @@ func (evm *EVM) Run(contract *Contract, input []byte) (ret []byte, err error) { }() } - // The EVM main run loop (contextual). This loop runs until either an + // The Interpreter main run loop (contextual). This loop runs until either an // explicit STOP, RETURN or SUICIDE is executed, an error accured during // the execution of one of the operations or until the evm.done is set by // the parent context.Context. diff --git a/core/vm/vm_jit.go b/core/vm/vm_jit.go index f6e4a515bc..eb3acfb10d 100644 --- a/core/vm/vm_jit.go +++ b/core/vm/vm_jit.go @@ -44,7 +44,7 @@ import ( ) type JitVm struct { - env Environment + env EVM me ContextRef callerAddr []byte price *big.Int @@ -161,7 +161,7 @@ func assert(condition bool, message string) { } } -func NewJitVm(env Environment) *JitVm { +func NewJitVm(env EVM) *JitVm { return &JitVm{env: env} } @@ -235,7 +235,7 @@ func (self *JitVm) Endl() VirtualMachine { return self } -func (self *JitVm) Env() Environment { +func (self *JitVm) Env() EVM { return self.env } diff --git a/eth/api.go b/eth/api.go index 6010d149cc..bf15a3fa7b 100644 --- a/eth/api.go +++ b/eth/api.go @@ -532,7 +532,7 @@ func (api *PrivateDebugAPI) TraceTransaction(ctx context.Context, txHash common. // Mutate the state if we haven't reached the tracing transaction yet if uint64(idx) < txIndex { - vmenv := vm.NewEnvironment(context, stateDb, api.config, vm.Config{}) + vmenv := vm.NewEVM(context, stateDb, api.config, vm.Config{}) _, _, err := core.ApplyMessage(vmenv, msg, new(core.GasPool).AddGas(tx.Gas())) if err != nil { return nil, fmt.Errorf("mutation failed: %v", err) @@ -541,7 +541,7 @@ func (api *PrivateDebugAPI) TraceTransaction(ctx context.Context, txHash common. continue } - vmenv := vm.NewEnvironment(context, stateDb, api.config, vm.Config{Debug: true, Tracer: tracer}) + vmenv := vm.NewEVM(context, stateDb, api.config, vm.Config{Debug: true, Tracer: tracer}) ret, gas, err := core.ApplyMessage(vmenv, msg, new(core.GasPool).AddGas(tx.Gas())) if err != nil { return nil, fmt.Errorf("tracing failed: %v", err) diff --git a/eth/api_backend.go b/eth/api_backend.go index f33b6f7e19..801b6a4f61 100644 --- a/eth/api_backend.go +++ b/eth/api_backend.go @@ -106,14 +106,14 @@ func (b *EthApiBackend) GetTd(blockHash common.Hash) *big.Int { return b.eth.blockchain.GetTdByHash(blockHash) } -func (b *EthApiBackend) GetVMEnv(ctx context.Context, msg core.Message, state ethapi.State, header *types.Header) (*vm.Environment, func() error, error) { +func (b *EthApiBackend) GetVMEnv(ctx context.Context, msg core.Message, state ethapi.State, header *types.Header) (*vm.EVM, func() error, error) { statedb := state.(EthApiState).state from := statedb.GetOrNewStateObject(msg.From()) from.SetBalance(common.MaxBig) vmError := func() error { return nil } context := core.NewEVMContext(msg, header, b.eth.BlockChain()) - return vm.NewEnvironment(context, statedb, b.eth.chainConfig, vm.Config{}), vmError, nil + return vm.NewEVM(context, statedb, b.eth.chainConfig, vm.Config{}), vmError, nil } func (b *EthApiBackend) SendTx(ctx context.Context, signedTx *types.Transaction) error { diff --git a/internal/ethapi/backend.go b/internal/ethapi/backend.go index 36d7e754bb..ebb14a5b5c 100644 --- a/internal/ethapi/backend.go +++ b/internal/ethapi/backend.go @@ -51,7 +51,7 @@ type Backend interface { GetBlock(ctx context.Context, blockHash common.Hash) (*types.Block, error) GetReceipts(ctx context.Context, blockHash common.Hash) (types.Receipts, error) GetTd(blockHash common.Hash) *big.Int - GetVMEnv(ctx context.Context, msg core.Message, state State, header *types.Header) (*vm.Environment, func() error, error) + GetVMEnv(ctx context.Context, msg core.Message, state State, header *types.Header) (*vm.EVM, func() error, error) // TxPool API SendTx(ctx context.Context, signedTx *types.Transaction) error RemoveTx(txHash common.Hash) diff --git a/internal/ethapi/tracer.go b/internal/ethapi/tracer.go index 6d632376b8..ef107fc42f 100644 --- a/internal/ethapi/tracer.go +++ b/internal/ethapi/tracer.go @@ -278,7 +278,7 @@ func wrapError(context string, err error) error { } // CaptureState implements the Tracer interface to trace a single step of VM execution -func (jst *JavascriptTracer) CaptureState(env *vm.Environment, pc uint64, op vm.OpCode, gas, cost *big.Int, memory *vm.Memory, stack *vm.Stack, contract *vm.Contract, depth int, err error) error { +func (jst *JavascriptTracer) CaptureState(env *vm.EVM, pc uint64, op vm.OpCode, gas, cost *big.Int, memory *vm.Memory, stack *vm.Stack, contract *vm.Contract, depth int, err error) error { if jst.err == nil { jst.memory.memory = memory jst.stack.stack = stack diff --git a/internal/ethapi/tracer_test.go b/internal/ethapi/tracer_test.go index 29814d7835..65a23f55e7 100644 --- a/internal/ethapi/tracer_test.go +++ b/internal/ethapi/tracer_test.go @@ -43,12 +43,12 @@ func (account) SetCode(common.Hash, []byte) {} func (account) ForEachStorage(cb func(key, value common.Hash) bool) {} func runTrace(tracer *JavascriptTracer) (interface{}, error) { - env := vm.NewEnvironment(vm.Context{}, nil, params.TestChainConfig, vm.Config{Debug: true, Tracer: tracer}) + env := vm.NewEVM(vm.Context{}, nil, params.TestChainConfig, vm.Config{Debug: true, Tracer: tracer}) contract := vm.NewContract(account{}, account{}, big.NewInt(0), big.NewInt(10000)) contract.Code = []byte{byte(vm.PUSH1), 0x1, byte(vm.PUSH1), 0x1, 0x0} - _, err := env.EVM().Run(contract, []byte{}) + _, err := env.Interpreter().Run(contract, []byte{}) if err != nil { return nil, err } @@ -133,7 +133,7 @@ func TestHaltBetweenSteps(t *testing.T) { t.Fatal(err) } - env := vm.NewEnvironment(vm.Context{}, nil, params.TestChainConfig, vm.Config{Debug: true, Tracer: tracer}) + env := vm.NewEVM(vm.Context{}, nil, params.TestChainConfig, vm.Config{Debug: true, Tracer: tracer}) contract := vm.NewContract(&account{}, &account{}, big.NewInt(0), big.NewInt(0)) tracer.CaptureState(env, 0, 0, big.NewInt(0), big.NewInt(0), nil, nil, contract, 0, nil) diff --git a/les/api_backend.go b/les/api_backend.go index 7dc548ec3e..e4f7417d61 100644 --- a/les/api_backend.go +++ b/les/api_backend.go @@ -88,7 +88,7 @@ func (b *LesApiBackend) GetTd(blockHash common.Hash) *big.Int { return b.eth.blockchain.GetTdByHash(blockHash) } -func (b *LesApiBackend) GetVMEnv(ctx context.Context, msg core.Message, state ethapi.State, header *types.Header) (*vm.Environment, func() error, error) { +func (b *LesApiBackend) GetVMEnv(ctx context.Context, msg core.Message, state ethapi.State, header *types.Header) (*vm.EVM, func() error, error) { stateDb := state.(*light.LightState).Copy() addr := msg.From() from, err := stateDb.GetOrNewStateObject(ctx, addr) @@ -99,7 +99,7 @@ func (b *LesApiBackend) GetVMEnv(ctx context.Context, msg core.Message, state et vmstate := light.NewVMState(ctx, stateDb) context := core.NewEVMContext(msg, header, b.eth.blockchain) - return vm.NewEnvironment(context, vmstate, b.eth.chainConfig, vm.Config{}), vmstate.Error, nil + return vm.NewEVM(context, vmstate, b.eth.chainConfig, vm.Config{}), vmstate.Error, nil } func (b *LesApiBackend) SendTx(ctx context.Context, signedTx *types.Transaction) error { diff --git a/les/odr_test.go b/les/odr_test.go index 6854359961..b5cbda838b 100644 --- a/les/odr_test.go +++ b/les/odr_test.go @@ -123,7 +123,7 @@ func odrContractCall(ctx context.Context, db ethdb.Database, config *params.Chai msg := callmsg{types.NewMessage(from.Address(), &testContractAddr, 0, new(big.Int), big.NewInt(100000), new(big.Int), data, false)} context := core.NewEVMContext(msg, header, bc) - vmenv := vm.NewEnvironment(context, statedb, config, vm.Config{}) + vmenv := vm.NewEVM(context, statedb, config, vm.Config{}) //vmenv := core.NewEnv(statedb, config, bc, msg, header, vm.Config{}) gp := new(core.GasPool).AddGas(common.MaxBig) @@ -141,7 +141,7 @@ func odrContractCall(ctx context.Context, db ethdb.Database, config *params.Chai msg := callmsg{types.NewMessage(from.Address(), &testContractAddr, 0, new(big.Int), big.NewInt(100000), new(big.Int), data, false)} context := core.NewEVMContext(msg, header, lc) - vmenv := vm.NewEnvironment(context, vmstate, config, vm.Config{}) + vmenv := vm.NewEVM(context, vmstate, config, vm.Config{}) //vmenv := light.NewEnv(ctx, state, config, lc, msg, header, vm.Config{}) gp := new(core.GasPool).AddGas(common.MaxBig) diff --git a/light/odr_test.go b/light/odr_test.go index 2f60f32fd9..a6c956e9a1 100644 --- a/light/odr_test.go +++ b/light/odr_test.go @@ -172,7 +172,7 @@ func odrContractCall(ctx context.Context, db ethdb.Database, bc *core.BlockChain msg := callmsg{types.NewMessage(from.Address(), &testContractAddr, 0, new(big.Int), big.NewInt(1000000), new(big.Int), data, false)} context := core.NewEVMContext(msg, header, bc) - vmenv := vm.NewEnvironment(context, statedb, config, vm.Config{}) + vmenv := vm.NewEVM(context, statedb, config, vm.Config{}) gp := new(core.GasPool).AddGas(common.MaxBig) ret, _, _ := core.ApplyMessage(vmenv, msg, gp) @@ -188,7 +188,7 @@ func odrContractCall(ctx context.Context, db ethdb.Database, bc *core.BlockChain msg := callmsg{types.NewMessage(from.Address(), &testContractAddr, 0, new(big.Int), big.NewInt(1000000), new(big.Int), data, false)} context := core.NewEVMContext(msg, header, lc) - vmenv := vm.NewEnvironment(context, vmstate, config, vm.Config{}) + vmenv := vm.NewEVM(context, vmstate, config, vm.Config{}) gp := new(core.GasPool).AddGas(common.MaxBig) ret, _, _ := core.ApplyMessage(vmenv, msg, gp) if vmstate.Error() == nil { diff --git a/tests/util.go b/tests/util.go index a7ce25d518..91e826f265 100644 --- a/tests/util.go +++ b/tests/util.go @@ -150,7 +150,7 @@ type VmTest struct { PostStateRoot string } -func NewEVMEnvironment(vmTest bool, chainConfig *params.ChainConfig, statedb *state.StateDB, envValues map[string]string, tx map[string]string) (*vm.Environment, core.Message) { +func NewEVMEnvironment(vmTest bool, chainConfig *params.ChainConfig, statedb *state.StateDB, envValues map[string]string, tx map[string]string) (*vm.EVM, core.Message) { var ( data = common.FromHex(tx["data"]) gas = common.Big(tx["gasLimit"]) @@ -210,5 +210,5 @@ func NewEVMEnvironment(vmTest bool, chainConfig *params.ChainConfig, statedb *st if context.GasPrice == nil { context.GasPrice = new(big.Int) } - return vm.NewEnvironment(context, statedb, chainConfig, vm.Config{NoRecursion: vmTest}), msg + return vm.NewEVM(context, statedb, chainConfig, vm.Config{NoRecursion: vmTest}), msg }