[00:00.000 --> 00:06.540] Our next presentation by Kathy Yun. Implementing a zero-knowledge proof or how to write bullet [00:06.540 --> 00:10.000] proofs in Rust. Give it up. [00:21.740 --> 00:27.840] Hello, everyone. Thank you for being out here. To change gears a little bit, we're going [00:27.840 --> 00:33.280] to do some math together. It's going to be fun, hopefully. For some context, I'm Kathy. [00:33.280 --> 00:40.920] I worked with a really awesome team at Chain and Interstellar of Henry and Oleg. And together [00:40.920 --> 00:45.160] we implemented bullet proofs in Rust and built a bunch of protocols on top of that. [00:45.160 --> 00:50.060] And today I just want to share some of that journey so that hopefully you can learn, maybe, [00:50.060 --> 00:55.220] find it interesting, pick up some tips, and have fun. [00:55.380 --> 00:59.880] So the outline is that first I'll tell you a little bit about the story, how we came [00:59.880 --> 01:05.740] to decide on implementing bullet proofs and what tools we used. And then I'll look into [01:05.740 --> 01:09.900] the code. I'll show you a little code snippet from our range proof code. I'll tell you about [01:09.900 --> 01:15.260] what we were able to do because we implemented it in Rust. And I'll talk a little bit about [01:15.260 --> 01:19.320] what we built above and beyond using that protocol. [01:19.680 --> 01:25.700] So first, let's talk about motivation. Why do we care about zero knowledge proofs? Zero [01:25.700 --> 01:29.340] knowledge proofs have been around for a really long time, but they've been getting a lot [01:29.340 --> 01:35.540] of interest recently because of their application in blockchains for blockchain privacy. [01:36.080 --> 01:42.320] So what does this mean? And how is this useful? So in a blockchain transaction, we have, you [01:42.320 --> 01:46.240] know, some inputs, some outputs, and for a financial transaction, at least, you want [01:46.240 --> 01:51.000] to make sure that the sum of the inputs balance out with the sum of the outputs. So trivially, [01:51.000 --> 01:55.540] when it's not encrypted, you can do it just by adding and checking. So that's cool. But [01:55.540 --> 02:01.040] what if you want to encrypt or hide what your inputs and outputs are? So then it's a little [02:01.040 --> 02:06.720] bit more complicated. And one way that you can do this is by using an additively homomorphic [02:06.720 --> 02:12.720] commitment. And so in the Bulletproofs paper, and in a lot of confidential transaction formats, [02:12.720 --> 02:17.340] people use Peterson commitments. But basically, what this allows you to do is it allows you [02:17.340 --> 02:23.680] to check if the commitments to the underlying values add up. And if they do, if A plus B [02:23.680 --> 02:28.380] equals C plus D, then you know that the underlying inputs add up to be equal to the underlying [02:28.380 --> 02:34.080] outputs with very high probability. So that's nice. But as I noted, this is actually a broken [02:34.080 --> 02:39.980] scheme. And the reason for that is you can actually commit to negative numbers. And therefore, [02:39.980 --> 02:46.080] you have an integer underflow, which means that you can sort of take your $10 or Bitcoin [02:46.080 --> 02:50.960] or whatever and go spend that, even though you should only be able to spend 9 because [02:50.960 --> 02:56.940] you only had 9 in the input. So that's bad. And we don't want to let that happen. But [02:56.940 --> 03:01.140] we still want to use this really awesome additively homomorphic commitment scheme. [03:01.320 --> 03:07.060] And so we can do in this case is we can add a zero-knowledge proof. I guess I should explain [03:07.060 --> 03:11.420] here what a zero-knowledge proof is exactly. A zero-knowledge proof is a proof that a statement [03:11.420 --> 03:17.680] is true about some input without having to reveal what that input is. So specifically [03:17.680 --> 03:22.720] in this case, an example of a zero-knowledge proof that we can use is a range proof. So [03:22.860 --> 03:28.780] a range proof is a proof that a certain input number is in range that you can verify without [03:28.780 --> 03:34.080] knowing what that input number is. So here you can make a proof that 3 is in range without [03:34.080 --> 03:39.480] revealing that it's actually 3. You only reveal the commitment, which is C. Does that make [03:39.480 --> 03:45.240] sense? Cool. Cool. So you use a zero-knowledge proof, and that way you can prove that it's [03:45.240 --> 03:49.540] in range. And if, for instance, you're making a commitment to a negative number, this range [03:49.540 --> 03:54.660] proof would actually fail. So this actually makes our confidential transaction not broken [03:54.660 --> 04:00.520] anymore. So that's really cool, and a lot of blockchain protocols use this general scheme, [04:00.520 --> 04:06.340] and it seems to be working so far. And why do we care about bulletproofs in particular? [04:06.340 --> 04:12.560] So bulletproofs is just one of many knowledge proof protocols, but the reason that we were [04:12.560 --> 04:17.600] looking at it was because it has really nice properties that we wanted in the context of [04:17.700 --> 04:23.180] a blockchain. So it has... or blockchains require a pretty constrained proof size if [04:23.180 --> 04:27.760] you're using proofs, because all the nodes that are full nodes have to receive and verify [04:27.760 --> 04:32.240] the proofs, and so you have to transmit all of these to all of the nodes. And bulletproofs [04:32.240 --> 04:37.300] does provide that. All of the proofs are in O of log N, and usually less than 1 kilobyte. [04:37.660 --> 04:41.860] And it has really fast verification, which is important because all the full nodes have [04:41.860 --> 04:47.580] to do verification, and bulletproofs provides really fast verification, as well as the ability [04:47.580 --> 04:52.560] to aggregate multiple proofs together into one proof that verifies more quickly, as well [04:52.560 --> 04:57.100] as the ability to batch multiple verifications of multiple proofs to have them basically [04:57.100 --> 05:02.240] run in parallel faster. And lastly, a really nice-to-have property is that you can actually [05:02.240 --> 05:08.140] have ad hoc logic, so you can code up a range proof, but you can also code up multiple other [05:08.140 --> 05:12.840] proofs of different statements, and you can do this without having trusted setup. So for [05:12.840 --> 05:17.520] those of you who are familiar with zk-SNARKs, for instance, those need a trusted reference [05:17.520 --> 05:24.380] string, which is why you have to have the secret setup ceremony, and that's sort of [05:24.380 --> 05:28.440] annoying for setting up new logic, and bulletproofs doesn't require that, because they don't require [05:28.440 --> 05:35.260] pairings. So that's why we at Chain picked bulletproofs. We were building a confidential [05:35.260 --> 05:40.440] blockchain protocol at the time, and so we said, hey, let's implement this paper. It [05:40.440 --> 05:45.840] just came out at the time in 2017, and then the next step was to actually understand how [05:45.840 --> 05:50.740] the paper worked. And that sort of felt like this. The paper says, we would like to make [05:50.880 --> 05:55.260] a proof of these statements, and then it says, okay, here's your massive verification equation [05:55.260 --> 06:00.020] that is like 30 lines long, and just like, you know, take it and run with it. And so [06:00.020 --> 06:04.480] as someone who's implementing the paper, it's nice to actually understand how the math works [06:04.480 --> 06:09.560] so that you can double-check that it's right, and so we really tried hard to do that. We [06:09.560 --> 06:14.600] spent I think like a full month basically just like writing down, you know, theories on the [06:14.600 --> 06:19.380] whiteboard of how you go from step one to step two, being like, no, that's wrong, and [06:19.380 --> 06:23.240] trying again, and then trying again, until finally we actually arrived at something that [06:23.240 --> 06:27.280] was fairly satisfactory. We sent it to Benedict, who is the author of bulletproofs, and he [06:27.280 --> 06:33.720] was like, cool, that looks good. And then we wrote it up on online notes so that no one [06:33.720 --> 06:37.300] else has to go through that, and they can just read our notes and, you know, follow along [06:37.300 --> 06:40.840] step by step as to how you get from the initial assumptions all the way to the final [06:40.840 --> 06:47.240] verification check. So hopefully this is like very easy to follow along with, and, you [06:47.240 --> 06:52.280] know, walks you through all of the different sort of manipulations to the initial [06:52.280 --> 06:57.900] assumptions that you have to do to arrive at the final math. So I guess you might be [06:57.900 --> 07:01.840] curious of what is that actual math. So I'll give you a little bit of an overview. I don't [07:01.840 --> 07:05.180] want to put everyone to sleep, so I'm not going to go too deep into the math, but [07:05.180 --> 07:09.420] hopefully just enough to give you like a little intuition of how it works. So the [07:09.420 --> 07:15.260] central building block of bulletproofs is this really efficient inner product argument. So [07:15.260 --> 07:20.180] as a refresher, an inner product is if you have two vectors and you take the sum of the [07:20.180 --> 07:24.920] entrywise multiplication. So the inner product of A and B equals C is the statement [07:24.920 --> 07:31.960] here. And an inner product argument is basically like a way to argue to someone that, in [07:31.960 --> 07:35.620] fact, the inner product of A and B is C. So like super naively, if I was just trying to [07:35.620 --> 07:40.600] prove that to you, I could send to you the vectors A and B and then send you the scalar [07:40.600 --> 07:45.080] C, and then you can do this math yourself. And you can check like either yes, it does [07:45.080 --> 07:49.580] equal C or no, the inner product of the two does not equal C. That's pretty easy. And [07:49.580 --> 07:54.660] that would take O of N space for me to send this proof to you. It'd be O of N where N is [07:54.660 --> 07:59.120] the length of the vectors. So that's like pretty inefficient if you have very large [07:59.120 --> 08:05.220] vectors A and B. And what Bulletproofs actually introduces is a really efficient way to [08:05.220 --> 08:11.940] make this argument. And this efficient way actually takes O of log N space instead of [08:11.940 --> 08:17.860] O of N space. And the intuition for how this works is that first you start off with the [08:17.860 --> 08:22.780] vectors A and B and you want to prove that C is the inner product of the vectors A and [08:22.780 --> 08:28.320] B. But at every step, you like do multiple rounds. And at every round, you actually [08:28.320 --> 08:33.880] half the size of vectors A and B. So you make A prime and B prime. And the way that you [08:33.880 --> 08:40.880] do this is you take a random scalar X and you multiply the first half of A with X and [08:40.880 --> 08:45.960] the second half of A with the inverse of X. And then you add those two. So by adding those [08:45.960 --> 08:50.480] two, you now create an A prime vector that is half the length of your original A. And [08:50.480 --> 08:54.600] you do something similar to B to make B prime. And then you have A and B the inner product [08:54.600 --> 08:59.420] of A prime and B prime. And then at this step, I'm not going to go into the details, but [08:59.420 --> 09:03.640] you basically make two commitments and then you send those commitments to the verifier. [09:03.740 --> 09:07.260] And then you repeat this step over and over again until you end at the base case where [09:07.260 --> 09:11.600] you just have two vectors of length one. So as you might have guessed, because you're [09:11.600 --> 09:16.400] having the vectors at every step and every step you make a constant number of commitments, [09:16.400 --> 09:23.540] this now takes O of log n space instead of O of n space. So that's actually the core [09:23.540 --> 09:27.420] tenet of how Bulletproof is able to be so space efficient. [09:28.980 --> 09:34.180] So you might be wondering, why do we even care about proving that C is equal to the [09:34.180 --> 09:39.440] inner product of A and B? And the reason for that is we can actually represent basically [09:39.440 --> 09:46.360] any statement we want as an inner product argument by applying math and cryptography [09:46.360 --> 09:51.480] to it. So as an example, I'll walk you through a little bit of how we can do this to a range [09:51.480 --> 09:57.080] statement. So here we start out with this statement that V is between zero and two to [09:57.080 --> 10:01.840] the n. We want to apply some math and cryptography to get it in the form of an inner product [10:01.840 --> 10:07.560] argument, where if and only if this inner product argument is true, if and only if C [10:07.560 --> 10:12.480] is equal to the inner product of A and B, then with very high probability, we know that [10:12.480 --> 10:17.500] V is in the range of zero and two to the n. Does that make sense? So that's our goal here [10:17.500 --> 10:23.100] is to do this jump between the left and the right. And the way we do that is actually [10:23.100 --> 10:29.860] by observing something really interesting, which is that if V is between zero and two [10:29.860 --> 10:36.320] to the n, you must be able to represent V as a binary number of length n. So this is [10:36.320 --> 10:42.380] just by definition of binary numbers. So for example, if V is seven, we know that seven [10:42.380 --> 10:48.300] is between zero and two to the n, where n is four. And therefore, you must be able to [10:48.300 --> 10:54.500] represent V as a binary number of length four, zero, one, one, one. Cool. And if V is outside [10:54.500 --> 10:58.640] like greater than two to the n, then we should not be able to represent it as a binary number [10:58.640 --> 11:06.700] of length four. Cool. So let's call this binary representation of V a sub L. So we can actually [11:06.700 --> 11:14.160] just say that V, the secret value, is the inner product of a sub L and the vector two to the n, [11:14.160 --> 11:18.440] where that's two to the three, two to the two, two to the one, two to the zero. Cool. So now [11:18.440 --> 11:23.880] actually, it seems like we have achieved our goal of representing our initial range statement [11:23.880 --> 11:29.820] as an inner product. But not yet, because you can do something malicious. Right here, [11:29.820 --> 11:37.600] we're assuming that a to the L is all zeros. But what if a sub L actually contains 100 in [11:37.600 --> 11:44.100] one of the digits? If that was the case, then a sub L would not just be a binary representation, [11:44.100 --> 11:50.020] and V could actually be incredibly outside of the range zero to the n, while still having this [11:50.020 --> 11:55.360] inner product argument, V equals a sub L and two to the n be true. So basically, we want to [11:55.360 --> 12:01.360] somehow guarantee that a sub L is only comprised of zeros and ones in order to make sure that V [12:01.360 --> 12:08.620] is actually in range. And the way that we do this is we add a second statement. We say that a sub L [12:08.620 --> 12:16.020] times a sub L minus one should be equal to zero for every index in a sub L. So if you think about [12:16.020 --> 12:20.240] this, this statement will only be true if a sub L is comprised of zeros and ones. If it was, for [12:20.240 --> 12:27.700] example, had a 100 at an index, then it would be a 100 times 99 equals not zero. So this checks that [12:27.700 --> 12:34.940] the bits are actually bits. So we continue to sort of add sort of, we continue to add these checks [12:34.940 --> 12:42.920] and different statements to our collection of statements. And then we add some more blinding [12:42.920 --> 12:47.500] factors, which basically blinding factors are a way to make sure that the secrets such as V and [12:47.640 --> 12:52.140] a sub L remain secret. And then we combine them. We just do a lot of math rearranging that's really [12:52.140 --> 12:57.560] tedious. And then we arrive at an inner product argument, C equals inner product of A and B, [12:57.560 --> 13:02.760] which is true, where if that is true, then V is in range with very high probability. [13:03.920 --> 13:09.680] So I'm actually going to be going more deeper into the math at another talk at Monero Village [13:09.680 --> 13:15.020] on Sunday. So if you want to learn more about the math, then please come to that. Or you can just [13:15.020 --> 13:19.900] read our notes on the Bulletproofs math. I'm just basically going to go through that and follow [13:19.900 --> 13:26.140] along at your own pace. So yeah, interestingly, Monero does use Bulletproofs and they do not use [13:26.140 --> 13:32.120] our implementation of Bulletproofs, although we're working on that. Cool. So now that we've [13:32.120 --> 13:37.360] understood the paper, mostly, we have to actually go and implement it. And there's a lot of things [13:37.360 --> 13:42.980] where cryptography papers will say, you need a prime order group, or you need just to apply a [13:42.980 --> 13:49.060] Fiat-Shamir heuristic, where it's not always very straightforward how as an implementer you do that. [13:49.060 --> 13:54.320] And so I'll talk a little bit about the tools that we use to implement these things. [13:54.320 --> 14:00.120] So starting with the prime order group, this picture is a little screenshot from the paper [14:00.120 --> 14:04.580] where the paper just says, let's need a cyclic group of prime order P. And as a reader, you're [14:04.580 --> 14:11.760] fine. We use a prime order group. But in practice, how do you implement this? So most people use [14:11.760 --> 14:16.240] elliptic curves because they're just really efficient. Edwards curves are really nice [14:16.240 --> 14:20.640] because they're really fast, have complete formulas, which means they don't have weird [14:20.640 --> 14:26.420] edge cases that you have to deal with one by one. And they're easy to implement in constant time. [14:26.420 --> 14:30.060] The problem, though, is that Edwards curves aren't prime order. [14:30.060 --> 14:35.540] Weierstrass curves, such as secp256k1, which is what Bitcoin uses, are prime order, [14:35.540 --> 14:40.960] but they don't have the nice performance and complete formula properties. So it'd be really [14:40.960 --> 14:46.840] awesome if we could just somehow get the best of both worlds. So in the past, what people have done [14:46.840 --> 14:52.340] is that they've said, well, we'll just use an Edwards curve in the place of a prime order group [14:52.340 --> 15:00.540] and it will be fine. And it was not fine. So that's not a good option. Don't do that, [15:00.540 --> 15:03.920] because then you'll have cofactor problems, which many people have learned before. [15:04.460 --> 15:09.420] However, we do have this really awesome protocol, two protocols, called decaf and [15:09.420 --> 15:14.560] ristretto, which actually do let us get the best of both worlds. So decaf was created by Mike [15:14.560 --> 15:21.540] Hamburg in 2015 and allows you to basically get a cofactor 4 reduction from an Edwards curve. [15:21.540 --> 15:25.900] That's really awesome. If you have an Edwards curve that has cofactor 4, which means that the [15:25.900 --> 15:32.000] order is 4 times a really large prime p, then you can actually create a prime group p from it. [15:32.280 --> 15:36.580] And then ristretto is actually something that was created by Mike Hamburg and Henry de Valence, [15:36.580 --> 15:41.560] which does a cofactor 8 reduction. And so the awesome thing about ristretto is that [15:41.560 --> 15:49.140] curve 255.19, which is an extremely fast Edwards curve, has cofactor 8. So because of the existence [15:49.140 --> 15:54.860] of ristretto, we can now create a prime order group over curve 255.19. So you can read more [15:54.860 --> 16:02.540] about decaf and ristretto at these links here. And what's really awesome about curve 255.19 is [16:02.540 --> 16:11.360] that it has extremely fast parallel formulas by this paper HWCD. And it's implemented as a library [16:11.360 --> 16:17.600] curve 255.19 Dalek, which uses these parallel formulas and uses AVX2 to get really good [16:17.600 --> 16:22.480] performance. So basically now because we have ristretto, we can take advantage of all of these [16:22.480 --> 16:29.560] performance speedups and make a prime order group over this curve 255.19 curve. And the end result [16:29.560 --> 16:34.740] is that, in fact, we do have extremely good performance if you compare it to other prime [16:34.740 --> 16:42.620] order groups. If you compare it to, for instance, secp256k1, the libsecp is four times slower than [16:43.260 --> 16:47.820] ristretto255. So that's really awesome. And I think if anyone's looking to build a prime order, [16:47.820 --> 16:53.860] use a prime order group, ristretto is sort of the obvious way to go. And it's implemented entirely [16:53.860 --> 17:01.360] in Rust. So that's an extra bonus. So that sort of covers our requirements for a prime order group. [17:01.420 --> 17:07.000] Next, we have to deal with the Fiat-Shamir heuristic. So if you've read through some [17:07.000 --> 17:13.420] interactive cryptography papers, you often see this snippet on the right, where the prover gives [17:13.420 --> 17:19.040] something to the verifier, and the verifier gets a random scaler, and then the verifier gives that [17:19.040 --> 17:24.940] random scaler back. And the paper says, well, here we have an interactive protocol, and you [17:24.940 --> 17:29.700] make it non-interactive by simply applying the Fiat-Shamir heuristic. And as an implementer, [17:29.700 --> 17:36.200] you're like, cool. How do I actually do that? In practice, a lot of people achieve, like, [17:36.200 --> 17:41.180] implement the Fiat-Shamir heuristic by simply hashing the things that the prover sends to the [17:41.180 --> 17:47.240] verifier. So that may work with a protocol that's sort of this simple. But if you have multiple [17:47.240 --> 17:53.280] rounds or multiple parties participating, that can actually get really complex and, like, really [17:53.280 --> 17:57.760] complicated with some edge cases that you might have to deal with. So what happens, for instance, [17:57.760 --> 18:03.780] if you forget to feed data into the hash? Or the data is ambiguously encoded? Or if you have [18:03.780 --> 18:08.060] multi-round protocols and you have to somehow hold on to the randomness from a previous round? [18:08.300 --> 18:13.000] What about domain separators? And there's just a lot of little edge case scenarios that are hard [18:13.000 --> 18:16.820] to deal with and you might just get a little bit wrong, which breaks your whole protocol. [18:18.040 --> 18:23.000] So it would be really nice if we didn't have to worry about this. If somehow you just had, like, [18:23.120 --> 18:27.400] a transcript object that held on to all the randomness for you and gave you some randomness [18:27.400 --> 18:32.980] back whenever you asked for it. So like this, if you changed your if you implemented the thing we [18:32.980 --> 18:38.060] saw in the first slide, like so, the prover gives the verifier L and R, which in practice when you're [18:38.060 --> 18:42.420] making it non-interactive is that you just give the transcript L and R. And then you get some [18:42.420 --> 18:47.100] challenge scaler back, which in practice in code means you just get a challenge scaler from the [18:47.100 --> 18:54.640] transcript. So that would be really nice. And luckily for us, Henry also implemented Merlin, [18:54.640 --> 18:58.760] which is a strobe-based transcript for zero-knowledge proofs. So this gives us everything [18:58.760 --> 19:04.540] we want. We have message framing, domain separation, composition of proofs, and basically [19:04.540 --> 19:08.000] it makes our lives super easy when it comes to dealing with the Fiat-Shamir heuristic. We sort [19:08.000 --> 19:12.080] of treat it as a black box and don't have to worry about what happens behind the scenes. [19:12.440 --> 19:17.300] And the best part about it is that it's more information is available at merlin.cool, [19:17.300 --> 19:24.340] so you can learn more about it there. Awesome. So now we've sort of learned about the story, [19:24.340 --> 19:28.380] you know, how we decided to implement a zero-knowledge proof, why we chose bulletproofs, [19:28.380 --> 19:33.760] and what tools we use. So you're probably itching to see the actual code. So let's dive into that. [19:34.080 --> 19:40.720] If you feel like following along, the GitHub repo is here. It's open source. You can look into it. [19:42.160 --> 19:50.460] Cool. So let's look at the range proof code. On the prover side, you have to actually assemble [19:50.460 --> 19:57.600] this proof. And I sort of gave you a little peek into the first few steps of making the proof, [19:57.600 --> 20:03.700] to make this A sub L vector, which is the bit vector that represents the V. So here on the [20:03.700 --> 20:09.400] left is an excerpt from the paper. And this might look familiar. A sub L is a binary vector such [20:09.400 --> 20:14.660] that the inner product of A sub L and the vector 2 to the N equals V. So that should look familiar [20:14.660 --> 20:21.140] from before. And then you just create A sub R, which is A sub L minus 1. So on the right-hand [20:21.140 --> 20:26.540] side is basically some pseudocode that matches pretty closely with our actual code, except that [20:26.540 --> 20:31.260] actual code has a few more optimizations that make it a little bit different, a little harder [20:31.260 --> 20:36.780] to read. So I made it a little nicer here. And you can follow along with the actual code at [20:36.780 --> 20:42.120] these links here. So on the left, what we do is we sample a random challenge scaler, [20:42.700 --> 20:48.400] a random scaler A alpha, and then we make a commitment, big A, using the blinding factor [20:48.400 --> 20:55.700] alpha, and taking the multiscalar multiplication of our G vector, which is our sort of base point [20:55.700 --> 21:03.640] generators, and A sub L, and then our H vectors and A sub R. So effectively what big A does is it [21:03.640 --> 21:09.700] commits along with a blinding factor to A sub L and A sub R. And then on the right-hand side, [21:09.700 --> 21:16.100] we can do this really simply using the Ristretto library and its curve and scaler operations to do [21:16.100 --> 21:22.620] H times alpha plus MSM, which is multiscalar multiplication of G vector and A sub L, [21:22.620 --> 21:28.320] and the multiscalar multiplication of H vector and A sub R. So hopefully this maps from the [21:28.320 --> 21:34.180] paper really well. And then we do the exact same thing, but with S sub L and S sub R, [21:34.180 --> 21:38.340] where S sub L and S sub R are actually blinding factors for A sub L and A sub R. [21:38.360 --> 21:43.140] So we generate those, we generate a blinding factor row, and then we create a big S, [21:43.140 --> 21:48.280] which is the commitment to all of those things. Cool. And then now we have the actual exciting [21:48.280 --> 21:54.360] part, which is that we get to do the Fiat-Shamir heuristic. So here in the paper, it just says, [21:54.360 --> 22:00.200] send A and S to the verifier. And in practice, what we can do in the code because of our transcript [22:00.200 --> 22:05.920] object, thanks to Merlin, is we can just commit the points A and S to the transcript. And then [22:05.920 --> 22:10.960] where we're supposed to, in the interactive protocol, get Y and Z from the verifier, [22:10.960 --> 22:16.700] we can now get the challenge scaler for Y and Z from the transcript. And you can see here that [22:16.700 --> 22:20.360] we actually have these domain separators at every one of these steps. And those domain separators [22:20.360 --> 22:25.920] make sure that we're actually getting A and S and not confusing it with any other steps. [22:27.220 --> 22:32.560] Cool. So that's a little pseudocode. And hopefully, all of the rest of the library is also [22:32.560 --> 22:37.420] about as easy to read. But I'm going to sort of talk about more high level, how we were able to [22:37.420 --> 22:43.800] take advantage of using Rust to get really good performance and really nice code safety. [22:43.800 --> 22:51.320] So one really cool thing that we were able to do was implement session types for an MPC protocol [22:51.320 --> 22:57.560] using Rust. So for context, I mentioned really briefly earlier that you can actually get really [22:57.560 --> 23:02.620] good aggregation properties from bullet proofs. And what that means is if you have N people who [23:02.620 --> 23:08.100] all have separate range proofs for their own private secret values, they could come together [23:08.100 --> 23:13.040] and without having to trust each other, actually make one aggregated range proof that is [23:13.040 --> 23:19.820] significantly smaller and faster to verify than having N separate single range proofs. [23:19.820 --> 23:25.320] So in order to do this, you have to engage in a multiparty computation protocol. And it looks [23:25.840 --> 23:30.660] sort of like this. You don't have to see the actual party states. But the state transitions [23:30.660 --> 23:37.520] look something like this. So basically, every party will go through some calculations on their [23:37.520 --> 23:41.870] secret value and then make a commitment. And they'll send this commitment either to a dealer, [23:41.870 --> 23:45.530] which is what we have pictured here, or they'll send it to all of the other parties if you don't [23:45.530 --> 23:50.230] trust a dealer. And those other parties will take the commitments and then generate a random [23:50.230 --> 23:54.170] challenge scaler and return it to all of the other parties. And they do this actually three [23:54.170 --> 23:59.870] separate times. So you can see how if we were just using hashing for the Fiat Shamir heuristic, [23:59.870 --> 24:03.930] this would actually be extremely complicated to do because you're hashing data from a bunch [24:03.930 --> 24:07.270] of different parties over a bunch of different steps. But with the transcript protocol, [24:07.270 --> 24:12.710] this is actually really efficient. But going back to my main point, because this is a [24:12.710 --> 24:17.030] multiparty competition protocol and you're actually doing multiple party transitions, [24:17.030 --> 24:22.050] it's really, really important that you get these transitions in the right order. So for example, [24:22.050 --> 24:30.830] if you were to call the same function on the same party state twice, that would actually break the [24:30.830 --> 24:34.470] protocol and you might actually be able to leak secrets from the party by doing that because [24:34.470 --> 24:39.170] you're doing a different challenge over the same secrets. So you have to make sure that you can [24:39.170 --> 24:43.830] only transition from one party state to the next and not repeat a party state. And the way that we [24:43.830 --> 24:48.650] make sure of this using Rust is by taking advantage of their memory management model. [24:48.690 --> 24:54.370] So every party transition actually is a function on a party state where the function takes ownership [24:54.870 --> 24:59.330] of the party state and then consumes it and generates the next party state. So you're [24:59.330 --> 25:05.350] physically not able to call the same function on a state twice. So I thought that was a really cool [25:05.350 --> 25:10.770] thing that you could do with Rust and basically guarantee that you don't abuse this multiparty [25:10.770 --> 25:18.010] competition protocol. So that's one fun thing. Another thing that we can do in Rust is make [25:18.010 --> 25:26.130] optimizations based on the fact that Rust iterators are lazy and zero cost. So I mentioned earlier [25:26.130 --> 25:32.370] that you can do multi-scalar multiplications of a large generator vector and a large scalar [25:32.370 --> 25:37.110] vector. And that basically looks like this down here. Q equals some scalar times a generator, [25:37.110 --> 25:42.930] another scalar times a generator. And you can chain these up. So if your iterators are lazy [25:42.930 --> 25:48.410] and zero cost, what you can do is any time that you have a multi-scalar multiplication, [25:48.410 --> 25:52.710] especially for the verification equation, instead of just doing that multi-scalar multiplication [25:53.310 --> 25:58.530] in place, what you can do is add all of the generators and add all of the scalars to [26:00.050 --> 26:05.590] increasingly large set of iterators. And then only at the very, very end do you do one massive [26:05.590 --> 26:10.770] multi-scalar multiplication using all of the generators, sorry, all of the points or generators [26:10.770 --> 26:15.190] and all of the scalars from the entire calculation. And this is actually way more efficient. [26:15.470 --> 26:20.430] Both because you don't have to do extra allocations or manage temporaries for those [26:20.430 --> 26:27.050] iterators. And because the backend we use, Ristretto library, has speedups such that if you [26:27.050 --> 26:31.730] have a lot of generators and a lot of scalars, it is able to take advantage of some performance [26:31.730 --> 26:39.070] properties. So the end result of all of this is that we have extremely good performance. So for [26:39.210 --> 26:45.990] a 64-bit range proof, we're able to do verification in less than one millisecond. And with IFMA, [26:45.990 --> 26:51.470] three times faster than LibSecP and seven times faster than Monero. So basically the state-of-the-art [26:51.470 --> 26:59.070] range proof out there that we know of. So that's pretty awesome. And this performance is a result [26:59.070 --> 27:04.170] of, as I mentioned, using Rust, using the iterators, using the Ristretto prime order group and a lot of [27:04.170 --> 27:09.010] other little performance tweaks that we did here and there. So I think this is really awesome. [27:09.970 --> 27:15.070] All right. So we have implemented this range proof. You're like, cool, now you can do [27:15.070 --> 27:19.650] confidential transactions on the blockchain. Now we can have private blockchain transactions. So [27:19.650 --> 27:24.330] that's pretty cool. But we didn't want to stop there. We're sort of on a roll. And so what we [27:24.330 --> 27:29.930] did is we actually kept building this protocol out. So what I mentioned early in the talk is [27:29.930 --> 27:35.970] that Bulletproofs actually allows not only for, you know, one specific proof type, the range proof, [27:35.970 --> 27:42.750] but it actually allows for the ability to make a proof over any set of arbitrary statements. [27:42.750 --> 27:48.450] And so we wanted to make a way for people to make their own statements. And the statement [27:48.450 --> 27:53.410] could be a range proof. It could be a proof that a loan has been repaid while keeping the [27:53.410 --> 27:58.630] loan amount and the percentage amount private. It could be basically whatever statement you [27:58.630 --> 28:04.270] want to make a proof over. And so we made this constraint system API for fully programmable [28:04.270 --> 28:11.910] proofs over the Bulletproofs protocol. And what that looks like is you can add multiplicative [28:11.910 --> 28:17.670] constraints. So you have variables X, Y, and Z. And you want to prove that X times Y equals Z [28:17.670 --> 28:22.310] while keeping all three of those variables secret. And you can also add linear constraints, which is [28:22.310 --> 28:28.810] basically a combination of secret variables with clear text weights being equal to zero. [28:28.830 --> 28:35.790] So these are the two things that we added to the API to allow you to build constraint systems, [28:35.790 --> 28:41.710] which can represent your arbitrary statements. But you might be asking why constraint systems [28:41.710 --> 28:46.410] want to use these to program your arbitrary statements. And that's because a constraint [28:46.410 --> 28:52.570] system can actually represent any efficiently verifiable program. Anything that is NP complete, [28:52.570 --> 28:59.270] for that matter. So as long as you can express something as a program, you can also express it [28:59.270 --> 29:03.790] as a constraint system. And then you can make a constraint system proof that all of the constraints [29:03.790 --> 29:10.450] are actually satisfied by your secret inputs. So that seems like a very complicated way of saying [29:10.450 --> 29:15.850] basically you can code whatever proof you want using this API. So we made that API, [29:15.850 --> 29:20.770] and we wrote up some more notes on that. And then we... the whole reason we wrote this API [29:20.770 --> 29:24.930] was because we wanted to use it. And one of the reasons that we wanted to use it was to build [29:24.930 --> 29:30.490] this confidential assets protocol. So the key difference between a confidential transaction [29:30.490 --> 29:34.890] protocol, which is what we talked about, what I talked about earlier, where you just have, [29:34.890 --> 29:40.130] you know, your input and output amounts as secret values, is that in a confidential assets protocol, [29:40.130 --> 29:45.430] not only are your input and output amounts secret, but your asset types are also secret. [29:45.610 --> 29:49.930] So a confidential assets protocol is actually a lot more complicated to build than a confidential [29:49.930 --> 29:55.010] transactions protocol, because you can't just add up all of the sums of all of the different asset [29:55.010 --> 29:59.530] types, because that would be revealing what the asset types are. So there's a little bit more [29:59.530 --> 30:06.550] finesse that we have to do to build a confidential assets protocol. And there's sort of four building [30:06.550 --> 30:12.030] blocks of this, and each of those building blocks is actually a combination of constraints that went [30:12.030 --> 30:16.490] into the constraint system. So you might be familiar with the furthest right one, the range [30:16.490 --> 30:20.510] proof, that basically just takes all of the constraints that we used to build the range proof [30:20.510 --> 30:26.890] in the first place that I talked about earlier. But there's also a shuffle, we call them gadgets, [30:27.010 --> 30:32.630] a shuffle gadget, which proves that your inputs and outputs to the gadget are a valid reordering [30:32.630 --> 30:37.850] of each other. We also have a merge and split gadget, and those basically either merge two [30:37.850 --> 30:43.930] items into one or leave them unaltered. And from a verifier's perspective, you can't actually tell [30:43.930 --> 30:48.830] whether those things were merged or whether they're left alone. You only know that one of [30:48.830 --> 30:55.630] those two happened. So we use these building blocks to make a cloak transaction. What that [30:55.630 --> 31:00.910] means is that we have these inputs, we have these outputs, and we apply all of these gadgets to the [31:00.910 --> 31:06.370] inputs, such that if these gadgets were applied correctly, then the whole proof will verify [31:06.370 --> 31:10.910] correctly, and then you know that the inputs and outputs are actually valid reorderings of each [31:10.910 --> 31:15.970] other. So let's just walk through that, just to give you an idea what that means. [31:16.730 --> 31:23.650] So here your inputs are $5, 3 yen, and $4. First you want to group the assets together, [31:23.650 --> 31:28.970] the asset types together. So here you're shuffling them, and you want to group the $5 and $4 together [31:28.970 --> 31:35.170] and the 3 yen at the very end. As a reminder, the verifier doesn't know exactly how you're [31:35.170 --> 31:39.630] ordering this. All the verifier can see is that you're doing a valid shuffle or that you're not [31:39.630 --> 31:44.590] doing a valid shuffle. So here this is a valid shuffle, and then we want to merge all of the [31:44.590 --> 31:51.890] things that are of the same asset type together. So $5 and $4 added to $9. Then we shuffle again, [31:51.890 --> 31:57.650] and we move all of the non-zero types to the top of each asset group. So $9 gets moved to the top, [31:57.650 --> 32:03.790] while $0 gets moved to the bottom of the asset group. Then we split the asset types into whatever [32:03.790 --> 32:08.250] output amounts we want. So if we look to the right, we actually want an output amount of $6 [32:08.250 --> 32:15.690] and $3. So we split $9 into $6 and $3, and we keep 3 yen the same. And then lastly, we do one [32:15.690 --> 32:21.530] shuffle just to make sure that we have a random ordering for the output. And then we add a range [32:21.530 --> 32:27.490] check to make sure that none of these values are negative. And then basically, as long as you make [32:27.630 --> 32:33.270] a proof that all of these operations were valid operations that satisfy the constraints in each [32:33.270 --> 32:38.870] of these gadgets, then the verifier can look at this proof, and without knowing what any of the [32:38.870 --> 32:43.490] inputs, any of the outputs, or any of the intermediate values are, they can actually say, [32:43.490 --> 32:49.470] yes, indeed, I am fairly sure that this is a valid confidential assets transaction. You did not, [32:49.470 --> 32:55.470] in fact, create extra assets, destroy assets, or anything like that. And to a verifier, [32:55.470 --> 32:59.370] transactions of the same size, meaning the same number of inputs and the same number of outputs, [32:59.370 --> 33:03.710] are indistinguishable from each other. So that's the whole point. We want to make sure that [33:03.710 --> 33:10.130] we can keep these transactions actually confidential. So the spec and code for this [33:10.130 --> 33:15.330] is online, and this is something that has actually been inherited by Stellar, the Stellar [33:15.330 --> 33:20.150] Development Foundation, and they're working on integrating this into Stellar. So that's pretty [33:20.150 --> 33:26.730] exciting. We now have the ability to do a confidential assets transaction with Bulletproofs [33:26.730 --> 33:32.990] without using Trusted Setup, which is something that is fairly interesting. And then, if you're [33:32.990 --> 33:39.730] still with me, the last sort of crazy thing was that we wanted to make a smart contract language [33:39.730 --> 33:45.170] where people who don't understand how constraints work, don't really care about a multiplicative [33:45.170 --> 33:50.530] constraint or a linear constraint, but want to write smart contracts, are able to use this smart [33:50.530 --> 33:58.410] contract language to write contracts that compile down to zero-knowledge proofs. So I'm near the end [33:58.410 --> 34:03.890] of my talk time, and I want to leave time for questions, but basically this was a whole separate [34:03.890 --> 34:09.510] talk that we gave at a conference recently about how we were able to make a zero-knowledge smart [34:09.510 --> 34:15.510] contract language using Bulletproofs that's a lot more user-friendly than building constraints by [34:15.510 --> 34:24.090] hand. Cool. So that's my talk. Once again, a lot of this stuff I worked on with Henry and Oleg at [34:24.090 --> 34:29.270] Chain and Interstellar. They're both super great, and Oleg is actually carrying on a lot of this [34:29.270 --> 34:34.650] work at the Stellar Development Foundation. And I also want to say thanks to George and Deirdre, [34:34.650 --> 34:40.650] who persuaded me to submit this talk, and George actually gave a very similar talk to this called [34:41.190 --> 34:48.990] Implementing an Elliptic Curve, How to Implement Curve 255.19 in Go at this exact village a few [34:48.990 --> 34:55.370] years ago. So I modeled a lot of my talk off of his talk. So those are my thanks. And for further [34:55.370 --> 34:58.910] reading, we have of course you should read the Bulletproofs paper. It's still a really good paper [34:58.910 --> 35:02.650] even though it doesn't explain the intermediate steps they take to get to their conclusion. [35:03.430 --> 35:08.910] You can check out our open source GitHub repo for implementation, and then you can follow along [35:08.910 --> 35:15.770] with our math here, where we write up how you actually get from step one to step two. And then [35:15.770 --> 35:21.190] lastly, if you want to refer to any of these slides, my slide deck is just at speakerdeck.com [35:21.190 --> 35:26.810] slash Kathy Yun, so that you can find all of these URLs in the future. And I am on Twitter [35:26.810 --> 35:34.110] if you want to shoot me any questions or just find me in person later. That is my talk. [35:39.790 --> 35:45.610] And questions at the mic in the center aisle if you have questions. We do have a cutoff, [35:46.130 --> 35:51.530] and so please walk up to the mic. And if there are any mobility issues, I'll always walk the mic [35:51.530 --> 36:00.250] over. Hi, thank you. I'm wondering if these validations, are these compile time or run time? [36:01.190 --> 36:05.930] So you're talking about the verification of proofs? [36:06.050 --> 36:09.370] Yeah, well, the components that you were showing. Oh, it's able to verify that this [36:09.370 --> 36:13.310] component actually does a valid shuffle or a valid merge, these kinds of things. Because [36:13.310 --> 36:17.630] it's really interesting. It's like you've kind of implemented a really cool like dependent types [36:17.630 --> 36:23.630] kind of thing or validation. And with Rust being a nice strongly typed language, that's kind of [36:23.630 --> 36:28.570] neat. Like bringing the types maybe into a higher level of being able to assert certain things. [36:28.570 --> 36:34.750] Yeah, so you're talking about basically for these gadgets, whether these are compile time. So [36:34.750 --> 36:40.190] basically whenever we build one of these gadgets, what we do is actually we use the constraint [36:40.190 --> 36:46.290] system API to like hand select, like here we want one more multiplier, one more linear constraint. [36:46.290 --> 36:53.990] And so that's all done basically at compile time. And yeah, does that answer your question? So we [36:53.990 --> 37:00.310] basically like do this by hand for Cloak. But then in ZKVM, you can actually do this with like [37:00.310 --> 37:05.870] certain opcodes. And that gets sort of like compiled down to these multiplicative and linear [37:05.870 --> 37:10.330] constraints. And those then form a proof. Yeah, I think it's great. Because also like lots of [37:10.330 --> 37:13.810] these blockchain languages, like a theory, whatever, like, they're like super, they seem [37:13.810 --> 37:19.410] super untyped and uncheckable. And so it's nice to see that we're using these modern developments [37:19.410 --> 37:25.670] to do this kind of work. Cool. Yeah, thanks. And if you want to learn more about our smart [37:25.670 --> 37:30.970] contract language, like philosophy, actually, we built ZKVM, which is like the zero knowledge [37:30.970 --> 37:36.390] virtual machine, based a lot on our design for TXVM, which is our original smart contract language [37:36.390 --> 37:41.410] that wasn't zero knowledge. And that was a transaction virtual machine. And that, like had [37:41.410 --> 37:45.450] in mind a lot of the things that you mentioned about like strongly typed, not being able to [37:45.450 --> 37:48.990] shoot yourself in the foot by accidentally like dropping a contract, things like that, [37:48.990 --> 37:55.210] having deterministic output, for instance. So we had a lot of lessons learned from developing TXVM. [37:57.170 --> 38:03.890] Anybody else? All right. Thank you very much. Great. Thank you.