Platform: Code4rena
Start Date: 06/09/2022
Pot Size: $90,000 USDC
Total HM: 33
Participants: 168
Period: 9 days
Judge: GalloDaSballo
Total Solo HM: 10
Id: 157
League: ETH
Rank: 151/168
Findings: 1
Award: $46.69
š Selected for report: 0
š Solo Findings: 0
š Selected for report: pfapostol
Also found by: 0x1f8b, 0x4non, 0x5rings, 0xA5DF, 0xSmartContract, 0xc0ffEE, 0xkatana, Aymen0909, Bnke0x0, CertoraInc, Chandr, CodingNameKiki, Cr4ckM3, Deivitto, DimSon, Franfran, JAGADESH, JC, Jeiwan, Lambda, LeoS, Matin, Metatron, Migue, MiloTruck, PPrieditis, PaludoX0, R2, RaymondFam, Respx, ReyAdmirado, Rolezn, Saintcode_, Samatak, SnowMan, StevenL, Tointer, TomJ, Tomo, WatchDogs, Waze, _Adam, __141345__, ajtra, asutorufos, ballx, brgltd, bulej93, c3phas, ch0bu, dharma09, djxploit, durianSausage, easy_peasy, fatherOfBlocks, gianganhnguyen, gogo, imare, leosathya, lucacez, martin, oyc_109, pauliax, peiw, prasantgupta52, ret2basic, rfa, robee, sikorico, simon135, tofunmi, volky, wagmi, zishansami
46.6937 USDC - $46.69
>=
cost more than >
A single > operator costs less gas as compared to the >= operator.
Instances of this issue :
OnlyOwner functions cannot be called by normal users and will not receive ETH by mistake. To save gas, these functions can be made payable.
Instances of this issue :
bool
s for storage incurs overheadIt costs more to declare storage variables as bools than as uint256.
Instances of this issue :
calldata
overĀ memory
When an external function with aĀ memory
array is called, theĀ abi.decode()
step has to use a for-loop to copy each index of theĀ calldata
to theĀ memory
Ā index. Each iteration of this for-loop costs at least 60 gas (i.e.Ā 60 * <mem_array>.length
).
Change the following from memory
to calldata
:
Declaration of variables with default values cost gas. such as
uint256 a = 0;
change to ā uint256 a;
Instances of this issue :
Change the following from:
uint256 b = a / 2;
ā uint256 b = a >> 1;
++x
instead of x++
Use Prefix increment rather than Postfix increment, it saves gas.
Instances of this issue :
<x> += <y>
Ā costs more gas thanĀ <x> = <x> + <y>
Using the addition operator instead of plus-equals saves gas.
Instances of this issue :
if()
Ā statements that useĀ ||/&&
Ā saves gasWhenever the conditional statement uses the ||/&&
operator to revert the same error, itās better to split the if statement so that the first condition is executed directly rather than having both conditions executed.
Instances of this issue :
When internal functions are called once in the contract, it is better to inline them rather than declaring because function declarations are expensive.
Instances of this issue :
Since there is a direct opcode for this operation, implementing this saves gas.
Instances of this issue :
The code should be refactored such that they no longer exist, or the block should do something useful, such as emitting an event or reverting. If the contract is meant to be extended, the contract should beĀ abstract
and the function signatures are added without any default implementation. If the block is an empty if-statement block to avoid doing subsequent checks in the else-if/else conditions, the else-if/else conditions should be nested under the negation of the if-statement, because they involve different classes of checks, which may lead to the introduction of errors when the code is later modified (if(x){}else if(y){...}else{...}
=> Ā if(!x){if(y){...}else{...}}
)
Instances of this issue :
#0 - GalloDaSballo
2022-09-26T20:48:24Z
Around 600 gas 500 of which from moving memory to calldata