Last Man Standing

First Flight #45
Beginner FriendlyFoundrySolidity
100 EXP
View results
Submission Details
Severity: low
Valid

Incorrect prize amount logged in GameEnded event due to premature pot reset

Description:

The declareWinner() function contains a logic error in the order of operations that causes the GameEnded event to emit incorrect prize amount data.

pendingWinnings[currentKing] = pendingWinnings[currentKing] + pot;
pot = 0; // Reset pot after assigning to winner's pending winnings
emit GameEnded(currentKing, pot, block.timestamp, gameRound); // pot is already 0!

The sequence of operations is:

  1. Add pot amount to winner's pending winnings

  2. Reset pot to 0

  3. Emit event with the now-zero pot value

This means the GameEnded event will always log prizeAmount = 0 instead of the actual prize amount that was won, regardless of how much ETH was actually in the pot.

Example:

  • Pot contains 10 ETH when grace period expires

  • Winner should receive 10 ETH prize

  • Event emits: GameEnded(winner, 0, timestamp, round) instead of GameEnded(winner, 10, timestamp, round)

Impact:

External monitoring systems receive false prize amount information

Recommended Mitigation:

Store the pot amount before resetting it, then emit the event with the correct prize value:

function declareWinner() external gameNotEnded {
require(currentKing != address(0), "Game: No one has claimed the throne yet.");
require(block.timestamp >= lastClaimTime + gracePeriod, "Game: Grace period has not expired yet.");
gameEnded = true;
// Store the actual prize amount before resetting pot
uint256 prizeAmount = pot;
pendingWinnings[currentKing] = pendingWinnings[currentKing] + pot;
pot = 0; // Reset pot after assigning to winner's pending winnings
// Emit event with correct prize amount
emit GameEnded(currentKing, prizeAmount, block.timestamp, gameRound);
}

This ensures the event accurately reflects the actual prize amount won, maintaining data integrity for all external systems monitoring the contract.

Updates

Appeal created

inallhonesty Lead Judge about 1 month ago
Submission Judgement Published
Validated
Assigned finding tags:

Game::declareWinner emits GameEnded event with pot = 0 always

Support

FAQs

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