Core Contracts

Regnum Aurum Acquisition Corp
HardhatReal World AssetsNFT
77,280 USDC
View results
Submission Details
Severity: medium
Valid

Precision Loss in Fee Distribution Due to Integer Division Order

2025-02-raac-main/contracts/core/collectors/FeeCollector.sol

Finding: Precision Loss Due to Integer Division Order

Issue Summary

The division operation in:

uint256 weight = (feeAmount * BASIS_POINTS) / totalFees;

is performed before subsequent multiplications. In Solidity, integer division truncates results, leading to precision loss, especially when feeAmount or totalFees are small.


Potential Vulnerability

Precision Loss:

  • If feeAmount is small relative to totalFees, the division truncates decimals before multiplication, reducing accuracy.

  • This could result in incorrect fee distribution, leading to unexpected token allocations or financial discrepancies.


Impact: Medium

  • Inaccurate fee calculations may shortchange or over-allocate certain shares.

  • Small amounts may be rounded to zero, causing unintentional fund loss.

Likelihood: Medium

  • The issue is likely if feeAmount is relatively small.

  • The error compounds over multiple transactions, causing cumulative miscalculations.


Proof of Concept (PoC)

Scenario

Consider feeAmount = 10 and totalFees = 30:

uint256 weight = (10 * 10000) / 30; // Evaluates to 3333 (truncated)
shares[0] += (3333 * 10) / 10000; // Result is 3 (losing precision)

Instead, performing multiplication first:

uint256 weight = (feeAmount * feeType.veRAACShare) / totalFees;

preserves precision, as the intermediate values remain larger.


Recommended Fix

Multiply Before Dividing Modify the weight calculation to ensure multiplication happens first:

uint256 weight = (feeAmount * feeType.veRAACShare) / totalFees; // Fix precision loss
shares[0] += (weight * BASIS_POINTS) / BASIS_POINTS;
shares[1] += (weight * feeType.burnShare) / BASIS_POINTS;
shares[2] += (weight * feeType.repairShare) / BASIS_POINTS;
shares[3] += (weight * feeType.treasuryShare) / BASIS_POINTS;

Updates

Lead Judging Commences

inallhonesty Lead Judge 4 months ago
Submission Judgement Published
Validated
Assigned finding tags:

FeeCollector distributes too much to treasury when fee amounts are small relative to total due to precision loss in (feeAmount * BASIS_POINTS) / totalFees

inallhonesty Lead Judge 4 months ago
Submission Judgement Published
Validated
Assigned finding tags:

FeeCollector distributes too much to treasury when fee amounts are small relative to total due to precision loss in (feeAmount * BASIS_POINTS) / totalFees

Support

FAQs

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