Owner can end game even if time of the game hasn't elapsed
When the game starts, it is determined upfront how long it will last. It’s not fair that games end before that predetermined time, yet it is possible to end them.
The function EggHuntGame::endGame can be executed only by the owner, and the only condition checked is whether the game is active or not. Yet, there is a duration for the game determined by the EggHuntGame::EndTime parameter, which can be greater than block.timestamp, meaning the game shouldn’t be ended.
Owner starts game with duration set to 100
The owner immediately ends the game
Other players cannot play, yet they expect that game stil last.
Following code should be placed inside EggHuntGameTest.t.sol
The player expects to be able to play if the duration time hasn’t elapsed. If the owner called EggHuntGame::endGame while EggHuntGame::EndTime > block.timestamp, any player who tries to call EggHuntGame::searchForEgg will have their transaction rejected. Yet it’s not fair that a player’s transaction is rejected while the predetermined condition of how long the game should last is still valid.
VS Code: Cloned the repository locally and identified the vulnerability through manual review.
The Function EggHuntGame::endGame should have one more condition to prevent ending the game while it still lasts.
Remaining time of game can be more than 0 after game has ended.
It is not sensable to have remaining time more than 0 if game has ended, yet owner can cause that kind of situation at his own will. Thus some players wouldn't have corret information about game time.
Using function EggHuntGame::endGame owner can end a game whenever they want. If time determined by EggHuntGame::startGame hasn't elapsed, function EggHuntGame::getTimeRemaining would then provide number bigger than 0 which would be incorrect since game is not active.
Player can use function EggHuntGame::getTimeRemaining and see that remaining game is more than 0. They can try to play the game by calling EggHuntGame::searchForEgg, but since game is not active their transaction will fail.
Vs Code: Cloned the repository locally and identified the vulnerability through manual review.
There are 2 posible solutions:
When owner calls EggHuntGame::endGame it can change parameter EggHuntGame::endTime to block.timestamp. That would suggest that time of game has elapsed.
When owner calls EggHuntGame::endGame and EggHuntGame::endTime > block.timestamp it reverts.
Incorrect values reported when a game is ended early
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.