The Rock Paper Scissors game smart contract contains a _handleTie
function that is theoretically unreachable due to the contract's requirement that all games must have an odd number of turns. This results in unused code that increases contract size, gas costs, and may indicate confusion about the game's mechanics or edge cases.
The contract enforces that all created games must have an odd number of turns through a requirement in both game creation functions (createGameWithEth
and createGameWithToken
):
This requirement is specifically designed to prevent ties, as games with an odd number of turns will always result in one player having more wins than the other (assuming all turns are completed).
However, the contract still includes a _handleTie
function (lines 588-622) that distributes rewards in the case of a tie. This function is referenced in _determineWinner
:
The comment acknowledges that ties should be impossible with odd turns but suggests the function might be needed for "timeouts or other unusual scenarios." However, the contract's design doesn't create any scenarios where a properly initialized game with an odd number of turns would result in a tie, even with timeouts.
While this isn't a security vulnerability in the traditional sense, it has several negative impacts:
Increased Contract Size: Unnecessary code increases the deployment cost and size of the contract.
Maintenance Burden: Future developers maintaining the code might spend time understanding and maintaining a function that should never be used.
Manual code review
Logic flow analysis
Remove the Redundant Function:
The simplest solution is to remove the _handleTie
function entirely and modify the _determineWinner
function to not consider the tie case and use <= instead of < in the game turn check:
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.