Description
The EggHuntGame
contract does not reset critical game state variables between game sessions, namely:
eggCounter
: the global counter tracking minted egg token IDs.
eggsFound
: a mapping storing how many eggs each player has found.
As a result, starting a new game session after ending the previous one leads to the continuation of game progress, which violates the principle of session isolation and undermines fair competition.
Root Cause
The root issue lies in the lack of state resets in the startGame
function. While this function initiates a new game by setting timestamps and marking gameActive = true
, it does not reset:
eggCounter
— causing token IDs to continue incrementing across sessions.
eggsFound
— causes players’ prior scores to persist into the new session.
These variables are declared at the contract level and are not tied to any session identifier or scoped reset mechanism.
Proof of Concept (PoC)
The following test simulates two separate game sessions with different participants. It clearly shows that the state from the first session carries over into the second, creating misleading and cumulative stats.
Impact
The implications of this bug vary depending on how the game is intended to be played and rewarded:
Game results from a prior session persist, causing confusion and undermining trust in fairness.
Players who participated in earlier sessions retain unfair advantages over new participants.
Aggregated stats across sessions skew game analytics and any leaderboards built on eggsFound
.
eggCounter
continues incrementing, creating one continuous ID sequence across sessions. This may or may not be intended, but it should be explicitly clarified or corrected.
Users expecting a fresh game each time will be confused or misled if their old scores or behaviors affect new sessions.
To fix this issue and enforce session isolation, consider the following remediations:
startGame()
⚠️ Note: You’d need to track previous participants in an array like
address[] public previousPlayers
, and append to it insearchForEgg()
.
Refactor the contract to track stats per session:
Then, increment sessionId
and work only within the current session mapping for each game.
Failing to reset session-related state variables causes data from previous games to persist, potentially skewing scoring logic, user expectations, and reward fairness. For games intended to have distinct rounds or competitions, this bug can significantly degrade the experience and integrity of gameplay. A scoped or resettable state design is strongly advised.
Incorrect values reported when a game is ended early
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.