How Proof of Work enables Decentralized Consensus

Jan 8, 2022

Suppose I give Alice 10 dollars and she later gives 5 dollars to Bob. Historically, we represented such transactions by transferring an object - cash. With the internet, transacting via physical cash became impractical, so we came up with ledgers. Then the problem was who maintains the truth-ness of the ledger? Historically, we trusted the banks, and governments with the ledger. This gave them immense power and control over the flow and creation of money. But now Bitcoin has the craziest answer you could imagine - everyone maintains a copy of the ledger.

Anyone running a node maintains a copy of the ledger since it’s dawn, keeping track of Bitcoin’s history and incoming transactions. Keeping power over the system in the hands of users.

How does this actually work?

Every transaction is broadcast out into the world, where nodes add it to their own copy of the ledger.

Problem: How to agree on the right ledger? When nodes receive transactions, how can they be sure that everyone else also received the same transaction.

We need a protocol for how to accept or reject transactions, and in what order, so that you can be sure that anyone else in the world following the same protocol, has the same ledger as you.

Proof of Work

If we use computational work as a basis for what to trust, you can make it so that fraudulent transactions are computationally infeasible.

Proof of work is a cryptographic proof in which the prover proves to others that a certain amount of computational effort has been expended.

Computational Work

Suppose that someone shows you a list of transactions, and they say “I found a special number so that when you put this number at the end of the list of transactions, and apply SHA-256 to the entire thing, the first 100 digits of the output are all zeros”. How hard do you think it was for them to find that number? It must have been really hard.

But once you know the number, you can quickly verify that this hash really does start with 100 zeros. You can verify that they went through a large amount of work without having to go through that same effort yourself. This number is called a proof of work.

NOTE: The purpose of proof of work algorithms is not proving that certain work was carried out, but deterring manipulation of data by establishing large energy and hardware requirements to be able to do so. [ 51% Attacks ]

Applying Proof of Work

For our decentralized ledger, we want a way for everyone to agree on the correct state of the ledger.

The core idea behind the bitcoin is to have everybody trust whichever ledger has the most computational work put into it. So even though there is no central authority, and everyone is maintaining their own copy of the blockchain, if everyone agrees to give preference to whichever blockchain has the most work put into it, we have a way to arrive at decentralized consensus.

Longest Chain rule

If you hear two miners broadcasting distinct blockchains with conflicting transaction histories, you defer to the longest one, i.e, the one with the most work put into it. If there’s a tie, wait until you hear an additional block that makes one longer.

Technically it’s not the longest chain, it’s the chain with the most work invested in it, it usually happens to be the longest chain. Learn about the difference here .

Why do nodes prefer the longest chain

  1. Resolving disagreements when two blocks are mined at the same time
  2. Protecting blocks already mined on to the blockchain.

Incentive for miners to build on the longest chain

A miner can claim a block reward if they are able to mine a block. Plus, the coins from this block reward can only be spent if the block is in the longest chain. The block reward incentivizes miners to always try and mine new blocks on top of the longest chain.

Conclusion

The usual framework of coins made from digital signatures, provides strong control of ownership, but is incomplete without a way to prevent double-spending. To solve this, Satoshi introduced a p2p network that uses Proof of Work to record a public history of transactions which quickly becomes computationally impractical for an attacker to change if honest nodes control a majority of CPU power.

It allows human who don’t know, trust each other who never reveal identities, location etc to transact securely.

Sources and references:

Thanks for reading :)


What is State in Ethereum

Summarizing Balaji's DeFi Matrix

Have a comment or response? Email me.