Eggstravaganza

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

No Explicit Initialization of eggCounter

Description:

In the EggHuntGame contract, the eggCounter variable is not explicitly initialized in the constructor. Although Solidity automatically initializes state variables of type uint256 to 0, not explicitly setting an initial value for this counter may cause confusion or potential issues when interacting with the contract in the future.

Impact:

Lack of explicit initialization might result in uncertainty for other developers interacting with the contract. While Solidity guarantees the variable starts at 0, explicitly initializing it makes the code clearer and avoids potential mistakes, especially if future modifications introduce assumptions about initia

Proof of Concept

In the current contract, eggCounter is declared but never initialized:

line: https://github.com/CodeHawks-Contests/2025-04-eggstravaganza/blob/main/src/EggHuntGame.sol#L23

uint256 public eggCounter;

The counter starts from 0, but it would be clearer and more robust to explicitly initialize it within the constructor like so:

uint256 public eggCounter = 0;

Recommended Mitigation:

Add an explicit initialization for eggCounter in the constructor, ensuring that its initial value is clear and documented:

constructor(address _eggNFTAddress, address _eggVaultAddress) Ownable(msg.sender){
require(_eggNFTAddress != address(0), "Invalid NFT address");
require(_eggVaultAddress != address(0), "Invalid vault address");
eggNFT = EggstravaganzaNFT(_eggNFTAddress);
eggVault = EggVault(_eggVaultAddress);
eggCounter = 0; // Explicit initialization
}
Updates

Lead Judging Commences

m3dython Lead Judge 3 months ago
Submission Judgement Published
Invalidated
Reason: Incorrect statement

Support

FAQs

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