Rounding Direction Explained in Detail
Solidity integer division cannot keep fractions. Rounding direction decides whether the result rounds down for unsigned division, rounds up when explicitly requested, or truncates toward zero for signed division.
In financial code, that leftover fraction belongs to someone.
Smart contract example
shares = assets * totalSupply / totalAssets;
This rounds down because Solidity integer division truncates.
Rounding Direction in Auditing
The wrong rounding direction can leak value, mint too many shares, burn too few shares, undercharge fees, or create repeated small-profit attacks.
Auditors check who benefits from every rounding remainder.
Red flags in code
-
Raw division appears in financial math without stated intent.
-
Deposit and withdraw paths round inconsistently.
-
Fee math rounds in the wrong party's favor.
-
ERC4626 conversions do not follow expected rounding behavior.
-
Tests use only large values where rounding is invisible.
How to test or review it
-
Fuzz small values and boundary values.
-
Check every division,
mulDiv, fee, exchange-rate, and share calculation. -
Verify monotonicity and conservation of value.
-
Compare deposit, mint, withdraw, and redeem paths.
-
Test whether repeated small operations can accumulate profit.
Keep learning this topic
Precision Loss
Precision loss happens when integer arithmetic drops fractional value during division, scaling, or fixed-point conversions.
Rounding Error
A rounding error is the difference between the mathematically exact result and the integer-rounded result returned by smart contract math.
ERC4626 Inflation Attack
An ERC4626 inflation attack manipulates an empty or low-supply vault's asset-to-share rate so a victim receives too few shares.
Practice this in real audit scenarios
Definitions help, but auditors need reps. SCH turns concepts like Rounding Direction into exploit labs, code review habits, and report-writing practice.
Start the free trial or see the full smart contract auditing course.