core/tracing: add CodeSection and functionDepth to traces

This commit is contained in:
Marius van der Wijden 2025-02-19 18:00:54 +01:00
parent 1bb727ba75
commit a03d1cdc1c
3 changed files with 19 additions and 1 deletions

View file

@ -43,6 +43,8 @@ type OpContext interface {
CallValue() *uint256.Int
CallInput() []byte
ContractCode() []byte
CurrentCodeSection() uint64
ReturnStackDepth() uint64
}
// StateDB gives tracers access to the whole state.

View file

@ -93,6 +93,20 @@ func (ctx *ScopeContext) ContractCode() []byte {
return ctx.Contract.Code
}
// CodeSection returns the current code section of the contract being executed.
func (ctx *ScopeContext) CurrentCodeSection() uint64 {
return ctx.CodeSection
}
// ReturnStackDepth returns the depth of the return stack.
func (ctx *ScopeContext) ReturnStackDepth() uint64 {
if ctx.Contract.IsEOF() {
return uint64(ctx.ReturnStack.Len() + 1)
} else {
return 0
}
}
type ReturnStack []*ReturnContext
// Pop removes an element from the return stack

View file

@ -57,6 +57,7 @@ type Config struct {
// current internal state prior to the execution of the statement.
type StructLog struct {
Pc uint64 `json:"pc"`
Section uint64 `json:"section,omitempty"`
Op vm.OpCode `json:"op"`
Gas uint64 `json:"gas"`
GasCost uint64 `json:"gasCost"`
@ -66,6 +67,7 @@ type StructLog struct {
ReturnData []byte `json:"returnData,omitempty"`
Storage map[common.Hash]common.Hash `json:"-"`
Depth int `json:"depth"`
FunctionDepth uint64 `json:"functionDepth,omitempty"`
RefundCounter uint64 `json:"refund"`
Err error `json:"-"`
}
@ -274,7 +276,7 @@ func (l *StructLogger) OnOpcode(pc uint64, opcode byte, gas, cost uint64, scope
stack = scope.StackData()
stackLen = len(stack)
)
log := StructLog{pc, op, gas, cost, nil, len(memory), nil, nil, nil, depth, l.env.StateDB.GetRefund(), err}
log := StructLog{pc, scope.CurrentCodeSection(), op, gas, cost, nil, len(memory), nil, nil, nil, depth, scope.ReturnStackDepth(), l.env.StateDB.GetRefund(), err}
if l.cfg.EnableMemory {
log.Memory = memory
}