President Elector

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

Lack of Validation for Empty Rankings

Summary

The RankedChoice smart contract does not have a mechanism to validate or handle cases where a voter submits an empty ranking (an empty array of candidates). This lack of validation can lead to inconsistencies in the election process, allowing voters to bypass the ranking mechanism and potentially exploit the system. Implementing checks for empty ranks is necessary to ensure the integrity and fairness of the election.

Vulnerability Details

In the current implementation, voters can submit their rankings of candidates using the rankCandidates or rankCandidatesBySig functions. However, the contract does not include any validation to ensure that the submitted rankings contain at least one candidate. If a voter submits an empty array, the contract does not prevent or handle this situation, which introduces vulnerabilities into the voting process.

function rankCandidates(address[] memory orderedCandidates) external {
_rankCandidates(orderedCandidates, msg.sender);
}

Here, orderedCandidates can be an empty array, as no checks are performed to validate its contents.

Impact

Submitting empty ranks would lead to votes being registered without any actual candidate selection. This can skew election outcomes, as the system would count the voter's participation but without any meaningful vote contribution. Also allowing empty ranks may result in inconsistencies when tallying votes. The lack of ranked candidates could affect the overall distribution of votes, particularly in smaller elections where a few voters can have a significant impact on the results.
Malicious voters could submit empty ranks as a strategy to disrupt the election process or reduce the number of valid votes, creating an advantage for other candidates.

Tools Used

Manual Review

Recommendations

Introduce validation to ensure that the orderedCandidates array contains at least one candidate. If an empty array is submitted, the contract should revert the transaction with an error, such as RankedChoice__InvalidInput.

function _rankCandidates(
address[] memory orderedCandidates,
address voter
) internal { /
// Checks
if (orderedCandidates.length > MAX_CANDIDATES) {
revert RankedChoice__InvalidInput();
}
+ if (orderedCandidates.length = 0) {
+ revert RankedChoice__InvalidInput();
}
if (!_isInArray(VOTERS, voter)) {
revert RankedChoice__InvalidVoter();
}
// Internal Effects
s_rankings[voter][s_voteNumber] = orderedCandidates;
}
Updates

Lead Judging Commences

inallhonesty Lead Judge about 1 year ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity

Support

FAQs

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