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();
assertEq(organizer.balance, 0);
vm.startPrank(player1);
vm.expectRevert();
dussehra.withdraw();
vm.stopPrank();
assertEq(player1.balance, 0);
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.