BriVault

First Flight #52
Beginner FriendlySolidity
100 EXP
View results
Submission Details
Severity: medium
Valid

The `_getWinnerShares` function uses an unbounded for loop which can cause denial of service.

The _getWinnerShares function uses an unbounded for loop which can cause denial of service.

Description

  • The _getWinnerShares function uses an unbounded loop, this can hit a gas limit for a transaction when the length of usersAddress is too large considering that the array can contain duplicates. Since the _getWinnerShares internal function is called by the setWinner function for the admin to set the winner, this can cause denial of service.

    function _getWinnerShares() internal returns (uint256) {
    for (uint256 i = 0; i < usersAddress.length; ++i) {
    address user = usersAddress[i];
    totalWinnerShares += userSharesToCountry[user][winnerCountryId];
    }
    return totalWinnerShares;
    }

Risk

Likelihood:

This happens when the usersAddress array is too large.

Impact:

  • Causes denial of service

Recommended Mitigation

  • Bound the loop to a maximum number to avoid reverts in case the array is long.

Updates

Appeal created

bube Lead Judge 19 days ago
Submission Judgement Published
Validated
Assigned finding tags:

Unbounded Loop in _getWinnerShares Causes Denial of Service

The _getWinnerShares() function is intended to iterate through all users and sum their shares for the winning country, returning the total.

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.

Give us feedback!