TwentyOne

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

A risk of insufficient funds to cover promised rewards.

Summary

The TwentyOne contract lacks mechanisms to ensure that it maintains sufficient funds to cover all potential reward payouts to the first users of the contract .

Vulnerability Details

The current implementation of the smart contract presents several critical problems that undermine its functionality and economic model:

  1. Absence of a constructor: The contract lacks a constructor function with the payable modifier, which is essential for receiving initial funding during deployment. This omission means the contract will be deployed without any initial capital. Due to the lack of a custom constructor, the contract assumes the default constructor is (constructor() {}), which is not capable of accepting payments.

  2. Missing receive function: The absence of a receive() function prevents direct funding of the contract through Ether transfers.

Impact

  1. Funding dependency: The contract's ability to distribute rewards is entirely dependent on players losing funds, rather than having a dedicated funding mechanism.

  2. Initial player disadvantage: The first players will face significant challenges in participating, as the contract lacks sufficient funds to cover potential rewards.

  3. Economic instability: The lack of a stable funding source jeopardizes the entire reward structure, potentially leaving players without compensation.

    ```diff
    [1445081] TwentyOneTest::test_Call_PlayerWins()
    ├─ [0] VM::startPrank(0x0000000000000000000000000000000000000123)
    │ └─ ← [Return]
    ├─ [1270369] TwentyOne::startGame{value: 1000000000000000000}()
    │ └─ ← [Return] 14
    ├─ [0] VM::mockCall(TwentyOne: [0x5615dEB798BB3E4dFa0139dFa1b3D433Cc23b72f], 0x6bdc6ad80000000000000000000000000000000000000000000000000000000000000123, 0x0000000000000000000000000000000000000000000000000000000000000012)
    │ └─ ← [Return]
    ├─ [155590] TwentyOne::call()
    + │ ├─ emit PlayerWonTheGame(message: "Dealer went bust, players winning hand: ", cardsTotal: 14)
    │ ├─ [0] 0x0000000000000000000000000000000000000123::fallback{value: 2000000000000000000}()
    - │ │ └─ ← [OutOfFunds] EvmError: OutOfFunds
    │ └─ ← [Revert] EvmError: Revert
    └─ ← [Revert] EvmError: Revert
    ```

Tools Used

Manual code review.

Recommendations

To address these issues, the following changes should be considered:

Implement a custom constructor with the payable modifier to receive initial funding. Add a receive() function to enable direct Ether transfers to the contract.

Updates

Lead Judging Commences

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

Contract Lacks Mechanism to Initialize or Deposit Ether

Support

FAQs

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