The PuppyRaffle::enterRaffle function enforces payment via a strict equality check:
Using a strict equality check on msg.value can cause the transaction to revert if the user sends slightly more or less than the exact calculated value. Minor rounding differences or front-end miscalculations can trigger unnecessary failures.
Severity: Medium
Type: Usability / Payment correctness
Impact: Legitimate transactions may fail, leading to poor user experience or accidental DoS for participants.
Likelihood:
Probability of Occurrence: Medium
Users or front-end applications may slightly miscalculate the total payment. On high-volume deployments, this can happen frequently.
Impact:
Effect: Legitimate transactions may fail due to small overpayments or underpayments. This can frustrate users, reduce participation, and affect the perceived availability of the raffle.
Add this function to PuppyRaffleTest.t.sol::PuppyRaffleTest and run forge test --mt testStrictEqualityIsBad:
Setup players: Creates an array of 5 dummy addresses to simulate a small raffle entry.
Fund the sender: Assigns the test player 6 ETH to cover the intended payment and any overpayment.
Trigger strict equality check: Calls PuppyRaffle::enterRaffle with msg.value = 5 ETH + 1 wei, slightly above the expected total (5 * entranceFee).
Expect revert: Uses vm.expectRevert with the exact revert message to assert that the transaction fails due to the strict == comparison.
Demonstrates usability issue: Confirms that even a minor overpayment causes a revert, highlighting why strict equality on msg.value is problematic.
Use a greater-than-or-equal check to allow slightly higher payments:
Optionally, refund excess ETH to the sender:
The contest is live. Earn rewards by submitting a finding.
Submissions are being reviewed by our AI judge. Results will be available in a few minutes.
View all submissionsThe contest is complete and the rewards are being distributed.