Platform: Code4rena
Start Date: 20/10/2021
Pot Size: $30,000 ETH
Total HM: 5
Participants: 15
Period: 3 days
Judge: 0xean
Total Solo HM: 3
Id: 44
League: ETH
Rank: 12/15
Findings: 1
Award: $151.95
🌟 Selected for report: 1
🚀 Solo Findings: 0
35.9883 USDC - $35.99
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:
<code> 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); } </code>#0 - Shadowfiend
2021-11-04T17:01:26Z
Duplicate of #72.
35.9883 USDC - $35.99
ye0lde
Shortening revert strings to fit in 32 bytes will decrease deployment time gas and will decrease runtime gas when the revert condition has been met.
Revert strings that are longer than 32 bytes require at least one additional mstore, along with additional overhead for computing memory offset, etc.
Revert strings > 32 bytes are here: https://github.com/code-423n4/2021-10-tally/blob/c585c214edb58486e0564cb53d87e4831959c08b/contracts/governance/EmergencyGovernable.sol#L54 https://github.com/code-423n4/2021-10-tally/blob/c585c214edb58486e0564cb53d87e4831959c08b/contracts/swap/Swap.sol#L52 https://github.com/code-423n4/2021-10-tally/blob/c585c214edb58486e0564cb53d87e4831959c08b/contracts/swap/Swap.sol#L64 https://github.com/code-423n4/2021-10-tally/blob/c585c214edb58486e0564cb53d87e4831959c08b/contracts/swap/Swap.sol#L118-L122 https://github.com/code-423n4/2021-10-tally/blob/c585c214edb58486e0564cb53d87e4831959c08b/contracts/swap/Swap.sol#L151 https://github.com/code-423n4/2021-10-tally/blob/c585c214edb58486e0564cb53d87e4831959c08b/contracts/swap/Swap.sol#L213-L221 https://github.com/code-423n4/2021-10-tally/blob/c585c214edb58486e0564cb53d87e4831959c08b/contracts/swap/Swap.sol#L248
Visual Studio Code, Remix
Shorten the revert strings to fit in 32 bytes.
Or consider moving to solc 0.8.4 or greater and use Custom Errors.
#0 - Shadowfiend
2021-11-04T16:54:31Z
Duplicate of #5.
🌟 Selected for report: ye0lde
79.974 USDC - $79.97
ye0lde
Caching state variables or using existing local variables instead of repeatedly reading state variables will save gas by converting SLOADs to MLOADs.
feeRecipient_ can be used here: https://github.com/code-423n4/2021-10-tally/blob/c585c214edb58486e0564cb53d87e4831959c08b/contracts/swap/Swap.sol#L55 https://github.com/code-423n4/2021-10-tally/blob/c585c214edb58486e0564cb53d87e4831959c08b/contracts/swap/Swap.sol#L75
swapFee_ can be used here: https://github.com/code-423n4/2021-10-tally/blob/c585c214edb58486e0564cb53d87e4831959c08b/contracts/swap/Swap.sol#L57 https://github.com/code-423n4/2021-10-tally/blob/c585c214edb58486e0564cb53d87e4831959c08b/contracts/swap/Swap.sol#L66
A cached version of feeRecipient can be declared at 246 and used here: https://github.com/code-423n4/2021-10-tally/blob/c585c214edb58486e0564cb53d87e4831959c08b/contracts/swap/Swap.sol#L247 https://github.com/code-423n4/2021-10-tally/blob/c585c214edb58486e0564cb53d87e4831959c08b/contracts/swap/Swap.sol#L253 https://github.com/code-423n4/2021-10-tally/blob/c585c214edb58486e0564cb53d87e4831959c08b/contracts/swap/Swap.sol#L254 https://github.com/code-423n4/2021-10-tally/blob/c585c214edb58486e0564cb53d87e4831959c08b/contracts/swap/Swap.sol#L257 https://github.com/code-423n4/2021-10-tally/blob/c585c214edb58486e0564cb53d87e4831959c08b/contracts/swap/Swap.sol#L258
Visual Studio Code, Remix
See Proof of Concept