Skip to content

Predictable / Weak On-Chain Randomness

SAFE-0042 Randomness Checked automatically by the scanner
1

What goes wrong

Randomness is derived from on-chain values (blockhash, block.timestamp, block.prevrandao, msg.sender). These are predictable or miner/validator-influenceable, so attackers can compute or bias outcomes (lotteries, NFT traits, games).

2

How to fix it

the pattern that is safe
// Chainlink VRF: request randomness, use fulfillRandomWords callback
function fulfillRandomWords(uint256, uint256[] memory words) internal override {
    winner = participants[words[0] % participants.length];
}
SWC-120. Use Chainlink VRF for secure randomness.
Check your own contract for this

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