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

Unsafe downcast of uint256 to uint64 for fee accumulation

[M-02] Unsafe cast of PuppyRaffle::fee loses fees

Description:

When accumulating fees, due to the fact that totalFees is uint64, both arguments should be uint64. Thats why in the code there is a downcast from uint256 to unit64, which is the reason the contract loses fees.

Impact:

Makes it less incentivising for the contract owner/owner of fee address.

Tools used:
foundry, manual

Proof of Concept:

function testDowncastOfUint256toUint64() public pure {
// possible amount of fees generated at for example round 10 of winner selection
// because the entrance fee can be large amount, this amount is possible
uint256 generatedFromSelectedWinnerAtRoundN = 2**64 + 1;
assert(uint64(generatedFromSelectedWinnerAtRoundN) < generatedFromSelectedWinnerAtRoundN);
}

Recommended Mitigation:

  1. Make totalFees type uint256 so you dont need to downcast to uint64

Updates

Lead Judging Commences

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

unsafe cast of fee to uint64

Support

FAQs

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