Incorrect adjusted amount calculation in getAdjustedLongAndShortTokenAmounts() always reverts
Summary
The cases are handled incorrectly, leading to the call always reverting, which means markets where the short and long token are the same will never work.
Vulnerability Detail
The function calculates the adjusted token amounts that would minimize the price impact.
It first handles the case poolLongTokenAmount < poolShortTokenAmount.
The issue is that it performs the incorrect subtraction poolLongTokenAmount - poolShortTokenAmount, which will underflow.
The same problem happens in the other block, which will always underflow (unless both amounts are 0, which is not a relevant case in a deposit context)
getAdjustedLongAndShortTokenAmounts() always reverts.
This function is called internally in executeDeposit when market.longToken == market.shortToken.
This means deposits do not work in this case: markets where the long and short token are the same will simply not work.
joestakey
medium
Incorrect adjusted amount calculation in
getAdjustedLongAndShortTokenAmounts()
always revertsSummary
The cases are handled incorrectly, leading to the call always reverting, which means markets where the short and long token are the same will never work.
Vulnerability Detail
The function calculates the adjusted token amounts that would minimize the price impact. It first handles the case
poolLongTokenAmount < poolShortTokenAmount
. The issue is that it performs the incorrect subtractionpoolLongTokenAmount - poolShortTokenAmount
, which will underflow.The same problem happens in the other block, which will always underflow (unless both amounts are 0, which is not a relevant case in a deposit context)
Impact
getAdjustedLongAndShortTokenAmounts()
always reverts. This function is called internally inexecuteDeposit
whenmarket.longToken == market.shortToken
. This means deposits do not work in this case: markets where the long and short token are the same will simply not work.Code Snippet
https://github.com/gmx-io/gmx-synthetics/blob/7be3ef2d119d9e84473e1a49f346bcdc06fd57a3/contracts/deposit/ExecuteDepositUtils.sol#L392-L402
Tool used
Manual Review
Recommendation
Duplicate of #165