Setting the entranceFee to an extremely low value can result in the winner and the protocol losing some or all of their funds due to number rounding errors.
If the entranceFee is set to a very low value, such as 1 wei, the prizePool and fee calculations in the selectWinner function are susceptible to rounding errors. This is because Solidity does not handle decimals well.
The provided test demonstrates the validity and severity of this vulnerability.
Requirements:
Install Foundry.
Clone the project codebase into your local workspace.
Step-by-step Guide to Run the Test:
Ensure the above requirements are met.
Copy the test below and add it to PuppyRaffleTest.t.sol tests.
Execute the following command in your terminal to run the test:
Note that the winner receives 3 wei instead of 3.2 wei due to Solidity's handling of decimals.
Permanent Loss of Funds for Both the Protocol and the Winner
Foundry
To address the precision loss issue, consider using a multiplying factor to deal with rounding errors. Here's an example of how to implement this:
Alternatively, you could set a lower bound for the allowed entranceFee to prevent precision loss.
like 1 wei
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.