It is possible to increase a position when neither the market nor the settlement are enabled. Also during settlement, the margin required to back the position will no be the highest
When someone creates a market order, there is a check to ensure that if the market or the settlement are not enabled it is not possible to increase the size of the position. So essentially the user would only be able to decrease it. This check is implemented as follows:
Looking at what is considered increasing a position we can see that it only handle the cases where the size is increase in the same direction of the already active size and when a position had no previous size. For example, if the current size is -300 and the delta size is -100 it is increasing in the same direction and it is considered an increase. However, this function is not taking into account the direction swapping. If a user had a short position of -100 and now wants to long the token by +1000, he will get a position of +900 which has increased the open interest and in the coded implementation has not considered it as an increase, so that means that he has bypassed these 2 security checks for the market and the settlement enabled.
Also during the settlement, the selected margin to be required to back the position choose the least one because it considered that the position is being decreased.
As we can see, the validation for the margin requirement will always select the maintenance margin which is always smaller than the initial maintenance margin, that is because the ctx.shouldUseMaintenanceMargin
will be true. So the result is that the user will need less margin than it would to if it was considered an increase.
It is true that if a user wants to exploit this issue, he needs to have an active position reversed before the market or the settlement gets disabled. That is because opening a position when you did not have any size it will be considered an increase and it will revert due to the market disabled. For example, if a user wants to increase a long position, he will need to have an active short position before, and if he wants to increase a short position, he will need a long position before.
The user can just open a position for the maximum amount of markets with a little size and wait when the market gets disabled, then he can execute this issue.
Medium, the open interest will increase even when the market or the settlement is disabled
Manual review
I would not consider an increase using these 3 conditions, I would use instead the change of the open interest once the trade is accounted. If the open interest increases compared to the previous one it will be 100% an increase of a position. If it does not increase it means that the position is decreasing his size.
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.