In both joinGameWithEth()
and joinGameWithToken()
functions, the game state is not updated from Created
to Committed
after a player joins. This is inconsistent with the game flow described in the README and could lead to unexpected behavior, including potential race conditions and confusion for players.
The issue exists in two functions:
In joinGameWithEth()
(lines 153-164), after Player B joins a game with ETH:
Similarly, in joinGameWithToken()
(lines 170-185), after Player B joins a game with tokens:
According to the game flow described in the README and the contract's state machine design, the game should transition from Created
to Committed
once Player B joins. However, this state transition is missing in both join functions.
Instead, the state is only updated to Committed
in the commitMove()
function (line 201) when the first player makes a move, but only if both commitA
and commitB
are empty (first turn, first commits).
This issue has several potential impacts:
Race Conditions: Multiple players could attempt to join the same game if the state isn't immediately updated after the first player joins.
Inconsistent Game State: The game state doesn't accurately reflect the current stage of the game, making it harder to reason about the contract's behavior.
Unexpected Behavior: Players might be confused about whether they can still join a game that appears to be in the Created
state even though it already has two players.
Contract Logic Inconsistency: The contract relies on checking the game state in multiple functions, and inconsistent state management could lead to unexpected behavior in other parts of the contract.
While this issue doesn't directly lead to fund loss, it creates confusion and potential race conditions that could impact the user experience and contract reliability.
Manual code review
Update both join functions to set the game state to Committed
after a player successfully joins:
For joinGameWithEth()
:
For joinGameWithToken()
:
Update the commitMove()
function to handle the case where the game is already in the Committed
state after a player joins, but before any moves are committed.
Code suggestions or observations that do not pose a direct security risk.
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.