Platform: Code4rena
Start Date: 12/12/2022
Pot Size: $36,500 USDC
Total HM: 8
Participants: 103
Period: 7 days
Judge: berndartmueller
Id: 193
League: ETH
Rank: 85/103
Findings: 1
Award: $14.83
🌟 Selected for report: 0
🚀 Solo Findings: 0
🌟 Selected for report: Rolezn
Also found by: 0x1f8b, 0xAgro, 0xSmartContract, 0xab00, 0xhacksmithh, Aymen0909, Bnke0x0, Breeje, Diana, HardlyCodeMan, IllIllI, JC, JrNet, Madalad, NoamYakov, RaymondFam, ReyAdmirado, SleepingBugs, UdarTeam, c3phas, carlitox477, cryptonue, gz627, lukris02, millersplanet, oyc_109, pavankv, ret2basic, saneryee, tnevler
14.833 USDC - $14.83
private
rather than public
for constantsSaves 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. If needed to be viewed externally, the values can be read from the verified contract source code.
public
functions not called internally can be marked external
Since public
functions require Solidity to copy arguments to memory, whereas external
functions simply read from calldata, external
functions result in lower gas costs.
internal
function rather than public
oneThe public
getter function baseTokenReserves
simply calls the internal
function _baseTokenReserves
. When calling this getter from within the contract, it is 35 gas cheaper to call the internal
version than the public
version. Moreover, this allows us to change the visibility of baseTokenReserves
to external
to further save gas.
&&
Replacing with two separate require statements saves 16 gas per instance
<br>unchecked
for calculations that cannot overflowBy bypassing Solidity's built in overflow/underflow checks using unchecked
, we can save gas. This is especially beneficial for the index variable within for loops (saves 120 gas per iteration).
Caching the array length outside a loop saves reading it on each iteration, as long as the array’s length is not changed during the loop.
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. This saves 24 gas per call
x = x + y
is cheaper than x += y
#0 - c4-judge
2023-01-14T17:15:22Z
berndartmueller marked the issue as grade-b