"constants" expressions are expressions, not constants. Use "immutable" instead. #62
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")
Handle
Dravee
Vulnerability details
Impact
Due to how
constant
variables are implemented, an expression assigned to aconstant
variable is recomputed each time that the variable is used, which wastes some gas.If the variable was
immutable
instead: the calculation would only be done once at deploy time (in the constructor), and then the result would be saved and read directly at runtime rather than being recalculated.See: ethereum/solidity#9232
Proof of Concept
Tools Used
VS Code
Recommended Mitigation Steps
Change these expressions from
constant
toimmutable
and implement the calculation in the constructorThe text was updated successfully, but these errors were encountered: