Rock Paper Scissors

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

`joinGameWithEth` can be exploited to enter into games created by tokens

Summary

joinGameWithEth does not check whether the game the player is about to join was created with ETH.

Vulnerability Details

In createGameWithToken, game.bet is set to 0 when creating a game with token,

function createGameWithToken(uint256 _totalTurns, uint256 _timeoutInterval) external returns (uint256) {
.
.
.
// In the case of a game created by a Token, game.bet is set to 0
game.bet = 0; // Zero ether bet because using token

In joinGameWithEth, we do not check if the game we are joining is a game created by eth. Thus, we can use joinGameWithEth to enter into a game created by a token.

For example,

  1. PlayerA creates a game using createGameWithToken using a token.

  2. Attacker joins this game by calling joinGameWithEth with msg.value set to 0.

Impact

A player can join a game without paying any tokens. This eventually causes the game creator (playerA) to lose money, leading to a severe disruption of functionality.

Tools Used

VSCode

Recommendations

In joinGameWithEth, add a check to see if the game is created with Eth,

function joinGameWithEth(uint256 _gameId) external payable {
Game storage game = games[_gameId];
.
.
.
+ require(game.bet > 0, "This game requires Token bet");
require(msg.value == game.bet, "Bet amount must match creator's bet");
game.playerB = msg.sender;
emit PlayerJoined(_gameId, msg.sender);
}
Updates

Appeal created

m3dython Lead Judge 2 months ago
Submission Judgement Published
Validated
Assigned finding tags:

Game Staking Inconsistency

joinGameWithEth function lacks a check to verify the game was created with ETH

m3dython Lead Judge 2 months ago
Submission Judgement Published
Validated
Assigned finding tags:

Game Staking Inconsistency

joinGameWithEth function lacks a check to verify the game was created with ETH

Support

FAQs

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