Gas Optimizations #124
Labels
bug
Something isn't working
G (Gas Optimization)
resolved
Finding has been patched by sponsor (sponsor pls link to PR containing fix)
sponsor confirmed
Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity")
1. array length in loops can be cached instead of calculating in every iteration
The loop bounds are calculated with
array.length
which are calculated in every loop iterations which can result in high gas.The array length can be cached instead of calculating in every loop iteration to save gas.
The instances where this pattern can be applied is found as follows
2. Use solidity custom errors to save gas
solidity 0.8.4 introduces custom errors which are cheaper than using revert strings in terms of gas
Use the custom error patterns to reduce gas cost.
for eg.
more details can be found here
3.
!=0
is cheaper than>0
!=0
is cheaper than using>0
for uintsThe text was updated successfully, but these errors were encountered: