Beatland Festival

First Flight #44
Beginner FriendlyFoundrySolidityNFT
100 EXP
View results
Submission Details
Impact: low
Likelihood: low
Invalid

Gas: Use Immutable for festivalContract (If Truly Immutable)

Root + Impact

Description

  • Normal Behavior:
    The festivalContract address is set once via setFestivalContract and is never meant to change for the lifetime of the BeatToken contract. Solidity provides the immutable keyword, which allows a variable to be assigned once at construction and then read at a lower gas cost than a regular storage variable.

    Issue:
    Currently, festivalContract is a regular storage variable, which incurs a higher gas cost for every read. If the design is truly immutable (i.e., the address is only set once and never changes), using the immutable keyword can reduce gas costs for every access to this variable, especially in the mint and burnFrom functions, which are called frequently.

address public festivalContract;

Risk

Likelihood:

  • This is a minor gas optimization and only applies if the contract is truly designed to never change the festival contract address after initial assignment.

Impact:

  • The gas savings are minor per call, but can add up over many transactions, especially in high-volume scenarios.

Proof of Concept

Every time festivalContract is read in mint or burnFrom, a storage read is performed, which is more expensive than reading an immutable variable.

// PoC: Every time festivalContract is read (e.g., in mint or burnFrom), a storage read is performed.
// If festivalContract were declared as immutable and set in the constructor, these reads would be cheaper.
// Example (current):
require(msg.sender == festivalContract, "Only_Festival_Mint");
// This is a storage read (expensive).
// If festivalContract were immutable, this would be a cheaper opcode.

Recommended Mitigation

If the contract is truly designed so that festivalContract is set only once (e.g., in the constructor), declare it as immutable and assign it in the constructor.

- address public festivalContract;
+ address public immutable festivalContract;
- constructor() ERC20("BeatDrop Token", "BEAT") Ownable(msg.sender){
- }
+ constructor(address _festival) ERC20("BeatDrop Token", "BEAT") Ownable(msg.sender){
+ require(_festival != address(0), "Festival contract cannot be zero address");
+ festivalContract = _festival;
+ }
Updates

Lead Judging Commences

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.