Skip to content

Commit

Permalink
core/vm: simplify tracer hook invocation in interpreter loop (#31074)
Browse files Browse the repository at this point in the history
Removes duplicate code in the interpreter loop.
  • Loading branch information
jwasinger authored Feb 3, 2025
1 parent fc12dbe commit 55a1861
Showing 1 changed file with 8 additions and 16 deletions.
24 changes: 8 additions & 16 deletions core/vm/interpreter.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,9 +258,9 @@ func (in *EVMInterpreter) Run(contract *Contract, input []byte, readOnly bool) (
contract.Gas -= cost
}

// All ops with a dynamic memory usage also has a dynamic gas cost.
var memorySize uint64
if operation.dynamicGas != nil {
// All ops with a dynamic memory usage also has a dynamic gas cost.
var memorySize uint64
// calculate the new memory size and expand the memory to fit
// the operation
// Memory check needs to be done prior to evaluating the dynamic gas portion,
Expand Down Expand Up @@ -290,21 +290,10 @@ func (in *EVMInterpreter) Run(contract *Contract, input []byte, readOnly bool) (
} else {
contract.Gas -= dynamicCost
}
}

// Do tracing before memory expansion
if debug {
if in.evm.Config.Tracer.OnGasChange != nil {
in.evm.Config.Tracer.OnGasChange(gasCopy, gasCopy-cost, tracing.GasChangeCallOpCode)
}
if in.evm.Config.Tracer.OnOpcode != nil {
in.evm.Config.Tracer.OnOpcode(pc, byte(op), gasCopy, cost, callContext, in.returnData, in.evm.depth, VMErrorFromErr(err))
logged = true
}
}
if memorySize > 0 {
mem.Resize(memorySize)
}
} else if debug {
// Do tracing before potential memory expansion
if debug {
if in.evm.Config.Tracer.OnGasChange != nil {
in.evm.Config.Tracer.OnGasChange(gasCopy, gasCopy-cost, tracing.GasChangeCallOpCode)
}
Expand All @@ -313,6 +302,9 @@ func (in *EVMInterpreter) Run(contract *Contract, input []byte, readOnly bool) (
logged = true
}
}
if memorySize > 0 {
mem.Resize(memorySize)
}

// execute the operation
res, err = operation.execute(&pc, in, callContext)
Expand Down

0 comments on commit 55a1861

Please sign in to comment.