The MartenitsaVoting::announceWinner
function is used to calculate the winner of a voting event. The winner is the NFT with the most votes. However, if 2 or more NFTs have the same amount of votes, the first one in the MartenitsaVoting::tokenIds
array will always be the winner. This is because the MartenitsaVoting::announceWinner
function uses the maxVotes
variable to store the maximum number of votes, and the winner
variable to store the winner NFT ID. If the current NFT has more votes than the maxVotes
variable, the winner
variable is updated with the current NFT ID. However, if the current NFT has the same amount of votes as the maxVotes
variable, the winner
variable is not updated, and the first NFT in the MartenitsaVoting::tokenIds
array is always the winner.
The winner of the voting event is always the first NFT in the MartenitsaVoting::tokenIds
array if 2 or more NFTs have the same amount of votes, which leads to unfair results in voting events.
Manual Review
Add this test to MartenitsaVoting.t.sol
:
The logs from this test show how Jack votes for Chasy's martenitsa, and Bob votes for Jack's martenitsa. The winner of the voting event is Chasy's martenitsa, even though Jack's martenitsa has the same amount of votes.
Consider implementing a different logic for MartenitsaVoting::announceWinner
function. For instance tokenIds, which have the same amount of votes can be stored in a newly created array. Then the winning NFT can be selected from the newly create array, by implementing Chainlink VRF for determining the winner randomly.
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.