@@ -29,6 +29,7 @@ import (
2929 "github.com/ethereum/go-ethereum/common/math"
3030 "github.com/ethereum/go-ethereum/core/types"
3131 "github.com/ethereum/go-ethereum/params"
32+ "github.com/holiman/uint256"
3233)
3334
3435// Storage represents a contract's storage.
@@ -66,7 +67,7 @@ type StructLog struct {
6667 GasCost uint64 `json:"gasCost"`
6768 Memory []byte `json:"memory"`
6869 MemorySize int `json:"memSize"`
69- Stack []* big .Int `json:"stack"`
70+ Stack []uint256 .Int `json:"stack"`
7071 ReturnData []byte `json:"returnData"`
7172 Storage map [common.Hash ]common.Hash `json:"-"`
7273 Depth int `json:"depth"`
@@ -76,7 +77,6 @@ type StructLog struct {
7677
7778// overrides for gencodec
7879type structLogMarshaling struct {
79- Stack []* math.HexOrDecimal256
8080 Gas math.HexOrDecimal64
8181 GasCost math.HexOrDecimal64
8282 Memory hexutil.Bytes
@@ -135,6 +135,14 @@ func NewStructLogger(cfg *LogConfig) *StructLogger {
135135 return logger
136136}
137137
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+
138146// CaptureStart implements the Tracer interface to initialize the tracing operation.
139147func (l * StructLogger ) CaptureStart (env * EVM , from common.Address , to common.Address , create bool , input []byte , gas uint64 , value * big.Int ) {
140148}
@@ -157,16 +165,16 @@ func (l *StructLogger) CaptureState(env *EVM, pc uint64, op OpCode, gas, cost ui
157165 copy (mem , memory .Data ())
158166 }
159167 // Copy a snapshot of the current stack state to a new buffer
160- var stck []* big .Int
168+ var stck []uint256 .Int
161169 if ! l .cfg .DisableStack {
162- stck = make ([]* big .Int , len (stack .Data ()))
170+ stck = make ([]uint256 .Int , len (stack .Data ()))
163171 for i , item := range stack .Data () {
164- stck [i ] = new (big. Int ). Set ( item . ToBig ())
172+ stck [i ] = item
165173 }
166174 }
167175 // Copy a snapshot of the current storage to a new container
168176 var storage Storage
169- if ! l .cfg .DisableStorage {
177+ if ! l .cfg .DisableStorage && ( op == SLOAD || op == SSTORE ) {
170178 // initialise new changed values storage container for this contract
171179 // if not present.
172180 if l .storage [contract .Address ()] == nil {
@@ -179,16 +187,16 @@ func (l *StructLogger) CaptureState(env *EVM, pc uint64, op OpCode, gas, cost ui
179187 value = env .StateDB .GetState (contract .Address (), address )
180188 )
181189 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.
185193 var (
186194 value = common .Hash (stack .data [stack .len ()- 2 ].Bytes32 ())
187195 address = common .Hash (stack .data [stack .len ()- 1 ].Bytes32 ())
188196 )
189197 l .storage [contract .Address ()][address ] = value
198+ storage = l .storage [contract .Address ()].Copy ()
190199 }
191- storage = l .storage [contract .Address ()].Copy ()
192200 }
193201 var rdata []byte
194202 if ! l .cfg .DisableReturnData {
@@ -238,7 +246,7 @@ func WriteTrace(writer io.Writer, logs []StructLog) {
238246 if len (log .Stack ) > 0 {
239247 fmt .Fprintln (writer , "Stack:" )
240248 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 ( ))
242250 }
243251 }
244252 if len (log .Memory ) > 0 {
@@ -314,7 +322,7 @@ func (t *mdLogger) CaptureState(env *EVM, pc uint64, op OpCode, gas, cost uint64
314322 // format stack
315323 var a []string
316324 for _ , elem := range stack .data {
317- a = append (a , fmt . Sprintf ( "%v" , elem .String () ))
325+ a = append (a , elem .Hex ( ))
318326 }
319327 b := fmt .Sprintf ("[%v]" , strings .Join (a , "," ))
320328 fmt .Fprintf (t .out , "%10v |" , b )
0 commit comments