Skip to free scan

Analysis Techniques

Invariant Testing

Invariant testing verifies that certain properties of a smart contract remain true no matter what sequence of function calls is made against it. An invariant is a system-wide truth — for example, "a lending market's total debt never exceeds total collateral" — that should survive any combination of user actions.

How It Works

You define invariants, and a fuzzer drives the contract through long, randomized sequences of calls (with varied actors and inputs), checking after each step that no invariant is violated. A violation is a concrete, reproducible sequence that breaks the system.

Invariant testing is especially powerful for stateful DeFi protocols where bugs emerge only from specific action orderings — the same class of issue behind many reward-accounting and liquidation failures.

Invariants vs Unit Tests

Unit tests check specific expected outcomes; invariant tests assert what must always be true and let the tool search for the sequence that breaks it. They catch emergent, multi-step bugs that unit tests miss.

Frequently Asked Questions

Q: What makes a good invariant?

A: A property that must hold globally regardless of call order, such as accounting identities (sum of balances equals total supply) or solvency conditions (collateral ≥ debt).


Q: How is invariant testing related to fuzzing?

A: Invariant testing uses a fuzzer as its engine: the fuzzer explores call sequences while the invariants define what counts as a failure.

Firepan

Scan Your Contracts

Run a free surface scan — results in minutes, no credit card required.

Run Free Scan →