Skip to content
medium Logic / State No SWC entry CWE-664

State Desync Between Related Variables

SAFE-0070 Logic / State Checked automatically by the scanner
1

What goes wrong

Two variables that must stay in sync (e.g. totalSupply vs sum of balances, totalStaked vs stakes) are updated in different places and can drift, breaking invariants relied on elsewhere.

2

How to fix it

the pattern that is safe
function unstake(uint a) external { stake[msg.sender]-=a; totalStaked-=a; }
Update coupled state atomically; assert invariants.
Check your own contract for this

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