# Under certain circumstances bad debt will cause first depositor to lose funds

When bad debt liquidation zeroes a pool's totalDepositAssets while shares remain, the next depositor's shares mint 1:1 and absorb prior losses.

- Payout: Audit contest
- Severity: medium
- Program: Sentiment
- Found by: A2-security
- Disclosed: 2024-08-07
- Write-up quality: 6/10
- Original: https://github.com/sherlock-audit/2024-08-sentiment-v2-judging/issues/319
- Library page: https://bugbountylibrary.com/r/sherlock%3A2024-08-sentiment-v2%3AM-14
- Tags: area:web3 domain:web3 impact:funds-loss kind:contest platform:sherlock sev:medium tech:evm tech:solidity technique:source-review vuln:accounting-error vuln:liquidation vuln:share-inflation

**Target:** Lending pool share accounting (PositionManager/Pool)
**Root cause:** rebalanceBadDebt can drive totalDepositAssets to 0 while totalDepositShares stays positive; _convertToShares mints 1:1 when totalAssets==0, so a new depositor's shares are diluted by existing shares.
**Steps:**
1. Alice deposits 100 tokens, gets 100 shares (first depositor, 1:1).
2. Bob borrows all 100 tokens; totalDepositAssets==totalBorrowAssets.
3. Interest accrues to 150; Bob becomes liquidatable but isn't liquidated.
4. Bob's debt goes bad; owner calls `liquidateBadDebt(position)` -> `rebalanceBadDebt` sets totalDepositAssets and totalBorrowAssets to 0 while totalDepositShares remains 100.
5. Charlie deposits 100 assets; `_convertToShares` returns assets when totalAssets==0, minting 100 shares 1:1.
6. Charlie now holds 100 of 200 shares but pool has only 100 assets, absorbing Alice's socialized loss.
**How found:** Code review of liquidateBadDebt/rebalanceBadDebt and _convertToShares, noticing the totalAssets==0 branch mints 1:1 despite outstanding shares after a full bad-debt write-off.
**Insight:** When auditing share-based lending pools, check the totalAssets==0 minting branch against scenarios where bad-debt socialization zeroes assets but leaves shares outstanding—first-depositor-style dilution can recur after liquidations, not just at pool creation.

