Consensus Algorithm
Dinesh Ravishankar
Blockchain dev @Donatuz | Solidity | Ethereum | solutionist | AU student | SKCET'24
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,
?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
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.