Eggstravaganza

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

Improper Game End Handling in EggHuntGame.sol

Summary

The EggHuntGame contract contains a design flaw in how it handles game end conditions. When a game's time elapses (block.timestamp > endTime), the contract enters an inconsistent state where the gameActive flag remains true, but the time-based checks prevent players from executing game actions. This inconsistent state persists until the contract owner explicitly calls the endGame() function.

Vulnerability Details

The issue arises because these two mechanisms can become out of sync:

function searchForEgg() external {
require(gameActive, "Game not active");
require(block.timestamp >= startTime, "Game not started yet");
require(block.timestamp <= endTime, "Game ended");

When a game's duration expires (block.timestamp > endTime), the contract continues to report that the game is active via the gameActive flag, but the time check in searchForEgg() prevents any further game actions. This creates an ambiguous state where:

  • gameActive == true suggests the game is active

  • Time-based checks prevent any game actions

  • getGameStatus() returns "Game time elapsed"

The game remains in this inconsistent state until the owner explicitly calls endGame().

Impact

User Confusion: Players may see the game is marked as active but cannot perform game actions

Interface Issues: dApps that rely solely on the gameActive flag to determine game state will display incorrect information

Contract Interaction Problems: External contracts that check only the gameActive flag might make incorrect decisions

Resource Consumption: The game remains in a semi-active state, potentially preventing new games from being starte

Tools Used

Maual code review

Forge Foundry

Recommendations

Automatic Game End: Modify the contract to automatically update the gameActive flag when block.timestamp > endTime:

function searchForEgg() external {
// Auto-update gameActive when time has elapsed
if (block.timestamp > endTime && gameActive) {
gameActive = false;
emit GameEnded(block.timestamp);
}
require(gameActive, "Game not active");
require(block.timestamp >= startTime, "Game not started yet");
require(block.timestamp <= endTime, "Game ended");
Updates

Lead Judging Commences

m3dython Lead Judge 2 months ago
Submission Judgement Published
Validated
Assigned finding tags:

Incomplete end game handling

Incorrect values reported when a game is ended early

Support

FAQs

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