The _rankCandidates function does not prevent the voter for voting the same candidate multiple times
https://github.com/Cyfrin/2024-09-president-elector/blob/main/src/RankedChoice.sol#L159
Voters can submit rankings with the same candidate listed multiple times. This could result in a single candidate being "ranked" higher than they should be and potentially skew the results of the ranked-choice voting process.
Duplicate rankings could lead to erroneous vote tallies, where a candidate receives more "points" or votes than they should. The POC was made to demonstrate the vulnerability and it will be placed as function in RankedChoiceTest.t.sol. The testDuplicateCandidateRanking function simulates the scenario where a voter (voters[0]) ranks the same candidate twice. The test checks if the duplicate ranking was stored in the contract. If the vulnerability exists, the same candidate will appear twice in the ranking array. If the vulnerability is present, the second assertion (assertEq(rankedCandidates[1], candidates[0]);) will pass, indicating that duplicate candidates were accepted.
For demo please run command forge test --match-test testDuplicateCandidateRankingand the test will fail.
Manual Review
Please add duplication check for preventing candidates getting ranked multiple times. It will check if a voter has ranked the same candidate more than once within their list.
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.