Skip to content

Commit

Permalink
Merge branch 'master' into tf/clippy
Browse files Browse the repository at this point in the history
* master:
  feat: codegen typed interfaces for functions in `noir_codegen` (#3533)
  chore: add dependency on noir_js from docs package (#3559)
  chore: Docs 0.19.3 (#3545)
  chore(debugger): Inject abstract foreign call executor to debugger (#3550)
  chore: nargo fmt (#3549)
  • Loading branch information
TomAFrench committed Nov 27, 2023
2 parents 0a3d15e + 290c463 commit 1da56c3
Show file tree
Hide file tree
Showing 193 changed files with 12,676 additions and 95 deletions.
25 changes: 5 additions & 20 deletions .github/workflows/docs-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ jobs:
if: needs.add_label.outputs.has_label == 'true'
steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v2
Expand All @@ -71,24 +71,8 @@ jobs:
run: |
npm i wasm-opt -g
- name: Install dependencies
run: yarn

- name: Build acvm_js
run: yarn workspace @noir-lang/acvm_js build

- name: Build noirc_abi
run: yarn workspace @noir-lang/noirc_abi build

- name: Build noir_js_types
run: yarn workspace @noir-lang/types build

- name: Build barretenberg wrapper
run: yarn workspace @noir-lang/backend_barretenberg build

- name: Run noir_js
run: |
yarn workspace @noir-lang/noir_js build
- name: Install Yarn dependencies
uses: ./.github/actions/setup

- name: Remove pre-releases
working-directory: docs
Expand All @@ -97,8 +81,9 @@ jobs:
run: yarn setStable

- name: Build docs
working-directory: docs
run:
yarn workspace docs build
yarn workspaces foreach -Rt run build

- name: Deploy to Netlify
uses: nwtgck/[email protected]
Expand Down
97 changes: 97 additions & 0 deletions .github/workflows/test-noir_codegen.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
name: noir_codegen

on:
pull_request:
merge_group:
push:
branches:
- master

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.ref || github.run_id }}
cancel-in-progress: true

jobs:
build-nargo:
runs-on: ubuntu-22.04
strategy:
matrix:
target: [x86_64-unknown-linux-gnu]

steps:
- name: Checkout Noir repo
uses: actions/checkout@v4

- name: Setup toolchain
uses: dtolnay/[email protected]

- uses: Swatinem/rust-cache@v2
with:
key: ${{ matrix.target }}
cache-on-failure: true
save-if: ${{ github.event_name != 'merge_group' }}

- name: Build Nargo
run: cargo build --package nargo_cli --release

- name: Package artifacts
run: |
mkdir dist
cp ./target/release/nargo ./dist/nargo
7z a -ttar -so -an ./dist/* | 7z a -si ./nargo-x86_64-unknown-linux-gnu.tar.gz
- name: Upload artifact
uses: actions/upload-artifact@v3
with:
name: nargo
path: ./dist/*
retention-days: 3

test:
needs: [build-nargo]
name: Test noir_codegen
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Install Yarn dependencies
uses: ./.github/actions/setup

- name: Setup toolchain
uses: dtolnay/[email protected]
with:
targets: wasm32-unknown-unknown

- uses: Swatinem/rust-cache@v2
with:
key: wasm32-unknown-unknown-noir-js
cache-on-failure: true
save-if: ${{ github.event_name != 'merge_group' }}

- name: Install jq
run: sudo apt-get install jq

- name: Install wasm-bindgen-cli
uses: taiki-e/install-action@v2
with:
tool: [email protected]

- name: Install wasm-opt
run: |
npm i wasm-opt -g
- name: Build acvm_js
run: yarn workspace @noir-lang/acvm_js build

- name: Build noirc_abi
run: yarn workspace @noir-lang/noirc_abi build

- name: Build noir_js_types
run: yarn workspace @noir-lang/types build

- name: Build noir_js
run: yarn workspace @noir-lang/noir_js build

- name: Run noir_codegen tests
run: yarn workspace @noir-lang/noir_codegen test
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,6 @@ compiler/wasm/web
tooling/noirc_abi_wasm/nodejs
tooling/noirc_abi_wasm/web
tooling/noir_js/lib

# docs autogen build
/docs/docs/noir_js/reference/
4 changes: 2 additions & 2 deletions docs/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# Generated files
.docusaurus
.cache-loader
/docs/noir_js/reference/
/docs/docs/noir_js/reference/

# Misc
.DS_Store
Expand All @@ -21,4 +21,4 @@ npm-debug.log*
yarn-debug.log*
yarn-error.log*

package-lock.json
package-lock.json
1 change: 1 addition & 0 deletions docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"@docusaurus/preset-classic": "^2.4.0",
"@easyops-cn/docusaurus-search-local": "^0.35.0",
"@mdx-js/react": "^1.6.22",
"@noir-lang/noir_js": "workspace:*",
"axios": "^1.4.0",
"clsx": "^1.2.1",
"docusaurus-plugin-typedoc": "1.0.0-next.18",
Expand Down
48 changes: 48 additions & 0 deletions docs/versioned_docs/version-v0.19.0/examples/merkle-proof.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
---
title: Merkle Proof Membership
description:
Learn how to use merkle membership proof in Noir to prove that a given leaf is a member of a
merkle tree with a specified root, at a given index.
keywords:
[merkle proof, merkle membership proof, Noir, rust, hash function, Pedersen, sha256, merkle tree]
---

Let's walk through an example of a merkle membership proof in Noir that proves that a given leaf is
in a merkle tree.

```rust
use dep::std;

fn main(message : [Field; 62], index : Field, hashpath : [Field; 40], root : Field) {
let leaf = std::hash::hash_to_field(message);
let merkle_root = std::merkle::compute_merkle_root(leaf, index, hashpath);
assert(merkle_root == root);
}

```

The message is hashed using `hash_to_field`. The specific hash function that is being used is chosen
by the backend. The only requirement is that this hash function can heuristically be used as a
random oracle. If only collision resistance is needed, then one can call `std::hash::pedersen_hash`
instead.

```rust
let leaf = std::hash::hash_to_field(message);
```

The leaf is then passed to a compute_merkle_root function with the root, index and hashpath. The returned root can then be asserted to be the same as the provided root.

```rust
let merkle_root = std::merkle::compute_merkle_root(leaf, index, hashpath);
assert (merkle_root == root);
```

> **Note:** It is possible to re-implement the merkle tree implementation without standard library.
> However, for most usecases, it is enough. In general, the standard library will always opt to be
> as conservative as possible, while striking a balance with efficiency.
An example, the merkle membership proof, only requires a hash function that has collision
resistance, hence a hash function like Pedersen is allowed, which in most cases is more efficient
than the even more conservative sha256.

[View an example on the starter repo](https://github.com/noir-lang/noir-examples/blob/3ea09545cabfa464124ec2f3ea8e60c608abe6df/stealthdrop/circuits/src/main.nr#L20)
Loading

0 comments on commit 1da56c3

Please sign in to comment.