WEBVTT - Automatic transcript; recognition may contain errors. Reviewed for technical wording and speaker labels. Times match the published episode.

00:00:20.660 --> 00:00:23.200
<v Aaron van Wirdum>Live from Utrecht, this is Bitcoin

00:00:23.200 --> 00:00:24.480
<v Sjors Provoost>Explained.

00:00:25.200 --> 00:00:26.240
<v Aaron van Wirdum>Welcome back, Sjors.

00:00:26.800 --> 00:00:27.160
<v Sjors Provoost>Thank you.

00:00:27.440 --> 00:00:30.580
<v Aaron van Wirdum>You were on holiday. That's why we were out for a couple of weeks. Where did you

00:00:30.580 --> 00:00:31.080
<v Aaron van Wirdum>actually go?

00:00:32.320 --> 00:00:33.420
<v Sjors Provoost>I'm not going to say.

00:00:35.320 --> 00:00:37.200
<v Aaron van Wirdum>Is that your OPSEC strategy?

00:00:37.440 --> 00:00:37.780
<v Sjors Provoost>Exactly.

00:00:37.780 --> 00:00:39.600
<v Aaron van Wirdum>Or just ashamed of where you went?

00:00:39.960 --> 00:00:40.240
<v Sjors Provoost>Both.

00:00:42.080 --> 00:00:46.820
<v Aaron van Wirdum>Okay, well, Bitcoin Amsterdam is coming up just a couple of months from now. You

00:00:46.820 --> 00:00:51.480
<v Aaron van Wirdum>know what that means, right, Sjors? A conference in Amsterdam. It means

00:00:51.480 --> 00:00:53.440
<v Sjors Provoost>It means having to go to Amsterdam.

00:00:53.440 --> 00:00:58.410
<v Aaron van Wirdum>It means 420 blaze it. That's why we're gonna talk about hash today.

00:00:58.410 --> 00:01:00.340
<v Aaron van Wirdum>Do you get it?

00:01:00.440 --> 00:01:01.260
<v Sjors Provoost>Oh.

00:01:01.260 --> 00:01:05.220
<v Aaron van Wirdum>That's that's the first pun. The first pun of the new season. I'm gonna consider

00:01:05.220 --> 00:01:09.660
<v Aaron van Wirdum>this a new season and we're strong out of the gate with with fresh new puns for our listeners

00:01:09.660 --> 00:01:13.220
<v Sjors Provoost>I did expect you were gonna make a a pun around that topic. yes.

00:01:13.920 --> 00:01:19.200
<v Aaron van Wirdum>We are going to talk about hashes, hash functions to be specific. This is a topic

00:01:19.200 --> 00:01:24.360
<v Aaron van Wirdum>that has come up here and there. And it's obviously a topic that everyone knows

00:01:24.360 --> 00:01:29.340
<v Aaron van Wirdum>something about. And you, our dear listener, might now think where you're talking

00:01:29.340 --> 00:01:34.000
<v Aaron van Wirdum>about hashes, we already know what hashes are. But do you really? Do you really

00:01:34.000 --> 00:01:38.740
<v Aaron van Wirdum>know what a hash is? I didn't. I thought I did. But I learned something in

00:01:38.740 --> 00:01:43.180
<v Aaron van Wirdum>preparation for this show. So you might as well. Sjors, I'm going to start with

00:01:43.180 --> 00:01:47.360
<v Aaron van Wirdum>the first basic question. I think most people have a general idea of what a hash

00:01:47.360 --> 00:01:50.700
<v Aaron van Wirdum>is, but still, Sjors, what is a hash?

00:01:51.680 --> 00:01:57.280
<v Sjors Provoost>Well, it's basically a function that goes in one way. It garbles the input.

00:01:57.560 --> 00:02:02.260
<v Sjors Provoost>So if you start with the word hello, then out comes some garbage. And if you

00:02:02.260 --> 00:02:04.660
<v Sjors Provoost>start with the word hello too, out comes some different garbage.

00:02:05.910 --> 00:02:10.630
<v Aaron van Wirdum>Yeah, well, you say garbage, but what you really mean is a number.

00:02:11.270 --> 00:02:11.750
<v Sjors Provoost>yes.

00:02:11.750 --> 00:02:12.130
<v Aaron van Wirdum>Data.

00:02:12.130 --> 00:02:12.910
<v Sjors Provoost>yes.

00:02:12.910 --> 00:02:15.790
<v Aaron van Wirdum>Essentially, zeros and ones.

00:02:15.790 --> 00:02:21.670
<v Sjors Provoost>Yes but I mean everything is zeros and ones so that's why a number. yeah.

00:02:21.670 --> 00:02:25.210
<v Aaron van Wirdum>Is that the best way to put it? A number comes out a number goes in a number

00:02:25.210 --> 00:02:31.190
<v Aaron van Wirdum>comes out, and any data you can convert any data a picture or a song or as

00:02:31.190 --> 00:02:37.070
<v Aaron van Wirdum>long as it's digital you can convert it into a number and then you can You can

00:02:37.070 --> 00:02:39.310
<v Aaron van Wirdum>hash that number and you get a different number, right?

00:02:39.590 --> 00:02:40.190
<v Sjors Provoost>Yeah, that's right.

00:02:40.750 --> 00:02:46.690
<v Aaron van Wirdum>Okay, now there are some important properties for a hash function to

00:02:46.690 --> 00:02:47.550
<v Aaron van Wirdum>be a hash function.

00:02:49.500 --> 00:02:55.400
<v Aaron van Wirdum>You can't just say multiply everything by two. If you do that, you get a

00:02:55.400 --> 00:02:59.320
<v Aaron van Wirdum>different number, but that's not a hash function. A hash function needs to do

00:02:59.320 --> 00:03:01.000
<v Aaron van Wirdum>something specific. So what does it need to do?

00:03:01.120 --> 00:03:06.380
<v Sjors Provoost>Yeah, it needs to make sure that if you know the hash,

00:03:07.000 --> 00:03:11.500
<v Sjors Provoost>like you can't just change it basically or maybe a better way to say it is so if

00:03:11.500 --> 00:03:16.380
<v Sjors Provoost>you have the word hello and you hash it it comes out a number and then you

00:03:16.380 --> 00:03:19.200
<v Sjors Provoost>shouldn't just be able to say well I want to make hello too I'm just going to

00:03:19.200 --> 00:03:22.560
<v Sjors Provoost>change the hash now, and then I know that it was hello too.

00:03:23.300 --> 00:03:25.760
<v Aaron van Wirdum>Right so what you're saying is…

00:03:25.760 --> 00:03:29.140
<v Sjors Provoost>So if in your example of multiplying by two let's say that the hash of the word

00:03:29.140 --> 00:03:35.050
<v Sjors Provoost>hello is one and if the hash of the word hello2 is 2, well, it's a little

00:03:35.050 --> 00:03:35.850
<v Sjors Provoost>bit too predictable.

00:03:36.470 --> 00:03:36.610
<v Aaron van Wirdum>Right.

00:03:36.850 --> 00:03:39.550
<v Sjors Provoost>I mean, that would be a weird example. Maybe a better example would be if the

00:03:39.550 --> 00:03:44.250
<v Sjors Provoost>hash of the word hello, hello was 2. It would be very predictable because now if

00:03:44.250 --> 00:03:49.170
<v Sjors Provoost>I can take the number 3 and I can guess, oh, then the original must be hello, hello, hello.

00:03:50.750 --> 00:03:56.550
<v Aaron van Wirdum>Yeah, so essentially... The outcome needs to be completely unpredictable.

00:03:56.990 --> 00:04:02.910
<v Aaron van Wirdum>So if you hash an entire book and then you

00:04:02.910 --> 00:04:08.550
<v Aaron van Wirdum>hash the exact same book, but you change one period into a comma, the hash needs

00:04:08.550 --> 00:04:09.850
<v Aaron van Wirdum>to be completely different, right?

00:04:10.050 --> 00:04:10.630
<v Sjors Provoost>Yes, absolutely.

00:04:10.830 --> 00:04:16.490
<v Aaron van Wirdum>And there needs to be no way to figure out which hash came from

00:04:16.490 --> 00:04:18.010
<v Aaron van Wirdum>which book.

00:04:18.450 --> 00:04:20.510
<v Sjors Provoost>Yeah, well, in particular, like...

