New Ethereum talks, every Monday. The week's conference uploads by event, in your inbox.

Loading player…

Mina Protocol 🛠️ Introduction to Mina Protocol and SnarkyJS - Angus Maidment

ETHGlobalMon, Oct 9, 2023, 12:00 AM

Join Angus Maidment from Mina Protocol for a workshop titled "Introduction to Mina Protocol and SnarkyJS". Thank you to everyone who joined us for ETHGlobal Paris 2023! Paris is the city of light and birthplace of many revolutions. Therefore we were thrilled to be back in one of the most buzzing and free-spirited cities in Europe for ETHGlobal Paris 2023. A lot has changed in the European ecosystem since the last time we hosted a hackathon in 2019. ----------------- Follow us: https://twitter.com/ETHGlobal​ Check us out: https://ethglobal.co​m Email us at: hello@ethglobal.com

Transcript

Great. Please excuse the slight delay in starting. I also keep my charger here, which I hope to be able to plug in at some point if, uh, my battery is almost empty if, uh, my battery is almost empty . Hello everyone. My name is Angus and today I will be talking to you about the Mina Protocol and SnarkyJS.

Today is July 21st. My name is on it. Yes, my name is Angus. I work in the developer community and talk to people about the Mina protocol, uh, and tell them how to build ZK apps with SnarkyJS. I live in Edinburgh, Scotland.

Uh, here's a picture of me practicing steganography and fitting myself into the sign. Uh, and if you happen to be watching the keynote on the main stage tonight, you might see me in a cucumber costume. Uh, you can also follow me on Twitter: Blockchain Beard. Uh, and you can send me memes. That would be cool.

The structure of today's talk is an introduction to the Mina Protocol and zero-knowledge proofs. I will talk about ZK apps and how they work with Mina and SnarkyJS. This is how you build ZK apps. This is the TypeScript library. And uh, we had a program called ZK Ignite, which I'm going to tell you about.

I believe the application deadline has just passed, but you can still find out how you can participate, uh, and what the next steps are, especially how to get support for the hackathon this weekend. Uh, well, my luggage is here, so I thought it would probably be easier than having to explain to him where the adapter is in my bag. I have a rather complex packing system. So a rather complex packing system. So , zero-knowledge proofs.

Who among you has already heard of ZK? Good. Many hands go up for everyone watching the stream. So I will do a kind of quick-run introduction to zero-knowledge proofs so that everyone has the necessary knowledge to understand what ZK apps are and how they work. It states here that zero-knowledge proofs can be used to prove and verify information in a private, untrusted, and decentralized manner .

That's good for blockchains, if you also know anything about blockchains. Uh, a good way to think about it is to imagine what you can do with a zero-knowledge proof. You can prove to someone that you know something without revealing any additional information , right? And that can, uh, vary depending on the context . A good way to imagine this is the game "Where's Waldo?"

This is what the character Walter looks like . In the American version, his name is Waldo. So there's this huge picture with an insane amount of detail on a kind of large map detail on a kind of large map , and you have to find this character called Wall-E. So if you want to show someone, or prove that you know where Wall-E is, you can show them the map or picture and simply point to the Wall-E figure and simply point to the Wall-E figure , but then that person already knows where Wall-E is, right? Then she can go up to other people and say: Look, I know where Wall-E is.

To imagine what you can do with a zero-knowledge proof, take the Wall-E map and a large piece of white cardboard. You cut a hole in the cardboard exactly the size of Wall-E and then place it over the map. Then you can show it to someone and say, "Look, there's Wall-E," because you can see the little Wall-E figure, but you can't see any contextual information around him. Looking at the map afterwards, it would be difficult to find Wall-E difficult to find Wall-E because it wasn't clear where he was located in relation to everything else. So this is one way to imagine what zero-knowledge proofs can do.

There are indeed many use cases for which zero-knowledge proofs can be used. Something that is talked about a lot is their use in increasing scalability and for rollups and similar items for various L2 similar items for various L2 solutions. And then there is the idea of ​​a ZKVM, where one can write calculations and verify them using a zero-knowledge proof . It is also good for things like private transactions, voting, or identity verification. Identity is obviously very important in our digital world, isn't it?

