President Elector

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

Redundant Else Statement in RankedChoice Contract

Summary

A redundant else statement has been identified in the _selectPresidentRecursive function of the RankedChoice contract. This statement does not affect the functionality of the contract but introduces unnecessary code complexity and potential confusion.

Relevant Links

https://github.com/Cyfrin/2024-09-president-elector/blob/fccb8e2b6a32404b4664fa001faa334f258b4947/src/RankedChoice.sol#L114-L121

Vulnerability Details

In the _selectPresidentRecursive function, there is an else statement that only contains a continue instruction. This else block is redundant because:

  1. The continue statement is the last operation in the loop.

  2. The loop would proceed to the next iteration regardless of this statement.

  3. It does not alter the control flow or logic of the function.

Impact

While this redundancy does not introduce any functional bugs or security vulnerabilities, it has the following minor negative impacts:

  1. Slightly increased gas costs due to unnecessary bytecode.

  2. Potential confusion for developers maintaining or auditing the code.

Tools Used

Manual code review

Recommendations

Remove the redundant else block entirely.

for (uint256 j = 0; j < s_rankings[VOTERS[i]][s_voteNumber].length; j++) {
address candidate = s_rankings[VOTERS[i]][s_voteNumber][j];
if (_isInArray(candidateList, candidate)) {
s_candidateVotesByRound[candidate][s_voteNumber][roundNumber] += 1;
break;
}
}

This change will maintain the exact same functionality while improving code quality and slightly reducing gas costs.

Updates

Lead Judging Commences

inallhonesty Lead Judge 9 months ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity

Support

FAQs

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