Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
/target
*.sage.py

# Noir and prover artifacts
*.json
*.gz

# Generated by Cargo
# will have compiled files and executables
debug/
Expand Down
14 changes: 7 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ bytemuck = "1.19.0"
hex-literal = "0.4.1"


# Noir lang: make sure it matches installed version `noirup -C 801c7188`
acir = { git = "https://github.com/noir-lang/noir", rev = "801c7188" }
acvm = { git = "https://github.com/noir-lang/noir", rev = "801c7188" }
acir_field = { git = "https://github.com/noir-lang/noir", rev = "801c7188" }
noirc_abi = { git = "https://github.com/noir-lang/noir", rev = "801c7188" }
noirc_artifacts = { git = "https://github.com/noir-lang/noir", rev = "801c7188" }
noirc_printable_type = { git = "https://github.com/noir-lang/noir", rev = "801c7188" }
# Noir lang: make sure it matches installed version `noirup -C 03b58fa2`
acir = { git = "https://github.com/noir-lang/noir", rev = "03b58fa2" }
acvm = { git = "https://github.com/noir-lang/noir", rev = "03b58fa2" }
acir_field = { git = "https://github.com/noir-lang/noir", rev = "03b58fa2" }
noirc_abi = { git = "https://github.com/noir-lang/noir", rev = "03b58fa2" }
noirc_artifacts = { git = "https://github.com/noir-lang/noir", rev = "03b58fa2" }
noirc_printable_type = { git = "https://github.com/noir-lang/noir", rev = "03b58fa2" }

[patch.crates-io]
ruint = { git = "https://github.com/recmo/uint", branch = "main" }
38 changes: 38 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,44 @@

Zero-knowledge proof toolkit targeting mobile devices.

## Demo instructions

