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

Loss of funds on the contract

Summary

An error in the formula for calculating the reward leads to the loss of funds on the contract.
The formula for calculating awards uses the total number totalVotes instead of totalVotesFor

Vulnerability Details

The formula for calculating awards uses the total number totalVotes instead of totalVotesFor,
rewardPerVoter = totalRewards / totalVotes and rewardPerVoter = Math.mulDiv(totalRewards, 1, totalVotes, Math.Rounding.Ceil)
but only those who votedFor are awarded
_sendEth(s_votersFor[i], rewardPerVoter)

So contract will have a frozen balance = totalRewards - rewardPerVoter * s_votersFor.length

Impact

Contract's balance

Tools Used

Forge tests

Recommendations

change the formula for rewardPerVoter, i.e.
rewardPerVoter = totalRewards / totalVotesFor

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.