Open code423n4 opened 2 years ago
This is a good improvement that will have some nice gas savings considering how often we access these variables. Which should probably be hardcoded rather than constructor arguments anyways.
also mentioned (not directly though) in #44
reopening as per judges assessment as "primary issue" on findings sheet
Handle
hrkrshnn
Vulnerability details
State Variables that can be changed to
immutable
Solidity 0.6.5 introduced
immutable
as a major feature. It allows setting contract-level variables at construction time which gets stored in code rather than storage.Consider the following generic example:
In the above example, each call to the function
owner()
reads from storage, using asload
. After EIP-2929, this costs 2100 gas cold or 100 gas warm. However, the following snippet is more gas efficient:In the above example, each storage read of the
owner
state variable is replaced by the instructionpush32 value
, wherevalue
is set during contract construction time. Unlike the last example, this costs only 3 gas.Examples