In the TwentyOne
contract, the playersHand
and dealersHand
function is responsible for calculating the total value of a player's hand in the game. However, the current implementation does not properly handle Aces, which can have a value of either 1 or 11 depending on the total hand value. This oversight results in inaccurate hand totals, potentially causing the contract to misjudge whether a player has exceeded 21 or reached the best possible hand. This could negatively affect the game logic and fairness, leading to incorrect outcomes.
The playersHand
and dealersHand
functions iterates through the player's cards and calculates their total value. While it handles face cards (Jack, Queen, King) correctly, it fails to account for the dynamic value of Aces. An Ace is always counted as 1 in the current implementation, regardless of whether counting it as 11 would yield a better hand value without exceeding 21.
Current implementation:
The lack of proper Ace handling can lead to situations where the player's total is unnecessarily low or a valid hand is incorrectly flagged as a bust.
A player is dealt two cards Aces and a 10.
The playersHand
function calculates the hand total as follows:
Each Ace is counted as 1.
The total is 1 (Ace) + 10 = 11
.
The correct total should be 11 (Ace) + 10 = 21
, but the function returns 11 due to improper Ace handling.
This could lead to incorrect decisions in the game, such as the player losing or hitting unnecessarily.
Game Logic Errors:
Miscalculated hand totals result in incorrect game outcomes, undermining the integrity of the game.
Player Dissatisfaction:
Players may lose confidence in the game's fairness due to incorrect handling of hands containing Aces.
Negative User Experience:
Unfair losses or misjudged game decisions caused by this bug could reduce player engagement and trust in the platform.
Manual Review
To ensure the playersHand
and dealersHand
function calculates accurate hand totals, implement logic to dynamically handle Aces as either 1 or 11. The function should count Aces as 1 initially and then adjust their value to 11 if doing so would not cause the player to exceed 21.
Updated implementation:
This implementation correctly handles Aces, ensuring that they contribute optimally to the hand total without causing a bust.
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.