Rock Paper Scissors

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

Magic Number Used in Token Transfers in `createGameWithToken` and `joinGameWithToken`

Summary

The RockPaperScissors::createGameWithToken and RockPaperScissors::joinGameWithToken functions use a hardcoded value 1 for token transfers, a magic number that reduces code readability and maintainability. A named constant should be used instead.

Vulnerability Details

In RockPaperScissors::createGameWithToken and RockPaperScissors::joinGameWithToken, the contract uses the hardcoded value 1 in the winningToken.transferFrom calls to transfer tokens from the caller to the contract. This magic number lacks context, making it unclear what the value represents (e.g., the required token stake amount). Hardcoding such values reduces code readability and increases the risk of errors if the token amount needs to change in the future, as developers must manually update all instances of 1 across the codebase.

Impact

  • Reduced code readability, making it harder for developers to understand the purpose of the token transfer amount.

  • Increased maintenance burden, as changing the token stake amount requires updating hardcoded values in multiple places.

  • Potential for errors if the hardcoded value is inconsistently updated in future modifications.

  • No immediate security impact, but it violates best practices for maintainable smart contract development.

Tools Used

Manual Review

Recommendations

+ uint256 public constant TOKEN_STAKE_AMOUNT = 1;
function createGameWithToken(uint256 _totalTurns, uint256 _timeout) external returns (uint256) {
- winningToken.transferFrom(msg.sender, address(this), 1);
+ winningToken.transferFrom(msg.sender, address(this), TOKEN_STAKE_AMOUNT);
}
function joinGameWithToken(uint256 _gameId) external {
- winningToken.transferFrom(msg.sender, address(this), 1);
+ winningToken.transferFrom(msg.sender, address(this), TOKEN_STAKE_AMOUNT);
}
Updates

Appeal created

m3dython Lead Judge 4 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 4 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.