diff --git a/core/tracing/hooks.go b/core/tracing/hooks.go index 68bfb2fedc..d31d8e268c 100644 --- a/core/tracing/hooks.go +++ b/core/tracing/hooks.go @@ -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. diff --git a/core/vm/interpreter.go b/core/vm/interpreter.go index 5ba4e07623..c6c5e08600 100644 --- a/core/vm/interpreter.go +++ b/core/vm/interpreter.go @@ -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 diff --git a/eth/tracers/logger/logger.go b/eth/tracers/logger/logger.go index 596ee97146..6c9890d85b 100644 --- a/eth/tracers/logger/logger.go +++ b/eth/tracers/logger/logger.go @@ -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 }