# Inconsistent Application of Reserve Factor Changes Leads to Protocol Insolvency Risk

Global reserveFactor change applies new factor to treasury accrual while liquidity index uses old cached rate, causing over/under-minting and pool insolvency.

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

**Target:** ZeroLend lending pool ReserveLogic.updateState / PoolFactory.setReserveFactor
**Root cause:** _updateIndexes uses the old liquidityRate (derived from old reserveFactor) cached in ReserveCache, while _accrueToTreasury uses the freshly fetched new reserveFactor, so interest credited to users and shares minted to treasury are computed from inconsistent factors.
**Steps:**
1. Deploy pool, supply 2000e18 tokenA, borrow 800e18.
2. Warp 30 days to accrue interest.
3. Call `poolFactory.setReserveFactor(0.2e4)` (20%).
4. Alice repays max via `pool.repaySimple`.
5. Alice calls `pool.withdrawSimple(..., UINT256_MAX)` — reverts because treasury shares minted exceed actual accrued interest, leaving insufficient funds.
**How found:** Code reading of updateState: noticed _updateIndexes relies on cached currLiquidityRate (old factor) while _accrueToTreasury takes the new _reserveFactor argument; compared to Aave v3.1 fix which calls syncIndexesState before setReserveFactor.
**Exploitation:** Admin (or any reserveFactor update) triggers updateState; _accrueToTreasury mints shares using new factor against debt accrued under old factor, over-allocating treasury and making the last user withdrawal revert. Repeated updates compound the shortfall.
**Escalation:** Affects all pools globally since reserveFactor is factory-wide; shortfall grows as treasury shares accrue yield, worsening insolvency over time.
**Insight:** When a global config parameter feeds both an index update and a share-mint in the same function, check whether one path reads a cached/derived value and the other reads the live parameter — that asymmetry is the bug; Aave's syncIndexesState-before-config-change is the canonical fix pattern.

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

**Foundry PoC test changing reserve factor then withdrawing**

```
function test\_auditPoc\_reserve() external {
    console.log('balance pool before : ', tokenA.balanceOf(address(pool)));
    \_mintAndApprove(alice, tokenA, 2 * amount, address(pool));
    vm.startPrank(alice);

    pool.supplySimple(address(tokenA), alice, amount, 0); // deposit : 2000e18
    pool.borrowSimple(address(tokenA), alice, borrowAmount, 0); // borrow : 800e18

    vm.stopPrank();
    // wrap sometime so the intrest accrue :
    vm.warp(block.timestamp + 30 days);
    // change reserve factor to 0.2e4 (20\%):
    poolFactory.setReserveFactor(0.2e4);

    vm.startPrank(alice);
    tokenA.approve(address(pool), UINT256\_MAX);
    pool.repaySimple(address(tokenA), UINT256\_MAX, 0);
    // withdraw all will revert cause there is not enough funds for treasury due to updating the factor :
    vm.expectRevert();
    pool.withdrawSimple(address(tokenA), alice, UINT256\_MAX, 0);
    vm.stopPrank();

  }
```

