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

Loading player…

RISC Zero 🛠️ Getting Started with RISC Zero

ETHGlobalWed, Oct 9, 2024, 12:00 AM

With RISC Zero, it's easier than ever to integrate ZKPs into whatever you're building. Join Paul Gafni in this workshop to learn how to get started building with RISC Zero, including what you can prove, options for proof generation, and how to get proofs verified on-chain. As new users flock to web3, critical infrastructure advancements are needed to scale. Join us April 5th-26th for three weeks of hacking and summits around shaping the future of Ethereum. ----------------- Follow us: https://x.com/ETHGlobal?s=20 Check us out: https://ethglobal.com/ Email us at: hello@ethglobal.com

Transcript

Okay, let's start with a short walkthrough on how to begin building a project with Risk Zero. We're at riskzero.com. You can go to the documentation and go directly to the getting started page. And it says that to harness the power of ZK, you must first write an application for Risk Zero's ZKVM.

Second, generate tests for your ZKVM application. And third, integrate your tests into applications in the chain. This diagram is perhaps a little small. Here is a slightly larger version of this diagram. At the top, we can see these three steps.

We need to build a ZKVM application, generate tests, and integrate those tests into blockchain applications. And then, in the middle layer here, we can see those three steps broken down we can see those three steps broken down . On the left, we have ZKVM application development, for which we suggest starting with the ZKVM quickstart, or there is a " ZKVM quickstart, or there is a " hello world" tutorial which is also a good option for learning about ZKVM application development. And then in between, we recognize that once you've built a ZKVM application, you'll want to generate tests for it. So, while you're building, you'll probably want to use development mode, which skips testing, allowing for very rapid prototyping.

If your application involves privacy, you may want to use local test generation. ZKVM is available in a mode where you run it locally on your own hardware or in a remote generation context, where you request our testing service, Bonsai, to generate the tests. Remote generation will offer substantially faster testing because we parallelized test generation at Bonsai. However, you should know that if you send your tests to Bonsai for generation, whoever is generating them can see all the internal information of the program, including private data. Therefore, if you want to generate a test on private data, you might want to generate your first tests locally to manage that data.

And the third step to the right is about integration with blockchain. Once we have generated the tests, we must publish them on the chain. And then we need those tests to be verified in the chain. We provide a chain verifier to facilitate that process. So, on the blockchain side, we offer a Foundry template that makes it very easy to get started with a cohesive project involving the ZKVM application side and the necessary Solidity contracts.

Let's pause here. I hope this guidance is helpful, and we will continue with more information soon. Okay, let's delve into a brief introduction on how to think about ZKVM applications and how to start creating them. The general idea is that you will need to write an application for the ZKVM of RISC Zero. You'll need to generate proofs for that application, and assuming you want to do anything with blockchains, you'll need to integrate those proofs into on-chain applications.

In this video, I want to delve deeper into the first part: how do we start writing an application for the ZKVM of RISC Zero? If we click on this link from the home page, it will take us directly to the quick start guide. But, before we get into the quick guide, I want to back up a bit to consider an overview of ZKVM. In particular, I want to go down in the ZKVM overview to this diagram, to contextualize the parts of the system. ZKVM allows you to demonstrate the correct execution of Rust code.

So you're going to provide some Rust code. The Rust code. The guest code is what will be demonstrated guest code is what will be demonstrated . You will compile your guest code using the cargo risczero tool into an ELF binary. This is like the RISC-V format of binary files.

Then you'll run your RISC-V binary on the ZKVM, which is essentially this box right here. The ZKVM will generate a receipt. And you can use this on-chain receipt to prove the correct execution of your Rust code. Within ZKVM there are some implementation details that you don't need to worry about too much for now. But, to introduce you to the idea, the executor will produce an execution trace, which is divided into several segments.

The session is the complete record of your large computation, or perhaps it's not such a large computation or perhaps it's not such a large computation . But suppose you are running a large computation on the ZKVM. The session is the complete record of the entire computation, and this will be divided into segments. Then, those segments will be demonstrated. Those tests will be added.

In the end, you'll get a single, concise SNARK that you can publish and verify on-chain. That, in essence, is the general vision of the ZKVM. What you should pay most attention to in order to successfully develop a ZKVM application is the guest code ZKVM application is the guest code ; To learn a little more about how to write it, we can go into this document. So, the guest functionality you should really focus on is that the guest should be able to read posts. It needs power, I suppose I'll highlight that here.

You need to be able to read entries. You need to be able to write private output to the host. And it needs to be able to send public statements to the newspaper. So, this is only during execution; there may be some input and output between the guest and the host. You're going to use the writing functionality.

And if you want something to actually appear on the receipt, you'll use the confirmation feature. So, here are some links to some of the most important features you'll need to work with. Each of these will direct you to the Rust packages for the features associated here Rust packages for the features associated here . We also provide some tools here for debugging and optimization. There's also a whole optimization section further down here.

