engine

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2026 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Overview

Package engine implements the core fuzzing logic for comparing SSZ reflection-based and codegen-based implementations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PrintStats

func PrintStats(stats *Stats, elapsed time.Duration)

PrintStats prints current fuzzing statistics to stdout.

Types

type Engine

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

Engine is the core fuzz testing engine. Each Engine instance owns a private RNG and Filler (not thread-safe), but shares DynSsz instances, Stats, and Reporter across workers.

func NewEngine

func NewEngine(reporter *Reporter, stats *Stats, ds, dsExtended *dynssz.DynSsz, seed int64, maxDataLen int, dsUnknown ...*dynssz.DynSsz) *Engine

NewEngine creates a new fuzz engine with its own RNG but shared DynSsz instances. The DynSsz TypeCache is thread-safe (uses sync.RWMutex), so sharing avoids duplicating large type caches across workers.

func (*Engine) FuzzEntry

func (e *Engine) FuzzEntry(entry corpus.TypeEntry)

FuzzEntry runs one fuzz iteration on a given type entry. It alternates between three modes:

  • Valid fill: create a struct with random values, test all comparisons
  • Mutated: valid data with random mutations
  • Random bytes: purely random input data

func (*Engine) FuzzEntryWithData

func (e *Engine) FuzzEntryWithData(entry corpus.TypeEntry, data []byte)

FuzzEntryWithData runs a fuzz iteration with specific data.

func (*Engine) SetOracles added in v1.4.0

func (e *Engine) SetOracles(enabled, reference bool, native, nativeExtended *dynssz.DynSsz)

SetOracles enables independent and invariant checks for valid values. The native engines must use WithNoFastHash so they exercise a separate SHA-256 backend.

type Filler

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

Filler populates Go struct instances with random valid values using reflection. It reads SSZ struct tags to determine valid sizes for slices, bitlists, etc.

func NewFiller

func NewFiller(rng *rand.Rand) *Filler

NewFiller creates a new random value filler.

func (*Filler) Fill

func (f *Filler) Fill(v reflect.Value)

Fill populates the value v with random data appropriate to its type. v must be settable (typically obtained via reflect.ValueOf(&x).Elem()).

func (*Filler) FillStruct

func (f *Filler) FillStruct(target any)

FillStruct fills a struct pointer with random values.

type Issue

type Issue struct {
	Type             IssueType
	TypeName         string
	Data             []byte
	Details          string
	ReflectionOutput []byte
	CodegenOutput    []byte
}

Issue represents a single fuzzing issue found.

type IssueType

type IssueType string

IssueType classifies the kind of fuzzing issue found.

const (
	IssuePanic             IssueType = "panic"
	IssueMarshalMismatch   IssueType = "marshal-mismatch"
	IssueSizeMismatch      IssueType = "size-mismatch"
	IssueHTRMismatch       IssueType = "htr-mismatch"
	IssueStreamMismatch    IssueType = "stream-mismatch"
	IssueUnmarshalDiff     IssueType = "unmarshal-diff"
	IssueReferenceMismatch IssueType = "reference-mismatch"
	IssueNonDeterministic  IssueType = "nondeterministic"
)

type Reporter

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

Reporter persists fuzzing issues to disk.

func NewReporter

func NewReporter(dir string, maxIssues int) (*Reporter, error)

NewReporter creates a new issue reporter that writes to the given directory.

func (*Reporter) Close

func (r *Reporter) Close() error

Close closes the reporter's log file.

func (*Reporter) IssueCount

func (r *Reporter) IssueCount() int

IssueCount returns the number of unique issues reported.

func (*Reporter) Report

func (r *Reporter) Report(issue *Issue)

Report persists an issue to disk.

type Stats

type Stats struct {
	Iterations        atomic.Uint64
	ValidFills        atomic.Uint64
	MutatedFills      atomic.Uint64
	RandomInputs      atomic.Uint64
	Panics            atomic.Uint64
	MarshalMismatches atomic.Uint64
	SizeMismatches    atomic.Uint64
	HTRMismatches     atomic.Uint64
	StreamMismatches  atomic.Uint64
	UnmarshalDiffs    atomic.Uint64
	WalkerPrograms    atomic.Uint64
	WalkerMismatches  atomic.Uint64
	Successes         atomic.Uint64
	OracleChecks      atomic.Uint64
	ReferenceChecks   atomic.Uint64
	ReferenceSkips    atomic.Uint64
}

Stats tracks fuzzing statistics.

Jump to

Keyboard shortcuts

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