Beginner FriendlyFoundryNFT
100 EXP
View results
Submission Details
Severity: high
Valid

Potential Overflow in Fee Calculation

Vulnerability Details

In the selectWinner function there is a potential for an overflow in the fee calculation. The contract is written in Solidity version 0.7.6, which does not automatically check for overflows. This vulnerability arises when calculating the totalAmountCollected:

function selectWinner() external {
// ...
uint256 totalAmountCollected = players.length * entranceFee;
uint256 prizePool = (totalAmountCollected * 80) / 100;
uint256 fee = (totalAmountCollected * 20) / 100;
totalFees += uint64(fee);
// ...
}

Impact

  • Overflow Scenario: If the players.length * entranceFee is large enough, the totalAmountCollected could result in a value that exceeds the maximum for a uint256, causing an overflow.

Recommendations

  • Use SafeMath Library: Implement the use of the OpenZeppelin's SafeMath library for arithmetic operations, which includes overflow checks.

  • Solidity Version Upgrade: Consider upgrading the contract to a newer version of Solidity (0.8.x or later) where overflow checks are done by default.

Updates

Lead Judging Commences

Hamiltonite Lead Judge about 2 years ago
Submission Judgement Published
Validated
Assigned finding tags:

overflow-uint64

Support

FAQs

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

Give us feedback!