logger

package
v0.0.0-...-1f8a15b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 12, 2023 License: GPL-3.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrTraceLimitReached = errors.New("the number of logs reached the specified limit")

Functions

func NewMarkdownLogger

func NewMarkdownLogger(cfg *LogConfig, writer io.Writer) *mdLogger

NewMarkdownLogger creates a logger which outputs information in a format adapted for human readability, and is also a valid markdown table

func WriteLogs

func WriteLogs(writer io.Writer, logs []*types.Log)

WriteLogs writes vm logs in a readable format to the given writer

func WriteTrace

func WriteTrace(writer io.Writer, logs []StructLog)

WriteTrace writes a formatted trace to the given writer

Types

type AccessListTracer

type AccessListTracer struct {
	// contains filtered or unexported fields
}

AccessListTracer is a tracer that accumulates touched accounts and storage slots into an internal set.

func NewAccessListTracer

func NewAccessListTracer(acl types2.AccessList, exclude map[libcommon.Address]struct{}, state evmtypes.IntraBlockState) *AccessListTracer

NewAccessListTracer creates a new tracer that can generate AccessLists. An optional AccessList can be specified to occupy slots and addresses in the resulting accesslist. An optional set of addresses to be excluded from the resulting accesslist can also be specified.

func (*AccessListTracer) AccessList

func (a *AccessListTracer) AccessList() types2.AccessList

AccessList returns the current accesslist maintained by the tracer.

func (*AccessListTracer) AccessListSorted

func (a *AccessListTracer) AccessListSorted() types2.AccessList

AccessList returns the current accesslist maintained by the tracer.

func (*AccessListTracer) CaptureEnd

func (*AccessListTracer) CaptureEnd(output []byte, usedGas uint64, err error)

func (*AccessListTracer) CaptureEnter

func (a *AccessListTracer) CaptureEnter(typ vm.OpCode, from libcommon.Address, to libcommon.Address, precompile bool, create bool, input []byte, gas uint64, value *uint256.Int, code []byte)

func (*AccessListTracer) CaptureExit

func (*AccessListTracer) CaptureExit(output []byte, usedGas uint64, err error)

func (*AccessListTracer) CaptureFault

func (*AccessListTracer) CaptureFault(pc uint64, op vm.OpCode, gas, cost uint64, scope *vm.ScopeContext, depth int, err error)

func (*AccessListTracer) CaptureStart

func (a *AccessListTracer) CaptureStart(env *vm.EVM, from libcommon.Address, to libcommon.Address, precompile bool, create bool, input []byte, gas uint64, value *uint256.Int, code []byte)

func (*AccessListTracer) CaptureState

func (a *AccessListTracer) CaptureState(pc uint64, op vm.OpCode, gas, cost uint64, scope *vm.ScopeContext, rData []byte, depth int, err error)

CaptureState captures all opcodes that touch storage or addresses and adds them to the accesslist.

func (*AccessListTracer) CaptureTxEnd

func (a *AccessListTracer) CaptureTxEnd(restGas uint64)

func (*AccessListTracer) CaptureTxStart

func (a *AccessListTracer) CaptureTxStart(gasLimit uint64)

func (*AccessListTracer) CreatedContracts

func (a *AccessListTracer) CreatedContracts() map[libcommon.Address]struct{}

CreatedContracts returns the set of all addresses of contracts created during tx execution.

func (*AccessListTracer) Equal

func (a *AccessListTracer) Equal(other *AccessListTracer) bool

Equal returns if the content of two access list traces are equal.

func (*AccessListTracer) UsedBeforeCreation

func (a *AccessListTracer) UsedBeforeCreation(addr libcommon.Address) bool

UsedBeforeCreation returns for a given address whether it was first used before creation.

type JSONLogger

type JSONLogger struct {
	// contains filtered or unexported fields
}

func NewJSONLogger

func NewJSONLogger(cfg *LogConfig, writer io.Writer) *JSONLogger

NewJSONLogger creates a new EVM tracer that prints execution steps as JSON objects into the provided stream.

func (*JSONLogger) CaptureEnd

func (l *JSONLogger) CaptureEnd(output []byte, usedGas uint64, err error)

CaptureEnd is triggered at end of execution.

func (*JSONLogger) CaptureEnter

func (l *JSONLogger) CaptureEnter(typ vm.OpCode, from libcommon.Address, to libcommon.Address, precompile bool, create bool, input []byte, gas uint64, value *uint256.Int, code []byte)

