The Last Man Standing game has a vulnerability in its declareWinner()
function where the GameEnded
event is emitted with an incorrect pot value. The event is emitted after the pot value has been reset to zero, which means that all event logs will show a pot value of 0 regardless of the actual prize amount won.
The GameEnded
event should accurately reflect the prize amount won by the king when the game ends. This information is important for off-chain applications, analytics, and historical record-keeping.
The GameEnded
event is emitted with a pot value of 0 because the event is emitted after the pot has been reset. This makes it impossible to determine the actual prize amount from the event logs.
The vulnerability exists in the declareWinner()
function where the pot is reset before emitting the event:
The issue is that the pot
variable is set to 0 before the GameEnded
event is emitted, causing the event to always show a pot value of 0.
The impact is medium because:
It doesn't affect the actual functionality of the contract (the winner still gets the correct amount)
However, it breaks the event log's integrity, which is important for:
Off-chain applications that rely on events for data
Historical record-keeping and analytics
Transparency for users and stakeholders
The likelihood is high as this issue will occur every time a winner is declared. It's not an edge case but affects a core event in the contract.
The issue can be verified by examining the declareWinner()
function in Game.sol. The pot
variable is reset to 0 before the GameEnded
event is emitted.
Store the pot value in a temporary variable before resetting it, and use this temporary variable in the event:
The fix stores the pot value in a temporary variable winningAmount
before resetting it, and then uses this variable in the GameEnded
event. This ensures that the event accurately reflects the actual prize amount won by the king, maintaining the integrity of the event logs.
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.