TwentyOne

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

Ether Might Get Locked in Contract

Summary

Ether can be locked in contract if dealers got high hand; as there is no requirement in the func. endGame to transfer ether to dealer.

Vulnerability Details

  • As we see the func. call logic,

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);
}
  • now focus on endGame func. logic:

if (playerWon) {
payable(player).transfer(2 ether); // Transfer the prize to the player
emit FeeWithdrawn(player, 2 ether); // Emit the prize withdrawal event
}

Now the point is:

  • If the player won the game 2ether will be transfer to the player, but incase if the player lose the game the ether will be stuck in the contract, as there is no (require option) of transferring the funds to the dealer.

  • Also there is no withdraw function so the dealer can get the funds.

Impact

  • Loss of Funds

Tools Used

Manual Review

Recommendations

  • add constructor to the contract and set owner:

constructor () {
owner = msg.sender;
}
  • add onlyOwner modifier:

modifier onlyOwner() {
require(msg.sender == owner, "not the contract's owner");
_;
}
  • lastly add a withdrawal function, such as:

function withdrawRemainingEther(uint256 amount) public onlyOwner {
require(address(this).balance >= amount, "Insufficient contract balance");
(bool success, ) = owner.call{value: amount}("");
require(success, "Withdrawal failed");
}
Updates

Lead Judging Commences

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

Owner has no method to withdraw

Support

FAQs

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