Dance with Rust and Zero Knowledge

Lauri Peltonen
Coinmonks
Published in
3 min readOct 25, 2023

--

We all want to learn Rust. Right? And we all want to learn Zero Knowledge… Right??

What if I told you there was a way to learn both of them? Let me spill the beans right here, right now. The amazing secret is: learn them together.

What makes writing Zero Knowledge apps difficult

Zero Knowledge is hard. Writing Zero Knowledge applications is even harder.

In the end, for ZK, it all boils down to the underlying mathematics: understanding how ZK works under the hood is very challenging. Abstracting away these challenges is also, well, challenging.

There are modern ZK languages that make writing ZK apps somewhat straightforward, but they are not (yet?) perfect. One still needs to understand the underlying technology, at least to some degree, to be able to write efficient ZK apps. This is a cumbersome hurdle for any aspiring ZK developer. To make the process at least a bit easier, we need a very modern language.

What makes Rust speshul

Rust is a modern programming language with some rather special properties.

Rusty learning. Image credits: Bing Dall-E

The most important properties, in my opinion, are:

  • Type safety (typical in most modern languages)
  • No automatic garbage collection. Memory management is handled by the user in a way that makes memory leaks pretty difficult, if not impossible
  • Special care for multi-thread execution (surprisingly related to memory management)

Unfortunately, Rust’s unconvential approach to memory management makes it a bit difficult to learn. Basically, writing anything meaningful requires one to understand how memory pointers and lifetimes work. And it takes time to learn that.

Dance together

Since ZK is difficult to get right and Rust is super careful about making things right, using those two together makes sense. Rust tries its best to force you to write ZK — or any apps — in a safe manner.

There are two main ways one can start using Rust for writing ZK programs:

  1. Use one of the ZK languages, which are Rust-based. They’re not exactly Rust, but they look and behave quite like Rust. The upside is that knowing Rust helps you understand these languages (and vice versa), but the downside is that you can’t use the traditional full Rust syntax with these languages, and you need to learn some new tricks as well. Examples of such languages are Noir and Cairo.
  2. Use pure Rust, with some extra crates. This is usually possible for more stand-alone ZK programs that don’t require interoperability. An example is the Risc Zero coprocessor.

You can start with either path — just pick the one that interests you more.

Most likely, you are either better in Rust or better in ZK. Using these together helps you learn both of them better.

Still not child’s play

Unfortunately, whichever path you choose, you will face challenges.

Image credits: Bing Dall-E

To write ZK programs, you need to adjust your mindset a bit. If you’re a web3 developer, you need to stop thinking so much in terms of transactions. If you’re a web2 developer, you need to adjust your mindset a lot.

I’m also still learning ZK development with Rust. Do let me know how your journey goes!

About the author

I’m a ZK & EVM freelancer. I organize ZK courses and, in general, try to educate people about ZK.

Questions, comments, wanna shout at someone? Get in touch!

This post was inspired by the Ethereum Writers cohort.

--

--