00:04:20.510 --> 00:04:22.450
<v Aaron van Wirdum>Unless you have the book, I should add.

00:04:22.670 --> 00:04:26.050
<v Sjors Provoost>Yeah, I think one thing you want to prevent is the thing called collisions,

00:04:26.330 --> 00:04:31.910
<v Sjors Provoost>right? So that means that if I take your book and now I change some comma in a

00:04:31.910 --> 00:04:36.350
<v Sjors Provoost>very specific place that I would get the same hash, that's a problem. Because

00:04:36.350 --> 00:04:39.830
<v Sjors Provoost>then I could show you two different books and it would have the same hash. And so

00:04:39.830 --> 00:04:43.630
<v Sjors Provoost>now I've cheated because the whole point of the hash was to prove that, you know,

00:04:43.750 --> 00:04:46.450
<v Sjors Provoost>I was actually referring to the book and not some other book.

00:04:47.180 --> 00:04:52.720
<v Aaron van Wirdum>Right. So each piece of data should result in a different hash.

00:04:52.940 --> 00:04:53.280
<v Sjors Provoost>Yes.

00:04:53.660 --> 00:04:59.470
<v Aaron van Wirdum>Right. Okay. So that ties into my next question. And

00:04:59.470 --> 00:05:03.550
<v Aaron van Wirdum>I'm not sure if we completely answered this question already, but so let's see if

00:05:03.550 --> 00:05:08.870
<v Aaron van Wirdum>we did or didn't. What would it make? So some hash functions have been broken in

00:05:08.870 --> 00:05:12.570
<v Aaron van Wirdum>the past. So what does it mean if a hash function is broken?

00:05:13.130 --> 00:05:17.650
<v Sjors Provoost>Yeah, so then we can get into some numbers, I guess. So let's say the resulting

00:05:17.650 --> 00:05:22.970
<v Sjors Provoost>hash is a number with like it's 64 bytes or 256

00:05:22.970 --> 00:05:28.910
<v Sjors Provoost>bits, right? 256 bits, that's the hash. And that means there are two to

00:05:28.910 --> 00:05:32.360
<v Sjors Provoost>the power of 256 possibilities. Right?

00:05:32.860 --> 00:05:37.240
<v Aaron van Wirdum>Yeah, and bits are literally the zeros and ones that I mentioned earlier.

00:05:37.360 --> 00:05:42.360
<v Sjors Provoost>Right, so 256 zeros and ones, that's the hash itself. So that means that if you

00:05:42.360 --> 00:05:47.780
<v Sjors Provoost>have some piece of text, say the word hello, and that results in this hash, now

00:05:47.780 --> 00:05:52.200
<v Sjors Provoost>the question would be, can you find another word that results in the same hash?

00:05:53.460 --> 00:05:59.140
<v Sjors Provoost>For example, the word hello too. And if the hash works really well, then you just

00:05:59.140 --> 00:06:04.580
<v Sjors Provoost>have to guess. You would try, you know, 2 to the power of 256 different words

00:06:04.580 --> 00:06:10.420
<v Sjors Provoost>or different sentences until you get the same hash as hello. And that should

00:06:10.420 --> 00:06:14.220
<v Sjors Provoost>take a very long time. Now, the hash is very broken if it doesn't take a very

00:06:14.220 --> 00:06:18.960
<v Sjors Provoost>long time. If it turns out that you can just try maybe 100 different things and

00:06:18.960 --> 00:06:22.300
<v Sjors Provoost>then you find a duplicate hash or a collision.

00:06:22.780 --> 00:06:27.920
<v Aaron van Wirdum>Right. So as soon as any hash collision is found,

00:06:28.870 --> 00:06:34.870
<v Aaron van Wirdum>which has happened with previous, or I'm not sure why, with older hash

00:06:34.870 --> 00:06:40.570
<v Aaron van Wirdum>functions. So as soon as any collision is found, is at that point the hash

00:06:40.570 --> 00:06:42.190
<v Aaron van Wirdum>function considered broken?

00:06:42.430 --> 00:06:47.630
<v Sjors Provoost>I don't know what the exact criteria is, but you can try and measure it. So if,

00:06:47.730 --> 00:06:53.710
<v Sjors Provoost>for example, it should take 2 to the power of 256 attempts, but in practice, you

00:06:53.710 --> 00:06:57.890
<v Sjors Provoost>can do it once in 100 times, then obviously it's broken. But if it takes 2 to the

00:06:57.890 --> 00:07:03.710
<v Sjors Provoost>power of 255 attempts, that's still a huge number. So there might still be some

00:07:03.710 --> 00:07:09.310
<v Sjors Provoost>practical limit. But probably in the case of this, if you're able to find a

00:07:09.310 --> 00:07:12.150
<v Sjors Provoost>single collision, that means the odds are already too high because it should

00:07:12.150 --> 00:07:15.430
<v Sjors Provoost>really never happen with that big of a number. It's such an astronomical number

00:07:15.430 --> 00:07:18.910
<v Sjors Provoost>that it should take you longer than the age of the universe to try all these

00:07:18.910 --> 00:07:21.690
<v Sjors Provoost>combinations. So if you find something in less than the age of the universe,

00:07:21.950 --> 00:07:23.650
<v Sjors Provoost>that's a really bad sign.

00:07:24.210 --> 00:07:29.710
<v Aaron van Wirdum>And if you do find something, it was presumably in less time than the age of the

00:07:29.710 --> 00:07:30.130
<v Aaron van Wirdum>universe.

00:07:30.390 --> 00:07:35.330
<v Sjors Provoost>Yes, because you're alive. And so in historical examples, there have been hash

00:07:35.330 --> 00:07:39.210
<v Sjors Provoost>functions that were able to be broken earlier. See if I can find the list or you

00:07:39.210 --> 00:07:44.880
<v Sjors Provoost>might have it. Yes. So for example, there was MD5, I think. And

00:07:44.880 --> 00:07:50.480
<v Sjors Provoost>MD5 was supposed to be 128-bit of hash. So that's 2 to the power of 128 attempts.

00:07:50.480 --> 00:07:53.680
<v Sjors Provoost>That is a very long time. Not as long as 256.

00:07:54.780 --> 00:07:56.040
<v Aaron van Wirdum>Or the age of the universe.

00:07:56.180 --> 00:08:01.780
<v Sjors Provoost>But still, that's still age of the universe longer than that. But 256 is even longer.

00:08:02.060 --> 00:08:02.440
<v Aaron van Wirdum>Right.

00:08:02.760 --> 00:08:07.640
<v Sjors Provoost>Yeah, yeah. Because 128 bits is the security of a 12-word mnemonic. So if you

00:08:07.640 --> 00:08:10.880
<v Sjors Provoost>have 12 words written down, the 12-word seed, that is 128 bits.

00:08:11.620 --> 00:08:12.220
<v Aaron van Wirdum>Got it.

00:08:12.220 --> 00:08:17.500
<v Sjors Provoost>24 one is 256 bits, right so it's it should be very very secure. However it turns

00:08:17.500 --> 00:08:22.360
<v Sjors Provoost>out that somebody was able to find a collision with only two to the power 18

00:08:22.360 --> 00:08:23.380
<v Sjors Provoost>attempts.

00:08:23.380 --> 00:08:24.960
<v Aaron van Wirdum>Right I see.

00:08:24.960 --> 00:08:28.120
<v Sjors Provoost>That is roughly… Should not try to do that off my head, but I think it's less

00:08:28.120 --> 00:08:28.540
<v Sjors Provoost>than a million.

00:08:29.090 --> 00:08:33.070
<v Aaron van Wirdum>Right. So in that case, the hash function is considered broken.

00:08:33.210 --> 00:08:36.570
<v Sjors Provoost>It's completely broken because if you can, you know, brute force a million

00:08:36.570 --> 00:08:41.090
<v Sjors Provoost>different words on a computer, like a million different passwords to guess what

00:08:41.090 --> 00:08:43.890
<v Sjors Provoost>the hash means, that's nothing. You can do that in a very short time.

00:08:44.230 --> 00:08:48.710
<v Aaron van Wirdum>Yeah. And you just use the word brute force. Is that the only way to break

00:08:48.710 --> 00:08:54.440
<v Aaron van Wirdum>a hash function in this way, or in this is well…

