Part 2

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

Disable market limitation can be bypassed

Summary

The isNotionalValueIncreasing function incorrectly checks if a new position is being opened. A user with an existing position can open a smaller position in the opposite direction, bypassing the disabled market check.

Vulnerability Details

When a market is disabled the protocol allows users to decrease positions, but it aims to prevent increasing them. The check in isNotionalValueIncreasing does not cover all cases allowing users to open a smaller position in the opposite direction which should still be considered and increase and disallowed when the market is disabled.

SD59x18 sizeDeltaX18 = sd59x18(sizeDelta);
SD59x18 sizeX18 = sd59x18(self.size);
// If position is being opened (size is 0) or if position is being increased (sizeDelta direction is same as
// position size)
// For a positive position, sizeDelta should be positive to increase, and for a negative position, sizeDelta
// should be negative to increase.
// This also implicitly covers the case where if it's a new position (size is 0), it's considered an increase.
return sizeX18.isZero() || (sizeDeltaX18.add(sizeX18).abs() > sizeX18.abs());

Example:

sizeDeltaX18 = -25

sizeX18 = 24

(-25 + 24).abs() > 24 = -1.abs > 24 = 1 > 24 = false; when we are closing the long and oppening a short position.

The check is also used for selecting between initial and maintenance margin, allowing users to use maintenance margin in some cases when opening positions in the opposite direction.

Impact

A trader can increase their position size in the opposite direction even when the market is disabled, and can use their maintenance margin to do so.

Recommendations

In the Position::isNotionalValueIncreasing, adjust the return statement to account for cases where a position is being opened in the opposite direction.

Updates

Lead Judging Commences

inallhonesty Lead Judge 6 months ago
Submission Judgement Published
Invalidated
Reason: Out of scope

Support

FAQs

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