Blockchain Consensus Mechanism
A Beginner’s Guide to Understanding the Proof of Work and Proof of Stake
Introduction
Blockchain transactions are executed without the involvement of a third party. You may ask how it is even possible to trust someone on the internet, even when the transaction data is available publicly. The answer lies in what is called a “consensus mechanism.” You can look at it as a set of rules that govern the blockchain, or a reward-penalty system. Regardless of the school of thought, you’re correct, but how does the blockchain implement these rules? This article answers all of that and more.
What is a blockchain?
It is best that you know how a blockchain works so that you have a mental picture of everything that will be discussed in this article.
A blockchain is a distributed ledger of transactions that is stored on a network of nodes (computers). “Network of nodes” refers to different computers that are interconnected. This interconnection is what creates a network. Since the ledger is stored on different computers, it makes it impossible for a single entity to manipulate or change the data of a transaction. After a transaction is carried out on the blockchain, it is stored as a block. This block contains what is called a "hash,” which is like the digital identification of the transaction. These blocks form a chain; this is how the name blockchain came about. For these blocks to be accepted by every node, they must be confirmed as authentic. The quest to find a generally acceptable way of validating blockchain transactions is what gave rise to the “consensus mechanism.”
What is the consensus mechanism?
A blockchain uses a consensus mechanism to mark a transaction as legitimate and authentic. In essence, it is the rule that the distributed nodes have established for how to validate or verify a transaction. It helps to ensure that the data on the blockchain is consistent. It also helps to establish trust among people who don’t know each other. This helps to maintain the integrity and transparency of the blockchain.
What is the need for a consensus mechanism?
You may still be wondering why we need a consensus in a decentralized system. 🤔 Keep in mind that anyone can view blockchain transactions because they are publicly available. What stops someone from hacking, editing, duplicating, or forging a transaction? To paint a clearer picture. I’ll illustrate with a real-world example. Let’s use three pseudonyms: Jon, Doe, and Cass.
Assuming Jon has a total of 20 BTC in his wallet, he decides to send all of it to Doe. So, how do we ensure that Jon doesn't send the same 20 BTC to Cass? This is called the double-spend problem. Remember that a blockchain is a digital ledger. The account balance for Jon is already stored on different computers. The moment Joe sends the 20 BTC to Doe, the blockchain will also send this information to the different nodes to query Joe's account balance. All of this is done automatically. It is the job of a miner or validator to verify this transaction. A consensus mechanism is used to ensure that everything is in sync. It is used to punish the bad miner or validator and reward the good miner or validator. Just like the saying “where there’s no law, there’s no sin," I hope you get the mental picture now. 😃 Let's go over the two popular consensus mechanisms used by blockchains to verify transactions.
Proof of Work (PoW)
When Satoshi Nakamoto launched the Bitcoin whitepaper in 2008, the consensus mechanism he proposed was proof of work. So, how does it work?
Proof of Work, which is abbreviated as "PoW.” It is a consensus mechanism that requires the participants (nodes) in a network, called miners, to solve some difficult cryptographic (mathematical) tasks. Whoever solves this task will be eligible to add new blocks to the blockchain. This task is solved by a computer or mining machine. The higher the computational power of the machine, the higher the chances of quickly finding the solution.
The first miner to solve the challenge will be selected to add a new block to the blockchain. The miner also receives rewards in the form of newly minted cryptocurrency and transaction fees; this process is known as mining. This ensures the network is secure from malicious actors.
Here's a breakdown:
Once a user initiates a transaction (for example, Jon transfers BTC to Doe) on the blockchain, a copy of the transaction is sent to the distributed networks( mining machines).
These transactions are grouped into a block to form the digital ledger. The miners will then compete to solve a cryptographic challenge associated with the block. The miners will then use their computational power to find a particular value, called “nonce.”
Once this value is merged with the block's data, it then produces a “block hash” that meets certain conditions. This condition is for a number that starts with a certain number of leading zeros. For Bitcoin, the difficulty of the challenge adjusts every ten minutes.
Once a miner has successfully solved the challenge, they’ll notify the other miners.
Other nodes can then confirm the solution by checking if the block hash satisfies the required conditions.
After the other nodes verify the solution, the new block will be added to the blockchain.
The other miners will then accept the block, and a consensus is reached.
The miner who solves the challenge will receive a fixed amount of cryptocurrency as a reward. For Bitcoin, it’s currently 6.25 BTC, although it halves every four years.
Examples of blockchains that use PoW include Bitcoin, Doge, Litecoin, Monero, Nervous Network, etc.
Miners can come together to form a mining pool. This pool helps to increase their computational power and boost their chances of being selected to add a new block. The reward is shared among the participants in the mining pool.
To control the system, you'll need high computational power to solve cryptographic challenges. Also, bad actors will need to control at least 51% of the system to manipulate it; this is known as the 51% attack.
Since other miners will have to also verify a transaction, it makes the process incorruptible. All this is impossible, which makes the blockchain tamper-proof. There are concerns over the PoW mechanism.
The high energy used to power these mining machines is detrimental to the environment. Also, only people who can afford mining machines and high electricity bills can become miners, which doesn't solve the problem of centralization. It was these concerns and more that led to the birth of a new consensus mechanism known as Proof of Stake.
Proof of Stake
Some blockchains have adopted the Proof of Stake consensus mechanism as a way to address the pitfalls of PoW. Peercoin was the first crypto to implement it. Just like PoW, it is a consensus mechanism that is used to confirm the authenticity of a blockchain transaction. But it works differently.
Instead of relying on miners to solve some challenging tasks, the Proof of Stake mechanism relies on validators. Validators are participants in a blockchain who lock up (i.e., stake) a specific amount of cryptocurrency. The lock amount is used as collateral to make them eligible to add new blocks to the blockchain. The specific amount of cryptocurrency to stake depends on the blockchain. For Ethereum, it is 32 ETH. The more cryptocurrency a validator stakes, the higher the chances of being selected to add a new block.
The process of validating blocks is done on a randomized and rotational basis. The blockchain also specifies other criteria or variables.
Here's a breakdown:
A transaction hash is created when a user of a blockchain performs a transaction, such as sending ETH to another user. A validator is selected to add a block that contains the transaction data. You can think of a block as a page on a ledger that contains all the information about a transaction.
Other validators will then verify and confirm the authenticity of the added block. If the chosen validator is shady and tries to authenticate a forged transaction, he’ll be penalized. This penalty is referred to as slashing. The miner will lose some percentage of their staked cryptocurrency.
However, if the transaction is confirmed as authentic by other validators, he’ll receive a reward. The reward can be the transaction fee or a newly minted cryptocurrency. The reward system varies depending on the blockchain.
Examples of blockchains that use PoS include Ethereum, Cardano, Cosmos, BNB, Flow, and more.
The reward penalty of the PoS ensures that validators are cooperative and maintains the transparency of the blockchain. The PoS mechanism has been commended for being energy efficient and reducing the chances of a 51% attack. However, it has also come under criticism. A huge amount is required to become a validator, which makes it centralized. Also, there are scalability issues that have plagued the PoS mechanisms. However, people with small funds can still participate and earn small rewards through mining pools. Additionally, some blockchains are currently adopting the introduction of side chains and layer 2 to address scalability issues.
Conclusion
The blockchain consensus mechanism continues to evolve. There are new consensus mechanisms such as proof of importance, proof of authority, delegated proof of stake, proof of capacity, and so on. Blockchain is amenable to technology. As the sector continues to grow, there will be solutions to counter the emerging problems. Let me know what you think about this article in the comment section.