Skip to content

Commit

Permalink
chore(docs): Update proving backend related docs (#5601)
Browse files Browse the repository at this point in the history
# Description

## Summary\*

Update docs related to the installation and use of proving backends
following #4960.

Focusing mainly on improving:
1. Noir's proving backend agnosticity
2. Formatting/readability

Best to merge this PR in before stable releasing v0.31.0 and v0.32.0.

## Documentation\*

Check one:
- [ ] No documentation needed.
- [x] Documentation included in this PR.
- [ ] **[For Experimental Features]** Documentation to be submitted in a
separate PR.

# PR Checklist\*

- [x] I have tested the changes locally.
- [x] I have formatted the changes with [Prettier](https://prettier.io/)
and/or `cargo fmt` on default settings.

---------

Co-authored-by: James Zaki <[email protected]>
  • Loading branch information
Savio-Sou and jzaki authored Jul 26, 2024
1 parent 106abd7 commit 29295a0
Show file tree
Hide file tree
Showing 24 changed files with 220 additions and 255 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"position": 1,
"label": "Install Barretenberg",
"label": "Install Proving Backend",
"collapsible": true,
"collapsed": true
}
31 changes: 31 additions & 0 deletions docs/docs/getting_started/backend/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
title: Proving Backend Installation
description: Proving backends offer command line tools for proving and verifying Noir programs. This page describes how to install `bb` as an example.
keywords: [
Proving
Backend
Barretenberg
bb
bbup
Installation
Terminal
Command
CLI
Version
]
pagination_next: getting_started/hello_noir/index
---

Proving backends each provide their own tools for working with Noir programs, providing functionality like proof generation, proof verification, and verifier smart contract generation.

For the latest information on tooling provided by each proving backend, installation instructions, Noir version compatibility... you may refer to the proving backends' own documentation.

You can find the full list of proving backends compatible with Noir in [Awesome Noir](https://github.com/noir-lang/awesome-noir/?tab=readme-ov-file#proving-backends).

## Example: Installing `bb`

`bb` is the CLI tool provided by the [Barretenberg proving backend](https://github.com/AztecProtocol/barretenberg) developed by Aztec Labs.

You can find the instructions for installation in [`bb`'s documentation](https://github.com/AztecProtocol/aztec-packages/blob/master/barretenberg/cpp/src/barretenberg/bb/readme.md#installation).

Once installed, we are ready to start working on [our first Noir program](../hello_noir/index.md).
47 changes: 0 additions & 47 deletions docs/docs/getting_started/barretenberg/index.md

This file was deleted.

59 changes: 33 additions & 26 deletions docs/docs/getting_started/hello_noir/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,41 +17,41 @@ sidebar_position: 1

---

Now that we have installed Nargo, it is time to make our first hello world program!
Now that we have installed Nargo and a proving backend, it is time to make our first hello world program!

## Create a Project Directory
### 1. Create a new project directory

Noir code can live anywhere on your computer. Let us create a _projects_ folder in the home
directory to house our Noir programs.
directory to house our first Noir program.

For Linux, macOS, and Windows PowerShell, create the directory and change directory into it by
running:
Create the directory and change directory into it by running:

```sh
mkdir ~/projects
cd ~/projects
```

## Create Our First Nargo Project
## Nargo

Nargo provides the ability to initiate and execute Noir projects. Read the [Nargo installation](../installation/index.md) section to learn more about Nargo and how to install it.

### 2. Create a new Noir project

Now that we are in the projects directory, create a new Nargo project by running:

```sh
nargo new hello_world
```

> **Note:** `hello_world` can be any arbitrary project name, we are simply using `hello_world` for
> demonstration.
>
> In production, the common practice is to name the project folder as `circuits` for better
> identifiability when sitting alongside other folders in the codebase (e.g. `contracts`, `scripts`,
> `test`).
`hello_world` can be any arbitrary project name, we are simply using `hello_world` for demonstration.

In production, it is common practice to name the project folder, `circuits`, for clarity amongst other folders in the codebase (like: `contracts`, `scripts`, and `test`).

A `hello_world` folder would be created. Similar to Rust, the folder houses _src/main.nr_ and
_Nargo.toml_ which contain the source code and environmental options of your Noir program
respectively.

### Intro to Noir Syntax
#### Intro to Noir Syntax

Let us take a closer look at _main.nr_. The default _main.nr_ generated should look like this:

Expand Down Expand Up @@ -81,7 +81,7 @@ The Noir syntax `assert` can be interpreted as something similar to constraints

For more Noir syntax, check the [Language Concepts](../../noir/concepts/comments.md) chapter.

## Build In/Output Files
### 3. Build in/output files

Change directory into _hello_world_ and build in/output files for your Noir program by running:

Expand All @@ -92,7 +92,7 @@ nargo check

A _Prover.toml_ file will be generated in your project directory, to allow specifying input values to the program.

## Execute Our Noir Program
### 4. Execute the Noir program

Now that the project is set up, we can execute our Noir program.

Expand All @@ -111,34 +111,41 @@ nargo execute witness-name

The witness corresponding to this execution will then be written to the file `./target/witness-name.gz`.

## Prove Our Noir Program
The command also automatically compiles your Noir program if it was not already / was edited, which you may notice the compiled artifacts being written to the file `./target/hello_world.json`.

## Proving Backend

:::info
Proving backends provide the ability to generate and verify proofs of executing Noir programs, following Noir's tooling that compiles and executes the programs. Read the [proving backend installation](../backend/index.md) section to learn more about proving backends and how to install them.

Nargo no longer handles communicating with backends in order to generate proofs. In order to prove/verify your Noir programs, you'll need an installation of [bb](../barretenberg/index.md).
Barretenberg is used as an example here to demonstrate how proving and verifying could be implemented and used. Read the [`bb` installation](../backend/index.md#example-installing-bb) section for how to install Barretenberg's CLI tool; refer to [`bb`'s documentation](https://github.com/AztecProtocol/aztec-packages/blob/master/barretenberg/cpp/src/barretenberg/bb/readme.md) for full details about the tool.

:::
### 5. Prove an execution of the Noir program

Prove the valid execution of your Noir program using `bb`:
Using Barretenberg as an example, prove the valid execution of your Noir program running:

```sh
bb prove -b ./target/hello_world.json -w ./target/witness-name.gz -o ./proof
bb prove -b ./target/hello_world.json -w ./target/witness-name.gz -o ./target/proof
```

A new file called `proof` will be generated in your project directory, containing the generated proof for your program.
The proof generated will then be written to the file `./target/proof`.

## Verify Our Noir Program
### 6. Verify the execution proof

Once a proof is generated, we can verify correct execution of our Noir program by verifying the proof file.

Verify your proof by running:
Using Barretenberg as an example, compute the verification key for the Noir program by running:

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

The verification will complete in silence if it is successful. If it fails, it will log the corresponding error instead.
And verify your proof by running:

```sh
bb verify -k ./target/vk -p ./target/proof
```

If successful, the verification will complete in silence; if unsuccessful, the command will trigger logging of the corresponding error.

Congratulations, you have now created and verified a proof for your very first Noir program!

Expand Down
3 changes: 1 addition & 2 deletions docs/docs/getting_started/hello_noir/project_breakdown.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ keywords:
sidebar_position: 2
---

This section breaks down our hello world program from the previous section. We elaborate on the project
structure and what the `prove` and `verify` commands did.
This section breaks down our hello world program from the previous section.

## Anatomy of a Nargo Project

Expand Down
6 changes: 2 additions & 4 deletions docs/docs/getting_started/installation/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,9 @@ keywords: [
pagination_next: getting_started/hello_noir/index
---

`nargo` is the one-stop-shop for almost everything related with Noir. The name comes from our love for Rust and its package manager `cargo`.
`nargo` is a tool for working with Noir programs on the CLI, providing you with the ability to start new projects, compile, execute and test Noir programs from the terminal.

With `nargo`, you can start new projects, compile, execute, prove, verify, test, generate solidity contracts, and do pretty much all that is available in Noir.

Similarly to `rustup`, we also maintain an easy installation method that covers most machines: `noirup`.
The name is inspired by Rust's package manager `cargo`; and similar to Rust's `rustup`, Noir also has an easy installation script `noirup`.

## Installing Noirup

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ assert(x != y);

The Noir syntax `assert` can be interpreted as something similar to constraints in other zk-contract languages.

For more Noir syntax, check the [Language Concepts](../language_concepts/comments.md) chapter.
For more Noir syntax, check the [Language Concepts](../language_concepts/09_comments.md) chapter.

## Build In/Output Files

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ fn main() {
> `false` in _Verifier.toml_.
The boolean type is most commonly used in conditionals like `if` expressions and `assert`
statements. More about conditionals is covered in the [Control Flow](../control_flow.md) and
[Assert Function](../assert.md) sections.
statements. More about conditionals is covered in the [Control Flow](../02_control_flow.md) and
[Assert Function](../04_assert.md) sections.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ You can instantiate a new array of a fixed size with the same value repeated for
let array: [Field; 32] = [0; 32];
```

Like in Rust, arrays in Noir are a fixed size. However, if you wish to convert an array to a [slice](./slices.mdx), you can just call `as_slice` on your array:
Like in Rust, arrays in Noir are a fixed size. However, if you wish to convert an array to a [slice](./05_slices.mdx), you can just call `as_slice` on your array:

```rust
let array: [Field; 32] = [0; 32];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ use dep::std::scalar_mul::fixed_base_embedded_curve;
```

Lastly, as demonstrated in the
[elliptic curve example](../standard_library/cryptographic_primitives/ec_primitives.md#examples), you
[elliptic curve example](../standard_library/cryptographic_primitives/04_ec_primitives.md#examples), you
can import multiple items in the same line by enclosing them in curly braces:

```rust
Expand Down
2 changes: 1 addition & 1 deletion docs/versioned_docs/version-v0.19.4/nargo/01_commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ you run `nargo test`. To print `println` statements in tests, use the `--show-ou

Takes an optional `--exact` flag which allows you to select tests based on an exact name.

See an example on the [testing page](./testing.md).
See an example on the [testing page](./02_testing.md).

### Options

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,19 @@ fn sha256<N>(_input : [u8; N]) -> [u8; 32] {}
Here is a list of the current black box functions that are supported by UltraPlonk:

- AES
- [SHA256](./cryptographic_primitives/hashes.mdx#sha256)
- [Schnorr signature verification](./cryptographic_primitives/schnorr.mdx)
- [Blake2s](./cryptographic_primitives/hashes.mdx#blake2s)
- [Pedersen Hash](./cryptographic_primitives/hashes.mdx#pedersen_hash)
- [Pedersen Commitment](./cryptographic_primitives/hashes.mdx#pedersen_commitment)
- [HashToField128Security](./cryptographic_primitives/hashes.mdx#hash_to_field)
- [ECDSA signature verification](./cryptographic_primitives/ecdsa_sig_verification.mdx)
- [Fixed base scalar multiplication](./cryptographic_primitives/scalar.mdx)
- [SHA256](./cryptographic_primitives/00_hashes.mdx#sha256)
- [Schnorr signature verification](./cryptographic_primitives/02_schnorr.mdx)
- [Blake2s](./cryptographic_primitives/00_hashes.mdx#blake2s)
- [Pedersen Hash](./cryptographic_primitives/00_hashes.mdx#pedersen_hash)
- [Pedersen Commitment](./cryptographic_primitives/00_hashes.mdx#pedersen_commitment)
- [HashToField128Security](./cryptographic_primitives/00_hashes.mdx#hash_to_field)
- [ECDSA signature verification](./cryptographic_primitives/03_ecdsa_sig_verification.mdx)
- [Fixed base scalar multiplication](./cryptographic_primitives/01_scalar.mdx)
- [Compute merkle root](./merkle_trees.md#compute_merkle_root)
- AND
- XOR
- RANGE
- [Keccak256](./cryptographic_primitives/hashes.mdx#keccak256)
- [Keccak256](./cryptographic_primitives/00_hashes.mdx#keccak256)
- [Recursive proof verification](./recursion.md)

Most black box functions are included as part of the Noir standard library, however `AND`, `XOR` and `RANGE` are used as part of the Noir language syntax. For instance, using the bitwise operator `&` will invoke the `AND` black box function. To ensure compatibility across backends, the ACVM has fallback implementations of `AND`, `XOR` and `RANGE` defined in its standard library which it can seamlessly fallback to if the backend doesn't support them.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"position": 1,
"label": "Install Barretenberg",
"label": "Install Proving Backend",
"collapsible": true,
"collapsed": true
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
title: Proving Backend Installation
description: Proving backends offer command line tools for proving and verifying Noir programs. This page describes how to install `bb` as an example.
keywords: [
Proving
Backend
Barretenberg
bb
bbup
Installation
Terminal
Command
CLI
Version
]
pagination_next: getting_started/hello_noir/index
---

Proving backends each provide their own tools for working with Noir programs, providing functionality like proof generation, proof verification, and verifier smart contract generation.

For the latest information on tooling provided by each proving backend, installation instructions, Noir version compatibility... you may refer to the proving backends' own documentation.

You can find the full list of proving backends compatible with Noir in [Awesome Noir](https://github.com/noir-lang/awesome-noir/?tab=readme-ov-file#proving-backends).

## Example: Installing `bb`

`bb` is the CLI tool provided by the [Barretenberg proving backend](https://github.com/AztecProtocol/barretenberg) developed by Aztec Labs.

You can find the instructions for installation in [`bb`'s documentation](https://github.com/AztecProtocol/aztec-packages/blob/master/barretenberg/cpp/src/barretenberg/bb/readme.md#installation).

Once installed, we are ready to start working on [our first Noir program](../hello_noir/index.md).

This file was deleted.

Loading

0 comments on commit 29295a0

Please sign in to comment.