The RockPaperScissors
contract contains a flaw where, after the first round, the revealDeadline
is not reset when players commit their moves in subsequent rounds. This allows a malicious player to commit their move, immediately reveal it (since revealDeadline
is stale from the first round), and then use timeoutReveal
to unfairly win the round before the opponent has a chance to commit or reveal their move.
In the commitMove
function, the revealDeadline
is only set if both players' commitments are submitted and it's the first round:
However, in rounds beyond the first, if a player commits first and then calls revealMove
, the stale revealDeadline
(from round 1) might already have passed. This allows them to:
Commit their move.
Immediately call revealMove
.
Wait a moment.
Call timeoutReveal
, claiming the opponent didn't reveal on time — even though the opponent never got a chance to commit in that round.
This leads to a forced win that breaks the fairness of the game.
Unfair advantage: A malicious player can abuse the outdated revealDeadline
to force wins.
Race condition: It creates a timing race where the first committer has the power to lock out the opponent.
Game logic flaw: The expected order of commit → commit → reveal → reveal is violated.
Undermines fairness: A core value of Rock-Paper-Scissors is simultaneous reveal, which this bug breaks.
Manual code review
Logic tracing of commitMove
, revealMove
, and timeoutReveal
Inference of state transitions across multiple rounds
Update the commitMove
function to reset revealDeadline
on every round, once both players have committed:
Ensure this block always runs, even after the first round. You might also refactor the condition logic to explicitly handle revealDeadline
reset in every round.
Additionally, consider adding a state check in revealMove
to prevent revealing before both commits are received:
This ensures the reveal phase begins only when both commitments are present, maintaining fair play.
timeoutReveal function incorrectly allows execution and game cancellation even when only one player has committed
Attack allows a player to reveal their move for the next turn before the opponent commits
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.