2.4 Byzantine Fault Tolerance - Video Tutorials & Practice Problems
Video duration:
7m
Play a video:
Video transcript
We've talked about the double spend problem. And now we're gonna talk about Byzantine fault tolerance. We have talked specifically about something called the Byzantine fault and we're gonna put it in the context of Bitcoin. Let me explain to you. Byzantine fault tolerance deals with the fact that blockchains work on a decentralized principle in which the transactions are recorded on a distributed ledger. Now, there's no centralized authority to control the blockchain. When we're talking about Bitcoin, there's no CEO of Bitcoin to set the rules. Basically, the network is a decentralized network. As a result, malicious actors have a large economic incentives to cheat the system. Think about it, if you're a miner and you can find a way to gain the system you could earn more Bitcoins than you deserve or you may try to gain the system to actually double spend even though you're not supposed to. So this is a key problem with Byzantine fault tolerance. Now, a Byzantine fault presents a challenge to the integrity of the system as bad actors may try to send inaccurate data or fail to pass on the data. If a miner doesn't transmit to the rest of the network what a valid transaction is or holds back a block, or for instance gains the block, puts in inaccurate transactions and sends to the rest of the system, they can really harm the integrity of the data. Now, let's talk about the Byzantine Generals' problem so you see exactly how this works. And this is an example that's usually cited whenever we talk about Byzantine faults. And the Byzantine Generals' problem there are multiple generals controlling a portion of the Byzantine army and they are looking to attack a common enemy. On their own, these generals cannot defeat the enemy and instead they need to cooperate with each other and attack or the uncoordinated attack will fail. So this is very similar as how miners work. Miners need to be in alignment to make sure that everybody has the single version of the truth, that's the blockchain. So all miners need to agree on what is the real blockchain. So this is a key challenge because if you have a rogue miner, that's trying to gain the system, this could present the problem. Now, to be able to decide when to attack these generals must send communications to each other and agree on whether do attack or retreat. There's a communication issue. And there's a possibility that one or more of these generals is a trader and can fail to issue the vote or lie about their choice. So this, again goes back to if you have a rogue minor and that rogue minor is issuing incorrect data or is holding back and is not transmitting the correct data to the rest of the network, this could present a problem to the integrity of the blockchain. So let's look at how this would play out. You have a common enemy and you have all these generals. For these generals to be able to successfully attack this common enemy, they all need to be aligned because only a simultaneous attack can win. This is a successful attack. Now, if by any chance, if these miners are in this case, the generals, were actually not in alignment and you had only two of them that were to attack and the others had incorrect information or follow different orders, you would have a failed attack because they would not be able to successfully attack the common enemy. And this is the key challenge when you're dealing with a decentralized network like Bitcoin. You're dealing with all these miners which don't trust each other, don't know each other, some of them may want to gain the system. So it's a really, really big issue. How do you keep the integrity of the Bitcoin blockchain? So let's look at Byzantine fault tolerance and blockchain. A solution can be achieved to this by reaching what is known as consensus. Consensus is when a majority of the participants agree on a course of action. In the case of Bitcoin, it's when over 51% of the miners agree on what the version of the truth is. And this is a key issue. You have the majority of the minors in alignment on what the truth and the correct version the blockchain is. The solution needs to be reached even though there may be some malicious actors trying to break the process. You know, there's always the possibility that a minor could be a rogue minor and could be trying to gain the system. So you have to take that into consideration, but how you work around that? In a blockchain, there's multiple ways to do that and these are known as consensus algorithms. That is, these are algorithms that achieve consensus among the miners. Let me give you some examples. I will now explain it to you how we achieve Byzantine fault tolerance in blockchain. And to do so, I'm gonna talk about two types of consensus algorithms. To achieve consensus, there are two very popular consensus algorithms which are using blockchain. There are more, but I'm gonna focus on two, which are the two most popular ones. The first one is proof of work, and this is the one that's used in Bitcoin. In this one, the miners, and this is the network of the people that actually process and confirm these transactions, perform very resource intensive, computer hash calculations using the information that's recorded in the blockchain in a race against the other miners. So you're basically doing a competition against the other miners and you're doing all these hash calculations to be able to get a successful proof of work so that you can get your block accepted by the rest of the network. And I'll explain to you exactly how that works in a subsequent lesson when we do our demo of the blockchain. Now, the purpose of this is that it serves as protection against malicious actors looking to manipulate the blockchain. And this is because the malicious party needs to invest a very large amount of time and resources producing the proof of work necessary to have any influence on the blockchain. If you think about it, if you're a miner and you actually have many mining computers, you not only invested a lot of money in these mining computers, but you also are spending electric power to make sure that that's actually working. And the truth is, it doesn't make sense to you economically to try to get a rogue block that will probably get rejected by the rest of the network for you to even try it. So in the grand scheme of things, by performing this proof of work, you're preserving the security of the network because you're doing it as a race against all the other miners that are to make sure that the blockchain is preserving its integrity. Now there's another approach to this. And as I mentioned, proof of work is used in Bitcoin, it's also used in Ethereum. But Ethereum is actually moving towards something known as proof of stake. And proof of stake is also used in other blockchains. Now, and proof of stake instead of having to perform these computer calculations validators invest in coins of the system that they are validating. So, in a proof of stake, the chances of being selected to create the next block to be added to the blockchain depends on how many coins the validator has. So the key thing is this, if you actually want to be a validator into a specific blockchain, you need to own a lot of the cryptocurrency for that blockchain. So it's in your best interest to make sure that every single block is valid because if a non-valid block goes in there your coins could be worthless. So by you owning coins, you actually have a higher chances of being able to have your block added to the blockchain. For example, if a validator with 500 coins is five times more likely to be selected to validate the next block, than a validator that only has 100 coins. In other words, the more coins you own, the higher the chances that your block will be selected as the next block in the blockchain.