Precision Loss
Cumulative inaccuracy caused by integer arithmetic and rounding in smart contract calculations.
Precision Loss refers to the cumulative degradation of numerical accuracy that occurs when smart contracts perform mathematical operations using integer arithmetic. Since the EVM does not support floating-point numbers, all calculations use fixed-point integer math where division operations truncate remainders. While individual precision losses are often negligible, they can compound over repeated operations — particularly in moving average calculations, interest accruals, and AMM invariant computations — creating exploitable vulnerabilities.
Why precision loss occurs
Solidity uses integer division, which always rounds toward zero:
1// Expected: 10 / 3 = 3.333...2// Actual: 10 / 3 = 3 (remainder discarded)3uint256 result = 10 / 3; // Returns 3, losing 0.333...
For a single operation, losing 0.333 wei is inconsequential. But in a loop calculating a moving average over many periods, or in compound interest calculations executed every block, these small errors accumulate.
Impact on moving averages
Moving average calculations are particularly susceptible:
1// SMA of [100, 101, 102] with 3 periods2// Expected: (100 + 101 + 102) / 3 = 101.03// Actual: 303 / 3 = 101 ✓ (exact in this case)45// SMA of [100, 101, 103] with 3 periods6// Expected: (100 + 101 + 103) / 3 = 101.333...7// Actual: 304 / 3 = 101 (lost 0.333...)
Over thousands of updates, this accumulated precision loss can drift the moving average away from its true value, potentially causing incorrect interest rate adjustments, faulty oracle prices, or invalid liquidation triggers.
Mitigation strategies
- Scale up before dividing: Multiply by a precision factor (e.g., 1e18) before division to preserve more significant digits.
- Round in the protocol's favor: Use
mulDownfor amounts going to users,mulUpfor amounts coming from users. - Enforce minimum values: Prevent calculations at microscopic scales where rounding errors dominate.
- Use higher-precision libraries: Libraries like PRBMath or ABDKMath provide 59.18 or 64.64 fixed-point arithmetic with better precision guarantees.
Difference from rounding error
Precision loss and rounding error are closely related but distinct. Rounding error is the inaccuracy in a single operation; precision loss is the cumulative effect of many rounding errors compounding over time. An attacker might exploit precision loss by deliberately triggering thousands of operations where each rounding error favors them.
Understanding precision loss is essential for auditing any protocol that performs iterative calculations, especially those involving moving averages, compound interest, or token price computations.
Articles Using This Term
Learn more about Precision Loss in these articles:
Related Terms
Rounding Error
Precision loss in mathematical calculations that can be exploited through repeated operations to drain protocol funds.
Integer Division
Division in Solidity that truncates the result to a whole number, discarding any fractional remainder and potentially causing precision loss.
Moving Average
A calculation that smooths price data over a specified period by continuously updating the average as new data arrives.
Need expert guidance on Precision Loss?
Our team at Zealynx has deep expertise in blockchain security and DeFi protocols. Whether you need an audit or consultation, we're here to help.
Get a Quote

