diff --git a/core/vm/evm.go b/core/vm/evm.go index 11b2fdde16..23ee4a74e0 100644 --- a/core/vm/evm.go +++ b/core/vm/evm.go @@ -142,7 +142,7 @@ func NewEVM(blockCtx BlockContext, txCtx TxContext, statedb StateDB, chainConfig evm.interpreter = NewEVMInterpreter(evm) if config.EnableOpcodeOptimizations { compiler.EnableOptimization() - evm.interpreter.table = evm.interpreter.optimizedTable + evm.interpreter.EnableOptimization() } return evm } @@ -434,7 +434,7 @@ func tryGetOptimizedCode(evm *EVM, codeHash common.Hash, rawCode []byte) (bool, var code []byte optimized := false code = rawCode - if evm.Config.EnableOpcodeOptimizations { + if evm.interpreter.IsOptimizationEnabled() { optCode := compiler.LoadOptimizedCode(codeHash) if len(optCode) != 0 { code = optCode diff --git a/core/vm/instructions.go b/core/vm/instructions.go index 93b895e2c8..283bff51a8 100644 --- a/core/vm/instructions.go +++ b/core/vm/instructions.go @@ -18,10 +18,13 @@ package vm import ( "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/core/opcodeCompiler/compiler" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/crypto" + "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/params" "github.com/holiman/uint256" + "runtime/debug" ) func opAdd(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) { @@ -818,6 +821,8 @@ func opRevert(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]b } func opUndefined(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) { + log.Error("Undefined Op", "optimization enabled", compiler.IsEnabled(), "use opt table", interpreter.table == interpreter.optimizedTable, "opcode", OpCode(scope.Contract.Code[*pc]).String()) + debug.PrintStack() return nil, &ErrInvalidOpCode{opcode: OpCode(scope.Contract.Code[*pc])} } diff --git a/core/vm/interpreter.go b/core/vm/interpreter.go index b2209eeabc..79f1bfe817 100644 --- a/core/vm/interpreter.go +++ b/core/vm/interpreter.go @@ -29,7 +29,7 @@ type Config struct { NoBaseFee bool // Forces the EIP-1559 baseFee to 0 (needed for 0 price calls) EnablePreimageRecording bool // Enables recording of SHA3/keccak preimages ExtraEips []int // Additional EIPS that are to be enabled - EnableOpcodeOptimizations bool // Disable optimization of opcode. + EnableOpcodeOptimizations bool // Enable opcode optimization } // ScopeContext contains the things that are per-call, such as stack and memory, @@ -101,9 +101,9 @@ func NewEVMInterpreter(evm *EVM) *EVMInterpreter { evm.Config.ExtraEips = extraEips if evm.Config.EnableOpcodeOptimizations { optimizedTable = copyJumpTable(table) - optimizedTable = enableOptimizedOpcode(optimizedTable) + optimizedTable = createOptimizedOpcodeTable(optimizedTable) + return &EVMInterpreter{evm: evm, table: optimizedTable, unOptimizedTable: table, optimizedTable: optimizedTable} } - return &EVMInterpreter{evm: evm, table: table, unOptimizedTable: table, optimizedTable: optimizedTable} } @@ -262,3 +262,7 @@ func (in *EVMInterpreter) EnableOptimization() { in.table = in.optimizedTable } } + +func (in *EVMInterpreter) IsOptimizationEnabled() bool { + return in.table == in.optimizedTable +} diff --git a/core/vm/jump_table.go b/core/vm/jump_table.go index 0c987b0242..d8f30eb880 100644 --- a/core/vm/jump_table.go +++ b/core/vm/jump_table.go @@ -1076,9 +1076,8 @@ func copyJumpTable(source *JumpTable) *JumpTable { return &dest } -func enableOptimizedOpcode(tbl *JumpTable) *JumpTable { +func createOptimizedOpcodeTable(tbl *JumpTable) *JumpTable { // super instructions - tbl[Nop] = &operation{ execute: opNop, constantGas: 0, @@ -1206,4 +1205,4 @@ func enableOptimizedOpcode(tbl *JumpTable) *JumpTable { } return tbl -} \ No newline at end of file +}