A critical vulnerability in the timeoutJoin
function of the Rock-Paper-Scissors game smart contract leads to DOS attack. This vulnerability allows cancellation of non-existent games, potentially leading to a Denial of Service (DoS) attack against the platform. The issue stems from insufficient validation of game existence before performing state transitions.
The timeoutJoin
function is designed to allow cancellation of games that have reached their join deadline without player B joining. However, the function only validates that the game is in the Created
state without verifying if the game actually exists.
Since GameState.Created
has a value of 0 (the default value for enums in Solidity), calling timeoutJoin
on a non-existent game passes the state check, as the default values for non-existent mapping entries in Solidity are zero.
The test provided demonstrates that calling timeoutJoin
on a non-existent game ID (20) successfully transitions the game state to Cancelled
(state 4) without any errors.
The test shows that an attacker can call timeoutJoin
with any arbitrary game ID, causing the function to emit a GameCancelled
event and mark the game as Cancelled
without any cost or restrictions.
This vulnerability can be exploited to:
Cancel games that haven't been created yet, effectively reserving game IDs in a Cancelled
state
Execute a DoS attack by cancelling a large batch of sequential game IDs, preventing legitimate users from creating games with those IDs
Potentially disrupt platform operation by continuously cancelling future game IDs
Foundry framework for testing and verification
Manual code review
Restructure enum to avoid using meaningful states as zero values: The current enum design uses Created
as the first value (index 0), which is problematic because it's indistinguishable from an uninitialized state. Redesign the enum to include an explicit "Uninitialized" or "NonExistent" state as the first value:
Add existence validation: Implement a check to verify that the game has been properly initialized before allowing cancellation:
Implement game tracking: Keep track of valid game IDs using an array or a separate mapping to verify game existence:
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.