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

An attacker can steal funds by sandwiching keeper's transaction.

Summary

There is no slippage check in PerpetualVault.sol#_doDexSwap().

Vulnerability Details

PerpetualVault.sol#_doDexSwap() function is as follows.

function _doDexSwap(bytes memory data, bool isCollateralToIndex) internal returns (uint256 outputAmount) {
(address to, uint256 amount, bytes memory callData) = abi.decode(data, (address, uint256, bytes));
IERC20 inputToken;
IERC20 outputToken;
if (isCollateralToIndex) {
inputToken = collateralToken;
outputToken = IERC20(indexToken);
} else {
inputToken = IERC20(indexToken);
outputToken = collateralToken;
}
uint256 balBefore = outputToken.balanceOf(address(this));
ParaSwapUtils.swap(to, callData);
outputAmount = IERC20(outputToken).balanceOf(address(this)) - balBefore;
emit DexSwap(address(inputToken), amount, address(outputToken), outputAmount, isCollateralToIndex);
}

As we can see above, there is no slippage check.
So an attacker can steal funds by sandwiching keeper's transaction.

_doDexSwap() function is called when keeper calls run()(long one leverage), runNextAction().

Impact

An attacker can steal funds from protocol by sandwiching keeper's transaction.

Tools Used

Manual Review

Recommendations

Add slippage check in _doDexSwap() function.

Updates

Lead Judging Commences

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

invalid_swap_slippage_and_deadline

Slippage and deadline are handled externally. Paraswap implementation used by the current code (behind the proxy): https://etherscan.io/address/0xdffd706ee98953d3d25a3b8440e34e3a2c9beb2c GMX code: https://github.com/gmx-io/gmx-synthetics/blob/caf3dd8b51ad9ad27b0a399f668e3016fd2c14df/contracts/order/OrderUtils.sol#L150C15-L150C33

Support

FAQs

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

Give us feedback!