code-423n4 / 2021-10-tally-findings

0 stars 0 forks source link

Function sweepFees Can Be Made More Efficient (Swap.sol) #56

Closed code423n4 closed 2 years ago

code423n4 commented 2 years ago

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); }

Shadowfiend commented 2 years ago

Duplicate of #72.