TwentyOne

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

[M-1] Missing Balance Check for Player Payouts

Summary

The contract lacks a balance check before attempting to transfer funds to a player. Specifically, there is no validation to ensure the contract has sufficient funds available before the payout is initiated. This can result in the contract attempting to pay the player when it doesn't have enough funds, leading to transaction failures.

Vulnerability Details

The current setup relies on the assumption that the contract will always have enough funds when the endGame function is triggered. However, without an explicit check of the contract's balance, the contract may encounter errors when attempting to make the payment, potentially affecting the user experience and financial integrity of the contract.

Impact

The lack of a balance check can lead to the following potential impacts:

  • Failed Transactions: Players may not receive their winnings, and the transaction will fail without any clear explanation.

  • Poor User Experience: Users may experience frustration or confusion when their payout fails due to insufficient contract balance.

  • Financial Integrity Risk: The contract may appear unreliable or untrustworthy, damaging its reputation.

  • Loss of Trust: Players may lose confidence in the system if payouts fail without proper validation, affecting future engagement with the contract.

Tools Used

  • Manual review

Recommendations

  • Implement a balance check: Before making any payout, add a require statement to check the contract's balance to ensure there are sufficient funds for the transaction. For example:

require(address(this).balance >= 2 ether, "Not enough funds to pay player");
  • Admin fund management: Provide a mechanism for the contract administrator to replenish funds if needed. Consider setting up an admin role with the ability to add funds to the contract.

Updates

Lead Judging Commences

inallhonesty Lead Judge 11 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.