Eggstravaganza

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

No protection against early game termination

Note: The documentation does not clarify whether the game owner is allowed to end the game before the scheduled end time. In the scenario shown below, the game is expected to run for a fixed duration defined at its start.

Summary

Currently, there is no safeguard preventing the game owner from ending the game prematurely. Players should have the full, predetermined time to search for hidden eggs, and the owner should not have the ability to cut the game short.

Impact

The game can be terminated before the originally defined end time.

Proof of Code

Add the following code to the EggHuntGameTest.t.sol file within the EggGameTest contract.

function testEndGameBeforeEndOfItsDuration() public {
// start game
uint256 duration = 100;
uint256 currentTime = block.timestamp;
game.startGame(duration);
// check game status
assertEq(game.getGameStatus(), "Game is active");
// check the setting of start and end times
assertEq(game.startTime(), currentTime);
assertEq(game.endTime(), currentTime + 100);
// warp time to before the game duration
vm.warp(currentTime + duration - 1);
// end the game before game ends
game.endGame();
assertEq(game.getGameStatus(), "Game is not active");
}

Tools Used

  • Manual Review

  • Foundry

Recommended Mitigation

To ensure players have the full allotted time to complete the game, a safeguard should be implemented to prevent the game from ending before the predetermined duration has passed. It is recommended to introduce below changes within the EggHuntGame contract.

function endGame() external onlyOwner {
require(gameActive, "Game not active");
+ require(block.timestamp > endTime, "Game is not over yet");
gameActive = false;
emit GameEnded(block.timestamp);
}
Updates

Lead Judging Commences

m3dython Lead Judge 8 months ago
Submission Judgement Published
Invalidated
Reason: Design choice
Assigned finding tags:

Trusted Owner

Owner is trusted and is not expected to interact in ways that would compromise security

Support

FAQs

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

Give us feedback!