TwentyOne

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

No check for tie result

Summary

There is no check if dealerHand and playerHand get equal points.

Vulnerability Details

In function call() where we compare both dealerHand and playerHand we have no check if they both get the same points.

Impact

If we recieve a equal result in points will be couted as a win for the dealer.

Tools Used

Manuel review

Recommendations

First we need to add the check for dealerHand > playerHand, because now It's just left as alternative result

else {
emit PlayerLostTheGame("Dealer's hand is higher, dealers winning hand: ", dealerHand);
endGame(msg.sender, false);
}

if both dealerHand > 21 and playerHand > dealerHand fail. After doing this the only possible result left is a tie between dealer and player. A new event needs to be created for this result:

event TheGameIsTie(string message, uint256 cardsTotal);

Also we need a new function to clean decks and send 1 ether back to player:

function endGameTie(address player) internal {
delete playersDeck[player].playersCards;
delete dealersDeck[player].dealersCards;
delete availableCards[player];
payable(player).transfer(1 ether);
}

And finally the check will look like:

else {
emit TheGameIsTie("Dealer's hand is equal to player's hand, they are tie", dealerHand);
}
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.