Last Man Standing

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

Incorrect Prize Amount in GameEnded Event

Root + Impact

Description

  • When a winner is declared, the GameEnded event should emit the actual prize amount that the winner received.

  • The code incorrectly sets the pot to zero before emitting the event, causing the event to log a prize amount of 0 instead of the actual winnings amount.

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

Risk

Likelihood:

  • This bug will occur every time a winner is declared.

Impact:

  • Off-chain applications monitoring events will receive incorrect prize amounts of 0, breaking any game tracking functionality.

  • User interfaces would be broken and show misleading information to users.

Recommended Mitigation

Store the prize amount in a local variable before modifying the pot state variable.

block.timestamp > lastClaimTime + gracePeriod,
"Game: Grace period has not expired yet."
);
+ uint256 prizeAmount = pot;
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);
+ emit GameEnded(currentKing, prizeAmount, block.timestamp, gameRound);
}
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.