This repository has been archived by the owner on Dec 10, 2023. It is now read-only.
IllIllI - Users can get impact pool discounts while also increasing the virtual impact pool skew #246
Labels
Medium
A valid Medium severity issue
Reward
A payout will be made for this issue
Sponsor Confirmed
The sponsor acknowledged this issue is valid
Will Fix
The sponsor confirmed this issue will be fixed
IllIllI
medium
Users can get impact pool discounts while also increasing the virtual impact pool skew
Summary
Virtual impacts will remain consistently negative, even if most pools' impacts are balanced
Vulnerability Detail
applyDeltaToPoolAmount()
/applyDeltaToVirtualInventoryForPositions()
always modify the virtual impact, even if the virtual impact wasn't consultedImpact
Imagine a different stablecoin is one of the tokens in each of 5 markets where the other side is Eth, all five markes are part of the same virtual market, and each of the markets' swap imbalance is such that users will get a discount for swapping from Eth into the stablecoin, and the global virtual swap balance for 'stable'/Eth is flat. Users will keep swapping from Eth into the stable, which will push the individual pool towards being flat, but will push the virtual swap inventory for stables to be more and more negative. As soon as one of the five markets becomes flat, any user trying to swap Eth into a stable will suddenly be hit with the huge virtual swap impact imbalance
Code Snippet
applyDeltaToPoolAmount()
unconditionally updates the virtual inventory for swaps:https://github.com/sherlock-audit/2023-04-gmx/blob/main/gmx-synthetics/contracts/market/MarketUtils.sol#L711-L717
but the actual price impact skips the virtual impact if one of the tokens doesn't have virtual inventory:
https://github.com/sherlock-audit/2023-04-gmx/blob/main/gmx-synthetics/contracts/pricing/SwapPricingUtils.sol#L119-L121
or if the impact was positive:
https://github.com/sherlock-audit/2023-04-gmx/blob/main/gmx-synthetics/contracts/pricing/SwapPricingUtils.sol#L91-L104
Virtual position impacts have the same issue
Tool used
Manual Review
Recommendation
Don't adjust the virtual inventory for swaps if the virtual inventory wasn't consulted when calculating the impact.
The text was updated successfully, but these errors were encountered: