The project documentation specifies that the user should deposit 1 ether, as the maximum possible profit is 2 ether. However, the startGame
function allows deposits greater than 1 ether, which could result in a loss of user funds since the maximum payout is still capped at 2 ether.
The issue is in the line require(msg.value >= 1 ether, "not enough ether sent");
, which enforces a minimum deposit of 1 ether but does not impose a maximum limit. As a result, the user can deposit more than 1 ether. However, regardless of the deposit amount, the user can only receive a maximum of 2 ether, leading to a potential loss of funds for deposits exceeding this limit.
If a user deposits more than 1 ether, believing they will always win double their deposit as in blackjack, they will lose the extra funds sent. These funds cannot be recovered, as there is no way to withdraw the deposit. The user will only receive 2 ether upon winning.
Example:
A user reads in the documentation that they will win double their deposit, so they deposit 5 ether. After winning, they only receive 2 ether instead of 10 ether. Instead of gaining 5 ether, they have lost 3 ether.
Add this code to the test file and run it to observe the vulnerability. You will see that you can deposit more than 1 ether.
Manual Review.
Changing require(msg.value >= 1 ether, "not enough ether sent");
to require(msg.value == 1 ether, "not enough ether sent");
will mitigate the issue by ensuring that only exactly 1 ether can be sent. This prevents users from accidentally sending more funds that could be lost, as the deposit limit will be strictly enforced.
Corrected Code Based on the Recommendation:
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.