Eggstravaganza

First Flight #37
Beginner FriendlySolidity
100 EXP
View results
Submission Details
Severity: low
Invalid

Unchanged state variable should be declared as constants or immutable in `EggHuntGame.sol`

Instances:

  • eggNFT should be immutable

  • eggVault should be immutable

The variable eggNFT is used to reference the NFT contract, and eggVault is used to reference the vault contract. These variables are not expected to change after deployment. Declaring them as immutable ensures that their values are set only once during contract initialization and cannot be modified afterward. This reduces gas costs associated with accessing these variables, as reading from immutable variables is cheaper than reading from storage.

Impact:
Declaring state variables as immutable reduces gas costs by avoiding storage reads. This optimization is particularly beneficial for frequently accessed variables, as it improves contract efficiency and reduces transaction costs.

// Example of declaring variables as immutable
contract EggVault {
address public immutable eggNFT;
address public immutable eggVault;
constructor(address _eggNFT, address _eggVault) {
eggNFT = _eggNFT;
eggVault = _eggVault;
}
}

Recommended Mitigation:
To address the issue, update the contract as follows:

  1. Declare the variables as immutable in the contract.

  2. Modify the constructor to initialize these variables.

// Updated Example
contract EggVault {
address public immutable eggNFT;
address public immutable eggVault;
constructor(address _eggNFT, address _eggVault) {
require(_eggNFT != address(0), "Invalid NFT address");
require(_eggVault != address(0), "Invalid Vault address");
eggNFT = _eggNFT;
eggVault = _eggVault;
}
}

This ensures that the variables are set only once during deployment and cannot be modified later, reducing gas costs and improving contract efficiency.

Updates

Lead Judging Commences

m3dython Lead Judge 8 months ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity
Assigned finding tags:

Gas optimization

Strategy to save gas and minimize transaction costs

Support

FAQs

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

Give us feedback!