Skip to content
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
a22d895
chore: add example script to generate a verifier contract
TomAFrench May 9, 2024
96b58f7
chore!: remove `codegen-verifier` command
TomAFrench May 9, 2024
8e6c37a
chore: update docs
TomAFrench May 13, 2024
37b68b1
Update noir/noir-repo/examples/codegen-verifier/codegen_verifier.sh
TomAFrench May 13, 2024
836b861
chore: update integration tests to call `bb` directly
TomAFrench May 13, 2024
75e4dd4
chore: update usage to handle bb.js
TomAFrench May 13, 2024
9ccef03
Merge branch 'master' into tf/remove-codegen-verifier
TomAFrench May 13, 2024
b08729d
chore: add simple docs for installing `bb`
TomAFrench May 13, 2024
adc693c
chore: fix codegen-verifiers.sh
TomAFrench May 13, 2024
1a0c641
chore: installs `bb` for noir CI
TomAFrench May 13, 2024
4cf2403
Update noir/noir-repo/examples/codegen-verifier/codegen_verifier.sh
TomAFrench May 16, 2024
b44d4b4
Merge branch 'master' into tf/remove-codegen-verifier
TomAFrench May 16, 2024
45783d7
feat: extend example to show how
TomAFrench May 16, 2024
1270e1b
pull over some more files
TomAFrench May 16, 2024
25dbbeb
Merge branch 'master' into tf/remove-codegen-verifier
TomAFrench May 16, 2024
0016c8d
chore: add `examples` target to CI
TomAFrench May 16, 2024
898cf57
chore: update test
TomAFrench May 16, 2024
fe3cfc7
chore: remove contract.sol
TomAFrench May 16, 2024
1d8acfe
chore(ci): dont look for tags if pure spot (#6446)
ludamad May 16, 2024
1962ead
Merge branch 'master' into tf/remove-codegen-verifier
TomAFrench May 16, 2024
76b7b59
Update noir/noir-repo/examples/codegen-verifier/codegen_verifier.sh
TomAFrench May 16, 2024
eadaa0d
chore!: remove `nargo prove` and `nargo verify` (#6321)
TomAFrench May 16, 2024
7dcc7da
feat!: remove backend interactions from `nargo` (#6369)
TomAFrench May 16, 2024
4a99019
Merge branch 'master' into tf/remove-codegen-verifier
TomAFrench May 16, 2024
fdcb0d8
Update noir/noir-repo/docs/docs/how_to/how-to-solidity-verifier.md
TomAFrench May 16, 2024
999e333
chore: remove dead code
TomAFrench May 16, 2024
9ac2ed1
Merge branch 'master' into tf/remove-codegen-verifier
TomAFrench May 17, 2024
12691b4
Merge branch 'master' into tf/remove-codegen-verifier
TomAFrench May 17, 2024
7fab767
fmt
TomAFrench May 17, 2024
435ab31
chore: update docs to reflect lack of `Verifier.toml` file
TomAFrench May 17, 2024
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
14 changes: 13 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -241,9 +241,21 @@ jobs:
- uses: ./.github/ci-setup-action
with:
concurrency_key: noir-x86
- name: "Test Noir JS packages"
- name: "Test Nargo"
run: earthly-ci --no-output ./noir+test

noir-examples:
needs: setup
runs-on: ${{ github.event.pull_request.user.login || github.actor }}-x86
steps:
- uses: actions/checkout@v4
with: { ref: "${{ env.GIT_COMMIT }}" }
- uses: ./.github/ci-setup-action
with:
concurrency_key: noir-examples-x86
- name: "Test Noir examples"
run: earthly-ci --no-output ./noir+examples

noir-packages-test:
needs: setup
runs-on: ${{ github.event.pull_request.user.login || github.actor }}-x86
Expand Down
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
url = https://github.com/Arachnid/solidity-stringutils
[submodule "barretenberg/sol/lib/openzeppelin-contracts"]
path = barretenberg/sol/lib/openzeppelin-contracts
url = https://github.com/OpenZeppelin/openzeppelin-contracts
url = https://github.com/OpenZeppelin/openzeppelin-contracts
15 changes: 15 additions & 0 deletions noir/Earthfile
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,21 @@ test:
COPY noir-repo/.rustfmt.toml noir-repo/.rustfmt.toml
RUN ./scripts/test_native.sh

examples:
FROM +nargo
ENV PATH="/usr/src/noir-repo/target/release:${PATH}"

COPY --dir noir-repo/examples noir-repo
COPY ../barretenberg/cpp/+preset-clang-assert/bin/bb /usr/src/barretenberg/cpp/build/bin/bb

ENV BACKEND=/usr/src/barretenberg/cpp/build/bin/bb

WORKDIR noir-repo/examples/codegen-verifier
RUN ./test.sh

WORKDIR ../prove_and_verify
RUN ./test.sh

format:
FROM +nargo
ENV PATH=$PATH:/usr/src/noir-repo/target/release
Expand Down
5 changes: 5 additions & 0 deletions noir/noir-repo/.github/workflows/test-js-packages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,11 @@ jobs:
- name: Checkout
uses: actions/checkout@v4

- name: Download bb binary
run: |
# Adds `bb` to PATH
./scripts/install_bb.sh

- name: Download nargo binary
uses: actions/download-artifact@v4
with:
Expand Down
2 changes: 0 additions & 2 deletions noir/noir-repo/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,26 +1,34 @@
#!/usr/bin/env bash

NARGO_BACKEND_PATH=${NARGO_BACKEND_PATH:-bb}

self_path=$(dirname "$(readlink -f "$0")")

repo_root=$self_path/../../..

# Run codegen-verifier for 1_mul
# We want to move all the contracts to the root of compiler/integration-tests
contracts_dir=$self_path/../contracts
rm -rf $contracts_dir
mkdir $contracts_dir

KEYS=$(mktemp -d)

# Codegen verifier contract for 1_mul
mul_dir=$repo_root/test_programs/execution_success/1_mul
nargo --program-dir $mul_dir codegen-verifier
nargo --program-dir $mul_dir compile
$NARGO_BACKEND_PATH write_vk -b $mul_dir/target/1_mul.json -o $KEYS/1_mul
$NARGO_BACKEND_PATH contract -k $KEYS/1_mul -o $contracts_dir/1_mul.sol

# Run codegen-verifier for assert_statement
# Codegen verifier contract for assert_statement
assert_statement_dir=$repo_root/test_programs/execution_success/assert_statement
nargo --program-dir $assert_statement_dir codegen-verifier
nargo --program-dir $assert_statement_dir compile
$NARGO_BACKEND_PATH write_vk -b $assert_statement_dir/target/assert_statement.json -o $KEYS/assert_statement
$NARGO_BACKEND_PATH contract -k $KEYS/assert_statement -o $contracts_dir/assert_statement.sol

# Run codegen-verifier for recursion
# Codegen verifier contract for recursion
recursion_dir=$repo_root/compiler/integration-tests/circuits/recursion
nargo --program-dir $recursion_dir codegen-verifier

# Copy compiled contracts from the root of compiler/integration-tests
contracts_dir=$self_path/../contracts
rm -rf $contracts_dir
mkdir $contracts_dir
nargo --program-dir $recursion_dir compile
$NARGO_BACKEND_PATH write_vk -b $recursion_dir/target/recursion.json -o $KEYS/recursion
$NARGO_BACKEND_PATH contract -k $KEYS/recursion ./ -o $contracts_dir/recursion.sol

cp $mul_dir/contract/1_mul/plonk_vk.sol $contracts_dir/1_mul.sol
cp $assert_statement_dir/contract/assert_statement/plonk_vk.sol $contracts_dir/assert_statement.sol
cp $recursion_dir/contract/recursion/plonk_vk.sol $contracts_dir/recursion.sol
rm -rf $KEYS
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"position": 1,
"label": "Install Barretenberg",
"collapsible": true,
"collapsed": true
}
54 changes: 54 additions & 0 deletions noir/noir-repo/docs/docs/getting_started/barretenberg/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
---
title: Barretenberg Installation
description:
`bb` is a command line tool for interacting with Aztec's proving backend Barretenberg. This page is a quick guide on how to install `bb`
keywords: [
Barretenberg
bb
Installation
Terminal Commands
Version Check
Nightlies
Specific Versions
Branches
]
pagination_next: getting_started/hello_noir/index
---

`bb` is the CLI tool for generating and verifying proofs for Noir programs using the Barretenberg proving library. It also allows generating solidity verifier contracts for which you can verify contracts which were constructed using `bb`.

## Installing `bb`

Open a terminal on your machine, and write:

##### macOS (Apple Silicon)

```bash
mkdir -p $HOME/.barretenberg && \
curl -o ./barretenberg-aarch64-apple-darwin.tar.gz -L https://github.com/AztecProtocol/aztec-packages/releases/download/aztec-packages-v0.38.0/barretenberg-aarch64-apple-darwin.tar.gz && \
tar -xvf ./barretenberg-aarch64-apple-darwin.tar.gz -C $HOME/.barretenberg/ && \
echo 'export PATH=$PATH:$HOME/.barretenberg/' >> ~/.zshrc && \
source ~/.zshrc
```

##### macOS (Intel)

```bash
mkdir -p $HOME/.barretenberg && \
curl -o ./barretenberg-x86_64-apple-darwin.tar.gz -L https://github.com/AztecProtocol/aztec-packages/releases/download/aztec-packages-v0.38.0/barretenberg-x86_64-apple-darwin.tar.gz && \
tar -xvf ./barretenberg-x86_64-apple-darwin.tar.gz -C $HOME/.barretenberg/ && \
echo 'export PATH=$PATH:$HOME/.barretenberg/' >> ~/.zshrc && \
source ~/.zshrc
```

##### Linux (Bash)

```bash
mkdir -p $HOME/.barretenberg && \
curl -o ./barretenberg-x86_64-linux-gnu.tar.gz -L https://github.com/AztecProtocol/aztec-packages/releases/download/aztec-packages-v0.38.0/barretenberg-x86_64-linux-gnu.tar.gz && \
tar -xvf ./barretenberg-x86_64-linux-gnu.tar.gz -C $HOME/.barretenberg/ && \
echo -e 'export PATH=$PATH:$HOME/.barretenberg/' >> ~/.bashrc && \
source ~/.bashrc
```

Now we're ready to start working on [our first Noir program!](../hello_noir/index.md)
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"position": 1,
"position": 2,
"collapsible": true,
"collapsed": true
}
41 changes: 27 additions & 14 deletions noir/noir-repo/docs/docs/getting_started/hello_noir/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ Two additional files would be generated in your project directory:

_Prover.toml_ houses input values, and _Verifier.toml_ houses public values.

## Prove Our Noir Program
## Execute Our Noir Program

Now that the project is set up, we can create a proof of correct execution of our Noir program.
Now that the project is set up, we can execute our Noir program.

Fill in input values for execution in the _Prover.toml_ file. For example:

Expand All @@ -105,37 +105,50 @@ x = "1"
y = "2"
```

Prove the valid execution of your Noir program:
Execute your Noir program:

```sh
nargo prove
nargo execute witness-name
```

A new folder _proofs_ would then be generated in your project directory, containing the proof file
`<project-name>.proof`, where the project name is defined in Nargo.toml.
The witness corresponding to this execution will then be written to the file `./target/witness-name.gz`.

The _Verifier.toml_ file would also be updated with the public values computed from program
execution (in this case the value of `y`):
The _Verifier.toml_ file would also be updated with the public values computed from program execution (in this case the value of `y`):

```toml
y = "0x0000000000000000000000000000000000000000000000000000000000000002"
```

> **Note:** Values in _Verifier.toml_ are computed as 32-byte hex values.
> **Note:** Fields in _Verifier.toml_ are outputted as 32-byte hex values.

## Prove Our Noir Program

:::info

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).

:::

Prove the valid execution of your Noir program using `bb`:

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

A new file called `proof` will be generated in your project directory, containing the generated proof for your program.

## Verify Our Noir Program

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

Verify your proof by running:

```sh
nargo verify
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.
The verification will complete in silence if it is successful. If it fails, it will log the corresponding error instead.

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,20 +92,15 @@ fn main(x : Field, y : Field) {
}
```

The parameters `x` and `y` can be seen as the API for the program and must be supplied by the
prover. Since neither `x` nor `y` is marked as public, the verifier does not supply any inputs, when
verifying the proof.
The parameters `x` and `y` can be seen as the API for the program and must be supplied by the prover. Since neither `x` nor `y` is marked as public, the verifier does not supply any inputs, when verifying the proof.

The prover supplies the values for `x` and `y` in the _Prover.toml_ file.

As for the program body, `assert` ensures that the condition to be satisfied (e.g. `x != y`) is
constrained by the proof of the execution of said program (i.e. if the condition was not met, the
verifier would reject the proof as an invalid proof).
As for the program body, `assert` ensures that the condition to be satisfied (e.g. `x != y`) is constrained by the proof of the execution of said program (i.e. if the condition was not met, the verifier would reject the proof as an invalid proof).

### Prover.toml

The _Prover.toml_ file is a file which the prover uses to supply his witness values(both private and
public).
The _Prover.toml_ file is a file which the prover uses to supply the inputs to the Noir program (both private and public).

In our hello world program the _Prover.toml_ file looks like this:

Expand All @@ -114,12 +109,9 @@ x = "1"
y = "2"
```

When the command `nargo prove` is executed, two processes happen:
When the command `nargo execute` is executed, nargo will execute the Noir program using the inputs specified in `Prover.toml`, aborting if it finds that these do not satisfy the constraints defined by `main`. In this example, `x` and `y` must satisfy the inequality constraint `assert(x != y)`.

1. Noir creates a proof that `x`, which holds the value of `1`, and `y`, which holds the value of `2`,
is not equal. This inequality constraint is due to the line `assert(x != y)`.

2. Noir creates and stores the proof of this statement in the _proofs_ directory in a file called your-project.proof. So if your project is named "private_voting" (defined in the project Nargo.toml), the proof will be saved at `./proofs/private_voting.proof`. Opening this file will display the proof in hex format.
If an output name is specified such as `nargo execute foo`, the witness generated by this execution will be written to `./target/foo.gz`. This can then be used to generate a proof of the execution.

#### Arrays of Structs

Expand Down Expand Up @@ -155,45 +147,18 @@ baz = 2

#### Custom toml files

You can specify a `toml` file with a different name to use for proving by using the `--prover-name` or `-p` flags.
You can specify a `toml` file with a different name to use for execution by using the `--prover-name` or `-p` flags.

This command looks for proof inputs in the default **Prover.toml** and generates the proof and saves it at `./proofs/<project-name>.proof`:
This command looks for proof inputs in the default **Prover.toml** and generates the witness and saves it at `./target/foo.gz`:

```bash
nargo prove
nargo execute foo
```

This command looks for proof inputs in the custom **OtherProver.toml** and generates proof and saves it at `./proofs/<project-name>.proof`:
This command looks for proof inputs in the custom **OtherProver.toml** and generates the witness and saves it at `./target/bar.gz`:

```bash
nargo prove -p OtherProver
nargo execute -p OtherProver bar
```

## Verifying a Proof

When the command `nargo verify` is executed, two processes happen:

1. Noir checks in the _proofs_ directory for a proof file with the project name (eg. test_project.proof)

2. If that file is found, the proof's validity is checked

> **Note:** The validity of the proof is linked to the current Noir program; if the program is
> changed and the verifier verifies the proof, it will fail because the proof is not valid for the
> _modified_ Noir program.

In production, the prover and the verifier are usually two separate entities. A prover would
retrieve the necessary inputs, execute the Noir program, generate a proof and pass it to the
verifier. The verifier would then retrieve the public inputs, usually from external sources, and
verify the validity of the proof against it.

Take a private asset transfer as an example:

A person using a browser as the prover would retrieve private inputs locally (e.g. the user's private key) and
public inputs (e.g. the user's encrypted balance on-chain), compute the transfer, generate a proof
and submit it to the verifier smart contract.

The verifier contract would then draw the user's encrypted balance directly from the blockchain and
verify the proof submitted against it. If the verification passes, additional functions in the
verifier contract could trigger (e.g. approve the asset transfer).

Now that you understand the concepts, you'll probably want some editor feedback while you are writing more complex code.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: Noir Codegen for TypeScript
description: Learn how to use Noir codegen to generate TypeScript bindings
keywords: [Nargo, Noir, compile, TypeScript]
sidebar_position: 2
sidebar_position: 3
---

When using TypeScript, it is extra work to interpret Noir program outputs in a type-safe way. Third party libraries may exist for popular Noir programs, but they are either hard to find or unmaintained.
Expand Down
4 changes: 2 additions & 2 deletions noir/noir-repo/docs/docs/how_to/how-to-oracles.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ interface ForeignCallResult {

## Step 3 - Usage with Nargo

Using the [`nargo` CLI tool](../getting_started/installation/index.md), you can use oracles in the `nargo test`, `nargo execute` and `nargo prove` commands by passing a value to `--oracle-resolver`. For example:
Using the [`nargo` CLI tool](../getting_started/installation/index.md), you can use oracles in the `nargo test` and `nargo execute` commands by passing a value to `--oracle-resolver`. For example:

```bash
nargo test --oracle-resolver http://localhost:5555
Expand All @@ -203,7 +203,7 @@ As one can see, in NoirJS, the [`foreignCallHandler`](../reference/NoirJS/noir_j

Does this mean you don't have to write an RPC server like in [Step #2](#step-2---write-an-rpc-server)?

You don't technically have to, but then how would you run `nargo test` or `nargo prove`? To use both `Nargo` and `NoirJS` in your development flow, you will have to write a JSON RPC server.
You don't technically have to, but then how would you run `nargo test`? To use both `Nargo` and `NoirJS` in your development flow, you will have to write a JSON RPC server.

:::

Expand Down
Loading