# Debt position interest is compounded while pool interest is simple causing inconsistency between expectedLiquidity_ and availableLiquidity_

CDPVault compounds debt interest via cumulative index while PoolV3 accrues simple linear interest, so borrowers overpay and final pool withdrawals revert on underflow.

- Payout: Audit contest
- Severity: high
- Program: LoopFi
- Found by: hash
- Disclosed: 2025-02-17
- Write-up quality: 7/10
- Original: https://github.com/code-423n4/2024-07-loopfi-findings/issues/95
- Library page: https://bugbountylibrary.com/r/c4%3A2024-07-loopfi%3AH-10
- Tags: area:web3 domain:web3 impact:dos impact:funds-loss kind:contest platform:code4rena sev:high tech:evm tech:solidity technique:source-review vuln:accounting-error vuln:dos

**Target:** PoolV3 / CDPVault interest accrual (Solidity lending pool)
**Root cause:** PoolV3 computes base interest linearly (borrowed * rate * elapsed/365d) but the debt position uses a cumulative interest index that compounds on every _calcBaseInterestIndex update, so position interest exceeds pool-accounted interest.
**Steps:**
1. Borrow 50 ether against a 100 ether position in CDPVault with quota interest forced to 0.
2. Advance time 1 day and call liquidityPool.deposit(0, ...) to trigger an interest index update; repeat once more after another day.
3. Compare vault.getDebtInfo(position) accrued interest vs liquidityPool.expectedLiquidity() delta: positionAccruedInterest > poolAccruedInterest.
4. Repay debt + positionAccruedInterest, then have all LPs withdraw; the final withdraw reverts with `SafeCast: value must be positive` because expectedLiquidity underflows.
**How found:** Code reading of the two interest formulas: noticed PoolV3 uses calcLinearGrowth while CreditLogic.calcAccruedInterest divides by a cumulative index that is itself multiplied by (RAY + linear growth) each update, implying compounding; confirmed with a Foundry PoC.
**Exploitation:** Borrowers accrue more interest than the pool records as expectedLiquidity; the excess is not credited to the pool, so when LPs withdraw shares the expectedLiquidity accounting underflows and the last withdrawal reverts, locking funds. Borrowers also overpay interest and effective borrow rates drift.
**Escalation:** Repeated index updates widen the compounding gap; combined with full LP withdrawal the mismatch causes a hard revert (DoS) on final withdrawal.
**Insight:** When a protocol reuses Gearbox-style cumulative interest indexes alongside a pool that accrues simple interest, the two accrual models diverge per update; check that index updates are additive (prevIndex + rate*dt) not multiplicative, and test expectedLiquidity vs availableLiquidity after multiple partial accruals.

