Skip to content
Menu
Finabase Learn

Crypto · How blockchains work

How a blockchain reaches agreement: consensus explained

How thousands of computers settle on one transaction history, why confirmations matter, and the odds of a 51% attack worked out from the bitcoin whitepaper.

On this page
  1. The problem: spending the same coin twice
  2. Who gets to add a block
  3. The longest-chain rule
  4. Confirmations and the six-block convention
  5. What a majority attacker can and cannot do
  6. Finality on proof-of-stake chains
  7. Pitfalls
  8. How Finabase does it
  9. Frequently asked questions
  10. Summary
  11. Check your understanding

Consensus is the process by which the computers on a blockchain network come to hold the same record of who owns what. In a bank this is not a problem worth a name: the bank's database is the record. On a network with no owner, where anyone may join and some participants are dishonest, getting everyone to the same answer is the central difficulty, and the method a chain uses to solve it is called its consensus mechanism.

The practical question behind it is the one a merchant asks: when is a payment final? A blockchain's answer is rarely "immediately". It is a probability that rises with time, or a checkpoint that arrives after a few minutes, depending on the design. This lesson explains both, and works out the numbers behind the common advice to wait for six confirmations.

The problem: spending the same coin twice

A digital coin is data, and data can be copied. Suppose Mia holds one coin and signs two transactions at the same instant: one paying a shop, one paying herself at a second address. Both signatures are valid. Both transactions are properly formed. Only one can be allowed to stand.

The signatures prove that Mia approved each payment. They say nothing about which came first. A bank settles this by processing requests one at a time against its own ledger. A network with no central ledger needs another way to agree on an order, and the order has to be one that Mia cannot later rearrange.

That is all a blockchain's consensus does: it produces a single ordering of transactions that every honest participant ends up with. Blocks are the ordering device. Whichever of Mia's two payments lands in a block first is valid, and the other, now spending a coin that is already spent, is rejected by every node.

So the problem moves up one level. Agreeing on the order of transactions becomes agreeing on the sequence of blocks.

Who gets to add a block

If anyone could add a block at any time for free, an attacker could flood the network with alternative histories and nothing would ever settle. Every open blockchain therefore makes the right to add a block depend on something scarce that cannot be faked by creating thousands of identities:

  • Proof of work ties it to computing power. Whoever first finds a block whose hash is below a target wins the right to add it.
  • Proof of stake ties it to coins locked up as a deposit. Validators are chosen at random, weighted by their deposit, and lose part of it if they break the rules.

Proof of work vs proof of stake: how they differ compares the two in detail. For this lesson what matters is that both make block production costly and both make an attacker's influence proportional to their share of the scarce resource, not to the number of computers they control.

The longest-chain rule

Because blocks are found by independent parties around the world, two of them sometimes produce a valid block at nearly the same moment, both building on the same parent. For a while the network is split: some nodes heard of block A first, others block B. Each node provisionally works with the one it saw first and keeps the other in reserve.

How a temporary fork is resolved under the longest-chain rule 1. Two producers find block 101 at almost the same moment Block 99 Block 100 101 A 101 B Some nodes hear A first others hear B first 2. The next block is built on A. Every node switches to the longer chain Block 99 Block 100 101 A 102 101 B the chain every node now follows dropped: its transactions go back to the waiting pool
A temporary fork. The tie is broken by whichever branch gets the next block, and every node then follows that branch.

The tie is broken by the next block. Whichever branch is extended first becomes the longer one, and the rule every node follows is to treat the chain with the most accumulated work as the true one. Nodes on the losing branch switch over. The abandoned block is discarded, and any of its transactions that are not already in the winning branch return to the waiting pool to be included later. This switch is called a reorganization, or reorg.

One-block reorganizations happen on bitcoin from time to time and harm nobody who waited. The lesson for a recipient is that a transaction in the newest block is not yet settled: there is a small chance that block will be replaced.

Confirmations and the six-block convention

A transaction has one confirmation when it is included in a block, two when another block is added on top, and so on. Each one makes reversal harder, because an attacker who wants to replace the payment has to build a competing branch from the block before it and overtake the honest chain, which keeps growing while they work.

The bitcoin whitepaper treats this as a race and gives a formula for the attacker's chance of ever catching up from z blocks behind, given their share q of the total mining power. We computed it for four attackers.

Confirmations Attacker has 10% 25% 30% 45%
1 20.46% 52.23% 62.77% 91.98%
2 5.10% 31.54% 44.57% 87.77%
3 1.32% 19.61% 32.46% 84.44%
6 0.02% 4.99% 13.21% 76.61%
10 0.0001% 0.85% 4.17% 68.54%
Chance that an attacker rewrites a payment, by confirmations waited 0.0001% 0.001% 0.01% 0.1% 1% 10% 100% 0 1 2 3 4 5 6 7 8 9 10 Attacker has 10% of the mining power Attacker has 25% of the mining power Attacker has 30% of the mining power Attacker has 45% of the mining power Blocks added on top of the payment (confirmations) Formula from section 11 of the bitcoin whitepaper (2008). Log scale. Values under 0.0001% are drawn at the bottom line.
Probability that an attacker ever overtakes the honest chain from z blocks behind, from the formula in section 11 of the bitcoin whitepaper.

