# `Controller`'s core function of Rebalance will not rebalance when rebalance is needed in some cases, breaking core functionality

RebalanceLib.checkMarket returns canRebalance=false when a market's collateral is zero, so Controller.rebalanceGroup skips rebalancing into new zero-collateral markets.

- Payout: Audit contest
- Severity: medium
- Program: Perennial
- Found by: panprog
- Disclosed: 2024-08-17
- Write-up quality: 6/10
- Original: https://github.com/sherlock-audit/2024-08-perennial-v2-update-3-judging/issues/20
- Library page: https://bugbountylibrary.com/r/sherlock%3A2024-08-perennial-v2-update-3%3AM-3
- Tags: area:web3 domain:web3 impact:funds-loss kind:contest platform:sherlock sev:medium tech:solidity technique:source-review vuln:accounting-error vuln:business-logic

**Target:** Perennial Account Controller / RebalanceLib
**Root cause:** checkMarket short-circuits to canRebalance=false whenever marketCollateral is zero, ignoring a non-zero targetCollateral, so a market needing funding from zero is never rebalanced.
**Steps:**
1. Configure rebalance for market1 (0.5) and market2 (0.5) with threshold 0.2; collateral 50/50.
2. Update config to market1 (0.4), market2 (0.4), market3 (0.2) where market3 has 0 collateral.
3. Call `Controller.rebalanceGroup`; it reverts/skips because `RebalanceLib.checkMarket` returns `(false, targetCollateral)` for market3.
4. Observe that adding 1 wei to market3 makes rebalance succeed, confirming the zero-collateral short-circuit.
**How found:** Code reading of RebalanceLib.checkMarket revealed the early return on zero collateral; comparing behavior with 1 wei of collateral showed the inconsistency.
**Insight:** When auditing ratio-based rebalancing logic, check zero-value edge cases against non-zero targets: a zero current balance is the most common state for newly added markets and is exactly when rebalancing is most needed.

