Closed code423n4 closed 2 years ago
ye0lde
Removing unnecessary array accesses while looping results in gas savings.
The function that can be modified is here: https://github.com/code-423n4/2021-10-tally/blob/c585c214edb58486e0564cb53d87e4831959c08b/contracts/swap/Swap.sol#L243-L259
Visual Studio Code, Remix
I suggest modifying swapFees as follows:
function sweepFees( address[] calldata tokens ) external nonReentrant { require( feeRecipient != address(0), "Swap::withdrawAccruedFees: feeRecipient is not initialized" // @audit long ); for (uint8 i = 0; i<tokens.length; i++) { address token = tokens[i]; uint256 balance = IERC20(token).balanceOf(address(this)); if (balance > 0) { IERC20(token).safeTransfer(feeRecipient, balance); emit FeesSwept(token, balance, feeRecipient); } } feeRecipient.transfer(address(this).balance); emit FeesSwept(address(0), address(this).balance, feeRecipient); }
Duplicate of #72.
Handle
ye0lde
Vulnerability details
Impact
Removing unnecessary array accesses while looping results in gas savings.
Proof of Concept
The function that can be modified is here: https://github.com/code-423n4/2021-10-tally/blob/c585c214edb58486e0564cb53d87e4831959c08b/contracts/swap/Swap.sol#L243-L259
Tools Used
Visual Studio Code, Remix
Recommended Mitigation Steps
I suggest modifying swapFees as follows:
function sweepFees( address[] calldata tokens ) external nonReentrant { require( feeRecipient != address(0), "Swap::withdrawAccruedFees: feeRecipient is not initialized" // @audit long ); for (uint8 i = 0; i<tokens.length; i++) {
address token = tokens[i]; uint256 balance = IERC20(token).balanceOf(address(this)); if (balance > 0) { IERC20(token).safeTransfer(feeRecipient, balance); emit FeesSwept(token, balance, feeRecipient); } } feeRecipient.transfer(address(this).balance); emit FeesSwept(address(0), address(this).balance, feeRecipient); }