MartenitsaVoting::announceWinner
will announce only one winner in case of a tie because of the algorithm used to find the most voted token.
The announceWinner algorithm works that in a case of a tie between few users, only the first user who was voted for will be the winner.
Lets say Jack and Chasy both make beautifull martenitsa tokens and they tie with 10 votes each.
Ann voted for Jack, and she was the first to vote for either Jack or Chasy, because of that Jack's tokenId is before the Chasy's tokenId
in MartenitsaVoting::voteCounts
array.
Now is time to announce the winner, as we said Jack and Chasy have the most votes - 10 each.
After voteCounts[_tokendIds[i]]
equals Jack token, maxVotes
will be set to 10 and winnerTokenId
will be set to Jack's token.
Now votesCounts[_tokenIds[i]]
equals Chasy token, but we won't go inside the if to set winnerTokenId
because this check fails if (voteCounts[_tokenIds[i]] > maxVotes) {
- we will be comparing if(10 > 10) which is false and poor Chasy won't get any reward although she has the same amount of votes as Jack.
Although there might be a few winners, at the end only one of them will get the reward and be announced as winner(the fisrt who was voted for).
Paste the following test in MartenitsaVoting.sol
and run forge test --match-test testAnnounceWinnerTie
Manual Review
Unit Tests
As The voting takes place only once.
we can crate a mapping of the winnerTokenIds;
Then change the alghorithm slightly so we can allow for a few winners.
Then split the reward between the winners or find another way to decide a winner.
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.