First make sure you have the exact correct version of Noir installed [so the artifacts can be read](./Cargo.toml#L58):

```sh
noirup -C 03b58fa2
```

Compile the Noir circuit and generate the witness:

```sh
cd noir-r1cs/noir-examples/poseidon-rounds
nargo execute
```

Generate the R1CS instance:

```sh
cargo run --release --bin noir-r1cs ./noir-r1cs/noir-examples/poseidon-rounds/target/basic.json ./noir-r1cs/noir-examples/poseidon-rounds/target/basic.gz
```

Generate the WHIR GR1CS proof:

```sh
cargo run --release --bin prover -- --input_file_path ./noir-r1cs/r1cs.json
```

This will write the proof to `prover/proof`.

Recursively verify in a Gnark proof (reads the proof from `../ProveKit/prover/proof`):

```sh
cd ..
git clone https://github.com/reilabs/gnark-whir
cd gnark-whir
go run .
```

## Components


Expand Down
8 changes: 8 additions & 0 deletions noir-r1cs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ anyhow.workspace = true
tracing.workspace = true
tracing-subscriber.workspace = true
base64.workspace = true
clap = { version = "4.4", features = ["derive"] }

# Noir lang
acir.workspace = true
Expand All @@ -23,3 +24,10 @@ noirc_artifacts.workspace = true
noirc_abi.workspace = true
noirc_printable_type.workspace = true
rand.workspace = true

flate2 = "1.0"
bincode = "1.3"

[[bin]]
name = "circuit_stats"
path = "src/bin/circuit_stats.rs"
8 changes: 8 additions & 0 deletions noir-r1cs/noir-examples/basic-2/Nargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[package]
name = "basic"
type = "bin"
authors = [""]
compiler_version = ">=0.22.0"

[dependencies]
poseidon2 = { tag = "main", git = "https://github.com/TaceoLabs/noir-poseidon", directory = "poseidon2"}
7 changes: 7 additions & 0 deletions noir-r1cs/noir-examples/basic-2/Prover.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
plains = [1,2]
a = 1
b = 2
c = 3
d = 5
x = 0
result = '0x0e90c132311e864e0c8bca37976f28579a2dd9436bbc11326e21ec7c00cea5b2'
8 changes: 8 additions & 0 deletions noir-r1cs/noir-examples/basic-2/prove.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
nargo compile
nargo check
nargo execute my-witness
bb prove -b ./target/basic.json -w ./target/my-witness.gz -o ./target/proof
echo "✅ Proof generated at ./target/proof"
bb write_vk -b ./target/basic.json -o ./target/vk
bb verify -k ./target/vk -p ./target/proof
echo "✅ Verified the proof at ./target/proof"
3 changes: 3 additions & 0 deletions noir-r1cs/noir-examples/basic-2/src/main.nr
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main(a: Field, b: Field, c: Field, d: Field) {
assert(a * b + c + d == 10);
}
8 changes: 8 additions & 0 deletions noir-r1cs/noir-examples/basic-3/Nargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[package]
name = "basic"
type = "bin"
authors = [""]
compiler_version = ">=0.22.0"

[dependencies]
poseidon2 = { tag = "main", git = "https://github.com/TaceoLabs/noir-poseidon", directory = "poseidon2"}
4 changes: 4 additions & 0 deletions noir-r1cs/noir-examples/basic-3/Prover.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
i = 1
j = 7
k = 3
l = 1
8 changes: 8 additions & 0 deletions noir-r1cs/noir-examples/basic-3/prove.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
nargo compile
nargo check
nargo execute my-witness
bb prove -b ./target/basic.json -w ./target/my-witness.gz -o ./target/proof
echo "✅ Proof generated at ./target/proof"
bb write_vk -b ./target/basic.json -o ./target/vk
bb verify -k ./target/vk -p ./target/proof
echo "✅ Verified the proof at ./target/proof"
41 changes: 41 additions & 0 deletions noir-r1cs/noir-examples/basic-3/src/main.nr
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
fn main(i: Field, j: Field, k: Field, l: Field) {
assert(3 * i * j * l + 2 * (k + 1) * (l + 5) + 1 == (l + 13) * 5);
// assert((i + j) * k * l + (j - i) * (k + l) == 48);
// assert(j * j - i * k * l + (l + k) * (i + j) == 78);
// assert((i * j + k) * (l + 2) - j == 23);
// // Complex nested operations with multiple terms
// assert((i * j * j + k * k) * (l + i) + (j - k) * (j + k) == 156);

// // Using squares and products with multiple groupings
// assert((j * j * j - k * k * i) * l + (i + l) * (j + k) == 354);

// // Multiple groups with mixed operations
// assert((i + j) * (j - k) * (k + l) + (j * j - i) * (k - l) == 224);

// // Nested multiplications with additions and subtractions
// assert((((i + j) * k - l) * (j - k) + i) * (l + k) == 372);

// // Very complex grouping with multiple terms
// assert((i * j + k * l) * (j * j - k) + (l + i) * (j - k) * (k + i) == 492);

// // Using differences of squares pattern with extra terms
// assert((j + k) * (j - k) + (i * l) * (j * j - k * k) + l == 81);

// // Complex polynomial with nested terms
// assert((j * j * j - k * k * i) * (l + i) + (j * k - i) * (j * j - k * l) == 1588);

// // Nested products with multiple groupings and differences
// assert((j * j + k * i) * (j - k) * (l + k) - (i + l) * (k * k * j) == 706);

// // Complex cubic terms with mixed operations
// assert((j + k) * (j * j - k * k) * (l + i) + (j - i) * k * (k + l) == 872);

// // Multiple nested groups with squares and products
// assert((j * j - i) * (k * k + l) * (j - k) + (i + l) * (j * k - l) == 1960);

// // Complex differences with cubic terms
// assert((j * j * j - k * k * k) * (l + i) - (j - k) * (j + k) * (j * l) == 352);

// // Nested operations with multiple factors
// assert((j * k + i * l) * (j * j - k * l) * (k + i) - (j - l) * k * k == 3994);
}
5 changes: 3 additions & 2 deletions noir-r1cs/noir-examples/basic/Prover.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
plains = [1,2,3,4,5,6,7,8]
plains = [1,2]
a = 1
b = 2
c = 3
d = 5
x = 0
x = 0
result = '0x0e90c132311e864e0c8bca37976f28579a2dd9436bbc11326e21ec7c00cea5b2'
6 changes: 4 additions & 2 deletions noir-r1cs/noir-examples/basic/src/main.nr
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use dep::poseidon2;

fn main(plains: [Field; 2]) -> pub Field {
poseidon2::bn254::hash_2(plains)
fn main(plains: [Field; 2], result: Field) {
let hash = poseidon2::bn254::hash_2(plains);
print(hash);
assert(hash == result);
}
8 changes: 8 additions & 0 deletions noir-r1cs/noir-examples/poseidon-rounds/Nargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[package]
name = "basic"
type = "bin"
authors = [""]
compiler_version = ">=0.22.0"

[dependencies]
poseidon2 = { tag = "main", git = "https://github.com/TaceoLabs/noir-poseidon", directory = "poseidon2"}
7 changes: 7 additions & 0 deletions noir-r1cs/noir-examples/poseidon-rounds/Prover.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
plains = [1,2]
a = 1
b = 2
c = 3
d = 5
x = 0
result = '0x0b5b6e4be36ffe606c2f640d972634fcf030bd0346eadcec12d0e3b95bf7f523'
8 changes: 8 additions & 0 deletions noir-r1cs/noir-examples/poseidon-rounds/prove.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
nargo compile
nargo check
nargo execute my-witness
bb prove -b ./target/basic.json -w ./target/my-witness.gz -o ./target/proof
echo "✅ Proof generated at ./target/proof"
bb write_vk -b ./target/basic.json -o ./target/vk
bb verify -k ./target/vk -p ./target/proof
echo "✅ Verified the proof at ./target/proof"
11 changes: 11 additions & 0 deletions noir-r1cs/noir-examples/poseidon-rounds/src/main.nr
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
use dep::poseidon2;

fn main(plains: [Field; 2], result: Field) {
let mut hash = poseidon2::bn254::hash_2(plains);
let rounds = 1000;
for _ in 0..rounds {
hash = poseidon2::bn254::hash_1([hash]);
}
println(hash);
assert(hash == result);
}
8 changes: 8 additions & 0 deletions noir-r1cs/noir-examples/poseidon-var/Nargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[package]
name = "basic"
type = "bin"
authors = [""]
compiler_version = ">=0.22.0"

[dependencies]
poseidon2 = { tag = "main", git = "https://github.com/TaceoLabs/noir-poseidon", directory = "poseidon2"}
2 changes: 2 additions & 0 deletions noir-r1cs/noir-examples/poseidon-var/Prover.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
plains = [1]
result = "0x019aacea87290b7f5d4c9533494a19308f8e2590a6fb18aa64b3f965af924eb3"
8 changes: 8 additions & 0 deletions noir-r1cs/noir-examples/poseidon-var/prove.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
nargo compile
nargo check
nargo execute my-witness
bb prove -b ./target/basic.json -w ./target/my-witness.gz -o ./target/proof
echo "✅ Proof generated at ./target/proof"
bb write_vk -b ./target/basic.json -o ./target/vk
bb verify -k ./target/vk -p ./target/proof
echo "✅ Verified the proof at ./target/proof"
44 changes: 44 additions & 0 deletions noir-r1cs/noir-examples/poseidon-var/src/main.nr
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
use dep::poseidon2;

fn hash_variable_input(input: [Field]) -> Field {
let input_size = input.len();
// Number of permutation events needed (ceiling of input_size/3)
let num_perm_events = (input_size + 2) / 3;

// Initial state with IV (input length) in last position
// Note: << 64 in Noir would be done differently, using field arithmetic
let iv = input_size as Field; // Simplified IV for example
let mut perm_state = [0, 0, 0, iv];

// Process input in chunks of 3
let mut processed = 0;
for _i in 0..num_perm_events {
// Determine chunk size (3 or remaining elements)
let chunk_size = if input_size - processed >= 3 {
3
} else {
input_size - processed
};

// Absorb input chunk into state
for j in 0..chunk_size {
perm_state[j] = perm_state[j] + input[processed + j];
}

println(perm_state);
// Apply permutation (using x5_4 as it handles 4-element state)
// perm_state = poseidon2::bn254::perm::x5_4(perm_state);
println(perm_state);

processed += chunk_size;
}

// Return first element as hash result
perm_state[0]
}

fn main(plains: [Field; 1], result: Field) {
let hash = hash_variable_input(plains);
println(hash);
assert(hash == 1);
}
1 change: 1 addition & 0 deletions noir-r1cs/noir-passport-examples/compare_age.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions noir-r1cs/noir-passport-examples/compare_birthdate.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions noir-r1cs/noir-passport-examples/compare_citizenship.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions noir-r1cs/noir-passport-examples/compare_expiry.json

Large diffs are not rendered by default.

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions noir-r1cs/noir-passport-examples/data_check_expiry.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions noir-r1cs/noir-passport-examples/data_check_integrity.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions noir-r1cs/noir-passport-examples/disclose_bytes.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions noir-r1cs/noir-passport-examples/disclose_flags.json

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions noir-r1cs/noir-passport-examples/outer.json

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Loading