Skip to content

Rounding Error Exploitation

SAFE-0018 Arithmetic Checked automatically by the scanner
1

What goes wrong

Rounding direction favors the user instead of the protocol. Repeated tiny operations accumulate rounding in the attacker's favor, or a single rounding lets shares/assets be minted for free.

2

How to fix it

the pattern that is safe
// deposit: round shares down; withdraw: round assets down (protocol-favoring)
shares = Math.mulDiv(amount, totalShares, totalAssets, Math.Rounding.Floor);
Use OZ Math.mulDiv with explicit rounding.
Check your own contract for this

The SaferICO scanner runs 201 detectors over your Solidity source, SAFE-0018 among them. Paste an address or the source itself — a small per-scan fee, shown before you sign, or unlimited on any plan.

Run the scanner See how it is attacked Read the docs