price is 50
In this case, the profitLossTimesTen is 42 * 5 * 10 / 50 = 42
We can also think of the following condition B.
priceShift is 5
position.additionalSize is 40
price is 50
In this case, the profitLossTimesTen is 40 * 5 * 10 / 50 = 40
In condition A the PnL is 3 and condition B, PnL is 4. It is unfair for users.
Impact
Incorrect calculation of _profitLoss will lead to user fund loss
Bony
medium
Wrong calculation in
PerpMath._profitLoss
Summary
PerpMath._profitLoss function doesn't calculate the
PnL
correctlyVulnerability Detail
We can think of the following condition A.
priceShift
is 5position.additionalSize
is 42price
is 50 In this case, theprofitLossTimesTen
is42 * 5 * 10 / 50 = 42
We can also think of the following condition B.
priceShift
is 5position.additionalSize
is 40price
is 50 In this case, theprofitLossTimesTen
is40 * 5 * 10 / 50 = 40
In condition A thePnL
is 3 and condition B,PnL
is 4. It is unfair for users.Impact
Incorrect calculation of
_profitLoss
will lead to user fund lossCode Snippet
https://github.com/sherlock-audit/2023-12-flatmoney/blob/bba4f077a64f43fbd565f8983388d0e985cb85db/flatcoin-v1/src/libraries/PerpMath.sol#L175
Tool used
Manual Review
Recommendation
Duplicate of #286