Rock Paper Scissors

First Flight #38
Beginner FriendlySolidity
100 EXP
View results
Submission Details
Severity: high
Invalid

Front-Running Vulnerability in Move Commitment

Summary

The RockPaperScissors smart contract is vulnerable to front-running due to the improper implementation of the commit-reveal pattern. Specifically, the second player can wait for the first player to reveal their move before committing their own, gaining an unfair advantage.

Vulnerability Details

The revealMove() function allows a player to reveal their move after both have committed. However, without enforcing a strict commit deadline, Player 2 can delay their commitment until after Player 1 reveals their move. Since commitment and reveal transactions are public on-chain, this leads to strategic front-running.

Vulnerable Code:

function revealMove(uint gameId, Move move, bytes32 salt) external {
...
require(game.players[msg.sender].exists, "You are not a player");
bytes32 moveHash = keccak256(abi.encodePacked(move, salt));
require(moveHash == game.players[msg.sender].moveHash, "Invalid move reveal");
...
}

Impact

  • Enables a malicious player to always win by selecting a counter move after seeing the opponent’s move.

  • Undermines fairness of the game.

Tools Used

  • Manual Code Review

Recommendations

  • Introduce strict commit and reveal deadlines.

  • Add forfeiture rules for players who fail to commit or reveal on time.

  • Example : require(block.timestamp <= game.commitDeadline, "Commit deadline passed");

Updates

Appeal created

m3dython Lead Judge about 2 months ago
Submission Judgement Published
Invalidated
Reason: Incorrect statement
m3dython Lead Judge about 2 months ago
Submission Judgement Published
Invalidated
Reason: Incorrect statement
cybervenom Submitter
about 2 months ago
m3dython Lead Judge
about 2 months ago
m3dython Lead Judge about 2 months ago
Submission Judgement Published
Invalidated
Reason: Incorrect statement

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.