diff --git a/core/vm/evm.go b/core/vm/evm.go index 11b2fdde16..9399c7be3f 100644 --- a/core/vm/evm.go +++ b/core/vm/evm.go @@ -142,7 +142,6 @@ func NewEVM(blockCtx BlockContext, txCtx TxContext, statedb StateDB, chainConfig evm.interpreter = NewEVMInterpreter(evm) if config.EnableOpcodeOptimizations { compiler.EnableOptimization() - evm.interpreter.table = evm.interpreter.optimizedTable } return evm } @@ -507,14 +506,12 @@ func (evm *EVM) create(caller ContractRef, codeAndHash *codeAndHash, gas uint64, contract.optimized = false if evm.Config.EnableOpcodeOptimizations { compiler.DisableOptimization() - evm.interpreter.DisableOptimization() } ret, err := evm.interpreter.Run(contract, nil, false) // After creation, retrieve to optimization if evm.Config.EnableOpcodeOptimizations { compiler.EnableOptimization() - evm.interpreter.EnableOptimization() } // Check whether the max code size has been exceeded, assign err if the case. diff --git a/core/vm/interpreter.go b/core/vm/interpreter.go index b2209eeabc..a06fbb1390 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, @@ -42,12 +42,10 @@ type ScopeContext struct { // EVMInterpreter represents an EVM interpreter type EVMInterpreter struct { - evm *EVM - table *JumpTable - unOptimizedTable *JumpTable - optimizedTable *JumpTable - hasher crypto.KeccakState // Keccak256 hasher instance shared across opcodes - hasherBuf common.Hash // Keccak256 hasher result array shared across opcodes + evm *EVM + table *JumpTable + hasher crypto.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 @@ -57,8 +55,6 @@ type EVMInterpreter struct { func NewEVMInterpreter(evm *EVM) *EVMInterpreter { // If jump table was not initialised we set the default one. var table *JumpTable - // The standard jump table without fused opcode. The main purpose is to follow the rule of spec and avoid fused opcode. - var optimizedTable *JumpTable switch { case evm.chainRules.IsCancun: table = &cancunInstructionSet @@ -98,13 +94,12 @@ func NewEVMInterpreter(evm *EVM) *EVMInterpreter { extraEips = append(extraEips, eip) } } + evm.Config.ExtraEips = extraEips if evm.Config.EnableOpcodeOptimizations { - optimizedTable = copyJumpTable(table) - optimizedTable = enableOptimizedOpcode(optimizedTable) + table = createOptimizedOpcodeTable(table) } - - return &EVMInterpreter{evm: evm, table: table, unOptimizedTable: table, optimizedTable: optimizedTable} + return &EVMInterpreter{evm: evm, table: table} } // Run loops and evaluates the contract's code with the given input data and returns @@ -250,15 +245,3 @@ func (in *EVMInterpreter) Run(contract *Contract, input []byte, readOnly bool) ( return res, err } - -func (in *EVMInterpreter) DisableOptimization() { - if in.table != in.unOptimizedTable { - in.table = in.unOptimizedTable - } -} - -func (in *EVMInterpreter) EnableOptimization() { - if in.table != in.optimizedTable { - 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 +}