func (*JSONLogger) CaptureExit

func (l *JSONLogger) CaptureExit(output []byte, usedGas uint64, err error)

func (*JSONLogger) CaptureFault

func (l *JSONLogger) CaptureFault(pc uint64, op vm.OpCode, gas, cost uint64, scope *vm.ScopeContext, depth int, err error)

CaptureFault outputs state information on the logger.

func (*JSONLogger) CaptureStart

func (l *JSONLogger) CaptureStart(env *vm.EVM, from libcommon.Address, to libcommon.Address, precompile bool, create bool, input []byte, gas uint64, value *uint256.Int, code []byte)

func (*JSONLogger) CaptureState

func (l *JSONLogger) CaptureState(pc uint64, op vm.OpCode, gas, cost uint64, scope *vm.ScopeContext, rData []byte, depth int, err error)

CaptureState outputs state information on the logger.

func (*JSONLogger) CaptureTxEnd

func (l *JSONLogger) CaptureTxEnd(restGas uint64)

func (*JSONLogger) CaptureTxStart

func (l *JSONLogger) CaptureTxStart(gasLimit uint64)

type JsonStreamLogger

type JsonStreamLogger struct {
	// contains filtered or unexported fields
}

JsonStreamLogger is an EVM state logger and implements Tracer.

JsonStreamLogger can capture state based on the given Log configuration and also keeps a track record of modified storage which is used in reporting snapshots of the contract their storage.

func NewJsonStreamLogger

func NewJsonStreamLogger(cfg *LogConfig, ctx context.Context, stream *jsoniter.Stream) *JsonStreamLogger

NewStructLogger returns a new logger

func (*JsonStreamLogger) CaptureEnd

func (l *JsonStreamLogger) CaptureEnd(output []byte, usedGas uint64, err error)

CaptureEnd is called after the call finishes to finalize the tracing.

func (*JsonStreamLogger) CaptureEnter

func (l *JsonStreamLogger) CaptureEnter(typ vm.OpCode, from libcommon.Address, to libcommon.Address, precompile bool, create bool, input []byte, gas uint64, value *uint256.Int, code []byte)

func (*JsonStreamLogger) CaptureExit

func (l *JsonStreamLogger) CaptureExit(output []byte, usedGas uint64, err error)

func (*JsonStreamLogger) CaptureFault

func (l *JsonStreamLogger) CaptureFault(pc uint64, op vm.OpCode, gas, cost uint64, scope *vm.ScopeContext, depth int, err error)

CaptureFault implements the Tracer interface to trace an execution fault while running an opcode.

func (*JsonStreamLogger) CaptureStart

func (l *JsonStreamLogger) CaptureStart(env *vm.EVM, from libcommon.Address, to libcommon.Address, precompile bool, create bool, input []byte, gas uint64, value *uint256.Int, code []byte)

CaptureStart implements the Tracer interface to initialize the tracing operation.

func (*JsonStreamLogger) CaptureState

func (l *JsonStreamLogger) CaptureState(pc uint64, op vm.OpCode, gas, cost uint64, scope *vm.ScopeContext, rData []byte, depth int, err error)

CaptureState logs a new structured log message and pushes it out to the environment

CaptureState also tracks SLOAD/SSTORE ops to track storage change.

func (*JsonStreamLogger) CaptureTxEnd

func (l *JsonStreamLogger) CaptureTxEnd(restGas uint64)

func (*JsonStreamLogger) CaptureTxStart

func (l *JsonStreamLogger) CaptureTxStart(gasLimit uint64)

type LogConfig

type LogConfig struct {
	DisableMemory     bool // disable memory capture
	DisableStack      bool // disable stack capture
	DisableStorage    bool // disable storage capture
	DisableReturnData bool // disable return data capture
	Debug             bool // print output during capture end
	Limit             int  // maximum length of output, but zero means unlimited
	// Chain overrides, can be used to execute a trace using future fork rules
	Overrides *chain.Config `json:"overrides,omitempty"`
}

LogConfig are the configuration options for structured logger the EVM

type Storage

type Storage map[libcommon.Hash]libcommon.Hash

Storage represents a contract's storage.

func (Storage) Copy

func (s Storage) Copy() Storage

Copy duplicates the current storage.

type StructLog

