@@ -29,6 +29,7 @@ import (
29
29
"github.com/ethereum/go-ethereum/common/math"
30
30
"github.com/ethereum/go-ethereum/core/types"
31
31
"github.com/ethereum/go-ethereum/params"
32
+ "github.com/holiman/uint256"
32
33
)
33
34
34
35
// Storage represents a contract's storage.
@@ -66,7 +67,7 @@ type StructLog struct {
66
67
GasCost uint64 `json:"gasCost"`
67
68
Memory []byte `json:"memory"`
68
69
MemorySize int `json:"memSize"`
69
- Stack []* big .Int `json:"stack"`
70
+ Stack []uint256 .Int `json:"stack"`
70
71
ReturnData []byte `json:"returnData"`
71
72
Storage map [common.Hash ]common.Hash `json:"-"`
72
73
Depth int `json:"depth"`
@@ -76,7 +77,6 @@ type StructLog struct {
76
77
77
78
// overrides for gencodec
78
79
type structLogMarshaling struct {
79
- Stack []* math.HexOrDecimal256
80
80
Gas math.HexOrDecimal64
81
81
GasCost math.HexOrDecimal64
82
82
Memory hexutil.Bytes
@@ -135,6 +135,14 @@ func NewStructLogger(cfg *LogConfig) *StructLogger {
135
135
return logger
136
136
}
137
137
138
+ // Reset clears the data held by the logger.
139
+ func (l * StructLogger ) Reset () {
140
+ l .storage = make (map [common.Address ]Storage )
141
+ l .output = make ([]byte , 0 )
142
+ l .logs = l .logs [:0 ]
143
+ l .err = nil
144
+ }
145
+
138
146
// CaptureStart implements the Tracer interface to initialize the tracing operation.
139
147
func (l * StructLogger ) CaptureStart (env * EVM , from common.Address , to common.Address , create bool , input []byte , gas uint64 , value * big.Int ) {
140
148
}
@@ -157,16 +165,16 @@ func (l *StructLogger) CaptureState(env *EVM, pc uint64, op OpCode, gas, cost ui
157
165
copy (mem , memory .Data ())
158
166
}
159
167
// Copy a snapshot of the current stack state to a new buffer
160
- var stck []* big .Int
168
+ var stck []uint256 .Int
161
169
if ! l .cfg .DisableStack {
162
- stck = make ([]* big .Int , len (stack .Data ()))
170
+ stck = make ([]uint256 .Int , len (stack .Data ()))
163
171
for i , item := range stack .Data () {
164
- stck [i ] = new (big. Int ). Set ( item . ToBig ())
172
+ stck [i ] = item
165
173
}
166
174
}
167
175
// Copy a snapshot of the current storage to a new container
168
176
var storage Storage
169
- if ! l .cfg .DisableStorage {
177
+ if ! l .cfg .DisableStorage && ( op == SLOAD || op == SSTORE ) {
170
178
// initialise new changed values storage container for this contract
171
179
// if not present.
172
180
if l .storage [contract .Address ()] == nil {
@@ -179,16 +187,16 @@ func (l *StructLogger) CaptureState(env *EVM, pc uint64, op OpCode, gas, cost ui
179
187
value = env .StateDB .GetState (contract .Address (), address )
180
188
)
181
189
l .storage [contract .Address ()][address ] = value
182
- }
183
- // capture SSTORE opcodes and record the written entry in the local storage.
184
- if op == SSTORE && stack . len () >= 2 {
190
+ storage = l . storage [ contract . Address ()]. Copy ()
191
+ } else if op == SSTORE && stack . len () >= 2 {
192
+ // capture SSTORE opcodes and record the written entry in the local storage.
185
193
var (
186
194
value = common .Hash (stack .data [stack .len ()- 2 ].Bytes32 ())
187
195
address = common .Hash (stack .data [stack .len ()- 1 ].Bytes32 ())
188
196
)
189
197
l .storage [contract .Address ()][address ] = value
198
+ storage = l .storage [contract .Address ()].Copy ()
190
199
}
191
- storage = l .storage [contract .Address ()].Copy ()
192
200
}
193
201
var rdata []byte
194
202
if ! l .cfg .DisableReturnData {
@@ -238,7 +246,7 @@ func WriteTrace(writer io.Writer, logs []StructLog) {
238
246
if len (log .Stack ) > 0 {
239
247
fmt .Fprintln (writer , "Stack:" )
240
248
for i := len (log .Stack ) - 1 ; i >= 0 ; i -- {
241
- fmt .Fprintf (writer , "%08d %x \n " , len (log .Stack )- i - 1 , math . PaddedBigBytes ( log .Stack [i ], 32 ))
249
+ fmt .Fprintf (writer , "%08d %s \n " , len (log .Stack )- i - 1 , log .Stack [i ]. Hex ( ))
242
250
}
243
251
}
244
252
if len (log .Memory ) > 0 {
@@ -314,7 +322,7 @@ func (t *mdLogger) CaptureState(env *EVM, pc uint64, op OpCode, gas, cost uint64
314
322
// format stack
315
323
var a []string
316
324
for _ , elem := range stack .data {
317
- a = append (a , fmt . Sprintf ( "%v" , elem .String () ))
325
+ a = append (a , elem .Hex ( ))
318
326
}
319
327
b := fmt .Sprintf ("[%v]" , strings .Join (a , "," ))
320
328
fmt .Fprintf (t .out , "%10v |" , b )
0 commit comments