From 55a18616b1c4d2ffee498e07ddef23f49bddbb6d Mon Sep 17 00:00:00 2001 From: jwasinger Date: Mon, 3 Feb 2025 09:44:26 -0800 Subject: [PATCH] core/vm: simplify tracer hook invocation in interpreter loop (#31074) Removes duplicate code in the interpreter loop. --- core/vm/interpreter.go | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/core/vm/interpreter.go b/core/vm/interpreter.go index e3237936a0..a0038d1aa8 100644 --- a/core/vm/interpreter.go +++ b/core/vm/interpreter.go @@ -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, @@ -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) } @@ -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)