Skip to main content

When to Use This Pattern

Verifies that the sum of all individual positions exactly matches the total supply reported by the protocol, preventing supply manipulation, double counting, and accounting discrepancies. Critical for lending protocols, liquidity pools, staking mechanisms, synthetic asset protocols, and fractionalized NFT protocols where accurate position accounting is fundamental to security. Any discrepancy between individual positions and total supply could lead to incorrect calculations, withdrawal failures, or protocol insolvency.

What This Pattern Checks

Since direct iteration over all positions isn’t currently supported, this assertion uses a workaround that tracks position changes through function calls:
  1. Capture the pre-state total supply before the transaction
  2. Monitor all function calls that modify positions (deposit, withdraw)
  3. Calculate the sum of changes to these positions
  4. Verify that the new total supply equals the pre-state total supply plus the sum of position changes
Uses these cheatcodes:
  • _preTx() / _postTx() with Reshiram snapshot reads: Capture total supply before and after transaction
  • ph.context() and ph.callinputAt(): Inspect the triggered position-modifying call
  • registerFnCallTrigger(): Trigger on position-modifying functions
Check Modified Key Discovery for details on what direct position iteration would look like. For more information about cheatcodes, see the Cheatcodes Documentation.

Assertion Pattern

Full examples and mock protocol code are available in credible-std.