e click on it and you will be directed to it. This section is again an excerpt of my course on blockchai

– Hey, guys, welcome everybody. I’m Heinrich from Firm Learning from this channel. Thank you for watching. Today is going to cover another topic around the blockchain technology. You maybe have already seen the introductory video that I posted a couple of days ago. If you haven’t, I posted a link here on top, please click on it and you will be directed to it. This section is again an excerpt of my course on blockchai technology that are linked down below into the description. If you would like to learn more about it and get a more holistic view, check out the link. We have roughly 10,000 students signed up in the course. You can read some reviews if you would like to learn more. But anyhow, in the next minutes, you will get just a section of that for you for free. And this section will cover something that is called consensus mechanism, the consensus mechanism. And that is a fundamental piece to understand if you would like to learn more on a more technical level, how blockchains work. It’s really at the core, it’s fundamental building of every blockchain out there. So if you’re interested, hang on. I trust you will learn a lot about that. And let me know in the comments if you have any questions or feedback, I’m very happy to answer it. This lecture is all about distributed consensus. Distributed consensus is a really important topic to learn about, if you want to understand the ins and outs of blockchain. So let’s directly jump into it. And what I would like to start with is to contrast once more centralized systems with decentralized systems like blockchains. A centralized system is a system where every participant in the system is linked with each other by some kind of central instance. An example would be a bank. So think about how you interact with a bank. You can go to a bank as a simple person and open a bank account. You can facilitate transactions through the bank by going to the bank and submitting a transaction and so on. And what’s your characteristic is that the bank is in the middle of everything that happens and can decide whether a transaction is valid or not. If there’s some kind of dispute that one participant says or claims that the transaction that he got was not valid, then the bank steps into it, investigates it and make some kind of resolution to the dispute that was filed. A decentralized system, like bitcoin or any kind of blockchain works differently. There is no such thing as a centralized institution that decides which transactions are valid or not, who is right, how the system is operated, and so on. And this begs a significant number of very important questions that need to be answered when designing a distributed system like a blockchain. One of these questions is who runs the distributed ledger? We already learned that a blockchain is one way of distributing a ledger through large number of individual nodes. But who’s responsible for making sure that the ledger is up to date with all the different nodes out there? The second question would be, who decides which transactions are valid? So now imagine the case of a cryptocurrency. And you submit a transaction to the network in which you claim that somebody else transferred you a significant amount of coins. And especially, if this claim is fraudulent, how does the network make sure that you are caught and that your transaction that you filed gets rejected as invalid? And in the case of crypto currencies, of course, the question that is up in the air is, who can create new coins? And then the last question, how are all these kind of meter level rules decided? Who decides and who can change these rules of the system that determine the answers to these questions that we just formulated. And the answer is consensus. There needs to be something in place called a consensus mechanism that facilitates consensus between the individual nodes and kind of it’s a system of rules that decides who is right and what happens if somebody wants to do something in the network. And something like that is just required to get productive distributed system. Because of course, it will rarely be the case in a very large distributed system, that every single one agrees with something. There will be a dispute and a consensus mechanism is the way to resolve this dispute. There are certain number of different consensus mechanisms out there in the world of blockchain that are used by different types of blockchains. And what I want to do now is I want to kind of give you a glimpse overview, a quick overview or the most important ones and then go into detail in the next lectures. First, on proof of work. And second, of proof of stake, because these two mechanisms are probably the most important and the most relevant ones up to date. But in this overview, now let’s start with proof of work. Proof of work is probably the most widely known consensus mechanism, because it was introduced by bitcoin. And of course, bitcoin is something like the godfather of all block chains and of all cryptocurrencies. And just kind of a disclaimer at the beginning, before we go into these next sections, to really understand these things, you need to get very, very technical, and I will not go into that level of technicality with you. What I want to do with you is give you the intuition that helps you understand how these things work on a more qualitative level, which means that I will need to simplify a number of things, so please forgive me if you already have more knowledge about that, that the things that I’m teaching you now are to a certain degree simplified. So back to proof of work, how does it work? But the basic intuition is that you as a node can opt in to contribute computing power to the network. And by doing that, you have the network to run. And then proof of work means that those nodes that contribute more computing power to the network, have more say in the network. And for instance, in the case of bitcoin, it works the way that if you contribute computing power, then you participate in some kind of puzzle and some kind of cryptographic puzzle that you want to solve. And if you are the one that solves this puzzle, and the more computing power you contribute, the higher your chances are of winning the puzzle. And if you are the one who wins the puzzle, you have the right to propose the next block of transactions to the network. And then the other nodes can verify that and if they believe that your transactions are valid, then the block gets added to the blockchain. And then at some point in the future, the next block gets proposed. So the more computing power you provide, the more say you have in the network. And bitcoin is one popular example using that. Another one would be Litecoin. And there are large number of other coins doing that as well. A bit more modern alternative to that is proof of stake. Instead of using kind of computing power as the decisive factor, the coin holding of the individual nodes are used. So the more coins you hold, kind of the more of a way, the more of a very rich person you are in the network, the more say you have in the network, and the larger your chances of you being the one who can propose the next transactions to the network. And you can imagine this as some kind of lottery system, where you get more tickets, the more coins you have. And the more tickets you have, of course, the higher your chances of winning are and winning means kind of making decisions in the network. And two popular examples are Lisk or Neo, even though I’m aware that for Neo it can be debated whether this is actually an arch type proof of stake or maybe also different, but probably that could go too far if we dive into that right now. A third consensus mechanism introduced by new economic movement, NEM, is proof of information, sorry, proof of importance. And here, the decision to be made, who decides, who makes the decisions in the network are based on the network activity and the reputation within the network. So simply put, the more useful you are to the network, the more say you have, and your level of usefulness is determined by a certain number of factors that then also every blockchain can set for themselves. NEM is the coin that popularized or introduced this proof of work mechanism. And then there are a couple of others like proof of burn, proof of capacity, proof of activity and so on. In each one of them, every one of them has distinctive advantages and disadvantages. And this is also the point that I would like to close this lecture with. To date, there’s no one single consensus mechanism that is generally believed to be the very best one. Every single one has advantages and disadvantages. So coins make different choices. Blockchains can make different choices depending on what is important to them. And probably one step further, probably in the future, new consensus mechanisms will arise which we haven’t been thinking about so far. And then these new consensus mechanisms might be then the gold standard in the future. So the field of consensus mechanisms is a quickly and steadily evolving one kind of fighting for or searching for the very best mechanism that fulfills the need of the individual blockchain applications that you want to build. This lecture focuses on the proof of work consensus mechanism. And before we go into more detail about how proof of work works, let’s first recap why there is a need for something like consensus mechanism. The consensus mechanism fundamentally wants to answer the question, what will be the next valid block of the blockchain? And if you think about it, you have the blockchain. And now there are all kinds of miners and all kinds of open transactions out there, but who decides what the next block is going to be? And of course, there needs to be consensus around this question. Everybody in the network needs to understand and agree on what the next block needs to be. So let’s go into this one level more detail and just understand this issue on a bit more systematic level. So this is a stylized version of the blockchain. So just imagine already some blocks filled with transaction data that has occurred in the past. And now the next level block needs to be selected. And the block is fundamentally nothing else than a collection of transactions that have occurred. So what exactly this means is that if you want to post the transaction to the network, so let’s think about the bitcoin network, you want to send somebody money, you post the transaction to the bitcoin blockchain. And this transaction lands in something that is called, especially in the bitcoin community, a memory pool or short, mempool. So the mempool consists of all the open, unconfirmed transactions posted to the blockchain network. But in order for them now to be validated, they need to be included in the official blockchain and one of the blocks. So now a miner comes, he picks up some transactions which are currently floating around in the mempool and aggregates them into the next block and he now tries to post this next block to the blockchain. So many miners are competing against each other in order to post one block to the blockchain. But of course, only one block can be the next block that actually gets added to it. So how do you decide which miner is the one that gets chosen to publish the next block. And in order for this proof of work comes into play, and kind of to put it shortly, to propose a new block, a miner need to show something that is called Nonce. A Nonce value that together with all other block inputs produces a hash value within a certain valid range. So this is something that is also called a hash puzzle. Different miners compete with each other in order to solve the hash puzzle. And the miner that first solves this hash puzzle is the one that can post the block to the blockchain. To understand this a bit further, so what is the hash puzzle? So just the visualization here, imagine this is the complete range of values that a hash function can take. So remember back at the introductory section where we introduced what hash functions are, hash functions are functions that take whatever input you have, you can put any input into it, and then they give you a certain output for the input value that you inserted. So measuring this range of values to be the complete range of values that the hash function can give you as an output. Then the algorithm defines that only a certain part of that hash function would be considered valid. So this means that often it’s done the way that there’s a threshold, a value threshold, so you need to come up with a hash output that has kind of a number or certain value below a certain threshold that is being defined. Now also, again, think back at the stylized blockchain that we talked about earlier where we saw the different blocks. And we changed the values and saw how the different hash functions concatenated the individual blocks to one blockchain. We saw that there was one value that was called Nonce. And it’s called Nonce, it stands for nonsense, this is barely what it means. So this has no intrinsic value, except for the miners needing to find the Nonce, that together with all the other content of a block that they want to propose, if all this content, including the Nonce is put into a hash function, the output of this hash function fulfills the criterion of validity that is given here, or kind of has a value that is considered valid by the network. And this is basically done by nothing else, the brute force. The miner needs to try lots and lots and lots of different Nonce values in order to come up with the kind of total hash output that is valid. And the smaller the range of valid hash outcomes is, of course, the more difficult it is for the miner to come up or to find the Nonce value that makes the equation valid. So, kind of in a bit more systematic way or technical way, what is the proof of work? Proof of work is a piece of data. So, something like the Nonce or maybe the Nonce combined with the other inputs that then give a hash function output that is costly and time consuming to produce. In order to find that, you will need to brute force try lots and lots and lots of different Nonce values in order to come up with the value that is valid. And it needs to be easy to verify the validity of the value by others. So if a miner now believes that he has found the solution and posts this block with his Nonce value to the blockchain, it needs to be easy for the other nodes in the network to understand that this, yes, this is a valid block. And because it’s valid, it is the next block of the blockchain. So this is how proof of work works, right? All the miners try to solve the hash puzzle of finding the Nonce that together with the other transaction data gives them a valid block. And the very first miner who comes up with such a valid block is then the one who can kind of post his block to the network and then is selected by the others as the next valid block. Now, of course, the question that is in the air is, why would people even do that? Why would people compete in such a way and invest all that computing power, which is quite a significant amount of computing power, in order to solve a block and be chosen as the one who composed this block to the network. And this is due to the introduction of incentives. So pretty much every blockchain system has some kind of an incentive system in order for miners, which are basically the nodes to engage in the system and basically run the system. And now very specifically, especially for the bitcoin network, the rewards are twofold. The first kind of reward is something that is called a block reward. So the miner that is chosen as being the one who can post this block to network gets a reward. And this is quite a significant reward. We’ll later go into the details for bitcoin in a moment. So this is the block reward. The second type of reward is something like a transaction fee. So if you are a user and you post your transaction to the memory pool, to the mempool, which is the pool from which the miners then pick up the transactions and combine them into one block, you need to pay in transaction fee for the miner to pick your transaction. And this works more or less like an open market place. The miner can decide by himself which transactions he want to pick up and combine them in one block and of course, the rational miner will pick up those transactions first, that gives him the highest transaction fees. So as a user, you can set your own transaction fees. And of course, the higher, the faster your transaction will be processed by the network. And we will see in a later lecture of this whole course, how transactions fees evolved over time. Now, let’s dive into some specifics of the bitcoin blockchain because, of course, bitcoin is the most prominent user of proof of work. So bitcoin does run proof of work as in consensus mechanism, and it is set up in a way that the so called block time amounts to 10 minutes. The block time is the time that the network takes between adding a new block. So every 10 minutes on average, a new block is added to the network. The block reward we talked about earlier is 12.5 bitcoins. So the miner who is chosen as the one who kind of solves the hash puzzle and then picks the next block to be added to the blockchain receives 12.5 bitcoin. And this is, of course, a very significant reward. At the time of me recording this video, one bitcoin fluctuates at around $10,000, so 12.5 bitcoin will roughly be $120,000, which is a very significant amount. Another important piece of information that you need to be aware of is that for bitcoin, the block reward halves every 210,000 blocks. And as one block takes about 10 minutes, this is approximately four years. So in the very beginning, the block reward for and finding the next block was 50 bitcoins. And since then, it is halving approximately every four year. This is just one specificity of the bitcoin network. And then another thing to keep in mind on bitcoin is that bitcoin recalibrates the difficulty of the hash puzzle it is presenting to the miners. So of course, the more computing power is introduced by miners to the network, the quicker it would be in order to solve the hash puzzle, because more computers now can in parallel with brute force, try out different Nonce values in order to come up with a valid one. And the more computing power you have, the faster you will be able to solve the puzzle. And for this, this is necessary to recalibrate the difficulty of the hash puzzle if you want to have the stable block time of 10 minutes for every block. And in the bitcoin network, every 2016 blocks, which is approximately 14 days, so two weeks, the bitcoin network recalibrates the block difficulty in order to make sure that the block time always fluctuates around 10 minutes. This lecture focuses on an alternative to proof of work. It is proof of stake, another consensus mechanism that is endorsed by some blockchains to solve the problem that we just discussed earlier. And let’s just remind us what the problem is. The problem is that there needs to be a next block, or a race, there needs to be a next block that is selected to the blockchain network. And there needs to be consensus among all the participating nodes, what the next block is going to be. So how do we achieve consensus about what the next block is going to be? How do we collectively decide on the next block? And why we discussed in detail how that works with proof of work, which is probably the most common and the most popular consensus mechanism at the moment. Another consensus mechanism that is gaining more and more traction is proof of stake. And probably the most popular proponent of it is Ethereum. So while Ethereum is at the moment still ran on proof of work, it is very close to implementing proof of stake in the so called Casper update in the very short feature. So it is a highly relevant consensus mechanism. So, how does it work? And the idea is that we are going away from miners solving something like hash puzzles needing to invest huge amount of computing powers in order to find some kind of hash function output that solves certain requirements. It goes away from that, and focuses more on users investing certain amounts of their coins, so investing some kind of stake that they have in the network, in order to be able to then be the one who has chosen to propose the next block. So in a bit more stylized way, so let’s imagine these guys are miners and they want to become part of the consensus mechanism. So in order to do that, they need to lock up a part of their funds that they have in their network in some kind of a virtual treasure locker. So this means is that they’re locking these funds away and won’t be able to use them for certain amount of time. And what exactly that amount of time is, of course, largely differs by implementation of the individual blockchains. So now people have committed to the consensus mechanism. And now some kind of lottery mechanism comes into play. And the lottery mechanism chooses now one of the miners to be the one who can propose the next block. And it does so to a certain extent randomly, but it takes into account the size of the individual coin holdings that the miners have locked up in order to participate in this consensus mechanism or in this lottery. Another way to think about it is that as a miner, you can kind of contribute or you can buy tickets to the lottery, right? And the more tickets you buy, of course, the higher the chances are for you to win. The more money you pay, the more tickets you get. But of course, even if you have lots and lots of tickets, while as others maybe have only very few tickets, there is no guarantee that in the end, you are the one who actually wins. Though the more tickets you have, the higher your funds, the higher your stake. This is why it’s called proof of stake. The higher your stake, the higher your chances to be the one that is then in the end selected to propose the new block. And I just want to mention the caveat that this is a kind of simplified view of how proof of stake works. Most implementations can have a much more complex, the mechanics involved and it’s also very noteworthy that there are lots and lots of variations, lots and lots of different implementations that are either discussed or already implemented with some coins. So, if you talk about proof of stake, many people mean very different things about that. But I think that this is kind of the common denominator, the basic intuition that you will need to understand in order to understand what this is all about. That being said, why would somebody need proof of stake? So what are the advantages? And one of the key advantages is that it is much more energy efficient. So many people criticize blockchains like bitcoin for the huge energy consumption. At the moment, the whole bitcoin network is allegedly consuming more energy than some small countries. So it is an extreme amount of energy that is consumed and the reason why it consumes so much energy are these miner farms, which just have like the huge amount of computers, huge computer wrecks, which just provide computing power which provide hash power in order to solve the hash puzzles because the more computing power you invest into the network, the higher your chances of solving the next block, and the higher your chances of thereby getting the block reward, which is quite significant as we have seen. So proof of stake doesn’t require computing power, or not at least not even close the amount of computing power that is introduced by proof of work, which is why proof of stake can be a solution to the sustainability problem of blockchains like bitcoin. Another advantage is that, the block reward you need to give out to the miners isn’t that high. So the reason why in the bitcoin network or other networks using proof of work, the block rewards are so high, so significant, is because the miners need to be compensated for the huge amount of computing power and electricity they invest into the network. As the costs of participating in terms of just energy and utility costs aren’t as high in proof of stake, the block rewards don’t need to be as high. And finally, the centralization risk is supposed to not be as high as proof of work. If you control huge mining farms in proof of work, you can control the network. And then this does pose a risk of centralization of the network, which of course, goes against the decentralized aspect of blockchain. Of course, the counter argument to proof of stake is that with proof of stake, the guy who owns the most coins, right, the richest guy in the system can be now the one who gets the control over the network. So it centralizes towards rich people towards the wealth to the our possibilities to design proof of stake in a way that this is not taking place. So an easy way to think about it would be to kind of cap the maximum amount of contributions that you get by introducing high coin values to the network. The simple solution of just capping it has disadvantages and will be too complicated to go into this at the moment, but just understand that there are kind of ways in order to mitigate the problem. And on the disadvantages side, there is another very well known problem, which is called nothing at stake problem. And it describes the problem that rational miners and such proof of stake regime might be incentivized to produce fraudulent invalid blocks all the time, which then might congest the network and might make it impossible for the nodes to reach consensus. If you would like to know more about this, just google nothing at stake problem and you will find extensive documentation on that. Could go into a bit more, too much detail if we cover that here, but if you Google it, you will find lots of also easy to understand explanations about what the nothing at stake problem is all about. So . I hope this video helped you more about understanding what consensus mechanism really is all about. If you took some value out of this video, please press the like button. And if you would like to receive regular updates of what’s going on with this channel, both on the frontier of career success, but also learning new technology such as blockchain, press the…