"constants" expressions are expressions, not constants. Use "immutable" instead. #26
Labels
bug
Something isn't working
G (Gas Optimization)
sponsor disputed
Sponsor cannot duplicate the issue, or otherwise disagrees this is an issue
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
Here, the exponentiation operation is computed everytime the
_pointsMultiplier
variable is used:Tools Used
VS Code
Recommended Mitigation Steps
Change expressions that are
constant
toimmutable
and implement the calculation in the constructorThe text was updated successfully, but these errors were encountered: