Last Man Standing

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

`GameEnded` Event Emits Incorrect Pot Value in `declareWinner()` function

Root + Impact

Description

In the `declareWinner()` function, the `GameEnded` event is emitted after the pot is reset to 0. As a result, the pot value logged in the event is always 0, even though the winner has received the actual prize internally through the pendingWinnings mapping. This creates a discrepancy between the internal state and the emitted event data.

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;
pendingWinnings[currentKing] = pendingWinnings[currentKing] + pot;
pot = 0; // Reset pot after assigning to winner's pending winnings
@> emit GameEnded(currentKing, pot, block.timestamp, gameRound);
}


*Impact*

The emitted event data misrepresents the amount won by the declared winner. Off-chain services (e.g., indexers, frontends, analytics tools) that rely on event logs for tracking the game's outcome will be misled, showing zero winnings instead of the actual prize. This does not affect the correctness of the contract’s internal logic, but it can confuse users and reduce transparency.

Recommended Mitigation

Store the pot value in a local variable before resetting it, and use that in the event emission:

gameEnded = true;
+ uint256 prize = pot;
pendingWinnings[currentKing] += prize;
pot = 0;
+ emit GameEnded(currentKing, prize, block.timestamp, gameRound);
Updates

Appeal created

inallhonesty Lead Judge about 2 months 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.