The selectPresident
function aggregates all candidates from voters' submissions, potentially leading to an extremely large s_candidateList
. If voters submit ballots with numerous unique candidates, it could cause the function to exceed the block gas limit, resulting in a Denial of Service (DoS) where the election cannot be completed.
Affected Function: selectPresident
Issue Explanation:
Unbounded Loop: The function iterates over VOTERS
and their orderedCandidates
, adding new candidates to s_candidateList
without limits.
Gas Limit Exceeded: With enough unique candidates, the gas required to execute the function could surpass the block gas limit.
DoS Scenario: If the function cannot complete due to gas constraints, the election process halts.
Severity: High
Election Halt: The president cannot be selected, effectively stopping the election process.
System Vulnerability: Malicious actors can intentionally cause this condition to disrupt governance.
Resource Exhaustion: Excessive gas consumption leads to increased costs for users and potential network strain.
Manual Code Review: Identified loops with potential for unbounded iteration.
Limit Candidate Entries:
Max Candidates Per Voter: Enforce a maximum number of candidates each voter can submit.
Track Unique Candidates Efficiently:
Use Mappings: Replace array searches with mappings to efficiently check for existing candidates.
Avoid Nested Loops: Refactor the code to eliminate or minimize nested looping structures.
Process Candidates Off-Chain:
Perform candidate aggregation off-chain and submit a compressed list to the contract.
Implement Batching:
If the list is too large, process candidates in batches over multiple transactions.
Set Gas Limits:
Include checks to ensure the function does not proceed if gas consumption is approaching limits.
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.