Steadefi

Steadefi
DeFiHardhatFoundryOracle
35,000 USDC
View results
Submission Details
Severity: low
Invalid

Not Choosing optimal path for swaps can result into loss of vaults

Summary

Whenever swaps needed protocol use uniswap for optimal swaps. Which uses direct hardcoded direct path from input token to final token. This can result in greater slippage since direct path won't be always optimal path for swapping the tokens

Vulnerability Details

struct SwapParams {
// Address of token in
address tokenIn;
// Address of token out
address tokenOut;
// Amount of token in; in token decimals
uint256 amountIn;
// Amount of token out; in token decimals
uint256 amountOut;
// Slippage tolerance swap; e.g. 3 = 0.03%
uint256 slippage;
// Swap deadline timestamp
uint256 deadline;
}

This is swap params which does not include paths

File: GMXWorker.sol
/**
* @dev Swap exact amount of tokenIn for as many amount of tokenOut
* @param self Vault store data
* @param sp ISwap.SwapParams
* @return amountOut Amount of tokens out in token decimals
*/
function swapExactTokensForTokens(
GMXTypes.Store storage self,
ISwap.SwapParams memory sp
) external returns (uint256) {
IERC20(sp.tokenIn).approve(address(self.swapRouter), sp.amountIn);
return self.swapRouter.swapExactTokensForTokens(sp);
}
/**
* @dev Swap as little tokenIn for exact amount of tokenOut
* @param self Vault store data
* @param sp ISwap.SwapParams
* @return amountIn Amount of tokens in in token decimals
*/
function swapTokensForExactTokens(
GMXTypes.Store storage self,
ISwap.SwapParams memory sp
) external returns (uint256) {
IERC20(sp.tokenIn).approve(address(self.swapRouter), sp.amountIn);
return self.swapRouter.swapTokensForExactTokens(sp);
}

Direct Hardcoded path won't be optimal path always. There can be different optimal path for swaps but keeper will be loosing funds to make swap from this hardcoded paths

This will affect more to compounded tokens since for compounded tokens protocol won't able to select best pools

Impact

Keeper will loose funds in every funds for not choosing optimal paths.

  1. For Bluechip assets it can be optimal but there has been many instance where swaping becomes costly on direct paths

  2. For Compounds, Keeper won't able to find optimal path and will lost funds for swapping directly.

Tools Used

Manual Review

Recommendations

Consider adding path param which can be used by keeper easily.
Keeper can do offchain simulation and opt for best path to save slippage funds from swaps

Updates

Lead Judging Commences

hans Lead Judge almost 2 years ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity
Assigned finding tags:

INFO: Suboptimal swap

Support

FAQs

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