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.
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:
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.
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.
Manually
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.
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.