So, I think that's enough for now as a sort of guideline. We reviewed the general description and the guest code. Of course, there are a couple more documents here that you can consult on your own if you are interested in reading a little more. Thanks for watching the video. Okay, now let's dive into how to start building a ZKVM application.

So, we're on the home page. We click here and end up on the quick start page. If you've never used RISC Zero, you'll probably want to start on the installation page. And you'll need to install Rust. And you will need to install the cargo-risczero tool.

So, you'll use these commands to install the cargo-risczero tool. And then you'll get a message indicating that it's ready to use. You can confirm that you have installed it correctly with this command. Then we can move on to the quick start. In the quick start, there are five steps.

We need to install the toolchain, which we just reviewed. Next, we will use the cargo-risczero tool to create a project. Let's get some guidance on the project. We are going to run the project in development mode. This omits test generation to allow things to move quickly while you build.

And finally, we'll see how to disable development mode to generate a real test of your program. So, step one, install Rust, install the toolchain. Step two, use the cargo risk zero tool to create a new project. Step three, familiarize yourself with this new project you just built. You might want to explore the directory, or perhaps take a look at the Hello World tutorial, which will guide you step-by-step through the parts of your new template project.

In particular, what you need to make sure you know how to do is how to share data between the host and the guest, how to send results to the journal, and how to generate a receipt and interact with it. Okay, once you're familiar with the project, or even if you prefer to skip this step and say "I'll learn later, I just want to run it." This command will skip generating tests. Development mode skips test generation so you can build quickly. And if you disable developer mode, you'll be able to generate real tests.

At the end of the quick guide, we have additional information on how to collect data about how many clock cycles your program uses. ZKVM supports calculations of unlimited size. If your programs are large, we will divide the calculation into several segments. Each segment consists of one million clock cycles. And that's all for the quick guide.

If you're looking for more advanced materials, there are instructions on how to generate proofs here, how to optimize your ZKVM applications here, and how to integrate them into blockchain contexts here. Happy developing and see you soon! Okay, let's talk about the options for generating tests. You've already written a zkVM application and you're ready to start generating tests. Hopefully, while you were developing, you used development mode so you wouldn't have to wait for test generation.

But now that you're ready to generate tests, you must choose between generating them locally on your own machine or requesting that we generate them for you using Bonsai and send them back to you . The advantage of using Bonsai is that it is highly parallelized. So, this means that the tests will be substantially faster than on your own machine. Remember that if you have a large calculation, when testing it, we will divide it into a group of segments. And when using Bonsai a group of segments.

And when using Bonsai , each of those segment tests will be generated in parallel. Whereas, if you use your own machine, each of those segment tests will be tested one by one sequentially. So again, the advantage of remote testing is that it is substantially faster. Plus, you don't have to worry about the condition of your hardware. And the peak demand on your application.

We will have Bonsai available to manage dynamic peaks in demand. The main reason to consider generating tests locally is if your data is highly sensitive information. In particular, it is important to note that although the ZKVM output is a zero-knowledge proof, whoever generates the proofs can see everything inside the system. Therefore, if you 're not willing to let your secrets leave your own machine, you'll want to generate your tests locally. Once you generate those tests, they can be distributed with complete confidence regarding the privacy of the information.

It is a total zero-knowledge proof that comes out of the ZKVM, whether generated locally or remotely. Those are your options for test generation options for test generation . I will note that, regarding the local test, there are options to run on CPU and GPU there are options to run on CPU and GPU . They don't appear to be documented on this page, but if you go to the main repository and look at the feature flags, you'll see that the flags for CUDA and Metal are listed there. So those are your options for test generation options for test generation .

Happy development. Okay, let's talk about integrating ZKVM applications into blockchain applications. So, essentially, what you'll need to do is publish proofs on the chain and then verify them on the chain. And if you click on this link to integrate your tests into on-chain applications, you'll be taken to our guidance page for blockchain integration. This is...

let me zoom out a bit so the sidebar is visible. So yes, we are in the blockchain integration section of the documents. And this diagram gives you an overview of the conceptual vision of what is going to happen. Assuming you use Bonsai to generate proofs, you will request a proof from Bonsai and Bonsai will send the proof back. And then that test will be published on the network.

And then it will be verified on the chain. So that's the conceptual framework here. We provide this checker. In our Foundry template, you can find starting points for your chain application contract and what we call the publisher application here. So I'll click on the Foundry template and zoom in a bit.

I'm going to move quickly through this. This is similar information to that on the other page, but with more granular details about different parts of the repository. Regarding the organization of the directory, there is a contracts folder that includes the relevant Solidity contracts. And a methods folder that includes the relevant ZKVM application. Inside this methods folder you will find the guest code.

The guest code for this example is "even". You can learn more about writing guest code with this guest code introduction file. So, that's my initial orientation here. There are probably more details I should explain, but the initial points I will point out are: this contracts folder contains everything related to Solidity. This methods folder contains everything related to ZKVM.

Automatic transcript — names and jargon may be misspelled.