Sparkn

CodeFox Inc.
DeFiFoundryProxy
15,000 USDC
View results
Submission Details
Severity: medium

[M] totalPercentage is left uninitialized in _Distribute which can lead to incorrect distribution of rewards

Summary

The issue revolves around the uninitialized totalPercentage variable within the _distribute function in the contract code. This variable is used to track the cumulative percentages of winners' rewards. When distributing rewards, the contract should ensure that the total of these percentages sums up to a specific value (e.g., 10000 - COMMISSION_FEE). If this total doesn't match the expected value, it indicates an incorrect distribution setup and should trigger a revert.

Vulnerability Details

Consider the following problematic scenario:

The totalPercentage variable is not explicitly initialized.

The percentages array contains uninitialized or incorrect values,
causing the loop within the _distribute function to execute without adding any values to totalPercentage.

The totalPercentage remains at its default value (probably 0 due to memory location) throughout the loop.

Since totalPercentage is not updated as expected, the final comparison
(if (totalPercentage != (10000 - COMMISSION_FEE))) would likely pass,
even though the actual distribution percentages are incorrect.

Impact

This situation can result in an incorrect distribution of rewards to winners, leading to undesired outcomes.

Tools Used

Manual Review

Recommendations

Explicitly initialize the totalPercentage variable to 0 before the loop starts:
uint256 totalPercentage = 0;.

Ensure that the percentages array contains accurate values that sum up to the expected total (e.g., 10000 - COMMISSION_FEE).

By initializing the totalPercentage variable and accurately calculating the sum of percentages,
you ensure that the distribution is properly set up, preventing unintended behavior.

Support

FAQs

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