TwentyOne.sol Blackjack smart contract, the handling of Ace cards (which can be worth either 1 or 11 points) is not properly implemented in both the player's and the dealer's hand calculations. This issue leads to incorrect game logic, potentially resulting in faulty game outcomes. The logic for the dealer's hand also lacked proper handling for the Ace, which may cause inconsistent game results.The vulnerability lies in the improper handling of Ace cards, a crucial aspect of Blackjack game rules. In the original code:
For the player’s hand (playersHand function): Aces are treated as 10, which is incorrect. Aces should be treated as 1 initially, and if the total hand value allows, an Ace should be counted as 11.
For the dealer’s hand (dealersHand function): Aces are not properly accounted for in the hand's total value, and the dealer’s hand calculation logic is inconsistent with the player’s hand calculation.
The issue can cause incorrect total calculations for both the player and the dealer, affecting the outcome of the game. A player might think they have a valid total, but the game may incorrectly register their hand, leading to undesired consequences.
Player's Hand Logic:
Dealer's Hand Logic:
Player's hand: Aces are treated as 10, which can mislead the player into thinking their hand is better or worse than it really is.
Dealer's hand: Aces are not handled at all. The dealer’s total could be incorrectly calculated, which could affect the final outcome of the game.
Incorrect Card Values: Aces are treated incorrectly, potentially causing incorrect totals for both the player and the dealer.
Faulty Game Outcomes: The mismatch in hand totals can lead to an unfair game where either the player or the dealer might win or lose incorrectly.
Player Experience: The player might receive incorrect feedback (such as winning or losing), as their hand total is not calculated correctly.
Smart Contract Integrity: If not addressed, this flaw could undermine the trust in the smart contract, leading to disputes or manipulation of the game logic.
Manual Code Review: The code was manually reviewed for logical errors related to the handling of card values, especially Aces.
The issue can be resolved by fixing the Ace-handling logic in both the playersHand and dealersHand functions. This will ensure that Aces are treated as either 1 or 11 depending on the context, thus adhering to the correct rules of Blackjack.
playersHand:dealersHand: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.