Eggstravaganza

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

The gameActive variable is not set to false automatically causing the EggHuntGame::getTimeRemaining returning an incorrect value.

Summary

The gameActive variable is set to false only when the owner call the EggHuntGame::endGame function. But this variable is not taken into account in the EggHuntGame::getTimeRemaining function returning an incorrect time remaining.

Vulnerability Details

The function EggHuntGame::getTimeRemaining calculates the time remaining of the game based on block.timestamp and does not take into account the gameActive variable.

function getTimeRemaining() external view returns (uint256) {
return block.timestamp >= endTime ? 0 : endTime - block.timestamp;
}

For example, if the owner starts a 10 min game and when 5 mins have passed he decides to call the EggHuntGame::endGame function, the game should be considered finished, but the EggHuntGame::getTimeRemaining function will say that there are still 5 mins left.

Impact

Incorrect return of the seconds remaining in the game.

Tools Used

  1. Foundry

  2. Manual Review

PoC

  1. Start a 10 minutes game.

  2. Let pass 5 mins.

  3. As the owner, end the game.

  4. Call the EggHuntGame::getTimeRemaining function and check the seconds remaining are 0.

function test_IncorrectTimeRemaining() public {
vm.prank(owner);
game.startGame(10 * 60);
vm.warp(1 + 5 * 60);
vm.prank(owner);
game.endGame();
uint256 timeRemaining = game.getTimeRemaining();
assertEq(timeRemaining, 0);
}

Copy this test on EggHuntGameTest.t.sol and see that it fails.

Recommendations

Take into account the gameActive variable.

function getTimeRemaining() external view returns (uint256) {
- return block.timestamp >= endTime ? 0 : endTime - block.timestamp;
+ return block.timestamp <= endTime && gameActive ? endTime - block.timestamp : 0;
}
Updates

Lead Judging Commences

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