Consensus algorithms
A consensus is a way of coming to an agreement. The blockchain is not decentralized by default. Its main agenda is in organizing data. The blockchain achieves this by storing every single change and arranging this data in a chain of blocks. What makes the blockchain decentralized, therefore, are the consensus algorithms used on the networks. A decentralized system will fall apart if it does not have a common consensus algorithm. Participants in a decentralized system do not need to trust each other; they just need to agree on common functioning principles. This is what consensus algorithms or mechanisms are used for in a blockchain.
Different blockchains use different consensus algorithms. There is none that is considered universal, good or bad. The blockchain is in its early days and therefore a lot of research is underway to provide the best consensus algorithms for the different blockchains. So far, a lot have been developed and are in use on the blockchains.
Proof of work
This is the mechanism used on the Bitcoin blockchain. In order for miners to participate in validation of transactions on this blockchain, they need to prove that they performed a certain task. The more work a miner has done, the bigger their chance to propose the next block and obtain a reward in form of fees. This prevents the blockchain from being attacked by fake votes.
In PoW, miners compete to add the next block in the chain. They race to solve difficult cryptographic puzzles and hence the first to solve these puzzles wins. In addition to the transaction fee the miner gets, they are also rewarded with 12.5 newly minted Bitcoins.
The answer to the mathematical equation in the proof of work mechanism is known as a hash. The cryptographic or mathematical puzzles include;
- Hash function
This is how to find an input while knowing the output.
- Integer factorization
This is how to present a number as a multiplication of two other numbers.
- Guided tour puzzle protocol
If the servers suspect a DoS attack on the network, hash functions need to be calculated for nodes in a defined order. In such a case of attack, the guided tour puzzle protocol is how to find the chain of hash function values problem.
The complexity of these puzzles depends on the number of users, network load and power. The hash of a block contains the hash of the previous block hence security and prevention of block violation.
In addition, the PoW consensus algorithms have the benefit of;
1. Defense against a DoS attack
This algorithm imposes certain limits on actions in a network. Therefore, attacks on the network need a lot of effort, time for calculations and a lot of computational power to be executed. Although such an attack is possible, it is useless because of the high costs.
2. Mining possibilities
Miners with a lot of coins in their wallets are not in charge of decisions on the networks. What matters in a PoW algorithm is computational power to solve the cryptographic puzzles.
There are however challenges that face this consensus algorithm. Transactions on the Bitcoin blockchain are very slow because the confirmations take a lot of time. Also, using this algorithm consumes a lot of computational energy which could be very expensive for miners as well as bad for the environment.
Other blockchains that use this algorithm apart from Bitcoin is Litecoin and Ethereum.
Proof of Stake
Proof of stake (PoS) is one of the most common consensus algorithms in blockchain. It is a way of validating transactions to achieve a distributed consensus. PoS is almost similar to PoW but the process used to reach the end goal is different.
This idea was suggested first on BitcoinTalk in 2011 and was first used on Peercoin in 2012. Other blockchains to first use this algorithm were Qora, ShadowCash, Nxt, BlackCoin, NavCoin and Nubits/NuShares.
Consensus algorithms have different ways of rewarding miners. In PoS, the creator of a new block is chosen in a deterministic way depending on their wealth or stake. This means that the user or miner has to show the ownership of a certain number of units of coins.
Creators of new blocks in PoS consensus algorithms are chosen through a pseudo-random way. Blocks are not mined but minted or forged. Blockchains that use the PoS algorithm creates their digital currencies at the launch hence the number is fixed. Forgers (miners) are not rewarded with crypto rewards but in transaction fees only.
Forgers in this consensus method have to first put their own coins as stake before they can create blocks. There are different methods selected to choose the forger to create the next block. Without these methods, there would be bias since forgers with a lot of funds would always be chosen over others with fewer cryptocurrencies. The most popular of these are randomized block selection and coin age-based selection.
- Randomized block selection
In this method, a forger is selected through a formula that looks for a combination of lowest hash value and stake size. The size of the stakes for all the forgers is public and nodes in the network can predict which user will be selected to forge the next block. Blackcoin and Nxt are some cryptocurrencies that use this block selection method.
- Coin age-based selection
This method selects the forger depending on the ‘coin age’ of their stake. This ‘coin age’ is calculated by multiplying the number of days the coins have been held as stake by the number of coins being staked. A forger should hold coins for a minimum of 30 days before he can use them to compete for block creation. Consequently, forgers who have staked older and larger amount of coins stand a better chance to be selected to forge the next block.
Once a user has been selected to forger the next block, the age of their coins is reset to zero hence, they have to wait another 30 days before they can stake and forge another block. A user has only 90 days to forge the next block. Users with very old and large stakes cannot dominate the network hence it is more secure from attack and centralization.
Peercoin uses both ‘coin age’ and randomized selection processes for their forgers. According to the developers of this blockchain, it makes it more difficult for malicious attacks on the network. Proof of stake has more benefits as compared to proof of work because less electrical and hardware costs are associated with the algorithm.