# `LiquidationLogic@_burnCollateralTokens` does not account for liquidation fees when withdrawing collateral during liquidation leading to incorrect accounting and Pools insolvency

LiquidationLogic burns only liquidator collateral, not protocol fee, leaving excess supply shares; liquidated user can re-borrow/withdraw phantom collateral, insolvency.

- 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/228
- Library page: https://bugbountylibrary.com/r/sherlock%3A2024-06-new-scope%3AH-5
- Tags: area:web3 domain:web3 impact:funds-loss impact:integrity kind:contest platform:sherlock sev:high tech:solidity technique:source-review vuln:accounting-error vuln:business-logic vuln:liquidation

**Target:** Lending pool liquidation logic (LiquidationLogic._burnCollateralTokens)
**Root cause:** _burnCollateralTokens withdraws only actualCollateralToLiquidate from user/pool supply shares, omitting liquidationProtocolFeeAmount that is separately transferred to treasury, so shares are under-burned.
**Steps:**
1. Set liquidationProtocolFeePercentage > 0 via poolFactory.setLiquidationProtcolFeePercentage(0.05e4).
2. Alice supplies tokenA, Bob supplies tokenB; Alice borrows tokenB and becomes liquidatable after oracle price drop.
3. Bob calls pool.liquidateSimple(tokenA, tokenB, pos, type(uint256).max).
4. Observe pool.getBalance(tokenA, alice) > tokenA.balanceOf(pool) because fee shares were not burned.
5. Alice can withdraw/borrow against the phantom shares, draining other suppliers.
**How found:** Code review of liquidation flow: noticed _calculateAvailableCollateralToLiquidate returns collateralAmount minus fee, but _burnCollateralTokens burns only that reduced amount while fee is transferred separately, so total shares burned < collateral removed.
**Exploitation:** Any liquidation with protocol fee set leaves unburned supply shares credited to the liquidated user; that user can later withdraw or borrow against them, extracting value from other pool participants and causing insolvency.
**Escalation:** Repeated liquidations amplify the share surplus; affects Curated Vaults reallocation and NFT positions.
**Insight:** In liquidation math, verify that the sum of all collateral outflows (to liquidator + treasury fee) equals the shares burned; fee-on-transfer or protocol-fee paths often under-burn.

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

**Foundry test proving liquidation fee accounting bug**

```
function testLiquidationWithFees() external {
    poolFactory.setLiquidationProtcolFeePercentage(0.05e4);

    _mintAndApprove(alice, tokenA, 3000 ether, address(pool));
    _mintAndApprove(bob, tokenB, 5000 ether, address(pool));

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

    vm.startPrank(alice);
    pool.supplySimple(address(tokenA), alice, 1000 ether, 0);
    pool.borrowSimple(address(tokenB), alice, 375 ether, 0);
    vm.stopPrank();

    oracleB.updateAnswer(2.5e8);

    vm.prank(bob);
    pool.liquidateSimple(address(tokenA), address(tokenB), pos, type(uint256).max);

    assertEq(pool.getBalance(address(tokenA), alice, 0), tokenA.balanceOf(address(pool)));
  }
```

