Summary: The contract lacks an explicit mechanism to ensure it starts with sufficient funds to cover potential payouts, particularly for the first game. If a player wins the initial game, the contract will revert due to an insufficient balance, potentially leading to disputes or loss of trust.
Vulnerability Details: The contract requires an entry fee of 1 ETH to start a game and promises a prize of 2 ETH for a win. However, the contract does not enforce or include a method to initialize its balance. This results in a scenario where the contract may be unable to pay the promised prize, especially during the first game or when its balance is insufficient due to prior losses.
Impact: If you are the first person to use the contract and you win, you transation will revert, that means the 1st player will lose 100% of the time.
Tools Used: Foundry, Remix
Recommendations:
Add a Constructor for Initial Funding
constructor() payable {
require(msg.value >= 10 ether, "Insufficient funding for the game.");
}
Check Contract Balance Before Starting a Game
require(address(this).balance >= 2 ether, "Contract cannot cover the prize.");