Skip to main content

Divide Before Multiply

What it detects

This detector flags arithmetic expressions where integer division is performed before multiplication. In Solidity, all division involving integers truncates toward zero, discarding the remainder. If division occurs before multiplication, especially with small numbers or ratios, this truncation can severely degrade accuracy.

For example, amount / rate * 100 will lose precision if amount / rate results in a fractional number less than 1, which will be rounded down to 0. In contrast, rewriting the formula as amount * 100 / rate preserves much of the precision by delaying truncation until the final division.

This pattern is especially risky in financial calculations involving token conversions, fee distributions, or reward computations where exact values matter.

Typical symptoms

  • Calculations unexpectedly return zero or a rounded-down value
  • Users receive lower rewards, interest, or dividends than expected
  • Protocol under-distributes or misallocates fees or payouts
  • Mispricing in AMMs or staking contracts due to poor precision

Solidity snippet (v0.8.25)

pragma solidity ^0.8.25;

contract DivisionOrder {
function calc(uint256 amount, uint256 rate) external pure returns (uint256) {
// Precision lost because division occurs before multiplication
return amount / rate * 100;
}

function fixedCalc(uint256 amount, uint256 rate) external pure returns (uint256) {
// Preserves precision by multiplying first
return amount * 100 / rate;
}
}

Why it matters on EVM

The EVM does not support floating-point arithmetic, so integer division always truncates the result. If smart contracts divide before multiplying, they can unintentionally reduce values to zero or a lower integer, creating discrepancies in payout logic, fee calculations, or pricing models.

These issues can:

  • Undermine protocol fairness by under-rewarding users
  • Create economic inefficiencies that affect liquidity or user trust
  • Introduce silent bugs that are hard to detect during audits or testing