The Standard

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

Hardcode or fixed fee is used while swapping tokens on uniswap

Summary

Hardcode or fixed fee is used while swapping tokens on uniswap

Vulnerability Details

swap() funtion in SmartVaultV3.sol contract is used to swap tokens one token to another token by owner of contract. The fee for swap is hardcoded to 3000 which is 0.3%.

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, @audit, // fee is hardcoded. it should be passed as params
recipient: address(this),
deadline: block.timestamp,
amountIn: _amount - swapFee,
amountOutMinimum: minimumAmountOut,
sqrtPriceLimitX96: 0
});
inToken == ISmartVaultManagerV3(manager).weth() ?
executeNativeSwapAndFee(params, swapFee) :
executeERC20SwapAndFee(params, swapFee);
}

Per uniswap v3,

Uniswap v3 introduces multiple pools for each token pair, each with a different swapping fee. Liquidity providers may initially create pools at three fee levels: 0.05%, 0.30%, and 1%. More fee levels may be added by UNI governance,

However, not all pools in Uniswap are created with fee level being 3000 or 0.3%.

This example may not be relevant to protocol but for issue understanding, for example,

  1. fee level of XMON / ETH (0x59b4bb1f5d943cf71a10df63f6b743ee4a4489ee) on Mainnet is 10000 (1%),

  2. fee level of WETH / BOB (0x1a54ae9f662b463f8d432482975c17e51518b50d) on Optimism is 500 (0.05%).

Therefore, fee should not be hardcoded while swapping tokens.

Impact

Using fixed or hardcoded fee when swap tokens may be failed if the pool swap fee is changed via governance and there would be no way to change the hardcoded fee result in redeployment of contract.

Tools Used

Manual review

Recommendations

Pass the fee as input param while swapping, alternatively a fee setter function can be introduced to update the fee variable as required in future.

Updates

Lead Judging Commences

hrishibhat Lead Judge over 1 year ago
Submission Judgement Published
Validated
Assigned finding tags:

fixed-uni-fee

hrishibhat Lead Judge over 1 year 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.