Consensus using proof of work
The blockchain is a distributed system and therefore, it needs a consensus mechanism to establish a single truth for the network. A consensus mechanism is an algorithm to be followed by all participants in order to agree on the protocol rules.
Bitcoin introduced a consensus mechanism based on the idea of proof of work. Let’s see how it works. Since all network participants want the right to include the next block in the blockchain and be rewarded, they must prove that they are performing computational work. For this, they need to find a certain number that, when included in the header of the proposed block, can generate a hash whose value is less than a particular established number, what is called a “target.” In this context, the number that needs to be discovered is known as a “nonce.”
There is no way to find this number other than by trial and error. The protocol alters the difficulty of the task so that this number can only be found, on average, every certain number of minutes. In Bitcoin, the protocol tries to keep this average at 10 minutes. Before migrating to proof-of-stake, the block time in the Ethereum network was around 12 seconds. Once a node finds the nonce, it can propagate the information to other peers indicating that such a block should be added to their copies of the ledger.
Proof-of-work is a mechanism to add new blocks, but it is insufficient for network cohesion. As this is a decentralized network, due to latency and other factors, two nodes can encounter a nonce simultaneously. This causes a temporary network fork, where two equally valid blockchains are propagated. When a node is given two possible blockchains, it must decide which one to follow. This issue is also part of the consensus mechanism.
A straightforward choice would be to follow the chain with the most blocks. Bitcoin’s protocol dictates something similar; instead of following the chain with more blocks, the node should follow the chain whose difficulty in finding the blocks is the greatest. Ethereum made a slightly different choice. Instead of considering only the chain of blocks, it is also necessary to consider eventual blocks that were not included in the chain but whose nonce was valid. Such blocks are called orphaned blocks.
Proof-of-work-based consensus mechanisms are secure and have been battle-tested over the last few years. However, they waste a considerable amount of resources. All the work to find a nonce is wasted and requires much computational power and electrical energy that could be better utilized elsewhere. Although consensus mechanisms based on proof-of-work have been developed whose work would have some use, in principle, such as discovering new prime numbers or performing complex scientific calculations, such mechanisms are challenging to implement.
Using proof-of-work in the consensus mechanism was a great idea by Satoshi Nakamoto, but it is possible to establish consensus in the blockchain without harming the environment. Let’s look at other possibilities for consensus mechanisms.