Introduction to Consensus
The consensus is a mechanism of providing the verification to the data uploaded in the blockchain by reaching a decision among the majority of the participants and adding the block to the blockchain once the consensus has been reached. Whenever the users join a blockchain, they need to agree on the initial state of the blockchain. Every block added after the genesis block needs to be validated through a consensus mechanism and added in the blockchain. Hence, the users can give validation to every block which will be added to the blockchain after they become an active node. The initial state integrated with the verification of the subsequent blocks can help the user to agree on the current state of the blockchain.
Types of Consensus Mechanisms in Blockchain
There are various types of consensus mechanisms that exist currently. They are the following:
Proof of work
In Proof of Work, the miners have to solve a cryptographic puzzle. This puzzle is difficult to solve but easy to verify. The first person to find the solution broadcasts it on the network and other nodes verify it after which the miner receives a reward. For the block to be valid, the output needs to start with a certain number of zeros at the beginning of the hash value. This depends on something known as ‘The Difficulty’. The computing power of the network changes the output. Bitcoin networks adjust the difficulty and that helps slow down the creation of new blocks. In Bitcoin, it takes 10 minutes to calculate the Proof of Work and add a new block to the chain. In order to produce the hash value with the desired amount of zeros, in the beginning, the miners add a ‘Nonce’ into the block number. Nonce stands for ‘Number Only Used Once’. It is the first number needed for solving a block of the blockchain. This is the number that the miners are searching for in order to solve the block. The probability of the miner being chosen to update the next block is determined by the computing power a miner controls. For example, if a miner controls 20% of the network power, the probability of him winning is 20%. The more computing power, the more the chances of obtaining a new Bitcoin.
Proof of Stake (PoS)
Proof of Stake or PoS is the most common alternative consensus mechanism to PoW and overcomes the disadvantage of the requirement of high computational energy in the PoW mechanism. The mining mechanism is completely replaced with a different approach of providing the opportunity to create the block in the blockchain, based on the stake the user holds in the blockchain system. This stake is usually defined based on the ownership of the digital currency operating in the blockchain. Although the choice of selection of block creator is random, it is proportional to the percent of ownership of the stake in comparison to the stake of the system. For example, if A has 20% of the stake, B has 31%, C has 18%, D has 9%, and E has 22%, and there are 100 blocks to create, A will create 20 blocks, B – 31, C – 18, D – 9, and E – 22. The order of the opportunity provided to them to generate the 1st to 100th block will be entirely random. Although the mechanism is less secure than PoW, the energy consumed to provide consensus is assuredly very low. Coin’s age, user’s age in the system are few of the other metrics used to measure the stake in the system.
Proof of Activity (PoA)
Proof of activity is a hybrid approach of Proof of Work and Proof of Stake. In this the mining process starts with a standard PoW with various miners trying to win the competition to find the new block. When the new block is mined, the block contains only the block header and the miner’s reward address, and the system switches to PoS. Based on the header, a new group of validators are selected from the blockchain network randomly. This time, the validators are chosen based on the stake they own similar to PoS. The same process is followed every time a block is mined.
Proof of Elapsed Time (PoET)
This mechanism is used by IntelLedger, an open-source blockchain platform developed by Intel. The process is similar to PoW but consumes lesser electricity. The process’s algorithm uses a Trusted Execution Environment (TEE) like Intel’s Software Guard Extensions (SGX) to generate a random leader (generally based on a lottery) who will generate the block and the protocol itself selects the next leader who will be appointed to build the next block. The way it is similar to PoW is that validators run the TEE using their Intel SGX and each validator requests wait time from the code running in TEE. The validator with the shortest wait time wins the lottery, becomes the leader, and upon his block creation also generates a proof of his block creation. The other validators can verify the block creation with the help of the proof. The wait times are generated randomly and this ensures the randomness of the distribution of the lead roles to the validators. One of the disadvantage to this approach is to rely solely on Intel for the specialized hardware.
Proof of Capacity (PoC)
Proof of Capacity also known as Proof of Space works similarly to PoW with a slight distinction. Instead of repeated computations on each block to solve the puzzle, this mechanism makes use of hard drives (memory space) to store the past solutions. The quickest miner to solve the most recent block puzzle wins to mine the block. These stored solutions are called as plots (which contain nonces), and clearly more the plots are saved in your hard drive, better is the probability to have the best solution to the puzzle. Proof of Capacity is an eco-friendly and energy-efficient alternative to Proof of Work.
Round Robin Consensus
This system requires a certain level of trust to exist between the mining nodes. In this process, the nodes take turns to create the blocks, and in case the block is absent during its turn, the opportunity is given to any random node This process is generally used in the Private Blockchains.
*DAG is not a consensus on a blockchain. It is used to draw comparisons with other consensus algorithms