A critical issue exists in the position size validation logic where positions smaller than minTradeSize
can become trapped, preventing users from closing their positions.
The system implements two separate validations for trade sizes. The initial validation occurs in PerpMarket.checkTradeSize()
, where every trade must pass a minimum size threshold:
A second validation exists in _fillOrder()
that checks the resulting position size after the trade, but only for non-zero positions:
The critical issue stems from the unconditional nature of the first validation in checkTradeSize()
. Since every trade must pass this check before any other validation occurs, it creates a situation where position closure becomes impossible for small positions. When a user has a position smaller than minTradeSize
, any attempt to close that position would require a trade size equal to their current position. However, this trade would inevitably fail the initial size check, as the closing trade size would be smaller than the minimum required size.
Consider a scenario with minTradeSize = 50
and a current position of 30. Any attempt to close this position would require a trade of size -30, which would fail at the checkTradeSize()
validation since |-30| < 50. The trade reverts with TradeSizeTooSmall
, leaving the position trapped regardless of the user's intentions.
The implications of this issue extend beyond mere inconvenience. Users with positions smaller than minTradeSize
are forced to maintain market exposure against their will. This impacts not only positions that were intentionally opened below the minimum size but also positions that may have fallen below this threshold through various mechanisms such as partial liquidations or historical trades executed before current validations were in place.
The validation logic needs to be restructured to handle position reductions and closures appropriately. This could be achieved by modifying checkTradeSize()
to include position-closing logic, removing the initial size validation in favor of final position size checks, or implementing specific handling for position reduction scenarios that would otherwise fail the minimum size requirement.
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.