Max Leverage Reduction Not Enforced for Legacy Positions
The system fails to enforce reduced maximum leverage limits when opening new positions, allowing users to maintain higher leverage than the current market maximum by leveraging legacy position leverage settings. An attacker could bypass risk management controls, leading to higher risk of bad debt.
Submitted by BenRai
perps/types/Market.sol #L382-L390
The system fails to enforce reduced maximum leverage limits when opening new positions, allowing users to maintain higher leverage than the current market maximum by leveraging legacy position leverage settings.
Finding description
The GTE perpetuals system implements leverage controls through the maxOpenLeverage parameter in market settings, which is intended to limit the maximum leverage users can employ. However, the system has a critical flaw in how it handles leverage validation during position opening.
The leverage validation system works as follows:
MarketLib.assertMaxLeverage()validates that leverage is between 1x and the currentmaxOpenLeveragesetting- This validation is only called in
PerpManager.setPositionLeverage()when users explicitly set their position leverage - However, when positions are opened through order execution, no leverage validation occurs against the current
maxOpenLeverage
The position opening flow works through the following components:
- Orders are placed via
ClearingHouse.placeOrder()→Market.placeOrder()→CLOBLib.placeOrder() - When orders are filled,
ClearingHouse._processTakerFill()processes the trade - The leverage for a new position is determined in
ClearingHouseLib._getPostiion()by callingMarket.getPositionLeverage()
function getPositionLeverage(Market storage self, address account, uint256 subaccount)
internal
view
returns (uint256 leverage)
{
leverage = self.position[account][subaccount].leverage;
if (leverage == 0) leverage = 1e18; // default leverage
}
When a user opens a new position, the system uses their existing position leverage (stored in self.position[account][subaccount].leverage) without checking if it exceeds the current maxOpenLeverage. This means:
- Legacy High Leverage: Users who previously set high leverage (e.g., 50x) can continue opening new positions at that leverage even after
maxOpenLeverageis reduced (e.g., to 25x) - Position Size Increases: Users can increase their position size at the old high leverage, effectively bypassing the reduced leverage limits
- Admin Intent Bypass: When administrators reduce
maxOpenLeveragefor risk management, existing users can circumvent these restrictions
Higher leverage than intended by the admin brings higher risk for bad debt in the market which must be covered by the endurance fund.
Impact Explanation
High Impact - This vulnerability allows users to bypass critical risk management controls. When administrators reduce maximum leverage limits (typically during high volatility or market stress), the intended risk reduction is completely circumvented. Users can maintain dangerous leverage levels that could lead to cascading liquidations and systemic risk to the protocol.
Likelihood Explanation
High Likelihood - This issue will occur whenever administrators reduce maxOpenLeverage settings, which is a common risk management practice during volatile market conditions. Any user with existing high-leverage positions can easily exploit this by not adjusting the leverage of their position manually.
Recommendation
Add leverage validation when the leverage for a new position is determined to ensure compliance with current maxOpenLeverage settings. If the position leverage is too high, either revert the function call or adjust the leverage to maxOpenLeverage.
Additionally, consider enforcing that an open position with leverage exceeding the new maxOpenLeverage can only be reduced in size, not increased.
View detailed Proof of Concept
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the leverage validation is only performed when users explicitly set their position leverage, not when positions are opened through order execution, so the stored leverage is used without checking against the current maximum.
Impact
Users can bypass reduced leverage limits, increasing the risk of bad debt that must be covered by the endurance fund.
What the attacker needed
User has an existing position with high leverage; Admin reduces maxOpenLeverage
The fix
Add leverage validation when determining the leverage for a new position to ensure compliance with current maxOpenLeverage settings, and consider restricting increases for positions exceeding the new limit.
How it was found
- User sets a high leverage (e.g., 50x) when maxOpenLeverage is 50x.
- Admin reduces maxOpenLeverage to 25x.
- User opens a new position without changing leverage.
- The system uses the stored 50x leverage without checking against the new 25x limit.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
In a trading system, there is a limit on how much you can borrow compared to your own money (leverage). The system only checks this limit when you explicitly set your leverage, but not when you open a new trade. So if you set a high leverage before the limit was lowered, you can keep opening new trades at that high leverage, bypassing the new safety limit.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.