TwentyOne

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

`call()` logic determines the player to lose even when player and dealer has same cardValue (a tie)

Summary

In the scenario of the player and dealer having the same cardValue(a tie), the else statement will catch this condition and assume the player to have lost the game and the dealer's hand is higher. Which in actual fact is incorrect.

Vulnerability Details

In the scenario of the player and dealer having the same cardValue(a tie), the else statement will catch this condition and determine the player of have lost the game and the dealer's hand is higher. Which in actual fact is incorrect.

function call() public {
..........
// Determine the winner
if (dealerHand > 21) {
emit PlayerWonTheGame(
"Dealer went bust, players winning hand: ",
playerHand
);
endGame(msg.sender, true);
} else if (playerHand > dealerHand) {
emit PlayerWonTheGame(
"Dealer's hand is lower, players winning hand: ",
playerHand
);
endGame(msg.sender, true);
} else {
emit PlayerLostTheGame(
"Dealer's hand is higher, dealers winning hand: ",
dealerHand
);
endGame(msg.sender, false);
}
}

Impact

This causes unfairness to players and reduces the integrity of the protocol.

Tools Used

Foundry

Recommendations

Implement another logic check to handle the scenario of dealer and player having same cardValue

else if (playerHand == dealerHand) {
implement action here...
}
Updates

Lead Judging Commences

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

Tie case

Support

FAQs

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