Beginner FriendlyFoundry
100 EXP
View results
Submission Details
Severity: low
Invalid

Last voter will pay higher gas.

Vulnerability Details

After quorum is reached, distributeRewards and sendEth function are executed. It means, last voter whose vote is needed to reach quorum will pay much higher gas than other voters.

Impact

Last voter will pay double gas than rest of voters.
PoC

function test_LastVoterWillPayHigherGas() public {
vm.prank(address(0x1));
booth.vote(false);
uint256 gasStartSecondVoter = gasleft();
vm.prank(address(0x2));
booth.vote(true);
uint256 gasEndSecondVoter = gasleft();
uint256 gasStartLastVoter = gasleft();
vm.prank(address(0x3));
booth.vote(true);
uint256 gasEndLastVoter = gasleft();
uint256 gasUsedSecondVoter = gasStartSecondVoter - gasEndSecondVoter;
uint256 gasUsedLastVoter = gasStartLastVoter - gasEndLastVoter;
assert(gasUsedLastVoter > gasUsedSecondVoter);
console.log("Gas used by second voter: ", gasUsedSecondVoter);
console.log("Gas used by last voter: ", gasUsedLastVoter);
}

Test result:

Gas used by second voter: 51467
Gas used by last voter: 115258

Tools Used

Foundry

Recommendations

_distributeRewards might be external function with 'if' statement inside allow to call only if quorum is reached. To keep current logic of the contract, do not forget add 'if' statement in vote function as well to prevent enter the function after the quorum is reached.

Updates

Lead Judging Commences

0xnevi Lead Judge
over 1 year ago
0xnevi Lead Judge over 1 year ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity

Support

FAQs

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