@stellar-registry/perch-artifacts 0.0.0-stage → 0.1.0

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.
Files changed (50) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +88 -2
  3. package/circuits/Nargo.toml +3 -0
  4. package/circuits/artifacts/perch_zk_recovery.json +104 -0
  5. package/circuits/artifacts/perch_zk_recovery_d24.json +104 -0
  6. package/circuits/manifest.json +101 -0
  7. package/circuits/perch_zk/Nargo.toml +9 -0
  8. package/circuits/perch_zk/src/lib.nr +126 -0
  9. package/circuits/perch_zk/src/tests.nr +145 -0
  10. package/circuits/perch_zk_recovery/Nargo.toml +7 -0
  11. package/circuits/perch_zk_recovery/src/main.nr +34 -0
  12. package/circuits/perch_zk_recovery_d24/Nargo.toml +7 -0
  13. package/circuits/perch_zk_recovery_d24/src/main.nr +38 -0
  14. package/circuits/vendor/poseidon/CHECKSUMS.sha256 +13 -0
  15. package/circuits/vendor/poseidon/LICENSE +201 -0
  16. package/circuits/vendor/poseidon/NOTICE +25 -0
  17. package/circuits/vendor/poseidon/Nargo.toml +7 -0
  18. package/circuits/vendor/poseidon/README.md +28 -0
  19. package/circuits/vendor/poseidon/src/bench.nr +6 -0
  20. package/circuits/vendor/poseidon/src/lib.nr +8 -0
  21. package/circuits/vendor/poseidon/src/oracle_tests.nr +20 -0
  22. package/circuits/vendor/poseidon/src/poseidon/bn254/consts.nr +24965 -0
  23. package/circuits/vendor/poseidon/src/poseidon/bn254/perm.nr +115 -0
  24. package/circuits/vendor/poseidon/src/poseidon/bn254.nr +173 -0
  25. package/circuits/vendor/poseidon/src/poseidon/mod.nr +359 -0
  26. package/circuits/vendor/poseidon/src/poseidon2.nr +98 -0
  27. package/circuits/vendor/poseidon/src/tests.nr +34 -0
  28. package/constants.json +14 -0
  29. package/deployments/testnet-exercise.json +2469 -0
  30. package/deployments/testnet.json +129 -0
  31. package/dist/cli/derive-id.d.ts +2 -0
  32. package/dist/cli/derive-id.js +17 -0
  33. package/dist/cli/fetch-infra-wasm.d.ts +2 -0
  34. package/dist/cli/fetch-infra-wasm.js +5 -0
  35. package/dist/cli/zk-toolchain.d.ts +2 -0
  36. package/dist/cli/zk-toolchain.js +5 -0
  37. package/dist/derive.d.ts +6 -0
  38. package/dist/derive.js +79 -0
  39. package/dist/index.d.ts +105 -0
  40. package/dist/index.js +31 -0
  41. package/dist/script.d.ts +1 -0
  42. package/dist/script.js +12 -0
  43. package/package.json +53 -4
  44. package/scripts/fetch-infra-wasm.sh +114 -0
  45. package/scripts/zk-toolchain.sh +91 -0
  46. package/vectors/auth-vectors.json +143 -0
  47. package/vectors/diagnostic-events.json +37 -0
  48. package/vectors/eval-vectors.json +2244 -0
  49. package/vectors/rule-hashes.json +60 -0
  50. package/vectors/statement-v2.json +230 -0
