Last Man Standing

First Flight #45
Beginner FriendlyFoundrySolidity
100 EXP
View results
Submission Details
Impact: medium
Likelihood: low
Invalid

`initialGracePeriod` Should Be Immutable for Gas Efficiency

Description

  • Variables that are set once in the constructor and never updated should be marked as immutable to optimize gas costs and improve code clarity.

  • The initialGracePeriod variable is set in the constructor but never updated later, only used as a template for resetting game state.

// @> Should be immutable since it never changes after deployment
uint256 public initialGracePeriod;
constructor(..., uint256 _gracePeriod, ...) {
initialGracePeriod = _gracePeriod; // Set once, never updated
}
function resetGame() external onlyOwner gameEndedOnly {
gracePeriod = initialGracePeriod; // Only used for reading
}

Risk

Likelihood:

  • Gas optimization opportunity is always available

  • Deployment costs are higher than necessary

Impact:

  • Higher deployment gas costs due to unnecessary storage slot allocation

  • Less explicit code intent about variable mutability

  • Missed gas optimization opportunity

  • Potential for accidental modification of template values

Proof of Concept

// Current: Uses storage slot, costs ~20,000 gas on deployment
uint256 public initialGracePeriod;
// Optimized: Uses immutable, no storage slot needed
uint256 public immutable initialGracePeriod;

Recommended Mitigation

Add to immutable:

- uint256 public initialGracePeriod;
+ uint256 public immutable initialGracePeriod;
Updates

Appeal created

inallhonesty Lead Judge about 2 months ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.