Variable subtracted where it should be assigned leads to getAdjustedLongAndShortTokenAmounts() reverting.
Summary
adjustedLongTokenAmount is subtracted where it should be initialized, leading to the call reverting with an underflow error, which means executeDeposit will revert in some cases.
Vulnerability Detail
The function calculates the adjusted token amounts that would minimize the price impact.
In the poolLongTokenAmount >= poolShortTokenAmount block, there is a subtraction where an assignment should be line 406
Note: currently the call reverts beforehand because of another error (handling of the poolLongTokenAmount < poolShortTokenAmount cases), which is detailed in another report. Once you have fixed it, the call will revert line 406 because of the problem described in this report.
Impact
getAdjustedLongAndShortTokenAmounts() always reverts in the case where poolLongTokenAmount >= poolShortTokenAmount for markets where market.longToken == market.shortToken.
joestakey
medium
Variable subtracted where it should be assigned leads to
getAdjustedLongAndShortTokenAmounts()
reverting.Summary
adjustedLongTokenAmount
is subtracted where it should be initialized, leading to the call reverting with an underflow error, which meansexecuteDeposit
will revert in some cases.Vulnerability Detail
The function calculates the adjusted token amounts that would minimize the price impact. In the
poolLongTokenAmount >= poolShortTokenAmount
block, there is a subtraction where an assignment should be line 406This line below will always revert, as
adjustedLongTokenAmount
is not initialized, meaningadjustedLongTokenAmount - longTokenAmount
will underflow.Note: currently the call reverts beforehand because of another error (handling of the
poolLongTokenAmount < poolShortTokenAmount
cases), which is detailed in another report. Once you have fixed it, the call will revert line 406 because of the problem described in this report.Impact
getAdjustedLongAndShortTokenAmounts()
always reverts in the case wherepoolLongTokenAmount >= poolShortTokenAmount
for markets wheremarket.longToken == market.shortToken
.Code Snippet
https://github.com/gmx-io/gmx-synthetics/blob/7be3ef2d119d9e84473e1a49f346bcdc06fd57a3/contracts/deposit/ExecuteDepositUtils.sol#L392-L402
Tool used
Manual Review
Recommendation
Duplicate of #164