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

Users can register as player more than once

Description

To find if a User has already registered, the following condition is looked at : playersStatus[msg.sender] == Status.Pending

It means that if the User is already Approved, they can register again.

Impact

1/ Loss of funds for the User.

2/ Less 'real' Players can be added because User takes a slot in players[].

PoC

Add this Getter in ThePredicter.sol :

function getPlayersLength() public view returns (uint256 count) {
return players.length;
}

Add this test at the end of the test file and run it :

forge test --mt test_cannotRegisterIfAlreadyApproved

function test_cannotRegisterIfAlreadyApproved() public {
vm.prank(stranger);
vm.warp(1);
vm.deal(stranger, 1 ether);
thePredicter.register{value: 0.04 ether}();
vm.warp(2);
vm.prank(organizer);
thePredicter.approvePlayer(stranger);
vm.prank(stranger);
// Should revert, but will not because organizer approved before
// vm.expectRevert(abi.encodeWithSelector(ThePredicter__CannotParticipateTwice.selector));
thePredicter.register{value: 0.04 ether}();
// Organizer approves a second time the same player
vm.prank(organizer);
thePredicter.approvePlayer(stranger);
// The same player takes two slots in the players array
assertEq(2, thePredicter.getPlayersLength());
assertEq(stranger.balance, 0.92 ether);
}

Recommendations

Update the condition in ThePredicter.register() to also revert if a player is already approved :

if (playersStatus[msg.sender] == Status.Pending || playersStatus[msg.sender] == Status.Approved) {
revert ThePredicter__CannotParticipateTwice();
}
Updates

Lead Judging Commences

NightHawK Lead Judge 10 months ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity

Support

FAQs

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