Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(docs): Update proving backend related docs #5601

Merged
merged 12 commits into from
Jul 26, 2024
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
}
61 changes: 61 additions & 0 deletions docs/docs/getting_started/backend/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
---
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 utilities such as proof generation, proof verification and smart contracts verifier generation.
Savio-Sou marked this conversation as resolved.
Show resolved Hide resolved

For the latest information on tooling provided by each proving backend, installation instructions, Noir version compatibility... you may refer to the proving backends' own documentations.
Savio-Sou marked this conversation as resolved.
Show resolved Hide resolved

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.

As an example of how a proving backend could be installed, you can install `bb` running the commands below in a terminal.
Savio-Sou marked this conversation as resolved.
Show resolved Hide resolved

1. Install `bbup`, Barretenberg CLI's installation script:

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

2. Reload your terminal shell environment:
Savio-Sou marked this conversation as resolved.
Show resolved Hide resolved

macOS:
```bash
source ~/.zshrc
```

Linux:
```bash
source ~/.bashrc
```

3. Install the version of `bb` compatible with your Noir version:
Savio-Sou marked this conversation as resolved.
Show resolved Hide resolved

```bash
bbup -v 0.46.1
```

4. Check if the installation was successful:

```bash
bb --version
```

If it successfully prints the version of `bb` 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, 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`).
Savio-Sou marked this conversation as resolved.
Show resolved Hide resolved

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 documentations](https://github.com/AztecProtocol/barretenberg/blob/master/cpp/src/barretenberg/bb/readme.md) for full details about the tool.
Savio-Sou marked this conversation as resolved.
Show resolved Hide resolved

:::
### 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, generate a verification key for your Noir program running:
Savio-Sou marked this conversation as resolved.
Show resolved Hide resolved

```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 the ability to start new projects, compile, execute and test Noir programs from the terminal.
Savio-Sou marked this conversation as resolved.
Show resolved Hide resolved

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
}
Loading
Loading