Platform: Code4rena
Start Date: 12/12/2022
Pot Size: $36,500 USDC
Total HM: 8
Participants: 103
Period: 7 days
Judge: berndartmueller
Id: 193
League: ETH
Rank: 84/103
Findings: 1
Award: $14.83
🌟 Selected for report: 0
🚀 Solo Findings: 0
🌟 Selected for report: Rolezn
Also found by: 0x1f8b, 0xAgro, 0xSmartContract, 0xab00, 0xhacksmithh, Aymen0909, Bnke0x0, Breeje, Diana, HardlyCodeMan, IllIllI, JC, JrNet, Madalad, NoamYakov, RaymondFam, ReyAdmirado, SleepingBugs, UdarTeam, c3phas, carlitox477, cryptonue, gz627, lukris02, millersplanet, oyc_109, pavankv, ret2basic, saneryee, tnevler
14.833 USDC - $14.83
Issue | Instances | User Savings (total avg) | Deployment Savings (total avg) | |
---|---|---|---|---|
[G-01] | Value Not Pre-Calculated | 1 | 5028 | 0 |
[G-02] | uint256 Iterator Checked Each Iteration | 7 | 3379 | 68 |
[G-03] | x += y Used For State Variables | 1 | 466 | 0 |
Readability can be sacrificed for user gas savings. The value 160 - 4 * 4
can be pre-calculated to 144
and inlined to save gas.
/src/lib/SafeERC20Namer.sol Links: 55.
55: return Strings.toHexString(uint160(token) >> (160 - 4 * 4));
Suggested Change
55: return Strings.toHexString(uint160(token) >> (144));
uint256
Iterator Checked Each IterationA uint256
iterator will not overflow before the check variable overflows. Unchecking the iterator increment saves gas.
Example
//From for (uint256 i; i < len; ++i) { //Do Something } //To for (uint256 i; i < len;) { //Do Something unchecked { ++i; } }
/src/Pair.sol Links: 238, 258, 468.
238: for (uint256 i = 0; i < tokenIds.length; i++) { 258: for (uint256 i = 0; i < tokenIds.length; i++) { 468: for (uint256 i = 0; i < tokenIds.length; i++) {
/src/lib/SafeERC20Namer.sol Links: 13, 22, 33, 39.
13: for (uint256 j = 0; j < 32; j++) { 22: for (uint256 j = 0; j < charCount; j++) { 33: for (uint256 i = 32; i < 64; i++) { 39: for (uint256 i = 0; i < charCount; i++) {
x += y
Usedx = x + y
is cheaper than x += y
in some cases like below.
/src/lib/SafeERC20Namer.sol Links: 35.
35: charCount += uint8(b[i]);
Suggested Change
35: charCount = charCount + uint8(b[i]);
#0 - c4-judge
2023-01-14T17:16:05Z
berndartmueller marked the issue as grade-b