The TwentyOne contract incorrectly implements the value calculation for Ace cards in Blackjack. In standard Blackjack rules, an Ace can count as either 1 or 11, with the value being chosen to benefit the player. However, the current implementation always treats Aces as 1, which significantly disadvantages players and breaks core game mechanics.
Location: src/TwentyOne.sol
https://github.com/Cyfrin/2024-11-TwentyOne/blob/main/src/TwentyOne.sol#L29
https://github.com/Cyfrin/2024-11-TwentyOne/blob/main/src/TwentyOne.sol#L43
The vulnerability exists in both the playersHand() and dealersHand() functions where card values are calculated. The current implementation treats Aces (cardValue == 1) the same as any other number card, assigning it a value of 1 instead of implementing the flexible 1/11 rule.
Proof of Concept:
The incorrect implementation of Ace card values has several significant impacts:
Game Mechanics Breaking
Players cannot achieve Blackjack (21) with an Ace + 10-value card combination
Natural Blackjack hands are impossible, removing a key game feature
Players are forced to treat Aces as only 1, significantly reducing strategic options
This implementation does not follow standard Blackjack rules
Economic Impact
Players have reduced winning chances due to suboptimal hand values
Potential loss of player funds due to hands being incorrectly valued
House advantage is artificially increased beyond intended game design
Trust and Fairness
Breaks standard Blackjack rules that players expect
May lead to player dissatisfaction and loss of trust
Could be perceived as intentionally unfair game mechanics
Foundry Testing Framework
Manual Code Review
Custom test cases for Ace card scenarios
Implement Flexible Ace Value Calculation:
Update Existing Functions:
Modify both playersHand() and dealersHand() to use the new calculation method
Ensure consistent Ace handling across all game functions
Add Comprehensive Testing:
Test Ace + face card combinations
Test multiple Ace scenarios
Test edge cases with Aces and various hand totals
Verify correct Blackjack detection
Documentation Updates:
Add clear documentation about Ace card handling
Include examples of various Ace value scenarios
Document the expected behavior for multiple Aces
Naturals. If a player's first two cards are an ace and a "ten-card" (a picture card or 10), giving a count of 21 in two cards, this is a natural or "blackjack." If any player has a natural and the dealer does not, the dealer immediately pays that player one and a half times the amount of their bet.
Naturals. If a player's first two cards are an ace and a "ten-card" (a picture card or 10), giving a count of 21 in two cards, this is a natural or "blackjack." If any player has a natural and the dealer does not, the dealer immediately pays that player one and a half times the amount of their bet.
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.