Last Man Standing

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

The `declareWinner` function emits event with incorrect `pot` value

Root + Impact

Description

  • The game design assumes that the declareWinner function will emit the GameEnded event with several information, among which should be information what pot size was won by a current king.

  • However, the GameEnded event will be emited with pot equal to 0 which can lead to confusion and incorrect off-chain services functioning.

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:

  • Described issue will occur every time when somebody will call the declareWinner function after a grace period expired after which a winner can be picked.

Impact:

  • Incorrectly emitted event can lead to confusion when verifying data on blockchain explorers.

  • Off-chain services that depend on correctly emited events can mulfunction.

Proof of Concept

​

Recommended Mitigation

To mitigate the issue, developers should move the event emision before reseting the pot variable value.

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

Appeal created

inallhonesty Lead Judge about 1 year 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.

Give us feedback!