00:08:54.440 --> 00:08:55.480
<v Aaron van Wirdum>Or can you also…

00:08:55.480 --> 00:08:59.100
<v Sjors Provoost>Brute force should not help you at all, right because that should take you the

00:08:59.100 --> 00:09:02.400
<v Sjors Provoost>age of the universe. No but it's usually combination with some trick right,

00:09:02.400 --> 00:09:05.100
<v Sjors Provoost>whatever that trick is and then brute force.

00:09:05.100 --> 00:09:09.740
<v Aaron van Wirdum>Right yeah that was going to be my question indeed. So there's a more pointed way

00:09:09.740 --> 00:09:13.620
<v Aaron van Wirdum>to try and break it. You're you're using some kind of strategy to break it then.

00:09:13.620 --> 00:09:17.000
<v Sjors Provoost>Yeah but you're still probably brute force looking but you have a better idea

00:09:17.000 --> 00:09:17.520
<v Sjors Provoost>where to look.

00:09:17.900 --> 00:09:23.800
<v Aaron van Wirdum>Right, got it. Is this the only or at least the main failure

00:09:23.800 --> 00:09:26.880
<v Aaron van Wirdum>mode or failure model of a hash function?

00:09:27.430 --> 00:09:31.410
<v Sjors Provoost>Yeah, that's when the hash function itself would be considered a failure, right?

00:09:31.690 --> 00:09:36.010
<v Sjors Provoost>But there are ways that you can use hashes that make you more prone to failure.

00:09:36.010 --> 00:09:40.350
<v Sjors Provoost>So for example there are websites that store passwords. Well they store they

00:09:40.350 --> 00:09:43.230
<v Sjors Provoost>don't store the password, that's really bad, but there are websites that store

00:09:43.230 --> 00:09:44.290
<v Sjors Provoost>the hash of a password.

00:09:44.290 --> 00:09:45.070
<v Aaron van Wirdum>Yeah right.

00:09:45.070 --> 00:09:48.710
<v Sjors Provoost>And now, let's say that that hash is not very good or even if it is very good

00:09:48.710 --> 00:09:53.230
<v Sjors Provoost>actually, somebody could make something called a rainbow table. So somebody would

00:09:53.230 --> 00:09:57.030
<v Sjors Provoost>say, well, what if the [unclear] password is hello? What if the password is hello

00:09:57.030 --> 00:10:01.510
<v Sjors Provoost>too? And they calculate the hash for each of these passwords. And then if you

00:10:01.510 --> 00:10:05.850
<v Sjors Provoost>find a leaked database with all these passwords, you can very quickly guess which

00:10:05.850 --> 00:10:09.050
<v Sjors Provoost>password belongs to which hash because you have this lookup table.

00:10:10.090 --> 00:10:14.770
<v Aaron van Wirdum>Right. It's basically you're just entering passwords yourself, seeing what the

00:10:14.770 --> 00:10:16.930
<v Aaron van Wirdum>hash is, and then remembering that.

00:10:18.350 --> 00:10:23.310
<v Aaron van Wirdum>If someone pops up using that hash as a password, then you can link the two, right?

00:10:23.310 --> 00:10:27.950
<v Sjors Provoost>Yeah, and that's not a mistake in the hash function. That's just the way that

00:10:27.950 --> 00:10:31.130
<v Sjors Provoost>you're using it. And the solution to that is called a salt, which means that

00:10:31.130 --> 00:10:36.030
<v Sjors Provoost>every time you store a hash, before you do that, you add something to it, to the

00:10:36.030 --> 00:10:40.310
<v Sjors Provoost>original text, like just the word salt or something, or one, two, three, four,

00:10:40.330 --> 00:10:45.520
<v Sjors Provoost>and then you hash it. And then that means that these tables are of no use.

00:10:45.960 --> 00:10:46.440
<v Aaron van Wirdum>Right.

00:10:46.680 --> 00:10:52.000
<v Sjors Provoost>Which means the attacker will have to guess a password and then do this

00:10:52.000 --> 00:10:54.300
<v Sjors Provoost>calculation. It just makes it more work for the attacker.

00:10:54.800 --> 00:10:59.300
<v Aaron van Wirdum>So this reminds me of something that I've been wondering about for a while.

00:11:00.780 --> 00:11:05.400
<v Aaron van Wirdum>And somehow I think this is going to be, well, let's see. So I've always wondered

00:11:05.400 --> 00:11:08.920
<v Aaron van Wirdum>about this and I've never thought about it for much longer than 10 seconds, but

00:11:08.920 --> 00:11:14.860
<v Aaron van Wirdum>maybe you have the answer. So when I enter a password, like I'm creating

00:11:14.860 --> 00:11:19.120
<v Aaron van Wirdum>a new account on a website and I'm entering my password there. And then the

00:11:19.120 --> 00:11:23.660
<v Aaron van Wirdum>website tells me, no, no, that password is no good because you need to use a

00:11:23.660 --> 00:11:26.880
<v Aaron van Wirdum>capital letter and you need to use the number and the special, whatever.

00:11:28.600 --> 00:11:33.700
<v Aaron van Wirdum>If the website is only getting my hash, then how do they know I'm not using a

00:11:33.700 --> 00:11:36.280
<v Aaron van Wirdum>capital letter or a number or any of that?

00:11:36.560 --> 00:11:40.660
<v Sjors Provoost>Well, if you're really lucky, then your browser is actually doing these checks.

00:11:41.020 --> 00:11:46.200
<v Sjors Provoost>But usually, unfortunately, sadly, you are sending the actual password to the

00:11:46.200 --> 00:11:50.580
<v Sjors Provoost>server. And the server is looking at that password, comparing it. Well, when

00:11:50.580 --> 00:11:53.980
<v Sjors Provoost>there's a new password, it's just looking at the password. And then it tells you

00:11:53.980 --> 00:11:54.640
<v Sjors Provoost>what's wrong with it.

00:11:55.500 --> 00:12:00.600
<v Aaron van Wirdum>So they're storing it in a hash ideally, but the first time you're creating your

00:12:00.600 --> 00:12:04.480
<v Aaron van Wirdum>account, you're actually sending them your text password.

00:12:04.780 --> 00:12:05.980
<v Sjors Provoost>Yeah, and every time you log in.

00:12:06.610 --> 00:12:11.170
<v Aaron van Wirdum>That is sort of the easy answer to my question, and I was hoping that there was a

00:12:11.170 --> 00:12:16.850
<v Aaron van Wirdum>more sophisticated solution. I was hoping they had a more sophisticated way of

00:12:16.850 --> 00:12:19.830
<v Aaron van Wirdum>dealing with that, but basically you're just trusting them to not.

00:12:20.070 --> 00:12:24.290
<v Sjors Provoost>I'm sure there are theoretically better ways to do this, but I don't think

00:12:24.290 --> 00:12:26.610
<v Sjors Provoost>they're used. At least they're usually not used.

00:12:27.210 --> 00:12:31.630
<v Aaron van Wirdum>Okay well this was a little bit of an off-topic question. Let's move on to the

00:12:31.630 --> 00:12:36.770
<v Aaron van Wirdum>probably more most important question of the of this entire episode here it

00:12:36.770 --> 00:12:42.470
<v Aaron van Wirdum>comes. So sure what actually… So we've now explained what a

00:12:42.470 --> 00:12:48.390
<v Aaron van Wirdum>hash does, but how does a hash do it? How does a hash

00:12:48.390 --> 00:12:52.130
<v Aaron van Wirdum>function actually do it? Like what's going on? What's the magic sauce?

00:12:52.130 --> 00:12:57.590
<v Sjors Provoost>yes. Well, it really does, to me, just looks like magic. So what happens is every

00:12:57.590 --> 00:13:00.710
<v Sjors Provoost>piece of text that you put into a hash function, you can just represent as a

00:13:00.710 --> 00:13:05.480
<v Sjors Provoost>series of zeros and ones. Basically bits. And then what happens is the hash

00:13:05.480 --> 00:13:10.980
<v Sjors Provoost>function will take little chunks of it. So we'll cut it into chunks, say, of 64

00:13:10.980 --> 00:13:15.680
<v Sjors Provoost>bits. It will cut the whole text in 64-bit chunks. And then it will say, okay,

