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

Wrong reward is sent to the`for` voters if the proposal has passed with any against vote

Summary

If a proposal has passed and also have 'against' votes, the reward amount is calculated wrongly and some amount is left on the contract.

Vulnerability Details

VotingBooth::_distributeRewards line 192

uint256 rewardPerVoter = totalRewards / totalVotes;

Impact

The reward amount is divided by all voters length but sent to for voters therefore for voters receive less and some amount is left on the contract.

Tools Used

update test VotingBoothTest.t:testVotePassesAndMoneyIsSent

function testVotePassesAndMoneyIsSent() public {
vm.prank(address(0x1));
- booth.vote(true);
+ booth.vote(false);
vm.prank(address(0x2));
booth.vote(true);
vm.prank(address(0x3));
booth.vote(true);
assert(!booth.isActive() && address(booth).balance == 0);
}

Recommendations

Reward calculation should be fixed

- uint256 rewardPerVoter = totalRewards / totalVotes;
+ uint256 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.