The declareWinner()
function contains a state management error where it resets the pot
variable to 0 before emitting the GameEnded
event, causing the event to emit an incorrect prize amount of 0 instead of the actual prize won by the winner.
The normal behavior should emit the actual prize amount that the winner receives in the GameEnded
event
The specific issue is in lines 240-243 of src/Game.sol
where the pot is reset before the event emission
Likelihood:
This occurs every time declareWinner()
is called (100% occurrence rate)
The function will be called regularly as part of normal game flow
Impact:
Off-chain applications and frontends will receive incorrect prize amount information
Game analytics and historical tracking will show all games ended with 0 prize amounts
Users and interfaces cannot properly track actual winnings from events
This test demonstrates how the declareWinner()
function emits incorrect prize amount data in the GameEnded
event. The test sets up a scenario where a player claims the throne, the grace period expires, and then declareWinner()
is called. We expect the event to emit the actual prize amount that was accumulated in the pot, but due to the premature reset of the pot
variable, the event emits 0 instead.
The fix involves storing the pot value in a temporary variable before resetting it to zero. This ensures that when the GameEnded
event is emitted, it contains the actual prize amount that the winner received, rather than the reset value of 0. This maintains data integrity for off-chain applications and provides accurate historical records.
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.