Rock Paper Scissors

First Flight #38
Beginner FriendlySolidity
100 EXP
View results
Submission Details
Severity: low
Invalid

Magic Number Usage for Timeout Interval in createGameWithEth & createGameWithToken

Summary

The RockPaperScissors::createGameWithEth and RockPaperScissors::createGameWithToken functions use a hardcoded value of 5 minutes to enforce a minimum _timeoutInterval. While functionally correct, this constitutes a magic number, which harms readability and maintainability. Replacing this literal with a named constant improves clarity and supports easier refactoring.


Vulnerability Details

function createGameWithEth(uint256 _totalTurns, uint256 _timeoutInterval) external payable returns (uint256) {
...
// @audit-issue Magic number usage for timeout interval
@> require(_timeoutInterval >= 5 minutes, "Timeout must be at least 5 minutes");
...
}
function createGameWithToken(uint256 _totalTurns, uint256 _timeoutInterval) external returns (uint256) {
...
// @audit-issue Magic number usage for timeout interval
@> require(_timeoutInterval >= 5 minutes, "Timeout must be at least 5 minutes");
...
}

Issue Explanation

The direct use of 5 minutes in both functions introduces the following problems:

  1. Reduced Readability
    The intent of the number is not obvious without additional context. A named constant like MIN_TIMEOUT_INTERVAL makes the purpose explicit.

  2. Harder to Modify
    Updating the minimum timeout value later requires searching for and replacing all literal values, which is error-prone.

  3. Consistency Risk
    Different developers may introduce slightly different timeout logic (e.g., 4 minutes, 6 minutes) without realizing the intended global standard.


Impact

  • Developer Confusion: Code is harder to interpret at a glance.

  • Maintainability Issues: Future changes to timeout logic are more difficult and error-prone.

  • Code Duplication Risk: Inconsistencies may arise in other parts of the codebase.


Tools Used

  • Aderyn


Recommendations

Introduce a descriptive constant to replace the 5 minutes literal:

uint256 public constant MIN_TIMEOUT_INTERVAL = 5 minutes;

Then update the relevant code:

require(_timeoutInterval >= MIN_TIMEOUT_INTERVAL, "Timeout must be at least 5 minutes");

This makes the code more readable, configurable, and less prone to errors.


Updates

Appeal created

m3dython Lead Judge 2 months ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity
Assigned finding tags:

Informational

Code suggestions or observations that do not pose a direct security risk.

m3dython Lead Judge 2 months ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity
Assigned finding tags:

Informational

Code suggestions or observations that do not pose a direct security risk.

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.