Part 2

Zaros
PerpetualsDEXFoundrySolidity
70,000 USDC
View results
Submission Details
Severity: medium
Invalid

Minimum Trade Size Validation Prevents Closure of Sub-Minimum Positions Forcing Users to Maintain Market Exposure

Summary

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:

if (sizeDeltaX18.abs().intoUD60x18().lt(ud60x18(self.configuration.minTradeSizeX18))) {
revert Errors.TradeSizeTooSmall();
}

A second validation exists in _fillOrder() that checks the resulting position size after the trade, but only for non-zero positions:

if (ctx.newPositionSizeX18.isZero()) {
oldPosition.clear();
} else {
if (ctx.newPositionSizeX18.abs().lt(sd59x18(int256(uint256(perpMarket.configuration.minTradeSizeX18))))) {
revert Errors.NewPositionSizeTooSmall();
}
oldPosition.update(ctx.newPosition);
}

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.

Example Scenario

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.

Impact

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.

Recommendation

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.

Updates

Lead Judging Commences

inallhonesty Lead Judge
4 months ago
inallhonesty Lead Judge 4 months ago
Submission Judgement Published
Invalidated
Reason: Incorrect statement

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.