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:15:16

Bitcoin: The security of transaction block chains

Video transcript

what I would like to do is describe an imaginary or a fictitious Bitcoin transaction and then talk about how somebody might try to game or defraud the system and why that's um only mathematically hard to do but why there's actually an incentive attribute an economic incentive in the Bitcoin system for different people to behave honestly so let's suppose that there is someone out there named Dan and the Dan wants to order a pizza maybe a cheese pizza from Pete's pizza shop and let's say the pizza pizza shop accepts bitcoins as payment and that it costs one Bitcoin one Bitcoin for a pizza pie and imagine the Dan receive previously let's say he received five bitcoins from his cousin Carol so maybe Carol we're going to label by C he gave to Dan five bitcoins which we can label as a B with a circle around it and that he wants to use one of these five bitcoins to buy a pizza from Pete and so what Dan's Bitcoin client will do is it will create a transaction record that includes information about how Dan got these bitcoins so in this case it includes information about this transaction between Carol we've marked by C and Dan for five bitcoins and then it specifies that Dan wants to give one of these bitcoins to P to me labeled Pete by a P and also that Dan is going to take the remaining four bitcoins and that will be basically change to himself and the way that Bitcoin is built is that you have to actually specify the change because you need to have a way whatever goes into the Bitcoin system has to kind of come out at the other end and so you can't have a transaction where the numbers don't add up and so whatever is remaining is either change or part of it can be used as a transaction fee and so on but for this example to keep things simple I'll assume that there is no transaction fee in place the transaction fee is just zero and will focus only on the situation in which everything is being accounted for in the transaction now this transaction record is going to be broadcast out to the entire Bitcoin world and so in particular Pete is going to receive a copy of this transaction but in addition to Pete receiving it so too will the other people on the on the Bitcoin system and if you recall there are these special no these special entities or people in Bitcoin that are known as Bitcoin miners and these Bitcoin miners are going to be responsible for making sure that everything checks out in the transaction from a global perspective what they do is they look at the full record of transactions in this transaction record is public it's known as the the transaction block chain and I've kind of put a description of the transaction block chain right here and this transaction block chain can take the history of every single transaction has ever occurred wouldn't the Bitcoin system from the beginning of time in the time of the first block which is known in Bitcoin as the Genesis block okay and everybody can verify that the details of any transaction if they want to because that information is public and in particular what these Bitcoin miners will look at is they look at whether or not I Dan previously received five bitcoins from from anybody else in this particular case it was as cousin Carol whether or not Dan has tried to spend those bitcoins previously and so on and so forth and these Bitcoin miners are all collectively trying to take all these recent transactions that haven't yet been recorded and that includes not only the transaction between Dan and Pete but there may be other transactions floating out there that took place around the same time and the Bitcoin miners will basically look at all these different transactions at once and they're going to basically try to figure out how to form a transaction block out of these transactions and they want to add this transaction block to the end of the current transaction block chain now if you might recall from previous videos that for a Bitcoin miner to add a transaction block to a transaction block chain they have to solve what's known as a proof-of-work puzzle and the Bitcoin system is designed or maybe calibrated as a better word so that on average one miner will solve a puzzle in about ten minutes now I think it's actually worth stressing here that it could take a long time for any one individual miner to solve the puzzle it could even take maybe a year or even two years but because there are so many of these miners working at the same time one of them is bound to get lucky and all the puzzle quickly now each puzzle in the proof-of-work each of these proof-of-work puzzles that is associated with a transaction block happens to have a difficulty score associated with it and this difficulty basically represents how hard it was to solve that proof-of-work puzzle and so imagine that there are some numbers and invoke all these numbers let's say though we'll call them D sub n for the most recent difficulty score they'll be D sub n minus 1 of these are just numbers that somehow represent how hard it was to solve this proof of work and when you look at an overall chain what the Bitcoin system is interested in in is its interested in how hard was it to construct that entire chain and the reason it's important for someone to understand how hard the entire chain was construct is because this this overall score for this chain this difficulty score for the chain is what's used by Peter by other people who are receiving bitcoins to figure out whether or not they trust that transaction the more work that went into the overall chain the more trust they'll have in that transaction and the reason for that is that the way Bitcoin works is that if there was ever more than one transaction block chain out there let's say there was a bad user out there or maybe somebody didn't receive a particular message in time or whatever reason if there's somehow more than one transaction block chain out there according to the Bitcoin protocol everyone is just supposed to work off of the chain that had the most work put into it so we ignore chains that are that have a lot less work and only consider the chain and at the most work put into it and in the Bitcoin system that particular chain is often referred to as the longest the longest chain in the system and this is actually kind of a confusing confusing piece of terminology because about a longest year we don't mean that this chain is long in any physical sense we really just mean and I'm going to put a 3 equal bars to kind of say what it means by the longest chain you mean the chain it has the most most work and the way that the work is defined is that you look at all these different difficulty scores and these are difficulty numbers and you add them up and that gives you a a score for the entire chain and now we're going to be interested in the chain that had the most work put into it and we call that the longest chain now let's imagine that Dan is dishonest and that after he eats the pizza let's say Pete's convinced and he gets he gets his Bitcoin from Dan he waits a bit he sees that there's a long chain out there that contains a transaction he sends the pizza over to Dan dan eats the pizza and then decide that he doesn't want to behave honestly and he wants to somehow cheat Pete or he wants a defrauded system and the way that Dan is going to try to defraud the system is by attempting to create another transaction in which he assigns the 5 bitcoins he got from Carol to somebody else and it could be we're going to let's call this person Fred and let's say Fred is basically you know Fred could be Dan's alter ego it could be a friend of Dan's doesn't matter who fred is because we know that Fred isn't the rightful owner of these bitcoins but what dan is going to try to do is he's going to try to take those five bitcoins that he got from Carol and he's going to now try to take those five bitcoins and assign them over to Fred and we know that this is something that we don't want to allow because that would mean that somehow Dan was able to spend these five bitcoins twice over he's effectively double spent those bitcoins and obviously one of these transactions should be considered fraudulent the other one should be allowed to go through now it's important to keep in mind that if Dan just tried to spend these same coins again without trying to cover his tracks or anything of that nature then everybody out there would know that Dan is up to no good because they can see from the existing longest transaction block chain namely this existing chain from the beginning they can see that hey Dan already spent these coins before he shouldn't be allowed to spend these coins again and so what Dan has to do is actually on his own he has to create a different transaction block chain that contains just the second bogus transaction in it and this would be the transaction to Fred and that would leave out the other transaction to Pete and hope that everybody else will start to accept or believe this newer chain and remember that since everyone in Bitcoin ultimately goes with the transaction blockchain that contains the most work namely this this longest chain that we talked about dan has a fighting chance he has a hope potentially of being able to pull off this type of a of a fraudulent scheme and the real question now is how likely is it for Dan to succeed so for Dan to be able to pull this off he has to start off with the transaction block chain that existed previously and yes to try to add to that transaction block chain a different transaction so rather than having this previous transaction where he gave money to to Pete he's going to try to create a new transaction and added to the transaction block chain that contains this other fraudulent transaction between between Dan and his friend Fred okay so this is going to be the bad transaction between Dan and Fred will be will be in this new this new block and in Bitcoin lingo this idea is known as a fork in the chain and all we mean by a fork is that somehow there is more than one version of history somebody tried to rewrite their tracks or to cover their tracks in turn to revise history the way we know it and what that really means is there's now somehow more than one version of what happened out there so in this example one branch in this fork is legitimate and the other branch is bogus and the legitimate branch was the one in our minds were dan paid his friend Peter this this vendor Pete for a pizza and the bogus one is this follow-on transaction board an attempted to pay his friend Fred with those same exact bitcoins but now remember that any transaction block that's added to this transaction block chain has to contain within it a proof-of-work puzzle or a solution rather to a proof-of-work puzzle otherwise no one will accept the chain and so if Dan wants to cheat the system he has to secretly solve a new proof-of-work puzzle himself but the challenge for Dan is that he's starting off at a bit of a handicap because there's already this longer chain out there that people have started accepting and keep in mind that because this chain is out there other nodes may have started to build on top of this chain every 10 minutes somebody's adding to this chain on average and so there's this longer transaction block chain out there and Dan wants to create his own fake chain and so he has to create a chain in order for that chain to be believable it has to now be the longest chain out there and he has to basically do all these proof of works to create a chain that is longer and to come up with this longer chain on his own dan has to outrun the existing proof of work chain and that means yes to solve not just typically one proof-of-work puzzle but you may need to solve several proof-of-work puzzles to create another chain that he hopes will be longer than the chain that's out there and if you can get the longest chain that you can get people to start using that chain instead and that's a chain that he might want people to use because it contains this fake transaction but it removes the previous transaction where you gave money to Pete and to solve a proof-of-work dan has to basically take whatever computing power he has accessed you and he has to start working on solving the proof-of-work puzzle and there are no known shortcuts for solving these puzzles if you recall from any of the proof-of-work videos to succeed in a proof-of-work is kind of like winning a lottery there are ways to do it but it really depends on how much computing power you have the more computing powers you have access to the more lottery tickets you have and if somebody has even one lottery ticket they do have a chance to win the lottery but they are far less likely to succeed compared to somebody who has a lot of lottery tickets in hand and even if you succeed once and winning the lottery with a small number of tickets the likelihood of repeating that feat over and over again several times in a row becomes much smaller but that's exactly what Dan has to do he has to basically win this lottery in multiple times until he has a bigger chain and so the key metric here the key thing you have to look for is how much computing power dan has versus how much computing power all the honest nodes in the system have together and if it's the case that all the honest nodes are stable called is the honest the honest computing power and when I say honest computing power I mean the total computing power for all the nodes who are honest all the Bitcoin mining nodes who are honest in work if that total computing power that they have access to is greater than the power that dedenne has access to so dance computing power then the Bitcoin system will be safe because it'll be hard for Dan to be able to create this fraudulent transaction chain because you won't be able to outrun the honest people the honest people win the lottery more frequently and they'll create a longer chain and Dan's attempt is going to be very much an uphill battle now it's theoretically possible that Dan could have access to a lot of computing power maybe he's very wealthy or he has a lot of resources but he'll really need a lot to be able to do that more than everyone else who's legitimate combined so that's one aspect of why the transaction block chain is secure because it's unlikely for any one individual to have access to just that much computing power and here I should point out that there is also another aspect to the security of Bitcoin if Dan has access to that kind of computing power to solve these proof-of-work puzzles then rather than trying to fight this uphill battle of forking the transaction block chain and creating fake transactions and so on then is probably much better off just using that computing power he has four legitimate Bitcoin mining himself you might remember that Bitcoin miners who solve proof-of-work puzzles get both a reward for succeeding they get some number of bitcoins and they also get a transaction fee for all the transactions in the block that they validated so there's this economic incentive for Dan to behave honestly and so maybe I should just recap in closing the video that the security of Bitcoin transactions comes from first of all this mathematical barrier that makes it hard for Dan to fort the transaction block chain in a dishonest way as well as an economic incentive for Dan to just act honestly in mind bitcoins for himself