# Truncated value validated at full precision

Check or ratio enforced on full-precision value while stored integer is truncated

_Area: DeFi accounting and math bugs. Seen in 4 disclosed reports; one confirmed bounty: $290,497; latest 2025-02-17. Updated 2026-10-24._

## How it works
A contract computes or validates a value at full precision, then stores or uses a truncated integer. The check passes on the precise number, but the value that actually governs behavior is the rounded-down one. The invariant the check was meant to enforce (a minimum ratio, a nonzero tax, a nonzero debt increment, a nonzero borrow) does not hold on the stored value. Small inputs make the gap largest because integer division loses the most there.

## Where it shows up
- Division whose result is stored or compared, especially `x * rate / 1e18` style formulas, where small `x` truncates to 0.
- Validation of a ratio or bound before a cast/truncation to a smaller type or to integer storage.
- A sentinel value (e.g. 0) that also occurs as a legitimate computed result.
- Per-operation increments (tax, debt, lock time) that can round to zero while a cumulative balance still grows.
- Cheap-L2 or batched paths where an attacker can split one operation into many dust-sized ones.

## How to review
Identify every value that is validated or computed at full precision and then stored or used truncated. The property that must hold: the invariant is checked on the value as stored/used, not on the pre-truncation input. Concretely:
- For each division, ask what the smallest realistic input is and whether the result can be 0 or off by one.
- For each ratio/bound check, confirm the comparison uses the same precision as storage; re-derive the bound after truncation.
- For each sentinel (0, max), confirm no valid rounded input can produce it.
- For each per-operation increment, confirm it cannot round to zero while the cumulative quantity grows.
- Test inputs just below truncation boundaries and just above minimums.

## Variants seen
- Tax computed as `tokensIn*rate/denom` truncates to 0 for small mints, letting mints be split into dust chunks to dodge tax [E1](https://bugbountylibrary.com/r/blog%3Aimmunefi-com-blog-bug-fix-reviews-the-graph-rounding-error-bugfix-review.md).
- Weighted-average lock time truncates so a tiny new unstake leaves the thaw period unchanged [E1](https://bugbountylibrary.com/r/blog%3Aimmunefi-com-blog-bug-fix-reviews-the-graph-rounding-error-bugfix-review.md).
- Leverage rounded down to a sentinel 0, which is then read as 100% borrow, producing far higher leverage than requested [E2](https://bugbountylibrary.com/r/c4%3A2023-04-rubicon%3AH-16.md).
- Fee scale validated against a limit at full precision but both truncated on storage, so the stored ratio violates the enforced bound [E3](https://bugbountylibrary.com/r/sherlock%3A2024-08-perennial-v2-update-3%3AM-7.md).
- Per-transfer reward-debt increment truncates to 0 while cumulative balance grows, so repeated tiny transfers accrue unearned rewards [E4](https://bugbountylibrary.com/r/c4%3A2024-03-neobase%3AM-05.md).

## Impact and severity
Led to dodged protocol fees/tax, bypassed unstaking thaw, unexpected leverage and liquidation risk, fees above protocol bounds, and unearned reward claims [E1](https://bugbountylibrary.com/r/blog%3Aimmunefi-com-blog-bug-fix-reviews-the-graph-rounding-error-bugfix-review.md)[E2](https://bugbountylibrary.com/r/c4%3A2023-04-rubicon%3AH-16.md)[E3](https://bugbountylibrary.com/r/sherlock%3A2024-08-perennial-v2-update-3%3AM-7.md)[E4](https://bugbountylibrary.com/r/c4%3A2024-03-neobase%3AM-05.md). Severity rises when the truncated quantity is user-controllable and repeatable (dust splitting, loops), and when the loss is silent so balances drift from reality unnoticed.

## Evidence
- E1: https://bugbountylibrary.com/r/blog%3Aimmunefi-com-blog-bug-fix-reviews-the-graph-rounding-error-bugfix-review.md
- E2: https://bugbountylibrary.com/r/c4%3A2023-04-rubicon%3AH-16.md
- E3: https://bugbountylibrary.com/r/sherlock%3A2024-08-perennial-v2-update-3%3AM-7.md
- E4: https://bugbountylibrary.com/r/c4%3A2024-03-neobase%3AM-05.md
