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

_doDexSwap Lacks Slippage Protection leading to potential loss in swaps

Vulnerability Details

The _doDexSwap function lacks slippage protection when executing token swaps through Paraswap. Without slippage protection, swaps can settle at any price, exposing users to potentially severe slippage losses. Adding a slippage protection would protect users from unfavorable trade execution.

Current code

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;
// no slippage protection or minimum output amount check
emit DexSwap(address(inputToken), amount, address(outputToken), outputAmount, isCollateralToIndex);
}

Impact

Lack of slippage protection will lead to so many things like users swap been manipulated by mev bots causing users swap to suffer significant losses due to unfavorable swap rates leading to unexpected and undesirable outcomes

Recommendations

slippage protection is needed in _doDexSwap kindly fix the below code

function _doDexSwap(
- (bytes memory data, bool isCollateralToIndex)
+ (bytes memory data, bool isCollateralToIndex,uint256 minOutputAmount) 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;
+ if (outputAmount < 0 || outputAmount < minOutputAmount ) {
+ revert Error.slippage();
+ }
emit DexSwap(address(inputToken), amount, address(outputToken), outputAmount, isCollateralToIndex);
}
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!