Summary
State variables should be cached in stack variables rather than re-reading them from storage
Vulnerability Details
https://github.com/Cyfrin/2023-07-beedle/blob/main/src/Fees.sol#L26-L44
File: src/Fees.sol
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
});
amount = swapRouter.exactInputSingle(params);
IERC20(WETH).transfer(staking, IERC20(WETH).balanceOf(address(this)));
}
@@ -1,12 +1,11 @@
+ function sellProfits(address _profits) public {
+ address _weth = WETH;
+ require(_profits != _weth, "not allowed");
- 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,
- tokenOut: WETH,
fee: 3000,
recipient: address(this),
deadline: block.timestamp,
@@ -16,5 +15,5 @@
});
amount = swapRouter.exactInputSingle(params);
+ IERC20(_weth).transfer(staking, IERC20(_weth).balanceOf(address(this)));
- IERC20(WETH).transfer(staking, IERC20(WETH).balanceOf(address(this)));
}