Root + Impact
[O-2] Modifier invoked only once.
Description
The Game::gameEndedOnly
modifier is invoked only once, the logic of it can be moved to the Game::resetGame
function since it is the only one requiring the modifier logic.
modifier gameEndedOnly() {
require(gameEnded, "Game: Game has not ended yet.");
_;
}
Risk
Likelihood: Low
Impact: None
Proof of Concept
The original Game::resetGame
function has a single invocation of the gameEndedOnly
modifier.
function resetGame() external onlyOwner gameEndedOnly {
currentKing = address(0);
lastClaimTime = block.timestamp;
pot = 0;
claimFee = initialClaimFee;
gracePeriod = initialGracePeriod;
gameEnded = false;
gameRound = gameRound + 1;
emit GameReset(gameRound, block.timestamp);
}
Recommended Mitigation
Consider removing the modifier or inlining the logic into the Game::resetGame
function.
- modifier gameEndedOnly() {
- require(gameEnded, "Game: Game has not ended yet.");
- _;
- }
- function resetGame() external onlyOwner gameEndedOnly {
+ function resetGame() external onlyOwner {
+ require(gameEnded, "Game: Game has not ended yet.");
currentKing = address(0);
lastClaimTime = block.timestamp;
pot = 0;
claimFee = initialClaimFee;
gracePeriod = initialGracePeriod;
gameEnded = false;
gameRound = gameRound + 1;
// totalClaims is cumulative across rounds, not reset here, but could be if desired.
emit GameReset(gameRound, block.timestamp);
}