President Elector

First Flight #24
Beginner FriendlyFoundry
100 EXP
View results
Submission Details
Severity: high
Invalid

When all candidates have the same rank, there is no clear rule for selecting the president.

Summary

When all candidates have the same rank,the first address of the list is selected to the president. This is unfair.

Vulnerability Details

add the code to the RankedChoiceTest.t.sol file, two voters(voters[0] and voters[1]) vote the same three candidates(candidates[0],candidates[1],candidates[2]), so the candidates[0],candidates[1],candidates[2] has the same rank, but the first one of the candidates(candidates[0])is choosed to the president, which is unfair.
POC

function testSameRankChoosePresident() public {
uint256 currentTimestamp = 1695671400;
vm.warp(currentTimestamp);
orderedCandidates = [candidates[0], candidates[1], candidates[2]];
vm.startPrank(voters[0]);
rankedChoice.rankCandidates(orderedCandidates);
vm.stopPrank();
vm.startPrank(voters[1]);
rankedChoice.rankCandidates(orderedCandidates);
vm.stopPrank();
rankedChoice.selectPresident();
assertEq(rankedChoice.getCurrentPresident(), candidates[0]);
}

Impact

When all candidates have the same rank,the first address of the list is selected to the president. This is unfair.

Tools Used

foundry, vscode

Recommendations

add the logic for selecting the president when the highest rank candidate greater than one person.

Updates

Lead Judging Commences

inallhonesty Lead Judge 12 months ago
Submission Judgement Published
Invalidated
Reason: Known issue

Support

FAQs

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