The token ID management in the project is split between different contracts, with eggCounter in the EggHuntGame contract and totalSupply in the EggstravaganzaNFT contract. This redundant state tracking creates unnecessary complexity, increases gas costs, and introduces potential risks of state inconsistency. Additionally, the mintEgg function requiring a tokenId parameter from the caller is redundant when the NFT contract could generate and track token IDs internally.
The project implements token ID management in multiple locations:
This dual-tracking approach creates several issues:
Redundancy: Both contracts track essentially the same information (the total number of NFTs minted).
Increased Attack Surface: Managing token IDs in multiple contracts creates more opportunities for errors or inconsistencies.
State Synchronization Risk: The two counters could potentially get out of sync, especially if the gameContract address is ever updated or if direct minting capabilities are added in the future.
Gas Inefficiency: Each mint operation updates storage in multiple contracts, consuming more gas than necessary.
The impact of this redundancy is low to medium:
Gas Costs: Higher gas costs for minting operations due to multiple state updates.
Potential for Inconsistency: If minting occurs through alternate paths or if the game contract is updated, the counters could become inconsistent.
Code Complexity: The split responsibility makes the code harder to maintain and understand.
Centralization of Logic: The NFT contract depends on external logic for ID generation, reducing its reusability.
While this issue doesn't directly lead to fund loss, it represents a design flaw that increases complexity and gas costs while potentially introducing risks for future development.
PoC
This vulnerability can be demonstrated by tracking the state changes during a typical minting operation
Each egg minting requires two separate storage updates to maintain synchronization between the contracts.
Manual code review
Centralize token ID management in the NFT contract where it logically belongs:
or even use internal ERC721 totatlSupply
This approach offers several advantages:
Single Source of Truth: Only one contract maintains token ID information.
Reduced Attack Surface: No possibility of counter misalignment between contracts.
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.