# Updating leverage changes the cross net and cross available value

De-leveraging a cross-margin position raises used value faster than margin, lowering cross net value and enabling unfair liquidation.

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

**Target:** perpetuals cross-margin account accounting (AccountProcess/PositionMarginProcess)
**Root cause:** Cross net value subtracts totalUsedValue*liquidationFactor while adding initial margin; de-levering increases both margin and used amount, but the liquidation-factor multiplier grows faster than the fixed margin, so net value drops.
**Steps:**
1. Deposit USDC and open a cross LONG position with leverage L1 via `createOrderRequest` + `executeOrder`.
2. Record `getCrossMMRTapir` crossValue.
3. Call `createUpdateLeverageRequest` with lower leverage L2 (same qty) and `executeUpdateLeverageRequest`.
4. Observe crossValue decreased (e.g. 194703.18 -> 190981.31) despite unchanged position quantity.
**How found:** Code-reading of `_getCrossNetValue` and the leverage-update path in PositionMarginProcess; noticed margin and used value both change on de-lever but used value is multiplied by liquidation factor, then confirmed with a coded PoC comparing crossValue before/after.
**Exploitation:** Attacker (or any user) de-levers a cross position to artificially reduce their own cross net value, or increases leverage to inflate it, enabling over-borrowing or triggering unfair liquidation of positions whose real risk is unchanged.
**Insight:** In margin accounting, any parameter that scales a subtracted term (liquidation factor) while the added margin term is fixed will break monotonicity under leverage changes; test net-value invariants across leverage updates, not just at position open.
