Eggstravaganza

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

Inaccurate Game Status Reporting

Summary

The getGameStatus function returns contradictory game states when gameActive is manually set to true but the current timestamp exceeds endTime. This creates mismatched status displays and operational inconsistencies.

Vulnerability Details

Flawed State Logic:

function getGameStatus() external view returns (string memory) {
if (gameActive) {
// Contradictory state when block.timestamp > endTime
if (block.timestamp < startTime) return "Game not started yet";
else if (block.timestamp <= endTime) return "Game is active";
else return "Game time elapsed"; // ❌ gameActive=true but game expired
}
return "Game is not active";
}

Key Issues:

  1. Manual gameActive state is not auto-synced with time conditions

  2. Allows gameActive=true and block.timestamp > endTime coexistence

  3. Frontend may display "Game time elapsed" while other functions still accept interactions

Impact

• User confusion due to conflicting status indicators (Low)
• Potential gas waste from invalid transactions (Medium)
• Inaccurate game analytics if admins forget to call endGame() (Medium)

Tools Used

• Manual code review

Recommendations

1. Time-Driven State Machine

function getGameStatus() external view returns (string memory) {
if (!gameActive) return "Game is not active";
if (block.timestamp < startTime) return "Game starts soon";
if (block.timestamp > endTime) return "Game ended"; // Auto-override gameActive
return "Game is active";
}

2. Auto-State Termination

modifier checkGameActive() {
if (block.timestamp > endTime) {
gameActive = false;
emit GameEnded(block.timestamp);
}
_;
}
function searchForEgg() external checkGameActive {
require(gameActive, "Game ended");
// ... original logic ...
}

3. Enhanced Admin Controls

function startGame(uint256 duration) external onlyOwner {
require(endTime == 0, "Game already configured"); // Prevent reinitialization
// ... original logic ...
}
Updates

Lead Judging Commences

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