What is Consensus
We know that blockchain is a distributed ledger, so let’s say we have 4 mining nodes here. So, all these nodes will have a copy of a blockchain, all these copies will be of same state, so they are exact copies here. If we got a new block to add and it should be added to blockchain. Let’s say that node 4 is adding the block to its blockchain and it’s replicated in all nodes. Now what if node 4 is malicious. How will we make sure that all the nodes follow the same protocol and have the same copy of information?
That’s where consensus algorithm comes to play. In the modern world we have lot of consensus algorithm using which we ensure that all the nodes have the same state of information.
Consensus Mechanism
Based on it is permission less or permissioned blockchain, we have a lot of mechanism. The first one is Proof of Work (PoW) which is one of the famous algorithm and Bitcoin uses the PoW to achieve consensus. All of these nodes will utilise some computational power, and the node with the most computing power will solve the problem and adds a block to the blockchain.
Proof of Work (PoW)
As we saw above whoever adds the block to the blockchain to undergo some mathematical puzzle, where it undergoes inverse hashing technique to solve. The node which solves these puzzles using high computational power will receive some reward.
Why do we need PoW?
If you are using high computational power, the chances of being a malicious node is reduced.
Now if we have 30 blocks and if the malicious node wants to change the 25 blocks. It will affect the hash of all remaining block and we start to recalculate the hash of remaining blocks; it will take some time since each and every block has to under go proof of work and also it consumes some computing power. At the time of doing all these processes, some other node will add a new block. All these works will be in veins.
What is the mathematical puzzle?
The complexity of the puzzle depends on,
- Network size
- Active users
- Blockchain size and many other factors
The puzzle will be of mathematical calculation like, given a three-digit numbers and find the factors of that number and it also has some more logics. Now this problem may be easy one but the real-world problem will be a difficult one and it take some time to calculate.
There is a famous hashing algorithm called sha256 algorithm which gives a hexadecimal number for each and every input and if you change even a single letter in the input, the whole hexadecimal number will change. So we have regenerate every time to get the correct input.
So, if we have the hexadecimal code and if we want to find the information, that’s where we will be doing a lot of calculations.
DRAWBACKS
- Loss of computational power, because many nodes will participate in solving mathematical puzzle, but only one node gets the reward.
- 51 percent attack – if blockchain node have 100 nodes and 51 nodes are malicious, then more than 50 percent of the network is corrupted.
Proof of Stake(PoS)
To overcome the drawbacks of PoW, PoS was introduced. In order to participate in Pos, the validators has to produce some stake. In Pow, the block is mined by the node which has the high computational power. But in PoS the validators are selected in terms of some selection algorithm and the amount of stake they hold and only then that validator will be allowed to add the block and the other validators need not waste any computational power since they are not selected. If the validator founds to be malicious, then they will lose their stake.
DIFFERENCE BETWEEN PoW AND PoS
PROOF OF WORK(PoW) |
PROOF OF STAKE(PoS) |
A proof of work is a piece of data which is difficult to produce but easy for others to verify and which satisfies certain requirements |
Proof of stake is a proposed alternative to proof of work.
With proof of stake, the resource that’s compared is the amount of bitcoin a miner holds. |
The probability of mining a block is dependent on how much work is done by the miner. |
Person can mine depending on how many stack they hold |
Pay-outs become smaller and smaller for bitcoin miners. There is less incentive to avoid a 51% attack. |
The PoS system makes any 51% attack more expensive. |
Proof of work high computing power hardware which is expensive |
Proof of stake no need of expensive hardware. |
Proof of work requires more electric power |
Proof of stake is energy efficient. |