# CDPVault.sol#liquidatePositionBadDebt() should not set profit = 0 when calling pool.repayCreditAccount()

Bad-debt liquidation passes profit=0 to repayCreditAccount, so accrued interest paid by liquidator is stranded in PoolV3 instead of rewarding lpETH stakers.

- 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/57
- Library page: https://bugbountylibrary.com/r/c4%3A2024-07-loopfi%3AH-12
- 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:liquidation

**Target:** CDPVault.sol liquidatePositionBadDebt / PoolV3.repayCreditAccount
**Root cause:** liquidatePositionBadDebt calls pool.repayCreditAccount(debtData.debt, 0, loss), hardcoding profit to zero even though the liquidator's repayAmount covers accrued interest beyond principal; PoolV3 only mints treasury shares when profit>0, so the interest portion of WETH remains in the pool with no lpETH to redeem it.
**Steps:**
1. Position has debt principal 1000, accrued interest 500, totalDebt 1500, collateral value 1600, discount 90% -> discounted value 1440.
2. Liquidator calls `liquidatePositionBadDebt(owner, repayAmount)`; takeCollateral=full collateral, repayAmount=1440, loss=1500-1440=60.
3. Vault transfers 1440 WETH from liquidator to pool, then calls `pool.repayCreditAccount(1000, 0, 60)`.
4. PoolV3 burns treasury shares for loss=60 but mints nothing for the 440 interest paid; 440 WETH stays in PoolV3 unbacked by lpETH.
5. Fix: call `pool.repayCreditAccount(debtData.debt, debtData.accruedInterest, loss)` and change PoolV3 to independent `if (profit>0)` / `if (loss>0)` branches.
**How found:** Code review of liquidatePositionBadDebt comparing the repayAmount (which includes interest) against the hardcoded profit=0 argument, then tracing PoolV3.repayCreditAccount to see profit is only credited when >0; noted the pattern was copied from GearboxV3 where profit semantics differ.
**Exploitation:** Any liquidator liquidating a bad-debt position triggers the accounting mismatch; the interest portion of the repayment is trapped in PoolV3, diluting lpETH stakers who bear the loss without receiving the corresponding profit.
**Insight:** When a liquidation path computes loss = totalDebt - repayAmount but passes only principal as repaidAmount, check whether the interest delta is credited as profit; copied accounting from another protocol (GearboxV3) often carries mismatched semantics.

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

**Bad debt liquidation call passing profit=0**

```
pool.repayCreditAccount(debtData.debt, 0, loss); // U:[CM-11]
```

