TwentyOne

First Flight #29
Beginner FriendlyGameFiFoundrySolidity
100 EXP
View results
Submission Details
Severity: low
Invalid

Potential Loss of Funds in startGame Function Due to Inadequate Ether Handling

Summary

The TwentyOne contract contains a vulnerability in the startGame function that allows users to inadvertently lose any Ether they send above 1 Ether. This vulnerability can result in the loss of funds for users.

Vulnerability Details

The startGame function allows users to start a game by sending Ether. However, the current logic only checks that the sent value (msg.value) is at least 1 Ether, without accounting for larger amounts. As a result, any Ether sent above 1 Ether is neither accounted for nor refunded, leading to a potential loss for the user.

Impact

The impact of this vulnerability is significant, as users sending more than 1 Ether will lose any extra amount sent. This can result in loss of funds and a poor user experience, as well as potential damage to the reputation of the contract and its developers.

Tools Used

To identify this vulnerability, the following tools and techniques were used:

  • Manual Code Review: Analyzing the contract line by line to identify logic and potential errors.

  • Foundry

Recommendations

To fix this vulnerability, it is recommended to update the startGame function to only accept exactly 1 Ether and return any excess sent. This can be achieved by updating the verification logic and adjusting the value of msg.value.

function startGame() public payable returns (uint256) {
address player = msg.sender;
require(msg.value == 1 ether, "Must send exactly 1 ether");
initializeDeck(player);
uint256 card1 = drawCard(player);
uint256 card2 = drawCard(player);
addCardForPlayer(player, card1);
addCardForPlayer(player, card2);
return playersHand(player);
}
Updates

Lead Judging Commences

inallhonesty Lead Judge 11 months ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity
Assigned finding tags:

[INVALID] User mistake, too much ETH sent

Support

FAQs

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