Skip to content
Merged
Show file tree
Hide file tree
Changes from 20 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
6 changes: 4 additions & 2 deletions .github/spot-runner-action/dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -754,8 +754,10 @@ function requestAndWaitForSpot(config) {
// wait 10 seconds
yield new Promise((r) => setTimeout(r, 5000 * Math.pow(2, backoff)));
backoff += 1;
core.info("Polling to see if we somehow have an instance up");
instanceId = yield ((_a = ec2Client.getInstancesForTags("running")[0]) === null || _a === void 0 ? void 0 : _a.instanceId);
if (config.githubActionRunnerConcurrency > 0) {
core.info("Polling to see if we somehow have an instance up");
instanceId = yield ((_a = ec2Client.getInstancesForTags("running")[0]) === null || _a === void 0 ? void 0 : _a.instanceId);
}
}
if (instanceId) {
core.info("Successfully requested/found instance with ID " + instanceId);
Expand Down
6 changes: 4 additions & 2 deletions .github/spot-runner-action/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,10 @@ async function requestAndWaitForSpot(config: ActionConfig): Promise<string> {
// wait 10 seconds
await new Promise((r) => setTimeout(r, 5000 * 2 ** backoff));
backoff += 1;
core.info("Polling to see if we somehow have an instance up");
instanceId = await ec2Client.getInstancesForTags("running")[0]?.instanceId;
if (config.githubActionRunnerConcurrency > 0) {
core.info("Polling to see if we somehow have an instance up");
instanceId = await ec2Client.getInstancesForTags("running")[0]?.instanceId;
}
}
if (instanceId) {
core.info("Successfully requested/found instance with ID " + instanceId);
Expand Down
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
12 changes: 12 additions & 0 deletions noir/Earthfile
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,18 @@ 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

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
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
}
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
14 changes: 11 additions & 3 deletions noir/noir-repo/docs/docs/how_to/how-to-solidity-verifier.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,19 @@ Generating a Solidity Verifier contract is actually a one-command process. Howev
This is by far the most straight-forward step. Just run:

```sh
nargo codegen-verifier
nargo compile
```

A new `contract` folder would then be generated in your project directory, containing the Solidity
file `plonk_vk.sol`. It can be deployed to any EVM blockchain acting as a verifier smart contract.
This will compile your source code into a Noir build artifact to be stored in the `./target` directory, you can then generate the smart contract using the commands:

```sh
# Here we pass the path to the newly generated Noir artifact.
bb write_vk -b ./target/<noir_artifact_name>.json
bb contract
```

replacing `<noir_artifact_name>` with the name of your Noir project. A new `contract` folder would then be generated in your project directory, containing the Solidity
file `contract.sol`. It can be deployed to any EVM blockchain acting as a verifier smart contract.

:::info

Expand Down
4 changes: 4 additions & 0 deletions noir/noir-repo/examples/codegen-verifier/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
out
cache
target
src/contract.sol
7 changes: 7 additions & 0 deletions noir/noir-repo/examples/codegen-verifier/Nargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "hello_world"
type = "bin"
authors = [""]
compiler_version = ">=0.29.0"

[dependencies]
2 changes: 2 additions & 0 deletions noir/noir-repo/examples/codegen-verifier/Prover.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
x = 1
y = 2
44 changes: 44 additions & 0 deletions noir/noir-repo/examples/codegen-verifier/codegen_verifier.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/bin/bash
set -eu

BACKEND=${BACKEND:-bb}

nargo compile

# TODO: backend should automatically generate vk if necessary.
Comment thread
TomAFrench marked this conversation as resolved.
$BACKEND write_vk -b ./target/hello_world.json
$BACKEND contract -o ./src/contract.sol

# We now generate a proof and check whether the verifier contract will verify it.

nargo execute witness

PROOF_PATH=./target/proof
$BACKEND prove -b ./target/hello_world.json -w ./target/witness.gz -o $PROOF_PATH

NUM_PUBLIC_INPUTS=1
PUBLIC_INPUT_BYTES=$((32 * $NUM_PUBLIC_INPUTS))
HEX_PUBLIC_INPUTS=$(head -c $PUBLIC_INPUT_BYTES $PROOF_PATH | od -An -v -t x1 | tr -d $' \n')
HEX_PROOF=$(tail -c +$(($PUBLIC_INPUT_BYTES + 1)) $PROOF_PATH | od -An -v -t x1 | tr -d $' \n')

# echo "Public inputs:"
# echo $HEX_PUBLIC_INPUTS

# echo "Proof:"
# echo "0x$HEX_PROOF"

Comment thread
TomAFrench marked this conversation as resolved.
Outdated
# Spin up an anvil node to deploy the contract to
anvil &

DEPLOY_INFO=$(forge create UltraVerifier \
--rpc-url "127.0.0.1:8545" \
--private-key "0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80" \
--json)
VERIFIER_ADDRESS=$(echo $DEPLOY_INFO | jq -r '.deployedTo')

# Call the verifier contract with our proof.
# Note that we haven't needed to split up `HEX_PUBLIC_INPUTS` as there's only a single public input
Comment thread
TomAFrench marked this conversation as resolved.
cast call $VERIFIER_ADDRESS "verify(bytes, bytes32[])(bool)" "0x$HEX_PROOF" "[0x$HEX_PUBLIC_INPUTS]"

# Stop anvil node again
kill %-
6 changes: 6 additions & 0 deletions noir/noir-repo/examples/codegen-verifier/foundry.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[profile.default]
src = "src"
out = "out"
libs = ["lib"]

# See more config options https://github.com/foundry-rs/foundry/blob/master/crates/config/README.md#all-options
3 changes: 3 additions & 0 deletions noir/noir-repo/examples/codegen-verifier/src/main.nr
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main(x: Field, y: pub Field) {
assert(x != y);
}
15 changes: 15 additions & 0 deletions noir/noir-repo/examples/codegen-verifier/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash
set -eu

# This file is used for Noir CI and is not required.

BACKEND=${BACKEND:-bb}

rm -f ./src/contract.sol

./codegen_verifier.sh

if ! [ -f ./src/contract.sol ]; then
printf '%s\n' "Contract not written to file" >&2
exit 1
fi
9 changes: 9 additions & 0 deletions noir/noir-repo/scripts/install_bb.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

# We use this script just for CI so we assume we're running on x86 linux

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/' >> ~/.bashrc
source ~/.bashrc
Loading