Skip to content
Access control Audit finding Intermediate

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

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:

  1. Margin Management Functions:

    • addMargin() - Allows adding margin to existing positions
    • removeMargin() - Allows removing margin from positions
    • setPositionLeverage() - Allows changing position leverage
  2. Collateral Management Functions:

    • deposit() - Allows depositing free collateral
    • withdraw() - Allows withdrawing free collateral
    • depositTo() - Allows depositing to other accounts
    • depositFromSpot() - Allows depositing from spot account
    • withdrawToSpot() - 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


The original report as published on Code4rena, by BenRai. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.

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.

More by BenRai

View all

13 more disclosed reports, best first.

More from GTE Perps and Launchpad

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Broken access control

The lesson behind this report.

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.