This series covers some of the popular methods of consensus being used in current public blockchain networks.
Before diving deep into the stream. To make things more clear, let’s understand which type of consensus protocol can be used in case of public blockchain networks.
In the case of permissioned blockchain, actual message passing (gossiping) takes place between the participating nodes. So nodes are known to each other in such networks.
Contrary to this, in public blockchain networks, any node can join or leave the network anytime. So nodes are anonymous to each other and to reach a decision, leader election will always take place in reaching the consensus.
The leader will decide what will be the next block and other nodes can easily validate the new proposed block.
At the end of the article, if you feel confident to explain the term to others, then don’t forget to leave claps behind.
Proof of Work(PoW)
This consensus algorithm is quite popular and used in many blockchain networks like Bitcoin and Ethereum.
To understand PoW in a better way, let’s discuss a few more terms:
Mining: It is the term given to the event of adding a new block of transactions to the blockchain. In public blockchains, a leader is elected who will decide what will be the next block. The elected leader is called “Miner” and the process of adding the block is called “Mining”.
Hash: A hash function is any function that can be used to map data of arbitrary size to fixed-size values — Wikipedia
Nonce: A nonce is a random number in cryptography which is used only once. In the context of Blockchain, the miners hash the block data and nonce to reach a target in a brute-force manner.
Let’s know more about Transaction Life-Cycle in Bitcoin Network-
- Each transaction is added to the transaction-pool first.
- From transaction-pool, different participating nodes take input the transactions and compete with each other to mine the next block.
- The node which solves the problem first wins and decides what will be the next block.
So, the first question you might be thinking must be- How does the leader gets elected? Who will decide what will be the next block since different miners who are competing will have different transaction list due to the network delays? Don’t worry, Let’s catch it up together after reading a few more things.
During the consensus process of PoW, the complex mathematical problem selected is such that it is very hard to solve but very easy to verify.
For example- in the case of the Bitcoin Network, the problem is – the generated block hash should have the fixed number of zeroes in the beginning. e.g the target Block-Hash should have 12 zeroes in the beginning.
So in the transaction life-cycle, different miners collect transactions and generate a new block and try to solve the complex mathematical problem. The miner who solves the problem first gets the chance to broadcast his block to the rest of the network, where it can be verified easily.
Moving forward, we are talking about ‘complex’ mathematical problem. So what exactly it is?
Before this, we need to understand how the block hash is actually generated. Let’s see the case of Bitcoin:
As already mentioned, different miners collect transactions from the pool. After that, they generate the Merkle root hash from the list of transactions. This is done by hashing the transactions in a pair-wise manner repetitively.
This ‘Merkle Root Hash’ along with the ‘previous block hash’ and ‘nonce’ constitute the ‘Block Header’ of the block. The ‘Block Header’ is then hashed with few more fields present in the block to generate a unique identifier of the block, called ‘Block Hash’.
Say, the target problem is- to generate the block hash to have initial 4 number of zeroes. Then to solve this problem, each miner will vary the nonce, so that generated block hash meets the target.
Hash(Blockheader[Nonce+Previous Block Hash] + OtherData) = BlockHash
The solution to this problem is complex as it can only be achieved through a brute-force approach by varying the nonce. A huge amount of computational power is spent in finding the right solution which meets the target.
Another amazing point is that, the difficulty of the complex problem(how much initial zeroes), is set according to network demands and transaction throughput of the bitcoin network.
So, now you can imagine just to add a valid block, a huge amount of computation is done. The tamper-proof characteristic of blockchain is somewhat supported by PoW. If someone tries to intrude any transaction data in the block, then its Block Hash becomes invalid and since in blockchain each block holds the hash of the previous block too, so hypothetically we say the chain breaks, and to restore the things the attacker needs to recompute the Block Hash of all the subsequent blocks from the block in which he changed the data till the most recent block, or we can say the attacker has to do the work again. All this will require a huge amount of computational resources which may worth very less than the value of data.
Surfing through the resources to understand PoW in a better way, I came across this amazing demo on Github. Do check this out: https://andersbrownworth.com/blockchain/blockchain
Motivation for Miners:
The only motivation for the miners to participate in Bitcoin mining is rewards. The miner gets reward for proposing a valid block and this reward is in the form of newly generated/mined bitcoins in the network.
That’s it, this is the short explanation of PoW from my side. Keep hustling to understand it till you are not satisfied.
Suggestions to explore stuff related to PoW-
Next in the series are more consensus algorithms explanations. Stay Tuned!!