If you're seeing this message, it means we're having trouble loading external resources on our website.

If you're behind a web filter, please make sure that the domains *.kastatic.org and *.kasandbox.org are unblocked.

Main content
Current time:0:00Total duration:11:25

Video transcript

the last really essential or salient piece for understanding the mechanics of how bitcoins work is what we call the the transaction block chain so if you recall in the previous videos we had a motivating example of a user Alice who wanted to let's say send some number of bitcoins to another user Bob in the system and what Alice had to do to initiate that transaction was to construct a transaction a record of sorts that contained information about the transaction and that was signed with Alice's signing key and that actually contained Alice's public verification key involved public verification key as well okay and that transaction information was basically broadcast out as we as we mentioned to the entire Bitcoin ecosystem to all the nodes on the Bitcoin peer-to-peer network now the various nodes in the Bitcoin ecosystem what we're going to sit there they're going to receive information about this transaction but they're also going to be getting information about a lot of other transactions that are taking place around the same time okay and what these notes are going to start doing is they're going to work on incorporating this transaction record into really a ledger of all transactions that have ever taken place in the Bitcoin system and so what happens is that each node basically starts off by taking all of the previously unincorporated transactions that they've ever received so there can be all these transactions out there that have kind of happened within a given time window and so there's all these Bitcoin transactions kind of floating around and these nodes these Bitcoin miners are as they're called are going to receive information about all these different transactions and they're going to start working on incorporating those transactions okay now their first goal is to collate these transactions okay into what's known as a transaction block so if you recall our ledger analogy a single Bitcoin transaction essentially corresponds to a proposed entry in a ledger in that capacity a transaction block would basically correspond to an entire page in a ledger where you have multiple transactions that are listed in that page of the ledger and the goal the Bitcoin miners goal is essentially to take that that page and get it added to the global ledger but the global comprehensive ledger book all right now to engage in this sort of work what these nose will basically do is they'll first take all the transactions that have been broadcast on let's say these four transactions have been broadcast out okay and they're going to basically hash these transactions in pairs okay and basically in a tree-like structure so they'll they'll take these two transactions and they'll apply a cryptographic hash function to those details and they'll get a corresponding digest they'll do the same for these two and then they'll take these two digests and hash them to get a single digest value and this digest effectively encodes all of the transactions that were previously unincorporated and that were received by these individual nodes all right and then this digest is basically going to be combined it's going to be combined with the hash of the transaction block that was previously accepted by the network so you can imagine that there is the network will have a series of transaction blocks that were previously accepted and in fact every transaction block as I mentioned just now incorporates the previous transaction block so this transaction block will incorporate the one that was used just before it and this transactional block will incorporate the one that was used just for it and it's going to go on literally until the beginning of Bitcoin times this is really where the Bitcoin the beginning of time for the Bitcoin system okay this is just a time time equals zero for Bitcoin okay and they're going to take this last block and they're going to essentially now take this last block and combine it with with this most recent block and so if you imagine that you have now not just an individual block but because each individual block incorporates the block before it we're not dealing anymore with an isolated or distinct block of transactions but rather with a chain of blocks that starts literally at the beginning of the entire Bitcoin system all right now when you do all this combination at the end of the day you're going to do some cryptographic hashing and you basically will end up with a sequence of numbers okay and this sequence of numbers will be derived by incorporating all these blocks together you'll get a sequence of numbers and what we're going to basically do is take the sequence of numbers and convert that sequence of numbers into a challenge in a proof-of-work protocol okay now I did a separate video on proof-of-work protocols I would encourage you to watch that if you want to get a better sense for how they work but the short of it is that what the Bitcoin mining node has to do at this point is he'll take the Bitcoin he'll take the the challenge and you'll have to come up with a separate sequence of numbers which we typically term the proof or the proof of work and this proof of work has to have a very specific mathematical property with that property entails is that if you take the the challenge numbers and you take these proof numbers and you concatenate them together and you make them the input to a cryptographic hash function okay the resulting output has to have a large prefix of zeros okay and that isn't have to be all zeros but a large portion of the the beginning the prefix has to be all zeros okay and if you think about it for a moment given the cryptographic hash functions given that their output tends to look fairly random it's unlikely that in any given instance you are going to see a proof a proposed proof that provides you with a large string of zeros at the beginning and so what the Bitcoin miner will have to do is on average he let's try many possible choices for these proof numbers until he finally gets lucky and he stumbles upon one that has this kind of offbeat or strange statistical property okay and the actual difficulty of finding these proof numbers as you can tell is dependent on exactly how many leading zeros are required okay the more leading zeros you require in this in this proof the the longer it takes to actually solve the problem longer it takes to actually come up with a proof that works with respect to a given challenge the fewer zeros that you require the less time it will take now the exact number of bits of zero bits required in the Bitcoin protocol actually does change over time it gets calibrated and it's designed so don't on average the average time taken across the whole system should be about about ten minutes okay so you wanted to take about ten minutes for at least one node to come up with a valid proof but keep in mind that a lot of nodes are working on this proof concurrently all right now once this proof of work is found let's say that the proof of work is eventually found the Bitcoin miner will announce the results to the overall peer-to-peer networks who's going to take this proof and really all to challenge it and so on and he's going to announce it to all the other nodes and they're not going to see that hey there's this proof out there somebody found it let's drop the other stuff we're doing and we're going to now start to work and build on top of this new proof a number this new proof and this new challenge these all incorporate all the previous transaction blocks you really what they're starting to do is they're starting to work off of a new updated transaction block chain okay and they're going to incorporate any new unincorperated transactions into that new transaction block chain now there are a couple of points I want to make here so first of all is part of constructing these transaction blocks and really as part of incorporating them into a transaction block chain Bitcoin miners are actually allowed one little special special treat they are allowed to include in that transaction block a special node for themselves and this node will basically be a little reward that they can get and let me let me use the kind of a greenish color for that reward so they can take the first the first block the first transaction item okay the first transaction record and they can put in that transaction record they can assign a reward to themselves okay now the amount of that reward will change over time okay but I do want to point out that what this this transaction is typically called is it's called a coin base a coinbase transaction or a a generation transaction this is how new coins get included in the Bitcoin system so whenever a miner succeeds in coming up with a a proof as part of that he leaves he'll have been allowed to come up with his own transaction to reward himself a special reward for expending the effort necessary to come up with this proof and for doing all this work associated with adding a new transaction block to the existing transit and blockchain for Bitcoin alright and I think that's reasonable after all these nodes are using a lot of computational power to come up with these these proofs and that if they're using computational power that must mean that somewhere along the line somebody is spending money on electricity and so on now I also want to point out that in addition to this this coin base award the nodes who are doing the Bitcoin money the ones succeed also get to collect the transaction fees that were specified in the transaction records if you recall on a person issuing a transaction in Bitcoin can allocate or set aside a certain amount of money maybe it could be a Bitcoin or a fractional Bitcoin for the node who succeeds in coming up and coming up with the actual proof of work and effectively the node that succeeds in being able to add that transaction to the overall Bitcoin transaction block chain and so that node that does the work that succeeds gets a reward of a transaction fee now this this could actually become quite large because the node will not only get the transaction table for one transaction it'll get the transaction fee for all the transactions that appeared in the current block that's going to get the aggregate over all these different these different transactions all right now the second point I want to make is that it might be possible for two nodes to solve the proof of work independently of each other and somehow they may both end up trying to add to that existing chain in some way so you may get some weird chain forking happening right that happens the peers in the Bitcoin network will basically break a tie by sticking with the longest chain and by longest I don't mean the one that has maybe the most transactions in it I really mean the one that has the highest aggregate difficulty associated with that underlying proof-of-work protocol in each of the the transaction blocks it'll basically look at the total amount of effort that was required to generate that chain but regard to that proof of work and whichever chain has the most work associated with it is a chain that sacrosanct it's a chain that everybody will accept now you may get some weird discrepancies because of network latency issues and so on but the idea is it after maybe a couple of rounds when there are ties they'll quickly resolve themselves as longest most of the nodes are behaving honestly and really stick to their implementation of the protocol all right now since Bitcoin miners are generating bitcoins I think there's an interesting question that comes up here which is you know how does a big plan money supply controlled and how is it managed and I'm going to talk about that concept in a subsequent video