TwentyOne

First Flight #29
Beginner FriendlyGameFiFoundrySolidity
100 EXP
View results
Submission Details
Severity: low
Invalid

Excessive Use of Magic Numbers

Summary

The contract contains multiple hardcoded numeric values ("magic numbers") without clear documentation or constant definitions. These numbers are used for game logic, card calculations, and ETH values, making the code less maintainable and more prone to errors.

Impact

  • Reduced code readability

  • Harder to maintain and modify

  • Increased risk of errors when updating values

  • Lack of clarity about the business logic

Proof of Concept

for (uint256 i = 1; i <= 52; i++) { // Magic number: 52 cards
availableCards[player].push(i);
}
uint256 standThreshold = (randomValue % 5) + 17; // Magic numbers: 5, 17
if (dealerHand > 21) { // Magic number: 21
// ...
}
payable(player).transfer(2 ether); // Magic number: 2 ether

Recommendations

  • Add constant to the contract

+ uint256 private constant DECK_SIZE = 52;
+ uint256 private constant BLACKJACK_VALUE = 21;
+ uint256 private constant MIN_DEALER_STAND = 17;
+ uint256 private constant DEALER_STAND_RANGE = 5;
// Payment constants
+ uint256 private constant REQUIRED_BET = 1 ether;
+ uint256 private constant WINNING_PAYOUT = 2 ether;
// Card constants
+ uint256 private constant FACE_CARD_VALUE = 10;
+ uint256 private constant CARDS_PER_SUIT = 13;
Updates

Lead Judging Commences

inallhonesty Lead Judge 11 months ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity

Support

FAQs

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