# It is nearly impossble for Liquidators to use liquidatePosition() to fully pay off a non bad-debt position

LoopFi CDPVault liquidation requires repayAmount*penalty to exactly equal time-accruing debt, so liquidators can't fully repay positions, leaving bad debt.

- Payout: Audit contest
- Severity: high
- Program: LoopFi
- Found by: pkqs90
- Disclosed: 2025-02-17
- Write-up quality: 6/10
- Original: https://github.com/code-423n4/2024-07-loopfi-findings/issues/62
- Library page: https://bugbountylibrary.com/r/c4%3A2024-07-loopfi%3AH-11
- 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.liquidatePosition() liquidation logic
**Root cause:** Full-repay branch only triggers when deltaDebt == calcTotalDebt(debtData); since debt accrues per second, any mismatch underflows in calcDecrease() and reverts, so exact full repayment is practically impossible.
**Steps:**
1. Liquidator computes repayAmount such that repayAmount*liquidationPenalty must be exactly equal to calcTotalDebt(debtData).
2. Transaction is delayed; debt accrues, so deltaDebt > maxRepayment at execution.
3. calcDecrease() underflows and reverts, blocking full liquidation.
4. Position retains residual debt, accumulating bad debt over time.
**How found:** Code reading of liquidatePosition(): noticed the strict equality `deltaDebt == maxRepayment` branch and that the else path calls calcDecrease() which underflows when deltaDebt exceeds debt, combined with per-second debt accrual.
**Exploitation:** Not an attacker exploit; a liquidator attempting full repayment reverts due to the time-window mismatch between off-chain estimate and on-chain debt accrual, preventing clean liquidation.
**Insight:** When a contract branches on exact equality against a value that accrues over time (interest index), the non-equal path often underflows or leaves dust; check whether full-repayment paths are reachable given block-timestamp drift.

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

**virtualDebt view used to estimate exact debt**

```
function virtualDebt(address position) external view returns (uint256) {
>         return calcTotalDebt(_calcDebt(positions[position]));
```

