Sparkn

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

Arithmetic Overflow Vulnerability

Summary

Arithmetic Overflow Vulnerability in Distributor Contract

Vulnerability Details

The vulnerability is related to the arithmetic calculations performed in the _distribute function of the Distributor contract. Specifically, the calculation totalAmount * percentages[i] / BASIS_POINTS has the potential to lead to an arithmetic overflow if the value of totalAmount is very large and the value of percentages[i] is close to the value of BASIS_POINTS. This could cause unintended behavior or result in an incorrect distribution of tokens.

Impact

If an overflow occurs in the mentioned calculation, it could lead to an incorrect distribution of tokens to winners. Depending on the values involved, this could result in loss of funds, where winners receive more tokens than intended, or an error in the distribution altogether.

Tools Used

Manual code review and analysis of the arithmetic calculations in the _distribute function.

Recommendations

To mitigate this vulnerability, the following recommendations are provided:

  1. Safe Arithmetic: Implement safe arithmetic functions to handle calculations and prevent overflow or underflow. You can use libraries like OpenZeppelin's SafeMath to perform arithmetic operations safely.

  2. Limit Percentages: Ensure that the percentages array contains values that are within a safe range to prevent potential overflow during calculations. Validate that percentages are reasonable and sum up to a valid total percentage (e.g., 10000 - COMMISSION_FEE).

  3. Thorough Testing: Perform extensive testing using various scenarios to ensure that the distribution calculations are accurate and don't lead to unexpected behavior.

By implementing these recommendations, you can reduce the risk of arithmetic overflow vulnerabilities and ensure the accurate distribution of tokens to winners in the Distributor contract.

Support

FAQs

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