Three things stand out.

The probability falls fast for a small attacker. At 10% of the power, each extra confirmation cuts the chance by roughly three quarters. Six confirmations, about an hour on bitcoin, bring it to 0.02%, which is where the convention of waiting for six comes from. To get below 0.1% a 10% attacker has to be held off for only 5 confirmations.

It falls slowly for a large one. At 30%, six confirmations still leave a 13.2% chance, and getting below 0.1% takes 24. At 45% it takes 340. The six-block habit quietly assumes that no single party holds a large share of the mining power.

Above 50% the attacker always wins eventually. With most of the power, their branch grows faster on average, so they overtake at any depth given enough time. No number of confirmations protects against this. It is the origin of the term 51% attack.

How long to wait is therefore a judgment about the amount at stake. Waiting costs the attacker nothing unless they are spending real resources to mine; a small payment is not worth attacking, so many merchants accept one confirmation or none for small sums, and exchanges crediting large deposits require more. Exchanges set different thresholds for different coins, with more confirmations demanded on chains that have less mining power.

What a majority attacker can and cannot do

The phrase "51% attack" sounds like total control. It is narrower than that.

An attacker with most of the block-producing power can:

  • reverse their own recent payments, spending the same coins again (the double spend);
  • refuse to include particular transactions, delaying or censoring them; and
  • collect all the block rewards while the attack lasts.

They cannot:

  • spend coins that belong to someone else, because that needs the owner's signature;
  • create coins beyond the schedule, because nodes reject such blocks; or
  • change the rules, which are enforced by every node independently.

The usual victim is an exchange. The attacker deposits coins, trades them for another asset, withdraws it, and then publishes a longer chain in which the deposit never happened.

The cost of doing this scales with the size of the network. For bitcoin it would mean acquiring and powering more specialized machines than the rest of the world's miners combined, and the attack would likely crash the price of the coin the attacker's equipment exists to earn. A small proof-of-work coin is protected by far less computing power, and one that shares its mining algorithm with a larger coin can be outgunned by a fraction of the larger coin's miners. A payment in a minor coin needs far more confirmations to carry the same assurance.

Finality on proof-of-stake chains

Bitcoin's settlement is probabilistic: a reversal becomes steadily less likely and never reaches exactly zero. Ethereum's proof of stake adds a second layer that gives explicit finality.

Time on Ethereum is divided into slots of twelve seconds, each of which may contain one block, and into epochs of 32 slots, or 6.4 minutes. In each epoch validators vote on a checkpoint. When validators holding at least two thirds of all staked ether vote for a checkpoint it is justified, and when the next one is justified on top of it, it is finalized. In normal conditions a transaction is final after two epochs: 64 slots of twelve seconds is 12.8 minutes, and Ethereum's own documentation says "about 15 minutes".

Reversing a finalized block would require at least a third of all staked ether to sign conflicting votes, and the protocol destroys the deposits of validators who do. So the cost of undoing finality is not an estimate of hardware and electricity; it is a known quantity of the attacker's own coins, burned.

The trade-off is that finality can stall. If more than a third of validators go offline, blocks keep arriving but checkpoints stop finalizing. After four epochs without finality the protocol starts draining the deposits of the absent validators, until those still voting make up two thirds again.

Chain Block time How a payment becomes final Typical wait people use
Bitcoin ~10 minutes Probabilistic: each block lowers the odds 1 to 6 blocks, 10 to 60 min
Ethereum 12 seconds Checkpoint finalized by two thirds of the stake About 13 to 15 minutes

Pitfalls

  • "Confirmed" is not one thing. One confirmation on bitcoin, one on a small coin and finality on Ethereum are very different levels of assurance. Ask how many, and on what.
  • Zero confirmations is a promise, not a payment. An unconfirmed transaction is only waiting in nodes' pools. It can be replaced by another spending the same coins.
  • Consensus says nothing about fairness. It guarantees one agreed order. It does not stop a block producer from choosing an order that profits them, or from leaving a transaction out.
  • Final means final for mistakes too. A settled payment to a scammer is exactly as irreversible as a settled payment to a shop.
  • An exchange's ledger is not the chain. A trade inside an exchange changes its own database. Nothing is confirmed on a blockchain until coins are withdrawn. See How crypto markets differ from stocks: hours, venues and volatility.

How Finabase does it

Finabase shows prices and market statistics for coins on the crypto list and on quote pages such as BTC.X. It does not connect to any blockchain: it shows no confirmations, transaction status, mining power or validator counts, and you cannot send or receive coins through it. To check a payment you need a block explorer or your own wallet.

