In this post, I'd like to talk about one of the most critical aspects of cryptocurrencies: The Consensus Algorithm. I will do so by using Bitcoin to exemplify the implementation of the consensus algorithm called Proof of Work. In some sense, Proof of Work isn't a new concept and can be found throughout history. Each of the seven wonders of the world but also a lot of other impressive constructions can be considered Proof of Work. If someone passes by, it is immediately apparent, that these constructs cannot be built cheaply. They require an incredible amount of resources, knowledge, but also an established form of society, economy, and governance for them to be created. Each of them is a testament of proof of work of a great civilization able to build something outstanding. It is not possible to recreate it without a considerable amount of work. Not even with the tools, technology, and resources we have today.
Proof of work: Something that cannot be built cheaply
Image Source: Pexels.com
Introduction
Before jumping right into the thick of things, I want to provide a short overview of what a consensus algorithm is and which role it plays in the context of the whole ecosystem of cryptocurrencies. One of the significant advantages of a cryptocurrency like Bitcoin, compared to the traditional system of money, is its decentralized nature and the fact, that transactions are neutral to the sender, the recipient, and the amount transferred. Meaning that there’s no distinction. Anyone can join and propagate transactions or participate in mining. From the perspective of the bitcoin network, every transaction is equal and is processed if the fees are paid and the transaction is valid.
The Consensus algorithm
Each time a bunch of transactions is processed into a new block, it is added to the public ledger, increasing its block height by one. Considering that we don’t trust anyone that propagates transactions or mines bocks, we need a mechanism that decides whether or not any given version of the public ledger is valid. Furthermore, the mechanism needs to detect and resolve possible conflicts. Now that we understand the job of a consensus algorithm, you might expect some super complicated procedure of how the conflicts are resolved. Surprisingly, the consensus algorithm of Bitcoin is quite simple and can be described in four words: The longest chain wins. If there are two conflicting versions of the Bitcoin blockchain, the one with the most blocks (the most extended chain) is declared to be the truth. You might ask:
- How such a simple condition could resolve all conflicts?
- How can the security of the network be maintained?
- Why isn't everyone just spamming longer chains for them to be accepted as the new truth?
This is where another crucial component of Bitcoin's consensus algorithm enters the playground: Proof of Work. The Blockchain guarantees that a new block and its transactions need to be consistent with everything from the past. Proof of Work ensures a block can't just be created without work being done.
"The characteristic that gives bitcoin its tamper-proof capability is not "the blockchain"; it's proof of work." Andreas Antonopoulos - The Internet of Money Vol. 2
Proof of Work
I found that many people think that mining is solely used to create new Bitcoins. In reality, it's quite the opposite and mining primarily serves the purpose of securing the network and processing transactions. The creation of Bitcoins used as block rewards is a mere side-effect of this process. The Block reward used to incentivize miners is halved every 210'000 blocks and will reach 0 at block 6'930'000. Expectations are that this block will be mined in the year 2040, after which transaction fees remain the only incentive for miners to process transactions into a block.
Bitcoin controlled supply timeline estimation
Image Source: The Bitcoin Wiki
Sudoku on a planetary scale!
Now that we know that Proof of Work primarily serves the purpose of processing transactions and securing the network while doing so, it's time to have a closer look at how this is done.
Mining a block must include work
In an earlier post, I described the difference between tamper-evident and tamper-proof and how the latter requires proof of work.
One of the most important aspects is to realize that if there's no work involved in creating a block, the network is not secured and immutability is not achieved. The blockchain by itself is only tamper-evident. This enables participants to notice changes and inconsistencies but doesn't hinder anyone to implement them. In combination with the consensus rule of "the longest chain wins", tamper-evident isn't enough and would end in a disaster.
So... what is the answer to this?
As you might know, each block divides into a block header and a list of transactions processed in that block. Besides some other attributes, the block header contains the hash (Merkle tree root) of all transactions as well as the hash of the previous block. With that, each participant can independently verify that the chain and all its transactions are valid and have not been tampered with.
The Bitcoin Blockchain, re-illustrated by
. Based on Mastering Bitcoin by Andreas Antonopoulos, Figure 9.1 P.201
The Bitcoin Sudoku
Let's have a look at how the process of hashing and Proof of Work compares to a game of Sudoku. One aspect of Sudoku we probably all agree on is that it needs time to solve. More importantly, we can also agree on the fact that verification is done in a fraction of the time needed to solve it. The last important aspect of a Sudoku is that its complexity - estimated time required to solve it - can be mathematically determined. These three aspects make it a perfect analogy to the consensus algorithm implemented by Bitcoin.
Tamper-evident
Let's imagine, that instead of hashes, each block is confirmed with a game of Sudoku. The numbers given at the start are based on the content of the block header. The numbers that need to be filled represent the nonce. Hashing alone would mean, that the Sudoku which is solved is super easy. It's as if you had a Sudoku where all the numbers but one are given, it wouldn't take a lot of time/work to complete it.
The Bitcoin Blockchain. Hashing imagined as a game of Sudoku. Illustration by
. Hashing alone is like solving a super simple Sudoku, it doesn't require much work.
Since it doesn't require work to solve a simple Sudoku, it can only provide tamper-evidence. Every participant can autonomously verify the whole blockchain and immediately takes notice of any change. The blockchain itself is tamper-evident but not tamper-proof because there's no real work required to apply changes to old blocks and recompute all "Sudokus" along the way.
"As long as there is no proof-of-work behind it, the cost of rewriting a ledger like that is zero." Andreas Antonopoulos - The Internet of Money Vol. 2
The Bitcoin Blockchain. Hashing imagined as a game of Sudoku. Illustration by
. Although no work is required to solve a simple Sudoku, the chain can be verified, making the blockchain tamper-evident.
Tamper-proof
To make it impossible to change old blocks, the Sudoku needs to become harder. With Proof of Work, Bitcoin introduces a certain requirement to the hash of a block: It has to start with a certain amount of zeroes. The resulting hash of a block is altered by modifying the nonce value in the block header. It's still like solving a Sudoku, only that this time, the Soduku became much more difficult. With a Sudoku as hard as this, a block isn't just created within seconds, it requires significant computational power. In other words, there's mathematical proof that the creation of this block required real work, thus calling it Proof of Work.
The Bitcoin Blockchain. Hashing imagined as a game of Sudoku. Illustration by
. Instead of solving a simple Sudoku, you're now required to solve a much harder Sudoku. The complexity is mathematically determined and strives for a solution time of 10 minutes considering all competing Sudoku players. In reality, the requirement for a hash consists of a certain amount of leading zeros. The nonce value is used to influence the resulting hash of the block header. The amount of time it takes to find such a hash strives for a solution time (time between blocks) of 10 minutes.
The amount of work needed correlates with the current amount of hashing power available in the Bitcoin network. The difficulty of the hash ("Sudoku") always strives towards a value that results in a 10-minute timespan to find an appropriate hash, considering the total hashing power currently available. The difficulty is adjusted every 2016 blocks, to sustain a block time of 10 minutes and compensate the circumstance of changing hashing power.
A monument of immutability
Immutability is when something cannot be changed. Maybe the internet can be considered as one of the first concepts achieving a considerable level of immutability. Because once something is published on the internet, it stays there forever. Attempts to remove specific content, mostly end in spreading it even further. Bitcoin implementing Proof of Work takes the concept of immutability one step further, by hardening the information utilizing computational power.
"Bitcoin's proof-of-work is a planetary scale, thermodynamically guaranteed, self-evident system of immutability" - Andreas Antonopoulos, The Internet of Money Vol. 2
The unbelievable amount of computational power utilized to solve each "Sudoku" along the way, makes it impossible to change any transaction in the past. Each new block secures every preceding block even further. Due to the amount of provable work required to create a valid hash ("solve the sudoku"), it only takes six successive blocks (6 confirmations) for a block to be considered impossible to change. Six confirmations to become truly immutable. Now imagine what it would take to replace one of the very first blocks. Besides the computational power, the fact that the difficulty adjusts every 2016 blocks adds the component of time. It would be a constant battle of increasing hashing power at the right time to sustain a block time lower than 10 minutes. It is the only way a manipulated chain could eventually surpass the original one and be accepted as the new truth. Never in human history, have we ever achieved this form of immutability, making bitcoins public ledger a real monument of immutability. It cannot be changed and it doesn't decay. Even if we consider technological progress and the ever increasing computational power, the blockchain of Bitcoin can't be rebuilt cheaply. Bitcoin's public ledger is truly immutable, based on the concept of Proof of Work and backed by a pool of unimaginable computational resources. With each block, that monument grows further and sets a new standard, redefining the term immutability.
"Now history is written by the expenditure of real-world energy, and there is no cheap way to forge that history." Andreas Antonopoulos - The Internet of Money Vol. 2
Conclusion
Proof of Work/Mining is far more than just the creation of some Bitcoins and primarily serves the purpose of securing the network. By doing so, people around the world created an incredibly impressive monument of immutability represented by the blockchain of Bitcoin. And it is growing bigger and stronger each day. To me, the result of this collaboration of thousands of miners to achieve true immutability is one of the most impressive aspects of Bitcoin and Cryptocurrencies. Bitcoin's example of immutability achieved through Proof of Work is unprecedented in scale amongst all cryptocurrencies. However, the principles described in this post can be applied to any cryptocurrency implementing Proof of Work as their consensus algorithm. Although there's the legitimate discussion of whether or not the power consumption is justified, I think the sheer existence of such a monument of immutability deserves acknowledgment and respect. Time will tell, how other consensus algorithms will perform once exposed to an adoption similar to Bitcoin. I'm excited to follow the progress of all the different ideas but consider Proof of Work the most proven and robust approach to reach consensus and immutability in existence.
I hope I was able to give you an insight into the fascinating aspects of Proof of Work & Immutability and appreciate any feedback, question or input in the comments below.
Thanks for reading and have a great day!
Sources & Additional Information
- Bitcoin Whitepaper
- Bitcoin.org - Open source P2P money
- Bitcoin Wiki
- Controlled supply - Bitcoin Wiki
- GitHub - bitcoin/bitcoin: Bitcoin Core integration/staging tree
- Bitcoin Block Explorer - Blockchain
- Andreas M. Antonopoulos – The open blockchain expert
- Andreas M. Antonopoulos (@aantonop) | Twitter
- Books – Andreas M. Antonopoulos
- Bitcoin - Wikipedia
- Blockchain - Wikipedia
- Merkle tree - Wikipedia
- OpenSky Sudoku Generator
- Free stock photos · Pexels
- WTF is Money? And why Bitcoin is more than just a currency. — Steemit
- What is Bitcoin? - When Money becomes a content type! — Steemit
- What is Git / Github? - The 3 minute journey through Bitcoins GitHub history — Steemit