When users open a position or increase an existing position, the system uses requiredInitialMarginUsdX18
as the margin ratio. For position reduction or closing, it uses requiredMaintenanceMarginUsdX18
. However, Zaros overlooks the possibility of opening a large position in the opposite direction while reducing a position, leading to situations where requiredMaintenanceMarginUsdX18
is used for calculations when requiredInitialMarginUsdX18
should be applied.
The program only considers the direction of position change when calculating requiredMarginUsdX18. When the position change is sufficiently large, it effectively equates to opening a new position. Logically, requiredInitialMarginUsdX18 should be used in such cases, but the program fails to account for this scenario.
This vulnerability allows users to exploit the system by:
Opening a minimal position in the opposite direction of their intended trade.
Subsequently opening a large position in their desired direction.
This method enables users to bypass the requiredInitialMarginUsdX18 restriction, effectively increasing their maximum leverage ratio. The consequences of this exploit are significant:
Increased Systemic Risk: Higher leverage ratios amplify the potential for cascading liquidations in volatile market conditions.
Unfair Advantage: Knowledgeable users can access higher leverage than intended, creating an uneven playing field.
Undermined Risk Management: The protocol's risk management mechanisms are compromised, potentially leading to insolvency in extreme cases.
Manual Review.
Implement a check to ensure that when closing or reducing a position, the absolute value of the traded position does not exceed the absolute value of the original position.This can be achieved by:
Comparing the new position size to the old position size.
If the absolute value of the new position exceeds the old one, treat it as opening a new position and use requiredInitialMarginUsdX18 in the opposite.
Only use requiredMaintenanceMarginUsdX18 when the absolute value of the new position is less than or equal to the old position.
This approach will prevent users from exploiting the system to gain excessive leverage and maintain the intended risk management parameters of the protocol.
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.