Documentation
¶
Index ¶
- func NewTxGasDimensionByOpcodeTracer(_ *tracers.Context, cfg json.RawMessage, chainConfig *params.ChainConfig) (*tracers.Tracer, error)
- func NewTxGasDimensionLogger(_ *tracers.Context, cfg json.RawMessage, chainConfig *params.ChainConfig) (*tracers.Tracer, error)
- func WasCallOrCreate(opcode vm.OpCode) bool
- type BaseExecutionResult
- type BaseGasDimensionTracer
- func (t *BaseGasDimensionTracer) AddToRootExecutionGasAccumulated(gas uint64)
- func (t *BaseGasDimensionTracer) Error() error
- func (t *BaseGasDimensionTracer) GetBaseExecutionResult() (BaseExecutionResult, error)
- func (t *BaseGasDimensionTracer) GetCallStack() CallGasDimensionStack
- func (t *BaseGasDimensionTracer) GetOpCount() uint64
- func (t *BaseGasDimensionTracer) GetOpRefund() uint64
- func (t *BaseGasDimensionTracer) GetPrecompileAddressList() []common.Address
- func (t *BaseGasDimensionTracer) GetPrevAccessList() (addresses map[common.Address]int, slots []map[common.Hash]struct{})
- func (t *BaseGasDimensionTracer) GetRefundAccumulated() uint64
- func (t *BaseGasDimensionTracer) GetRootIsPrecompile() bool
- func (t *BaseGasDimensionTracer) GetRootIsStylus() bool
- func (t *BaseGasDimensionTracer) GetStateDB() tracing.StateDB
- func (t *BaseGasDimensionTracer) OnOpcode(pc uint64, op byte, gas, cost uint64, scope tracing.OpContext, rData []byte, ...) error
- func (t *BaseGasDimensionTracer) OnTxEnd(receipt *types.Receipt, err error)
- func (t *BaseGasDimensionTracer) OnTxStart(env *tracing.VMContext, tx *types.Transaction, from common.Address)
- func (t *BaseGasDimensionTracer) Reason() error
- func (t *BaseGasDimensionTracer) SetRefundAccumulated(refund uint64)
- func (t *BaseGasDimensionTracer) Status() uint64
- func (t *BaseGasDimensionTracer) Stop(err error)
- type BaseGasDimensionTracerConfig
- type CalcGasDimensionFunc
- type CallGasDimensionInfo
- type CallGasDimensionStack
- type CallGasDimensionStackInfo
- type DimensionLog
- type DimensionLogRes
- type DimensionTracer
- type ExecutionResult
- type FinishCalcGasDimensionFunc
- type GasesByDimension
- type TracerErrorWithDimLogs
- type TxGasDimensionByOpcodeExecutionResult
- type TxGasDimensionByOpcodeTracer
- func (t *TxGasDimensionByOpcodeTracer) Error() error
- func (t *TxGasDimensionByOpcodeTracer) GetOpcodeDimensionSummary() map[string]GasesByDimension
- func (t *TxGasDimensionByOpcodeTracer) GetProtobufResult() ([]byte, error)
- func (t *TxGasDimensionByOpcodeTracer) GetResult() (json.RawMessage, error)
- func (t *TxGasDimensionByOpcodeTracer) OnFault(pc uint64, op byte, gas, cost uint64, scope tracing.OpContext, depth int, ...)
- func (t *TxGasDimensionByOpcodeTracer) OnOpcode(pc uint64, op byte, gas, cost uint64, scope tracing.OpContext, rData []byte, ...)
- type TxGasDimensionLogger
- func (t *TxGasDimensionLogger) DimensionLogs() []DimensionLog
- func (t *TxGasDimensionLogger) GetResult() (json.RawMessage, error)
- func (t *TxGasDimensionLogger) OnFault(pc uint64, op byte, gas, cost uint64, scope tracing.OpContext, depth int, ...)
- func (t *TxGasDimensionLogger) OnOpcode(pc uint64, op byte, gas, cost uint64, scope tracing.OpContext, rData []byte, ...)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewTxGasDimensionByOpcodeTracer ¶
func NewTxGasDimensionByOpcodeTracer( _ *tracers.Context, cfg json.RawMessage, chainConfig *params.ChainConfig, ) (*tracers.Tracer, error)
gasDimensionTracer returns a new tracer that traces gas usage for each opcode against the dimension of that opcode takes a context, and json input for configuration parameters
func NewTxGasDimensionLogger ¶
func NewTxGasDimensionLogger( _ *tracers.Context, cfg json.RawMessage, chainConfig *params.ChainConfig, ) (*tracers.Tracer, error)
gasDimensionTracer returns a new tracer that traces gas usage for each opcode against the dimension of that opcode takes a context, and json input for configuration parameters
func WasCallOrCreate ¶
WasCallOrCreate returns true if the opcode is a type of opcode that makes calls increasing the stack depth
Types ¶
type BaseExecutionResult ¶
type BaseExecutionResult struct { GasUsed uint64 `json:"gasUsed"` GasUsedForL1 uint64 `json:"gasUsedForL1"` GasUsedForL2 uint64 `json:"gasUsedForL2"` IntrinsicGas uint64 `json:"intrinsicGas"` AdjustedRefund uint64 `json:"adjustedRefund"` RootIsPrecompile bool `json:"rootIsPrecompile"` RootIsPrecompileAdjustment uint64 `json:"rootIsPrecompileAdjustment"` RootIsStylus bool `json:"rootIsStylus"` RootIsStylusAdjustment uint64 `json:"rootIsStylusAdjustment"` Failed bool `json:"failed"` TxHash string `json:"txHash"` BlockTimestamp uint64 `json:"blockTimestamp"` BlockNumber *big.Int `json:"blockNumber"` Status uint64 `json:"status"` }
BaseExecutionResult has shared fields for execution results
type BaseGasDimensionTracer ¶
type BaseGasDimensionTracer struct {
// contains filtered or unexported fields
}
BaseGasDimensionTracer contains the shared functionality between different gas dimension tracers
func NewBaseGasDimensionTracer ¶
func NewBaseGasDimensionTracer(cfg json.RawMessage, chainConfig *params.ChainConfig) (*BaseGasDimensionTracer, error)
create a new base gas dimension tracer
func (*BaseGasDimensionTracer) AddToRootExecutionGasAccumulated ¶
func (t *BaseGasDimensionTracer) AddToRootExecutionGasAccumulated(gas uint64)
Add to the execution gas accumulated, for tracking adjusted refund
func (*BaseGasDimensionTracer) Error ¶
func (t *BaseGasDimensionTracer) Error() error
Error returns the EVM execution error captured by the trace
func (*BaseGasDimensionTracer) GetBaseExecutionResult ¶
func (t *BaseGasDimensionTracer) GetBaseExecutionResult() (BaseExecutionResult, error)
get the result of the transaction execution that we will hand to the json output
func (*BaseGasDimensionTracer) GetCallStack ¶
func (t *BaseGasDimensionTracer) GetCallStack() CallGasDimensionStack
GetCallStack returns the call stack
func (*BaseGasDimensionTracer) GetOpCount ¶
func (t *BaseGasDimensionTracer) GetOpCount() uint64
GetOpCount returns the op count
func (*BaseGasDimensionTracer) GetOpRefund ¶
func (t *BaseGasDimensionTracer) GetOpRefund() uint64
GetOpRefund returns the current op refund
func (*BaseGasDimensionTracer) GetPrecompileAddressList ¶
func (t *BaseGasDimensionTracer) GetPrecompileAddressList() []common.Address
GetPrecompileAddressList returns the list of precompile addresses
func (*BaseGasDimensionTracer) GetPrevAccessList ¶
func (t *BaseGasDimensionTracer) GetPrevAccessList() (addresses map[common.Address]int, slots []map[common.Hash]struct{})
GetPrevAccessList returns the previous access list
func (*BaseGasDimensionTracer) GetRefundAccumulated ¶
func (t *BaseGasDimensionTracer) GetRefundAccumulated() uint64
GetRefundAccumulated returns the accumulated refund
func (*BaseGasDimensionTracer) GetRootIsPrecompile ¶
func (t *BaseGasDimensionTracer) GetRootIsPrecompile() bool
GetRootIsPrecompile returns whether the root of the call stack is a precompile
func (*BaseGasDimensionTracer) GetRootIsStylus ¶
func (t *BaseGasDimensionTracer) GetRootIsStylus() bool
GetRootIsStylus returns whether the root of the call stack is a stylus contract
func (*BaseGasDimensionTracer) GetStateDB ¶
func (t *BaseGasDimensionTracer) GetStateDB() tracing.StateDB
GetStateDB returns the state database
func (*BaseGasDimensionTracer) OnOpcode ¶
func (t *BaseGasDimensionTracer) OnOpcode( pc uint64, op byte, gas, cost uint64, scope tracing.OpContext, rData []byte, depth int, err error, ) error
OnOpcode handles the shared opcode execution logic since this is so sensitive, we supply helper methods for different parts of the logic but expect child tracers to implement their own specific logic in their own OnOpcode method
func (*BaseGasDimensionTracer) OnTxEnd ¶
func (t *BaseGasDimensionTracer) OnTxEnd(receipt *types.Receipt, err error)
OnTxEnd handles transaction end
func (*BaseGasDimensionTracer) OnTxStart ¶
func (t *BaseGasDimensionTracer) OnTxStart(env *tracing.VMContext, tx *types.Transaction, from common.Address)
OnTxStart handles transaction start
func (*BaseGasDimensionTracer) Reason ¶
func (t *BaseGasDimensionTracer) Reason() error
Reason returns any errors that occurred in the tracer itself
func (*BaseGasDimensionTracer) SetRefundAccumulated ¶
func (t *BaseGasDimensionTracer) SetRefundAccumulated(refund uint64)
SetRefundAccumulated sets the accumulated refund
func (*BaseGasDimensionTracer) Status ¶
func (t *BaseGasDimensionTracer) Status() uint64
Status returns the status of the transaction, e.g. 0 for failure, 1 for success a transaction can revert, fail, and still be mined and included in a block
func (*BaseGasDimensionTracer) Stop ¶
func (t *BaseGasDimensionTracer) Stop(err error)
Stop signals the tracer to stop tracing
type BaseGasDimensionTracerConfig ¶
type BaseGasDimensionTracerConfig struct {
Debug bool
}
BaseGasDimensionTracerConfig is the configuration for the base gas dimension tracer
type CalcGasDimensionFunc ¶
type CalcGasDimensionFunc func( t DimensionTracer, pc uint64, op byte, gas, cost uint64, scope tracing.OpContext, rData []byte, depth int, err error, ) (GasesByDimension, *CallGasDimensionInfo, error)
calcGasDimensionFunc defines a type signature that takes the opcode tracing data for an opcode and return the gas consumption for each dimension for that given opcode.
INVARIANT (for non-call opcodes): the sum of the gas consumption for each dimension equals the input `gas` to this function
func GetCalcGasDimensionFunc ¶
func GetCalcGasDimensionFunc(op vm.OpCode) CalcGasDimensionFunc
getCalcGasDimensionFunc is a massive case switch statement that returns which function to call based on which opcode is being traced/executed
type CallGasDimensionInfo ¶
type CallGasDimensionInfo struct { Pc uint64 Op vm.OpCode GasCounterAtTimeOfCall uint64 MemoryExpansionCost uint64 AccessListComputationCost uint64 AccessListStateAccessCost uint64 IsValueSentWithCall bool InitCodeCost uint64 HashCost uint64 // contains filtered or unexported fields }
in the case of opcodes like CALL, STATICCALL, DELEGATECALL, etc, in order to calculate the gas dimensions we need to allow the call to complete and then look at the data from that completion after the call has returned. CallGasDimensionInfo retains the relevant information that needs to be remembered from the start of the call to compute the gas dimensions after the call has returned.
type CallGasDimensionStack ¶
type CallGasDimensionStack []CallGasDimensionStackInfo
CallGasDimensionStack is a stack of CallGasDimensionStackInfo so that RETURN opcodes can pop the appropriate gas dimension info and then write the gas dimensions into the dimension logs
func (*CallGasDimensionStack) Peek ¶
func (c *CallGasDimensionStack) Peek() (CallGasDimensionStackInfo, bool)
Peek the top layer of the call stack, returning false if the stack is empty
func (*CallGasDimensionStack) Pop ¶
func (c *CallGasDimensionStack) Pop() (CallGasDimensionStackInfo, bool)
Pop a CallGasDimensionStackInfo from the stack, returning false if the stack is empty
func (*CallGasDimensionStack) Push ¶
func (c *CallGasDimensionStack) Push(info CallGasDimensionStackInfo)
Push a new CallGasDimensionStackInfo onto the stack
func (*CallGasDimensionStack) UpdateExecutionCost ¶
func (c *CallGasDimensionStack) UpdateExecutionCost(executionCost uint64)
UpdateExecutionCost updates the execution cost for the top layer of the call stack so that the call knows how much gas was consumed by child opcodes in that call depth
type CallGasDimensionStackInfo ¶
type CallGasDimensionStackInfo struct { GasDimensionInfo CallGasDimensionInfo DimensionLogPosition int ExecutionCost uint64 }
CallGasDimensionStackInfo is a struct that contains the gas dimension info and the position of the dimension log in the dimension logs array so that the finish functions can directly write into the dimension logs
type DimensionLog ¶
type DimensionLog struct { Pc uint64 `json:"pc"` Op vm.OpCode `json:"op"` Depth int `json:"depth"` OneDimensionalGasCost uint64 `json:"oneDimensionalGasCost"` Computation uint64 `json:"computation"` StateAccess uint64 `json:"stateAccess"` StateGrowth uint64 `json:"stateGrowth"` HistoryGrowth uint64 `json:"historyGrowth"` StateGrowthRefund int64 `json:"stateGrowthRefund"` CallRealGas uint64 `json:"callRealGas"` ChildExecutionCost uint64 `json:"callExecutionCost"` CallMemoryExpansion uint64 `json:"callMemoryExpansion"` CreateInitCodeCost uint64 `json:"createInitCodeCost"` Create2HashCost uint64 `json:"create2HashCost"` Err error `json:"-"` }
DimensionLog emitted to the EVM each cycle and lists information about each opcode and its gas dimensions prior to the execution of the statement.
func (*DimensionLog) ErrorString ¶
func (d *DimensionLog) ErrorString() string
ErrorString formats the log's error as a string.
type DimensionLogRes ¶
type DimensionLogRes struct { Pc uint64 `json:"pc"` Op string `json:"op"` Depth int `json:"depth"` OneDimensionalGasCost uint64 `json:"cost"` Computation uint64 `json:"cpu,omitempty"` StateAccess uint64 `json:"rw,omitempty"` StateGrowth uint64 `json:"growth,omitempty"` HistoryGrowth uint64 `json:"history,omitempty"` StateGrowthRefund int64 `json:"refund,omitempty"` CallRealGas uint64 `json:"callRealGas,omitempty"` ChildExecutionCost uint64 `json:"childExecutionCost,omitempty"` CallMemoryExpansion uint64 `json:"callMemoryExpansion,omitempty"` CreateInitCodeCost uint64 `json:"createInitCodeCost,omitempty"` Create2HashCost uint64 `json:"create2HashCost,omitempty"` Err error `json:"err,omitempty"` }
formatted logs for json output as opposed to DimensionLog which has real non-string types keep json field names as short as possible to save on bandwidth bytes
func (*DimensionLogRes) DebugString ¶
func (d *DimensionLogRes) DebugString() string
DebugString returns a string representation of the DimensionLogRes for debugging
type DimensionTracer ¶
type DimensionTracer interface { GetOpRefund() uint64 GetRefundAccumulated() uint64 SetRefundAccumulated(uint64) GetPrevAccessList() (addresses map[common.Address]int, slots []map[common.Hash]struct{}) GetPrecompileAddressList() []common.Address GetStateDB() tracing.StateDB GetCallStack() CallGasDimensionStack GetOpCount() uint64 GetRootIsPrecompile() bool GetRootIsStylus() bool }
define interface for a dimension tracer that provides the minimum necessary methods to make the calcSstore function work
type ExecutionResult ¶
type ExecutionResult struct { BaseExecutionResult DimensionLogs []DimensionLogRes `json:"dim"` }
ExecutionResult groups all dimension logs emitted by the EVM while replaying a transaction in debug mode as well as transaction execution status, the amount of gas used and the return value
type FinishCalcGasDimensionFunc ¶
type FinishCalcGasDimensionFunc func( totalGasUsed uint64, codeExecutionCost uint64, callGasDimensionInfo CallGasDimensionInfo, ) (GasesByDimension, error)
FinishCalcGasDimensionFunc defines a type signature that takes the code execution cost of the call and the callGasDimensionInfo and returns the gas dimensions for the call opcode itself THIS EXPLICITLY BREAKS THE ABOVE INVARIANT FOR THE NON-CALL OPCODES as call opcodes only contain the dimensions for the call itself, and the dimensions of their children are computed as their children are seen/traced.
func GetFinishCalcGasDimensionFunc ¶
func GetFinishCalcGasDimensionFunc(op vm.OpCode) FinishCalcGasDimensionFunc
for any opcode that increases the depth of the stack, we have to call a finish function after the call has returned to know the code_execution_cost of the call and then use that to compute the gas dimensions for the call opcode itself.
type GasesByDimension ¶
type GasesByDimension struct { OneDimensionalGasCost uint64 `json:"gas1d"` Computation uint64 `json:"cpu"` StateAccess uint64 `json:"rw,omitempty"` StateGrowth uint64 `json:"growth,omitempty"` HistoryGrowth uint64 `json:"hist,omitempty"` StateGrowthRefund int64 `json:"refund,omitempty"` ChildExecutionCost uint64 `json:"childcost,omitempty"` }
GasesByDimension is a type that represents the gas consumption for each dimension for a given opcode.
type TracerErrorWithDimLogs ¶
type TracerErrorWithDimLogs struct { BaseError error Logs []DimensionLog }
TracerErrorWithDimLogs is a custom error type that includes dimension logs in its string representation for debugging purposes
func (*TracerErrorWithDimLogs) Error ¶
func (e *TracerErrorWithDimLogs) Error() string
Error implements the error interface
func (*TracerErrorWithDimLogs) Unwrap ¶
func (e *TracerErrorWithDimLogs) Unwrap() error
Unwrap returns the underlying error for error wrapping
type TxGasDimensionByOpcodeExecutionResult ¶
type TxGasDimensionByOpcodeExecutionResult struct { BaseExecutionResult Dimensions map[string]GasesByDimension `json:"dimensions"` }
ExecutionResult groups all dimension logs emitted by the EVM while replaying a transaction in debug mode as well as transaction execution status, the amount of gas used and the return value
type TxGasDimensionByOpcodeTracer ¶
type TxGasDimensionByOpcodeTracer struct { *BaseGasDimensionTracer OpcodeToDimensions map[vm.OpCode]GasesByDimension }
gasDimensionTracer struct
func (*TxGasDimensionByOpcodeTracer) Error ¶
func (t *TxGasDimensionByOpcodeTracer) Error() error
Error returns the VM error captured by the trace.
func (*TxGasDimensionByOpcodeTracer) GetOpcodeDimensionSummary ¶
func (t *TxGasDimensionByOpcodeTracer) GetOpcodeDimensionSummary() map[string]GasesByDimension
stringify opcodes for dimension log output
func (*TxGasDimensionByOpcodeTracer) GetProtobufResult ¶
func (t *TxGasDimensionByOpcodeTracer) GetProtobufResult() ([]byte, error)
produce protobuf serialized result for storing to file in compact format
func (*TxGasDimensionByOpcodeTracer) GetResult ¶
func (t *TxGasDimensionByOpcodeTracer) GetResult() (json.RawMessage, error)
produce json result for output from tracer this is what the end-user actually gets from the RPC endpoint
type TxGasDimensionLogger ¶
type TxGasDimensionLogger struct { *BaseGasDimensionTracer // contains filtered or unexported fields }
TxGasDimensionLogger struct
func (*TxGasDimensionLogger) DimensionLogs ¶
func (t *TxGasDimensionLogger) DimensionLogs() []DimensionLog
DimensionLogs returns the captured log entries.
func (*TxGasDimensionLogger) GetResult ¶
func (t *TxGasDimensionLogger) GetResult() (json.RawMessage, error)
produce json result for output from tracer this is what the end-user actually gets from the RPC endpoint