The vote
function does not use a modifier to check that the voter is allowed and has not voted before. This could make the code less readable and reusable, as the require statement is repeated in the function body.
The vote
function is responsible for casting votes for the proposal. However, it does not use a modifier to check that the voter is allowed and has not voted before. Instead, it uses a require statement in the function body, which checks that the voter has the ALLOWED state in the s_voters mapping. 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.
A better practice is to use a modifier to check the access control conditions and apply it to the function. This way, the code is more readable and reusable, as the modifier can be applied to other functions that need the same access control. It could also reduce the gas cost of the function, as the modifier is executed only once before the function is called.
The impact of this issue is that the code quality and readability of the vote function is reduced. This could make the code harder to maintain and debug, 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.
Manual
The following test case demonstrates how the vote function works without a modifier:
Deploy the contract with an array of three allowed voters and 1 ether as the reward.
Call the vote function from one of the allowed voters with a valid input.
Observe that the vote is recorded and the state is updated.
Call the vote function from the same voter again with a different input.
Observe that the transaction reverts with the error message “DP: voter not allowed or already voted”.
Use a modifier to check that the voter is allowed and has not voted before and apply it to the vote function. This way, the code is more readable and reusable, as the modifier can be applied to other functions that need the same access control. It could also reduce the gas cost of the function, as the modifier is executed only once before the function is called.
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.