Skip to content

Commit

Permalink
add log
Browse files Browse the repository at this point in the history
  • Loading branch information
sunny2022da committed Mar 29, 2024
1 parent d484393 commit e2dfaf9
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
4 changes: 2 additions & 2 deletions core/vm/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions core/vm/instructions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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])}
}

Expand Down
10 changes: 7 additions & 3 deletions core/vm/interpreter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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}
}

Expand Down Expand Up @@ -262,3 +262,7 @@ func (in *EVMInterpreter) EnableOptimization() {
in.table = in.optimizedTable
}
}

func (in *EVMInterpreter) IsOptimizationEnabled() bool {
return in.table == in.optimizedTable
}
5 changes: 2 additions & 3 deletions core/vm/jump_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -1206,4 +1205,4 @@ func enableOptimizedOpcode(tbl *JumpTable) *JumpTable {
}

return tbl
}
}

0 comments on commit e2dfaf9

Please sign in to comment.