@@ -137,12 +137,17 @@ func (in *Interpreter) Run(snapshot int, contract *Contract, input []byte) (ret
137
137
// to be uint256. Practically much less so feasible.
138
138
pc = uint64 (0 ) // program counter
139
139
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
140
145
)
141
146
contract .Input = input
142
147
143
148
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 )
146
151
}
147
152
}()
148
153
@@ -154,6 +159,16 @@ func (in *Interpreter) Run(snapshot int, contract *Contract, input []byte) (ret
154
159
// Get the memory location of pc
155
160
op = contract .GetOp (pc )
156
161
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
+
157
172
// get the operation from the jump table matching the opcode
158
173
operation := in .cfg .JumpTable [op ]
159
174
if err := in .enforceRestrictions (op , operation , stack ); err != nil {
@@ -199,7 +214,8 @@ func (in *Interpreter) Run(snapshot int, contract *Contract, input []byte) (ret
199
214
}
200
215
201
216
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
203
219
}
204
220
205
221
// execute the operation
0 commit comments