Skip to content
40 changes: 10 additions & 30 deletions core/vm/interpreter.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,13 +208,11 @@ func (in *EVMInterpreter) Run(contract *Contract, input []byte, readOnly bool) (
pc = uint64(0) // program counter
cost uint64
// copies used by tracer
pcCopy uint64 // needed for the deferred EVMLogger
gasCopy uint64 // for EVMLogger to log gas remaining before execution
logged bool // deferred EVMLogger should ignore already logged steps
loggedLiveTracer bool // deferred LiveTracer should ignore already logged steps
res []byte // result of the opcode execution function
debug = in.evm.Config.Tracer != nil
debugLiveTracer = in.evm.Config.LiveTracer != nil
pcCopy uint64 // needed for the deferred EVMLogger
gasCopy uint64 // for EVMLogger to log gas remaining before execution
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we remove struct EVMLogger ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#91
Nice catch, please review

logged bool // deferred LiveTracer should ignore already logged steps
res []byte // result of the opcode execution function
debug = in.evm.Config.LiveTracer != nil
)
// Don't move this deferrred function, it's placed before the capturestate-deferred method,
// so that it get's executed _after_: the capturestate needs the stacks before
Expand All @@ -224,28 +222,15 @@ func (in *EVMInterpreter) Run(contract *Contract, input []byte, readOnly bool) (
}()
contract.Input = input

// TODO: remove old tracer
if debug {
defer func() {
if err != nil {
if !logged {
in.cfg.Tracer.CaptureState(pcCopy, op, gasCopy, cost, callContext, in.returnData, in.evm.depth, err)
} else {
in.cfg.Tracer.CaptureFault(pcCopy, op, gasCopy, cost, callContext, in.evm.depth, err)
}
}
}()
}

if debugLiveTracer {
defer func() {
if err == nil {
return
}
if !loggedLiveTracer && in.evm.Config.LiveTracer.OnOpcode != nil {
if !logged && in.evm.Config.LiveTracer.OnOpcode != nil {
in.evm.Config.LiveTracer.OnOpcode(pcCopy, byte(op), gasCopy, cost, callContext, in.returnData, in.evm.depth, VMErrorFromErr(err))
}
if loggedLiveTracer && in.evm.Config.LiveTracer.OnFault != nil {
if logged && in.evm.Config.LiveTracer.OnFault != nil {
in.evm.Config.LiveTracer.OnFault(pcCopy, byte(op), gasCopy, cost, callContext, in.evm.depth, VMErrorFromErr(err))
}
}()
Expand All @@ -262,7 +247,7 @@ func (in *EVMInterpreter) Run(contract *Contract, input []byte, readOnly bool) (
}
if debug {
// Capture pre-execution values for tracing.
logged, loggedLiveTracer, pcCopy, gasCopy = false, false, pc, contract.Gas
logged, logged, pcCopy, gasCopy = false, false, pc, contract.Gas
}

// Get the operation from the jump table and validate the stack to ensure there are
Expand Down Expand Up @@ -326,24 +311,19 @@ func (in *EVMInterpreter) Run(contract *Contract, input []byte, readOnly bool) (
}

// Do tracing before memory expansion
if debugLiveTracer {
if debug {
if in.evm.Config.LiveTracer.OnGasChange != nil {
in.evm.Config.LiveTracer.OnGasChange(gasCopy, gasCopy-cost, tracing.GasChangeCallOpCode)
}
if in.evm.Config.LiveTracer.OnOpcode != nil {
in.evm.Config.LiveTracer.OnOpcode(pc, byte(op), gasCopy, cost, callContext, in.returnData, in.evm.depth, VMErrorFromErr(err))
loggedLiveTracer = true
logged = true
}
}
if memorySize > 0 {
mem.Resize(memorySize)
}

if debug {
in.cfg.Tracer.CaptureState(pc, op, gasCopy, cost, callContext, in.returnData, in.evm.depth, err)
logged = true
}

// execute the operation
res, err = operation.execute(&pc, in, callContext)
// if the operation clears the return data (e.g. it has returning data)
Expand Down