Open code423n4 opened 2 years ago
I have to preface that I very much like the formatting on this submission. I think all submission should try to show the code and have titles, it does help.
safe.slurpAndLess()
can't argue with that, would save a CALL and a Auth check, let's say 200 gas
Removing && would save 3 gas per &, let's say 15 gas
for (uint256 i = 0; i < data.length; i++) {
in multicall is indeed paying the extra cost for getting the length each time, (boundary check) caching it would save gas, let's say 10 (because out of scope)
Unfortunately everything else is out of scope although technically valid
I want to commend the warden for their submission and the thoroughness
225 gas saved
There should be a
safe.slurpAndLess()
in order to avoid duplicating the modifiers of the separate functionshttps://github.com/code-423n4/2022-02-tribe-turbo/blob/66f27fe51083f49f7935e3fe594ab2380b75dee8/src/TurboRouter.sol#L130-L133
Functions not called by the contract itself should be
external
rather thanpublic
All of the rest in this contract are external, and this one isn't called anywhere
https://github.com/code-423n4/2022-02-tribe-turbo/blob/66f27fe51083f49f7935e3fe594ab2380b75dee8/src/TurboRouter.sol#L118
Splitting
require()
statements that use&&
saves gasSee this issue for an example
https://github.com/code-423n4/2022-02-tribe-turbo/blob/main/src/TurboSafe.sol
https://github.com/code-423n4/2022-02-tribe-turbo/blob/main/lib/solmate/src/utils/CREATE3.sol (technically not in scope but maybe useful)
https://github.com/code-423n4/2022-02-tribe-turbo/blob/main/lib/solmate/src/tokens/ERC20.sol (technically not in scope but maybe useful)
https://github.com/code-423n4/2022-02-tribe-turbo/blob/main/lib/ERC4626/lib/solmate/src/utils/CREATE3.sol (technically not in scope but maybe useful)
https://github.com/code-423n4/2022-02-tribe-turbo/blob/main/lib/ERC4626/lib/solmate/src/tokens/ERC20.sol (technically not in scope but maybe useful)
Using
bool
s for storage incurs overheadhttps://github.com/code-423n4/2022-02-tribe-turbo/blob/main/src/modules/TurboBooster.sol#L28
<array>.length
should not be looked up in every loop of a for-loophttps://github.com/code-423n4/2022-02-tribe-turbo/blob/main/lib/ERC4626/src/external/Multicall.sol#L14 (technically not in scope but maybe useful)
++i
/i++
should beunchecked{++i}
/unchecked{++i}
when it is not possible for them to overflow, as is the case when used in for- and while-loopshttps://github.com/code-423n4/2022-02-tribe-turbo/blob/main/lib/ERC4626/src/external/Multicall.sol#L14 (technically not in scope but maybe useful)
++i
costs less gas than++i
, especially when it's used in for-loops (--i
/i--
too)https://github.com/code-423n4/2022-02-tribe-turbo/blob/main/lib/ERC4626/src/external/Multicall.sol#L14 (technically not in scope but maybe useful)
It costs more gas to initialize variables to zero than to let the default of zero be applied
https://github.com/code-423n4/2022-02-tribe-turbo/blob/main/lib/ERC4626/src/external/Multicall.sol#L14 (technically not in scope but maybe useful)