The RankedChoice
contract suffers from a vulnerability in the selectPresident
function that uses a recursive approach to determine the winner of the election. The recursive implementation can lead to stack overflow or out-of-gas issues when dealing with a large number of voters or candidates. This could result in the function failing unexpectedly during execution, preventing the election process from completing successfully.
The selectPresident
function relies on the _selectPresidentRecursive
helper function to recursively narrow down candidates until a winner is selected. However, with a large number of voters and rounds, this recursive approach can lead to:
Stack Overflow: Recursion depth can exceed the allowed stack size in Solidity, leading to a stack overflow
error.
Out-of-Gas Errors: Since each recursive call consumes gas, the function may run out of gas before it can complete, especially in scenarios with many voters or rounds.
The test testSelectPresidentRecursiveFuzz
confirmed this behavior, with the function failing due to an array out-of-bounds access, which was likely triggered by exceeding recursion depth limits.
Test:
The contract may fail to select a winner when there are a large number of voters or candidates, causing the election process to halt and preventing any candidate from being selected as the president.
Manual Review
Foundry Test
Use different approach to achieve the goals
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.