Bitcoin Fundamentals 3: Proof Of Stake
Hi there. Hope you all are doing well :). We just hit 2800+ subscribers ❤️❤️❤️ Thank you for your support :) Sharing another of my favorite gifs from Seinfeld :)
This blog is the 3rd part of a blog series I wanted to share on understanding Blockchain better. In this blog post, I cover Proof-Of-Stake, an alternative to the Proof-Of-Work consensus algorithm. Before we go any further, let us go through a quick recap.
Part I: Blockchain Fundamentals And Smart Contracts
This blog focuses on two topics: Blockchain and Smart Contracts and is a good starting point for Blockchain.
Part II: Proof-Of-Work: Bitcoin’s Consensus Algorithm
This blog focuses on the Proof-Of-Work, the consensus algorithm used by Bitcoin Blockchain.
Introduction
In the previous blog posts, we discussed the fundamentals of blockchain and Proof-Of-Work which was first used by Satoshi Nakamoto and is widely used on the Bitcoin blockchain. For the scope of this blog post, I wanted to focus on another consensus algorithm — Proof-Of-Stake. The fundamental difference between Proof-Of-Work and Proof-Of-Stake is that Proof-Of-Stake works by selecting validators in proportion to their quantity of holdings in the associated cryptocurrency. The underlying thesis behind this difference is that validators with a more significant hold on the associated cryptocurrency are more trustworthy than others. This is done to avoid the computational cost of proof of work schemes. The first functioning use of PoS for cryptocurrency was Peercoin in 2012.
Quick Recap On Consensus
A blockchain is a distributed ledger and self-governing system. There isn’t a central system that maintains the truth value for the system. Contributions come from hundreds of thousands of users that make it function properly. For blocks to be added to the blockchain, a valid cryptographic hash must be added. A quorum of validators must validate the cryptographic hash.
Drawbacks of Proof-Of-Work Consensus Scheme
Let us first recap the drawbacks of the proof-of-work scheme and understand why alternative schemes have been proposed for it.
Problem #1: High Energy Consumption
The original Bitcoin paper proposes a scheme where each validator has equal weight, leading to high computation costs. According to a research study published in January 2018, the Bitcoin blockchain uses around 54TWh of electricity, enough to power 5M households in the USA or enough to power the entire country of New Zealand or Hungary. Today, the energy consumption stands at around 200TWh of electricity.
Problem #2: Centralization Due To Miner Groups
Another problem with the mining scheme on the Bitcoin blockchain is that miners can combine to form pools. This is done to avoid the high computational costs of solving the cryptographic hash puzzle. The miners then redistribute the prize amongst the different miners in the group in the proportion of the computational energy contributed. However, this leads to the centralization of the Bitcoin blockchain and is susceptible to attacks. In some ways, centralization is the antithesis of the cryptocurrency effort.
Given the set as mentioned earlier of problems, a new technique had to be found.
Enter QuantumMechanic
In 2011, a user called QuantumMechanic proposed a different consensus algorithm. His observation with regards to Proof-Of-Work was as follows:
Observation #1: Each of the miners in the system does the same work since they are competing against each other.
Observation #2: There is a lot of wastage of work.
He proposed that the system could be optimized by designing a system where instead of your "vote" on the accepted transaction history being weighted by the share of computing resources you bring to the network, it's weighted by the number of bitcoins you can prove you own, using your private keys. That sure sounds interesting!
Algorithm Design
In Proof-Of-Stake, there are no miners. Instead, miners are replaced by validators. The validators do not mine. Instead, they forge/mint a new block. This is a difference in terminology on the surface. So, let us not worry about it. A node must deposit a certain amount of coins into the network to become a validator as a stake. You can understand this as a security deposit. The size of the security deposit determines the chance of a validator being chosen to forge the next block. It is a linear correlation. So, let us assume that Bob deposits $10 into the network and Alice deposits $100 into the network as a stake. Alice's chances of being a validator will be ten times higher. One can argue that this scheme favors the rich. However, that is not the case. With the Proof-Of-Work consensus algorithm, the rich can buy a higher computational power set and solve the cryptographic hash problem quicker. The cost of electricity tapers off non-linearly due to economies of scale. The price paid for mining equipment remains constant, and therefore, electricity per KWH decreases as you increase the required output. Now back to the work that the validators end up doing. A validator will validate a newly minted block and all its associated transactions. They get the associated gas fee for the computational cost incurred.
How is security guaranteed?
If a validator approves a fraudulent transaction, the validator loses a fraction of its stake. As long as the stake is higher than the transaction fee, we can trust them to do their job correctly because the losses incurred would eventually bankrupt a fraudulent validator. In short, it is a financial motivator (a constraint to say so) and ensures that the validator remains honest.
If a node stops being a validator, the stake will be released back to the node after a certain period.
Key Takeaways
In this section, let us discuss the key takeaways from the blog post. Firstly, let us look at the Proof-Of-Work and Proof-Of-Stake algorithms.
Proof-Of-Work expends a large amount of wasted energy because every node participates in the mining process. Proof-Of-Work selects only a single node to be a validator. This ensures that energy is not wasted unnecessarily.
Proof-Of-Work also allows for Mining Pools, and this leads to centralization, and possibly the network could be compromised. The image below shows the share of Mining Pools on the Bitcoin blockchain (reference). If the top 3 mining pools came together, they could take over the entire blockchain.
The 51% attack
If a node buys a 51% stake (i.e., a majority stake) in the network, the node can effectively control the blockchain. This is a significant shortcoming of the Proof-Of-Work consensus algorithm. On the other hand, Proof-Of-Stak makes this attack hard since the value of the cryptocurrency may be high. So, for example, the market cap of the Bitcoin network is $790 Billion. A 51% stake nearly equals USD 403 Billion. This is because Proof-Of-Stake does not allow groups to mine together.
Risks With Proof-Of-Stake
The Proof-Of-Stake algorithm has its own set of problems. This section discusses the issues with the algorithms and the possible solutions around them.
Problem #1: Favors The Rich
The Proof-Of-Stake algorithm may end up favoring the rich as the probability of selecting the validator is proportional to the size of the stake. It then becomes a self-fulfilling prophecy where the richer start to get richer as they get the opportunity to validate more and get paid more. One of the techniques used to combat this effect is called Coin Aging.
Coin Aging
To distinguish between users who have just obtained their coins and users who have been holding their coins for some time, proof-of-stake algorithms use the idea of coinage.
A coin’s age is used to calculate both stake weight and staking reward. The coin's APR sets the staking reward. The effect is a stable, consistent interest for staking wallets, regardless of input size or downtime. The longer a user holds the coins, the chances of winning the right to create a block of the network blockchain and get a reward.
The coin aging mechanism ensures that nodes that have less amount of stake but have aged long enough have a higher probability of getting selected as a validator.
Problem #2: Single Point Of Failure
One of the problems with the Proof-Of-Stake algorithm is that a single validator is chosen to validate the new block. However, this also creates a single point of failure since the system can fail if the validator does not show up. One way to work around this problem is to create backups for the validator. The system can select several back validators. If the primary validator doesn’t respond, the secondary validator can respond and validate the new block.
Key Takeaways:
Proof-Of-Stake is an alternative to Proof-Of-Work that reduces the overall cost of energy requirements.
The key idea is to enable validation by a single node and have them keep a stake on the network chain.
Most of the major blockchains (Bitcoin, Ethereum) are yet to adopt Proof-Of-Stake.
Some of the drawbacks of the algorithm include starvation of poorer validators and single-point-of-failure.
How can you help?
I will need you to do a few things if you are interested in receiving the updates. This is the only way we can grow and will keep me motivated :)
Step-I: Move the Email Notification from “Promotions” To “Inbox”. This way the Gmail Smap notification will not mark this email as spam. Check out the video below.
Step-II: Click on the Bell Icon on LinkedIn, if you want to follow my updates. Here is a quick video on how to do it - only if you find the content useful :)
How Do I Get Access To Your System Design E-Book?
If you wish to get access to my sample e-book, you can download it from this link.
The contents of the book are as follows:
Chapter 1: Fundamentals of System Design.
Chapter 2: Challenges in System Design.
Chapter 3: Designing a scalable Notification System.
Chapter 4: Designing an Auto Complete Engine from scratch.
Chapter 5: Designing a Distributed Cache.
Chapter 6: Designing a system to calculate the topK elements (aka the Heavy Hitters problem).
Chapter 7: Principles Of Microservice Architecture.
I will end this blog post with this quote from Nelson Mandela:
“Education is the most powerful weapon which we can use to change the world.”
Cheers,
Ravi.