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

Slippage Control Bypass Vulnerability

Summary

The vault's swap mechanism allows keepers to execute trades with no enforced slippage limits, enabling theft of >99.9% of deposited funds in a single transaction.

Vulnerability Details

Root Cause:

  • The minOutputAmount parameter in swap operations is fully controlled by the keeper without on-chain validation.

  • Malicious keepers can set minOutputAmount = 1 wei, bypassing all economic safeguards.

Affected Code:

// In _doGmxSwap:
IGmxProxy.OrderData memory orderData = IGmxProxy.OrderData({
...
minOutputAmount: minOutputAmount // ❌ Keeper-controlled value
});

Proof of Concept (PoC)

Attack Scenario:

  1. Attacker deposits 1,000 USDC into the vault.

  2. Keeper forces a swap with minOutputAmount = 1 wei.

  3. Swap executes with near-total slippage, converting 1,000 USDC to ~1 wei of output.

Test Code:

function test_SlippageAttack() public {
address attacker = makeAddr("attacker");
uint256 depositAmount = 1000e6; // 1000 USDC (6 decimals)
uint256 maliciousMinOutput = 1; // 1 wei
// 1. Deposit funds
depositFixture(attacker, depositAmount);
// 2. Prepare malicious swap
MarketPrices memory prices = mockData.getMarketPrices();
address[] memory gmxPath = new address[](1);
gmxPath[0] = address(0x70d955...); // GMX market
bytes[] memory swapData = new bytes[](1);
swapData[0] = abi.encode(PROTOCOL.GMX, abi.encode(
gmxPath,
depositAmount,
maliciousMinOutput
));
// 3. Execute swap as keeper
vm.prank(PerpetualVault(vault).keeper());
PerpetualVault(vault).run(true, true, prices, swapData);
// 4. Verify catastrophic loss
address indexToken = PerpetualVault(vault).indexToken();
uint256 outputAmount = IERC20(indexToken).balanceOf(vault);
// Allow <0.1% of original value (1000e6 * 0.1% = 1000e3)
assertLt(outputAmount, 1000e3, "Slippage attack failed");
}

Recommendations

1. Implement calculateExpectedOutput Function

// Add to PerpetualVault contract
function calculateExpectedOutput(
uint256 inputAmount,
MarketPrices memory prices,
bool isCollateralToIndex
) public pure returns (uint256) {
if (isCollateralToIndex) {
// Collateral → Index: (inputAmount * collateralPrice) / indexPrice
return (inputAmount * prices.shortTokenPrice.min)
/ prices.indexTokenPrice.max;
} else {
// Index → Collateral: (inputAmount * indexPrice) / collateralPrice
return (inputAmount * prices.indexTokenPrice.min)
/ prices.shortTokenPrice.max;
}
}

2. Enforce Slippage Checks

// Modified _doGmxSwap:
uint256 expectedOutput = calculateExpectedOutput(
amountIn,
prices,
swapProgressData.isCollateralToIndex
);
// 5% slippage tolerance (configurable)
uint256 maxSlippageBps = 500;
uint256 minAllowed = (expectedOutput * (10_000 - maxSlippageBps)) / 10_000;
require(
orderData.minOutputAmount >= minAllowed,
"Slippage exceeds tolerance"
);

3. Add Governance Controls

// Governance-controlled parameter
uint256 public maxSlippageBps = 500; // 5% in basis points
function setMaxSlippage(uint256 _slippage) external onlyOwner {
require(_slippage <= 1000, "Excessive slippage"); // Max 10%
maxSlippageBps = _slippage;
}
Updates

Lead Judging Commences

n0kto Lead Judge 5 months ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity
Assigned finding tags:

Admin is trusted / Malicious keepers

Please read the CodeHawks documentation to know which submissions are valid. If you disagree, provide a coded PoC and explain the real likelihood and the detailed impact on the mainnet without any supposition (if, it could, etc) to prove your point. Keepers are added by the admin, there is no "malicious keeper" and if there is a problem in those keepers, that's out of scope. ReadMe and known issues states: " * System relies heavily on keeper for executing trades * Single keeper point of failure if not properly distributed * Malicious keeper could potentially front-run or delay transactions * Assume that Keeper will always have enough gas to execute transactions. There is a pay execution fee function, but the assumption should be that there's more than enough gas to cover transaction failures, retries, etc * There are two spot swap functionalies: (1) using GMX swap and (2) using Paraswap. We can assume that any swap failure will be retried until success. " " * Heavy dependency on GMX protocol functioning correctly * Owner can update GMX-related addresses * Changes in GMX protocol could impact system operations * We can assume that the GMX keeper won't misbehave, delay, or go offline. " "Issues related to GMX Keepers being DOS'd or losing functionality would be considered invalid."

Support

FAQs

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