Skip to main content
This case study describes a separate example fork. For the current credible-std adapters and their activation limits, see Aave example notes.
This suite implements Aave V3 invariants as assertions. See the Phylax fork for code and tests.

Approach

Most assertions follow Aave’s invariant specifications. Mocks create invalid states to test assertion failures.

Maturity

The suite includes local tests. Before production, review release backtesting for false positives against recent protocol activity.

Here Be Dragons 🐲

The example fork contains an intentional bug. Anyone borrowing exactly 333e6 tokens will receive double the amount of tokens they would normally receive if they borrowed any other amount. The bug can be found in the BorrowLogic.sol file.
DO NOT USE THIS VERSION OF AAVE V3 IN PRODUCTION!

Key Features

The suite covers supply, borrow, repay, withdrawal, liquidation, and flash-loan operations.

Assertion Types

The repository separates production assertions from showcase assertions. Showcase checks illustrate behavior that protocol Solidity can also enforce.

Assertion Collections

Production Assertions

Core Invariants

  • BaseInvariants - Cross-transaction accounting validation:
    • Debt token supply consistency across operations
    • AToken supply consistency across operations
    • Underlying balance invariant validation
    • Virtual balance sanity checks
    • Liquidity index integrity verification

Price Consistency

  • OracleAssertions - Price consistency checks:
    • Borrow/supply/liquidation price deviation monitoring (5% max)
    • Price consistency validation across transactions
    • Manipulated pricing input detection

Flashloan Protection

Log-Based Verification

  • LogBasedAssertions - Proxy/delegatecall resilient validation:
    • Balance change verification using event logs
    • Works with complex call patterns

Showcase Assertions

Operation Validation

  • LendingInvariantAssertions - Standard supply/withdrawal checks:
    • Reserve state validation
    • Supply cap enforcement
    • Balance change verification
    • Collateral withdrawal health
  • LiquidationInvariantAssertions - Standard liquidation checks:
    • Health factor thresholds
    • Grace period validation
    • Close factor conditions
    • Deficit accounting
    • Reserve state requirements

Health Factor Management

  • HealthFactorAssertions - Health factor transitions:
    • Non-decreasing health factor actions
    • Healthy to unhealthy transition prevention
    • Supply/withdraw/repay health maintenance

Basic Validation

Testing

The tests cover valid and invalid operations, sequences, batches, and boundary conditions. Mocks provide controlled failure cases.

Intentional Bugs

  1. 333e6 Borrow Bug: Borrowing exactly 333e6 tokens returns double amount
    • Location: BorrowLogic.sol lines 128-144
    • Test: test_BASE_INVARIANT_A_DebtTokenSupply_333e6Bug()
  2. Mock Protocol: BrokenPool.sol for controlled testing

Usage