# D3VaultFunding#checkBadDebtAfterAccrue is inaccurate and can lead to further damage to both LP's and MM

D3VaultFunding's bad-debt check uses weighted collateral/debt, so a still-liquidatable pool can be flagged as bad debt, blocking liquidators and causing LP/MM losses.

- Payout: Contest reward
- Severity: medium
- Program: Dodo
- Credited: 0x52
- Disclosed: 2023-06-14
- Write-up quality: 7/10
- Original: https://github.com/sherlock-audit/2023-06-dodo-judging/issues/192
- Library page: https://bugbountylibrary.com/r/sherlock%3A2023-06-dodo%3AM-8
- Tags: domain:web3 impact:funds-loss kind:contest platform:sherlock sev:medium tech:solidity technique:source-review vuln:accounting-error vuln:liquidation

**Target:** D3VaultFunding.sol collateral ratio / bad debt check
**Root cause:** checkBadDebtAfterAccrue compares collateral ratio to 1e18 using collateralWeight and debtWeight-adjusted values, so a pool with profitable excess collateral can still show ratio < 1e18 and be misclassified as bad debt.
**Steps:**
1. Read D3VaultFunding.sol#L382-L386: collateral += min(balance-borrows, maxCollateralAmount)*collateralWeight*price; debt += (borrows-balance)*debtWeight*price.
2. Construct pool: Token A borrows 100 balance 125 price 1 collateralWeight 0.8; Token B borrows 100 balance 80 price 1 debtWeight 1.2.
3. Compute collateral = 25*0.8 = 20, debt = 20*1.2 = 24, ratio = 0.83 < 1e18.
4. Observe excess collateral 25*0.95 = 23.75 > excess debt 20, so liquidation is still profitable.
5. Trigger checkBadDebtAfterAccrue; pool flagged bad debt and external liquidators blocked.
**How found:** Code review of the collateral/debt weighting math in checkBadDebtAfterAccrue; noticed weights distort the ratio and constructed a numeric counterexample where ratio < 1e18 but liquidation remains profitable.
**Exploitation:** Once the bad-debt flag trips, only DODO can liquidate; external liquidators are excluded, so the position decays into real bad debt paid by vault LPs while the MM loses collateral that could have covered the debt.
**Insight:** When a health/bad-debt check reuses risk-adjusted (weighted) values, test whether the weights can push the ratio below the threshold while raw excess collateral still covers debt; compare weighted ratio against unweighted liquidation profitability.
