TwentyOne

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

Incorrect logic handled for the case when `cardValue` is equal to zero inside `TwentyOne::dealersHand` function.

Description

In the TwentyOne::dealersHand function, the condition evaluated in the if statement in L:47 doesn't count the case when cardValue is equal to zero as the TwentyOne::playersHand does.

if (cardValue >= 10) {
dealerTotal += 10;
} else {
dealerTotal += cardValue;
}

Impact

In this case when cardValue is equal to zero, the value of 0 will be added to the dealerTotal variable. This will result in an incorrect value assigned, since the correct value added to dealerTotal should be 10, due to when cardValue is equal to zero, it represents the case where a K card is given to the dealer.

Recommended mitigation

Change the logic to the same inside TwentyOne::playersHand function.

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.