Flow

Sablier
FoundryDeFi
20,000 USDC
View results
Submission Details
Severity: high
Invalid

Precision Loss in `calculateAmountsFromFee` Calculations

Summary

In financial calculations, particularly involving high-value transactions within smart contracts, fixed-point data types like UD60x18 provide enhanced precision. However, when converting these types to standard integer formats like uint128, significant fractional parts may be truncated, leading to precision loss. This precision loss can result in smaller payments or fees to users or brokers, causing them direct financial losses. If not properly handled, such precision issues may accumulate over time, leading to substantial discrepancies and potential dissatisfaction from affected parties.

Vulnerability Details

When financial operations are performed using high-precision types such as UD60x18 and later converted to lower-precision types like uint128, any fractional component is discarded. For instance, in the following Solidity code snippet:

feeAmount = ud(totalAmount).mul(fee).intoUint128();

https://github.com/Cyfrin/2024-10-sablier/blob/8a2eac7a916080f2022527408b004578b21c51d0/src/libraries/Helpers.sol#L22

Here, the totalAmount is first scaled to UD60x18, allowing for precise calculations. However, the high-precision result is truncated when converted to uint128, and only the integer part of feeAmount is retained, discarding any fractional portion. This issue particularly impacts scenarios involving small, recurring fees on large transaction amounts, where fractional losses may accumulate significantly over time.

In this scenario, the precision loss directly affects brokers or users entitled to receive fees or payments. If the fractional portion of the fee or payment is discarded, the recipient may receive less than expected, which, over repeated transactions, could result in significant revenue leakage.

Impact

Revenue Loss for Brokers and Service Providers: When a fee is calculated and converted to uint128, the fractional portion may be discarded, resulting in brokers or intermediaries receiving less than the full calculated fee. While this discrepancy may seem minor in individual transactions, it can accumulate significantly over high transaction volumes, leading to considerable losses for service providers and brokers.

Tools Used

Manually

Recommendations

Retain High-Precision Types Throughout Calculations: Whenever possible, avoid converting high-precision data types like UD60x18 to lower-precision types for sensitive financial calculations. Maintain high-precision formats throughout the computation chain to ensure accurate final amounts.

Updates

Lead Judging Commences

inallhonesty Lead Judge 7 months ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity
inallhonesty Lead Judge 7 months ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity

Support

FAQs

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