Summary
The push case isn't configured, if the dealer and the player have the same card, the player actually loose
Vulnerability Details
On the if else if else there is one else if missing where if the dealer hand and the player hand have the same number, the eth bet return to the player
Impact
Actually, if it's a push the player loose all of his eth
Tools Used
Recommendations
Current code :
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);
}
}
function endGame(address player, bool playerWon) internal {
delete playersDeck[player].playersCards;
delete dealersDeck[player].dealersCards;
delete availableCards[player];
if (playerWon) {
payable(player).transfer(2 ether);
emit FeeWithdrawn(player, 2 ether);
}
}
Correction :
event PlayerPush(string message, uint256 cardsTotal);
if (dealerHand > 21) {
emit PlayerWonTheGame(
"Dealer went bust, players winning hand: ",
playerHand
);
endGame(msg.sender, true, false);
} else if (playerHand > dealerHand) {
emit PlayerWonTheGame(
"Dealer's hand is lower, players winning hand: ",
playerHand
);
endGame(msg.sender, true, false);
} else if (playerHand = dealerHand){
emit PlayerPush(
"Dealer and Players hand are the same, push",
playerHand
)
endGame(msg.sender, false, true)
} else {
emit PlayerLostTheGame(
"Dealer's hand is higher, dealers winning hand: ",
dealerHand
);
endGame(msg.sender, false, false);
}
}
function endGame(address player, bool playerWon, bool playerPush) internal {
delete playersDeck[player].playersCards;
delete dealersDeck[player].dealersCards;
delete availableCards[player];
if (playerWon) {
payable(player).transfer(2 ether);
emit FeeWithdrawn(player, 2 ether);
}
if (playerPush) {
payable(player).transfer(1 ether);
emit FeeWithdrawn(player, 1 ether);
}
}