00:13:15.700 --> 00:13:19.040
<v Sjors Provoost>for each chunk, I'm going to look at the first bit and I'm going to flip it

00:13:19.040 --> 00:13:22.720
<v Sjors Provoost>around and move it to the third position. And then I'm going to take the second

00:13:22.720 --> 00:13:26.260
<v Sjors Provoost>bit and I'm going to flip that around twice and move it to the first position.

00:13:26.460 --> 00:13:29.660
<v Sjors Provoost>And I'm going to take the third bit and I'm going to... Not flip it around, but

00:13:29.660 --> 00:13:34.820
<v Sjors Provoost>compare it to the first bit and say, I want the inverse of the two bits added up

00:13:34.820 --> 00:13:38.640
<v Sjors Provoost>together or something like that. So you're basically just doing this random,

00:13:38.920 --> 00:13:44.040
<v Sjors Provoost>well, not random, but specifically designed way of scrambling the original text.

00:13:44.040 --> 00:13:50.200
<v Sjors Provoost>And you repeat that for every 64-bit chunk. And that results in this this hash.

00:13:50.200 --> 00:13:54.780
<v Aaron van Wirdum>Right so this was in this is what I mentioned at the start of the episode this

00:13:54.780 --> 00:13:57.700
<v Aaron van Wirdum>was for me kind of probably the most surprising thing but…

00:13:57.700 --> 00:14:00.320
<v Sjors Provoost>It looks very much like sorcery or like you know whatever.

00:14:00.320 --> 00:14:05.120
<v Aaron van Wirdum>Well but the thing is it really isn't. Like it's really just a design that was

00:14:05.120 --> 00:14:11.120
<v Aaron van Wirdum>designed by someone with the specific intent of just shoveling

00:14:11.120 --> 00:14:13.840
<v Aaron van Wirdum>bits around in a specific way.

00:14:14.260 --> 00:14:19.820
<v Sjors Provoost>Yeah, but in terms of design, it's not like they have an absolute formula of how

00:14:19.820 --> 00:14:23.500
<v Sjors Provoost>to make something random. It's just that if you do these operations, people have

00:14:23.500 --> 00:14:26.160
<v Sjors Provoost>found that that is enough to make it really random.

00:14:27.250 --> 00:14:32.290
<v Aaron van Wirdum>Right. Yeah. In my mind, that was some sort of elegant math trick or something.

00:14:32.450 --> 00:14:36.770
<v Aaron van Wirdum>But when I was looking into it more closely, it really seemed like more

00:14:36.770 --> 00:14:42.750
<v Aaron van Wirdum>mechanical. It is a designed algorithm by someone

00:14:42.750 --> 00:14:48.630
<v Aaron van Wirdum>that does something deterministically, but then the results

00:14:48.630 --> 00:14:52.290
<v Aaron van Wirdum>should be random as far as we can hope.

00:14:52.770 --> 00:14:56.110
<v Sjors Provoost>Well, it's predictably random, right? It's pseudo-random, because for anything

00:14:56.110 --> 00:14:59.410
<v Sjors Provoost>that goes in, you know exactly what's going to come out. So in that sense, it's

00:14:59.410 --> 00:15:04.670
<v Sjors Provoost>not random, but it looks random if you plot it, for example. If you represent the

00:15:04.670 --> 00:15:09.910
<v Sjors Provoost>output as a number, then on a chart, then the number might be 1, and then the

00:15:09.910 --> 00:15:14.250
<v Sjors Provoost>number might be 256, and then the number might be 128, and that should look

00:15:14.250 --> 00:15:15.970
<v Sjors Provoost>completely random. It should look like noise.

00:15:16.190 --> 00:15:21.210
<v Aaron van Wirdum>Right, so that's the way to test it. You basically chart out the results and...

00:15:21.670 --> 00:15:24.570
<v Aaron van Wirdum>Just by looking at the chart, it should look random enough.

00:15:24.770 --> 00:15:27.350
<v Sjors Provoost>Exactly. I'm sure there's a more mathematical way to prove that.

00:15:27.490 --> 00:15:30.170
<v Aaron van Wirdum>I guess so, yeah. But that's how you prove it, right?

00:15:31.500 --> 00:15:36.420
<v Aaron van Wirdum>Okay, and so there have been a number of hash functions.

00:15:38.050 --> 00:15:40.450
<v Aaron van Wirdum>So which one does Bitcoin use?

00:15:40.770 --> 00:15:44.950
<v Sjors Provoost>Well, Bitcoin uses at least two or three. The most important one, I would say, is

00:15:44.950 --> 00:15:48.130
<v Sjors Provoost>called SHA-256, which is part of the SHA-2 family.

00:15:49.300 --> 00:15:51.680
<v Aaron van Wirdum>Yeah, what does SHA stand for, Sjors?

00:15:52.290 --> 00:15:54.550
<v Sjors Provoost>If you had asked me that earlier, I would have told you.

00:15:54.550 --> 00:15:59.530
<v Aaron van Wirdum>Well, I can tell you because I didn't know either, but it just stands for secure

00:15:59.530 --> 00:16:00.810
<v Aaron van Wirdum>hash algorithm.

00:16:01.070 --> 00:16:02.070
<v Sjors Provoost>Okay, that's impressive.

00:16:04.200 --> 00:16:08.400
<v Aaron van Wirdum>The little nuggets of knowledge you get from this podcast.

00:16:08.580 --> 00:16:10.480
<v Sjors Provoost>And that proves that it is secure.

00:16:10.620 --> 00:16:11.120
<v Aaron van Wirdum>There you go.

00:16:11.280 --> 00:16:15.360
<v Sjors Provoost>Well, we'll get to that there's such a thing as a non-secure hash, which is not

00:16:15.360 --> 00:16:20.600
<v Sjors Provoost>always a bad thing. But yeah, the SHA-256 one is important. It basically means

00:16:20.600 --> 00:16:26.240
<v Sjors Provoost>that whatever you throw into it, you'll get back 256 bits of data.

00:16:26.800 --> 00:16:32.000
<v Sjors Provoost>And that happens to be this, well, the size of a transaction identifier, but also

00:16:32.000 --> 00:16:35.780
<v Sjors Provoost>the size of a block hash because a block hash is the SHA-256 or actually the

00:16:35.780 --> 00:16:40.880
<v Sjors Provoost>double SHA-256. So you just do it twice of a block, of the contents of a block.

00:16:40.880 --> 00:16:45.740
<v Aaron van Wirdum>Okay before we get because that will be the next and last part of the episode I

00:16:45.740 --> 00:16:50.690
<v Aaron van Wirdum>guess is how hashes are used in Bitcoin so we'll get there in one minute. Okay

00:16:50.690 --> 00:16:55.750
<v Aaron van Wirdum>but very briefly before we get there can we… So there have been several hash

00:16:55.750 --> 00:17:01.530
<v Aaron van Wirdum>functions since so when was the first hash function introduced

00:17:01.530 --> 00:17:02.050
<v Aaron van Wirdum>invented?

00:17:02.050 --> 00:17:07.530
<v Sjors Provoost>As far as I know in the 1970s but I haven't done super deep research, but it's

00:17:07.530 --> 00:17:12.290
<v Sjors Provoost>not that old. So the I think the general idea was known or suspected that there

00:17:12.290 --> 00:17:17.330
<v Sjors Provoost>are mathematical operations which this is that will take some input and will

00:17:17.330 --> 00:17:22.110
<v Sjors Provoost>produce predictably garbage output and that you cannot go back from the output to

00:17:22.110 --> 00:17:23.550
<v Sjors Provoost>the input so it's a one-way function.

00:17:23.550 --> 00:17:27.890
<v Aaron van Wirdum>Hang on you just use the term one-way function. So one-way function is an

00:17:27.890 --> 00:17:28.730
<v Aaron van Wirdum>umbrella term

00:17:29.970 --> 00:17:35.510
<v Aaron van Wirdum>for mathematical tricks, functions that are easy to calculate in one way and

00:17:35.510 --> 00:17:36.890
<v Aaron van Wirdum>harder in the opposite direction.

00:17:36.890 --> 00:17:40.910
<v Sjors Provoost>I would say impossible in the other direction. So this is distinct from the

00:17:40.910 --> 00:17:45.650
<v Sjors Provoost>elliptic curve cryptography where it's very hard to go one way. So it's very easy

