Platform: Code4rena
Start Date: 23/05/2022
Pot Size: $75,000 USDC
Total HM: 23
Participants: 75
Period: 7 days
Judge: GalloDaSballo
Total Solo HM: 13
Id: 130
League: ETH
Rank: 74/75
Findings: 1
Award: $49.95
🌟 Selected for report: 0
🚀 Solo Findings: 0
🌟 Selected for report: IllIllI
Also found by: 0x1f8b, 0x4non, 0xNazgul, 0xf15ers, 0xkatana, Chom, ControlCplusControlV, DavidGialdi, Deivitto, Dravee, ElKu, Fitraldys, Funen, GimelSec, MadWookie, MaratCerby, MiloTruck, Picodes, Randyyy, TerrierLover, TomJ, Tomio, UnusualTurtle, WatchPug, Waze, _Adam, asutorufos, c3phas, catchup, csanuragjain, delfin454000, djxploit, fatherOfBlocks, gzeon, hake, hansfriese, horsefacts, orion, oyc_109, pauliax, reassor, rfa, rotcivegaf, sach1r0, saian, sashik_eth, simon135, supernova, teddav, z3s
49.9472 USDC - $49.95
Use ++ i instead of i++ to Save Gas
When using i++
this uses more gas since Solidity 0.8.0 due to the way the compiler handles incrementing in safemath. This is less efficient than using ++i
which uses less gas because of how Solidity implements Safemath, even they though both accomplish the same thing within a for loop. The following lines' use of i++
can be replaced with ++i
.
For example, take line 57 (Minter.sol) which utilizes i++
which can be made more efficient with the use of ++i
instead
[line57] for (uint i = 0; i < claimants.length; i++)
alter this to
[line 57] for (uint i = 0; i < claimants.length; ++i)
There are many for loops through the code, so using ++i can add up substantially in gas. Replace i++
with ++i
in the following lines.
Changes are reccomended on lines 179, 353, 405, 426, 448, 484
Line 179 - change the i++
in for (uint i = 0; i < numRewards; i++)
to ++i
Line 353 - change the i++
in for (uint i = 0; i < tokens.length; i++)
to ++i
Line 405- change the i++
in for (uint i = _startIndex; i < _endIndex; i++)
to ++i
Line 426 - change the i++
in for (uint i; i < [ength; i++)
to i++
Line 448 - change the i++
in for (uint i = _startIndex; i < _endIndex; i++)
to ++i
Line 484 - change the i++
in for (uint i = _startIndex; i < _endIndex; i++)
to ++i
Changes are recommended on lines 257, 389
Line 257 - change the i++
in for (uint i = 0; i < _prices.length; i++)
to ++i
Line 389 - change the i++
in [line389] for (uint i = 0; i < 255; i++)
to ++i
Changes are recommended on lines 75, 105, 121, 148, 195, 252, 301
Line 75 - change the i++
in for (uint i = 0; i < 20; i++)
to ++i
Line 105 - change the i++
in for (uint i = 0; i < 128; i++)
Line 121 - change the i++
in for (uint i = 0; i < 128; i++)
to ++i
Line 148 - change the i++
infor (uint i = 0; i < 20; i++)
to ++i
Line 195 - change the i++
in for (uint i = 0; i < 50; i++
to ++i
Line 252 - change the i++
in for (uint i = 0; i < 50; i++
to ++i
Line 301 - change the i++
in for (uint i = 0; i < _tokenIds.length; i++)
to ++i
Changes are recommended on lines 90, 316
Line 90 - change the i++
in for (uint i = 0; i < routes.length; i++)
to ++i
Line 316 - change the i++
in for (uint i = 0; i < routes.length; i++)
to ++i
Changes are recommmended on line 24
Line 24 - change the i++
in for (uint i = 0; i < 255; i++)
to ++i
Changes are recommended on lines 76, 103, 128, 143, 147, 266, 272, 304, 310, 340, 346
Line 76 - change the i++
in for (uint i = 0; i < _tokens.length; i++)
to ++i
Line 103 - change the i++
in for (uint i = 0; i < _poolVoteCnt; i++)
to ++i
Line 128 - change the i++
in for (uint i = 0; i < _poolCnt; i++)
to ++i
Line 143 - change the i++
in for (uint i = 0; i < _poolCnt; i++)
to ++i
Line 147 - change the i++
in for (uint i = 0; i < _poolCnt; i++)
to ++i
[Line 266]((https://github.com/code-423n4/2022-05-velodrome/blob/main/contracts/contracts/Voter.sol#L266) - change the i++
in for (uint i = 0; i < _gauges.length; i++)
to ++i
Line 272 - change the i++
in for(uint i = start; i < end; i++)
to ++i
Line 304 - change the i++
in for (uint i = 0; i < _gauges.length; i++)
to ++i
Line 310 - change the i++
in for (uint i = 0; i < _gauges.length; i++)
to ++i
Line 340 - change the i++
in for (uint x = start; x < finish; x++)
to ++i
Line 346 - change the i++
in for (uint x = 0; x < _gauges.length; x++)
to ++i
Changes are recommended on lines 1146, 1193, 1125, 1249, 1295, 1320, 1325
Line 1146 - change the i++
in for (uint i = 0; i < _tokenIds.length; i++)
to ++i
Line 1193 - change the i++
in for (uint i = 0; i < _tokenIds.length; i++)
to ++i
Line 1225- change the i++
in for (uint i = 0; i < srcRepOld.length; i++)
to ++i
Line 1249 - change the i++
in for (uint i = 0; i < dstRepOld.length; i++)
to ++i
Line 1295- change the i++
in for (uint i = 0; i < srcRepOld.length; i++)
to ++i
Line 1320- change the i++
in for (uint i = 0; i < dstRepOld.length; i++)
to ++i
Line 1325 - change the i++
in for (uint i = 0; i < ownerTokenCount; i++)
to ++i
footnote - consider declaring all public functions as payable as it shouldn't interfere with any functionality, but will remove a 5 gas runtime check for each call.
#0 - GalloDaSballo
2022-06-30T00:00:06Z
Would save hundreds of gas
#1 - GalloDaSballo
2022-06-30T02:09:57Z
100