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

totalFunds should not be stored in uint64, no overflow handling

Summary

the totalFunds variable does not handle overflow. Any solidity versions < 0.8 do not throw any errors for overflows/underflows so funds would be lost.

Vulnerability Details

Overflow will happen when the value is too large to be stored in the uint64 data type, usually in solidity versions < 0.8 it will be caused to wrap around (which is the case here).

Impact

Can lead to a loss of funds and potentially unexpected behaviour within your smart contract.

Tools Used

Manual Review

Recommendations

Change the variable to a uint256 data type and also use OpenZeppelins safeMath library to prevent overflow/underflow because of the version of solidity you are using (for the version of solidity your using it is actually referred to as SafeCast).

+ import {SafeCast} from "@openzeppelin/contracts/utils/SafeCast.sol";
+ using SafeCast for uint256;
- uint64 public totalFees = 0;
+ uint256 public totalFees = 0;
- totalFees = totalFees + uint64(fee);
+ totalFees = totalFees + fee;
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!