Calculating fractions while failing to perform division before multiplication can lead to incorrect result uint256 amount = (totalAmount * percentages[i]) / BASE_POINT;
https://github.com/Cyfrin/2023-08-sparkn/blob/0f139b2dc53905700dd29a01451b330f829653e9/src/Distributor.sol#L146C74-L146C74
In calculations involving fractions or percentages, failing to perform division
before multiplication
can lead to incorrect results. For example, if you intend to calculate a percentage of a total value by multiplying it with a decimal fraction (e.g., 0.1 for 10%), you should first divide the percentage by 100 and then multiply it with the total value.
Not performing division before multiplication can lead to incorrect results in calculations, affecting the accuracy of your contract's logic. This might not necessarily result in critical vulnerabilities, but it could lead to unexpected behavior or inaccurate computations.
VSCode and Remix
Incorrect: totalValue
* 0.1 (multiplication first)
Correct: totalValue
* (0.1 / 100) (division before multiplication)
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.