Skip to content
Draft
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
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
19 changes: 17 additions & 2 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,6 +65,12 @@ 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
Expand All @@ -82,6 +89,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 +113,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 +140,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
Loading
Loading