00:17:45.650 --> 00:17:49.950
<v Sjors Provoost>to go from a public key to a... Sorry, it's very easy to go from a private key to

00:17:49.950 --> 00:17:53.570
<v Sjors Provoost>a public key. It's very hard to go from a public key to a private key, but

00:17:53.570 --> 00:17:54.850
<v Sjors Provoost>mathematically it's possible.

00:17:55.030 --> 00:17:56.050
<v Aaron van Wirdum>Wait, so wouldn't you...

00:17:56.050 --> 00:17:57.690
<v Sjors Provoost>But a hash, it is not possible to go back.

00:17:58.560 --> 00:18:03.420
<v Aaron van Wirdum>Right, but this is just how we apply terms. Maybe this is not the most

00:18:03.420 --> 00:18:07.820
<v Aaron van Wirdum>interesting thing, but wouldn't you consider both one-way functions? Like

00:18:07.820 --> 00:18:11.880
<v Aaron van Wirdum>wouldn't one-way function be the umbrella term for both of these things?

00:18:11.790 --> 00:18:14.640
<v Sjors Provoost>It could be. I don't know if mathematicians look at it that way, so you'd have to

00:18:14.640 --> 00:18:18.740
<v Sjors Provoost>ask them. I mean, they are different in the sense that one of them you can, in

00:18:18.740 --> 00:18:23.620
<v Sjors Provoost>theory, go back from a mathematical point of view. It just goes both ways. And

00:18:23.620 --> 00:18:25.520
<v Sjors Provoost>these hash functions, really, they don't go back.

00:18:27.060 --> 00:18:32.820
<v Aaron van Wirdum>Yeah at least yeah okay got it. So a but anyway so a one-way function

00:18:32.820 --> 00:18:38.520
<v Aaron van Wirdum>is an umbrella term at least that's how you use it for mathematical functions

00:18:38.520 --> 00:18:43.340
<v Aaron van Wirdum>that can only go one way and then hash is a good example of that.

00:18:43.340 --> 00:18:46.820
<v Sjors Provoost>Yeah and a very useful example of that, right because a simple one-way function

00:18:46.820 --> 00:18:52.690
<v Sjors Provoost>could be take the take the input and then output zero always that's that's one way.

00:18:52.690 --> 00:18:54.030
<v Aaron van Wirdum>Sure right.

00:18:54.030 --> 00:18:55.070
<v Sjors Provoost>Not useful yeah.

00:18:55.740 --> 00:19:01.340
<v Aaron van Wirdum>Okay, yeah. As far as I know, one-way functions have been sort of

00:19:01.340 --> 00:19:06.790
<v Aaron van Wirdum>considered and discussed within the circles of cryptographers since the

00:19:06.790 --> 00:19:12.230
<v Aaron van Wirdum>early 70s. It's also what inspired Diffie and Hellman to come up with public key

00:19:12.230 --> 00:19:17.990
<v Aaron van Wirdum>cryptography. And then the first hash functions were like the late 70s.

00:19:18.190 --> 00:19:23.910
<v Aaron van Wirdum>And that evolved from, I think the first one, was it called MDA?

00:19:24.350 --> 00:19:28.310
<v Aaron van Wirdum>Was that, am I saying it right? MDA, yeah. I think that's, that's what I had in

00:19:28.310 --> 00:19:31.080
<v Aaron van Wirdum>mind. Possibly the first one or the oldest one.

00:19:31.080 --> 00:19:34.640
<v Sjors Provoost>It could be much older I think because that's the 1990s and I think there were

00:19:34.640 --> 00:19:36.180
<v Sjors Provoost>some ones in the 1970s too.

00:19:36.180 --> 00:19:42.060
<v Aaron van Wirdum>But okay possibly but then… So where I'm getting at really is so

00:19:42.060 --> 00:19:47.240
<v Aaron van Wirdum>where does Bitcoin's hashing algorithm come from?

00:19:47.240 --> 00:19:52.940
<v Aaron van Wirdum>Who designed it? How did it develop over the years, because it

00:19:52.940 --> 00:19:58.440
<v Aaron van Wirdum>started with MDA I think somehow and then it evolved into SHA.

00:19:59.810 --> 00:20:03.310
<v Sjors Provoost>Yeah, I mean, it may have started, like I said, with something even older. But

00:20:03.310 --> 00:20:07.590
<v Sjors Provoost>generally what happens is somebody designs this hash function in the way we just

00:20:07.590 --> 00:20:11.530
<v Sjors Provoost>described. And then it turns out there's a collision or it's too easy to find

00:20:11.530 --> 00:20:15.910
<v Sjors Provoost>collisions. And so somebody tweaks, usually just tweaks it a little bit, like

00:20:15.910 --> 00:20:20.490
<v Sjors Provoost>adds one little operation that flips another bit. You know, it takes the left bit

00:20:20.490 --> 00:20:24.790
<v Sjors Provoost>and moves it to the right. Just a slight change and then hope, praise that it

00:20:24.790 --> 00:20:29.770
<v Sjors Provoost>works better. That seems to be, I'm sure I'm not doing it justice here, but

00:20:29.770 --> 00:20:34.030
<v Sjors Provoost>generally they're constantly based on each other. So the other one that's in

00:20:34.030 --> 00:20:34.710
<v Sjors Provoost>Bitcoin is...

00:20:34.710 --> 00:20:39.970
<v Aaron van Wirdum>I think MDA was designed or at least based on the design by

00:20:39.970 --> 00:20:44.350
<v Aaron van Wirdum>Ronald Rivest, which is also the R in RSA.

00:20:45.570 --> 00:20:51.330
<v Aaron van Wirdum>One of the three designers of the RSA algorithm. And then that

00:20:51.550 --> 00:20:57.280
<v Aaron van Wirdum>design inspired SHA. And wasn't SHA... Designed by the NSA?

00:20:58.340 --> 00:21:00.020
<v Aaron van Wirdum>Didn't they have a hand in the design?

00:21:00.300 --> 00:21:04.360
<v Sjors Provoost>They always have a hand in all these things. I don't know those specific details

00:21:04.360 --> 00:21:06.340
<v Sjors Provoost>who was involved with what. What I do know is that...

00:21:06.340 --> 00:21:10.180
<v Aaron van Wirdum>No, it is. Because while we're discussing this, I have my phone in my hand and

00:21:10.180 --> 00:21:13.620
<v Aaron van Wirdum>I'm scrolling through Wikipedia. I did this before the show, but I'm just making

00:21:13.620 --> 00:21:16.280
<v Aaron van Wirdum>sure. Yeah, no, it was designed by the NSA.

00:21:16.800 --> 00:21:16.960
<v Sjors Provoost>Okay.

00:21:17.040 --> 00:21:19.120
<v Aaron van Wirdum>Is this something we should be worried about?

00:21:19.280 --> 00:21:21.260
<v Sjors Provoost>This was the pre-Snowden NSA, right?

00:21:22.580 --> 00:21:27.440
<v Aaron van Wirdum>I mean, it was the NSA that was going to war on encryption in the 90s.

00:21:28.200 --> 00:21:31.100
<v Sjors Provoost>Well, you wouldn't go to war over something if you thought it didn't work.

00:21:33.090 --> 00:21:37.610
<v Sjors Provoost>But that wasn't about hash functions, I think. That was mostly about public key encryption.

00:21:37.730 --> 00:21:38.250
<v Aaron van Wirdum>Yeah, it was.

00:21:38.530 --> 00:21:42.750
<v Sjors Provoost>But what I was trying to say is that the Europeans didn't trust the NSA, and so

00:21:42.750 --> 00:21:47.370
<v Sjors Provoost>they came up with this RIPEMD, or I don't know how you would pronounce it, but it

00:21:47.370 --> 00:21:52.390
<v Sjors Provoost>is basically a variation of SHA-2 or SHA, where they just... If you read the

00:21:52.390 --> 00:21:56.370
<v Sjors Provoost>original paper, you can see, oh, yeah, we changed a few bit flips here and there,

00:21:56.390 --> 00:21:59.190
<v Sjors Provoost>but we didn't want to deviate too much from the original algorithm because we

00:21:59.190 --> 00:22:04.270
<v Sjors Provoost>know it works. But one of the problems is, how do you pick these little bits and

