The RockPaperScissors
contract allows players to create an unlimited number of games simultaneously without any restrictions. A malicious player can exploit this vulnerability to create numerous games, potentially causing resource exhaustion, degrading user experience, and temporarily locking funds in abandoned games.
In theRockPaperScissors::createGameWithEth
and RockPaperScissors::createGameWithToken
functions, there is no mechanism to limit the number of active games a single player can create:
This vulnerability has several negative impacts on the system:
Storage Bloat: Malicious users can create numerous games, increasing the contract's storage requirements and potentially increasing gas costs for other operations.
Funds Locking: Players joining these games will have their funds temporarily locked until timeout resolution, causing frustration and degrading user experience.
Game Manipulation: A player could create multiple games with different parameters to increase their chances of favorable matchups or game conditions.
Abandoned Games: Players can strategically abandon games they're losing, focusing only on games with favorable outcomes, which reduces the integrity of the game system.
Denial of Service: At scale, this could lead to a form of DoS attack by making legitimate game discovery more difficult among numerous abandoned or inactive games.
Implementing a reasonable limit on the number of active games per player would mitigate this vulnerability while maintaining the intended functionality of the contract
Manual Review
To address the unrestricted game creation vulnerability, I recommend implementing the following changes:
This implementation:
Tracks the number of active games per player
Enforces a reasonable limit (3 in this example, but can be adjusted)
Properly increments and decrements counters as games are created and completed
Provides a view function to check active game counts
The value for MAX_ACTIVE_GAMES_PER_PLAYER should be carefully chosen to balance user flexibility with system protection. A value between 3-5 is reasonable for most use cases, preventing abuse while allowing legitimate players to have multiple active games.
Additionally, consider implementing a game inactivity timeout mechanism to automatically cancel games that have been in the Created state for too long without player B joining, which would further mitigate the impact of abandoned 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.