Precision Loss Explained in Detail
Precision loss is the value lost when a calculation cannot represent the exact fractional result. Solidity does not use floating point numbers for token accounting, so protocols usually emulate decimals with integer scaling factors such as 1e18.
The most common mistake is dividing too early. Once a fraction is truncated, later multiplication cannot recover it.
Smart contract example
function reward(uint256 amount, uint256 rate) external pure returns (uint256) {
return amount / 1e18 * rate;
}
If amount is smaller than 1e18, the division returns 0. The reward is zero even when the exact calculation should produce a small nonzero value.
Precision Loss in Auditing
Precision loss can move value between users and the protocol. A single truncation may be small, but repeated deposits, redemptions, liquidations, rewards, or fee calculations can turn small losses into an economic bug.
Auditors review where fixed-point math converts between token units, oracle units, shares, debt, collateral, and fee rates. Precision loss is especially important in ERC-4626 vaults, reward systems, and thin-liquidity DeFi states.
Red flags in code
-
Division happens before multiplication.
-
Token amounts are scaled up and down multiple times in one flow.
-
Small deposits, small shares, or small rewards can round to zero.
-
1e18is hardcoded even when token or oracle decimals differ. -
Dust left by truncation is not assigned or bounded clearly.
How to test or review it
-
Test tiny amounts, one-unit amounts, and values just below each scaling factor.
-
Compare Solidity output against a high-precision reference model.
-
Check whether precision loss consistently favors one side.
-
Review token decimals and oracle decimals together.
-
Add invariant testing for conservation of assets, shares, fees, and rewards.