You are viewing a free preview of this lesson.
Subscribe to unlock all 10 lessons in this course and every other course on LearningBro.
In a decentralised network with no central authority, how do participants agree on the state of the ledger? Consensus mechanisms are the rules and protocols that allow distributed nodes to reach agreement on which transactions are valid and in what order they are recorded.
In a centralised database, a single administrator decides what data is valid. In a blockchain:
A consensus mechanism must ensure that all honest nodes eventually agree on the same ledger state, even in the presence of faulty or malicious participants.
The foundational challenge of distributed consensus was formalised in 1982 by Lamport, Shostak, and Pease:
Imagine several generals surrounding a city. They must agree on a battle plan (attack or retreat), but some generals may be traitors who send conflicting messages.
| Scenario | Outcome |
|---|---|
| All generals are honest | Consensus is straightforward |
| Some generals are traitors | Honest generals must still reach agreement despite conflicting messages |
| More than 1/3 of generals are traitors | Classical BFT algorithms cannot guarantee consensus |
Blockchain consensus mechanisms are solutions to this problem.
Proof of Work is the original consensus mechanism, introduced by Bitcoin in 2009.
1. Transactions are broadcast to the network
2. Miners collect transactions into a candidate block
3. Miners race to find a nonce such that:
Hash(block header + nonce) < target difficulty
4. The first miner to find a valid nonce broadcasts the block
5. Other nodes verify the block and add it to their chain
6. The winning miner receives a block reward (newly minted coins + transaction fees)
| Property | Description |
|---|---|
| Difficulty adjustment | The network adjusts the target difficulty to maintain a consistent block time (e.g. ~10 minutes for Bitcoin) |
| Energy-intensive | Miners expend significant computational power (and electricity) |
| Sybil resistance | Creating fake identities does not help; only computational power matters |
| Longest chain rule | The chain with the most cumulative proof of work is considered canonical |
| 51% attack threshold | An attacker needs more than 50% of the network's hash power to consistently outpace honest miners |
Target: Find a hash starting with at least 18 leading zeroes
Hash("Block data" + nonce=0):
a3f8b2c1d4e5f6... (doesn't start with enough zeroes)
Hash("Block data" + nonce=1):
7bc29d4e1f3a08... (doesn't start with enough zeroes)
... (billions of attempts) ...
Hash("Block data" + nonce=48291073):
0000000000000000003a8f... (valid! Starts with 18 zeroes)
| Advantages | Disadvantages |
|---|---|
| Battle-tested (Bitcoin since 2009) | Extremely energy-intensive |
| Highly secure with large networks | Slow transaction throughput |
| Simple and well-understood | Tendency towards mining pool centralisation |
| No need to trust validators | Specialised hardware (ASICs) creates barriers to entry |
Proof of Stake selects block validators based on the amount of cryptocurrency they have "staked" (locked up) as collateral.
1. Validators lock up (stake) their tokens as collateral
2. The protocol selects a validator to propose the next block
(selection weighted by stake amount, with randomisation)
3. The chosen validator creates and broadcasts the block
4. Other validators attest (vote) to the block's validity
5. If the block is accepted, the validator earns rewards
6. If the validator acts maliciously, their stake is slashed (partially or fully destroyed)
Subscribe to continue reading
Get full access to this lesson and all 10 lessons in this course.