The contract exhibits a flaw in the reward distribution mechanism for successful proposals that receive votes against. The _distributeRewards
function divides totalRewards
by the sum of s_votersFor.length
and s_votersAgainst.length
, leading to incorrect reward allocations for voters who supported the proposal. This vulnerability manifests when there are votes against a successful proposal, resulting in funds being left stuck in the contract.
The vulnerability arises due to the inclusion of number of votes against a successful proposal in the rewardPerVoter
calculation. This miscalculation impacts the reward distribution, making it dependent on the total number of votes, rather than the number of voters who supported the proposal.
The impact of this vulnerability is high, as it compromises the fairness of the reward distribution specifically in successful proposals with votes against. Additionally, funds are left remaining in the contract, creating a risk of loss. Unanimously successful proposals with no votes against exhibit the correct reward calculation.
Foundry
As a PoC, include the following test in the VotingBoothTest.t.sol
file:
Modify the following lines of the _distributeRewards
function:
This modification ensures that rewards are distributed only to voters who supported the successful proposal in scenarios where there are votes against.
After modifying, you can run the following test and see that all funds are distributed to users who vote in favor of a successful proposal, regardless of the voter mix:
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.