When user votes for and against till the quorum reached and proposal passes. Then fund should be divided into the voters who voted for. But a flawed logic in _distributeRewards()
function wrongly divided the fund by all voters and transferred only to them who voted for. Incorrect rewardPerVoter
will be sent to those who voted for. And other remaining reward part of those voters who voted against will be stuck in the contract.
There is no way the get the against voter fund if totalVotesFor are greater than totalVotesAgainst
In _distributeRewards
function when totalVotesAgainst
are smaller than totalVotesFor
the else block is going to execute which is calculating rewardPerVoter
for all voters which is incorrect we need to calculate reward for the voters who voted to totalVotesFor. So that all reward can be transferred.
/src/VotingBooth.sol#L192-L209
I added some lines and a new test in the given test file VotingBoothTest.t.sol.
To run the test use command
forge test --mt testVotePassesAndAgainstVotersPartRewardStuck -vv
Five voters need to vote in total 9 voters to reach the quorum and to pass proposal for votes will be 4 and against votes are only 1 so proposal will pass. But the part of against voters fund is stuck in current scenario 20% of total reward because 20% voter voted against. The reward was divided into 5 parts instead of 4 (who voted for) due to wrong logic and 1 part of that is stuck. We can see using assert the fund is there but we can't withdraw that. Because once the proposal passes contract becomes useless voting becomes inactive. After that even if we try to vote it will revert.
The user who voted to For
their funds are not correct and also the reward divided by all voters number so remaining funds of against voters will be stuck forever in contract.
Foundry
Use totalVotesFor
in place of totalVotes
in the else block to divide totalRewards
so voters who voted for there funds are accurately calculated.
change this below in _distributeRewards
function of VotingBooth.sol
. So award will only be divided into who voted for when proposal passes and no Eth will be stuck in contract.
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.