Platform: Code4rena
Start Date: 09/12/2021
Pot Size: $25,000 USDC
Total HM: 12
Participants: 25
Period: 4 days
Judge: LSDan
Total Solo HM: 4
Id: 64
League: ETH
Rank: 22/25
Findings: 1
Award: $64.25
🌟 Selected for report: 4
🚀 Solo Findings: 0
26.9701 USDC - $26.97
robee
In ITwabRewards.sol, Promotion is optimized to: 4 slots from: 5 slots. The new order of types (you choose the actual variables): 1. IERC20 2. uint216 3. uint32 4. uint8 5. address 6. uint32 7. address
18.2048 USDC - $18.20
robee
Prefix increments are cheaper than postfix increments.
Further more, using unchecked {++x} is even more gas efficient, and the gas saving accumulates every iteration and can make a real change
There is no risk of overflow caused by increamenting the iteration index in for loops (the ++i
in for (uint256 i = 0; i < numIterations; ++i)
).
But increments perform overflow checks that are not necessary in this case.
These functions use not using prefix increments (++x
) or not using the unchecked keyword:
change to prefix increment and unchecked: TwabRewards.sol, index, 172 change to prefix increment and unchecked: TwabRewards.sol, index, 217
#0 - PierrickGT
2021-12-10T00:26:09Z
I did some gas golfing to figure out if ++i
is really less gas consuming than i++
. We would only save 5 gas per iteration but also lose in code clarity, so this gas saving trade off isn't really worth it.
About the unchecked part, results are a bit more convincing but still negligible. We would save 77 gas per iteration but as stated in the following issue, it is not possible to write unchecked { ++i }
inline so we would have to write a helper function which would make our code less legible and harder to maintain in the future.
I've acknowledged the issue but we won't actually make the changes cause we prefer to keep a simple code base that will be easier to maintain in the future.
🌟 Selected for report: robee
Also found by: 0x0x0x, defsec, leastwood, pmerkleplant
13.1075 USDC - $13.11
robee
Caching the array length is more gas efficient.
This is because access to a local variable in solidity is more efficient than query storage / calldata / memory
We recommend to change from:
for (uint256 i=0; i<array.length; i++) { ... }
to:
uint len = array.length
for (uint256 i=0; i<len; i++) { ... }
These functions use not using prefix increments (++x
) or not using the unchecked keyword:
TwabRewards.sol, _epochIds, 172 TwabRewards.sol, _epochIds, 217
🌟 Selected for report: robee
Also found by: GiveMeTestEther, Jujic, Meta0xNull, WatchPug, defsec, sirhashalot, ye0lde
5.9721 USDC - $5.97
robee
The following require messages are of length more than 32 and we think are short enough to short them into exactly 32 characters such that it will be placed in one slot of memory and the require function will cost less gas. The list:
Solidity file: TwabRewards.sol, In line 128, Require message length to shorten: 38, The message: TwabRewards/recipient-not-zero-address Solidity file: TwabRewards.sol, In line 175, Require message length to shorten: 35, The message: TwabRewards/rewards-already-claimed Solidity file: TwabRewards.sol, In line 231, Require message length to shorten: 35, The message: TwabRewards/ticket-not-zero-address