Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ContractRevertMetrics ¶
type ContractRevertMetrics struct {
// Name is the name of the contract.
Name string `json:"name"`
// FunctionRevertMetrics holds the revert metrics for each function in the contract.
FunctionRevertMetrics map[string]*FunctionRevertMetrics `json:"functionRevertMetrics"`
}
ContractRevertMetrics is used to track the number of times calls to various functions in a contract revert and why.
type FunctionRevertMetrics ¶
type FunctionRevertMetrics struct {
// Name is the name of the function.
Name string `json:"name"`
// TotalCalls is the total number of calls to the function.
TotalCalls uint `json:"totalCalls"`
// TotalReverts is the total number of times the function reverted.
TotalReverts uint `json:"totalReverts"`
// Pct is the percent of times a call to this function reverted
Pct float64 `json:"pct"`
// PrevPct is the percentage of total calls that reverted in the previous campaign.
PrevPct float64 `json:"prevPct"`
// RevertReasonMetrics holds the revert reason metrics for the function.
RevertReasonMetrics map[string]*RevertReasonMetrics `json:"revertReasonMetrics"`
}
FunctionRevertMetrics is used to track the number of times a function reverted and why
type RevertMetrics ¶
type RevertMetrics struct {
// ContractRevertMetrics holds the revert metrics for each contract in the fuzzing campaign.
ContractRevertMetrics map[string]*ContractRevertMetrics `json:"contractRevertMetrics"`
}
RevertMetrics is used to track the number of times calls to various contracts and functions revert and why.
func NewRevertMetrics ¶
func NewRevertMetrics() *RevertMetrics
NewRevertMetrics will create a new RevertMetrics object.
func NewRevertMetricsFromPath ¶
func NewRevertMetricsFromPath(path string) (*RevertMetrics, error)
NewRevertMetricsFromPath will load a RevertMetrics object using the provided file path.
func (*RevertMetrics) Finalize ¶
func (m *RevertMetrics) Finalize(other *RevertMetrics)
Finalize finalizes the revert metrics by updating the percentages for each function and revert reason. Additionally, if an optional RevertMetrics object is provided, it is merged into the current RevertMetrics object.
func (*RevertMetrics) Update ¶
func (m *RevertMetrics) Update(update *RevertMetricsUpdate, errorIDs map[string]abi.Error)
Update updates the RevertMetrics based on the execution result of a call sequence element. A mapping of error IDs to their custom error names is also provided to aid with decoding the revert reason.
type RevertMetricsUpdate ¶
type RevertMetricsUpdate struct {
// ContractName is the name of the contract which was called
ContractName string
// FunctionName is the name of the function which was called
FunctionName string
// ExecutionResult is the result of the execution
ExecutionResult *core.ExecutionResult
}
RevertMetricsUpdate is used to update the RevertMetrics struct. The fuzzer workers will send these updates via the metrics channel.
type RevertReasonMetrics ¶
type RevertReasonMetrics struct {
// Reason is the revert reason.
Reason string `json:"reason"`
// Count is the number of times the revert reason occurred.
Count uint `json:"count"`
// Pct is the percentage of total calls to that resulted in the revert reason.
Pct float64 `json:"pct"`
// PrevPct is the percentage of total calls to that resulted in the revert reason in the previous campaign.
PrevPct float64 `json:"prevPct"`
}
RevertReasonMetrics is used to track the number of times a revert reason occurred for a function.
type RevertReporter ¶
type RevertReporter struct {
// Enabled determines if the reporter is enabled
Enabled bool
// Path is the path to the directory where the revert metrics and report will be stored from this campaign.
// We will also look at this directory for the RevertMetricsArtifact from the previous campaign.
Path string
// CustomErrors is a map of different error IDs to their custom errors. This is used to resolve the revert reasons
// when updating the revert metrics.
CustomErrors map[string]abi.Error
// RevertMetricsCh is the channel that will receive RevertMetricsUpdate objects from fuzzer workers to update the revert metrics.
// We will be receiving pointers to the execution result object within the RevertMetricsUpdate object since we are confident that
// will be no races on that value.
RevertMetricsCh chan RevertMetricsUpdate
// RevertMetrics holds the revert metrics for the current campaign.
RevertMetrics *RevertMetrics
// PrevRevertMetrics holds the revert metrics for the previous campaign.
PrevRevertMetrics *RevertMetrics
}
RevertReporter is responsible for tracking and storing the RevertMetrics for the fuzzing campaign.
func NewRevertReporter ¶
func NewRevertReporter(enabled bool, corpusDirectory string) (*RevertReporter, error)
NewRevertReporter creates a new RevertsReporter. If there is any issue loading the previous artifact (if it exists), an error is returned.
func (*RevertReporter) AddCustomErrors ¶
func (r *RevertReporter) AddCustomErrors(contractDefinitions contracts.Contracts)
AddCustomErrors allows users to provide a list of contract definitions that will be parsed to identify any custom, user-defined errors in each contract's ABI. We _need_ to decouple this from the creation of the actual RevertReporter object because of some edge case behavior with using crytic-export as the output folder for revert reports. Since the crytic-export folder is deleted by crytic-compile, we need to create the revert reporter, compile, and then attach the compiled artifacts to perform comparative analysis to the previous fuzzing campaign.
func (*RevertReporter) BuildArtifacts ¶
func (r *RevertReporter) BuildArtifacts() error
BuildArtifacts writes the revert metrics to disk and also generates an HTML version of it for the user.
func (*RevertReporter) Start ¶
func (r *RevertReporter) Start(ctx context.Context)
Start starts the revert reporter goroutine. It will continue to run until the context is cancelled.