Ready to get a bit TECHNICAL? Alrightyyy!!
We have mentioned consensus algorithms before in previous articles. But ignored its explanation each time :p But not today. In this article we are going to get a deep understanding of consensus and discuss its types and properties. So sit back!!
Consensus forms the backbone of the Blockchain network. It is a protocol that each and every peer participating in the network has to abide by. The network expands world wide. Ensuring proper functioning and regulation of assets is a major concern while handling millions of nodes around the globe. Therefore a predefined algorithm is required to automate this decision making process, which is resistant to any kind of violation. This algorithm is defined at the core architecture of the Blockchain.
The main purpose of the consensus protocol is to make the decision of choosing the miner of the next valid block. Over the years, many Blockchains have defined different consensus protocols depending on their needs and problem solving aspects. The very first algorithm, Proof of Work (PoW), was developed by Satoshi Nakamoto, the anonymous creator of Bitcoin. Later, Ethereum adopted the Proof of Stake (PoS) protocol. Since then many other consensus algorithms have been adopted, for example, Proof of Space (PoSpace), Proof of Elapsed Time (PoET), and many more.
In this article, we will focus upon PoW and PoS, for these are the most popular consensus algorithms. Lets discuss these two in detail...
Proof of Work (PoW):
This algorithm involves solving a cryptography puzzle that will generate a hash with predefined trailing zeros or the difficulty that we studied in Structure of a Block. The initial difficulty is specified by the Blockchain architect inside the genesis block. It varies according to the mine rate, i.e., number of blocks mined per unit time or theoretically, the time taken to mine a block. The difficulty increases if the mine rate increases and vice versa.
So, in here, what miners have to do is, they put all the elements of the block with some random number (or string) into a hash algorithm and have to generate a hash matching the number of leading zeros as specified by the difficulty of the Block.
The miner have to keep validating the transactions until they find a nonce that will produce the required hash value. Due to avalanche effect, miner may also have to change the transactions from the mempool. This requires a lot of computational power. Bitcoin mining is done using large hardware devices. Also the timestamps effect the hash value greatly. For instance, lets suppose a miner is trying to mine a block created at timeStamp "now". He tries with some nonce values and a second passes. Now, since the timeStamp is changed the whole hash value changes and miner has to test all over again with the previous nonce values. Therefore, it has to be a speedy process which requires a lot of computational power and doesn't prove to be environment friendly. This also makes mining a slow process. Currently, Bitcoin transaction rate is quite low than traditional Visa payment method.
However, now Blockchain have adopted other consensus algorithms to solve this problem, for example, the Proof of Stake (PoS), which we are going to study about next.
Proof of Stake (PoS):
To solve the above problem, Ethereum decided to shift to Proof of Stake consensus protocol. In this consensus, peers who want to contribute to the Blockchain, put some percent of their crypto as a stake. The node with maximum stake is elected to mine the next block. If he creates a valid block, he gets his staked money back with the total fee as a reward.
However, if someone tries to create a malicious block, he will lose his stake to the network. This way the network resists any spiteful behavior and ensures the integrity of the participating peers.
There are some disadvantages of this protocol.
In Proof of Work, if a miner owns 51% of the computational power of the network, he is capable of attacking the network. However in PoS, an attacker needs 50% of the currency to gain control.
An attacker can bribe a miner to confirm the transactions after reversing some of the victim's. This is known as bribe attack.
Solutions to the above problems are being revised actively by adopting several other protocols. In every consensus, the main concern of making the network resistant to attacks has been focused upon. These algorithms help the network grow and ensures a trustless yet reliable platform for peers to participate.
Next, lets look at some problems that Blockchain solves and the issues that Blockchain faces.
Till then STAY TUNED and comment any suggestions below.
Bubye ;)
Komentáře