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
2 changes: 1 addition & 1 deletion execution/tracing/tracers/js/tracer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func runTrace(tracer *tracers.Tracer, vmctx *vmContext, chaincfg *chain.Config,

tracer.OnTxStart(env.GetVMContext(), types.NewTransaction(0, accounts.ZeroAddress.Value(), nil, gasLimit, nil, nil), contract.Caller())
tracer.OnEnter(0, byte(vm.CALL), contract.Caller(), contract.Address(), false, []byte{}, startGas, value, contractCode)
ret, endGas, err := env.Interpreter().Run(contract, startGas, []byte{}, false)
ret, endGas, err := env.Run(contract, startGas, []byte{}, false)
tracer.OnExit(0, ret, startGas-endGas, err, true)
// Rest gas assumes no refund
tracer.OnTxEnd(&types.Receipt{GasUsed: gasLimit - endGas}, nil)
Expand Down
2 changes: 1 addition & 1 deletion execution/tracing/tracers/logger/logger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func TestStoreCapture(t *testing.T) {
contract.Code = []byte{byte(vm.PUSH1), 0x1, byte(vm.PUSH1), 0x0, byte(vm.SSTORE)}
var index common.Hash
logger.OnTxStart(evm.GetVMContext(), nil, accounts.ZeroAddress)
_, _, err := evm.Interpreter().Run(contract, 100000, []byte{}, false)
_, _, err := evm.Run(contract, 100000, []byte{}, false)
if err != nil {
t.Fatal(err)
}
Expand Down
38 changes: 19 additions & 19 deletions execution/vm/eips.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ func enable1884(jt *JumpTable) {
}
}

func opSelfBalance(pc uint64, interpreter *EVMInterpreter, callContext *CallContext) (uint64, []byte, error) {
balance, err := interpreter.evm.IntraBlockState().GetBalance(callContext.Contract.Address())
func opSelfBalance(pc uint64, evm *EVM, callContext *CallContext) (uint64, []byte, error) {
balance, err := evm.IntraBlockState().GetBalance(callContext.Contract.Address())
if err != nil {
return pc, nil, err
}
Expand All @@ -116,8 +116,8 @@ func enable1344(jt *JumpTable) {
}

// opChainID implements CHAINID opcode
func opChainID(pc uint64, interpreter *EVMInterpreter, callContext *CallContext) (uint64, []byte, error) {
chainId, _ := uint256.FromBig(interpreter.evm.ChainRules().ChainID)
func opChainID(pc uint64, evm *EVM, callContext *CallContext) (uint64, []byte, error) {
chainId, _ := uint256.FromBig(evm.ChainRules().ChainID)
callContext.Stack.push(*chainId)
return pc, nil, nil
}
Expand Down Expand Up @@ -203,28 +203,28 @@ func enable1153(jt *JumpTable) {
}

// opTload implements TLOAD opcode
func opTload(pc uint64, interpreter *EVMInterpreter, scope *CallContext) (uint64, []byte, error) {
func opTload(pc uint64, evm *EVM, scope *CallContext) (uint64, []byte, error) {
loc := scope.Stack.peek()
key := accounts.InternKey(loc.Bytes32())
val := interpreter.evm.IntraBlockState().GetTransientState(scope.Contract.Address(), key)
val := evm.IntraBlockState().GetTransientState(scope.Contract.Address(), key)
loc.SetBytes(val.Bytes())
return pc, nil, nil
}

// opTstore implements TSTORE opcode
func opTstore(pc uint64, interpreter *EVMInterpreter, scope *CallContext) (uint64, []byte, error) {
if interpreter.readOnly {
func opTstore(pc uint64, evm *EVM, scope *CallContext) (uint64, []byte, error) {
if evm.readOnly {
return pc, nil, ErrWriteProtection
}
loc := scope.Stack.pop()
val := scope.Stack.pop()
interpreter.evm.IntraBlockState().SetTransientState(scope.Contract.Address(), accounts.InternKey(loc.Bytes32()), val)
evm.IntraBlockState().SetTransientState(scope.Contract.Address(), accounts.InternKey(loc.Bytes32()), val)
return pc, nil, nil
}

// opBaseFee implements BASEFEE opcode
func opBaseFee(pc uint64, interpreter *EVMInterpreter, callContext *CallContext) (uint64, []byte, error) {
baseFee := interpreter.evm.Context.BaseFee
func opBaseFee(pc uint64, evm *EVM, callContext *CallContext) (uint64, []byte, error) {
baseFee := evm.Context.BaseFee
callContext.Stack.push(baseFee)
return pc, nil, nil
}
Expand All @@ -241,7 +241,7 @@ func enable3855(jt *JumpTable) {
}

// opPush0 implements the PUSH0 opcode
func opPush0(pc uint64, interpreter *EVMInterpreter, scope *CallContext) (uint64, []byte, error) {
func opPush0(pc uint64, evm *EVM, scope *CallContext) (uint64, []byte, error) {
scope.Stack.push(uint256.Int{})
return pc, nil, nil
}
Expand All @@ -265,18 +265,18 @@ func enable4844(jt *JumpTable) {
}

// opBlobHash implements the BLOBHASH opcode
func opBlobHash(pc uint64, interpreter *EVMInterpreter, scope *CallContext) (uint64, []byte, error) {
func opBlobHash(pc uint64, evm *EVM, scope *CallContext) (uint64, []byte, error) {
idx := scope.Stack.peek()
if idx.LtUint64(uint64(len(interpreter.evm.BlobHashes))) {
hash := interpreter.evm.BlobHashes[idx.Uint64()]
if idx.LtUint64(uint64(len(evm.BlobHashes))) {
hash := evm.BlobHashes[idx.Uint64()]
idx.SetBytes(hash.Bytes())
} else {
idx.Clear()
}
return pc, nil, nil
}

func opCLZ(pc uint64, interpreter *EVMInterpreter, scope *CallContext) (uint64, []byte, error) {
func opCLZ(pc uint64, evm *EVM, scope *CallContext) (uint64, []byte, error) {
x := scope.Stack.peek()
// count leading zero bits in x
x.SetUint64(256 - uint64(x.BitLen()))
Expand All @@ -297,7 +297,7 @@ func enable5656(jt *JumpTable) {
}

// opMcopy implements the MCOPY opcode (https://eips.ethereum.org/EIPS/eip-5656)
func opMcopy(pc uint64, interpreter *EVMInterpreter, scope *CallContext) (uint64, []byte, error) {
func opMcopy(pc uint64, evm *EVM, scope *CallContext) (uint64, []byte, error) {
var (
dst = scope.Stack.pop()
src = scope.Stack.pop()
Expand All @@ -315,8 +315,8 @@ func enable6780(jt *JumpTable) {
}

// opBlobBaseFee implements the BLOBBASEFEE opcode
func opBlobBaseFee(pc uint64, interpreter *EVMInterpreter, callContext *CallContext) (uint64, []byte, error) {
blobBaseFee := interpreter.evm.Context.BlobBaseFee
func opBlobBaseFee(pc uint64, evm *EVM, callContext *CallContext) (uint64, []byte, error) {
blobBaseFee := evm.Context.BlobBaseFee
callContext.Stack.push(blobBaseFee)
return pc, nil, nil
}
Expand Down
40 changes: 21 additions & 19 deletions execution/vm/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (

"github.com/holiman/uint256"

"github.com/erigontech/erigon/common"
"github.com/erigontech/erigon/common/crypto"
"github.com/erigontech/erigon/common/dbg"
"github.com/erigontech/erigon/common/u256"
Expand Down Expand Up @@ -64,16 +65,19 @@ type EVM struct {
// IntraBlockState gives access to the underlying state
intraBlockState *state.IntraBlockState

// table holds the opcode specific handlers
jt *JumpTable

// depth is the current call stack
depth int

// chainConfig contains information about the current chain
chainConfig *chain.Config
// chain rules contains the chain rules for the current epoch
chainRules *chain.Rules
// virtual machine configuration options used to initialise the
// evm.
config Config
// global (to this context) ethereum virtual machine
// used throughout the execution of the tx.
interpreter Interpreter
// abort is used to abort the EVM calling operations
abort atomic.Bool
// callGasTemp holds the gas available for the current call. This is needed because the
Expand All @@ -82,6 +86,12 @@ type EVM struct {
callGasTemp uint64
// optional overridden set of precompiled contracts
precompiles PrecompiledContracts

hasher keccakState // Keccak256 hasher instance shared across opcodes
hasherBuf common.Hash // Keccak256 hasher result array shared across opcodes

readOnly bool // Whether to throw on stateful modifications
returnData []byte // Last CALL's return data for subsequent reuse
}

// NewEVM returns a new EVM. The returned EVM is not thread safe and should
Expand All @@ -100,7 +110,7 @@ func NewEVM(blockCtx evmtypes.BlockContext, txCtx evmtypes.TxContext, ibs *state
chainConfig: chainConfig,
chainRules: blockCtx.Rules(chainConfig),
}
evm.interpreter = NewEVMInterpreter(evm, vmConfig)
evm.jt = jumpTable(evm.chainRules, vmConfig)

return evm
}
Expand All @@ -127,7 +137,9 @@ func (evm *EVM) ResetBetweenBlocks(blockCtx evmtypes.BlockContext, txCtx evmtype
evm.config = vmConfig
evm.chainRules = chainRules

evm.interpreter = NewEVMInterpreter(evm, vmConfig)
evm.depth = 0
evm.returnData = nil
evm.jt = jumpTable(chainRules, vmConfig)

// ensure the evm is reset to be used again
evm.abort.Store(false)
Expand Down Expand Up @@ -155,17 +167,12 @@ func (evm *EVM) SetPrecompiles(precompiles PrecompiledContracts) {
evm.precompiles = precompiles
}

// Interpreter returns the current interpreter
func (evm *EVM) Interpreter() Interpreter {
return evm.interpreter
}

func (evm *EVM) call(typ OpCode, caller accounts.Address, callerAddress accounts.Address, addr accounts.Address, input []byte, gas uint64, value uint256.Int, bailout bool) (ret []byte, leftOverGas uint64, err error) {
if evm.abort.Load() {
return ret, leftOverGas, nil
}

depth := evm.interpreter.Depth()
depth := evm.depth

version := evm.intraBlockState.Version()
if (dbg.TraceTransactionIO && !dbg.TraceInstructions) && (evm.intraBlockState.Trace() || dbg.TraceAccount(caller.Handle())) {
Expand Down Expand Up @@ -283,7 +290,7 @@ func (evm *EVM) call(typ OpCode, caller accounts.Address, callerAddress accounts
if typ == STATICCALL {
readOnly = true
}
ret, gas, err = evm.interpreter.Run(contract, gas, input, readOnly)
ret, gas, err = evm.Run(contract, gas, input, readOnly)
}
// 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
Expand Down Expand Up @@ -370,7 +377,7 @@ func (evm *EVM) create(caller accounts.Address, codeAndHash *codeAndHash, gasRem
}()
}

depth := evm.interpreter.Depth()
depth := evm.depth

// BAL: record target address even on failed CREATE/CREATE2 calls
evm.intraBlockState.MarkAddressAccess(address)
Expand Down Expand Up @@ -458,7 +465,7 @@ func (evm *EVM) create(caller accounts.Address, codeAndHash *codeAndHash, gasRem
return nil, address, gasRemaining, nil
}

ret, gasRemaining, err = evm.interpreter.Run(contract, gasRemaining, nil, false)
ret, gasRemaining, err = evm.Run(contract, gasRemaining, nil, false)

// EIP-170: Contract code size limit
if err == nil && evm.chainRules.IsSpuriousDragon && len(ret) > evm.maxCodeSize() {
Expand Down Expand Up @@ -605,8 +612,3 @@ func (evm *EVM) captureEnd(depth int, typ OpCode, startGas uint64, leftOverGas u
tracer.OnExit(depth, ret, startGas-leftOverGas, VMErrorFromErr(err), reverted)
}
}

// Depth returns the current depth
func (evm *EVM) Depth() int {
return evm.interpreter.Depth()
}
Loading
Loading