State the quantity that must remain conserved or bounded.
LET’S PICTURE IT
A ledger should explain every coin entering, leaving or remaining owed.
SEE IT FOR YOURSELF
Pack small values into Solidity storage slotsStep 1 / 4
In this simple default-layout example, two uint128 values come before one uint256. Each slot holds thirty-two bytes.
In this simple default-layout example, two uint128 values come before one uint256. Each slot holds thirty-two bytes.The first sixteen-byte value occupies the low-order half of slot zero. Low-order bytes are shown on the right.The second uint128 fits in the remaining sixteen bytes. Both values now share slot zero.C needs a complete thirty-two-byte slot, so it begins at slot one. Two packed small values plus C use two slots.
Animated local teaching model. No wallet, RPC or live blockchain data. Some labels and hashes are abbreviated for readability.
Choose a precise property
An example is total recorded credits never exceeding accounted assets under the supported asset model. State whether direct transfers, fees and rounding are included.
Include every transition
Deposits, withdrawals, transfers, fees, upgrades and emergency actions can affect the property. Testing only the main deposit path misses other state changes.
Model external asset behavior
Rebases, transfer fees or unsolicited balances can break simplistic equality assumptions. Define supported behavior and the expected accounting treatment.
Test action sequences
Invariant testing should generate sequences and multiple actors. A property that holds after isolated calls can still fail after a particular combination.
Work through the boundary
accounted assets >= outstanding redeemable obligations
Define rounding, fees, direct donations and supported assets before treating this as a test oracle.
A simplified local review scenario. The example establishes a question to test, not a guarantee of production safety.
QUICK CHECK · NO PRESSURE
Should an invariant state its asset-model assumptions?
The meaning of the property depends on supported behavior.