President Elector

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

Wrong Handling of Candidates with Equal Votes in _selectPresidentRecursive

Summary

The _selectPresidentRecursive function in the RankedChoiceVoting contract is responsible for recursively selecting the president based on ranked choices from voters. However, the current implementation does not handle cases where multiple candidates have the same number of votes. In such scenarios, the function removes the first candidate in the array with the fewest votes, potentially leading to unfair outcomes if there are ties.

Vulnerability Details

Issue: The _selectPresidentRecursive function does not include any logic for handling ties when multiple candidates have the same number of votes. When candidates have an equal number of votes, the function removes the first candidate found with the fewest votes, which could be arbitrary and unfair if there is no further tie-breaking logic.

// Remove the lowest candidate or break
//@audit no condition to cater for candidates with same number of votes in _selectPresidentRecursive, first one in the array is removed
address fewestVotesCandidate = candidateList[0];
uint256 fewestVotes = s_candidateVotesByRound[fewestVotesCandidate][
s_voteNumber
][roundNumber];
for (uint256 i = 1; i < candidateList.length; i++) {
uint256 votes = s_candidateVotesByRound[candidateList[i]][
s_voteNumber
][roundNumber];
if (votes < fewestVotes) {
fewestVotes = votes;
fewestVotesCandidate = candidateList[i];
}
}

Impact

  • Unfair Outcomes: Candidates with equal votes are not given a fair chance, as the function does not determine how to break ties beyond removing the first candidate found. This can lead to suboptimal or undesired outcomes in the election.

  • Potential for Bias: The arbitrary removal of the first candidate with the fewest votes could introduce bias, as it does not consider any additional criteria for tie-breaking.

Tools Used

Manual Review

Recommendations

Introduce a tie-breaking mechanism to handle cases where multiple candidates have the same number of votes. This could involve additional criteria or a secondary method for selecting the candidate to remove.

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.