Dividing the total rewards by the total number of voters in _distributeRewards
might overflow for high reward amounts and many voters, leading to inaccurate calculations and potential manipulation by the creator.
When distributing rewards within _distributeRewards
, the function calculates the individual reward for each voter by dividing the total reward amount by the total number of voters. However, this division uses simple integer arithmetic, which can overflow for large values. If the total reward or number of voters is high, the calculations might overflow, resulting in inaccurate, potentially zero, individual rewards and allowing the creator to retain a significant portion of the funds.
Inaccurate or missing reward distribution for voters, potentially benefiting the creator and undermining trust in the system.
Manual Code Review
Deploy the VotingBooth
contract.
Set a high reward amount and simulate a voting process with a large number of voters.
Monitor the individual reward calculations within _distributeRewards
.
Check if the total distributed rewards match the expected amount and if any overflow errors occur.
Inaccurate individual reward calculations due to overflow might lead to some voters receiving significantly less or no reward.
Total distributed rewards might not match the expected amount due to potential overflow and loss of precision.
Use safe math libraries like OpenZeppelin's SafeMath
to perform calculations involving large values in _distributeRewards
. These libraries implement overflow protection mechanisms to ensure accurate calculations and prevent manipulation.
Consider alternative approaches for reward distribution that are less susceptible to overflow, such as dividing the rewards proportionally based
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.