Skip to main content

Use Case & Applications

Ensures ERC4626 operations maintain correct accounting for both assets and shares, preventing share calculation errors and fund loss. Critical for yield aggregators (Yearn, Aave, Compound), lending protocols with ERC4626 interest-bearing tokens, liquidity pools using ERC4626 for LP tokens, and staking protocols with ERC4626 staking tokens. Any discrepancy between preview functions and actual operations could lead to users receiving incorrect amounts, potentially resulting in value loss.

Focused Approach: Deposit & Withdraw

Five assertion functions for deposit/withdrawal verification: Deposit Assertions:
  • Asset Accounting: Total vault assets increase by exact deposit amount
  • Share Accounting: Depositors receive correct shares
Withdrawal Assertions:
  • Asset Accounting: Total vault assets decrease by exact withdrawal amount
  • Share Accounting: Correct shares burned
Share Value Assertion:
  • Share Value Monotonicity: Share value never decreases unexpectedly (with precision tolerance for rounding)
Uses ph.getCallInputs(), ph.forkPreTx() / ph.forkPostTx(), and registerCallTrigger(). See the Cheatcodes Reference for details.

Comprehensive Approach: All Operations + Batch Handling

Use this approach when your protocol:
  • Uses mint/redeem in addition to deposit/withdraw
  • Handles multiple operations in a single transaction
  • Needs validation against preview functions
Four assertion functions covering all ERC4626 operations:
  • Batch Operations Consistency: Validates deposit, mint, withdraw, and redeem in a single transaction. Uses preview functions for expected value calculation.
  • Deposit Balance Verification: Confirms vault assets increase by exact deposit amount
  • Depositor Shares Verification: Confirms depositor receives shares matching previewDeposit()
  • Base Invariant: Ensures vault always has at least as many assets as shares
Uses both registerCallTrigger() and registerStorageChangeTrigger().
Full examples with tests available in the Phylax Assertion Examples Repository.