Protocol Disable Functionality Bypass Allows Critical Operations During Emergency Shutdown
Several margin and collateral management functions in the perpetuals protocol lack the onlyActiveProtocol modifier, so they remain callable after the emergency shutdown flag is set to false. A user could still change leverage, remove margin and withdraw collateral while the protocol is meant to be halted.
BenRai Follow with anchabadze and Riceee
Originally disclosed on Code4rena
Submitted by BenRai, also found by anchabadze and Riceee
perps/PerpManager.sol#L97perps/PerpManager.sol#L136-L139
The protocol’s emergency shutdown mechanism fails to properly restrict critical margin and collateral management functions, allowing users to continue modifying positions and managing funds even when the protocol is disabled.
The GTE perpetuals protocol implements an emergency shutdown mechanism through the deactivateProtocol() function in AdminPanel.sol, which sets the active flag in the clearing house to false. This mechanism is designed to halt all trading and position management activities during emergencies or maintenance periods.
The onlyActiveProtocol modifier is defined in PerpManager.sol:
modifier onlyActiveProtocol() override (AdminPanel, LiquidatorPanel) {
if (!StorageLib.loadClearingHouse().active) revert ProtocolNotActive();
_;
}
However, several critical functions that should be restricted during protocol emergency shutdown are missing this modifier:
-
Margin Management Functions:
addMargin()- Allows adding margin to existing positionsremoveMargin()- Allows removing margin from positionssetPositionLeverage()- Allows changing position leverage
-
Collateral Management Functions:
deposit()- Allows depositing free collateralwithdraw()- Allows withdrawing free collateraldepositTo()- Allows depositing to other accountsdepositFromSpot()- Allows depositing from spot accountwithdrawToSpot()- Allows withdrawing to spot account
The inconsistency becomes apparent when comparing these functions to trading functions like placeOrder(), which correctly includes the onlyActiveProtocol modifier and properly reverts when the protocol is disabled.
[!NOTE] The protocol correctly restricts order placement, amendment, and cancellation functions, but fails to apply the same restrictions to margin and collateral management functions.
This creates a scenario where, during an emergency shutdown when the protocol needs to halt all user activities, a user can still increase his leverage, remove margin from a subaccount and withdraw the collateral from the protocol.
Recommended mitigation steps
Add the onlyActiveProtocol modifier to all margin and collateral management functions that should be restricted during protocol shutdown.
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 access-control modifier that checks the protocol's active flag was simply not applied to the margin and collateral functions, unlike the trading functions.
Impact
During an emergency shutdown a user could still raise leverage, remove margin and withdraw collateral, undermining the halt the operators intended.
What the attacker needed
Protocol has been deactivated; user has an existing position or collateral
The fix
The onlyActiveProtocol modifier should be added to all margin and collateral management functions that must be restricted during shutdown.
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.
The protocol has an emergency stop button that is supposed to freeze activity. Some functions that move money and change risk settings were not wired to that stop button, so they keep working while everything else is frozen. That means someone could pull funds out or raise their risk during a shutdown the operators intended to lock down.
What is Access control?
A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.