Now that we know what proof of work is conceptually, let's see how it's implemented in Bitcoin. Let's see how the board is partitioned according to computing power and how the needle is [inaudible]. The way that Bitcoin chooses to implement proof of work, is in a quite simple, maybe deceptively simple hashing puzzle. As the nodes are compiling their blocks, the Bitcoin protocol requires them to append a random number called a ''Nonce'' to the transaction data in the block. The hashing puzzle is simply this: Take a hash of the block plus the nonce, and I want you to find at least X number of leading zeros in the resulting hash. But you might wonder how is this related to letting the nodes proving their computing power? Well, if you recall the property of the hashing function that we discussed in the previous module, you'll realize that because of the high avalanche effect, you can't analytically derive a hash with X leading zeros. It has to be found by trial and error. Hashing the ever changing block with different nonces again and again until you produce the requisite number of zeros. Let's see how this works in a simple example. Suppose the block data you received is a simple text string. ''Hello world''. Now, I want you to find a nonce that produces four leading zeros. How would you do that? Well, you would try each one at a time, right? So let's start with zero. We append it to the data and take a hash. No. How about one? No. So we keep trying two, three, four and so on. 4248, 4249 and finally, we get lucky using 4250 as the nonce. This is essentially all the Bitcoin miners are doing as they're compiling the block. It doesn't matter what data they have received, they just keep trying to nonce numbers, keep taking the hashes at trillions of times per second, hoping to produce the required number of leading zeros. Now crucially, remember that the more computing power you have, the more trillions of hashes you can carry out. Therefore, the miner with a higher computing power is more likely to find the lucky solution. This simple hashing puzzle therefore achieves exactly the same function as the partition board and the needle spinning that we saw in the last video. It creates a weighted lottery system where the likelihood of finding the lucky answer is determined by the miners hash power. Just as the board example, the winning miner gets to post his block together with a nonce that was found to produce the leading zeros. After this, other nonce that didn't win in this round again, take a more passive role. They simply take the data and the nonce and verify that it indeed produces the leading zeros and the transactions in the block are valid. Satisfying the UTX0 and having the right signatures. This takes very little time and a valid block will be added to the block chain. This achieves consensus in this round and the nodes start compiling a new block and hash again. Now, another interesting design feature of the hashing puzzle is that the difficulty, that is the number of required leading zeros are adjusted dynamically. The more leading zeros, the more hashes are required to find it. In every 2016 blocks or roughly every two weeks, the Bitcoin protocol monitors the total hash power of all miners, that is the total number of hashes being carried out and adjusts the next puzzles difficulty such that it roughly takes ten minutes for the entire group of miners to find the solution. This design is there to ensure that the average block interval is relatively constant at 10 minutes per block and is not affected by the total number of miners. When more miners join the puzzle gets more difficult and it gets less difficult when miners lead and there are fewer miners in the pool. This, of course, is not precise. So a new block is added, not exactly in 10 minutes and the block interval do vary a bit, but it's been roughly centered at one every 10 minutes or so. Now that we know how Bitcoin implements proof of work, you might still be wondering why, wasn't it for the miners to go through all the trouble buying computing power and burning the energy to do all the seemingly meaningless hashes. There obviously need to be strong incentives for them to participate. In bitcoin, there are two primary incentives. First is new Bitcoins. The miner that won the hashing puzzle get to mend some bitcoins out of thin air. It gets to include in the block a so-called ''Coinbase Transaction'', which as we have seen in a previous video has no inputs and has an output awarding the new coins to the miners own address. This is a crucial incentive for the miners to participate. Because if they perceive that the Bitcoins that they get have some value and that value exceeds the hardware energy costs incurred in doing these hashes, they will be more likely to participate and stay in the game. Now in Bitcoin, this is going to change over time because Bitcoin has a special feature where's total supply is capped at 21 million coins and no more. The coin is therefore deflationary by design. We'll talk about what it means for its pricing in the next module. But here what it means for the miners is that the new coin reward is going to get smaller and smaller, closer to zero, as the total number of Bitcoins approaches 21 million. Right now at the end of 2019, over 18 million have been mined and the reward for each block is 12.5 bitcoins. This is half from three years ago where it was 25 per block. In 2020 it'll be halfed again to six and a quarter per block and will keep getting halved every few years until he reaches zero in roughly 2140. That's when the 21 million coin cap will be hit. Again, this is specifically for Bitcoin and it's certainly not a requirement for cryptocurrencies. Contrary to what many people think, not all cryptocurrencies are deflationary and have a finite supply. Many like a theorem have infinite supplies. But for Bitcoin miners, the decreasing reward structure, means that the second type of incentive will become ever more important. This incentive is in the form of transaction fees, which is like a voluntary tip that users paid to the miners to process and record their transaction data on the Bitcoin block chain. This is done by modifying the UTX0 principle that we discussed earlier. Instead of total input equals total output, the users could leave some amount in the output for the miners. It's completely discretionary to them how much they want to leave as the tip and whether they want to leave a tip at all or is it. Suppose you don't tip or just tip a very tiny amount, then the miners will simply prioritize transactions that come with higher tips. Remember, the Bitcoin transactions are not done in a first come, first serve basis. The miners have complete freedom in when and whether to include transactions in the block that they're compiling. So in reality, the transaction fee is not voluntary at all. If you use a wallet, you can specify that your self or the Wallet app could choose it for you based on historical data. For Bitcoin, the transaction fees had been fairly high, hovering around two percent. This high fee is a major reason for a failure to gain traction as a mainstream payment system. The situation probably won't get much better for Bitcoin and many other deflationary cryptocurrencies. As time goes on, the newly minted coin reward will get lower and lower. However, the key to the survival of the system is a healthy base of miners. So they need to be incentivized to stay. Going forward therefore, if Bitcoin needs to survive, the transaction fees will likely get higher and play a bigger role in retaining the network of nodes.