Description
In the declareWinner()
function, the GameEnded
event emits pot
as the prize amount. However, pot
is reset to zero before the event is emitted:
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;
@> emit GameEnded(currentKing, pot, block.timestamp, gameRound);
}
As a result, the `prizeAmount` field in the emitted event will always be 0, which misrepresents the actual winnings distributed and causes incorrect logs for indexers or off-chain systems.
Impact:
Frontends and analytics tools will display wrong prize amounts.
Recommended Mitigation
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); //@audit pot = 0 now
}
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
}