When calculating the price impact from an increase position, we first calculate what is the expected amount without price impact and what is the actual amount. Based on the difference we get the price impact. The problem in Gamma implementation is that for both short and long positions, we use min price of index token to get the size delta in token when we should be using max price for long positions and min price for short positions.
Taking a look into PositionUtils::getExecutionPriceForIncrease() in GMX code, we first calculate baseSizeDeltaInTokens which is the amount without price impact (this is semantically the same as expected delta in size tokens in Gamma).
We see that there is different calculation of the amount of tokens based on if the position is short or long, while in Gamma (VaultReader::getPriceImpactInCollateral()) we always use min price:
Incorrect price impact calculations leading to unfair shares allocation since users' deposits are adjusted based on the calculated price impact when minting shares.
Manual review.
Consider checking if position is long or short and use the correct price to match the actual calculation in GMX.
Please read the CodeHawks documentation to know which submissions are valid. If you disagree, provide a coded PoC and explain the real likelihood and the detailed impact on the mainnet without any supposition (if, it could, etc) to prove your point.
Likelihood: High, every long position. Impact: Informational/Very Low. Long positions should use the ask price to calculate `expectedSizeInTokensDelta`. This will lead to a slight miscalculation of the shares. However, since the same calculation is applied to every user, and all users are in the same position (short or long), it won’t have a real impact. Moreover, both prices always have a very small difference.
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.