TwentyOne

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

Lack of Contract Balance Check Before Starting Game in Solidity

Summary

The startGame() function of the TwentyOne contract fails to correctly manage and check contract balances, leading to issues with payouts. Specifically, the contract asserts that the player's balance should be greater than 2 ether after they win the game, but the contract balance is not checked or updated to reflect the payout properly. This can lead to a situation where, even if a player wins, they do not receive their intended funds.

Vulnerability Details

The assertion in the test case assertGt(player2.balance, 2 ether); fails because the contract doesn't properly manage the balance after the game.

  • The startGame() function may accept funds, but it doesn't ensure that the contract holds enough funds to cover payouts. In this scenario, even when a player wins the game, the contract balance is not checked, and the payout is not correctly made to the player.

  • The error occurs due to an imbalance between the contract's internal state and the external player's balance, causing the assertion to fail.

Impact

Player Payout Failure: If a player wins the game, they may not receive their winnings if the contract balance is not properly handled or updated, leading to a failed transaction.

  • Broken Game Logic: The failure to properly track and manage the contract balance impacts the core functionality of the game, which relies on payouts for correct operation.

  • Player Experience: Players may be confused or frustrated when they win but do not receive the expected payout, leading to a poor user experience.

  • Contract Malfunctions: This vulnerability undermines the contract's trustworthiness, as the payout mechanism is not fully reliable.

Tools Used

Manual Review

Recommendations

Implement a require on the startGame()` to check that the contract balance is superior to the payout prize.

require(address(this).balance >= 2 ether, "The contract balance isn't enough for the payout");
Updates

Lead Judging Commences

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

Insufficient balance for payouts / Lack of Contract Balance Check Before Starting Game

Support

FAQs

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