@@ -0,0 +1,98 @@
1
+ use std::default::Default;
2
+ use std::hash::Hasher;
3
+
4
+ comptime global RATE: u32 = 3;
5
+
6
+ pub struct Poseidon2 {
7
+ cache: [Field; 3],
8
+ state: [Field; 4],
9
+ cache_size: u32,
10
+ squeeze_mode: bool, // 0 => absorb, 1 => squeeze
11
+ }
12
+
13
+ impl Poseidon2 {
14
+ #[no_predicates]
15
+ pub fn hash<let N: u32>(input: [Field; N], message_size: u32) -> Field {
16
+ Poseidon2::hash_internal(input, message_size)
17
+ }
18
+
19
+ pub(crate) fn new(iv: Field) -> Poseidon2 {
20
+ let mut result =
21
+ Poseidon2 { cache: [0; 3], state: [0; 4], cache_size: 0, squeeze_mode: false };
22
+ result.state[RATE] = iv;
23
+ result
24
+ }
25
+
26
+ fn perform_duplex(&mut self) {
27
+ // add the cache into sponge state
28
+ for i in 0..RATE {
29
+ // We effectively zero-pad the cache by only adding to the state
30
+ // cache that is less than the specified `cache_size`
31
+ if i < self.cache_size {
32
+ self.state[i] += self.cache[i];
33
+ }
34
+ }
35
+ self.state = crate::poseidon2_permutation(self.state, 4);
36
+ }
37
+
38
+ fn absorb(&mut self, input: Field) {
39
+ assert(!self.squeeze_mode);
40
+ if self.cache_size == RATE {
41
+ // If we're absorbing, and the cache is full, apply the sponge permutation to compress the cache
42
+ self.perform_duplex();
43
+ self.cache[0] = input;
44
+ self.cache_size = 1;
45
+ } else {
46
+ // If we're absorbing, and the cache is not full, add the input into the cache
47
+ self.cache[self.cache_size] = input;
48
+ self.cache_size += 1;
49
+ }
50
+ }
51
+
52
+ fn squeeze(&mut self) -> Field {
53
+ assert(!self.squeeze_mode);
54
+ // If we're in absorb mode, apply sponge permutation to compress the cache.
55
+ self.perform_duplex();
56
+ self.squeeze_mode = true;
57
+
58
+ // Pop one item off the top of the permutation and return it.
59
+ self.state[0]
60
+ }
61
+
62
+ fn hash_internal<let N: u32>(input: [Field; N], in_len: u32) -> Field {
63
+ let two_pow_64 = 18446744073709551616;
64
+ let iv: Field = (in_len as Field) * two_pow_64;
65
+ let mut sponge = Poseidon2::new(iv);
66
+ for i in 0..input.len() {
67
+ if i < in_len {
68
+ sponge.absorb(input[i]);
69
+ }
70
+ }
71
+ sponge.squeeze()
72
+ }
73
+ }
74
+
75
+ pub struct Poseidon2Hasher {
76
+ _state: [Field],
77
+ }
78
+
79
+ impl Hasher for Poseidon2Hasher {
80
+ fn finish(self) -> Field {
81
+ let iv: Field = (self._state.len() as Field) * 18446744073709551616; // iv = (self._state.len() << 64)
82
+ let mut sponge = Poseidon2::new(iv);
83
+ for i in 0..self._state.len() {
84
+ sponge.absorb(self._state[i]);
85
+ }
86
+ sponge.squeeze()
87
+ }
88
+
89
+ fn write(&mut self, input: Field) {
90
+ self._state = self._state.push_back(input);
91
+ }
92
+ }
93
+
94
+ impl Default for Poseidon2Hasher {
95
+ fn default() -> Self {
96
+ Poseidon2Hasher { _state: &[] }
97
+ }
98
+ }
@@ -0,0 +1,34 @@
1
+ use super::poseidon;
2
+
3
+ #[test]
4
+ fn reference_impl_test_vectors() {
5
+ // hardcoded test vectors from https://extgit.iaik.tugraz.at/krypto/hadeshash/-/blob/master/code/test_vectors.txt
6
+ {
7
+ let mut state = [0, 1, 2];
8
+ let mut expected = [
9
+ 0x115cc0f5e7d690413df64c6b9662e9cf2a3617f2743245519e19607a4417189a,
10
+ 0x0fca49b798923ab0239de1c9e7a4a9a2210312b6a2f616d18b5a87f9b628ae29,
11
+ 0x0e7ae82e40091e63cbd4f16a6d16310b3729d4b6e138fcf54110e2867045a30c,
12
+ ];
13
+ assert_eq(
14
+ expected,
15
+ poseidon::bn254::perm::x5_3(state),
16
+ "Failed to reproduce output for [0, 1, 2]",
17
+ );
18
+ }
19
+ {
20
+ let mut state = [0, 1, 2, 3, 4];
21
+ let mut expected = [
22
+ 0x299c867db6c1fdd79dcefa40e4510b9837e60ebb1ce0663dbaa525df65250465,
23
+ 0x1148aaef609aa338b27dafd89bb98862d8bb2b429aceac47d86206154ffe053d,
24
+ 0x24febb87fed7462e23f6665ff9a0111f4044c38ee1672c1ac6b0637d34f24907,
25
+ 0x0eb08f6d809668a981c186beaf6110060707059576406b248e5d9cf6e78b3d3e,
26
+ 0x07748bc6877c9b82c8b98666ee9d0626ec7f5be4205f79ee8528ef1c4a376fc7,
27
+ ];
28
+ assert_eq(
29
+ expected,
30
+ poseidon::bn254::perm::x5_5(state),
31
+ "Failed to reproduce output for [0, 1, 2, 3, 4]",
32
+ );
33
+ }
34
+ }
package/constants.json ADDED
@@ -0,0 +1,14 @@
1
+ {
2
+ "comment": "Written by crates/integration-tests/tests/artifact_constants.rs (PERCH_BLESS=1) from the crates' own constants.",
3
+ "doc_compiler": {
4
+ "MAX_DOC_CANONICAL_BYTES": 8192,
5
+ "MAX_DOC_RULES": 11,
6
+ "MAX_DOC_SIGNERS": 8,
7
+ "MAX_RULE_NAME_BYTES": 20
8
+ },
9
+ "program": {
10
+ "MAX_PROGRAM_LEN": 256,
11
+ "MAX_STACK_DEPTH": 128,
12
+ "PROGRAM_VERSION": 1
13
+ }
14
+ }