Skip to main content

Module snapshot

Module snapshot 

Source
Expand description

Snapshot fuzzing: resume invariant runs from interesting states reached by earlier runs.

After every accepted call the storage writes are compressed into features. A slot’s values are a set, each value its own feature, until the slot took more than MAX_SET_VALUES distinct values; from then on they are a distribution, binned by sign-folded log2. Mapping and array entries are folded per contract, plus the log2 of how many of them are nonzero.

A call that reaches a feature no earlier call reached makes its post-call state a snapshot: the executor is cloned together with the call prefix that produced it. Later runs start either from the post-setUp state or from a snapshot, picked by a power schedule that favors snapshots whose features are still rare and whose runs keep finding new coverage or new states. Runs started from a snapshot carry its prefix in their inputs, so counterexamples, shrinking, replay and corpus entries still start from the post-setUp state.

Re-exportsΒ§

use crate::executors::Executor; πŸ”’
use alloy_primitives::Address; πŸ”’
use alloy_primitives::U256; πŸ”’
use alloy_primitives::map::AddressMap; πŸ”’
use alloy_primitives::map::HashMap; πŸ”’
use alloy_primitives::map::HashSet; πŸ”’
use evm2::evm::PendingState; πŸ”’
use foundry_evm_core::constants::CHEATCODE_ADDRESS; πŸ”’
use foundry_evm_core::eip2935::is_history_storage_address; πŸ”’
use foundry_evm_core::evm::FoundryEvmNetwork; πŸ”’
use foundry_evm_fuzz::BasicTxDetails; πŸ”’
use proptest::prelude::Rng; πŸ”’
use proptest::test_runner::TestRunner; πŸ”’
use std::hash::BuildHasher; πŸ”’
use std::hash::BuildHasherDefault; πŸ”’
use std::hash::DefaultHasher; πŸ”’
use std::sync::Arc; πŸ”’

StructsΒ§

Energy πŸ”’
RunStart πŸ”’
The state a run starts from.
Snapshot πŸ”’
StateSnapshots πŸ”’
Per-worker pool of snapshots and the state features seen so far.

EnumsΒ§

Start πŸ”’
Where the current run started.

ConstantsΒ§

COMPUTED_SLOT πŸ”’
Slots at or above 2^128 are treated as computed (mapping or dynamic array) slots.
MAX_PREFIX_DEPTHS πŸ”’
Snapshots are only taken while the reproducing sequence is at most this many run depths long.
MAX_SET_VALUES πŸ”’
Distinct values a slot may take before it is treated as a distribution rather than a set.
MAX_SNAPSHOTS πŸ”’
Most snapshots kept per worker.
MIN_LIVENESS πŸ”’
Least share of its find rate that a state keeps when every call made from it reverts.
SNAPSHOT_SLOT_BUDGET πŸ”’
Storage slots that the snapshots of all workers may copy together. Each snapshot holds a full copy of the backend, so workers keep fewer snapshots as their states grow, but at least two, so a run resumed from one snapshot can still replace the other.

FunctionsΒ§

computed_cardinality πŸ”’
Nonzero computed slots per contract in the executor’s backend.
log2_bin πŸ”’
Sign-folded bit length: small positive and small negative (two’s complement) values land in different, magnitude-ordered bins.
storage_slots πŸ”’
Storage slots held by the executor’s backend.