A critical vulnerability exists in the Rock-Paper-Scissors game smart contract that allows multiple players to join the same game as "Player B," resulting in lost funds. The contract fails to verify if a game already has a Player B before allowing new players to join, allowing an unlimited number of users to join the same game, with only the last one being recognized as the official Player B while all previous players lose their staked ETH or tokens.
The vulnerability exists in both the joinGameWithEth
and joinGameWithToken
functions, which lack a crucial check to verify if the game already has a Player B:
The same issue exists in the joinGameWithToken
function. When multiple players attempt to join the same game, the contract:
Accepts ETH or tokens from each player
Overwrites the game.playerB
address each time
Does not refund previous players
This issue is made worse by the reward calculation in the finishGame
function:
This calculation assumes exactly two players have contributed funds. However, with this vulnerability, the contract could collect funds from dozens of players while only accounting for two players' worth of stakes in the reward distribution.
Players who attempt to join a game that already has a Player B will lose their funds permanently.
The contract will accumulate more funds than it can distribute, creating an imbalance.
The game is designed for exactly two players, but this vulnerability allows more players to contribute funds.
Players losing funds will lose trust in the protocol.
Manual code review
Add a critical check in both join functions to verify that no Player B has already joined:
The same check should be added to the joinGameWithToken
function. This ensures that once a game has a Player B, no additional players can join and lose their funds.
Alternatively, you could consider changing the game state after a Player B joins:
Game state remains Created after a player joins
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.