The concept of identity and the proof of certain things about one's own identity without revealing all information at once is something that can be achieved with zero-knowledge . And simply this idea of ​​verifying calculations, right? So this is also a foil. We will look at zero-knowledge proofs and compare them with other cryptographic tools cryptographic tools you may have used before , and take a look at so- called prototypes, I think, and how to use them. Something else you need to know about zero-knowledge proofs : The proofs Mina uses can be verified in constant time .

It is therefore very fast and you don't have to see all the inputs that someone has used to create the proof . You can choose whether to keep your entries private or make them public. This is also very good for data protection also very good for data protection if you want to offer your users privacy and don't have to make all their input for methods public . Okay, here you go. Here, you've probably used a hash function before.

So, with a hash function, you input data, for example as a string, and then receive this other string, right then receive this other string, right ? OK. And hash functions have a number of properties, but the most important point we are considering here is the fact that if you have data and run it through a hash function, you can verify it against others, right? You can give the data to someone else, then that person can use the hash function, and if the same string comes out, you know it's the same data , right? You can therefore check the integrity of data using a hash function.

Similarly, with a public-key signature, you can take data, sign it with a private key sign it with a private key , and other people can then use the public key to verify that this message or data was signed with a private key, right? So we're now talking about zero-knowledge proofs, right? In Mina, they work by writing a computer program, i.e., giving people code to perform a calculation, and then performing a compilation step that generates this string called the verification key.

So, if the goal is for people to use your code , right? You give them the code you wrote, and they execute this so-called prover function. So here in the middle is the proof. You have a program that you run, as well as public and private inputs that generate the proof, right? The ZK proofs we keep talking about.

This creates a string. That's the proof. And then you can run the verification function, which uses the proof you generated during the calculation, as well as the public inputs but not the private inputs, and the verification key you generated when you created your ZK app. Correct? And the result is a Boolean value.

Therefore, you can verify whether a piece of evidence is valid or not. OK? With a hash function, you input data. But now we say that with this cryptography, one can prove that someone has performed a calculation, i.e.

, executed a program. So, this is how Mina works: We use zero-knowledge proofs to verify all calculations and transactions . It uses ZK, which is why the banner at the bottom says "the world's first ZK blockchain". It is a Layer 1 blockchain that is entirely based on ZKPs. OK.

And as I said, ZKPs are great for privacy and scalability. Mina therefore offers a number of these advantages. Checking the condition is very quick. As I said, it always takes the same amount of time. Therefore, the state can be verified, and these proofs always remain the same size.

Mina also has a feature called recursion, where you can use proofs as input to create new proofs. The blocks of the chain are linked together by one proof of state flowing into the next; When creating the state proof for the next block, the previous state is used as input. This allows you to verify all blocks up to the current block, and it's very fast. You may have also heard that it is a 22- heard that it is a 22- kilobyte blockchain. So you can verify the status of your account.

You need the proof of state, which is about 1 kilobyte in size, plus some metadata—with 22 kilobytes you can check the account balance in the Mina network. Um, you can synchronize a node with only this small amount of data . That's pretty cool. But this isn't just something we simply tell people. The Nil Foundation is working on a method to take a Mina proof and verify it in the EVM.

One can therefore imagine using a lot of computing power via Mina . A proof is created that the calculations have been performed, this is verified in the EVM, and then actions are triggered in an EVM blockchain , while the actual calculation runs via Mina. This is in progress; We can give you links for that . It is still in the research phase. We also have Open Mina, a real blockchain node that runs in a web browser—it's pretty impressive.

So if you want to build apps and attract users to your apps, they can start a node directly in the web browser without relying on a third-party provider or node provider . That's pretty cool. Now that I've told you about ZK proofs and how Mina uses them, you're probably wondering how you can build things with zero-knowledge proofs yourself – can build things with zero-knowledge proofs yourself – and that's where ZK apps come in. So, this is about the functionality of smart contracts. This makes it possible to create so-called ZK-Apps, i.

e., applications that use zero-knowledge proofs . If you are familiar with Ethereum or have developed with the EVM before: The EVM model is based on on-chain calculations. So, calculations are verified by having all nodes in the network execute the same code and then all arrive at the same result, right? The graphic here shows a user at their computer.

He wants to call a smart contract method, whereupon all nodes in the Ethereum network execute this method and make the corresponding updates. So you are replicating the entire calculation on all these nodes. Mina is different. ZK apps use off-chain calculations and on-chain verification. Here's how it works: You write code, the user executes it, creates a proof of correct execution, and the Mina network...

