Solidity

Rounding Direction

Rounding direction is the choice to round a division or fixed-point result down, up, or toward zero.

Rounding direction decides who gets the leftover fraction when Solidity math cannot represent it.

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.

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.

Sources