Sparkn

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

Missing Division before Multiplications

Summary

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

Vulnerability Details

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.

Impact

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.

Tools Used

VSCode and Remix

Recommendations

Incorrect: totalValue * 0.1 (multiplication first)

Correct: totalValue * (0.1 / 100) (division before multiplication)

Support

FAQs

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