takes this proof, verifies it, and then applies the status updates that the user wanted to perform with the ZK app. That 's quite a difference, isn't it ? The entire code runs client-side; the proof is submitted in a transaction and then verified. So, as I said, this is completely different from the EVM model I just explained. There are a number of advantages to using off-chain computing.

Primarily data protection. As I said, you can choose what input users provide for smart contracts. You can decide whether they should remain public or private. So this is good for privacy. Furthermore, there are no gas charges as you would normally know them.

The costs of using the Mina network do not scale with the computing effort. You can therefore perform as many calculations as you like, and only need to pay the simple transaction fee for sending the proof to the network . So you can calculate as much as you want. You simply create this one proof and then pay a transaction fee to the network. So no gas charges.

That's pretty cool. Um, there is also the possibility of composition. It allows you to do things; you can design your apps to be modular, but you can also basically create your own rollups. So, this feature I mentioned earlier, called recursion. You can therefore take one piece of evidence and use it as input for another piece of evidence.

There are some cool things you can do with it, and I'll tell you more about that later in the presentation. And then there's the idea that the proof of status is small and quick to verify, so that it can be verified in different locations. You can therefore use Mina to perform calculations and verify them in other locations or on other blockchains. So, to go through the process you need to think about when building ZK apps : It works via the compilation step I was talking about earlier. When you generate the verification key and deploy your ZK app, you send this verification key to the network.

So here is a box containing a key that goes to the network nodes. This verification key is public, and it is precisely this key that you use to verify evidence generated by people . When a user uses your ZK app, it is hosted here at mycodezapp.com. So you are using your ZK app.

They execute the code with some input and then generate this proof and then generate this proof . What happens next is that they send this proof in a transaction, and the nodes in the network use your verification key from earlier to check whether the proof is valid or invalid. If valid proof is provided, status updates can be made , but if invalid proof is provided, the transaction will be rejected. Also, ZK apps consist of methods. If you want to develop ZK apps for the hackathon, you will write methods .

There is a diagram here that shows . There is a diagram here that shows that methods have arguments. So you have inputs and a smart contract status. So you have very limited on-chain storage to back up the state of your smart contract, as well as some values ​​from the rest of the world. For example, from a database, a server, or something similar database, a server, or something similar .

And when you execute a method , you are the outputs where you can make updates to the status of your smart contract or update the status externally . So that's roughly what flows into and out of methods . Therefore, if you want to write methods, you need to master SnarkyJS. SnarkyJS is a TypeScript library. So if you want to start a petition to rename it "Narts", you can argue about it with people on GitHub.

So, it's the TypeScript library for defining zero-knowledge proofs. So you can create—oh, there's the low battery warning. You can create, prove, and verify zero-knowledge proofs . So there are tools that you already know and love if you are familiar with TypeScript. We have good integration with Visual Studio Code and IntelliSense, which is very useful.

And you can use tools like npm and Jest for testing. The idea behind SnarkyJS is to make your life easier and to make it simple for you to build apps with ZK. This is a kind of quick start guide in five steps. All you need to do is install npm. There is a CLI tool that was also developed to make your life easier .

It can help you set up, create, and deploy your projects. We have also prepared some flyers with this information. So come by the stand to get some. Alternatively, you can also find this information in the documentation to which I will link. The idea is that you can get started in just five steps, install the tools and deploy your ZK app .

If you want to write SnarkyJS smart contracts, you need to know about field elements ; These are the numbers you use in zero-knowledge cryptography , based on the concept of finite fields for computations of finite fields for computations . So this is the basic data unit you need to use data unit you need to use . You can store a number with up to almost 256 bits. So we have a guy in SnarkyJS called "Field". Here is a small example of how you would declare this constant .

In a programming language you are already familiar with, you would simply use the numbers one and three. But in JS you have to specify that you are using the field type specify that you are using the field type . So this is how it's implemented here. This means, create a field, give it the value one, and then there is a built-in method called dot add. And then it says, add this other new field, which I'm creating here with a value of three.

So, fields, you have to use fields for everything. That's how ZK cryptography works. We also have other built-in types to make your developer life easier. Things like Merkle trees, public and private keys, signatures, and similar things. These also have integrated methods.