00:22:04.270 --> 00:22:09.950
<v Sjors Provoost>things and operations? It looks very arbitrary. And that means that if

00:22:09.950 --> 00:22:14.210
<v Sjors Provoost>you don't trust the person who made it, you might be worried that they build in

00:22:14.210 --> 00:22:18.030
<v Sjors Provoost>some sort of sneaky backdoor, some vulnerability that they know, but you don't

00:22:18.030 --> 00:22:22.230
<v Sjors Provoost>know. And then one way to defend against that is, Well, there's two things. One

00:22:22.230 --> 00:22:25.430
<v Sjors Provoost>is that the NSA would say, well, this is how we, you know, how we designed it.

00:22:25.510 --> 00:22:30.190
<v Sjors Provoost>And that's all arbitrary. But here's like a series of numbers of like one plus

00:22:30.190 --> 00:22:34.350
<v Sjors Provoost>five plus 17 plus like 15 different, like a very elegant looking series of

00:22:34.350 --> 00:22:38.870
<v Sjors Provoost>numbers and say, well, if you just add this to it and then it still works. And

00:22:38.870 --> 00:22:43.130
<v Sjors Provoost>that kind of proves like, well, these numbers are so elegant that they probably

00:22:43.130 --> 00:22:48.220
<v Sjors Provoost>were chosen randomly or something. That's one way. And the other thing is you

00:22:48.220 --> 00:22:52.410
<v Sjors Provoost>just change it— that they were… Or that the end result could not have been

00:22:52.410 --> 00:22:56.670
<v Sjors Provoost>tampered with. Because you're saying you're adding so much stuff to it that is

00:22:56.670 --> 00:22:59.930
<v Sjors Provoost>very hard, that makes it more difficult to design a malicious system. But it's

00:22:59.930 --> 00:23:03.790
<v Sjors Provoost>still a bit hand-wavy. And the other thing you would do is what the Europeans

00:23:03.790 --> 00:23:07.210
<v Sjors Provoost>did, I guess. They just changed it a bit. Not too much, but a little bit, so that

00:23:07.210 --> 00:23:09.210
<v Sjors Provoost>any backdoor that might have been in there would be broken.

00:23:09.570 --> 00:23:09.770
<v Aaron van Wirdum>Right.

00:23:11.210 --> 00:23:11.570
<v Aaron van Wirdum>Okay.

00:23:13.160 --> 00:23:18.220
<v Aaron van Wirdum>Let's move on to... what this podcast is

00:23:18.220 --> 00:23:24.040
<v Aaron van Wirdum>or at least promises to be about in in the title… How does

00:23:24.040 --> 00:23:25.140
<v Aaron van Wirdum>hashes…

00:23:26.400 --> 00:23:32.680
<v Aaron van Wirdum>A hash is really maybe the core fundamental building block for Bitcoin, wouldn't you say?

00:23:32.960 --> 00:23:34.560
<v Sjors Provoost>Well, it's certainly quite useful.

00:23:35.420 --> 00:23:40.240
<v Aaron van Wirdum>It's used here and there. So where are hashes used? How

00:23:40.240 --> 00:23:42.980
<v Aaron van Wirdum>do hashes help Bitcoin?

00:23:43.180 --> 00:23:47.300
<v Sjors Provoost>Well, for one thing, every block, if you take the entire contents of the block,

00:23:47.520 --> 00:23:52.190
<v Sjors Provoost>that's hashed. And, you know, descriptively call it the block hash.

00:23:53.310 --> 00:23:57.370
<v Sjors Provoost>And it turns out that this hash of the block, well, first of all, the block

00:23:57.370 --> 00:24:01.710
<v Sjors Provoost>itself consists of transactions. And so every transaction also has a hash. So

00:24:01.710 --> 00:24:02.690
<v Sjors Provoost>that's two use cases.

00:24:02.850 --> 00:24:03.770
<v Aaron van Wirdum>Which is its transaction ID.

00:24:04.050 --> 00:24:09.550
<v Sjors Provoost>Yeah. Now blocks link to each other. So one block links to the previous block.

00:24:09.730 --> 00:24:13.180
<v Sjors Provoost>And the way it links to that block is using the hash of that block. Because the

00:24:13.180 --> 00:24:16.240
<v Sjors Provoost>hash itself of a block is not in the blockchain. The block is in the blockchain.

00:24:16.600 --> 00:24:19.460
<v Sjors Provoost>And then your computer just reads the block and then figures out, okay, this is

00:24:19.460 --> 00:24:22.760
<v Sjors Provoost>the hash. And so the next block will mention that hash, and that's how you know

00:24:22.760 --> 00:24:26.660
<v Sjors Provoost>that the next block actually builds on top of the first one. This, again, is why

00:24:26.660 --> 00:24:30.440
<v Sjors Provoost>you really don't want collisions, right? Because if it was possible to create

00:24:30.440 --> 00:24:34.440
<v Sjors Provoost>another block with very different transactions in it with the same hash, you

00:24:34.440 --> 00:24:35.040
<v Sjors Provoost>would have a problem.

00:24:38.920 --> 00:24:42.320
<v Aaron van Wirdum>Right. What would be the problem exactly?

00:24:42.680 --> 00:24:47.980
<v Sjors Provoost>Well, let's say the first block creates 25 Bitcoin and sends it to you.

00:24:48.610 --> 00:24:52.150
<v Sjors Provoost>And everybody accepts that block and builds on top of it. And that means you will

00:24:52.150 --> 00:24:56.270
<v Sjors Provoost>have that Bitcoin forever, essentially, until you decide to move it. But now I

00:24:56.270 --> 00:25:02.030
<v Sjors Provoost>come in and I create a new block where that 25 Bitcoin

00:25:02.030 --> 00:25:03.170
<v Sjors Provoost>actually goes to me.

00:25:05.280 --> 00:25:10.680
<v Sjors Provoost>I find a way to produce the same hash of the block, which is impossible. But if I

00:25:10.680 --> 00:25:15.000
<v Sjors Provoost>were able to produce the same hash, then I could send everybody else my block and

00:25:15.000 --> 00:25:19.560
<v Sjors Provoost>they would look at the hash and say, okay, that's definitely a valid hash of that

00:25:19.560 --> 00:25:23.920
<v Sjors Provoost>second block in the blockchain. So all the blocks are still connected. So that

00:25:23.920 --> 00:25:26.700
<v Sjors Provoost>means that existing users wouldn't be tricked in this case, right? Because they

00:25:26.700 --> 00:25:30.140
<v Sjors Provoost>would already have the block and they have no reason to replace it. But any new

00:25:30.140 --> 00:25:33.560
<v Sjors Provoost>person downloading the blockchain would be confused because they would just get

00:25:33.560 --> 00:25:38.720
<v Sjors Provoost>the fake block. But it's not fake in any sense that the Bitcoin software cares

00:25:38.720 --> 00:25:42.780
<v Sjors Provoost>about because it would have the same hash. So there would be two different blocks

00:25:42.780 --> 00:25:46.440
<v Sjors Provoost>with the same hash with very different events. And that would be a complete

00:25:46.440 --> 00:25:46.880
<v Sjors Provoost>disaster.

00:25:47.240 --> 00:25:53.210
<v Aaron van Wirdum>Right. So hashes are used to link blocks together into a blockchain. And then

00:25:53.210 --> 00:25:57.410
<v Aaron van Wirdum>the other thing about a block hash is that it also...

00:25:58.790 --> 00:26:01.910
<v Aaron van Wirdum>determines whether the block itself is even valid in the first place.

00:26:02.170 --> 00:26:03.330
<v Sjors Provoost>Well, that's the proof of work part.

00:26:03.590 --> 00:26:03.790
<v Aaron van Wirdum>Right.

00:26:03.970 --> 00:26:09.210
<v Sjors Provoost>So what happens is that this hash is just 256 bits. And so what you can do, and

00:26:09.210 --> 00:26:13.650
<v Sjors Provoost>that's what proof of work essentially does, is it says the first several bits

00:26:13.650 --> 00:26:17.670
<v Sjors Provoost>need to be zero, or roughly, like the whole hash needs to be lower than a certain

00:26:17.670 --> 00:26:21.690
<v Sjors Provoost>number, but it doesn't really matter. You could see it as, okay, so we're going

