# Flashlender.sol#flashLoan() should use mintProfit() to mint fees, as the current implementation may lead to locked up WETH in PoolV3

Flashlender credits flash-loan fees via repayCreditAccount instead of mintProfit, leaving expectedLiquidity understated so WETH withdrawals underflow and lock funds.

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

**Target:** Flashlender.sol flashLoan / PoolV3 accounting
**Root cause:** flashLoan() calls pool.repayCreditAccount(total-fee, fee, 0), which mints shares but does not increase expectedLiquidity, whereas mintProfit() correctly raises expectedLiquidity for non-interest profit.
**Steps:**
1. Observe flashLoan() calls `pool.repayCreditAccount(total - fee, fee, 0)` after transferring amount+fee to pool.
2. Note repayCreditAccount mints treasury shares but passes `expectedLiquidityDelta: -loss` (0 here), so expectedLiquidity is unchanged.
3. Compare with `mintProfit(amount)` which sets `expectedLiquidityDelta: amount`.
4. Accumulate flash-loan fees so WETH balance > expectedLiquidity.
5. Have lpETH holders withdraw; `_withdraw` applies `expectedLiquidityDelta: -assetsSent`, underflowing once withdrawals exceed stale expectedLiquidity, reverting and locking WETH.
**How found:** Code review comparing how CDPVault sends liquidation penalty via mintProfit() versus Flashlender using repayCreditAccount with profit==fee; noticed expectedLiquidity delta mismatch in PoolV3.
**Exploitation:** No attacker profit path; fees accrue and WETH becomes unwithdrawable because expectedLiquidity is understated relative to actual balance, causing withdrawal reverts/underflow.
**Insight:** When a pool tracks expectedLiquidity separately from token balance, audit every path that mints shares/profit and verify it updates expectedLiquidity consistently; fee/profit entry points that reuse repay/interest logic often skip the delta.

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

**FlashLoan fee accounting bug in repayCreditAccount call**

```
underlyingToken.transferFrom(address(receiver), address(pool), total);
@>      pool.repayCreditAccount(total - fee, fee, 0);
```

**mintProfit updates expectedLiquidity correctly**

```
function mintProfit(uint256 amount) external creditManagerOnly {
        _mint(treasury, amount);

        _updateBaseInterest({
@>          expectedLiquidityDelta: amount.toInt256(),
```

