Gas Optimization: in Vader.sol, Turn Variables _1m, maxSupply, and decimals, into Constants/Immutable variables
Currently, in Vader.sol, the variables "_1m", "maxSupply", and "decimals", are kept mutable, incurring an SLOAD call on every invocation.
However, the variable "_1m" is only ever used to refer to the constant value of 1 million weiDecimals, the variable maxSupply is only ever used to refer to 2 million weiDecimals, and decimals is only ever used to refer to 10 ** 18.
If you make these variables constant, the compiler will inline those values into every call to _1m, maxSupply, and decimals, avoiding all SLOAD's in any calls that use them.
Proof of Concept
In Vader.sol's constructor, the following lines are used:
decimals = 18;
_1m = 10*6 10 * decimals; //1m
maxSupply = 2 _1m;
Recommended Mitigation Steps
If you would like to set the value in the constructor rather than simply hardcoding it, then use the keyword "immutable" to set it once and never use an SLOAD again. Or, you can simply hardcode the value in the variable's declaration, and then use the "constant" keyword.
Handle
jvaqa
Vulnerability details
Impact
Gas Optimization: in Vader.sol, Turn Variables _1m, maxSupply, and decimals, into Constants/Immutable variables
Currently, in Vader.sol, the variables "_1m", "maxSupply", and "decimals", are kept mutable, incurring an SLOAD call on every invocation. However, the variable "_1m" is only ever used to refer to the constant value of 1 million weiDecimals, the variable maxSupply is only ever used to refer to 2 million weiDecimals, and decimals is only ever used to refer to 10 ** 18. If you make these variables constant, the compiler will inline those values into every call to _1m, maxSupply, and decimals, avoiding all SLOAD's in any calls that use them.
Proof of Concept
In Vader.sol's constructor, the following lines are used: decimals = 18; _1m = 10*6 10 * decimals; //1m maxSupply = 2 _1m;
Recommended Mitigation Steps
If you would like to set the value in the constructor rather than simply hardcoding it, then use the keyword "immutable" to set it once and never use an SLOAD again. Or, you can simply hardcode the value in the variable's declaration, and then use the "constant" keyword.