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

feat: updated to use noir_bigcurve library #4

Merged
merged 10 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
58 changes: 25 additions & 33 deletions .github/workflows/noir.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: noir
name: Noir CI

on:
pull_request:
Expand All @@ -11,47 +11,39 @@ permissions:
contents: read

jobs:
fmt-noir:
noir:
runs-on: ubuntu-latest

steps:
- name: Checkout Repository
uses: actions/checkout@v4

- name: Install Nargo
uses: noir-lang/noirup@v0.1.3
- name: Cache Nargo Binary
uses: actions/cache@v4
id: nargo-cache
with:
toolchain: nightly
path: ~/.nargo/bin/nargo
key: ${{ runner.os }}-nargo-binary
restore-keys: |
${{ runner.os }}-nargo-binary

- name: Create `.nargo/bin` directory
shell: bash
run: |
mkdir -p $HOME/.nargo/bin
echo "${HOME}/.nargo/bin" >> $GITHUB_PATH

- name: Install Noir
if: steps.nargo-cache.outputs.cache-hit != 'true'
run: |
curl -L https://raw.githubusercontent.com/noir-lang/noirup/main/noirup | bash -s -- \
-C 51ae1b324cd73fdb4fe3695b5d483a44b4aff4a9

- name: Run nargo fmt
run: nargo fmt --check

check-noir:
runs-on: ubuntu-latest

steps:
- name: Checkout Repository
uses: actions/checkout@v4

- name: Install Nargo
uses: noir-lang/noirup@v0.1.3
with:
toolchain: nightly


- name: Run nargo check
run: nargo check --silence-warnings

test-noir:
runs-on: ubuntu-latest

steps:
- name: Checkout Repository
uses: actions/checkout@v4

- name: Install Nargo
uses: noir-lang/noirup@v0.1.3
with:
toolchain: nightly

run: nargo check --silence-warnings

- name: Run nargo test
run: nargo test --silence-warnings
run: nargo test --silence-warnings
78 changes: 48 additions & 30 deletions BENCHMARK.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,38 @@

> Computational statistics.

## Noir v0.35.0 Barrettenberg v0.56.0
## v1.0.0

_Machine_: `MacBook Pro M2 Max 32 GB RAM 1 TB Storage`

_Maximum RAM consumption_: `15 GB`

_Noir_: 0.35.0+51ae1b324cd73fdb4fe3695b5d483a44b4aff4a9

_Barrettenberg_: 0.56.0

---

| Version | Message Length | ACIR Opcodes | Brillig Opcodes | Compilation Time | Execution Time | Ultra Plonk Proof Time | Ultra Plonk VK Writing Time | Ultra Plonk Verification Time | Ultra Honk Proof Time | Ultra Honk VK Writing Time | Ultra Honk Verification Time |
|---------|----------------|--------------|-----------------|------------------|----------------|------------------------|-----------------------------|-------------------------------|-----------------------|----------------------------|------------------------------|
| v1 | 32 | 217,057 | 468,974 | 50.460 seconds | 30.207 seconds | 10.076 seconds | 9.385 seconds | 0.030 seconds | 4.786 seconds | 3.621 seconds | 0.037 seconds |
| v2 | 32 | 215,215 | 468,628 | 42.989 seconds | 30.330 seconds | 9.673 seconds | 9.024 seconds | 0.029 seconds | 4.734 seconds | 3.620 seconds | 0.035 seconds |
| v1 | 100 | 217,447 | 469,042 | 54.699 seconds | 30.496 seconds | 9.968 seconds | 9.598 seconds | 0.031 seconds | 4.791 seconds | 3.769 seconds | 0.038 seconds |
| v2 | 100 | 215,605 | 468,696 | 45.778 seconds | 30.393 seconds | 10.110 seconds | 9.519 seconds | 0.029 seconds | 4.795 seconds | 3.723 seconds | 0.038 seconds |
| v1 | 10,000 | 274,871 | 478,942 | 73.138 seconds | 38.606 seconds | 35.419 seconds | 33.338 seconds | 0.033 seconds | 13.728 seconds | 11.027 seconds | 0.039 seconds |
| v2 | 10,000 | 273,029 | 478,596 | 65.427 seconds | 39.092 seconds | 35.247 seconds | 33.148 seconds | 0.029 seconds | 14.097 seconds | 11.159 seconds | 0.036 seconds |

