Last Man Standing

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

[M-1] - `pot` parameter in `GameEnded` event will always be set to 0, not reflecting the real pot amount.

[M-1] - pot parameter in GameEnded event will always be set to 0, not reflecting the real pot amount.


Description

  • In declareWinner() function, GameEnded event is called to store relevant data about the game that is being finished: emit GameEnded(currentKing, pot, block.timestamp, gameRound);. The problem is that pot value is being set to 0 before emitting GameEnded event creating a discrepancy between the real pot value before ending the game and the one that is being recorded on the event.

    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:

  • Everytime a game is being ended this error will be reproduced.

Impact:

  • Although this error does not directly affect contract funds or any user funds, it can create discrepancies when displaying data in a frontend or when collecting data from past games.

Proof of Concept

As we can see in the declareWinner function, pot is being set to 0 right before emiting the event.

@> pot = 0; // Reset pot after assigning to winner's pending winnings
emit GameEnded(currentKing, pot, block.timestamp, gameRound);

Recommended Mitigation

One recommended mitigation could be assigning the value of pot to a variable before setting pot to 0

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;
+ uint256 potAmount = pot;
pendingWinnings[currentKing] = pendingWinnings[currentKing] + pot;
pot = 0;
- emit GameEnded(currentKing, pot, block.timestamp, gameRound);
+ emit GameEnded(currentKing, potAmount, block.timestamp, gameRound);
}
Updates

Appeal created

inallhonesty Lead Judge 27 days 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.