Rock Paper Scissors

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

In `RockPaperScissor::_finishGame` function there is a logic error token distribution

Summary

In RockPaperScissor::_finishGame, the winner receives two newly minted tokens rather than receiving the tokens bet by the players.

Impact

This creates an inflation problem and does not properly transfer the ownership of the wagered WinningToken.

Tools Used

Manual code review

Recommendations

Instead of minting new tokens, transfer the wagered tokens from the protocol to the winner.

function _finishGame(uint256 _gameId, address _winner) internal {
Game storage game = games[_gameId];
game.state = GameState.Finished;
uint256 prize = 0;
// Handle ETH prizes
if (game.bet > 0) {
// Calculate total pot and fee
uint256 totalPot = game.bet * 2;
uint256 fee = (totalPot * PROTOCOL_FEE_PERCENT) / 100;
prize = totalPot - fee;
// Accumulate fees for admin to withdraw later
accumulatedFees += fee;
emit FeeCollected(_gameId, fee);
// Send prize to winner
(bool success,) = _winner.call{value: prize}("");
require(success, "Transfer failed");
}
// Handle token prizes - winner gets both tokens
if (game.bet == 0) {
// Mint a winning token
- winningToken.mint(_winner, 2);
+ (bool success,) = winningToken.transfer(_winner, 2)
+ require(success, "Transfer failed");
} else {
// Mint a winning token for ETH games too
winningToken.mint(_winner, 1);
}
emit GameFinished(_gameId, _winner, prize);
}
Updates

Appeal created

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

Minting Instead of Transferring Staked Tokens

Mints new tokens upon game completion or cancellation for token-based games

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

Minting Instead of Transferring Staked Tokens

Mints new tokens upon game completion or cancellation for token-based games

Support

FAQs

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