# Pool amount adjustments for collateral decreases aren't undone if swaps are successful

In GMX Synthetics, swapProfitToCollateralToken returns early on successful swap, leaving a stale poolAmountAdjustment in storage that misprices all subsequent swaps.

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

**Target:** DecreasePositionCollateralUtils.swapProfitToCollateralToken / DataStore poolAmountAdjustmentKey
**Root cause:** The temporary poolAmountAdjustment is set in DataStore before the swap, but the success branch returns early inside the try block, skipping the reset to 0 that only runs after the try-catch.
**Steps:**
1. Trigger a position decrease that calls swapProfitToCollateralToken() with a non-zero poolAmountDelta.
2. Observe `dataStore.setInt(Keys.poolAmountAdjustmentKey(market, pnlToken), poolAmountDelta)` at line 454.
3. swapHandler.swap() succeeds, hitting `return (true, swapOutputAmount)` at line 472, bypassing line 480 reset.
4. Subsequent swap orders read the stale adjustment via getNextPoolAmountsParams(), skewing swap impact pricing.
**How found:** Code reading of the try-catch control flow: noticed the reset at line 480 is unreachable on the success path because of the early return inside the try block.
**Exploitation:** Any user performing swaps after a successful profit-to-collateral swap gets mispriced swap impact: some receive undeserved discounts, others undeserved penalties, extracting or losing value depending on direction.
**Insight:** When auditing try/catch swap patterns, check whether cleanup/state-reset code placed after the try block is reachable on every return path — early returns inside try silently skip it.
