In the _distribute function, if the percentages array is empty, the loop calculating totalPercentage will never run. As a result, totalPercentage will remain zero. This can lead to an underflow issue when the check totalPercentage != (10000 - COMMISSION_FEE) is performed. Since 10000 - COMMISSION_FEE is always positive, the condition will pass even when totalPercentage is zero, which is not the intended behavior.
See the summary
Here is the vulnerable part in code
With this issue an attacker can distribute tokens without adhering to the intended distribution logic. The condition for a valid distribution (totalPercentage equals 10000 - COMMISSION_FEE) could be bypassed, leading to unintended token distribution. And result in financial losses, as tokens might be distributed incorrectly or unfairly to recipients.
Here is the Exploitation Plan:
The attacker will call the distribute function with an empty winners array and percentages array. This will result in totalPercentage remaining at zero.
Since totalPercentage is zero, the condition totalPercentage != (10000 - COMMISSION_FEE) will evaluate to true, despite the intended logic.
Exploitation Steps:
Attacker's Call
The attacker crafts a transaction to call the distribute function with empty arrays:
Execution Path:
The attacker's call will not enter the loop calculating totalPercentage, as the percentages array is empty.
Thus, totalPercentage will remain zero.
The condition totalPercentage != (10000 - COMMISSION_FEE) evaluates to true (0 != 9500).
The intended logic of verifying a valid distribution is bypassed.
The attacker successfully tricks the contract into considering the distribution as valid, despite the fact that no winners have been specified and the totalPercentage is zero.
The contract will proceed to transfer tokens according to the invalid distribution logic, leading to financial losses and potentially transferring tokens to unintended addresses.
Output :
COMMISSION_FEE is 500. If the attacker's call is successful, the output:
Manual review
check at the _distribute function to ensure that the winners array is not empty
As this
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.