Aztec’s Core Cryptography, Now in Noir

Aztec achieves Noir alignment

Today Aztec Labs is proud to announce that Aztec’s core circuits have been rewritten in Noir.

Aztec’s core circuits were previously written in C++. The circuits spanning private execution, public execution, and proof recursion are now in Noir. We didn’t undertake this decision lightly, but we made the call based on a single fact:

Writing circuits in Noir is simply better.

It was always our goal to achieve Aztec-Noir alignment, unifying our cryptography stack and making our code safer, simpler, and easier to audit.

We’re there now, in the era of unabashed Noir maximalism.

💻 You can find the open Noir circuit repos here.

The Noir circuits are merged and passing Aztec’s stringent protocol test suite–huge achievement for Noir as a language.

Why Noir at all? Why a DSL?

Writing your code in a domain-specific language (DSL) does not make it safer than writing it in a library.
This may not be apparent – a DSL is just a language made for a specific problem. One could create a DSL that makes writing circuits easier, but does not improve on performance. One could even create one that makes writing circuits harder, but it’s very performant. Noir makes writing circuits easier and safer than our cpp library with little sacrifice to performance.

As a startup you want to be able to write code fast, but also safely. If you take too long to ship, you may just die. If you write code that is unsafe or brittle, you may lose the trust of your target audience.

We could say that all developers need to do better. Skill issue. However, this approach doesn’t scale beyond. Developers love to write smart, elegant, clever code, i.e. code that’s subject to bugs. In Noir, you need to opt into writing unsafe code.

The Barretenberg C++ Library

So what’s wrong with using Barretenberg as a C++ library?

Nothing.

In fact, a library inherits a lot of adoption from its host language; a Solidity library can be picked up quickly by Solidity developers, for example.

Aztec’s constraint system library is written in C++, and while this allows developers to do anything they want, it also allows developers to do anything they want

Developers need to be aware of quirks with C++ whenever they use Barretenberg. This can lead to subtle bugs due to the inherent compounding of quirks specific to C++ and quirks specific to the library. In other words, more gotchas or footguns.

Library writers also need to be careful because in some places they are reasoning about constraints. In other places, they are reasoning about unconstrained code or non-constraint system code.

The overarching problem here is that in order to write safe circuits, you need to be able to write C++ code and also be a good circuit writer. These are two different skill sets that Noir reduces to one because Noir is specifically designed as a circuit writing language.

Making the Switch

In March, a team of cryptography engineers developed Aztec’s core cryptography circuits under the guidance of Aztec Labs CEO Zac Williamson. Developing in C++ required significant onboarding and technical overhead, including:

  • Developing an embedded C++ DSL
  • Dealing with the quirks of C++ plus the quirks of our embedded DSL
  • Creating a Frankenstein workflow of CMake and custom build scripts

In the meantime, the Noir team has built a comprehensive toolchain that makes ZK development significantly smoother:

  • Syntactic simplicity makes code easier to reason about
  • Nargo provides convenient package management
  • One-line CLI improves testing

In addition to developer tooling like performance profiling, syntax highlighting, and auto-formatting.

With Noir, we built the fast and safe DevEx we wanted for ourselves, resulting in a full rewrite of all Aztec core circuits from C++ to Noir in less than a month of three engineers’ time.

Here’s a side-by-side code snippet comparison of our private kernelbase rollup circuit in C++ and Noir, highlighting the legibility and simplicity of Noir.

C++:

wukq5oDMz RLVGp0o2CJDCmXKWqjikaufu0JSyeSSOz9p6gKXeqHXtWQjTGsU4gc3FwWDuDzigjrIO3lQg h5MGliNUs2 r3c7Uw4Re3JsVwe6xMtchCfWZkIUyRtzmWV0sGvOiT DcN N 5Vlb3al8

Noir:


Why did we switch?

  • Contributors: developers no longer need to know C++ to write circuits, meaning the number of developers who can now contribute to Aztec’s core circuits has doubled or tripled overnight
  • Tooling: Noir tooling only needs to cater to writing circuits, whereas Barretenberg Library tooling will always take into consideration what is written in C++
  • Stack integration: contracts on the Aztec network are also written in Noir, leading to tighter integration
  • Better optimizations: updates to Noir include new applications that are immediately applied to existing code

Noir Ecosystem

Finally, Aztec Labs gets to more fully participate in Noir’s vibrant ecosystem.

The community continues to develop new tooling that improves code analysis. Developers building in the Noir ecosystem and discovering bugs continuously battle-test the compiler. And Aztec is now fully aligned with the many developers building applications and protocols on Noir.

We too would like to share in the fruits of the Noir community.

Noir maximalism is open-source maximalism.

Build with us toward production

While Noir is still Beta software and isn’t fully production-ready until it is audited, the language is progressing towards an implementation freeze by the first half of 2024, and a completed audit by the back half of the year.

xBQqWxDRdsUaCB8VqWvK5GheUIWDwTOmUXb9NiGcjzIJNE33aKQjcgrRtRUooBSXiXPQnfT5mmzQvARW8pBFJhXA0LH VbCMX1p 6BEQBXkhdPzfhWol2vhBGaWgeV 2aDQozPOR5wWINt0Er9F1JFM

🏗️ Start building with Noir at noir-lang.org.

Next stop: insane crypto

In addition to basic optimizations required for the kernel circuit to run on low-powered mobile devices, we intend on integrating Noir with the arsenal of novel cryptography in our development pipeline:

  • Honk: our next-generation proving system
  • Protogalaxy: super-fast folding
  • Goblin Honk: super-fast recursion
  • Super low-memory proving

Building Aztec in Noir has been a long time coming.

As a result of adapting our core circuits to Noir, testing a wide array of features, and having Noir code pass extensive test suites, we have dramatically more confidence in its stability.

The collaborative approach between our internal Aztec and Noir teams demonstrates a commitment to advancing the capabilities of zero-knowledge proof technologies in an integrated fashion.

Improving Noir now improves Aztec.

Now is the time to Noir

The truth of the matter is: you cannot escape potentially dangerous code.

You can still write unsafe code in Noir.

You can only move the responsibility of writing dangerous code to folks who are least likely to make a mistake. And with Noir, you make it Aztec Labs engineers’ responsibility to write compiler code and optimizations. And with our stack, we make it the cryptographers’ responsibility to write absolutely unhinged cryptographic proving systems.

You are free to rebuild all of this yourself in C++. But Noir makes it so you don’t need to.

Where we cannot help you is unsafe business logic. If your application was meant to choose a random number between 1 and 10 and it instead chooses a random number between 0 and 1, then that’s on you. 

But that’s as it should be! That’s the sort of code that you should be responsible for, and Noir aims to make it such that that’s the only thing you are responsible for.

If that sounds good to you, you might consider making the switch, as we have.

⭐ Get started with Noir today at noir-lang.org.