@@ -18,7 +18,6 @@ package vm
1818
1919import (
2020 "encoding/hex"
21- "errors"
2221 "fmt"
2322 "io"
2423 "math/big"
@@ -32,8 +31,6 @@ import (
3231 "github.com/ethereum/go-ethereum/params"
3332)
3433
35- var errTraceLimitReached = errors .New ("the number of logs reached the specified limit" )
36-
3734// Storage represents a contract's storage.
3835type Storage map [common.Hash ]common.Hash
3936
@@ -107,10 +104,10 @@ func (s *StructLog) ErrorString() string {
107104// Note that reference types are actual VM data structures; make copies
108105// if you need to retain them beyond the current call.
109106type Tracer interface {
110- CaptureStart (from common.Address , to common.Address , create bool , input []byte , gas uint64 , value * big.Int ) error
111- CaptureState (env * EVM , pc uint64 , op OpCode , gas , cost uint64 , memory * Memory , stack * Stack , rData []byte , contract * Contract , depth int , err error ) error
112- CaptureFault (env * EVM , pc uint64 , op OpCode , gas , cost uint64 , memory * Memory , stack * Stack , contract * Contract , depth int , err error ) error
113- CaptureEnd (output []byte , gasUsed uint64 , t time.Duration , err error ) error
107+ CaptureStart (env * EVM , from common.Address , to common.Address , create bool , input []byte , gas uint64 , value * big.Int )
108+ CaptureState (env * EVM , pc uint64 , op OpCode , gas , cost uint64 , scope * ScopeContext , rData []byte , depth int , err error )
109+ CaptureFault (env * EVM , pc uint64 , op OpCode , gas , cost uint64 , scope * ScopeContext , depth int , err error )
110+ CaptureEnd (output []byte , gasUsed uint64 , t time.Duration , err error )
114111}
115112
116113// StructLogger is an EVM state logger and implements Tracer.
@@ -139,17 +136,19 @@ func NewStructLogger(cfg *LogConfig) *StructLogger {
139136}
140137
141138// CaptureStart implements the Tracer interface to initialize the tracing operation.
142- func (l * StructLogger ) CaptureStart (from common.Address , to common.Address , create bool , input []byte , gas uint64 , value * big.Int ) error {
143- return nil
139+ func (l * StructLogger ) CaptureStart (env * EVM , from common.Address , to common.Address , create bool , input []byte , gas uint64 , value * big.Int ) {
144140}
145141
146142// CaptureState logs a new structured log message and pushes it out to the environment
147143//
148144// CaptureState also tracks SLOAD/SSTORE ops to track storage change.
149- func (l * StructLogger ) CaptureState (env * EVM , pc uint64 , op OpCode , gas , cost uint64 , memory * Memory , stack * Stack , rData []byte , contract * Contract , depth int , err error ) error {
145+ func (l * StructLogger ) CaptureState (env * EVM , pc uint64 , op OpCode , gas , cost uint64 , scope * ScopeContext , rData []byte , depth int , err error ) {
146+ memory := scope .Memory
147+ stack := scope .Stack
148+ contract := scope .Contract
150149 // check if already accumulated the specified number of logs
151150 if l .cfg .Limit != 0 && l .cfg .Limit <= len (l .logs ) {
152- return errTraceLimitReached
151+ return
153152 }
154153 // Copy a snapshot of the current memory state to a new buffer
155154 var mem []byte
@@ -199,17 +198,15 @@ func (l *StructLogger) CaptureState(env *EVM, pc uint64, op OpCode, gas, cost ui
199198 // create a new snapshot of the EVM.
200199 log := StructLog {pc , op , gas , cost , mem , memory .Len (), stck , rdata , storage , depth , env .StateDB .GetRefund (), err }
201200 l .logs = append (l .logs , log )
202- return nil
203201}
204202
205203// CaptureFault implements the Tracer interface to trace an execution fault
206204// while running an opcode.
207- func (l * StructLogger ) CaptureFault (env * EVM , pc uint64 , op OpCode , gas , cost uint64 , memory * Memory , stack * Stack , contract * Contract , depth int , err error ) error {
208- return nil
205+ func (l * StructLogger ) CaptureFault (env * EVM , pc uint64 , op OpCode , gas , cost uint64 , scope * ScopeContext , depth int , err error ) {
209206}
210207
211208// CaptureEnd is called after the call finishes to finalize the tracing.
212- func (l * StructLogger ) CaptureEnd (output []byte , gasUsed uint64 , t time.Duration , err error ) error {
209+ func (l * StructLogger ) CaptureEnd (output []byte , gasUsed uint64 , t time.Duration , err error ) {
213210 l .output = output
214211 l .err = err
215212 if l .cfg .Debug {
@@ -218,7 +215,6 @@ func (l *StructLogger) CaptureEnd(output []byte, gasUsed uint64, t time.Duration
218215 fmt .Printf (" error: %v\n " , err )
219216 }
220217 }
221- return nil
222218}
223219
224220// StructLogs returns the captured log entries.
@@ -292,7 +288,7 @@ func NewMarkdownLogger(cfg *LogConfig, writer io.Writer) *mdLogger {
292288 return l
293289}
294290
295- func (t * mdLogger ) CaptureStart (from common.Address , to common.Address , create bool , input []byte , gas uint64 , value * big.Int ) error {
291+ func (t * mdLogger ) CaptureStart (env * EVM , from common.Address , to common.Address , create bool , input []byte , gas uint64 , value * big.Int ) {
296292 if ! create {
297293 fmt .Fprintf (t .out , "From: `%v`\n To: `%v`\n Data: `0x%x`\n Gas: `%d`\n Value `%v` wei\n " ,
298294 from .String (), to .String (),
@@ -307,10 +303,11 @@ func (t *mdLogger) CaptureStart(from common.Address, to common.Address, create b
307303| Pc | Op | Cost | Stack | RStack | Refund |
308304|-------|-------------|------|-----------|-----------|---------|
309305` )
310- return nil
311306}
312307
313- func (t * mdLogger ) CaptureState (env * EVM , pc uint64 , op OpCode , gas , cost uint64 , memory * Memory , stack * Stack , rData []byte , contract * Contract , depth int , err error ) error {
308+ // CaptureState also tracks SLOAD/SSTORE ops to track storage change.
309+ func (t * mdLogger ) CaptureState (env * EVM , pc uint64 , op OpCode , gas , cost uint64 , scope * ScopeContext , rData []byte , depth int , err error ) {
310+ stack := scope .Stack
314311 fmt .Fprintf (t .out , "| %4d | %10v | %3d |" , pc , op , cost )
315312
316313 if ! t .cfg .DisableStack {
@@ -327,18 +324,13 @@ func (t *mdLogger) CaptureState(env *EVM, pc uint64, op OpCode, gas, cost uint64
327324 if err != nil {
328325 fmt .Fprintf (t .out , "Error: %v\n " , err )
329326 }
330- return nil
331327}
332328
333- func (t * mdLogger ) CaptureFault (env * EVM , pc uint64 , op OpCode , gas , cost uint64 , memory * Memory , stack * Stack , contract * Contract , depth int , err error ) error {
334-
329+ func (t * mdLogger ) CaptureFault (env * EVM , pc uint64 , op OpCode , gas , cost uint64 , scope * ScopeContext , depth int , err error ) {
335330 fmt .Fprintf (t .out , "\n Error: at pc=%d, op=%v: %v\n " , pc , op , err )
336-
337- return nil
338331}
339332
340- func (t * mdLogger ) CaptureEnd (output []byte , gasUsed uint64 , tm time.Duration , err error ) error {
333+ func (t * mdLogger ) CaptureEnd (output []byte , gasUsed uint64 , tm time.Duration , err error ) {
341334 fmt .Fprintf (t .out , "\n Output: `0x%x`\n Consumed gas: `%d`\n Error: `%v`\n " ,
342335 output , gasUsed , err )
343- return nil
344336}
0 commit comments