Virtual impacts can be trivially bypassed via structuring
The virtual price impact mechanism, intended to deter oracle price manipulation, can be bypassed by splitting a large order into multiple smaller orders below the threshold. An attacker could then manipulate the oracle price and execute all small orders in the same block, defeating the protection.
Source: https://github.com/sherlock-audit/2023-02-gmx-judging/issues/145
Found by
IllIllI
Summary
Virtual impacts can be trivially bypassed by chopping large orders into multiple smaller ones
Vulnerability Detail
Virtual price impacts are meant to ensure that even if a user spreads their orders over multiple pools, that they still will have a sufficient price impact to deter oracle price manipulation. The code, however, allows smaller orders to go through without incurring this global virtual price impact.
Impact
A user can get around a large virtual price impact by chopping their large orders into multiple smaller orders, below the price impact threshold, manipulate the oracle price, and have all of the small orders executed in the same block, defeating the manipulation protection.
Code Snippet
Only looks at change in position:
// File: gmx-synthetics/contracts/pricing/PositionPricingUtils.sol : PositionPricingUtils.getPriceImpactUsd() #1
209 if (!hasVirtualInventory) {
210 return priceImpactUsd;
211 }
212
213 OpenInterestParams memory openInterestParamsForVirtualInventory = getNextOpenInterestForVirtualInventory(params);
214 int256 priceImpactUsdForVirtualInventory = _getPriceImpactUsd(params.dataStore, params.market, openInterestParamsForVirtualInventory);
215 int256 thresholdPriceImpactUsd = Precision.applyFactor(params.usdDelta.abs(), thresholdImpactFactorForVirtualInventory);
216
217 @> if (priceImpactUsdForVirtualInventory > thresholdPriceImpactUsd) {
218 return priceImpactUsd;
219 }
220
221 return priceImpactUsdForVirtualInventory < priceImpactUsd ? priceImpactUsdForVirtualInventory : priceImpactUsd;
222: }
Tool used
Manual Review
Recommendation
Virtual price impact needs to always apply, in order to solve for the case of splitting a large order over multiple accounts. If orders split over multiple accounts is not a risk you want to address, the price impact should at least take into account the total position size for a single account when determining whether the threshold should apply.
Discussion
xvi10
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the virtual price impact threshold is applied per order rather than to the total position size or across all orders in a block, allowing orders below the threshold to bypass the impact.
Impact
An attacker could manipulate the oracle price and have all small orders executed in the same block, defeating the manipulation protection.
What the attacker needed
Ability to place multiple orders; orders below price impact threshold; same-block execution
The fix
The virtual price impact should always apply, or at least consider the total position size for a single account when determining the threshold.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
Virtual price impact is a fee or penalty that makes large trades more expensive to prevent price manipulation. The code only checks each order individually, so if you split a big trade into many small ones, each small trade avoids the penalty. This lets an attacker manipulate prices without paying the intended cost.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.