⛓️ Blockchain Consensus
Miners race to find a nonce whose hash beats the difficulty target, append a block and broadcast it. Watch the longest chain win, forks resolve, difficulty retarget, and a 51% attacker try to out-mine the honest network.
About Blockchain Consensus Mechanisms
Blockchain consensus is the process by which a distributed network of computers — none of which trust each other — agrees on a single, tamper-resistant history of transactions. In Proof-of-Work (PoW), the mechanism used by Bitcoin, each miner repeatedly hashes a block header with a random nonce until the result falls below a target value, a process that requires enormous computation but is trivially verifiable by anyone. The "longest chain wins" rule, known as Nakamoto consensus, ensures that an attacker must outpace the entire honest network to rewrite history — an economic guarantee rather than a cryptographic one.
This simulation lets you control the number of honest miners, the hash difficulty, the fraction of hash rate held by an attacker, and the block reward. Watch forks form and resolve as miners occasionally find blocks simultaneously, observe difficulty retargeting every few rounds to keep block times near a target, and raise the attacker fraction above 50% to see double-spend attempts become increasingly probable.
Frequently Asked Questions
How does Proof-of-Work mining actually work?
A miner takes a block of pending transactions, adds a random number called a nonce, and hashes the entire header using SHA-256. If the resulting hash begins with enough leading zeroes (i.e. is numerically below the network's target), the block is valid and the miner broadcasts it. The expected number of hashes needed equals 2^(leading zero bits), so increasing difficulty by one bit doubles the average work required.
What is the 51% attack and how does it threaten security?
If a single entity controls more than half the network's total hash rate, it can mine a private chain faster than the public chain on average. Once its secret chain is longer, it broadcasts it, the network switches to it under the longest-chain rule, and any transactions on the now-abandoned public chain are reversed — a "double spend." In practice, executing a 51% attack on Bitcoin would cost an estimated hundreds of millions of dollars per hour, making it economically irrational against the network's market cap.
What is a blockchain fork and how is it resolved?
A fork occurs when two miners find valid blocks at nearly the same time, producing two competing chain tips. Each propagates its block, and the network temporarily splits. The tie is broken as soon as one chain grows by a further block — the longer chain wins and the losing block becomes an "orphan" or "uncle." This natural resolution happens within seconds on Bitcoin but depends on block propagation speed across the peer-to-peer network.
How does difficulty adjustment work in Bitcoin?
Bitcoin recalculates its proof-of-work target every 2,016 blocks (approximately two weeks). If those blocks were found faster than the 10-minute target, the target is lowered (difficulty increases); if slower, it is raised. The maximum allowed change per adjustment is a factor of four, preventing sudden extreme swings. This feedback mechanism keeps average block times near 10 minutes regardless of how much hash rate joins or leaves the network.
What is Proof-of-Stake and how does it differ from Proof-of-Work?
In Proof-of-Stake (PoS), validators are chosen to propose blocks in proportion to the amount of cryptocurrency they lock up as collateral ("stake") rather than by performing computation. Ethereum switched from PoW to PoS in "The Merge" in September 2022, reducing its energy consumption by approximately 99.95%. Attacking a PoS chain requires controlling a majority of staked coins, and the protocol can slash (confiscate) the stake of detected attackers.
Why do transactions need multiple confirmations before being considered final?
Each additional block added on top of a transaction's block makes it exponentially harder to reverse. Bitcoin's convention of six confirmations (~60 minutes) reflects the probability that an attacker with 30% hash rate could secretly mine a longer fork from that point: the probability drops below 0.1% by block six. For very large transactions, merchants may require many more confirmations.
What is a nonce and can a miner run out of nonces?
A nonce (number used once) is a 32-bit integer in the block header that miners increment looking for a valid hash. With 2³² ≈ 4.3 billion possibilities per nonce, modern high-speed miners can exhaust the nonce space in under a second. When this happens, they change another field — typically the timestamp or the "extraNonce" in the coinbase transaction — to create a fresh set of nonces to search.
What is a selfish mining attack?
In selfish mining, a miner with sufficient hash rate (as little as ~33%) withholds found blocks, building a private lead. It only publishes when the honest network is about to catch up, causing honest miners to waste work on a chain that will be discarded. Selfish mining can give the attacker a disproportionate share of block rewards without the full 51% needed for a double-spend, and it is a known vulnerability of Nakamoto consensus.
How much energy does Bitcoin mining consume?
Bitcoin's network consumes an estimated 120–150 TWh per year, roughly comparable to the annual electricity use of a country such as Argentina. This energy expenditure is deliberate — it is what makes the ledger costly to rewrite. Critics argue the consumption is wasteful for a payment system, while proponents note that an increasing fraction is sourced from surplus renewable energy and that the security it buys is proportionally valuable.
Can blockchains be used for things other than cryptocurrency?
Yes — smart contracts, NFTs, decentralised finance (DeFi), supply-chain provenance tracking, and digital identity are all active areas. Ethereum popularised programmable blockchains where arbitrary code runs in a virtual machine on every node, creating trustless applications. However, on-chain computation is expensive per operation, so many applications only store cryptographic commitments on-chain and keep bulk data off-chain.
Proof-of-Work mining and longest-chain consensus: miners race to beat the difficulty target, blocks broadcast and forks resolve, difficulty retargets, and a 51% attacker's success probability is shown.
3D · Three.js / WebGL renderer · 60 FPS target · runs fully client-side, no install