Eggstravaganza

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

dead code in getGameStatus() __ EggHuntGame.sol

Summary

The getGameStatus() function attempts to return detailed game states like "Game time elapsed", but due to how the gameActive flag is used, this message becomes unreachable.

Vulnerability Details

The condition that returns "Game time elapsed" depends on gameActive still being true. However, in the endGame() function, gameActive is set to false, which causes getGameStatus() to skip that branch entirely.

As a result, once the game is manually ended or time has expired and gameActive is set to false, the function always returns "Game is not active" — even if the time actually ran out.

This makes the "Game time elapsed" branch unreachable and misleading about the true reason the game ended

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";
}
}

Impact

Users checking the game status may receive incorrect or incomplete feedback.

Tools Used

Manual review

Recommendations

Fixed code:

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 if (block.timestamp > endTime && gameActive) {
return "Game time elapsed";
}
} else {
return "Game is not active";
}
Updates

Lead Judging Commences

m3dython Lead Judge 3 months ago
Submission Judgement Published
Invalidated
Reason: Incorrect statement

Appeal created

hawks Submitter
3 months ago
m3dython Lead Judge 3 months ago
Submission Judgement Published
Invalidated
Reason: Incorrect statement

Support

FAQs

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