Platform: Code4rena
Start Date: 12/04/2023
Pot Size: $60,500 USDC
Total HM: 21
Participants: 199
Period: 7 days
Judge: hansfriese
Total Solo HM: 5
Id: 231
League: ETH
Rank: 171/199
Findings: 1
Award: $21.03
🌟 Selected for report: 0
🚀 Solo Findings: 0
🌟 Selected for report: c3phas
Also found by: 0xDACA, 0xRB, 0xSmartContract, 0xhacksmithh, 0xnev, Aymen0909, BenRai, Breeje, DishWasher, Erko, EvanW, JCN, MohammedRizwan, NoamYakov, Polaris_tow, Proxy, Rageur, Raihan, RaymondFam, ReyAdmirado, SAAJ, Sathish9098, Satyam_Sharma, Udsen, __141345__, aria, codeslide, decade, fatherOfBlocks, hunter_w3b, karanctf, matrix_0wl, nadin, naman1778, niser93, pavankv, petrichor, pfapostol, sebghatullah, slvDev, trysam2003, xmxanuel
21.0255 USDC - $21.03
Caching of a state variable replace each Gwarmaccess (100 gas) with a much cheaper stack read. Other less obvious fixes/optimizations include having local memory caches of state variable structs, or having local caches of state variable contracts/addresses.
minters[_minter]
should be cached before #L294 because the is a high possibilty of it being read twice from storage
possible 97 gas save with risking loss of only 3 gas. if the check passes we save 97 for the second minted
read and if it fails we just lose 3 gas. cache it before this line
minted
should be cached before #L141 because its being read at least twice. first read is in the condition in #L141 in case the condition succeeds its gonna be read in the #L142 which could be prevented by using the cached version. in case the condition in #L141 fails its gonna be read in #L149.
make the variable outside the loop and only give the value to variable inside
current
j
Using ternary operator instead of the if else statement saves gas. the placed that it make sense are listed here
saves 6 gas per instance
before transfer we should check for amount being 0 so the function doesnt run when its not gonna do anything
check amount
freedAmount - _amountExcludingReserve
reserveLeft
In the EVM, there is no opcode for non-strict inequalities (>=, <=) and two operations are performed (> + = or < + =).
consider replacing >= with the strict counterpart > and add - 1
to the second side
#0 - c4-judge
2023-05-16T14:21:36Z
hansfriese marked the issue as grade-b