type StructLog struct {
	Pc            uint64                            `json:"pc"`
	Op            vm.OpCode                         `json:"op"`
	Gas           uint64                            `json:"gas"`
	GasCost       uint64                            `json:"gasCost"`
	Memory        []byte                            `json:"memory"`
	MemorySize    int                               `json:"memSize"`
	Stack         []*big.Int                        `json:"stack"`
	ReturnData    []byte                            `json:"returnData"`
	Storage       map[libcommon.Hash]libcommon.Hash `json:"-"`
	Depth         int                               `json:"depth"`
	RefundCounter uint64                            `json:"refund"`
	Err           error                             `json:"-"`
}

StructLog is emitted to the EVM each cycle and lists information about the current internal state prior to the execution of the statement.

func (*StructLog) ErrorString

func (s *StructLog) ErrorString() string

ErrorString formats the log's error as a string.

func (StructLog) MarshalJSON

func (s StructLog) MarshalJSON() ([]byte, error)

MarshalJSON marshals as JSON.

func (*StructLog) OpName

func (s *StructLog) OpName() string

OpName formats the operand name in a human-readable format.

func (*StructLog) UnmarshalJSON

func (s *StructLog) UnmarshalJSON(input []byte) error

UnmarshalJSON unmarshals from JSON.

type StructLogRes

type StructLogRes struct {
	Pc      uint64             `json:"pc"`
	Op      string             `json:"op"`
	Gas     uint64             `json:"gas"`
	GasCost uint64             `json:"gasCost"`
	Depth   int                `json:"depth"`
	Error   error              `json:"error,omitempty"`
	Stack   *[]string          `json:"stack,omitempty"`
	Memory  *[]string          `json:"memory,omitempty"`
	Storage *map[string]string `json:"storage,omitempty"`
}

StructLogRes stores a structured log emitted by the EVM while replaying a transaction in debug mode

func FormatLogs

func FormatLogs(logs []StructLog) []StructLogRes

FormatLogs formats EVM returned structured logs for json output

type StructLogger

type StructLogger struct {
	// contains filtered or unexported fields
}

StructLogger is an EVM state logger and implements Tracer.

StructLogger can capture state based on the given Log configuration and also keeps a track record of modified storage which is used in reporting snapshots of the contract their storage.

func NewStructLogger

func NewStructLogger(cfg *LogConfig) *StructLogger

NewStructLogger returns a new logger

func (*StructLogger) CaptureEnd

func (l *StructLogger) CaptureEnd(output []byte, usedGas uint64, err error)

CaptureEnd is called after the call finishes to finalize the tracing.

func (*StructLogger) CaptureEnter

func (l *StructLogger) CaptureEnter(typ vm.OpCode, from libcommon.Address, to libcommon.Address, precompile bool, create bool, input []byte, gas uint64, value *uint256.Int, code []byte)

CaptureEnter implements the Tracer interface to initialize the tracing operation for an internal call.

func (*StructLogger) CaptureExit

func (l *StructLogger) CaptureExit(output []byte, usedGas uint64, err error)

CaptureExit is called after the internal call finishes to finalize the tracing.

func (*StructLogger) CaptureFault

func (l *StructLogger) CaptureFault(pc uint64, op vm.OpCode, gas, cost uint64, scope *vm.ScopeContext, depth int, err error)

CaptureFault implements the Tracer interface to trace an execution fault while running an opcode.

func (*StructLogger) CaptureStart

func (l *StructLogger) CaptureStart(env *vm.EVM, from libcommon.Address, to libcommon.Address, precompile bool, create bool, input []byte, gas uint64, value *uint256.Int, code []byte)

CaptureStart implements the Tracer interface to initialize the tracing operation.

func (*StructLogger) CaptureState

func (l *StructLogger) CaptureState(pc uint64, op vm.OpCode, gas, cost uint64, scope *vm.ScopeContext, rData []byte, depth int, err error)

CaptureState logs a new structured log message and pushes it out to the environment

CaptureState also tracks SLOAD/SSTORE ops to track storage change.

func (*StructLogger) CaptureTxEnd

func (l *StructLogger) CaptureTxEnd(restGas uint64)

func (*StructLogger) CaptureTxStart

func (l *StructLogger) CaptureTxStart(gasLimit uint64)

func (*StructLogger) Error

func (l *StructLogger) Error() error

Error returns the VM error captured by the trace.

func (*StructLogger) Flush

func (l *StructLogger) Flush(tx types.Transaction)

func (*StructLogger) Output

func (l *StructLogger) Output() []byte

Output returns the VM return value captured by the trace.

func (*StructLogger) StructLogs

func (l *StructLogger) StructLogs() []StructLog

StructLogs returns the captured log entries.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL