# Malicious user can frontrun withdrawals from Insurance Fund to significantly decrease value of shares

Insurance Fund withdraw computes vUSD from balance()*shares/totalSupply; frontrunning with settleBadDebt drains vUSD, cutting withdrawal value.

- Payout: Contest reward
- Severity: medium
- Program: Hubble Exchange
- Credited: 0xDjango
- Disclosed: 2023-04-16
- Write-up quality: 6/10
- Original: https://github.com/sherlock-audit/2023-04-hubble-exchange-judging/issues/72
- Library page: https://bugbountylibrary.com/r/sherlock%3A2023-04-hubble-exchange%3AM-4
- Tags: 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

**Target:** InsuranceFund.sol withdraw / MarginAccount.sol settleBadDebt
**Root cause:** Withdraw redemption uses balance()*shares/totalSupply() where balance() is raw vUSD, so any vUSD outflow (bad-debt seizure) between unbond and withdraw lowers per-share value.
**Steps:**
1. User unbonds shares and waits unbonding period
2. Attacker (or chance) calls `settleBadDebt` in MarginAccount.sol before victim's `withdraw`
3. settleBadDebt -> insuranceFund.seizeBadDebt -> settlePendingObligation -> `vusd.safeTransfer(marginAccount, toTransfer)`
4. Victim calls `withdraw`; amount = `balance() * shares / totalSupply()` now computed on reduced balance
5. Victim receives fewer (potentially 0) vUSD for same shares
**How found:** Code reading of withdraw share pricing vs. bad-debt settlement path that transfers vUSD out of the fund; noted balance() dependency.
**Exploitation:** Requires pre-existing unclaimed bad debt; attacker triggers settleBadDebt just before victim's withdraw to reduce fund vUSD balance, shrinking victim's redemption.
**Insight:** When a vault prices shares off raw token balance(), any external function that moves tokens out (bad-debt seizure, fee transfer) is a frontrunnable value-reduction vector; check all outflow paths against redemption math.
