Platform: Code4rena
Start Date: 01/07/2022
Pot Size: $75,000 USDC
Total HM: 17
Participants: 105
Period: 7 days
Judge: Jack the Pug
Total Solo HM: 5
Id: 143
League: ETH
Rank: 97/105
Findings: 1
Award: $38.23
🌟 Selected for report: 0
🚀 Solo Findings: 0
🌟 Selected for report: 0xA5DF
Also found by: 0v3rf10w, 0x09GTO, 0x1f8b, 0x29A, 0xDjango, 0xKitsune, 0xNazgul, 0xdanial, 0xf15ers, Aymen0909, Bnke0x0, Ch_301, Cheeezzyyyy, Chom, ElKu, Funen, Hawkeye, IllIllI, JC, JohnSmith, Kaiziron, Lambda, Limbooo, Meera, Metatron, MiloTruck, Noah3o6, Picodes, Randyyy, RedOneN, ReyAdmirado, Rohan16, Saintcode_, Sm4rty, TomJ, Tomio, Tutturu, UnusualTurtle, Waze, _Adam, __141345__, ajtra, apostle0x01, asutorufos, brgltd, c3phas, cRat1st0s, codexploder, defsec, delfin454000, djxploit, durianSausage, exd0tpy, fatherOfBlocks, hake, horsefacts, ignacio, jayfromthe13th, joestakey, jonatascm, kaden, kebabsec, m_Rassska, mektigboy, mrpathfindr, oyc_109, rajatbeladiya, rbserver, rfa, robee, sach1r0, sashik_eth, simon135
38.2308 USDC - $38.23
For arithmetic operations which are unlikely to overflow or underflow, you could put them inside an unchecked block. This is usually the case for increment of loop indices in for
and while
loops.
For example:
for (uint256 _i = 0; i < _terminals.length; _i++)
could be rewritten as:
// you can remove initializing to _i as well as its redundant. // the length of the array can be cached if the arrays are long, but if its just few elements then you will // end up using more gas than before. So I have left it to the sponsor’s judgement. for (uint256 _i; _i < _terminals.length; ) { //statements… unchecked { _i++; } }
There is a total of 13 instances of this issue found in 4 files.
File : contracts\JBFundingCycleStore.sol:
File : contracts\JBSplitsStore.sol:
The above optimizations reduced the deployment cost from 862721 to 847308(15413 saved = 1.79% gas saving).
The max execution cost of set
function was reduced from 57527 to 57453(74 saved = 0.13%).
The max execution cost of splitsOf
function was reduced from 8679 to 8606(73 saved = 0.84%).
File : contracts\JBOperatorStore.sol:
File : contracts\JBDirectory.sol:
The above optimizations reduced the deployment cost from 1250080 to 1244680(5400 saved = 0.43% gas saving).
The max execution cost of primaryTerminalOf
function was reduced from 6046 to 5972(74 saved = 1.22%).
The max execution cost of setTerminalsOf
function was reduced from 78546 to 78254(292 saved = 0.37%).
Storage read costs 100 gas while memory read costs only 3 gas. Instances where we can profit from this are:
burnFrom
function from 6267 to 6002(265 saved = 4.23%).claimFor
function from 51755 to 51490(265 saved = 0.51%).unclaimedBalanceOf[_holder][_projectId]
at line 448 and line 452 is already cached at line 442. So use that, instead of accessing the storage again.