Weak Randomness Explained in Detail
Weak randomness happens when a contract uses predictable or influenceable data as randomness. Common examples include block timestamp, block number, previous block hash, sender address, or pool state.
On-chain data is visible before execution or can be influenced by block builders, validators, users, or surrounding transactions.
Smart contract example
The result below is predictable and influenceable:
uint256 roll = uint256(keccak256(abi.encodePacked(block.timestamp, msg.sender))) % 100;
A player can choose when to call. A validator may also influence timestamp within protocol limits.
Weak Randomness in Auditing
Weak randomness affects lotteries, NFT mints, games, raffles, validator selection, reward distribution, and liquidation ordering. It often combines with MEV, front-running, or weak commit-reveal design.
Red flags in code
-
Randomness uses
block.timestamp,block.number,blockhash,msg.sender, ortx.origin. -
Users can retry until they get a favorable outcome.
-
Randomness is generated and consumed in the same transaction.
-
Low-entropy salts or predictable seeds.
-
Random result controls value distribution or privileged selection.
How to test or review it
-
Identify who can observe, influence, or delay the entropy source.
-
Test repeated calls, delayed calls, and transaction ordering changes.
-
Check whether users can abort unfavorable outcomes.
-
Prefer verifiable randomness, commit-reveal with penalties, or delayed settlement where appropriate.
-
Review whether oracle manipulation can affect any value used as entropy.
Keep learning this topic
Commit-Reveal
Commit-reveal is a two-step pattern where users first submit a hidden commitment and later reveal the original value to reduce front-running.
MEV
MEV, or maximal extractable value, is value that can be extracted from transaction inclusion, exclusion, or ordering beyond normal block rewards and fees.
Oracle Manipulation
Oracle manipulation occurs when an attacker distorts a data source that a smart contract trusts, causing the contract to make decisions from unsafe data.
Weak Randomness Attacks
See how this vulnerability appears in real smart contract audits.
Frontrunning & Sandwich Attacks
Frontrunning and sandwich attacks in Solidity: how MEV bots extract value from DeFi traders, real examples, and slippage-based protections.
Smart Contract Audit Checklist
Use this SCH tool to turn the concept into practical audit work.
Practice this in real audit scenarios
Definitions help, but auditors need reps. SCH turns concepts like Weak Randomness into exploit labs, code review habits, and report-writing practice.
Start the free trial or see the full smart contract auditing course.