Eggstravaganza

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

[M-01] The game can be terminated before the configured duration is expired

Summary

[M-01] The game can be terminated before the configured duration is expired

Vulnerability Details

The following function EggHuntGame.sol::endGame() implements the conditions when exactly the game owner can terminate the game. There is only a check of the state variable gameActive. Ther is no check if endTime has expired. That leads to potential incorrect earlier game termination and no more player could take part of the underlying game, until a new game starts. In addition the function EggHuntGame.sol::getRemainigTime() returns the remaining time until endTime, misleading the players there is still active game, no matter the game has been actually stopped.

function endGame() external onlyOwner {
// the game could be terminated before the duration is expired
require(gameActive, "Game not active");
gameActive = false;
emit GameEnded(block.timestamp);
}

Impact

Мissing required check leads to:

  • incorrect earlier termination of the game

  • getTimeRemaining() missleads the players, returning incorrect result

  • players not able to participate anymore in the underlying game

Tools Used

Manual review
Foundry

PoC

Add the following test to EggHuntGameTest.t.sol.

function testEndGameBeforeDurationExpired() public {
uint256 duration = 100;
uint256 start = block.timestamp;
uint256 endTime = start + duration;
console.log("startTime: ", start);
console.log("expected endTime: ", start + duration);
vm.prank(game.owner());
game.startGame(duration);
vm.warp(block.timestamp + duration / 2);
vm.prank(game.owner());
game.endGame();
console.log("game ended: ", block.timestamp);
assertTrue(block.timestamp < endTime);
}

Recommendations

Add the following check to EggHuntGame.sol::endGame() in order to allow ending games only after the configured duration is expired. In addition endTime should be updated as well.

function endGame() external onlyOwner {
require(gameActive, "Game not active");
+ require(block.timestamp > endTime, "Game not ended yet");
gameActive = false;
+ endTime = block.timestamp;
emit GameEnded(block.timestamp);
}
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.