Gas is wasted accessing storage when a variable never changes after the constructor. The immutable keyword is used to designate such variables. Immutable variables are like constant variables, except that they can be assigned in the constructor.
This variable is only ever assigned in the constructor, so it should be labeled immutable. Here are the bytecode differences between what is in the repository, and adding the single immutable keyword to the line, leading to large gas savings:
Handle
IllIllI
Vulnerability details
Impact
Gas is wasted accessing storage when a variable never changes after the constructor. The
immutable
keyword is used to designate such variables.Immutable
variables are likeconstant
variables, except that they can be assigned in the constructor.Proof of Concept
https://github.com/code-423n4/2022-01-yield/blob/e946f40239b33812e54fafc700eb2298df1a2579/contracts/ConvexYieldWrapper.sol#L17
This variable is only ever assigned in the constructor, so it should be labeled
immutable
. Here are the bytecode differences between what is in the repository, and adding the singleimmutable
keyword to the line, leading to large gas savings:Tools Used
Hardhat npx @remix-project/remix-lib
Recommended Mitigation Steps
Add
immutable
to variables only set during the constructor