The contract currently faces an issue with player funds mismanagement, which could occur when the contract balance is insufficient to cover prize payouts at the end of the game. Specifically, if a player wins and the contract does not have enough funds to transfer the prize, the contract may revert, leaving the player without the expected reward. This vulnerability arises because there is no check or alternative flow to handle insufficient funds for payouts in the endGame()
function.
Insufficient Funds Check Missing: The contract does not check if it has enough balance to pay out the player’s prize (2 ether) when the game ends.
Potential for Unmet Expectations: When a player wins, they expect to receive the prize, but if the contract balance is insufficient, the contract will revert and no funds will be transferred.
No Fallback Mechanism: There is no mechanism to handle the situation where the contract balance is insufficient for payouts, such as storing pending payouts or notifying players of the insufficient balance.
Player Experience: Players may end a game expecting a payout, but due to insufficient funds in the contract, they will not receive the prize, and the transaction will fail.
Trust Issues: Players may lose trust in the contract, as it could appear that the game system is unreliable or faulty due to the unexpected lack of payouts.
Reverts and Inconsistent State: When the contract balance is insufficient, the transaction reverts entirely, including state changes like card drawing, making the contract behavior unpredictable and potentially confusing.
Financial Risk: The contract owner may face financial and reputational risks if players are not able to claim their prizes, leading to negative feedback or dispute
Manual Review
To address this issue, the following changes should be made to the startGame()
function:
Define Constants for Payout and Fees: Use constants to avoid magic numbers and ensure consistency across the contract. The prize payout for each player should be defined as a constant. The fees (e.g., gas fees) should also be calculated in advance to avoid underestimating the necessary funds.
Balance Check: Before allowing a player to start a game, check if the contract has sufficient funds to cover the prize payouts for all active players as well as the fees. If the balance is insufficient, revert the transaction with an appropriate error message.
Either this, or you implement a 1 player only system.
With a global variable being true
or false
becoming true upong startGame()
function being called, and false
upon endGame
being called.
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.