Platform: Code4rena
Start Date: 07/07/2023
Pot Size: $121,650 USDC
Total HM: 36
Participants: 111
Period: 7 days
Judge: Picodes
Total Solo HM: 13
Id: 258
League: ETH
Rank: 73/111
Findings: 1
Award: $24.30
🌟 Selected for report: 0
🚀 Solo Findings: 0
🌟 Selected for report: c3phas
Also found by: 0x11singh99, 0xAnah, 0xn006e7, LeoS, Rageur, Raihan, ReyAdmirado, Rolezn, SAAJ, SAQ, SM3_SS, Udsen, alymurtazamemon, hunter_w3b, koxuan, naman1778, petrichor, ybansal2403
24.2984 USDC - $24.30
This saves deployment gas.
If a function modifier such as onlyOwner is used, the function will revert if a normal user tries to pay the function. Marking the function as payable will lower the gas cost for legitimate callers because the compiler will not include checks for whether a payment was provided.
Saves a storage slot for the mapping. Depending on the circumstances and sizes of types, can avoid a Gsset (20000 gas) per mapping combined. Reads and subsequent writes can also be cheaper when a function requires both values and they both fit in the same storage slot. Finally, if both fields are accessed in the same function, can save ~42 gas per access due to not having to recalculate the key’s keccak256 hash (Gkeccak256 - 30 gas) and that calculation’s associated stack operations.
It is not necessary to have both a named return and a return statement.
Modifiers make code more elegant, but cost more than normal functions.
assembly
to write address storage valuesIt uses more gas in the distribution process and also for each transaction than constant usage.
Instead of using address(this)
, it is more gas-efficient to pre-calculate and use the hardcoded address
If needed, the values can be read from the verified contract source code, or if there are multiple values there can be a single getter function that returns a tuple of the values of all currently-public constants. Saves 3406-3606 gas in deployment gas due to the compiler not having to create non-payable getter functions for deployment calldata, not having to store the bytes of the value outside of where it’s used, and not adding another entry to the method ID table.
Use abi.encodePacked() where possible to save gas.
#0 - c4-judge
2023-07-18T19:01:15Z
Picodes marked the issue as grade-b
#1 - PierrickGT
2023-09-07T23:45:11Z
GAS-1: impossible to fix without a link to the actual code GAS-2: non payable functions shouldn't be marked as payable GAS-3, 4, 5, 6: we would lose in code legibility GAS-7, 8: does not save any gas GAS-9: constants are always public GAS-10: we can't use encodePacked