Incorrect check allows users to increase their positions even when a market is disabled
If a user is increasing his position whenever a market is disabled or whenever a settlement is disabled, he will not be allowed to do so due to this check:
This is how isIncreasing
gets its value:
A position is increased in these 3 scenarios:
The size of the position was 0 which means that it always increases as there was not a position beforehand
The size of the position was over 0 (long) and he is putting more money into the long (sizeDelta is positive
The size of the position was below 0 (short) and he is putting more money into the short (sizeDelta is negative)
However, this doesn't cover the case where the user had a long position and he is increasing it in the opposite direction. Take this example:
Bob has a position size of 10
He creates a new market order with a sizeDelta of -30
His new position size is -20 which means he increased it but changed it from a long to a short
The bigger issue here is that not only can the user do that but he can also create a new order afterwards and change his position to his initial direction.
Imagine the scenario where the markets are disabled and Bob wants to increase his position from 50 to 100 but he is not allowed to do so due to the check. He can still do so because of the issue above:
Bob has a position size of 50 and he changes it to any negative value (short position)
This passes as self.size is equal 50 and his sizeDelta is equal -100, for example
Now he has a position of -50 and he can change his position to 100 by specifying a sizeDelta of 150
This will pass as self.size will equal -50 and his sizeDelta is equal to 150, self.size is < 0 but sizeDelta is not < 0
Now, he increased his position even though the market was actually disabled
Furthermore, the isIncreasing
value is used to determine whether to use the required maintenance margin or the required initial margin which could cause other huge issues like incorrect liquidations.
Incorrect check allows users to increase their positions even when a market is disabled
Manual Review
Refactor the code to return the proper value. Use the abs()
function like you do in many places in the code to properly check whether the position is increasing or decreasing.
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.