The selectPresident function uses a recursive scheme that is repeated by the number of candidates to choose the final candidate as the president. However, the voting mechanism allows users to vote for up to 10 persons, potentially increasing the number of candidates to 10 * NumberOfVoters in the worst case. This leads to significantly increased gas costs for the function call.
The selectPresident function has several issues that contribute to the vulnerability:
Recursive scheme:
The function calls itself recursively, potentially leading to deep recursion and high gas costs.
Dynamic candidate population:
Candidates are dynamically added to s_candidateList based on voter rankings, potentially exceeding the maximum allowed candidates.
Lack of candidate limit check:
There's no explicit check to ensure the number of candidates doesn't exceed a reasonable limit.
Potential for infinite recursion:
In extreme cases where all voters vote for the same candidate, the recursive calls could theoretically go on indefinitely.
The selectPresident function cannot be called efficiently or will cost a lot of gas, especially if the number of voters is increased. This could lead to denial of service (DoS) attacks or significantly higher transaction costs for users.
Manual Review
Implement a maximum candidate limit: Add a constant MAX_CANDIDATES and compare it against s_candidateList.length after populating it. If exceeded, revert the transaction.
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.