Description:
The contract utilizes arrays (s_votersFor
and s_votersAgainst
) to store voters who have cast their votes. While arrays are a convenient data structure, manipulating their length dynamically can lead to potential gas inefficiencies and, in extreme cases, out-of-gas errors. As the length of these arrays grows, the gas cost associated with array resizing increases, impacting the overall performance of the contract.
Impact:
The potential impact of array length manipulation is primarily on gas costs and, in extreme scenarios, the risk of encountering out-of-gas errors. As the number of voters increases, the gas required to expand the array length can become substantial, affecting the efficiency of the contract.
Proof of Concept:
Consider a scenario where the number of voters reaches the upper limit, causing the arrays s_votersFor
and s_votersAgainst
to grow significantly. The gas cost associated with dynamic array resizing can be observed using a tool like Remix IDE or during actual deployment.
Recommended Mitigation:
Consider using a mapping or a different data structure to avoid dynamic array resizing. Mappings provide constant-time lookups and insertions, making them more gas-efficient than arrays for large datasets.
Severity:
The severity of this risk is considered low to medium. While dynamic array resizing can lead to increased gas costs, the impact is more pronounced in scenarios with a large number of voters. For contracts with a limited number of voters, the risk may be relatively low. Nonetheless, adopting more gas-efficient data structures is recommended to enhance the contract's scalability and reduce the likelihood of encountering gas-related issues.
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.