Gas Optimizations #2
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")
cache in variables instead of loading
description
The code can be optimized by minimising the number of SLOADs. SLOADs are expensive (100 gas) compared to MLOADs/MSTOREs (3 gas).
findings
array lengths should be cached
use calldata instead of memory
description
Use calldata instead of memory for function parameters saves gas if the function argument is only read.
findings
named returns and a return statement isn’t necessary
description
Removing unused named returns variables can reduce gas usage (MSTOREs/MLOADs) and improve code clarity. To save gas and improve code quality: consider using only one of those.
findings
using prefix increments save gas
description
Prefix increments are cheaper than postfix increments,
eg ++i rather than i++
findings
use custom errors
description
use custom errors instead of revert strings
If the contract(s) in scope allow using Solidity >=0.8.4, consider using Custom Errors as they are more gas efficient while allowing developers to describe the error in detail using NatSpec.
findings
eg
The text was updated successfully, but these errors were encountered: