The Standard

The Standard
DeFiHardhat
20,000 USDC
View results
Submission Details
Severity: medium
Valid

`SmartVaultV3::swap` hardcodes Uniswap fee which will lead to losses compared to optimal routing

Summary

In the swap() function of the SmartVaultV3 contract, the Uniswap fee is hardcoded as 3000 ~ 0.3% which significantly reduces the possibilities of the swap and will lead to non-optimal routes. In particular, all swaps using the ETH path will use the wrong pool as it will, for example, use the ETH / USDC .3% pool due to the hardcoded 3000 fee.

Vulnerability Details

function swap(bytes32 _inToken, bytes32 _outToken, uint256 _amount) external onlyOwner {
uint256 swapFee = _amount * ISmartVaultManagerV3(manager).swapFeeRate() / ISmartVaultManagerV3(manager).HUNDRED_PC();
address inToken = getSwapAddressFor(_inToken);
uint256 minimumAmountOut = calculateMinimumAmountOut(_inToken, _outToken, _amount);
ISwapRouter.ExactInputSingleParams memory params = ISwapRouter.ExactInputSingleParams({
tokenIn: inToken,
tokenOut: getSwapAddressFor(_outToken),
@> fee: 3000,
recipient: address(this),
deadline: block.timestamp,
amountIn: _amount - swapFee,
amountOutMinimum: minimumAmountOut,
sqrtPriceLimitX96: 0
});
inToken == ISmartVaultManagerV3(manager).weth() ?
executeNativeSwapAndFee(params, swapFee) :
executeERC20SwapAndFee(params, swapFee);
}

Impact

For example, at the time of writing this report, ETH / WBTC the optimal route is currently ETH -> WETH -> BTC, and the pool ETH / WBTC has 0.15% (USD 3.4) fee which is 50% less when compared to the hardcoded one with 3000 ~ 0.3% (USD 6.8) for a basic swap. Therefore, using the current implementation would create a significant loss of funds.

Here's a link to a screenshot for the swap routes backing up this issue:
https://imgur.com/HSa6mMd

Tools Used

Manual review

Recommendations

Classic mitigation would be to set in advance the best Uniswap paths in a mapping for the supported assets for example ETH > WBTC, then use this data for the swaps. This allows for complex routes that save gas costs as you would also avoid limiting all swaps to a single pool like the code currently does.

Updates

Lead Judging Commences

hrishibhat Lead Judge almost 2 years ago
Submission Judgement Published
Validated
Assigned finding tags:

fixed-uni-fee

hrishibhat Lead Judge almost 2 years ago
Submission Judgement Published
Validated
Assigned finding tags:

hardcoded-fee

Support

FAQs

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

Give us feedback!