eth/tracers, core: update OpcodeHook to pass Cancun fork status param

This commit is contained in:
Cedrick AHOUANGANSI 2025-02-06 02:24:54 +01:00
parent 9e33b29c74
commit fbb8b85aee
13 changed files with 21 additions and 21 deletions

View file

@ -128,9 +128,9 @@ func (l *fileWritingTracer) hooks() *tracing.Hooks {
l.inner.OnExit(depth, output, gasUsed, err, reverted) l.inner.OnExit(depth, output, gasUsed, err, reverted)
} }
}, },
OnOpcode: func(pc uint64, op byte, gas, cost uint64, scope tracing.OpContext, rData []byte, depth int, err error) { OnOpcode: func(pc uint64, op byte, gas, cost uint64, scope tracing.OpContext, rData []byte, depth int, isCancun bool, err error) {
if l.inner != nil && l.inner.OnOpcode != nil { if l.inner != nil && l.inner.OnOpcode != nil {
l.inner.OnOpcode(pc, op, gas, cost, scope, rData, depth, err) l.inner.OnOpcode(pc, op, gas, cost, scope, rData, depth, isCancun, err)
} }
}, },
OnFault: func(pc uint64, op byte, gas, cost uint64, scope tracing.OpContext, depth int, err error) { OnFault: func(pc uint64, op byte, gas, cost uint64, scope tracing.OpContext, depth int, err error) {

View file

@ -108,7 +108,7 @@ type (
ExitHook = func(depth int, output []byte, gasUsed uint64, err error, reverted bool) ExitHook = func(depth int, output []byte, gasUsed uint64, err error, reverted bool)
// OpcodeHook is invoked just prior to the execution of an opcode. // OpcodeHook is invoked just prior to the execution of an opcode.
OpcodeHook = func(pc uint64, op byte, gas, cost uint64, scope OpContext, rData []byte, depth int, err error) OpcodeHook = func(pc uint64, op byte, gas, cost uint64, scope OpContext, rData []byte, depth int, isCancun bool, err error)
// FaultHook is invoked when an error occurs during the execution of an opcode. // 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) FaultHook = func(pc uint64, op byte, gas, cost uint64, scope OpContext, depth int, err error)

View file

@ -216,7 +216,7 @@ func (in *EVMInterpreter) Run(contract *Contract, input []byte, readOnly bool) (
return return
} }
if !logged && in.evm.Config.Tracer.OnOpcode != nil { if !logged && in.evm.Config.Tracer.OnOpcode != nil {
in.evm.Config.Tracer.OnOpcode(pcCopy, byte(op), gasCopy, cost, callContext, in.returnData, in.evm.depth, VMErrorFromErr(err)) in.evm.Config.Tracer.OnOpcode(pcCopy, byte(op), gasCopy, cost, callContext, in.returnData, in.evm.depth, in.evm.chainConfig.IsCancun(in.evm.Context.BlockNumber, in.evm.Context.Time), VMErrorFromErr(err))
} }
if logged && in.evm.Config.Tracer.OnFault != nil { if logged && in.evm.Config.Tracer.OnFault != nil {
in.evm.Config.Tracer.OnFault(pcCopy, byte(op), gasCopy, cost, callContext, in.evm.depth, VMErrorFromErr(err)) in.evm.Config.Tracer.OnFault(pcCopy, byte(op), gasCopy, cost, callContext, in.evm.depth, VMErrorFromErr(err))
@ -298,7 +298,7 @@ func (in *EVMInterpreter) Run(contract *Contract, input []byte, readOnly bool) (
in.evm.Config.Tracer.OnGasChange(gasCopy, gasCopy-cost, tracing.GasChangeCallOpCode) in.evm.Config.Tracer.OnGasChange(gasCopy, gasCopy-cost, tracing.GasChangeCallOpCode)
} }
if in.evm.Config.Tracer.OnOpcode != nil { if in.evm.Config.Tracer.OnOpcode != nil {
in.evm.Config.Tracer.OnOpcode(pc, byte(op), gasCopy, cost, callContext, in.returnData, in.evm.depth, VMErrorFromErr(err)) in.evm.Config.Tracer.OnOpcode(pcCopy, byte(op), gasCopy, cost, callContext, in.returnData, in.evm.depth, in.evm.chainConfig.IsCancun(in.evm.Context.BlockNumber, in.evm.Context.Time), VMErrorFromErr(err))
logged = true logged = true
} }
} }

View file

@ -680,7 +680,7 @@ func TestColdAccountAccessCost(t *testing.T) {
Execute(tc.code, nil, &Config{ Execute(tc.code, nil, &Config{
EVMConfig: vm.Config{ EVMConfig: vm.Config{
Tracer: &tracing.Hooks{ Tracer: &tracing.Hooks{
OnOpcode: func(pc uint64, op byte, gas, cost uint64, scope tracing.OpContext, rData []byte, depth int, err error) { OnOpcode: func(pc uint64, op byte, gas, cost uint64, scope tracing.OpContext, rData []byte, depth int, isCancun bool, err error) {
// Uncomment to investigate failures: // Uncomment to investigate failures:
//t.Logf("%d: %v %d", step, vm.OpCode(op).String(), cost) //t.Logf("%d: %v %d", step, vm.OpCode(op).String(), cost)
if step == tc.step { if step == tc.step {
@ -934,7 +934,7 @@ func TestDelegatedAccountAccessCost(t *testing.T) {
State: statedb, State: statedb,
EVMConfig: vm.Config{ EVMConfig: vm.Config{
Tracer: &tracing.Hooks{ Tracer: &tracing.Hooks{
OnOpcode: func(pc uint64, op byte, gas, cost uint64, scope tracing.OpContext, rData []byte, depth int, err error) { OnOpcode: func(pc uint64, op byte, gas, cost uint64, scope tracing.OpContext, rData []byte, depth int, isCancun bool, err error) {
// Uncomment to investigate failures: // Uncomment to investigate failures:
t.Logf("%d: %v %d", step, vm.OpCode(op).String(), cost) t.Logf("%d: %v %d", step, vm.OpCode(op).String(), cost)
if step == tc.step { if step == tc.step {

View file

@ -329,7 +329,7 @@ func (t *jsTracer) onStart(from common.Address, to common.Address, create bool,
} }
// OnOpcode implements the Tracer interface to trace a single step of VM execution. // OnOpcode implements the Tracer interface to trace a single step of VM execution.
func (t *jsTracer) OnOpcode(pc uint64, op byte, gas, cost uint64, scope tracing.OpContext, rData []byte, depth int, err error) { func (t *jsTracer) OnOpcode(pc uint64, op byte, gas, cost uint64, scope tracing.OpContext, rData []byte, depth int, isCancun bool, err error) {
if !t.traceStep { if !t.traceStep {
return return
} }

View file

@ -196,10 +196,10 @@ func TestHaltBetweenSteps(t *testing.T) {
evm.SetTxContext(vm.TxContext{GasPrice: big.NewInt(1)}) evm.SetTxContext(vm.TxContext{GasPrice: big.NewInt(1)})
tracer.OnTxStart(evm.GetVMContext(), types.NewTx(&types.LegacyTx{}), common.Address{}) tracer.OnTxStart(evm.GetVMContext(), types.NewTx(&types.LegacyTx{}), common.Address{})
tracer.OnEnter(0, byte(vm.CALL), common.Address{}, common.Address{}, []byte{}, 0, big.NewInt(0)) tracer.OnEnter(0, byte(vm.CALL), common.Address{}, common.Address{}, []byte{}, 0, big.NewInt(0))
tracer.OnOpcode(0, 0, 0, 0, scope, nil, 0, nil) tracer.OnOpcode(0, 0, 0, 0, scope, nil, 0, true, nil)
timeout := errors.New("stahp") timeout := errors.New("stahp")
tracer.Stop(timeout) tracer.Stop(timeout)
tracer.OnOpcode(0, 0, 0, 0, scope, nil, 0, nil) tracer.OnOpcode(0, 0, 0, 0, scope, nil, 0, true, nil)
if _, err := tracer.GetResult(); !strings.Contains(err.Error(), timeout.Error()) { if _, err := tracer.GetResult(); !strings.Contains(err.Error(), timeout.Error()) {
t.Errorf("Expected timeout error, got %v", err) t.Errorf("Expected timeout error, got %v", err)

View file

@ -61,7 +61,7 @@ func newNoopTracer(_ json.RawMessage) (*tracing.Hooks, error) {
}, nil }, nil
} }
func (t *noop) OnOpcode(pc uint64, op byte, gas, cost uint64, scope tracing.OpContext, rData []byte, depth int, err error) { func (t *noop) OnOpcode(pc uint64, op byte, gas, cost uint64, scope tracing.OpContext, rData []byte, depth int, isCancun bool, err error) {
} }
func (t *noop) OnFault(pc uint64, op byte, gas, cost uint64, _ tracing.OpContext, depth int, err error) { func (t *noop) OnFault(pc uint64, op byte, gas, cost uint64, _ tracing.OpContext, depth int, err error) {

View file

@ -132,7 +132,7 @@ func (a *AccessListTracer) Hooks() *tracing.Hooks {
} }
// OnOpcode captures all opcodes that touch storage or addresses and adds them to the accesslist. // OnOpcode captures all opcodes that touch storage or addresses and adds them to the accesslist.
func (a *AccessListTracer) OnOpcode(pc uint64, opcode byte, gas, cost uint64, scope tracing.OpContext, rData []byte, depth int, err error) { func (a *AccessListTracer) OnOpcode(pc uint64, opcode byte, gas, cost uint64, scope tracing.OpContext, rData []byte, depth int, isCancun bool, err error) {
stackData := scope.StackData() stackData := scope.StackData()
stackLen := len(stackData) stackLen := len(stackData)
op := vm.OpCode(opcode) op := vm.OpCode(opcode)

View file

@ -254,7 +254,7 @@ func (l *StructLogger) Hooks() *tracing.Hooks {
// OnOpcode logs a new structured log message and pushes it out to the environment // OnOpcode logs a new structured log message and pushes it out to the environment
// //
// OnOpcode also tracks SLOAD/SSTORE ops to track storage change. // OnOpcode also tracks SLOAD/SSTORE ops to track storage change.
func (l *StructLogger) OnOpcode(pc uint64, opcode byte, gas, cost uint64, scope tracing.OpContext, rData []byte, depth int, err error) { func (l *StructLogger) OnOpcode(pc uint64, opcode byte, gas, cost uint64, scope tracing.OpContext, rData []byte, depth int, isCancun bool, err error) {
// If tracing was interrupted, exit // If tracing was interrupted, exit
if l.interrupt.Load() { if l.interrupt.Load() {
return return
@ -491,7 +491,7 @@ func (t *mdLogger) OnExit(depth int, output []byte, gasUsed uint64, err error, r
} }
// OnOpcode also tracks SLOAD/SSTORE ops to track storage change. // OnOpcode also tracks SLOAD/SSTORE ops to track storage change.
func (t *mdLogger) OnOpcode(pc uint64, op byte, gas, cost uint64, scope tracing.OpContext, rData []byte, depth int, err error) { func (t *mdLogger) OnOpcode(pc uint64, op byte, gas, cost uint64, scope tracing.OpContext, rData []byte, depth int, isCancun bool, err error) {
if t.skip { if t.skip {
return return
} }

View file

@ -97,11 +97,11 @@ func NewJSONLoggerWithCallFrames(cfg *Config, writer io.Writer) *tracing.Hooks {
} }
func (l *jsonLogger) OnFault(pc uint64, op byte, gas uint64, cost uint64, scope tracing.OpContext, depth int, err error) { 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 // TODO: Add rData and Cancun status to this interface as well
l.OnOpcode(pc, op, gas, cost, scope, nil, depth, err) l.OnOpcode(pc, op, gas, cost, scope, nil, depth, true, err)
} }
func (l *jsonLogger) OnOpcode(pc uint64, op byte, gas, cost uint64, scope tracing.OpContext, rData []byte, depth int, err error) { func (l *jsonLogger) OnOpcode(pc uint64, op byte, gas, cost uint64, scope tracing.OpContext, rData []byte, depth int, isCancun bool, err error) {
memory := scope.MemoryData() memory := scope.MemoryData()
stack := scope.StackData() stack := scope.StackData()

View file

@ -76,10 +76,10 @@ func newMuxTracer(ctx *tracers.Context, cfg json.RawMessage, chainConfig *params
}, nil }, nil
} }
func (t *muxTracer) OnOpcode(pc uint64, op byte, gas, cost uint64, scope tracing.OpContext, rData []byte, depth int, err error) { func (t *muxTracer) OnOpcode(pc uint64, op byte, gas, cost uint64, scope tracing.OpContext, rData []byte, depth int, isCancun bool, err error) {
for _, t := range t.tracers { for _, t := range t.tracers {
if t.OnOpcode != nil { if t.OnOpcode != nil {
t.OnOpcode(pc, op, gas, cost, scope, rData, depth, err) t.OnOpcode(pc, op, gas, cost, scope, rData, depth, isCancun, err)
} }
} }
} }

View file

@ -58,7 +58,7 @@ func newNoopTracer(ctx *tracers.Context, cfg json.RawMessage, chainConfig *param
}, nil }, nil
} }
func (t *noopTracer) OnOpcode(pc uint64, op byte, gas, cost uint64, scope tracing.OpContext, rData []byte, depth int, err error) { func (t *noopTracer) OnOpcode(pc uint64, op byte, gas, cost uint64, scope tracing.OpContext, rData []byte, depth int, isCancun bool, err error) {
} }
func (t *noopTracer) OnFault(pc uint64, op byte, gas, cost uint64, _ tracing.OpContext, depth int, err error) { func (t *noopTracer) OnFault(pc uint64, op byte, gas, cost uint64, _ tracing.OpContext, depth int, err error) {

View file

@ -101,7 +101,7 @@ func newPrestateTracer(ctx *tracers.Context, cfg json.RawMessage, chainConfig *p
} }
// OnOpcode implements the EVMLogger interface to trace a single step of VM execution. // OnOpcode implements the EVMLogger interface to trace a single step of VM execution.
func (t *prestateTracer) OnOpcode(pc uint64, opcode byte, gas, cost uint64, scope tracing.OpContext, rData []byte, depth int, err error) { func (t *prestateTracer) OnOpcode(pc uint64, opcode byte, gas, cost uint64, scope tracing.OpContext, rData []byte, depth int, isCancun bool, err error) {
if err != nil { if err != nil {
return return
} }