@stellar-registry/perch-artifacts 0.0.0-stage → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/README.md +87 -2
- package/circuits/Nargo.toml +3 -0
- package/circuits/artifacts/perch_zk_recovery.json +104 -0
- package/circuits/artifacts/perch_zk_recovery_d24.json +104 -0
- package/circuits/manifest.json +101 -0
- package/circuits/perch_zk/Nargo.toml +9 -0
- package/circuits/perch_zk/src/lib.nr +126 -0
- package/circuits/perch_zk/src/tests.nr +145 -0
- package/circuits/perch_zk_recovery/Nargo.toml +7 -0
- package/circuits/perch_zk_recovery/src/main.nr +34 -0
- package/circuits/perch_zk_recovery_d24/Nargo.toml +7 -0
- package/circuits/perch_zk_recovery_d24/src/main.nr +38 -0
- package/circuits/vendor/poseidon/CHECKSUMS.sha256 +13 -0
- package/circuits/vendor/poseidon/LICENSE +201 -0
- package/circuits/vendor/poseidon/NOTICE +25 -0
- package/circuits/vendor/poseidon/Nargo.toml +7 -0
- package/circuits/vendor/poseidon/README.md +28 -0
- package/circuits/vendor/poseidon/src/bench.nr +6 -0
- package/circuits/vendor/poseidon/src/lib.nr +8 -0
- package/circuits/vendor/poseidon/src/oracle_tests.nr +20 -0
- package/circuits/vendor/poseidon/src/poseidon/bn254/consts.nr +24965 -0
- package/circuits/vendor/poseidon/src/poseidon/bn254/perm.nr +115 -0
- package/circuits/vendor/poseidon/src/poseidon/bn254.nr +173 -0
- package/circuits/vendor/poseidon/src/poseidon/mod.nr +359 -0
- package/circuits/vendor/poseidon/src/poseidon2.nr +98 -0
- package/circuits/vendor/poseidon/src/tests.nr +34 -0
- package/constants.json +14 -0
- package/deployments/pending-registry.json +1 -0
- package/deployments/testnet-exercise.json +2469 -0
- package/deployments/testnet.json +129 -0
- package/dist/cli/derive-id.d.ts +2 -0
- package/dist/cli/derive-id.js +17 -0
- package/dist/cli/fetch-infra-wasm.d.ts +2 -0
- package/dist/cli/fetch-infra-wasm.js +5 -0
- package/dist/cli/zk-toolchain.d.ts +2 -0
- package/dist/cli/zk-toolchain.js +5 -0
- package/dist/derive.d.ts +6 -0
- package/dist/derive.js +79 -0
- package/dist/index.d.ts +105 -0
- package/dist/index.js +31 -0
- package/dist/script.d.ts +1 -0
- package/dist/script.js +12 -0
- package/package.json +54 -4
- package/scripts/fetch-infra-wasm.sh +150 -0
- package/scripts/zk-toolchain.sh +91 -0
- package/vectors/auth-vectors.json +143 -0
- package/vectors/diagnostic-events.json +37 -0
- package/vectors/eval-vectors.json +2244 -0
- package/vectors/rule-hashes.json +60 -0
- package/vectors/statement-v2.json +230 -0
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
//! Shared constraints for Perch's ZK recovery membership proof.
|
|
2
|
+
//!
|
|
3
|
+
//! One relation, parameterized only by tree depth. With `acct` the account's
|
|
4
|
+
//! contract id, `enr` the enrollment id its recovery configuration names, and
|
|
5
|
+
//! `digest` the 32-byte recovery-statement digest (each split into two
|
|
6
|
+
//! big-endian 128-bit halves):
|
|
7
|
+
//!
|
|
8
|
+
//! inner = H(DOM_LEAF, secret) client-side commitment
|
|
9
|
+
//! leaf = H(DOM_BIND, acct_hi, acct_lo, enr_hi, enr_lo, inner) computed by the pool
|
|
10
|
+
//! root = MerkleRoot(leaf, leaf_index, siblings) H2 interior nodes, empty leaf 0
|
|
11
|
+
//! nullifier = H(DOM_NULLIFIER, acct_hi, acct_lo, enr_hi, enr_lo, secret)
|
|
12
|
+
//! statement_hash = H(DOM_AUTH, acct_hi, acct_lo, enr_hi, enr_lo, digest_hi, digest_lo)
|
|
13
|
+
//!
|
|
14
|
+
//! Public inputs, in order: `root`, `nullifier`, `statement_hash`. Everything
|
|
15
|
+
//! else is private. `H` is `Poseidon2::hash(inputs, inputs.len())` from
|
|
16
|
+
//! noir-lang/poseidon v0.2.0 (vendored, `../vendor/poseidon`), which
|
|
17
|
+
//! `soroban-poseidon`'s `Poseidon2Sponge::<4, Bn254Fr>` reproduces on the
|
|
18
|
+
//! Soroban host; `crates/perch-zk-primitives` pins both sides to shared
|
|
19
|
+
//! vectors.
|
|
20
|
+
//!
|
|
21
|
+
//! These are the formulas of `perch-recovery-interface::zk` (the spec's "ZK
|
|
22
|
+
//! adapter boundary"). The circuit knows nothing about the statement's
|
|
23
|
+
//! layout: the controller hashes its structured statement to 32 bytes, so a
|
|
24
|
+
//! statement-format change never needs a new circuit or verification key.
|
|
25
|
+
//! What the circuit binds directly is the account and the enrollment id,
|
|
26
|
+
//! because the leaf and nullifier are computed from them.
|
|
27
|
+
//!
|
|
28
|
+
//! Domain constants are `sha256("perch/recovery/zk/v2/<name>") mod r`.
|
|
29
|
+
|
|
30
|
+
use poseidon::poseidon2::Poseidon2;
|
|
31
|
+
|
|
32
|
+
pub global DOM_LEAF: Field = 0x1981de3e07709613862272edb5ff4fab545737382d1405fe8d0970dc7d4d7ed6;
|
|
33
|
+
pub global DOM_BIND: Field = 0x20ae6172af8bed19c921e91e21641198661035616a6a4d733346853501fd07c5;
|
|
34
|
+
pub global DOM_NULLIFIER: Field =
|
|
35
|
+
0x0280c3170f4abb8389838a5c280dbdac8bfd7c75fcb780a9485d93af553ab840;
|
|
36
|
+
pub global DOM_AUTH: Field = 0x04e4c99c7477379c7e47c9380170e3fb1e7c565afe67dd56216df99861f1fb3c;
|
|
37
|
+
|
|
38
|
+
pub fn hash2(a: Field, b: Field) -> Field {
|
|
39
|
+
Poseidon2::hash([a, b], 2)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
pub fn commitment(secret: Field) -> Field {
|
|
43
|
+
Poseidon2::hash([DOM_LEAF, secret], 2)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
pub fn leaf(acct_hi: Field, acct_lo: Field, enr_hi: Field, enr_lo: Field, inner: Field) -> Field {
|
|
47
|
+
Poseidon2::hash([DOM_BIND, acct_hi, acct_lo, enr_hi, enr_lo, inner], 6)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
pub fn nullifier(
|
|
51
|
+
acct_hi: Field,
|
|
52
|
+
acct_lo: Field,
|
|
53
|
+
enr_hi: Field,
|
|
54
|
+
enr_lo: Field,
|
|
55
|
+
secret: Field,
|
|
56
|
+
) -> Field {
|
|
57
|
+
Poseidon2::hash([DOM_NULLIFIER, acct_hi, acct_lo, enr_hi, enr_lo, secret], 6)
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
pub fn statement_hash(
|
|
61
|
+
acct_hi: Field,
|
|
62
|
+
acct_lo: Field,
|
|
63
|
+
enr_hi: Field,
|
|
64
|
+
enr_lo: Field,
|
|
65
|
+
digest_hi: Field,
|
|
66
|
+
digest_lo: Field,
|
|
67
|
+
) -> Field {
|
|
68
|
+
Poseidon2::hash(
|
|
69
|
+
[DOM_AUTH, acct_hi, acct_lo, enr_hi, enr_lo, digest_hi, digest_lo],
|
|
70
|
+
7,
|
|
71
|
+
)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/// Root of a depth-`D` tree containing `leaf` at `leaf_index`. The index is
|
|
75
|
+
/// decomposed into exactly `D` little-endian bits, which also range-checks it
|
|
76
|
+
/// to `[0, 2^D)`: a bit of 0 means the running node is the left child.
|
|
77
|
+
pub fn merkle_root<let D: u32>(leaf: Field, leaf_index: Field, siblings: [Field; D]) -> Field {
|
|
78
|
+
let bits: [u1; D] = leaf_index.to_le_bits();
|
|
79
|
+
let mut cur = leaf;
|
|
80
|
+
for i in 0..D {
|
|
81
|
+
cur = if bits[i] == 0 {
|
|
82
|
+
hash2(cur, siblings[i])
|
|
83
|
+
} else {
|
|
84
|
+
hash2(siblings[i], cur)
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
cur
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/// The whole relation. Each `bin` package's `main` is this function at a
|
|
91
|
+
/// fixed depth.
|
|
92
|
+
pub fn check<let D: u32>(
|
|
93
|
+
root: Field,
|
|
94
|
+
nullifier_pub: Field,
|
|
95
|
+
statement_hash_pub: Field,
|
|
96
|
+
secret: Field,
|
|
97
|
+
acct_hi: Field,
|
|
98
|
+
acct_lo: Field,
|
|
99
|
+
enr_hi: Field,
|
|
100
|
+
enr_lo: Field,
|
|
101
|
+
digest_hi: Field,
|
|
102
|
+
digest_lo: Field,
|
|
103
|
+
leaf_index: Field,
|
|
104
|
+
siblings: [Field; D],
|
|
105
|
+
) {
|
|
106
|
+
let stored = leaf(acct_hi, acct_lo, enr_hi, enr_lo, commitment(secret));
|
|
107
|
+
assert(merkle_root(stored, leaf_index, siblings) == root);
|
|
108
|
+
assert(nullifier(acct_hi, acct_lo, enr_hi, enr_lo, secret) == nullifier_pub);
|
|
109
|
+
assert(
|
|
110
|
+
statement_hash(acct_hi, acct_lo, enr_hi, enr_lo, digest_hi, digest_lo)
|
|
111
|
+
== statement_hash_pub,
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/// `zero[0] = 0` (the empty leaf), `zero[i + 1] = H2(zero[i], zero[i])`.
|
|
116
|
+
pub fn zero_hashes<let D: u32>() -> [Field; D] {
|
|
117
|
+
let mut zeros: [Field; D] = [0; D];
|
|
118
|
+
let mut prev: Field = 0;
|
|
119
|
+
for i in 0..D {
|
|
120
|
+
zeros[i] = prev;
|
|
121
|
+
prev = hash2(prev, prev);
|
|
122
|
+
}
|
|
123
|
+
zeros
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
mod tests;
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
use crate::{check, commitment, hash2, leaf, merkle_root, nullifier, statement_hash, zero_hashes};
|
|
2
|
+
use poseidon::poseidon2::Poseidon2;
|
|
3
|
+
|
|
4
|
+
// Host-parity vectors: `crates/perch-zk-primitives/src/test.rs::parity`
|
|
5
|
+
// computes the same inputs with `soroban-poseidon` on the Soroban host and
|
|
6
|
+
// asserts the same outputs. If either side drifts (a Poseidon2 library bump, a
|
|
7
|
+
// changed arity, a reordered input), one of the two suites fails.
|
|
8
|
+
#[test]
|
|
9
|
+
fn parity_vectors() {
|
|
10
|
+
assert(hash2(1, 2) == 0x038682aa1cb5ae4e0a3f13da432a95c77c5c111f6f030faf9cad641ce1ed7383);
|
|
11
|
+
assert(commitment(3) == 0x301d7a7973f3ec9c92ebc8afa9855b49aef4ba8c7c67fb64fae99fac8992dfa0);
|
|
12
|
+
assert(
|
|
13
|
+
leaf(4, 5, 6, 7, 8) == 0x241225f632b43077765a98b79d36e32782272c95b46b8a2c9275bfd0ac551d1c,
|
|
14
|
+
);
|
|
15
|
+
assert(
|
|
16
|
+
nullifier(9, 10, 11, 12, 13)
|
|
17
|
+
== 0x1ffa05820357fd280b04acdf157da0a4481feefec252476b44fc702b77902b8c,
|
|
18
|
+
);
|
|
19
|
+
assert(
|
|
20
|
+
statement_hash(14, 15, 16, 17, 18, 19)
|
|
21
|
+
== 0x17d4bf97cdbb6037d073d98b2e87f37039e7db0927c2be8b2f46c668b15f3cf7,
|
|
22
|
+
);
|
|
23
|
+
let zeros: [Field; 33] = zero_hashes();
|
|
24
|
+
assert(zeros[32] == 0x0b59baa35b9dc267744f0ccb4e3b0255c1fc512460d91130c6bc19fb2668568d);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
global SECRET: Field = 0x2a2a;
|
|
28
|
+
global ACCT_HI: Field = 0x11111111111111111111111111111111;
|
|
29
|
+
global ACCT_LO: Field = 0x22222222222222222222222222222222;
|
|
30
|
+
global ENR_HI: Field = 0x33333333333333333333333333333333;
|
|
31
|
+
global ENR_LO: Field = 0x44444444444444444444444444444444;
|
|
32
|
+
global DIGEST_HI: Field = 0x55555555555555555555555555555555;
|
|
33
|
+
global DIGEST_LO: Field = 0x66666666666666666666666666666666;
|
|
34
|
+
|
|
35
|
+
fn stored() -> Field {
|
|
36
|
+
leaf(ACCT_HI, ACCT_LO, ENR_HI, ENR_LO, commitment(SECRET))
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
fn run<let D: u32>(root: Field, null_pub: Field, stmt_pub: Field, index: Field, sib: [Field; D]) {
|
|
40
|
+
check(
|
|
41
|
+
root,
|
|
42
|
+
null_pub,
|
|
43
|
+
stmt_pub,
|
|
44
|
+
SECRET,
|
|
45
|
+
ACCT_HI,
|
|
46
|
+
ACCT_LO,
|
|
47
|
+
ENR_HI,
|
|
48
|
+
ENR_LO,
|
|
49
|
+
DIGEST_HI,
|
|
50
|
+
DIGEST_LO,
|
|
51
|
+
index,
|
|
52
|
+
sib,
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
fn good_null() -> Field {
|
|
57
|
+
nullifier(ACCT_HI, ACCT_LO, ENR_HI, ENR_LO, SECRET)
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
fn good_stmt() -> Field {
|
|
61
|
+
statement_hash(ACCT_HI, ACCT_LO, ENR_HI, ENR_LO, DIGEST_HI, DIGEST_LO)
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
#[test]
|
|
65
|
+
fn first_leaf_of_depth_32_tree() {
|
|
66
|
+
let zeros: [Field; 32] = zero_hashes();
|
|
67
|
+
let root = merkle_root(stored(), 0, zeros);
|
|
68
|
+
run(root, good_null(), good_stmt(), 0, zeros);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// Index 2^32 - 1 has every path bit set: the leaf is the right child at every
|
|
72
|
+
// level. This is the last slot before the pool rolls over to a new tree.
|
|
73
|
+
#[test]
|
|
74
|
+
fn last_leaf_of_depth_32_tree() {
|
|
75
|
+
let zeros: [Field; 32] = zero_hashes();
|
|
76
|
+
let mut cur = stored();
|
|
77
|
+
for i in 0..32 {
|
|
78
|
+
cur = hash2(zeros[i], cur);
|
|
79
|
+
}
|
|
80
|
+
run(cur, good_null(), good_stmt(), 0xffffffff, zeros);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
#[test(should_fail)]
|
|
84
|
+
fn index_past_capacity_is_unprovable() {
|
|
85
|
+
let zeros: [Field; 32] = zero_hashes();
|
|
86
|
+
let root = merkle_root(stored(), 0, zeros);
|
|
87
|
+
// 2^32 aliases index 0 if it were truncated; the bit decomposition must
|
|
88
|
+
// reject it instead.
|
|
89
|
+
run(root, good_null(), good_stmt(), 0x100000000, zeros);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
#[test(should_fail)]
|
|
93
|
+
fn wrong_root_fails() {
|
|
94
|
+
let zeros: [Field; 32] = zero_hashes();
|
|
95
|
+
let root = merkle_root(stored(), 0, zeros);
|
|
96
|
+
run(root + 1, good_null(), good_stmt(), 0, zeros);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
#[test(should_fail)]
|
|
100
|
+
fn wrong_index_fails() {
|
|
101
|
+
let zeros: [Field; 32] = zero_hashes();
|
|
102
|
+
let root = merkle_root(stored(), 0, zeros);
|
|
103
|
+
run(root, good_null(), good_stmt(), 1, zeros);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
#[test(should_fail)]
|
|
107
|
+
fn wrong_nullifier_fails() {
|
|
108
|
+
let zeros: [Field; 32] = zero_hashes();
|
|
109
|
+
let root = merkle_root(stored(), 0, zeros);
|
|
110
|
+
run(root, good_null() + 1, good_stmt(), 0, zeros);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
#[test(should_fail)]
|
|
114
|
+
fn wrong_statement_hash_fails() {
|
|
115
|
+
let zeros: [Field; 32] = zero_hashes();
|
|
116
|
+
let root = merkle_root(stored(), 0, zeros);
|
|
117
|
+
run(root, good_null(), good_stmt() + 1, 0, zeros);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// A leaf enrolled for one account cannot back a statement for another
|
|
121
|
+
// account: the statement hash's account must be the leaf's account.
|
|
122
|
+
#[test(should_fail)]
|
|
123
|
+
fn statement_for_another_account_fails() {
|
|
124
|
+
let zeros: [Field; 32] = zero_hashes();
|
|
125
|
+
let root = merkle_root(stored(), 0, zeros);
|
|
126
|
+
let other = statement_hash(ACCT_HI + 1, ACCT_LO, ENR_HI, ENR_LO, DIGEST_HI, DIGEST_LO);
|
|
127
|
+
run(root, good_null(), other, 0, zeros);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// A leaf enrolled under one enrollment id cannot back a statement checked
|
|
131
|
+
// against another (for example the account's newer enrollment).
|
|
132
|
+
#[test(should_fail)]
|
|
133
|
+
fn statement_for_another_enrollment_fails() {
|
|
134
|
+
let zeros: [Field; 32] = zero_hashes();
|
|
135
|
+
let root = merkle_root(stored(), 0, zeros);
|
|
136
|
+
let other = statement_hash(ACCT_HI, ACCT_LO, ENR_HI, ENR_LO + 1, DIGEST_HI, DIGEST_LO);
|
|
137
|
+
run(root, good_null(), other, 0, zeros);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
#[test]
|
|
141
|
+
fn hash_arity_is_domain_separated() {
|
|
142
|
+
// Poseidon2's IV encodes the message length, so H2(a, b) never equals the
|
|
143
|
+
// first two inputs of a longer hash with trailing zeros.
|
|
144
|
+
assert(Poseidon2::hash([1, 2], 2) != Poseidon2::hash([1, 2, 0], 3));
|
|
145
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// Perch ZK recovery membership proof at depth 32. The relation lives in
|
|
2
|
+
// `perch_zk::check`; see that crate for the formulas.
|
|
3
|
+
|
|
4
|
+
global DEPTH: u32 = 32;
|
|
5
|
+
|
|
6
|
+
fn main(
|
|
7
|
+
root: pub Field,
|
|
8
|
+
nullifier: pub Field,
|
|
9
|
+
statement_hash: pub Field,
|
|
10
|
+
secret: Field,
|
|
11
|
+
acct_hi: Field,
|
|
12
|
+
acct_lo: Field,
|
|
13
|
+
enr_hi: Field,
|
|
14
|
+
enr_lo: Field,
|
|
15
|
+
digest_hi: Field,
|
|
16
|
+
digest_lo: Field,
|
|
17
|
+
leaf_index: Field,
|
|
18
|
+
siblings: [Field; DEPTH],
|
|
19
|
+
) {
|
|
20
|
+
perch_zk::check(
|
|
21
|
+
root,
|
|
22
|
+
nullifier,
|
|
23
|
+
statement_hash,
|
|
24
|
+
secret,
|
|
25
|
+
acct_hi,
|
|
26
|
+
acct_lo,
|
|
27
|
+
enr_hi,
|
|
28
|
+
enr_lo,
|
|
29
|
+
digest_hi,
|
|
30
|
+
digest_lo,
|
|
31
|
+
leaf_index,
|
|
32
|
+
siblings,
|
|
33
|
+
);
|
|
34
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// Perch ZK recovery membership proof at depth 24. The relation lives in
|
|
2
|
+
// `perch_zk::check`; see that crate for the formulas.
|
|
3
|
+
//
|
|
4
|
+
// Benchmark/fallback build only: the release circuit is depth 32
|
|
5
|
+
// (../perch_zk_recovery). Kept so the depth decision in docs/zk/README.md can
|
|
6
|
+
// be re-measured, and so the documented depth-24 fallback stays buildable.
|
|
7
|
+
|
|
8
|
+
global DEPTH: u32 = 24;
|
|
9
|
+
|
|
10
|
+
fn main(
|
|
11
|
+
root: pub Field,
|
|
12
|
+
nullifier: pub Field,
|
|
13
|
+
statement_hash: pub Field,
|
|
14
|
+
secret: Field,
|
|
15
|
+
acct_hi: Field,
|
|
16
|
+
acct_lo: Field,
|
|
17
|
+
enr_hi: Field,
|
|
18
|
+
enr_lo: Field,
|
|
19
|
+
digest_hi: Field,
|
|
20
|
+
digest_lo: Field,
|
|
21
|
+
leaf_index: Field,
|
|
22
|
+
siblings: [Field; DEPTH],
|
|
23
|
+
) {
|
|
24
|
+
perch_zk::check(
|
|
25
|
+
root,
|
|
26
|
+
nullifier,
|
|
27
|
+
statement_hash,
|
|
28
|
+
secret,
|
|
29
|
+
acct_hi,
|
|
30
|
+
acct_lo,
|
|
31
|
+
enr_hi,
|
|
32
|
+
enr_lo,
|
|
33
|
+
digest_hi,
|
|
34
|
+
digest_lo,
|
|
35
|
+
leaf_index,
|
|
36
|
+
siblings,
|
|
37
|
+
);
|
|
38
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
4458503dd48e88c4e0b945fb252a08b93c40ec757309b8ffa7c594dfa1e35104 LICENSE
|
|
2
|
+
ffaf9da5f383a785814c84e46a62bfd91c14edec394c2dad8572b62b35b4a974 NOTICE
|
|
3
|
+
551d27ec7bf58e6e40896ee424210ac0f3724b29c05068cf34fef3ea8ca1b57a Nargo.toml
|
|
4
|
+
c5d9384ee8d4701495a9d2cdfbbfa1111e3e6e43eca25d9307565fdda18c4437 README.md
|
|
5
|
+
6f37e9a3bc035d6a4d72a5ff6b31cd088089616f3262516ab261ae2b3b7b9d7c src/bench.nr
|
|
6
|
+
5d8b3eeccceb4ac36b66430d3678fc2e8d9e6ab5b759556244be1234882fdff9 src/lib.nr
|
|
7
|
+
5cbc92699d59102e18f3809a59b8b37d0325069bdba8450ebf51a56fcc0e2943 src/oracle_tests.nr
|
|
8
|
+
3007cd7ed46c89b92d613e5af93f40ab9c9aa76a05ae1b13c39c507a7b342694 src/poseidon/bn254.nr
|
|
9
|
+
0e1ce6ec6ed2ebbab52739ab07a2ab7a9cfb9b479cb012527f5e08447677dfd2 src/poseidon/bn254/consts.nr
|
|
10
|
+
1daf55657af0418deb717b74cd45a1a4e9ac9d59678335cf0e677ed8a682be23 src/poseidon/bn254/perm.nr
|
|
11
|
+
a4682f0d4aa03250784c07a06da5bc7c7278eb02a95bd77eb36795e3206f0f9b src/poseidon/mod.nr
|
|
12
|
+
6d3ddc2ab0812a660fa2861415cdb6f108ea140a03dc1e83f627a3ccd272e1f9 src/poseidon2.nr
|
|
13
|
+
41515204b15fb01b0277bc4745dde42032d4e314545f4f4c109b21b54f783662 src/tests.nr
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
Vendored third-party dependency
|
|
2
|
+
===============================
|
|
3
|
+
|
|
4
|
+
Library: poseidon (Noir)
|
|
5
|
+
Upstream: https://github.com/noir-lang/poseidon
|
|
6
|
+
Tag: v0.2.0
|
|
7
|
+
Commit: 4bc50d88dd8d94a00a95730fd76501e676417abf
|
|
8
|
+
License: Apache License 2.0 (see LICENSE)
|
|
9
|
+
|
|
10
|
+
Copied verbatim from NethermindEth/rs-soroban-ultrahonk@c2160987
|
|
11
|
+
(circuits/vendor/poseidon), which vendors the commit above unmodified; it is
|
|
12
|
+
also byte-identical to a fresh nargo checkout of the v0.2.0 tag. Only the
|
|
13
|
+
upstream repository's build/CI scaffolding is omitted (none of it is compiled
|
|
14
|
+
by nargo).
|
|
15
|
+
|
|
16
|
+
Why vendored: a git dependency names a mutable tag, and nargo has no `rev`
|
|
17
|
+
key and writes no lockfile, so a rebuild could fetch different library
|
|
18
|
+
source from unchanged repository source and produce a different ACIR and
|
|
19
|
+
verification key (OpenZeppelin's audit of the verifier repository, finding
|
|
20
|
+
N-06). A path dependency freezes the source in the repository.
|
|
21
|
+
|
|
22
|
+
CHECKSUMS.sha256 pins every vendored file;
|
|
23
|
+
crates/perch-zk-adapter/tests/vendor.rs fails on any drift. Changing this
|
|
24
|
+
library changes the verification key of circuits/perch_zk_recovery (and
|
|
25
|
+
_d24): regenerate with `just zk-artifacts` and redeploy the adapter.
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# Poseidon Hashing Library
|
|
2
|
+
|
|
3
|
+
This package contains the Poseidon hashing interface, formerly in the Noir standard library.
|
|
4
|
+
|
|
5
|
+
## Noir version compatibility
|
|
6
|
+
|
|
7
|
+
This library is tested to work as of Noir version 0.36.0.
|
|
8
|
+
|
|
9
|
+
## Benchmarks
|
|
10
|
+
|
|
11
|
+
Benchmarks are ignored by `git` and checked on pull-request. As such, benchmarks may be generated
|
|
12
|
+
with the following command.
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
# execute the following
|
|
16
|
+
./scripts/build-gates-report.sh
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
The benchmark will be generated at `./gates_report.json`.
|
|
20
|
+
|
|
21
|
+
## Installation
|
|
22
|
+
|
|
23
|
+
In your _Nargo.toml_ file, add the version of this library you would like to install under dependency:
|
|
24
|
+
|
|
25
|
+
```toml
|
|
26
|
+
[dependencies]
|
|
27
|
+
poseidon = { tag = "v0.1.1", git = "https://github.com/noir-lang/poseidon" }
|
|
28
|
+
```
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
use super::poseidon2;
|
|
2
|
+
|
|
3
|
+
/// This calls the bb.js Poseidon2 implementation
|
|
4
|
+
#[oracle(getPoseidon2Hash)]
|
|
5
|
+
unconstrained fn poseidon2_hash_oracle(input: [Field; 10]) -> Field {}
|
|
6
|
+
|
|
7
|
+
unconstrained fn get_poseidon2_hash(input: [Field; 10]) -> Field {
|
|
8
|
+
poseidon2_hash_oracle(input)
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
#[test]
|
|
12
|
+
unconstrained fn test_poseidon2(input: [Field; 10]) {
|
|
13
|
+
// get hash from Noir implementation
|
|
14
|
+
let noir_hash = poseidon2::Poseidon2::hash(input, input.len());
|
|
15
|
+
|
|
16
|
+
// get hash from bb.js via oracle
|
|
17
|
+
let bb_hash = get_poseidon2_hash(input);
|
|
18
|
+
|
|
19
|
+
assert_eq(noir_hash, bb_hash);
|
|
20
|
+
}
|