Use Case & Applications
Ensures the fundamental lending protocol invariant that total tokens borrowed never exceed total tokens deposited, preventing protocol insolvency and ensuring withdrawal requests can be honored. Critical for lending and borrowing platforms (Aave, Compound, Morpho), money markets with deposit/borrow pools, yield aggregators implementing lending strategies, and synthetic asset protocols with collateralized debt positions. Violating this invariant could lead to protocol insolvency, loss of user funds, or destabilization of dependent DeFi ecosystems.Explanation
Implements straightforward verification that total tokens borrowed never exceed total tokens deposited:ph.forkPostState()
: Capture protocol state after transaction to verify invariant holdsregisterStorageChangeTrigger()
: Trigger on storage slots tracking supply and borrow totals- Check total supply of assets (tokens deposited) and total borrowed assets
- Assert total supply ≥ total borrowed assets
Code Example
Note: Full examples with tests available in the Phylax Assertion Examples Repository.