Platform: Code4rena
Start Date: 21/04/2022
Pot Size: $75,000 USDC
Total HM: 7
Participants: 45
Period: 7 days
Judge: 0xean
Total Solo HM: 5
Id: 111
League: ETH
Rank: 42/45
Findings: 1
Award: $66.32
🌟 Selected for report: 0
🚀 Solo Findings: 0
🌟 Selected for report: 0xkatana
Also found by: 0v3rf10w, 0x1f8b, 0xNazgul, 0xmint, CertoraInc, Dravee, Fitraldys, Funen, IllIllI, NoamYakov, Scocco, Tomio, catchup, csanuragjain, defsec, delfin454000, djxploit, fatima_naz, gzeon, joestakey, joshie, kebabsec, nahnah, oyc_109, rayn, robee, rotcivegaf, saian, samruna, sorrynotsorry, teryanarmen, z3s
66.3179 USDC - $66.32
Gas optimization issue in the for loop
of xtribe.sol
L95:
[1] Un-necessary initialisation of loop invariant :
Statement uint256 i=0
is not required, because all uninitialised uint variable, by default, are set to 0
[2] ++i is cheaper than i++ for unsigned integer
[3] Value of accounts[i]
is loaded twice, so instead load the value of accounts[i]
once, store it in a local variable and then use it.
So the final optimised for loop is as follows:
for (uint256 i; i < size; ) { uint256 memory acc = accounts[i]; emit DelegateVotesChanged(acc, 0, getVotes(acc)); unchecked { ++i; } }