Beginner FriendlyFoundry
100 EXP
View results
Submission Details
Severity: high
Valid

rewardPerVoter in _distributeRewards() is wrong

Summary

Calculation of rewardPerVoter in _distributeRewards() is wrong

Vulnerability Details

in this logic uint256 rewardPerVoter = totalRewards / totalVotes; we're considering the totalRewards with totalVotes, totalVotes were the total number of voters who participated in this VotingBooth, So, once rewards distributed there is still remaining eth exist in the contract.

Impact

The voters in s_votersFor will get only a small share due to considering the whole voters in this VotingBooth.

Tools Used

Remix IDE

Recommendations

Need to re-write the logic, by considering only the voters in s_votersFor. So the voters in s_votersFor will get a correct share of reward.

The else block in

+ uint256 rewardPerVoter = totalRewards / totalVotesFor;
- uint256 rewardPerVoter = totalRewards / totalVotes;

Green highlighted one is recommended

Updates

Lead Judging Commences

0xnevi Lead Judge over 1 year ago
Submission Judgement Published
Validated
Assigned finding tags:

VotingBooth._distributeRewards(): Incorrect computation of rewardPerVoter

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.