# LpPool's can become insolvent if shorters are in huge profits

Elfi LpPool solvency check ignores unrealized short profits, letting shorts accrue losses beyond pool liquidity and causing insolvency when realized.

- Payout: Contest reward
- Severity: high
- Program: Elfi Protocol
- Credited: ZeroTrust
- Disclosed: 2024-05-09
- Write-up quality: 7/10
- Original: https://github.com/sherlock-audit/2024-05-elfi-protocol-judging/issues/72
- Library page: https://bugbountylibrary.com/r/sherlock%3A2024-05-elfi-protocol%3AH-17
- Tags: domain:web3 impact:dos impact:funds-loss kind:contest platform:sherlock sev:high technique:source-review vuln:business-logic vuln:liquidation

**Target:** LpPool liquidity accounting in LpPoolQueryProcess.sol
**Root cause:** Available liquidity calculation only subtracts realized stable token losses, not unrealized losses from profitable short positions, so pool can lend out more than its true net liquidity.
**Steps:**
1. Open a large short position on BTC via UsdPool stable tokens.
2. BTC price drops, creating significant unrealized profit for the shorter (loss for LpPool).
3. Other users open long positions; LpPoolQueryProcess.getAvailableLiquidity does not account for the unrealized short profit, so it reports more available BTC than actually exists.
4. Longs borrow BTC from LpPool, reducing available liquidity to near zero.
5. Shorter realizes profit; LpPool must pay stable tokens, but lacks sufficient liquidity, causing insolvency.
**How found:** Manual review of LpPoolQueryProcess.getAvailableLiquidity and IncreasePositionProcess, noticing that only realized losses (tokenBalance.lossAmount) are subtracted, while unrealized short profits are ignored.
**Exploitation:** Attacker opens a large short position, waits for price drop to accrue large unrealized profit, then other users (or attacker) open longs to drain available liquidity; when short profit is realized, pool cannot cover the loss.
**Insight:** In perp protocols, solvency checks must include unrealized PnL of all open positions, not just realized losses; profitable shorts create liabilities that reduce available liquidity.
