Rock Paper Scissors

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

Missing check for game existence in joinGameWithToken()

Summary

The function joinGameWithToken() allows a player to join a non-existent game, since there is no check for whether the specified gameId actually maps to a created game.

Vulnerability Details

Accessing games[_gameId] on an uninitialized mapping entry returns a default struct. If playerA is address(0), this is likely an invalid game. However, the function continues assuming the game exists, allowing a player to join and triggering side effects like token transfers.

Impact

  • Game integrity violated

  • Players can join games that were never created

Tools Used

  • Manual code review

Recommendations

Add a guard to verify the game exists:

function joinGameWithToken(uint256 _gameId) external {
Game storage game = games[_gameId];
+ require(game.playerA != address(0), "Game does not exist");
require(game.state == GameState.Created, "Game not open to join");
require(game.playerA != msg.sender, "Cannot join your own game");
require(block.timestamp <= game.joinDeadline, "Join deadline passed");
require(game.bet == 0, "This game requires ETH bet");
require(winningToken.balanceOf(msg.sender) >= 1, "Must have winning token");
// Transfer token to contract
winningToken.transferFrom(msg.sender, address(this), 1);
game.playerB = msg.sender;
emit PlayerJoined(_gameId, msg.sender);
}

This should be placed after fetching the game struct but before any other logic.

Updates

Appeal created

m3dython Lead Judge 4 months ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity
Assigned finding tags:

Informational

Code suggestions or observations that do not pose a direct security risk.

m3dython Lead Judge 4 months ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity
Assigned finding tags:

Informational

Code suggestions or observations that do not pose a direct security risk.

Support

FAQs

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