00:26:21.690 --> 00:26:26.710
<v Sjors Provoost>to require that the first 10 bits of the block are zero.

00:26:27.490 --> 00:26:31.110
<v Sjors Provoost>And then you can, because the only way to figure out what a hash is is brute

00:26:31.110 --> 00:26:35.990
<v Sjors Provoost>force, the only way to get 10 zeros is to just try two to the power of 10

00:26:35.990 --> 00:26:41.190
<v Sjors Provoost>different things. And so the thing you would change in the block, you'd have to

00:26:41.190 --> 00:26:44.270
<v Sjors Provoost>change something in the block to get a different hash. And so one of the things

00:26:44.270 --> 00:26:46.370
<v Sjors Provoost>you would change is the nonce in the header of the block.

00:26:47.050 --> 00:26:48.390
<v Aaron van Wirdum>Which is just a random number.

00:26:49.150 --> 00:26:51.370
<v Sjors Provoost>Yeah, exactly. That's just a random number.

00:26:51.870 --> 00:26:55.090
<v Aaron van Wirdum>Add a random number to a block and then you get a different hash and then you

00:26:55.090 --> 00:26:58.650
<v Aaron van Wirdum>check if the hash is valid. If not, you try again with a new random number.

00:26:58.850 --> 00:27:01.910
<v Sjors Provoost>Yeah, exactly. And the one thing that's in the block is the timestamp. So every

00:27:01.910 --> 00:27:06.650
<v Sjors Provoost>second that timestamp changes as well. So there's a couple of things there and

00:27:06.650 --> 00:27:09.570
<v Sjors Provoost>there's some trouble around it that we don't have to go into. But that's

00:27:09.570 --> 00:27:14.150
<v Sjors Provoost>basically how the proof of work works. So it's using this fact that the hashes

00:27:14.150 --> 00:27:17.970
<v Sjors Provoost>are random, which means you cannot... There's no way to say I'm just going to put

00:27:17.970 --> 00:27:21.350
<v Sjors Provoost>10 zeros in front of this at the start of this hash and then figure out the rest

00:27:21.350 --> 00:27:22.590
<v Sjors Provoost>of the hash later. You can't do that.

00:27:23.010 --> 00:27:28.730
<v Aaron van Wirdum>Right. Okay. So that's blocks, transactions. One detail about transactions that's

00:27:28.730 --> 00:27:32.630
<v Aaron van Wirdum>maybe kind of interesting to mention before we move on is that the hash of a

00:27:32.630 --> 00:27:36.330
<v Aaron van Wirdum>transaction doesn't include the entire transaction, right? Because it doesn't

00:27:36.330 --> 00:27:38.010
<v Aaron van Wirdum>include the signature, most notably.

00:27:38.290 --> 00:27:39.130
<v Sjors Provoost>Not in SegWit, yeah.

00:27:39.430 --> 00:27:41.990
<v Aaron van Wirdum>Because the signature needs to sign.

00:27:43.110 --> 00:27:47.350
<v Sjors Provoost>Well, because we want to be compatible with old nodes. So as far as all the nodes

00:27:47.350 --> 00:27:51.900
<v Sjors Provoost>before SegWit is concerned, everything in the transaction is hashed. But as far

00:27:51.900 --> 00:27:52.960
<v Sjors Provoost>as SegWit is...

00:27:52.960 --> 00:27:58.640
<v Aaron van Wirdum>No, no, no. You can't... The signature was not hashed because then you

00:27:58.640 --> 00:28:00.420
<v Aaron van Wirdum>can't sign the transaction.

00:28:00.700 --> 00:28:05.360
<v Sjors Provoost>That's different. So the signature... So there's two hashes involved here. One is

00:28:05.360 --> 00:28:10.820
<v Sjors Provoost>what I was describing is to refer to another transaction. That's using the hash

00:28:10.820 --> 00:28:16.640
<v Sjors Provoost>and that covers the entire transaction. Well, minus the SegWit stuff at the moment.

00:28:16.820 --> 00:28:17.560
<v Aaron van Wirdum>Okay, yeah.

00:28:17.720 --> 00:28:20.840
<v Sjors Provoost>And then the transaction itself has a signature, but the signature, of course,

00:28:20.960 --> 00:28:26.440
<v Sjors Provoost>cannot refer to the signature itself. So in order to make a signature, you don't

00:28:26.440 --> 00:28:30.960
<v Sjors Provoost>take the hash of the transaction. You take certain chunks of the transaction and

00:28:30.960 --> 00:28:34.580
<v Sjors Provoost>leave the rest. You set it to zero, and then you sign that hash.

00:28:35.830 --> 00:28:40.810
<v Aaron van Wirdum>Right. So you take chunks out of the transaction, you hash that, and you sign that.

00:28:41.150 --> 00:28:41.470
<v Sjors Provoost>Yes.

00:28:41.670 --> 00:28:47.510
<v Aaron van Wirdum>And now the whole package is hashed again, which is referenced by

00:28:47.510 --> 00:28:49.190
<v Aaron van Wirdum>other transactions. Am I saying that right now?

00:28:49.430 --> 00:28:53.390
<v Sjors Provoost>Yeah. So other transactions don't refer to the SegWit part of a transaction.

00:28:53.530 --> 00:28:53.990
<v Aaron van Wirdum>Right, right, right.

00:28:54.070 --> 00:28:57.750
<v Sjors Provoost>But the way that's solved is because in the Coinbase of every block, there is a

00:28:57.750 --> 00:28:59.370
<v Sjors Provoost>hash that does refer to all these things.

00:28:59.610 --> 00:29:04.270
<v Aaron van Wirdum>Okay. So hash is actually used twice, even in a single transaction.

00:29:05.440 --> 00:29:07.280
<v Sjors Provoost>Yeah, in multiple ways. Yeah, exactly.

00:29:07.460 --> 00:29:12.760
<v Aaron van Wirdum>In multiple ways, yeah. Okay, so that's blocks, transactions, proof of work. I

00:29:12.760 --> 00:29:18.520
<v Aaron van Wirdum>think most people knew that or at least kind of knew that. But there's more

00:29:18.520 --> 00:29:24.180
<v Aaron van Wirdum>ways in which hashes are used. So it's used now in Taproot?

00:29:24.620 --> 00:29:29.420
<v Sjors Provoost>Well, maybe easier to say, well, yeah, in Taproot, that's right. If you have this

00:29:29.420 --> 00:29:33.260
<v Sjors Provoost>tree with multiple conditions, multiple ways that you can spend the script, that

00:29:33.260 --> 00:29:37.610
<v Sjors Provoost>tree uses hashes. And like go into a Merkle tree. We've described that in a

00:29:37.610 --> 00:29:38.070
<v Sjors Provoost>different episode.

00:29:38.210 --> 00:29:40.050
<v Aaron van Wirdum>Yeah, let's not get into the whole Merkle tree.

00:29:40.370 --> 00:29:44.130
<v Sjors Provoost>But that's where you have hashes. Again, SHA-256. Then you have addresses.

00:29:44.550 --> 00:29:48.310
<v Sjors Provoost>Originally, anyway, addresses you would start from a public key and then you

00:29:48.310 --> 00:29:53.830
<v Sjors Provoost>would take the SHA-256 hash or double SHA-256 hash of the public key. And then

00:29:53.830 --> 00:29:59.060
<v Sjors Provoost>you would take this European RIPEMD hash of that hash and that would be your address.

00:29:59.060 --> 00:30:04.580
<v Aaron van Wirdum>Oh that that in that part of Bitcoin or at least… Yeah that's where they used

00:30:04.580 --> 00:30:06.960
<v Aaron van Wirdum>we used Bitcoin used European…

00:30:06.960 --> 00:30:12.770
<v Sjors Provoost>Both and that may have been some like ah well I don't trust either thing by

00:30:12.770 --> 00:30:14.710
<v Sjors Provoost>Satoshi, I haven't read the history of why he did…

00:30:14.710 --> 00:30:18.070
<v Aaron van Wirdum>Oh actually Satoshi introduced that as far as I know.

00:30:18.070 --> 00:30:23.990
<v Sjors Provoost>Yes this address format has been in there from from the beginning But with

00:30:23.990 --> 00:30:26.370
<v Sjors Provoost>Taproot, there's no longer a hash involved in the address.

