TwentyOne

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

Incorrect Dealer Hand Value Calculation in TwentyOne::dealersHand Function

Summary

The dealerTotal calculation in the TwentyOne::dealersHand function does not account for cases where cardValue equals 0, resulting in an incorrect computation of dealerTotal.

Vulnerability Details

In the dealersHand function of the TwentyOne contract, when calculating the dealer's hand total (dealerTotal), the special case where cardValue equals 0 is not handled correctly. Specifically, when a card with a value of 0 is drawn, it is directly added to the total as 0 instead of being treated as 10 per the game rules. This miscalculation leads to an inaccurate dealerTotal, disrupting the normal flow of the game and affecting win/loss decisions.

Impact

Due to the miscalculation of the dealer's hand total, the following significant issues may arise:

  1. Unfair game results, where players may lose a game they should have won.

  2. Incorrect dealer strategy execution, affecting the overall fairness of the game.

Tools Used

Manual review.

Recommendations

It is recommended to modify the logic in the dealersHand function to correctly handle the case where cardValue equals 0. Specifically, adjust the condition from "cardValue >= 10" to "cardValue == 0 || cardValue >= 10" to ensure that a drawn card with a value of 0 is correctly treated as 10 points. This change will ensure the dealer's hand total calculation aligns with game rules.

function dealersHand(address player) public view returns (uint256) {
uint256 dealerTotal = 0;
for (uint256 i = 0; i < dealersDeck[player].dealersCards.length; i++) {
uint256 cardValue = dealersDeck[player].dealersCards[i] % 13;
- if (cardValue >= 10) {
+ if (cardValue == 0 || cardValue >= 10) {
dealerTotal += 10;
} else {
dealerTotal += cardValue;
}
}
return dealerTotal;
}
Updates

Lead Judging Commences

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

Asymmetric calculation of hands is rigged in the player`s favor.

Support

FAQs

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