So hopefully you should find the types and methods you need for your purposes . And if you think something is missing, you should build it and submit it to the hackathon. This is a short, basic example of a smart contract that comes with the CLI tool . And so I just wanted to give you a brief tour. This above brief tour.

This above , if you can see my mouse, says: It uses the state decorator, which means you are storing this on-chain; This provides eight memory fields for a ZK app. This means that we will store a number in this state. You declare, you essentially create a smart contract by extending the smart contract class. You declare a state that you want to save. Oh, oops, I was just about to scroll down.

So scroll down. So , yes, you declare what you want to store on-chain in the state want to store on-chain in the state , and here are some things that define the permissions for who can do what and how to interact with the ZK app . You can read more about permissions in the documentation . So this is the init method. It initializes your ZK app.

So, what we're simply saying here is that this state variable we declared is set to one declared is set to one . And then there is an update method here that states that we will retrieve the field from the state will retrieve the field from the state . We verify that it actually corresponds to the current state , and add two to it. So, it means adding two, and this assert equals then states that we have added two and check we have added two and check if the new state is equal to the old state plus two. So it's about thinking about what you prove, and this is where it's determined that we establish this new status.

So when you call this method, the status is incremented by two, and the next time you look at the status , you will see the number plus two. So this is a very simple example of what a smart contract looks like. Um, I said earlier that I would tell you more about recursion. Recursion is a very cool feature of snarkyjs. So, this example here has this card game.

Um, nobody ever mentions it, but I thought I should point out that it's probably the worst card game of all time because everyone has the exact same cards. And I think that's not one of the strongest hands you can have in poker, is it? So everyone has something like a straight flush that only happens once in a million, or something like that . Uh, so if you imagine a card game, a turn-based game, then you can, because you can take evidence that has already been created and use it as input for creating further evidence . You can have one player.

Player one therefore executes the game logic and creates a proof stating that I made my move in a way that is valid according to the rules, i.e., the logic of the game . and they can generate a proof that they can pass on to player two and player two can verify the proof. So you can check whether player one made their move in a valid way made their move in a valid way .

They can then make their move, and if they can provide proof that they have made their move, they can use the proof that player one gave them. And when they create a new proof , player three can verify whether player two made their move in a valid way, but also that player one made their move in a valid way as well . One can therefore imagine passing the evidence among the players ad infinitum or until the game ends. And you can also tell that there's no blockchain involved here. So you can essentially do this off-chain, share evidence and verify things without bringing them back onto the blockchain until you want to.

In this way, recursion allows you to do many cool things, but you have to think about things a little differently think about things a little differently . Um, here are a few examples of things people have built on Mina for our ZK Ignite program. So people are developing L2s to improve data privacy and scalability. Someone has developed a keyless wallet. Also, things that utilize Social Recovery and Shamir’s Secret Sharing.

That 's pretty cool. And someone has developed Bio-Snarks to share data in the biotech industry and to verify things without revealing sensitive information. There is a whole list of numerous projects that people have developed for our ZK-Ignite program. We can link you to this list so you can see what people have done and how they implemented it , to inspire you. Next steps at the hackathon: If you want to build something, come by our booth and talk to us.

We are there to answer your questions and discuss your ideas . The documentation contains all the information at docs.minaprotocol.com. We have a ZK-Apps Q&A channel on our Discord server, which is full of people who respond very quickly, are competent and helpful.

So if you have any technical questions, you can go to the Discord server. This is discord.gg/minaprotocol. I believe this QR code also leads to Discord. And yes, you can ask your questions there.

There is also the ETH Global Discord server. We have a "Mina Sponsor" channel there. You can also go there and ask questions about your plans or make an appointment to meet someone at the booth. You can also send me a DM on Twitter, at Blockchain Beard. I only added that to get more followers.

Thank you for listening, and if you have any questions, we have about five more minutes. Do we have them? No. But I set a timer. So, five minutes.

Yes. Five minutes. No, you don't have to. You can also verify the proof off-chain. But if you want to change the status on-chain, you have to send it to the network, and one of the nodes has to verify the proof that you have a ZK app.

Are there any further questions? Yes. I think I can answer this question like this: Just come join us afterwards, as we have to come to the end now. But we can gladly talk more about how to think about recursion and how to write the corresponding code. Anyone else who is interested can also talk to us or visit us at our stand .

Thank you all so much.

Automatic transcript — names and jargon may be misspelled.