@@ -258,9 +258,9 @@ func (in *EVMInterpreter) Run(contract *Contract, input []byte, readOnly bool) (
258258 contract .Gas -= cost
259259 }
260260
261+ // All ops with a dynamic memory usage also has a dynamic gas cost.
262+ var memorySize uint64
261263 if operation .dynamicGas != nil {
262- // All ops with a dynamic memory usage also has a dynamic gas cost.
263- var memorySize uint64
264264 // calculate the new memory size and expand the memory to fit
265265 // the operation
266266 // 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) (
290290 } else {
291291 contract .Gas -= dynamicCost
292292 }
293+ }
293294
294- // Do tracing before memory expansion
295- if debug {
296- if in .evm .Config .Tracer .OnGasChange != nil {
297- in .evm .Config .Tracer .OnGasChange (gasCopy , gasCopy - cost , tracing .GasChangeCallOpCode )
298- }
299- if in .evm .Config .Tracer .OnOpcode != nil {
300- in .evm .Config .Tracer .OnOpcode (pc , byte (op ), gasCopy , cost , callContext , in .returnData , in .evm .depth , VMErrorFromErr (err ))
301- logged = true
302- }
303- }
304- if memorySize > 0 {
305- mem .Resize (memorySize )
306- }
307- } else if debug {
295+ // Do tracing before potential memory expansion
296+ if debug {
308297 if in .evm .Config .Tracer .OnGasChange != nil {
309298 in .evm .Config .Tracer .OnGasChange (gasCopy , gasCopy - cost , tracing .GasChangeCallOpCode )
310299 }
@@ -313,6 +302,9 @@ func (in *EVMInterpreter) Run(contract *Contract, input []byte, readOnly bool) (
313302 logged = true
314303 }
315304 }
305+ if memorySize > 0 {
306+ mem .Resize (memorySize )
307+ }
316308
317309 // execute the operation
318310 res , err = operation .execute (& pc , in , callContext )
0 commit comments