President Elector

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

Arbitrary Tie-Breaking Leading to Premature Candidate Elimination

Summary

The RankedChoice smart contract lacks a structured tie-breaking mechanism, resulting in ties being handled arbitrarily. This could cause a candidate to be prematurely eliminated during the voting rounds, potentially leading to unfair or inaccurate election outcomes.

Vulnerability Details

The contract's _selectPresidentRecursive function handles the elimination of candidates with the fewest votes in each round of the election. However, if two or more candidates have the same number of votes (i.e., a tie), the contract does not have a defined process to break the tie. Instead, it relies on the order of iteration, which could arbitrarily eliminate one of the tied candidates.

...snip...
// Remove the lowest candidate or break
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];
}
}
address[] memory newCandidateList = new address[](
candidateList.length - 1
);
bool passedCandidate = false;
for (uint256 i; i < candidateList.length; i++) {
if (passedCandidate) {
newCandidateList[i - 1] = candidateList[i];
} else if (candidateList[i] == fewestVotesCandidate) {
passedCandidate = true;
} else {
newCandidateList[i] = candidateList[i];
}
}
return _selectPresidentRecursive(newCandidateList, roundNumber + 1);

In this code, if two candidates have an equal number of votes, the one that appears later in the loop is arbitrarily chosen for elimination. This can result in an unfair removal of a candidate.

Impact

This arbitrary elimination of candidates could result in a situation where a candidate who should have advanced based on voter preference is removed from the race prematurely, affecting the fairness of the election process. The randomness of this tie-breaking mechanism undermines the legitimacy of the results, especially in close elections.

Tools Used

Manual Review

Recommendations

Introduce a structured tie-breaking process that could involve comparing the rankings from subsequent rounds to determine which tied candidate should advance.

Updates

Lead Judging Commences

inallhonesty Lead Judge about 1 year ago
Submission Judgement Published
Invalidated
Reason: Known issue

Support

FAQs

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