Description The _tokenIds array is saving a new copy of the token id numbers with each new vote.
The length of that array is later used in ManteritsaVoting:announceWinner
in a loop doing repeated checks of the same token id number
Impact This will overflow the gas cost to call ManteritsaVoting:announceWinner
making it uncallable.
Proof Of Concept
We will check the gas cost 150 votes, 1500 votes and 15000 votes to see the gas cost difference.
console log
Recommended Mitigation: To prevent duplicate entries of tokenId
in the _tokenIds
array, you can modify the voteForMartenitsa
function to include a check for whether the tokenId
already exists in the _tokenIds
array. This can be achieved by iterating through the _tokenIds
array and comparing each element to the tokenId
in question. If a match is found, it would mean the tokenId
is already in the array, and thus, you shouldn't push it again. However, please note that this approach might not be gas-efficient for large arrays due to the iteration process. Consider using a mapping for a more efficient solution if you have performance concerns.
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.