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): refactoring guides and some other nits #6175

Merged
merged 19 commits into from
Oct 19, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ yarn-error.log*

package-lock.json
versions.json
.supermavenignore
3 changes: 0 additions & 3 deletions docs/.markdownlint.json
signorecello marked this conversation as resolved.
Show resolved Hide resolved

This file was deleted.

2 changes: 1 addition & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ yarn build
### Local Development

```
yarn workspace docs start
yarn workspace docs dev
```

This command starts a local development server and opens up a browser window. Most changes are
Expand Down
114 changes: 114 additions & 0 deletions docs/docs/getting_started.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
---
title: Getting Started
tags: []
---

## A Quick Start

The easiest way to use Noir is through `nargo` (inspired by Rust's `cargo`). You can use `noirup` to quickly install `nargo`:

```bash
curl -L noirup.dev | bash
signorecello marked this conversation as resolved.
Show resolved Hide resolved
noirup
```

Since Noir is a backend-agnostic programming language for writing zero-knowledge proofs, we need to pair it with a proving backend.

As an example, we can will use Aztec Lab's [Barretenberg backend](https://github.com/AztecProtocol/aztec-packages/tree/master/barretenberg). This is made easy by [`bbup`](https://github.com/AztecProtocol/aztec-packages/blob/master/barretenberg/bbup), which installs Barretenberg's [`bb` CLI tool](https://github.com/AztecProtocol/aztec-packages/tree/master/barretenberg):

```bash
curl -L bbup.dev | bash
bbup
```

:::info

_Always_ inspect what you run.

- `noirup.dev` redirects to [this script](https://github.com/noir-lang/noirup/blob/main/install) and adds [this program](https://github.com/noir-lang/noirup/blob/main/noirup) to your path.
- according to the [bbup documentation](https://github.com/AztecProtocol/aztec-packages/tree/master/barretenberg/bbup), `bbup.dev` redirects to [this script](https://github.com/AztecProtocol/aztec-packages/blob/master/barretenberg/bbup/install) which adds [this program](https://github.com/AztecProtocol/aztec-packages/blob/master/barretenberg/bbup/bbup.ts) globally, installing `node` if needed.
TomAFrench marked this conversation as resolved.
Show resolved Hide resolved

:::

## Nargo

Nargo provides the ability to initiate and execute Noir projects. Let's initialize the traditional `hello_world`:

```sh
nargo new hello_world
```

Two files will be created.

- `src/main.nr` contains a simple boilerplate circuit
- `Nargo.toml` contains environmental options, such as name, author, dependencies, and others.

Glancing at _main.nr_ , we can see that inputs in Noir are private by default, but can be labeled public using the keyword `pub`. This means that we will _assert_ that we know a value `x` which is different from `y` without revealing `x`:

```rust
fn main(x : Field, y : pub Field) {
assert(x != y);
}
```

To learn more about private and public values, check the [Data Types](./noir/concepts/data_types/index.md) section.

### Compiling and executing

We can now use `nargo` to generate a _Prover.toml_ file, where our input values will be specified:

```sh
nargo check
```

Let's feed some valid values into this file:

```toml
x = "1"
y = "2"
```

We're now ready to compile and execute our Noir program. By default the `nargo execute` command will do both, and generate the `witness` that we need to feed to our proving backend:

```sh
nargo execute hello-witness
signorecello marked this conversation as resolved.
Show resolved Hide resolved
```

You can now see the witness and the compiled circuit in the `target` folder. We're ready to prove

## Barretenberg

Using the `bb` CLI tool as an example:

```sh
bb prove -b ./target/hello_world.json -w ./target/hello-witness.gz -o ./target/proof
signorecello marked this conversation as resolved.
Show resolved Hide resolved
```

:::tip

Naming can be confusing, specially as you pass them to the `bb` commands. If unsure, it won't hurt to delete the target folder and start anew to make sure you're using the most recent versions of the compiled circuit and witness.

:::

The proof is now generated in the `target` folder. To verify it we first need to compute the verification key from the compiled circuit, and use it to verify:

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

:::info

Notice that in order to verify a proof, the verifier knows nothing but the circuit, which is compiled and used to generate the verification key. This is obviously quite important: private inputs remain private.

As for the public inputs, you may have noticed they haven't been specified. This behavior varies with each particular backend, but barretenberg typically attaches them to the proof. You can see them by parsing and splitting it. For example for if your public inputs are 32 bytes:

```bash
head -c 32 ./target/proof | od -An -v -t x1 | tr -d $' \n'
```

:::

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

In the [next section](./getting_started/project_breakdown.md), we will go into more detail on each step performed.
5 changes: 0 additions & 5 deletions docs/docs/getting_started/_category_.json

This file was deleted.

6 changes: 0 additions & 6 deletions docs/docs/getting_started/backend/_category_.json

This file was deleted.

31 changes: 0 additions & 31 deletions docs/docs/getting_started/backend/index.md

This file was deleted.

5 changes: 0 additions & 5 deletions docs/docs/getting_started/hello_noir/_category_.json

This file was deleted.

157 changes: 0 additions & 157 deletions docs/docs/getting_started/hello_noir/index.md

This file was deleted.

6 changes: 0 additions & 6 deletions docs/docs/getting_started/installation/_category_.json

This file was deleted.

46 changes: 0 additions & 46 deletions docs/docs/getting_started/installation/index.md

This file was deleted.

Loading
Loading