Beginner FriendlyFoundryNFT
100 EXP
View results
Submission Details
Severity: low
Invalid

Precision Loss: Organizer and player will get 0 ETH of the fund collected when the entrance fee is 1 wei

Summary

If the entrance fee is less than 2 wei and the number of participants is 1, the organizer and slected ram will collect 0 ETH due to precision loss.

Vulnerability Details

If the entrance fee is equal to 1 wei and there is only 1 participant, both the organizer and the participant will lose their fund and reward due to precision loss.

Impact

The participant will lose their 1 wei.

Code Example

This code should be added to the smart contract Dussehra.sol#CounterTest:

function test_precision_error() public {
vm.startPrank(organizer);
dussehra = new Dussehra(1 wei, address(choosingRam), address(ramNFT));
vm.stopPrank();
vm.startPrank(player1);
vm.deal(player1, 1 wei);
dussehra.enterPeopleWhoLikeRam{value: 1 wei}();
vm.stopPrank();
vm.warp(1728691200 + 1);
vm.startPrank(organizer);
choosingRam.selectRamIfNotSelected();
vm.stopPrank();
vm.startPrank(player1);
dussehra.killRavana();
vm.stopPrank();
// Check organizer balance
assertEq(organizer.balance, 0);
vm.startPrank(player1);
vm.expectRevert();
dussehra.withdraw();
vm.stopPrank();
// Check balance of player1
assertEq(player1.balance, 0);
// Check balance of the contract, fund is locked in the contract forever
assertEq(address(dussehra).balance, 1 wei);
}

Result
The user is selected as RAM

forge test --mt test_precision_error -v
[⠊] Compiling...
No files changed, compilation skipped
Ran 1 test for test/Dussehra.t.sol:CounterTest
[PASS] test_precision_error() (gas: 909846)
Suite result: ok. 1 passed; 0 failed; 0 skipped; finished in 2.46ms (516.38µs CPU time)

Tools Used

Manual review.

Recommendations

The entrance fee should be at least equal to 2 wei or there should be at least 2 participants in the event.

Updates

Lead Judging Commences

bube Lead Judge about 1 year ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity
Assigned finding tags:

Info/Gas/Invalid according to docs

Support

FAQs

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