Games are created without any limit. Which means, one user could create an unlimited number of games. With winning tokens, he could create a game for each token, for free. The struct Game
, which takes up 11 slots, is stored in the contract storage without any cleanup or deletion mechanism. So, if we keep adding entries to the games
mapping and never remove old/finished ones, your contract's state will keep growing forever.
In a long term, this could lead to bloat in the contract storage, which could make it impossible to interact with. There is a risk of Denial of Service (DoS) if the contract storage becomes too large. This could lead to a situation where users are unable to create or join games, effectively locking them out of the contract.
This is how the storage of the RockPaperScissors
contract looks like:
The Game
struct takes up 11 slots, and the games
mapping is public. This means that every time a game is created, the contract storage grows by 11 slots. If a user creates an unlimited number of games, the contract storage will grow indefinitely.
After creating 100 games, the contract storage has grown by 1100 slots. And at the end of each game (or cancelled), the game is not removed from the storage.
Imagine if a user creates 1000 games, the contract storage will grow by 11000 slots. And if the user never removes the games, the contract storage will keep growing indefinitely.
Foundry test:
Consider implementing a cleanup mechanism to remove old or finished games from the contract storage. This could be done by adding an admin function that allows the owner to remove games that are no longer needed. Additionally, consider adding a limit on the number of games that can be created by a single user. You could also track the active entries in the games
mapping and archive them when they are no longer needed (maybe off-chain).
Code suggestions or observations that do not pose a direct security risk.
Code suggestions or observations that do not pose a direct security risk.
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.