02 Feb Consensus Protocols
In any Blockchain, the greatest challenge is to get all the participants to agree on what has been done so that nobody can break the rules. In order to do so, the consensus protocols are used. In many of these protocols, transactions are added to the network by dividing them in blocks, checking if they are correct, and “mining” them.
Since anyone can be a miner in public networks, in order to minimise the possible attacks (soft forks, trying to build a longer chain…) it is necessary to introduce a limitation which gives miners the obligation to prove (“Proof-of”) that they have spent something, so their block is taken into account.
Most common types of consensus protocols
The proof of work is the best-known way to prove that a node meets the requirements to add a transaction block to a blockchain, i.e., “to mine” (look for) a hash which proves that it took approximately 10 minutes (in the case of the bitcoin) to process this block. This is what the bitcoin network does (it was the first one), and also what most of the public networks that have adopted a similar protocol do.
It is necessary to do this, since any person in the world can connect to the network and publish blocks. In addition to this, the number of validators is potentially infinite and, thus, we cannot easily establish a system in order to know if there is a majority of nodes which want to add a block. However, the biggest problem proof of work pose is that their energy usage is extremely high (https://www.extremetech.com/extreme/259882-bitcoin-mining-now-uses-power-159-countries), and, thus, new alternatives are being developed. The most popular alternative, and the one we will be focusing on, is the proof of stake, since it is also perfect for private networks.
Proof of Work
This type of proof entails solving a hash which consists of the transaction data and a random number. The miner has to keep changing this random number until its hash code is lower than a defined value (in other words, a value that begins with a specific number of 0s). It guarantees that it will take an average of X minutes/seconds to find the solution to the problem, and it also evolves with hardware. This means that the processing difficulty/time is easily controlled by lowering the valid set of values, which allows the network to self-regulate according to the hardware evolution in an easy and autonomous way. For example: if instead of finding a result lower than 1000 the network is forced to find a result lower than 100, it will take 10 times longer to find a solution.
This solution is used in almost all public networks, bitcoin, Ethereum… since, although its energy cost is high, mining is still profitable in those countries where power is cheaper (such as China).
Proof of Stake
This type of proof is more complex to implement, but it also has many advantages over the proof of work, since it does not use energy. Instead of proving that we have solved an algorithm (a task which uses a great amount of energy), this proof is based on proving that we are one of the assigned validators (if validators are previously known), or it is based on betting any item which, in the event it is lost due to the illegality of the transaction, it can be used to dissuade miners/validators from signing invalid transactions.
In private networks (usually between companies) this is a simple case in which the assigned validators are previously known. In this case, the objective of the miners/validators is to maintain a customer service (the client will pay for this service by way of commissions, bills…), since it is not necessary that they get rewards. The proof of stake is used in different technologies (Hyperledger Fabric, Monax…) targeted at Enterprise networks. In addition to this, since these networks do not have as many actors as a public network, the confirmation time of a transaction can also be reduced to periods of time which are shorter than a second.
Public networks (Ethereum is nowadays the pioneer among the largest public networks) are beginning to implement this type of proofs. However, this task is not so easy in this type of networks since they are public and we cannot know the number of validators, and we do not have a small number of actors. For Ethereum, in its CASPER algorithm (which is included in the metropolis hard-fork), validators are going to bet a part of their Ether (money) instead of solving an algorithm (proof of work) as they used to do before. This Ether will be returned to them when the block is correctly added to the blockchain. Thus, if someone tries to introduce invalid blocks, this person will lose Ether.
Many people argue that this type of algorithms in public networks benefits the fact that rich people control the network (since they can bet more money). However, since mining is nowadays highly “professionalised”, the reality is that in order to mine in an effective way a great amount of money is required.
In addition to the aforementioned, which are the best-known ones, other proofs have been suggested, although they were not very successful. This is the case of the “Time-lapse proof”, a proof which is based on an Intel proposal of including a hardware system in its CPUs which can cryptographically guarantee that the CPU has spent a specific amount of time “waiting”. This offers the same advantages as Proof of work, and, if it is not proven to be vulnerable, it does not use an excessive amount of energy.