The Rock Paper Scissors contract uses bytes32(0)
as both a sentinel value to check if a player has committed a move and as a potentially valid commit value. This creates ambiguity in the game state and opens up potential exploits.
The contract uses bytes32(0)
to check if a player has already committed:
The vulnerability exists because:
The contract checks if a commit is bytes32(0)
to determine if a player has committed
But the contract does not prevent a player from committing the value bytes32(0)
This creates confusion: does bytes32(0)
mean "no commit" or a valid commit of zero?
A player could legitimately generate a commit hash that equals bytes32(0)
if they found the right combination of move and salt. Although extremely unlikely, it's theoretically possible.
This vulnerability impacts the game in several ways:
State Confusion: The contract uses bytes32(0)
both as "no commit" and potentially as a valid commit
Logic Errors: A player who commits bytes32(0)
might have their commit treated as "not committed"
Potential Game Manipulation: This confusion could be exploited to manipulate game state in certain edge cases
While difficult to exploit directly, this represents a fundamental flaw in state management and data integrity.
Manual code review
Add an explicit check to reject bytes32(0)
as a valid commit value:
This ensures a clear distinction between "no commit" (represented by bytes32(0)
) and valid commits (any non-zero value). This is a basic but important validation that maintains clean state management and prevents ambiguity.
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.