Beginner FriendlyFoundry
100 EXP
View results
Submission Details
Severity: medium
Valid

Division by zero is possible in reward calculation

Summary

The reward calculation in the withdraw function doesn't check for a zero divisor, which could lead to a division by zero error.

Vulnerability Details

In the withdraw function:

reward = maxScore < 0
? entranceFee
: (shares * players.length * entranceFee) / totalShares;

There's no check to ensure totalShares is not zero before performing the division.

Impact

If totalShares is zero (which could happen if all players have zero or negative scores), the function will revert due to a division by zero error.

Tools Used

Manual code review

Recommendations

  1. Add a check for zero totalShares:

    require(totalShares > 0, "No positive scores");
  2. Handle the case where all scores are zero or negative separately:

    if (totalShares == 0) {
    reward = entranceFee;
    } else {
    reward = (shares * players.length * entranceFee) / totalShares;
    }
Updates

Lead Judging Commences

NightHawK Lead Judge about 1 year ago
Submission Judgement Published
Validated
Assigned finding tags:

Possible maxScore of zero is not accounted

The checks related to maxScore do not account possible maxScore of zero leading to stuck funds or a division by zero error.

Support

FAQs

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