## v0.1.2

_Machine_: `20 Cores, 300 GB RAM`

_Maximum RAM consumption_: `200 GB`

## Table
_Noir_: 0.35.0+51ae1b324cd73fdb4fe3695b5d483a44b4aff4a9

_Barrettenberg_: 0.56.0

---

| Version | Message Length | Constraints | Execution Time | Proving Ultra Plonk Time | Writing VK Ultra Plonk Time | Verifying Ultra Plonk Time | Proving Ultra Honk Time | Writing Vk Ultra Honk Time | Verifying Ultra Honk Time |
|---------|----------------|-------------|--------------------|--------------------|--------------------|----------------|-------------------------|----------------------------|---------------------------|
Expand All @@ -19,40 +44,33 @@ _Maximum RAM consumption_: `200 GB`
| v1 | 10000 | 754,652 | 56 minutes 22 seconds | 2 minutes 27 seconds | 2 minutes 19 seconds | 0.12 seconds | 1 minute 16 seconds | 1 minute 2 seconds | 0.08 seconds |
| v2 | 10000 | 753,998 | 56 minutes 16 seconds | 2 minutes 25 seconds | 2 minutes 20 seconds | 0.07 seconds | 1 minute 12 seconds | 1 minute 3 seconds | 0.08 seconds |

## Noir v0.33.0 Barrettenberg v0.47.1
## v0.1.0

_Machine_: `20 Cores, 144 GB RAM`

_Maximum RAM consumption_: `43 GB`
_Maximum RAM consumption_: `123 GB`

## Table (Ultra Honk)
Ultra Plonk:

| Version | Message Length | Constraints | Execution Time | Proving Time | Writing VK Time | Verifying Time |
|---------|----------------|-------------|--------------------|--------------------|--------------------|----------------|
| v1 | 5 | 2,998,712 | 13 minute 56 seconds | 13 minutes 23 seconds | 12 minutes 3 seconds | 0.06 seconds |
| v2 | 5 | 2,998,520 | 13 minutes 52 seconds | 13 minutes 9 seconds | 12 minutes 14 seconds | 0.06 seconds |
| v1 | 32 | 2,998,905 | 14 minutes 14 seconds | 13 minutes 3 seconds | 11 minutes 44 seconds | 0.06 seconds |
| v2 | 32 | 2,998,636 | 14 minutes 5 seconds | 12 minutes 55 seconds | 11 minutes 48 seconds | 0.06 seconds |
| v1 | 100 | 2,999,162 | 14 minutes 44 seconds | 13 minutes 4 seconds | 12 minutes 30 seconds | 0.06 seconds |
| v2 | 100 | 2,998,893 | 13 minutes 58 seconds | 12 minutes 57 seconds | 12 minutes 2 seconds | 0.06 seconds |
| v1 | 10000 | 3,036,441 | 17 minutes 47 seconds | 13 minutes 35 seconds | 12 minutes 13 seconds | 0.06 seconds |
| v2 | 10000 | 3,036,172 | 1 minutes 16 seconds | 13 minutes 59 seconds | 12 minutes 25 seconds | 0.06 seconds |
1. _Noir_: 0.32.0

## Noir v0.32.0 Barrettenberg v0.46.1
2. _Barrettenberg_: 0.46.1

_Machine_: `20 Cores, 144 GB RAM`
Ultra Honk:

_Maximum RAM consumption_: `123 GB`
1. _Noir_: 0.33.0

2. _Barrettenberg_: 0.47.1

---

## Table (Ultra Plonk)

