DeFiFoundry
50,000 USDC
View results
Submission Details
Severity: high
Invalid

PerpetualVault Swap Approvals Can Permanently Block Future Trades Due to Non-Zero Allowances

Brief

The PerpetualVault protocol’s token approval mechanism with the GMXProxy contract unintentionally leaves behind non-zero allowances after failed or canceled swaps. Because SafeERC20 prevents changing a non-zero allowance to another non-zero value, a leftover allowance blocks all new approval attempts for the same token-spender pair, leading to a permanent DoS for future swap operations.

Details

The core issue comes from how the protocol handles token approvals on retries when a swap fails or is canceled. Specifically, the GmxProxy contract calls safeApprove without resetting any previously granted allowance. Below is a simplified code excerpt from GmxProxy.createOrder illustrating this:

function createOrder(
Order.OrderType orderType,
IGmxProxy.OrderData memory orderData
) public returns (bytes32) {
if (
orderType == Order.OrderType.MarketSwap ||
orderType == Order.OrderType.MarketIncrease
) {
IERC20(orderData.initialCollateralToken).safeApprove(
address(gmxRouter),
orderData.amountIn
);
}
...
}

When a MarketSwap order is canceled, no mechanism exists to revert this non-zero approval back to zero. The SafeERC20 library enforces a rule disallowing safeApprove(...) from a non-zero to another non-zero amount, so these lingering approvals block future attempts to re-approve the same token. The afterOrderCancellation path in GmxProxy and PerpetualVault likewise never resets the leftover allowance:

function afterOrderCancellation(...) external {
// Retrying the swap is attempted...
// but no reset of the past non-zero approval occurs here
nextAction.selector = NextActionSelector.SWAP_ACTION;
...
}

Because the protocol always calls safeApprove(...) again on every retry, the remaining non-zero allowance triggers SafeERC20’s revert condition, causing further swaps for that token pair to fail irreversibly unless manual intervention zeroes out the approval.

Specific Impact

This flaw introduces a permanent DoS on swap operations for any token pair that experiences a failed or canceled swap with a leftover non-zero allowance, preventing all subsequent trading for affected tokens and requiring manual fixes to restore normal functionality.

Updates

Lead Judging Commences

n0kto Lead Judge 9 months ago
Submission Judgement Published
Validated
Assigned finding tags:

finding_MarketSwap_cancelled_DoS_protocol_with_safeApprove_no_reset

Likelihood: Medium/High, when MarketSwap order are canceled. Impact: High, DoS MarketSwap order, safeApprove reverting.

Appeal created

sakshamseth5 Auditor
9 months ago
n0kto Lead Judge
9 months ago
n0kto Lead Judge 8 months ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity

Support

FAQs

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

Give us feedback!