# Virtual swap balances don't take into account token prices

GMX virtual swap inventory tracked raw token amounts without price conversion, letting traders exploit cross-market impact discounts between differently-priced collateral tokens.

- Payout: Contest reward
- Severity: medium
- Program: Gmx
- Credited: IllIllI
- Disclosed: 2023-04-20
- Write-up quality: 6/10
- Original: https://github.com/sherlock-audit/2023-04-gmx-judging/issues/251
- Library page: https://bugbountylibrary.com/r/sherlock%3A2023-04-gmx%3AM-9
- Tags: domain:web3 impact:funds-loss kind:contest platform:sherlock sev:medium tech:evm tech:solidity technique:source-review vuln:accounting-error vuln:business-logic

**Target:** GMX Synthetics swap/deposit/withdrawal virtual inventory accounting
**Root cause:** applyDeltaToVirtualInventoryForSwaps stores the raw token delta without converting the collateral token to the virtual token's price, so impacts across markets sharing a virtual pool are mis-scaled.
**Steps:**
1. Observe virtual swap inventory deltas in `SwapUtils._swap()` applied via `applyDeltaToPoolAmount` and stored unaltered in `MarketUtils.applyDeltaToVirtualInventoryForSwaps()`.
2. Note same raw-delta storage for deposits, increases, decreases, withdrawals.
3. Identify two markets sharing a virtual impact pool whose collateral tokens differ in price (e.g. USDC vs USDT, historically 0.86-1.20).
4. Swap through the market with smaller impact to push impact negative, then swap through the other market where the same funds yield a larger positive impact.
5. Collect the excess impact discount, draining discounts available to legitimate traders.
**How found:** Code review of virtual inventory accounting: noticed virtual position impacts assume virtual token equals index token, but virtual swap impacts involve a different collateral token, implying a missing exchange-rate conversion.
**Exploitation:** Precondition: two markets sharing a virtual impact pool with differently-priced collateral tokens. Attacker routes swaps to accumulate negative impact cheaply in one market and harvest a larger positive impact in the other, extracting discount value at the expense of honest traders.
**Insight:** When a shared accounting pool aggregates amounts across tokens, check whether deltas are normalized to a common unit; any raw-amount storage across differently-priced assets is a cross-market arbitrage surface.
