The completeVoting
function does not use a modifier to check that the voting is not completed before. This could make the code less readable and reusable, as the require statement is repeated in the function body. The _distributeRewards
function does not check that s_votingComplete == true
before executing. This could allow anyone to call the function and trigger payouts or refunds, even if the voting is not completed.
The completeVoting
function is responsible for completing the voting process and distributing the rewards or refunds for the proposal. However, it does not use a modifier to check that the voting is not completed before. Instead, it uses a require statement in the function body, which checks that s_votingComplete == false
. This could make the code less readable and reusable, as the require statement is repeated in the function body. It could also increase the gas cost of the function, as the require statement is executed every time the function is called.
The _distributeRewards
function is responsible for distributing the rewards to the voters who voted for the proposal, or refunding the reward amount back to the proposal creator, depending on the proposal outcome. However, this function does not check that s_votingComplete == true
before executing. This means that anyone can call the function and trigger payouts or refunds, even if the voting is not completed. This could result in a loss of funds for the proposal creator and the voters, as the contract could transfer funds based on an incorrect proposal outcome.
The impact of this issue is that the contract could lose all the funds that it holds as a reward for the voters. Anyone could exploit this issue by calling the _distributeRewards
function and triggering payouts or refunds, even if the voting is not completed. This would also prevent the voting process from completing and the rewards from being distributed to the legitimate voters.
Manual
Foundry
The following test case demonstrates how anyone could exploit this issue:
Deploy the contract with an array of three allowed voters and 1 ether as the reward.
Call the _distributeRewards
function from any address that is not the proposal creator or one of the allowed voters, before the voting is completed.
Observe that the contract balance is transferred to the caller and the contract is emptied.
Use a modifier to check that the voting is not completed before and apply it to the completeVoting
function. This way, the code is more readable and reusable, as the modifier can be applied to other functions that need the same check. It could also reduce the gas cost of the function, as the modifier is executed only once before the function is called. You should also add a require statement in the _distributeRewards
function to check that s_votingComplete == true
, as this function can be called by anyone and should only be executed after the voting is completed.
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.