The constructor of the contract does not initialize the s_creator
variable, which is supposed to store the address of the proposal creator. This leaves the s_creator
variable with the default value of zero address. This could allow anyone to call the refund function and drain the contract balance, as the refund function does not check that msg.sender == s_creator
.
The constructor of the contract is responsible for setting the initial state of the contract, such as the allowed voters, the reward amount, and the proposal creator. However, the constructor does not initialize the s_creator variable, which is supposed to store the address of the proposal creator. This leaves the s_creator variable with the default value of zero address, which is a special address that can receive funds but cannot send them.
This could allow anyone to call the refund function and drain the contract balance, as the refund function does not check that msg.sender == s_creator
. The refund function is supposed to refund the reward amount back to the proposal creator if the proposal is defeated or the voting is not completed within the deadline. However, since the s_creator
variable is zero address, anyone can call the refund function and claim the reward amount as their own. This could result in a loss of funds for the proposal creator and the voters.
The impact of this vulnerability is that the contract could lose all the funds that it holds as a reward for the voters. Anyone could exploit this vulnerability by calling the refund function and transferring the contract balance to their own address. This would also prevent the voting process from completing and the rewards from being distributed to the legitimate voters.
Manual
The following test case demonstrates how anyone could exploit this vulnerability:
Deploy the contract with an array of three allowed voters and 1 ether as the reward.
Call the refund function from any address that is not the proposal creator or one of the allowed voters.
Observe that the contract balance is transferred to the caller and the contract is emptied.
To fix this issue, I recommend that you assign msg.sender
to s_creator
in the constructor and add a require statement in the refund function to check that msg.sender == s_creator
. This way, you can ensure that only the proposal creator can call the refund function and claim the reward amount.
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.