# When vault's market weight is set to 0 to remove the market from the vault, vault's leverage in this market is immediately set to max leverage risking position liquidation

Setting a Perennial vault market weight to 0 makes rebalance withdraw collateral down to exact margin, leaving the position at max leverage and risking liquidation or a bricked vault.

- Payout: Contest reward
- Severity: medium
- Program: Perennial V2 3
- Credited: panprog
- Disclosed: 2024-02-28
- Write-up quality: 6/10
- Original: https://github.com/sherlock-audit/2024-02-perennial-v2-3-judging/issues/8
- Library page: https://bugbountylibrary.com/r/sherlock%3A2024-02-perennial-v2-3%3AM-1
- Tags: domain:web3 impact:dos impact:funds-loss kind:contest platform:sherlock sev:medium tech:evm tech:solidity technique:source-review vuln:business-logic vuln:dos vuln:liquidation

**Target:** Perennial V2 vault StrategyLib rebalance / market allocation
**Root cause:** StrategyLib computes marketCollateral as margin + (collateral-totalMargin)*weight; with weight=0 collateral collapses to marketContext.margin (minimum margin for max leverage) while the position stays open at minPosition.
**Steps:**
1. Open vault positions across two markets via deposits (leverage applied).
2. Owner calls `vault.updateWeights([1.0, 0])` to remove the second market.
3. Trigger rebalance with a small withdrawal: `vault.update(user, 0, smallDeposit, 0)` then `updateOracle()`.
4. Observe pos2 unchanged (206187) but col2 drops from 2002000000 to 800796548, i.e. exactly margin at max leverage.
5. Any subsequent price move against the maker pushes collateral below margin; next vault action reverts on settle, bricking the vault until liquidation.
**How found:** Code reading of StrategyLib rebalance math: noticed weight=0 zeroes the weighted collateral term, leaving only margin, while target.position is floored at minPosition so the position is not closed.
**Exploitation:** Admin sets weight to 0 expecting market removal; first rebalance withdraws max collateral leaving position at max leverage. If skew prevents closing, position sits at max leverage until liquidated, losing depositor funds; combined with margin-settle reverts the vault can be temporarily bricked with no admin recovery (re-setting weight reverts during rebalance).
**Escalation:** Confluence with issue #23 (settle reverts when collateral between maintenance and margin) turns a liquidation-fee cost into a vault-wide DoS.
**Insight:** When a weight/allocation parameter is zeroed to 'remove' an asset, check whether the position is actually closed or merely left at the minimum-margin floor; minPosition/maxPosition clamps can keep exposure alive at max leverage.
