Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions cmd/evm/internal/t8ntool/file_tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,15 @@ func (l *fileWritingTracer) hooks() *tracing.Hooks {
l.inner.OnFault(pc, op, gas, cost, scope, depth, err)
}
},
OnFaultV2: func(pc uint64, op byte, gas, cost uint64, scope tracing.OpContext, rData []byte, depth int, err error) {
if l.inner != nil {
if l.inner.OnFaultV2 != nil {
l.inner.OnFaultV2(pc, op, gas, cost, scope, rData, depth, err)
} else if l.inner.OnFault != nil {
l.inner.OnFault(pc, op, gas, cost, scope, depth, err)
}
}
},
OnSystemCallStart: func() {
if l.inner != nil && l.inner.OnSystemCallStart != nil {
l.inner.OnSystemCallStart()
Expand Down
7 changes: 7 additions & 0 deletions core/tracing/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,12 @@ type (
// FaultHook is invoked when an error occurs during the execution of an opcode.
FaultHook = func(pc uint64, op byte, gas, cost uint64, scope OpContext, depth int, err error)

// FaultHookV2 is invoked when an error occurs during the execution of an opcode.
// It includes the return data (e.g. revert reason) available at the time of the fault.
// This mirrors the signature of OpcodeHook by including rData and allows tracers to
// capture revert data directly at fault time.
FaultHookV2 = func(pc uint64, op byte, gas, cost uint64, scope OpContext, rData []byte, depth int, err error)

// GasChangeHook is invoked when the gas changes.
GasChangeHook = func(old, new uint64, reason GasChangeReason)

Expand Down Expand Up @@ -198,6 +204,7 @@ type Hooks struct {
OnExit ExitHook
OnOpcode OpcodeHook
OnFault FaultHook
OnFaultV2 FaultHookV2
OnGasChange GasChangeHook
// Chain events
OnBlockchainInit BlockchainInitHook
Expand Down
8 changes: 6 additions & 2 deletions core/vm/interpreter.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,12 @@ func (evm *EVM) Run(contract *Contract, input []byte, readOnly bool) (ret []byte
if !logged && evm.Config.Tracer.OnOpcode != nil {
evm.Config.Tracer.OnOpcode(pcCopy, byte(op), gasCopy, cost, callContext, evm.returnData, evm.depth, VMErrorFromErr(err))
}
if logged && evm.Config.Tracer.OnFault != nil {
evm.Config.Tracer.OnFault(pcCopy, byte(op), gasCopy, cost, callContext, evm.depth, VMErrorFromErr(err))
if logged {
if evm.Config.Tracer.OnFaultV2 != nil {
evm.Config.Tracer.OnFaultV2(pcCopy, byte(op), gasCopy, cost, callContext, evm.returnData, evm.depth, VMErrorFromErr(err))
} else if evm.Config.Tracer.OnFault != nil {
evm.Config.Tracer.OnFault(pcCopy, byte(op), gasCopy, cost, callContext, evm.depth, VMErrorFromErr(err))
}
}
}()
}
Expand Down
7 changes: 6 additions & 1 deletion eth/tracers/logger/logger_json.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ func NewJSONLogger(cfg *Config, writer io.Writer) *tracing.Hooks {
OnExit: l.OnExit,
OnOpcode: l.OnOpcode,
OnFault: l.OnFault,
OnFaultV2: l.OnFaultV2,
}
return l.hooks
}
Expand All @@ -92,15 +93,19 @@ func NewJSONLoggerWithCallFrames(cfg *Config, writer io.Writer) *tracing.Hooks {
OnExit: l.OnExit,
OnOpcode: l.OnOpcode,
OnFault: l.OnFault,
OnFaultV2: l.OnFaultV2,
}
return l.hooks
}

func (l *jsonLogger) OnFault(pc uint64, op byte, gas uint64, cost uint64, scope tracing.OpContext, depth int, err error) {
// TODO: Add rData to this interface as well
l.OnOpcode(pc, op, gas, cost, scope, nil, depth, err)
}

func (l *jsonLogger) OnFaultV2(pc uint64, op byte, gas uint64, cost uint64, scope tracing.OpContext, rData []byte, depth int, err error) {
l.OnOpcode(pc, op, gas, cost, scope, rData, depth, err)
}

func (l *jsonLogger) OnOpcode(pc uint64, op byte, gas, cost uint64, scope tracing.OpContext, rData []byte, depth int, err error) {
memory := scope.MemoryData()
stack := scope.StackData()
Expand Down
11 changes: 11 additions & 0 deletions eth/tracers/native/mux.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ func newMuxTracer(ctx *tracers.Context, cfg json.RawMessage, chainConfig *params
OnExit: t.OnExit,
OnOpcode: t.OnOpcode,
OnFault: t.OnFault,
OnFaultV2: t.OnFaultV2,
OnGasChange: t.OnGasChange,
OnBalanceChange: t.OnBalanceChange,
OnNonceChange: t.OnNonceChange,
Expand Down Expand Up @@ -92,6 +93,16 @@ func (t *muxTracer) OnFault(pc uint64, op byte, gas, cost uint64, scope tracing.
}
}

func (t *muxTracer) OnFaultV2(pc uint64, op byte, gas, cost uint64, scope tracing.OpContext, rData []byte, depth int, err error) {
for _, t := range t.tracers {
if t.OnFaultV2 != nil {
t.OnFaultV2(pc, op, gas, cost, scope, rData, depth, err)
} else if t.OnFault != nil {
t.OnFault(pc, op, gas, cost, scope, depth, err)
}
}
}

func (t *muxTracer) OnGasChange(old, new uint64, reason tracing.GasChangeReason) {
for _, t := range t.tracers {
if t.OnGasChange != nil {
Expand Down