@@ -137,12 +137,17 @@ func (in *Interpreter) Run(snapshot int, contract *Contract, input []byte) (ret
137137 // to be uint256. Practically much less so feasible.
138138 pc = uint64 (0 ) // program counter
139139 cost uint64
140+ // copies used by tracer
141+ stackCopy = newstack () // stackCopy needed for Tracer since stack is mutated by 63/64 gas rule
142+ pcCopy uint64 // needed for the deferred Tracer
143+ gasCopy uint64 // for Tracer to log gas remaining before execution
144+ logged bool // deferred Tracer should ignore already logged steps
140145 )
141146 contract .Input = input
142147
143148 defer func () {
144- if err != nil && in .cfg .Debug {
145- in .cfg .Tracer .CaptureState (in .evm , pc , op , contract . Gas , cost , mem , stack , contract , in .evm .depth , err )
149+ if err != nil && ! logged && in .cfg .Debug {
150+ in .cfg .Tracer .CaptureState (in .evm , pcCopy , op , gasCopy , cost , mem , stackCopy , contract , in .evm .depth , err )
146151 }
147152 }()
148153
@@ -154,6 +159,16 @@ func (in *Interpreter) Run(snapshot int, contract *Contract, input []byte) (ret
154159 // Get the memory location of pc
155160 op = contract .GetOp (pc )
156161
162+ if in .cfg .Debug {
163+ logged = false
164+ pcCopy = uint64 (pc )
165+ gasCopy = uint64 (contract .Gas )
166+ stackCopy = newstack ()
167+ for _ , val := range stack .data {
168+ stackCopy .push (val )
169+ }
170+ }
171+
157172 // get the operation from the jump table matching the opcode
158173 operation := in .cfg .JumpTable [op ]
159174 if err := in .enforceRestrictions (op , operation , stack ); err != nil {
@@ -199,7 +214,8 @@ func (in *Interpreter) Run(snapshot int, contract *Contract, input []byte) (ret
199214 }
200215
201216 if in .cfg .Debug {
202- in .cfg .Tracer .CaptureState (in .evm , pc , op , contract .Gas , cost , mem , stack , contract , in .evm .depth , err )
217+ in .cfg .Tracer .CaptureState (in .evm , pc , op , gasCopy , cost , mem , stackCopy , contract , in .evm .depth , err )
218+ logged = true
203219 }
204220
205221 // execute the operation
0 commit comments