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 83055f5
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 31 deletions.
3 changes: 0 additions & 3 deletions core/vm/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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.
Expand Down
33 changes: 8 additions & 25 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 All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}
}
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 83055f5

Please sign in to comment.