On blockchain a transaction has some gaslimit, exceeding which reverts the transaction and it is not executed. A for loop which runs for a certain number of iterations such that the count of iterations exceed the gas limit for that transaction leads to out of gas error and the transaction reverts.
The announceWinner
function is implemented in such a way that it iterates all over the _tokenIds
array to find the token id having the highest votes received and rewards the winner.
But the length of _tokenIds
being larger than the threshold limit corresponding to the gas limit will eventually lead to out of gas scenario and transaction will be reverted and winner can never be announced.
As well as voteForMartenitsa
function makes the token ids present in _tokenIds
array redundant because when x
amount of users votes for the same tokenId, then that token id is added in that array x
times.
The vulnerability is present in the announceWinner
function due to its implementation of deciding the winner by iterating all over the _tokenIds
array to get the winner with the largest votes.
But _tokenIds
array getting very large will result in out of gas and thus reverting the whole transaction, as a result of which the transaction can never be executed.
Even though the total amount of unique token ids receiving votes are within the limit, but due to the voteForMartenitsa
function adding every token id again and again in it will make it tremendously large, thus leads to a revert.
Winner can never be announced.
No health token will be rewarded to the winner.
Manual Review
Instead of iterating over the whole _tokenIds
array in announceWinner
function, it would be more beneficial to keep the track of current tokenid winning everytime when voteForMartenitsa
is called. In this way there will be no requirement to iterate over the whole array, and the O(N) operation is now minimized to just O(1) and DoS due to gas limit exceeding will thus be prevented.
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.