Skip to 0 minutes and 12 secondsAs we mentioned before there are two algorithms that can be used to reach consensus in public blockchains. Proof of Work and Proof of Stake. In this lesson we will go into detail on how both of the algorithms works and analyze the advantages and disadvantages of each of them. As obvious as it may sound, the objective of a consensus algorithm is to reach consensus. If we had the certainty that everybody in a system is and will always be honest, that would be an easy task. But what happens if there is a high amount of malicious participants? It gets tricky.
Skip to 0 minutes and 54 secondsThe maximum percentage of dishonest participants that the algorithm can handle while still finding the true version of the ledger is called Byzantine fault tolerance. The higher the tolerance is, the system can handle a higher number of dishonest behaviors.
Skip to 1 minute and 12 secondsAlso, the algorithm has to carry low operational costs compared to the gains obtained at reaching consensus. We can’t spend more money in protecting the transactions than we gain from enabling them!
Skip to 1 minute and 26 secondsThe algorithm also needs a mechanism to discourage certain parties to cluster inside the system and gain power over other users. And finally, the algorithm needs to disincentivize malicious behaviors by making them very expensive to carry out. If it meets these criteria, we have found of a suitable consensus mechanism.
Skip to 1 minute and 50 secondsNow let’s dig into the technicalities of the two most popular mechanisms. Proof of Work and Proof of Stake.
Skip to 1 minute and 58 secondsPreviously, we learnt that voting rights for consensus mechanisms are assigned based on the ownership of scarce resources. For proof of work, that resource was computational power. Massive amounts of computational power are required in order to validate and store one set of transactions in the blockchain.
Skip to 2 minutes and 19 secondsThe process works as follows: The transactions taking place in the network get broadcasted to the miners. The miners collect multiple transactions and put them together in a group that receives the name “block”. In order to successfully store the data, the miners need to find the correct hash for each block. A hash is a mathematical function that maps data of arbitrary size to a short string of numbers and letters. A hash functions has the property that it's infeasible to invert. You cannot guess the input by seeing the output. The miner need to find a specific hash. A hash is accepted as the correct one when it starts with a minimum number of 0s. Now here is where the work starts.
Skip to 3 minutes and 8 secondsThe hash of a block will completely change every time a miner modifies in the slightest the data in the block. However, this is precisely what the miners need to do in order to obtain the correct hash. Thus, the miners proceed to add small packages of data, which receive the name Nonce. Nonces are 32 bit numbers, and it is impossible to predict which combination of bits will result in the right hash. Many different nonce values are tried, and the hash is recomputed for each value until a hash containing the required number of zero bits at the beginning of the string is found.
Skip to 3 minutes and 48 secondsAs this iterative calculation requires time and resources, the finding of the block with the correct nonce value constitutes a proof of work. To succeed, miners do not have to find some predefined hash, but the hash must start with a certain amount of 0s. The difficulty for mining can be adjusted by setting the minimum amount of 0s.
Skip to 4 minutes and 15 secondsCurrently, there is so much competition that the system needs to adjust the difficulty to pace the cadency of block creation. The probability for a single miner to successfully obtain the hash and mine a block is incredibly low, so miners tend to associate with other miners in associations called mining pools. When one of the miners succeeds, the reward is then distributed between all the members of the mining pool. The reward for the successful miners is, in the case of Bitcoin, 12.5 newly generated Bitcoin and the sum of all the transactions fees that users paid for the transactions stored in that block.
Skip to 4 minutes and 54 secondsTo balance the economy, the amount of Bitcoin rewarded is getting lowered over time and a day will come where only the transaction fees will work as a reward.
Skip to 5 minutes and 6 secondsDifferent mining pools compete against each other in mining each block. Bigger mining pools have higher probabilities of succeeding, as they have more computational power. However, the fraction of reward that each member will obtain will also be considerably lower.
Skip to 5 minutes and 25 secondsProof of work has successfully powered Bitcoin’s blockchain since 2009. So what’s the need for Proof of Stake? Well, proof of work has some weak points. First of all, Proof of Work requires a huge amount of energy. Very specific hardware is used to carry out all the hash iterations, and the sum of all the devices represents a 0,08% of all global energy consumption. It's estimated that both Bitcoin and Ethereum burn over $1 million dollar worth of electricity and hardware costs per day as part of their consensus mechanism. That is a lot of energy. Proof of Stake its an experimental concept that aims to provide an equally safe consensus mechanism while addressing these flaws.
Skip to 6 minutes and 17 secondsThere are currently few blockchains working with proof of stake, but many big players like Ethereum are planning to adopt it in the near future. But how does Proof of Stake really work? Remember Alice and Chuck? They built a strong Proof of Work chain, but now they want to explore a Proof of Stake based consensus. In a chain-based proof of stake, one user is pseudo-randomly selected as validator for each block. The probability of one participant getting selected to be the validator depends directly on the amount of coins he possesses. The bigger the amount possessed, the higher the probability. In other words, the algorithm selects those with more funds at stake.
Skip to 7 minutes and 5 secondsLet's say that Alice got randomly selected as validator and thus she gets the right to attach a new block to the chain. Alice votes for the chain which she thinks is correct, and she does it by attaching her block to it. In a chain-based proof of stake, the main and true chain is selected according to the “longest chain rule”. Let's say that a fork has taken place and the main chain is split in two, chain A and chain B. Alice sees that some Blocks in chain B are not valid and attaches her block to chain A. As in proof of work, the system will reward her honest behavior with newly generated coins.
Skip to 7 minutes and 53 secondsFor the next block, Chuck is selected as validator. By now, we know Chuck will never give up on his attempts of cheating, so he simply attaches his block to both chains, aiming to get rewarded twice. With Proof of Work he would have needed twice the mining power, but now nothing can stop him! Well Chuck should have done his homework! The system can be designed to punish every validator publishing blocks in more than one chain and those who publish it in chains that are later on discontinued by other validators! We just learnt about the different ways of reaching consensus in blockchains. But does that apply to every existent Blockchain? Stay with us to discover other types of chains.
Blockchain differentiates between legit and fake transactions without a centralised authority. Watch this video to learn about the different consensus models (Proof-of-Work and Proof-of-Stake), how exactly are the blocks connected in a blockchain, what is Merkle Tree and how transactions are confirmed.
A lesson from Alexander Kaiser, Blockchain Developer at BlockInfinity
© EIT InnoEnergy