In Solidity, immutable variables are evaluated at construction time and embedded in the contract's bytecode, reducing storage usage and gas costs for reads (no SLOAD). The constructor of RaiseBoxFaucet initializes faucetDrip, sepEthAmountToDrip, and dailySepEthCap with specific values (e.g., 100 * 10**18, 0.01 ether, 0.05 ether) and does not modify them thereafter, as indicated by the absence of setters or state-changing logic affecting these variables.
Declaring them as uint256 public immutable would:
Save ~2000 gas per variable during deployment (avoiding storage slot allocation).
Reduce read gas costs slightly (bytecode access vs. storage).
However, the current implementation uses regular public variables, reserving storage slots and incurring higher gas overhead. This is a missed optimization opportunity, common in contracts where immutable benefits are not fully utilized.
Likelihood:
Medium: Overlooking immutable is a frequent optimization miss in Solidity development, especially in early drafts.
More likely in contracts with multiple constructor parameters where immutable usage is inconsistently applied.
Impact:
Low: Functional behavior is unaffected, and the gas increase is minor (~6000 gas total for three variables at deployment).
Optimization loss: Missed opportunity to reduce costs in a gas-sensitive environment like Ethereum.
The following Foundry test compares gas costs and storage usage with and without immutable, confirming the optimization potential.
Add to RaiseBoxFaucetTest.t.sol:
Setup: Deploys both versions, measuring deployment gas.
Issue Demonstration: The non-immutable version incurs higher gas (~6000 more) due to storage slot allocation, verifiable in the gas logs.
Result: The test passes, confirming the gas savings with immutable, highlighting the missed optimization.
The console logs quantify the difference, proving the inefficiency.
Declare faucetDrip, sepEthAmountToDrip, and dailySepEthCap as immutable to optimize gas usage and reduce storage overhead.
No changes are needed in the constructor assignment, as the current initialization logic is compatible with immutable.
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.