Last Man Standing

First Flight #45
Beginner FriendlyFoundrySolidity
100 EXP
View results
Submission Details
Impact: low
Likelihood: low
Invalid

Redundant pot reset operation wastes gas and creates code confusion

Description:

The resetGame() function contains a redundant state variable reset that is guaranteed to be unnecessary due to the game's flow control. In resetGame():

function resetGame() external onlyOwner gameEndedOnly {
currentKing = address(0);
lastClaimTime = block.timestamp;
pot = 0; // This line is redundant
claimFee = initialClaimFee;
gracePeriod = initialGracePeriod;
gameEnded = false;
gameRound = gameRound + 1;
emit GameReset(gameRound, block.timestamp);
}

However, the pot variable is already guaranteed to be zero when resetGame() is called due to the following logical flow:

  1. resetGame() has the gameEndedOnly modifier, meaning it can only be called after a game has ended

  2. The only way a game can end is through declareWinner() function

  3. In declareWinner() the pot is explicitly reset to zero:

pendingWinnings[currentKing] = pendingWinnings[currentKing] + pot;
pot = 0; // Reset pot after assigning to winner's pending winnings

Therefore, pot = 0; in resetGame() is always redundant since the pot is guaranteed to already be zero.

Impact:

Unnecessary SSTORE operation costs ~5,000 gas for setting an already-zero value to zero

Recommended Mitigation:

Remove the redundant pot = 0; line from the resetGame() function:

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);
}
Updates

Appeal created

inallhonesty Lead Judge about 1 month ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.