Last Man Standing

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

Incorrect Event Emission in `declareWinner()` Causes Misleading Prize Data

Root + Impact

Description

  • The declareWinner() function should emit a GameEnded event that accurately reflects the final pot amount distributed to the winner. Off-chain systems, analytics tools, and UIs rely on this event for displaying accurate game results.

  • However, the contract resets the pot to zero before emitting the GameEnded event. As a result, the event logs a prize amount of 0, which does not match the actual payout that occurred internally via pendingWinnings[currentKing] += pot.

pot = 0; // Reset pot after assigning to winner's pending winnings
emit GameEnded(currentKing, pot, block.timestamp, gameRound);// @> Event emits 0 as the prize

Risk

Likelihood:

  • This will always occur when declareWinner() is called , the event will report the pot as zero every time.

  • Developers and users relying on event logs for prize tracking or frontend display will consistently receive incorrect information.

Impact:

  • Event logs provide misleading data about the amount won, breaking trust with users and developers.

  • Off-chain services such as subgraphs, dashboards, or game histories will show incorrect winnings for each round.

Recommended Mitigation

Capture the pot amount in a temporary variable before resetting it, and use that for emitting the event.

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

It preserves the accurate prize value for the event while still resetting the pot afterward.

External systems consuming the GameEnded event will now receive correct and consistent information.

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.