Skip to content

Reward-Per-Token Precision Loss

SAFE-0219 Arithmetic Checked automatically by the scanner
1

What goes wrong

Staking rewards divide before multiplying (reward / totalSupply * stake) or omit a scaling factor (1e18), so small stakers accrue zero rewards and dust accumulates unclaimed in the contract.

2

The vulnerable pattern

proof of concept — how it is exploited
// rewardPerToken = reward / totalSupply; // integer -> 0 when reward < supply
// every small staker earns 0; rewards pile up and are never distributed.
3

How to fix it

the pattern that is safe
rewardPerToken += reward * 1e18 / totalSupply;      // scale up first
earned = stake * (rewardPerToken - paid[user]) / 1e18; // scale down last
Scale by 1e18 and multiply before dividing.
Check your own contract for this

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