This case study describes a separate example fork. For the current
credible-std adapters and their activation limits, see Aave example notes.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 exactly333e6 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.
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
- FlashloanInvariantAssertions - Flashloan security:
- Repayment verification (amount + fee)
- Fee payment validation
- Reserve state integrity
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
- BorrowLogicErrorAssertion - Simple balance validation:
- Borrow amount matches underlying balance change
Testing
The tests cover valid and invalid operations, sequences, batches, and boundary conditions. Mocks provide controlled failure cases.Intentional Bugs
-
333e6 Borrow Bug: Borrowing exactly 333e6 tokens returns double amount
- Location:
BorrowLogic.sollines 128-144 - Test:
test_BASE_INVARIANT_A_DebtTokenSupply_333e6Bug()
- Location:
-
Mock Protocol:
BrokenPool.solfor controlled testing

