Skip to content

Commit fa830e3

Browse files
committed
fix(core/vm): trace before memory expansion ethereum#31074
Move opcode tracing out of the dynamic gas branch so tracing always runs before memory expansion. Keep memory resizing in one place to match the upstream interpreter flow.
1 parent f5fe86c commit fa830e3

1 file changed

Lines changed: 8 additions & 16 deletions

File tree

core/vm/interpreter.go

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -183,9 +183,9 @@ func (evm *EVM) Run(contract *Contract, input []byte, readOnly bool) (ret []byte
183183
contract.Gas -= cost
184184
}
185185

186+
// All ops with a dynamic memory usage also has a dynamic gas cost.
187+
var memorySize uint64
186188
if operation.dynamicGas != nil {
187-
// All ops with a dynamic memory usage also has a dynamic gas cost.
188-
var memorySize uint64
189189
// calculate the new memory size and expand the memory to fit
190190
// the operation
191191
// Memory check needs to be done prior to evaluating the dynamic gas portion,
@@ -215,21 +215,10 @@ func (evm *EVM) Run(contract *Contract, input []byte, readOnly bool) (ret []byte
215215
} else {
216216
contract.Gas -= dynamicCost
217217
}
218+
}
218219

219-
// Do tracing before memory expansion
220-
if debug {
221-
if evm.Config.Tracer.OnGasChange != nil {
222-
evm.Config.Tracer.OnGasChange(gasCopy, gasCopy-cost, tracing.GasChangeCallOpCode)
223-
}
224-
if evm.Config.Tracer.OnOpcode != nil {
225-
evm.Config.Tracer.OnOpcode(pc, byte(op), gasCopy, cost, callContext, evm.returnData, evm.depth, VMErrorFromErr(err))
226-
logged = true
227-
}
228-
}
229-
if memorySize > 0 {
230-
mem.Resize(memorySize)
231-
}
232-
} else if debug {
220+
// Do tracing before memory expansion
221+
if debug {
233222
if evm.Config.Tracer.OnGasChange != nil {
234223
evm.Config.Tracer.OnGasChange(gasCopy, gasCopy-cost, tracing.GasChangeCallOpCode)
235224
}
@@ -238,6 +227,9 @@ func (evm *EVM) Run(contract *Contract, input []byte, readOnly bool) (ret []byte
238227
logged = true
239228
}
240229
}
230+
if memorySize > 0 {
231+
mem.Resize(memorySize)
232+
}
241233

242234
// execute the operation
243235
res, err = operation.execute(&pc, evm, callContext)

0 commit comments

Comments
 (0)