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.
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.
This situation can result in an incorrect distribution of rewards to winners, leading to undesired outcomes.
Manual Review
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.
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.