| Version | Message Length | Constraints | Execution Time | Proving Time | Writing VK Time | Verifying Time |
|---------|----------------|-------------|--------------------|--------------------|--------------------|----------------|
| v1 | 5 | 2,998,712 | 15 minute 59 seconds | 53 minutes 15 seconds | 37 minutes 19 seconds | 0.1 seconds |
| v2 | 5 | 2,998,520 | 18 minutes 32 seconds | 58 minutes 42 seconds | 36 minutes 25 seconds | 0.1 seconds |
| v1 | 32 | 2,998,905 | 17 minutes 34 seconds | 53 minutes 38 seconds | 36 minutes 43 seconds | 0.11 seconds |
| v2 | 32 | 2,998,636 | 17 minutes 9 seconds | 50 minutes 17 seconds | 38 minutes 59 seconds | 0.14 seconds |
| v1 | 100 | 2,999,162 | 16 minutes 49 seconds | 24 minutes 9 seconds | 22 minutes 58 seconds | 0.06 seconds |
| v2 | 100 | 2,998,893 | 16 minutes 28 seconds | 30 minutes 11 seconds | 25 minutes 14 seconds | 0.07 seconds |
| v1 | 10000 | 3,036,441 | 23 minutes 55 seconds | 38 minutes 18 seconds | 32 minutes 19 seconds | 0.08 seconds |
| v2 | 10000 | 3,036,172 | 20 minutes 35 seconds | 28 minutes 46 seconds | 30 minutes 40 seconds | 0.07 seconds |
| Version | Message Length | Constraints | Execution Time | Proving Ultra Plonk Time | Writing VK Ultra Plonk Time | Verifying Ultra Plonk Time | Proving Ultra Honk Time | Writing VK Ultra Honk Time | Verifying Ultra Honk Time |
|---------|----------------|-------------|----------------------|--------------------------|-----------------------------|----------------------------|-------------------------|----------------------------|---------------------------|
| v1 | 5 | 2,998,712 | 15 minutes 59 seconds | 53 minutes 15 seconds | 37 minutes 19 seconds | 0.1 seconds | 13 minutes 23 seconds | 12 minutes 3 seconds | 0.06 seconds |
| v2 | 5 | 2,998,520 | 18 minutes 32 seconds | 58 minutes 42 seconds | 36 minutes 25 seconds | 0.1 seconds | 13 minutes 9 seconds | 12 minutes 14 seconds | 0.06 seconds |
| v1 | 32 | 2,998,905 | 17 minutes 34 seconds | 53 minutes 38 seconds | 36 minutes 43 seconds | 0.11 seconds | 13 minutes 3 seconds | 11 minutes 44 seconds | 0.06 seconds |
| v2 | 32 | 2,998,636 | 17 minutes 9 seconds | 50 minutes 17 seconds | 38 minutes 59 seconds | 0.14 seconds | 12 minutes 55 seconds | 11 minutes 48 seconds | 0.06 seconds |
| v1 | 100 | 2,999,162 | 16 minutes 49 seconds | 24 minutes 9 seconds | 22 minutes 58 seconds | 0.06 seconds | 13 minutes 4 seconds | 12 minutes 30 seconds | 0.06 seconds |
| v2 | 100 | 2,998,893 | 16 minutes 28 seconds | 30 minutes 11 seconds | 25 minutes 14 seconds | 0.07 seconds | 12 minutes 57 seconds | 12 minutes 2 seconds | 0.06 seconds |
| v1 | 10,000 | 3,036,441 | 23 minutes 55 seconds | 38 minutes 18 seconds | 32 minutes 19 seconds | 0.08 seconds | 13 minutes 35 seconds | 12 minutes 13 seconds | 0.06 seconds |
| v2 | 10,000 | 3,036,172 | 17 minutes 47 seconds | 28 minutes 46 seconds | 30 minutes 40 seconds | 0.07 seconds | 13 minutes 59 seconds | 12 minutes 25 seconds | 0.06 seconds |
33 changes: 0 additions & 33 deletions Makefile

This file was deleted.

2 changes: 1 addition & 1 deletion Nargo.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[workspace]
members = ["crates/plume", "crates/use"]
members = ["crates/plume", "crates/use_v1", "crates/use_v2"]
62 changes: 10 additions & 52 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# Plume in Noir
# PLUME in Noir

