The _calculateDistribution
function in FeeCollector.sol suffers from precision loss when handling small fee amounts relative to the total fees, potentially leading to incorrect distribution calculations and loss of funds for stakeholders.
In the _calculateDistribution
function, the weight calculation for each fee type is performed as:
When feeAmount
is significantly smaller than totalFees
, this calculation can result in a weight of 0 due to integer division rounding down.
For example:
If feeAmount = 100
BASIS_POINTS = 10000
as defined in the contract
totalFees = 10000000
The calculation becomes: weight = (100 * 10000) / 10000000 = 1000000 / 10000000 = 0
The actual weight should be 0.1, but due to integer division, small amounts get completely rounded down to zero, effectively being ignored in the distribution.
This issue is further compounded because the weights are then used to calculate the final shares:
Small fee amounts may be effectively ignored in distribution calculations
Stakeholders may not receive their correct share of fees
The distribution proportions defined in feeTypes
are not accurately maintained
Loss of funds for stakeholders when processing small fee amounts
Manual code review and mathematical analysis
consider minimum fee thresholds to prevent dust amounts:
2 Implement fixed-point arithmetic using a library like PRBMath or custom fixed-point calculations:
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.