totalFees
is declared as an uint64
to take advantage of storage packing, the maximum value for this type is 18_446_744_073_709_551_615
which is aproximately 18.45 ether, considering 20% of the entrance fee per player is collected and added to totalFees
, this amount can be reached easily and make the value overflow.
The compiler version used by the developer in the raffle is 0.7.6
, versions of the compiler below 0.8.0
does not protect against overflow, meaning that once totalFees
surpasses the max value for its type it will reset to zero, resulting in a complete lost of the fees.
Assume 92 players have already played the raffle and the totalFees
is 18 ether. A new round starts with five players and a new winner is selected, after this round totalFees
overflows and the value is aprox. 0.95 ether. Over 17 ether has been lost.
Paste and execute the following code snippet in PuppyRaffleTest.t.sol
to see the effect of the bug.
Lost of funds.
VS Code and Foundry.
Apply SafeMath
library from OpenZeppelin to protect math operations from underflow/overflow.
Increment totalFees
type to uint256
.
Reduce raffleDuration
and raffleStartTime
types to uint128
and declared as the top of the contract so they are packed together in the slot zero.
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.