TwentyOne

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

Inflexible Ace Valuation Reduces Game Authenticity

Summary

The playersHand() and dealersHand() functions always value Aces as 1, ignoring the standard blackjack rule that Aces can be 1 or 11. This limits strategic play and diverges from standard gameplay.

Vulnerability Details

  • Issue: Aces (cardValue == 1) are always counted as 1.

  • Affected Code Snippet:

    // Aces are added as 1 without flexibility
    playerTotal += cardValue;
  • Explanation: There's no logic to adjust the Ace's value to 11 when it benefits the hand total.

Impact

  • Reduced Strategic Depth: Players can't utilize the flexibility of Aces.

  • Deviation from Standard Rules: The game doesn't align with typical blackjack, possibly affecting player satisfaction.

Tools Used

  • Manual code review of playersHand() and dealersHand() functions.

Recommendations

  • Implement Flexible Ace Valuation:

    uint256 aceCount = 0;
    // When counting cards
    if (cardValue == 1) {
    playerTotal += 11;
    aceCount += 1;
    }
    // After summing cards
    while (playerTotal > 21 && aceCount > 0) {
    playerTotal -= 10;
    aceCount -= 1;
    }
  • Apply to Both Functions: Ensure both player and dealer hands handle Aces flexibly.

  • Add Tests: Create tests for hands with Aces to verify correct totals.

Updates

Lead Judging Commences

inallhonesty Lead Judge 11 months ago
Submission Judgement Published
Validated
Assigned finding tags:

Wrong ace value

Support

FAQs

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