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

Reward Inflation / Incorrect Reward Accounting

SAFE-0067 DeFi Economic Checked automatically by the scanner
1

What goes wrong

Reward-per-share or accrual math is wrong (updated in the wrong order, not scaled, or recomputed on stale state), letting users claim more rewards than earned or claim repeatedly.

2

How to fix it

the pattern that is safe
function claim() external updateReward(msg.sender) {
    uint r = rewards[msg.sender]; rewards[msg.sender]=0;
    reward.safeTransfer(msg.sender, r);
}
modifier updateReward(address a){
    rewardPerTokenStored = rewardPerToken();
    rewards[a] += earned(a);
    userPaid[a] = rewardPerTokenStored; _;
}
Use Synthetix StakingRewards accounting pattern.
Check your own contract for this

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