[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT) [![Noir CI 🌌](https://github.com/distributed-lab/noir-plume/actions/workflows/noir.yml/badge.svg)](https://github.com/distributed-lab/noir-plume/actions/workflows/noir.yml)

Plume is needed to confirm your identity without disclosing your private data, i.e. [zero-knowledge proof](https://en.wikipedia.org/wiki/Zero-knowledge_proof). Plume has another feature: you can send a message from a private group using special group message. For more details visit <https://blog.aayushg.com/nullifier/>.

## How to use?
## Eager to try? 😎

### Add dependency to your project's `Nargo.toml`

```toml
[dependencies]
plume = { git = "https://github.com/distributed-lab/noir-plume", tag = "v0.1.2", directory = "crates/plume"}
plume = { git = "https://github.com/distributed-lab/noir-plume", tag = "v1.0.0", directory = "crates/plume"}
```

### Use in your `Noir` code as following
Expand All @@ -33,60 +33,18 @@ use plume::plume_v2;
plume_v2(msg, c, s, pk, nullifier);
```

### Example
### Examples

See the example in `crates/use`. For proving data generation, check out our `SageMath` [implementation](./etc).
Check out how to generate proofs with PLUME in either `crates/use_v1` or `crates/use_v2`.
For proving data generation, see our `SageMath` [implementation](./etc).

## Benchmark
## Benchmark 📊

We have provided information regarding different computational statistics such as constraints amount and time for various activities, see [Benchmark.md](./BENCHMARK.md)

## Miscellaneous
## There is more? 🤯

### Message Lenght Restriction

Due to `Noir` specifics and generics limitations, message length is hardcoded to be constant value `32`.
In case you need to change it, see [constants.nr](./crates/plume/src/constants.nr).

### Cryptography

In order to bring in `PLUME` to `Noir`, we needed to implement `secp256k1_XMD:SHA-256_SSWU_RO_` hash-to-curve algorithm.
In order to bring in `PLUME` to `Noir`, we needed to implement `secp256k1_XMD:SHA-256_SSWU_RO_` hash-to-curve algorithm, ergo now it is available in `Noir` ecosystem!

Based on [this description](https://datatracker.ietf.org/doc/id/draft-irtf-cfrg-hash-to-curve-06.html).
Testes using [this data](https://www.ietf.org/archive/id/draft-irtf-cfrg-hash-to-curve-13.html#appendix-J.8.1).

#### The algorithm

```bash
hash_to_curve(msg)

Input: msg, an arbitrary-length byte string.
Output: P, a point in the secp256k1 curve.

Steps:
1. u = hash_to_field(msg)
2. Q0 = map_to_curve(u[0])
3. Q1 = map_to_curve(u[1])
4. P = iso_map(Q0) + iso_map(Q1)
5. return P
```

##### hash_to_field

Implemented in [hash_to_field.nr](crates/plume/src/hash_to_field.nr).
Follows the algorithm described [here](https://www.ietf.org/archive/id/draft-irtf-cfrg-hash-to-curve-13.html#hashtofield).

##### map_to_curve

Implemented in [map_to_curve.nr](crates/plume/src/map_to_curve.nr).
Follows the algorithm described [here](https://www.ietf.org/archive/id/draft-irtf-cfrg-hash-to-curve-13.html#simple-swu).

##### iso_map

Implemented in [iso_map.nr](crates/plume/src/iso_map.nr).
Follows the algorithm described [here](https://www.ietf.org/archive/id/draft-irtf-cfrg-hash-to-curve-13.html#appx-iso-secp256k1).

##### Elliptic Curve operations

Implemented in [ec_ops.nr](crates/plume/src/ec_ops.nr).
Follows the algorithm described [here](https://www.rareskills.io/post/elliptic-curve-addition).
Tested using [this data](https://www.ietf.org/archive/id/draft-irtf-cfrg-hash-to-curve-13.html#appendix-J.8.1).
Loading