What Uniswap’s swap rule can teach us about smart contract invariants

A snapshot of a Uniswap v2 pool’s reserves cannot, on its own, show whether a swap respected the pool’s pricing rule. An explainer published on November 24, 2026, at 13:21:54 (UTC+08:00) uses the pool’s fee-adjusted constant-product constraint to illustrate why: the rule relates the reserves before a swap to the reserves after it. It constrains how the contract can change state, rather than simply describing its current state.

To check an invariant, two questions matter: does the property hold in the initial state, and if it holds before an operation, does it still hold afterward? Foundry fuzz tests look for violations across generated test cases. Certora Prover checks whether the property holds initially and whether operations preserve it under the stated assumptions.

The choice of property matters as much as the check. A weak invariant can hold without establishing the behavior the developer cares about. A stronger one places tighter constraints on that behavior. If a filter excludes a state the contract can actually reach, or an assumption rules out behavior that can actually occur, a successful check may not support the intended conclusion.

The explainer illustrates this limit with Uniswap v4’s solvency proof: the core solvency invariant needs supporting invariants and assumptions about how tokens behave. It also describes a workflow in which AutoProver helps generate candidate properties, tests and Prover rules. Generating a candidate and establishing that it captures the intended guarantee remain distinct tasks.

Further reading