# Unclaimable reserve assets will accrue in a pool due to the difference between interest paid on borrows and interest earned on supplies

Borrow interest compounds while supply interest is linear, so surplus tokens accrue in the pool with no skim function, permanently locked.

- Payout: Audit contest
- Severity: medium
- Program: New Scope
- Found by: Nihavent
- Disclosed: 2024-06-27
- Write-up quality: 6/10
- Original: https://github.com/sherlock-audit/2024-06-new-scope-judging/issues/429
- Library page: https://bugbountylibrary.com/r/sherlock%3A2024-06-new-scope%3AM-10
- Tags: area:web3 domain:web3 impact:funds-loss kind:contest platform:sherlock sev:medium tech:evm tech:solidity technique:source-review vuln:accounting-error

**Target:** Lending pool reserve accounting (ReserveLogic/MathUtils)
**Root cause:** Borrow index uses calculateCompoundedInterest while liquidity index uses calculateLinearInterest, so borrowers repay more than suppliers can claim; no skim/rebase function recovers the delta.
**Steps:**
1. Supply tokenB as bob via `pool.supplySimple(tokenB, bob, 1000e18, 0)`
2. Supply tokenA collateral and `pool.borrowSimple(tokenB, alice, 1000e18, 0)` at 100% utilization
3. `vm.warp(block.timestamp + 2 seconds)` then `pool.forceUpdateReserves()`
4. Alice repays full debt via `pool.repaySimple(tokenB, max, 0)`; debtShares == 0
5. Compute Bob's claim = supplyShares * liquidityIndex / 1e27 plus treasury accruedToTreasuryShares * liquidityIndex / 1e27
6. Assert `tokenB.balanceOf(pool) > BobsMaxWithdrawAssets + accruedTreasuryAssets` — surplus is unclaimable
**How found:** Code reading of ReserveLogic._updateIndexes comparing calculateLinearInterest (supply) vs calculateCompoundedInterest (borrow); noticed no skim function exists unlike Aave's rescueTokens, then wrote a forge PoC showing pool balance exceeds all claims.
**Exploitation:** No direct theft; surplus accrues passively each time debt is repaid and remains borrowable/flash-loanable but never claimable, compounding the locked balance over time.
**Insight:** When auditing lending forks, diff the supply vs borrow index math (linear vs compound) and check whether any function can claim the resulting delta; a missing skim/rescue path turns an intentional rate asymmetry into permanently locked funds.

## Proof of concept (copied exactly from the original report)

**PoC test showing unclaimable balance buildup**

```
function test_POC_UnclaimableBalanceBuildupOnPool () public {
    uint256 aliceMintAmount = 10_000e18;
    uint256 bobMintAmount = 10_000e18;
    uint256 supplyAmount = 1000e18;
    uint256 borrowAmount = 1000e18;

    _mintAndApprove(alice, tokenA, aliceMintAmount, address(pool));         // alice collateral
    _mintAndApprove(bob, tokenB, bobMintAmount, address(pool));             // bob supply
    _mintAndApprove(alice, tokenB, aliceMintAmount, address(pool));         // alice needs some funds to pay interest

    vm.startPrank(bob);
    pool.supplySimple(address(tokenB), bob, supplyAmount, 0); 
    vm.stopPrank();

    vm.startPrank(alice);
    pool.supplySimple(address(tokenA), alice, aliceMintAmount, 0);  // alice collateral
    pool.borrowSimple(address(tokenB), alice, borrowAmount, 0);     // 100% utilization
    vm.stopPrank();

    vm.warp(block.timestamp + 365 days); // Time passes, interest accrues, treasury shares accrue
    pool.forceUpdateReserves();

    // Alice full repay
    vm.startPrank(alice);
    tokenB.approve(address(pool), type(uint256).max);
    pool.repaySimple(address(tokenB), type(uint256).max, 0);

    (,,, uint256 debtShares) = pool.marketBalances(address(tokenB));
    // All debt has been repaid
    assert(debtShares == 0); 

    // Bob's claim on pool's tokenB
    bytes32 bobPos = keccak256(abi.encodePacked(bob, 'index', uint256(0)));
    uint256 BobsMaxWithdrawAssets = pool.supplyShares(address(tokenB), bobPos) * pool.getReserveData(address(tokenB)).liquidityIndex / 1e27;

    // Treasury claim on pool's tokenB
    uint256 accruedTreasuryAssets = pool.getReserveData(address(tokenB)).accruedToTreasuryShares * pool.getReserveData(address(tokenB)).liquidityIndex / 1e27;

    // Total balance of pool's tokenB
    uint256 poolTokenBBalance = tokenB.balanceOf(address(pool));

    assert(poolTokenBBalance > BobsMaxWithdrawAssets + accruedTreasuryAssets); // There are more tokenB on the pool than all suppliers + treasury claim.
```

**Adjusted PoC warping only 2 seconds**

```
vm.warp(block.timestamp + 2 seconds); // Time passes, interest accrues, treasury shares accrue
    pool.forceUpdateReserves();
```