The probabilities in the table were computed by the script that draws the figure, using the formula printed in the whitepaper. Its values agree with the paper's own table, which lists 0.2045873 for one confirmation at 10% and 0.1773523 for five at 30%.

Frequently asked questions

How many confirmations does a bitcoin payment need?

It depends on the amount. Six, about an hour, is the long-standing convention for large sums, and reduces a 10% attacker's chance to 0.02%. Small payments are often accepted after one. The party receiving the money sets the threshold, since they bear the risk.

What is a 51% attack?

A 51% attack is one in which a party controlling most of a chain's block production builds a private branch and publishes it to replace recent history. It lets them reverse their own payments and censor others. It does not let them take coins from other people's addresses.

Is bitcoin at risk of a 51% attack?

The risk is low because of scale: an attacker would need more mining machines and power than every other miner combined. The whitepaper's own point is that someone with that much power earns more by mining honestly than by undermining the coin they are paid in. Smaller proof-of-work coins have far less protection.

What does finality mean in crypto?

Finality is the point after which a transaction cannot be reversed. On bitcoin it is a matter of degree, growing with each block. On Ethereum it is a defined event: a checkpoint approved by two thirds of the stake, normally 13 to 15 minutes after the transaction.

Why can a blockchain not confirm payments instantly?

Blocks must be spaced far enough apart for each to reach the whole network before the next arrives. Shorter gaps cause more ties and more discarded blocks. Faster chains accept that cost, use fewer and more powerful block producers, or both.

Summary

Consensus is how a network with no owner agrees on one order of transactions, which is what prevents the same coin from being spent twice. Bitcoin's nodes follow the chain with the most work, so a payment becomes safer with each block on top of it: against an attacker with 10% of the mining power the chance of reversal is 0.02% after six blocks, while an attacker with a majority can reverse at any depth. Proof-of-stake chains add checkpoints that make reversal cost a fixed share of all staked coins. In both designs the protection depends on how large and how widely held the chain's mining power or stake is, which is why the same number of confirmations means less on a small chain.

Check your understanding

5 questions on this lesson. Each answer comes with the reason, and nothing is scored.

  1. What problem is a blockchain’s consensus mechanism there to solve?

    1. Keeping transaction amounts secret
    2. Agreeing on one order of transactions so a coin cannot be spent twice
    3. Making transactions free
    Show the answer

    B. Agreeing on one order of transactions so a coin cannot be spent twice Signatures prove who approved a payment but not which of two conflicting payments came first. Consensus fixes a single order that all nodes share.

  2. Two valid blocks are found at the same height. How does bitcoin settle which one stays?

    1. The block with more transactions wins
    2. Nodes vote by email
    3. Whichever branch is extended first becomes the longer chain, and nodes follow it
    Show the answer

    C. Whichever branch is extended first becomes the longer chain, and nodes follow it Nodes follow the chain with the most accumulated work. The next block breaks the tie, and the other block is dropped.

  3. An attacker holds 30% of a chain’s mining power. After six confirmations, their chance of reversing a payment is about:

    1. 0.02%
    2. 13%
    3. 77%
    Show the answer

    B. 13% The whitepaper formula gives 13.2% for q = 0.30 and z = 6. Six confirmations are only strong protection when no attacker holds a large share.

  4. Which of these can an attacker with a majority of the mining power do?

    1. Spend coins from any address
    2. Create extra coins beyond the schedule
    3. Reverse their own recent payments
    Show the answer

    C. Reverse their own recent payments They can replace recent blocks, which undoes their own payments. Spending other people’s coins needs their signatures, and extra coins break rules every node enforces.

  5. What makes a finalized Ethereum block costly to reverse?

    1. At least a third of all staked ether would have to sign conflicting votes and be destroyed
    2. The block is stored on a government server
    3. Nothing: finality is only a convention
    Show the answer

    A. At least a third of all staked ether would have to sign conflicting votes and be destroyed Finality needs two thirds of the stake. Undoing it needs a third to contradict itself, and the protocol slashes those deposits.

Sources and further reading

  1. Satoshi Nakamoto — Bitcoin: A Peer-to-Peer Electronic Cash System (2008), sections 2, 4, 5 and 11 (the catch-up probability and its table)
  2. Bitcoin developer guide — Block chain (block height and forking, the longest-chain rule)
  3. Bitcoin.org — Some things you need to know (confirmations and irreversibility)
  4. Ethereum.org — Proof-of-stake (slots, epochs, finality)
  5. Ethereum.org — Single slot finality ("It takes about 15 minutes for an Ethereum block to finalize")
  6. Ethereum.org — Proof-of-stake attack and defense
  7. Probabilities on this page — computed by Finabase from the formula in section 11 of the whitepaper; the values match its published table