TwentyOne

First Flight #29
Beginner FriendlyGameFiFoundrySolidity
100 EXP
View results
Submission Details
Severity: low
Invalid

The function `TwentyOne::hit` should not revert in the case `handBefore` is greater than 21, but call `TwentyOne::endGame` instead

Description

In L::109 inside the TwentyOne::hit function, if the handBefore variable has a value greater than 21 then function will only revert, but the game is never ended eventhough the player would have lost already.

Impact

Since the TwentyOne::hit function only reverts if handBefore goes above 21, the user would need to make an extra call to TwentyOne::call function in order to terminate the game.

Recommended mitigation

Make the following code changes inside TwentyOne::hit

function hit() public {
require(
playersDeck[msg.sender].playersCards.length > 0,
"Game not started"
);
uint256 handBefore = playersHand(msg.sender);
- require(handBefore <= 21, "User is bust");
+ if (handBefore > 21) {
+ emit PlayerLostTheGame("Player is bust", handAfter);
+ endGame(msg.sender, false);
+ }
uint256 newCard = drawCard(msg.sender);
addCardForPlayer(msg.sender, newCard);
uint256 handAfter = playersHand(msg.sender);
if (handAfter > 21) {
emit PlayerLostTheGame("Player is bust", handAfter);
endGame(msg.sender, false);
}
}
Updates

Lead Judging Commences

inallhonesty Lead Judge 10 months ago
Submission Judgement Published
Invalidated
Reason: Incorrect statement

Support

FAQs

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