Eggstravaganza

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

Game Time Control Issues

Summary

The game time control in the EggHuntGame contract has inconsistencies that may lead to game state not matching actual time, affecting game experience and fairness.

Vulnerability Details

The current game status reporting mechanism allows the game to be in a state where gameActive is true but block.timestamp > endTime:

function getGameStatus() external view returns (string memory) {
if (gameActive) {
if (block.timestamp < startTime) {
return "Game not started yet";
} else if (block.timestamp >= startTime && block.timestamp <= endTime) {
return "Game is active";
} else {
return "Game time elapsed";
}
} else {
return "Game is not active";
}
}

However, there is no automatic mechanism to end the game when time expires. This means the game can still be "active" even though getGameStatus returns "Game time elapsed".

Impact

  1. Game state inconsistent with actual time

  2. Potential user confusion

  3. Possible game mechanic exploits

  4. Reliance on manual intervention to end games

Tools Used

  • Manual code review

  • Time control logic analysis

Recommendations

Implement an automatic game state update mechanism or add a function that can be called by anyone to update game state when time expires:

// Add a function that can be called by anyone to end an expired game
function endExpiredGame() external {
require(gameActive, "Game not active");
require(block.timestamp > endTime, "Game time not elapsed yet");
gameActive = false;
emit GameEnded(block.timestamp);
}
// Or modify the searchForEgg function to automatically end the game if time has elapsed
function searchForEgg() external {
require(gameActive, "Game not active");
require(block.timestamp >= startTime, "Game not started yet");
// Automatically end expired games
if (block.timestamp > endTime) {
gameActive = false;
emit GameEnded(block.timestamp);
revert("Game has ended");
}
// Continue with normal search logic...
}
Updates

Lead Judging Commences

m3dython Lead Judge 5 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.