The current implementation of the RockPaperScissors::_cancelGame
function allows a user to create a game with a token bet and immediately cancel it while the game is still in the "Created" state. If no one has joined or if neither player has committed, the user can call the cancellation function to receive minted tokens instead of returning the originally sent tokens.
This behavior leads to the minting of new tokens instead of transferring the existing ones back to the creator, enabling attackers to exploit this mechanism. By repeatedly creating and canceling games, an attacker can mint an unlimited number of tokens, resulting in token supply inflation. This vulnerability arises due to improper tracking of tokens sent to the contract and the failure to return or burn those tokens upon cancellation.
Initial Setup:
Player1 has 10 tokens, contract has 0.
Game Creation:
Player1 creates a game, spending 1 token.
New balances: Player1: 9 tokens, Contract: 1 token.
Game Cancellation:
Player1 cancels the game.
Final balances: Player1: 10 tokens (refund received), Contract: 1 token.
Conclusion:
The test confirms that after game cancellation, the player gets their token back, but the contract retains 1 token.
The impact of this vulnerability is significant as it allows an attacker to artificially inflate the token supply by repeatedly creating and canceling games. Since tokens are minted for the creator instead of returning the original bet, the attacker can amass an arbitrary number of tokens without any real stake in the game.
This inflation of tokens undermines the token economy, potentially decreasing the value of the token, destabilizing its market price, and eroding trust in the system. Furthermore, the lack of proper token tracking and handling can lead to a loss of integrity in the game's mechanics and economy, potentially causing long-term damage to the project's reputation and financial stability.
Foundry
Replace the logic that mints new tokens upon game cancellation with a mechanism that instead either:
Transfers the originally staked tokens back to the player from the contract’s balance, or
Burns the tokens held by the contract and mint fresh tokens to the players, that way the tokenomics stays in check.
Mints new tokens upon game completion or cancellation for token-based games
Mints new tokens upon game completion or cancellation for token-based games
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.