00:30:27.900 --> 00:30:33.580
<v Aaron van Wirdum>Okay. I see here in the notes that is, are hashes used in the random

00:30:33.580 --> 00:30:35.980
<v Aaron van Wirdum>number generation part of?

00:30:36.590 --> 00:30:37.490
<v Sjors Provoost>In general.

00:30:37.750 --> 00:30:39.790
<v Aaron van Wirdum>I guess that would be creating private keys.

00:30:40.010 --> 00:30:45.570
<v Sjors Provoost>Yeah. So in general, when you create the seed, the randomness that uses a random

00:30:45.570 --> 00:30:49.950
<v Sjors Provoost>number generator. And mostly that's done by your computer itself though there is

00:30:49.950 --> 00:30:54.770
<v Sjors Provoost>also some code in Bitcoin that adds some extra randomness and generally random

00:30:54.770 --> 00:30:59.110
<v Sjors Provoost>number generators use hash functions in all sorts of weird ways. Might be a

00:30:59.110 --> 00:31:03.770
<v Sjors Provoost>little bit out of scope, but the idea is like because the computer doesn't have a

00:31:03.770 --> 00:31:08.670
<v Sjors Provoost>way to actually throw dice so it needs to get randomness somehow, and what it

00:31:08.670 --> 00:31:14.220
<v Sjors Provoost>does tends to do is like it'll look at what time it is, it'll look what's on its

00:31:14.220 --> 00:31:18.200
<v Sjors Provoost>hard drive, which would be the result of many months of random things happening

00:31:18.200 --> 00:31:23.100
<v Sjors Provoost>to it. It might maybe look at the temperature sensor of the CPU or things like

00:31:23.100 --> 00:31:28.860
<v Sjors Provoost>that and then hash all those things and hash those things again. And that's where

00:31:28.860 --> 00:31:30.940
<v Sjors Provoost>the random numbers come from, more or less.

00:31:31.580 --> 00:31:31.980
<v Aaron van Wirdum>Right.

00:31:33.410 --> 00:31:37.170
<v Aaron van Wirdum>So you mentioned that something that your computer does and then the Bitcoin

00:31:37.170 --> 00:31:38.830
<v Aaron van Wirdum>software does it again?

00:31:39.070 --> 00:31:44.130
<v Sjors Provoost>Does a little bit more. Yeah, the idea is if you have some random data from one

00:31:44.130 --> 00:31:48.290
<v Sjors Provoost>source, you can mix it with random data from the other source. And as long as one

00:31:48.290 --> 00:31:52.030
<v Sjors Provoost>of those two sources is really random, you're fine. So it just makes it better.

00:31:52.170 --> 00:31:55.630
<v Sjors Provoost>If you have bad random data and you mix it with good random data, the result is

00:31:55.630 --> 00:31:56.930
<v Sjors Provoost>good random data.

00:31:59.790 --> 00:32:00.930
<v Aaron van Wirdum>Right. Anything else?

00:32:01.150 --> 00:32:05.170
<v Sjors Provoost>Well, yeah. The other thing is if you have a seed, so you start with the 12 word

00:32:05.170 --> 00:32:10.770
<v Sjors Provoost>mnemonic in order to go from that to individual keys that are derived from your

00:32:10.770 --> 00:32:13.350
<v Sjors Provoost>wallet, you know, unique addresses that uses hashes too.

00:32:13.490 --> 00:32:14.650
<v Aaron van Wirdum>How does it use hashes?

00:32:16.080 --> 00:32:21.620
<v Sjors Provoost>Well, it, it derives like the next key from it. And I think the

00:32:21.620 --> 00:32:25.360
<v Sjors Provoost>derivation involves a bunch of hashes inside of it to go from the private key to

00:32:25.360 --> 00:32:28.860
<v Sjors Provoost>the next private key. It's not just plus one. It's like plus the hash of

00:32:28.860 --> 00:32:30.840
<v Sjors Provoost>something, plus the hash of something else, right.

00:32:31.160 --> 00:32:35.600
<v Aaron van Wirdum>So each new private key is basically a hash of a previous private key.

00:32:36.840 --> 00:32:38.140
<v Sjors Provoost>Higher up in the tree, yeah.

00:32:38.300 --> 00:32:38.960
<v Aaron van Wirdum>Right, right.

00:32:39.890 --> 00:32:44.610
<v Sjors Provoost>And another place where we use it a little bit more fun is the address bucketing

00:32:44.610 --> 00:32:47.290
<v Sjors Provoost>system. We talked about Eclipse attacks many episodes ago.

00:32:47.610 --> 00:32:48.090
<v Aaron van Wirdum>Yeah.

00:32:48.190 --> 00:32:51.870
<v Sjors Provoost>And one of the things we described is that when a Bitcoin node learns about other

00:32:51.870 --> 00:32:57.040
<v Sjors Provoost>Bitcoin nodes, it has to store all these IP addresses of the other nodes. And it

00:32:57.040 --> 00:33:00.900
<v Sjors Provoost>doesn't store those in one giant list. It divides those over a bunch of buckets.

00:33:01.950 --> 00:33:06.990
<v Sjors Provoost>And the way to decide which IP address that you've gossiped around, which IP

00:33:06.990 --> 00:33:11.660
<v Sjors Provoost>address goes in which bucket also involves a hash function. So you take a hash of

00:33:11.660 --> 00:33:15.380
<v Sjors Provoost>the IP address and then you say, okay, if the hash is 1, it goes in bucket 1. If

00:33:15.380 --> 00:33:16.840
<v Sjors Provoost>the hash is 2, it goes in bucket 2, etc.

00:33:17.480 --> 00:33:22.200
<v Aaron van Wirdum>Right, so it's basically a way to just get a random number in that sense.

00:33:22.360 --> 00:33:26.240
<v Sjors Provoost>And in this case, the security of the random number is not that important. So you

00:33:26.240 --> 00:33:30.980
<v Sjors Provoost>don't need the secure hash algorithm, SHA. You can use a simpler hash function

00:33:30.980 --> 00:33:35.900
<v Sjors Provoost>that is faster, basically, because that's the trade-off. You can do hashes

00:33:35.900 --> 00:33:38.900
<v Sjors Provoost>faster, but then you're not going to get them perfectly random, but that's okay

00:33:38.900 --> 00:33:40.280
<v Sjors Provoost>for this purpose.

00:33:40.500 --> 00:33:42.580
<v Aaron van Wirdum>So which one does it use?

00:33:42.740 --> 00:33:46.300
<v Sjors Provoost>I think this one's called SipHash. I don't know what it stands for.

00:33:46.890 --> 00:33:48.730
<v Aaron van Wirdum>Is it designed for Bitcoin?

00:33:49.050 --> 00:33:49.870
<v Sjors Provoost>No, no, it's older.

00:33:50.170 --> 00:33:52.680
<v Aaron van Wirdum>Okay. This doesn't refer to sipa?

00:33:52.900 --> 00:33:53.260
<v Sjors Provoost>No.

00:33:53.600 --> 00:33:54.920
<v Aaron van Wirdum>Okay, just making sure.

00:33:57.260 --> 00:34:03.020
<v Aaron van Wirdum>Okay, so we've mentioned hashes are used in blocks, transactions,

00:34:03.820 --> 00:34:09.350
<v Aaron van Wirdum>proof of work, which is also part of blocks, but either way. Addresses,

00:34:09.930 --> 00:34:15.450
<v Aaron van Wirdum>Merkle trees, the random number generation, and...

00:34:15.920 --> 00:34:20.640
<v Sjors Provoost>Key derivation. It's used inside various cryptographic operations. So when you

00:34:20.640 --> 00:34:24.080
<v Sjors Provoost>make a signature, you're making a hash before you sign it.

00:34:26.990 --> 00:34:28.210
<v Aaron van Wirdum>Plenty of hash in Bitcoin.

00:34:28.970 --> 00:34:31.650
<v Sjors Provoost>Yep, it's everywhere. Okay, I think that's all, right?

00:34:31.910 --> 00:34:32.410
<v Aaron van Wirdum>I think so.

00:34:32.670 --> 00:34:34.710
<v Sjors Provoost>Thank you for listening to Bitcoin

00:34:34.710 --> 00:34:35.950
<v Aaron van Wirdum>Explained.

