Skip to content
medium DeFi Economic No SWC entry CWE-682

Rounding Direction Favors the User

SAFE-0217 DeFi Economic Checked automatically by the scanner
1

What goes wrong

Share/asset conversions round in the user's favor (mint rounds up, redeem rounds up) rather than the protocol's. Repeated deposits/withdrawals extract a wei of value each time, slowly draining the pool via rounding dust.

2

The vulnerable pattern

proof of concept — how it is exploited
// each redeem rounds up by 1 wei in the user's favor.
// attacker loops deposit/redeem thousands of times, skimming dust
// until the vault is measurably short.
3

How to fix it

the pattern that is safe
// mint shares: round DOWN; redeem/withdraw assets owed: round DOWN to protocol
shares = assets.mulDiv(supply, totalAssets, Math.Rounding.Floor);
Always round in the protocol's favor (EIP-4626 guidance).
Check your own contract for this

The SaferICO scanner runs 201 detectors over your Solidity source, SAFE-0217 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