20,000 USDC
View results
Submission Details
Severity: gas
Valid

Unnecessary Variable Assignment in sellProfits Function

Summary

The sellProfits function in the smart contract includes an unnecessary variable assignment, which does not impact the functionality of the contract but leads to suboptimal gas usage. This report highlights the issue, its potential impact, and provides recommendations for optimizing the code.

Vulnerability Details

In the sellProfits function, the variable amount is assigned the return value of the swapRouter.exactInputSingle(params) function call. However, this amount variable is not used anywhere else in the function. The assignment is redundant and does not serve any purpose in the contract's logic.

Impact

The impact of this vulnerability is primarily related to gas optimization. Since the amount variable is not utilized after the assignment, the extra step of assigning its value consumes unnecessary gas during contract execution. While the gas cost may be negligible for individual transactions, it can add up and affect the overall efficiency of the contract, especially when dealing with multiple transactions.

Tools Used

Remix IDE

Recommendations

To optimize gas usage and improve the efficiency of the contract, it is recommended to remove the unnecessary assignment of the amount variable in the sellProfits function. The updated function would look as follows:

function sellProfits(address _profits) public {
require(_profits != WETH, "not allowed");
uint256 amount = IERC20(_profits).balanceOf(address(this));
ISwapRouter.ExactInputSingleParams memory params = ISwapRouter
.ExactInputSingleParams({
tokenIn: _profits,
tokenOut: WETH,
fee: 3000,
recipient: address(this),
deadline: block.timestamp,
amountIn: amount,
amountOutMinimum: 0,
sqrtPriceLimitX96: 0
});
swapRouter.exactInputSingle(params);
IERC20(WETH).transfer(staking, IERC20(WETH).balanceOf(address(this)));
}

Support

FAQs

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