GameEnded Event Emits Zero Value for Pot Prize when winner is declared, Providing Misleading Data to Off-Chain Services
Normal Behavior: When a winner is declared, the GameEnded event should be emitted with the correct winner address and the prizeAmount they have won. This allows off-chain services, front-ends, and analytics platforms to accurately track game history.
The Issue: In the declareWinner function, the state variable pot is set to 0 before the GameEnded event is emitted. The event is then called using the now-zeroed pot variable as the prizeAmount parameter. As a result, every GameEnded event will report a prize of 0, which is incorrect and misleading.
Likelihood: HIGH
This will happen for every game round that concludes with a declared winner.
Impact: LOW
This bug does not cause a loss of funds within the contract, as the prize is correctly assigned to pendingWinnings. However, it corrupts the contract's data history as told by its events. Any application or user relying on these events to display game results or calculate statistics will be broken or show incorrect information, undermining the transparency of the game.
Play the game until the pot contains a non-zero amount (e.g., 5 ETH).
Let the grace period expire.
Call the declareWinner() function.
Observe: Use an explorer like Etherscan or a local script to inspect the logs for the GameEnded event. The winner parameter will be correct, but the prizeAmount parameter will be 0.
Expected Result: The prizeAmount parameter in the event log should be 5 ETH.
Add this code to the test file:
Store the prize amount in a local memory variable before zeroing out the pot state variable. Use this local variable in the event emission.
Modify the declareWinner function as follows:
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.