The playersHand
function in the TwentyOne
contract contains a logical flaw in handling the value of an Ace in Blackjack. The Ace is always counted as 10, instead of being flexible and allowing it to be counted as either 1 or 11, which is essential for accurate gameplay in Blackjack.
The playersHand
function calculates the total value of a player's hand but incorrectly handles the Ace by always counting it as 10. In Blackjack, an Ace can be worth either 1 or 11, depending on which value benefits the player most without causing the total to exceed 21.
The incorrect handling of the Ace's value can lead to inaccurate totals, causing players to lose games they should have won or not get the most advantageous hand. This impacts the fairness and integrity of the game, leading to potential user dissatisfaction and mistrust.
To identify this vulnerability, the following tools and techniques were used:
Manual Code Review: Detailed examination of the contract’s logic to identify discrepancies with Blackjack rules.
Foundry
To fix this issue, update the playersHand
function to correctly handle the Ace's flexible value. Here’s an improved version of the function that accurately accounts for Aces:
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.