Sailos
Tutorials

Noir

Requires Rust curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

Install Noir and BB

BB is Aztec's Barretenberg Proving backend.

curl -L https://raw.githubusercontent.com/noir-lang/noirup/main/install | bash
curl -L https://raw.githubusercontent.com/AztecProtocol/aztec-packages/master/barretenberg/cpp/installation/install | bash

Close the terminal, open another one, and run.

noirup
bbup --version 0.59.0

Noir Lang & BB Compatibility

  • Noir v1.0.0-beta.0 - BB v0.63.1
  • Noir v0.36.0 - BB v0.59.0
  • Noir v0.34.0 - BB v0.55.0
  • Noir v0.33.0 - BB v0.47.1
  • Noir v0.32.0 - BB v0.46.1
  • Noir v0.31.0 - BB v0.41.0

Setting up the Project

cargo init && nargo init

Your folder structure should look like this

main.nr
main.rs
Cargo.toml
Nargo.toml

Build and Test your Circuit

nargo check

This should create a Prover.toml file like such,

x = ""
y = ""

You can edit this file to pass inputs to your circuits.

You should play around with this file and try out different inputs. Example,

x = "1"
y = "2"

Now run your circuit,

nargo execute mywitness

Your witness should be available in ./target/mywitness.gz

nargo compile

Your circuit should be present in ./target/hello_world.json directory.

Build and Verify your Proof

Prove

bb prove -b ./target/hello_world.json -w ./target/mywitness.gz -o ./target/proof

Verify

bb write_vk -b ./target/hello_world.json -o ./target/vk
bb verify -k ./target/vk -p ./target/proof

On-chain Verification

bb write_vk -b ./target/hello_world.json
bb contract

You should now have a contract.sol in your ./target/ directory.

Trimming your SRS

trim.rs
use noir_rs::srs::{get_srs, localsrs::LocalSrs, netsrs::NetSrs, Srs};
 
fn main() {
  let srs: Srs = NetSrs::new(4194304).to_srs(); // 2^22
  let local_srs = LocalSrs(srs);
 
  let save_path = "./srs22.dat";
  local_srs.save(Some(&save_path));
}

More Reading

On this page