starkshield 1.0.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 (156) hide show
  1. package/README.md +101 -0
  2. package/bin/circom +0 -0
  3. package/bin/cli.js +36 -0
  4. package/bin/index.js +13 -0
  5. package/circomlib/.vscode/launch.json +63 -0
  6. package/circomlib/README.md +18 -0
  7. package/circomlib/circuits/README.md +830 -0
  8. package/circomlib/circuits/aliascheck.circom +33 -0
  9. package/circomlib/circuits/babyjub.circom +107 -0
  10. package/circomlib/circuits/binsub.circom +74 -0
  11. package/circomlib/circuits/binsum.circom +101 -0
  12. package/circomlib/circuits/bitify.circom +106 -0
  13. package/circomlib/circuits/comparators.circom +141 -0
  14. package/circomlib/circuits/compconstant.circom +74 -0
  15. package/circomlib/circuits/eddsa.circom +139 -0
  16. package/circomlib/circuits/eddsamimc.circom +124 -0
  17. package/circomlib/circuits/eddsamimcsponge.circom +124 -0
  18. package/circomlib/circuits/eddsaposeidon.circom +123 -0
  19. package/circomlib/circuits/escalarmul.circom +166 -0
  20. package/circomlib/circuits/escalarmulany.circom +197 -0
  21. package/circomlib/circuits/escalarmulfix.circom +299 -0
  22. package/circomlib/circuits/escalarmulw4table.circom +52 -0
  23. package/circomlib/circuits/gates.circom +96 -0
  24. package/circomlib/circuits/mimc.circom +156 -0
  25. package/circomlib/circuits/mimcsponge.circom +293 -0
  26. package/circomlib/circuits/montgomery.circom +142 -0
  27. package/circomlib/circuits/multiplexer.circom +115 -0
  28. package/circomlib/circuits/mux1.circom +48 -0
  29. package/circomlib/circuits/mux2.circom +63 -0
  30. package/circomlib/circuits/mux3.circom +75 -0
  31. package/circomlib/circuits/mux4.circom +119 -0
  32. package/circomlib/circuits/pedersen.circom +257 -0
  33. package/circomlib/circuits/pedersen_old.circom +68 -0
  34. package/circomlib/circuits/pointbits.circom +164 -0
  35. package/circomlib/circuits/poseidon.circom +208 -0
  36. package/circomlib/circuits/poseidon_constants.circom +24959 -0
  37. package/circomlib/circuits/poseidon_constants_old.circom +252 -0
  38. package/circomlib/circuits/poseidon_old.circom +97 -0
  39. package/circomlib/circuits/sha256/ch.circom +47 -0
  40. package/circomlib/circuits/sha256/constants.circom +53 -0
  41. package/circomlib/circuits/sha256/main.circom +35 -0
  42. package/circomlib/circuits/sha256/maj.circom +45 -0
  43. package/circomlib/circuits/sha256/rotate.circom +28 -0
  44. package/circomlib/circuits/sha256/sha256.circom +81 -0
  45. package/circomlib/circuits/sha256/sha256_2.circom +91 -0
  46. package/circomlib/circuits/sha256/sha256compression.circom +166 -0
  47. package/circomlib/circuits/sha256/sha256compression_function.circom +112 -0
  48. package/circomlib/circuits/sha256/shift.circom +33 -0
  49. package/circomlib/circuits/sha256/sigma.circom +77 -0
  50. package/circomlib/circuits/sha256/sigmaplus.circom +50 -0
  51. package/circomlib/circuits/sha256/t1.circom +58 -0
  52. package/circomlib/circuits/sha256/t2.circom +51 -0
  53. package/circomlib/circuits/sha256/xor3.circom +45 -0
  54. package/circomlib/circuits/sign.circom +36 -0
  55. package/circomlib/circuits/smt/smthash_mimc.circom +58 -0
  56. package/circomlib/circuits/smt/smthash_poseidon.circom +57 -0
  57. package/circomlib/circuits/smt/smtlevins.circom +103 -0
  58. package/circomlib/circuits/smt/smtprocessor.circom +261 -0
  59. package/circomlib/circuits/smt/smtprocessorlevel.circom +95 -0
  60. package/circomlib/circuits/smt/smtprocessorsm.circom +165 -0
  61. package/circomlib/circuits/smt/smtverifier.circom +138 -0
  62. package/circomlib/circuits/smt/smtverifierlevel.circom +71 -0
  63. package/circomlib/circuits/smt/smtverifiersm.circom +106 -0
  64. package/circomlib/circuits/switcher.circom +42 -0
  65. package/circomlib/doc/root_transfer.monopic +0 -0
  66. package/circomlib/doc/smt_diagram_0.monopic +0 -0
  67. package/circomlib/doc/smt_diagram_1.monopic +0 -0
  68. package/circomlib/doc/smt_hash.monopic +0 -0
  69. package/circomlib/doc/smt_levins.monopic +0 -0
  70. package/circomlib/doc/smt_sm.monopic +0 -0
  71. package/circomlib/doc/smt_verifier_sm.monopic +0 -0
  72. package/circomlib/doc/voting.monopic +0 -0
  73. package/circomlib/doc/window.monopic +0 -0
  74. package/circomlib/doc/window_chain.monopic +0 -0
  75. package/circomlib/index.js +2 -0
  76. package/circomlib/package.json +33 -0
  77. package/circomlib/test/aliascheck.js +77 -0
  78. package/circomlib/test/babyjub.js +118 -0
  79. package/circomlib/test/binsub.js +52 -0
  80. package/circomlib/test/binsum.js +38 -0
  81. package/circomlib/test/circuits/aliascheck_test.circom +4 -0
  82. package/circomlib/test/circuits/babyadd_tester.circom +4 -0
  83. package/circomlib/test/circuits/babycheck_test.circom +4 -0
  84. package/circomlib/test/circuits/babypbk_test.circom +4 -0
  85. package/circomlib/test/circuits/binsub_test.circom +33 -0
  86. package/circomlib/test/circuits/constants_test.circom +20 -0
  87. package/circomlib/test/circuits/eddsa_test.circom +5 -0
  88. package/circomlib/test/circuits/eddsamimc_test.circom +5 -0
  89. package/circomlib/test/circuits/eddsaposeidon_test.circom +5 -0
  90. package/circomlib/test/circuits/edwards2montgomery.circom +5 -0
  91. package/circomlib/test/circuits/escalarmul_min_test.circom +27 -0
  92. package/circomlib/test/circuits/escalarmul_test.circom +33 -0
  93. package/circomlib/test/circuits/escalarmul_test_min.circom +28 -0
  94. package/circomlib/test/circuits/escalarmulany_test.circom +30 -0
  95. package/circomlib/test/circuits/escalarmulfix_test.circom +31 -0
  96. package/circomlib/test/circuits/escalarmulw4table.circom +20 -0
  97. package/circomlib/test/circuits/escalarmulw4table_test.circom +19 -0
  98. package/circomlib/test/circuits/escalarmulw4table_test3.circom +19 -0
  99. package/circomlib/test/circuits/greatereqthan.circom +5 -0
  100. package/circomlib/test/circuits/greaterthan.circom +5 -0
  101. package/circomlib/test/circuits/isequal.circom +5 -0
  102. package/circomlib/test/circuits/iszero.circom +5 -0
  103. package/circomlib/test/circuits/lesseqthan.circom +5 -0
  104. package/circomlib/test/circuits/lessthan.circom +5 -0
  105. package/circomlib/test/circuits/mimc_sponge_hash_test.circom +5 -0
  106. package/circomlib/test/circuits/mimc_sponge_test.circom +5 -0
  107. package/circomlib/test/circuits/mimc_test.circom +5 -0
  108. package/circomlib/test/circuits/montgomery2edwards.circom +5 -0
  109. package/circomlib/test/circuits/montgomeryadd.circom +5 -0
  110. package/circomlib/test/circuits/montgomerydouble.circom +5 -0
  111. package/circomlib/test/circuits/mux1_1.circom +33 -0
  112. package/circomlib/test/circuits/mux2_1.circom +37 -0
  113. package/circomlib/test/circuits/mux3_1.circom +41 -0
  114. package/circomlib/test/circuits/mux4_1.circom +56 -0
  115. package/circomlib/test/circuits/pedersen2_test.circom +34 -0
  116. package/circomlib/test/circuits/pedersen_test.circom +31 -0
  117. package/circomlib/test/circuits/pointbits_loopback.circom +25 -0
  118. package/circomlib/test/circuits/poseidon3_test.circom +5 -0
  119. package/circomlib/test/circuits/poseidon6_test.circom +5 -0
  120. package/circomlib/test/circuits/poseidonex_test.circom +5 -0
  121. package/circomlib/test/circuits/sha256_2_test.circom +17 -0
  122. package/circomlib/test/circuits/sha256_test448.circom +5 -0
  123. package/circomlib/test/circuits/sha256_test512.circom +5 -0
  124. package/circomlib/test/circuits/sign_test.circom +5 -0
  125. package/circomlib/test/circuits/smtprocessor10_test.circom +5 -0
  126. package/circomlib/test/circuits/smtverifier10_test.circom +5 -0
  127. package/circomlib/test/circuits/sum_test.circom +33 -0
  128. package/circomlib/test/comparators.js +187 -0
  129. package/circomlib/test/eddsa.js +75 -0
  130. package/circomlib/test/eddsamimc.js +102 -0
  131. package/circomlib/test/eddsaposeidon.js +103 -0
  132. package/circomlib/test/escalarmul.js +121 -0
  133. package/circomlib/test/escalarmulany.js +51 -0
  134. package/circomlib/test/escalarmulfix.js +95 -0
  135. package/circomlib/test/helpers/printsignal.js +22 -0
  136. package/circomlib/test/helpers/sha256.js +178 -0
  137. package/circomlib/test/mimccircuit.js +27 -0
  138. package/circomlib/test/mimcspongecircuit.js +47 -0
  139. package/circomlib/test/montgomery.js +101 -0
  140. package/circomlib/test/multiplexer.js +101 -0
  141. package/circomlib/test/pedersen.js +83 -0
  142. package/circomlib/test/pedersen2.js +56 -0
  143. package/circomlib/test/point2bits.js +30 -0
  144. package/circomlib/test/poseidoncircuit.js +80 -0
  145. package/circomlib/test/sha256.js +118 -0
  146. package/circomlib/test/sign.js +82 -0
  147. package/circomlib/test/smtprocessor.js +219 -0
  148. package/circomlib/test/smtverifier.js +141 -0
  149. package/lib/compile.js +82 -0
  150. package/lib/deploy.js +391 -0
  151. package/lib/test.js +47 -0
  152. package/lib/verify.js +153 -0
  153. package/package.json +43 -0
  154. package/pot12_0000.ptau +0 -0
  155. package/pot12_0001.ptau +0 -0
  156. package/ptau/pot12_final.ptau +0 -0
@@ -0,0 +1,68 @@
1
+ /*
2
+ Copyright 2018 0KIMS association.
3
+
4
+ This file is part of circom (Zero Knowledge Circuit Compiler).
5
+
6
+ circom is a free software: you can redistribute it and/or modify it
7
+ under the terms of the GNU General Public License as published by
8
+ the Free Software Foundation, either version 3 of the License, or
9
+ (at your option) any later version.
10
+
11
+ circom is distributed in the hope that it will be useful, but WITHOUT
12
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13
+ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
14
+ License for more details.
15
+
16
+ You should have received a copy of the GNU General Public License
17
+ along with circom. If not, see <https://www.gnu.org/licenses/>.
18
+ */
19
+ pragma circom 2.0.0;
20
+
21
+ include "escalarmul.circom";
22
+
23
+ template Pedersen(n) {
24
+ signal input in[n];
25
+ signal output out[2];
26
+
27
+ var nexps = ((n-1) \ 250) + 1;
28
+ var nlastbits = n - (nexps-1)*250;
29
+
30
+ component escalarMuls[nexps];
31
+
32
+ var PBASE[10][2] = [
33
+ [10457101036533406547632367118273992217979173478358440826365724437999023779287,19824078218392094440610104313265183977899662750282163392862422243483260492317],
34
+ [2671756056509184035029146175565761955751135805354291559563293617232983272177,2663205510731142763556352975002641716101654201788071096152948830924149045094],
35
+ [5802099305472655231388284418920769829666717045250560929368476121199858275951,5980429700218124965372158798884772646841287887664001482443826541541529227896],
36
+ [7107336197374528537877327281242680114152313102022415488494307685842428166594,2857869773864086953506483169737724679646433914307247183624878062391496185654],
37
+ [20265828622013100949498132415626198973119240347465898028410217039057588424236,1160461593266035632937973507065134938065359936056410650153315956301179689506],
38
+ [1487999857809287756929114517587739322941449154962237464737694709326309567994,14017256862867289575056460215526364897734808720610101650676790868051368668003],
39
+ [14618644331049802168996997831720384953259095788558646464435263343433563860015,13115243279999696210147231297848654998887864576952244320558158620692603342236],
40
+ [6814338563135591367010655964669793483652536871717891893032616415581401894627,13660303521961041205824633772157003587453809761793065294055279768121314853695],
41
+ [3571615583211663069428808372184817973703476260057504149923239576077102575715,11981351099832644138306422070127357074117642951423551606012551622164230222506],
42
+ [18597552580465440374022635246985743886550544261632147935254624835147509493269,6753322320275422086923032033899357299485124665258735666995435957890214041481]
43
+
44
+ ];
45
+
46
+ var i;
47
+ var j;
48
+ var nexpbits;
49
+ for (i=0; i<nexps; i++) {
50
+ nexpbits = (i == nexps-1) ? nlastbits : 250;
51
+ escalarMuls[i] = EscalarMul(nexpbits, PBASE[i]);
52
+
53
+ for (j=0; j<nexpbits; j++) {
54
+ escalarMuls[i].in[j] <== in[250*i + j];
55
+ }
56
+
57
+ if (i==0) {
58
+ escalarMuls[i].inp[0] <== 0;
59
+ escalarMuls[i].inp[1] <== 1;
60
+ } else {
61
+ escalarMuls[i].inp[0] <== escalarMuls[i-1].out[0];
62
+ escalarMuls[i].inp[1] <== escalarMuls[i-1].out[1];
63
+ }
64
+ }
65
+
66
+ escalarMuls[nexps-1].out[0] ==> out[0];
67
+ escalarMuls[nexps-1].out[1] ==> out[1];
68
+ }
@@ -0,0 +1,164 @@
1
+ /*
2
+ Copyright 2018 0KIMS association.
3
+
4
+ This file is part of circom (Zero Knowledge Circuit Compiler).
5
+
6
+ circom is a free software: you can redistribute it and/or modify it
7
+ under the terms of the GNU General Public License as published by
8
+ the Free Software Foundation, either version 3 of the License, or
9
+ (at your option) any later version.
10
+
11
+ circom is distributed in the hope that it will be useful, but WITHOUT
12
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13
+ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
14
+ License for more details.
15
+
16
+ You should have received a copy of the GNU General Public License
17
+ along with circom. If not, see <https://www.gnu.org/licenses/>.
18
+ */
19
+ pragma circom 2.0.0;
20
+
21
+ include "bitify.circom";
22
+ include "aliascheck.circom";
23
+ include "compconstant.circom";
24
+ include "babyjub.circom";
25
+
26
+
27
+ function sqrt(n) {
28
+
29
+ if (n == 0) {
30
+ return 0;
31
+ }
32
+
33
+ // Test that have solution
34
+ var res = n ** ((-1) >> 1);
35
+ // if (res!=1) assert(false, "SQRT does not exists");
36
+ if (res!=1) return 0;
37
+
38
+ var m = 28;
39
+ var c = 19103219067921713944291392827692070036145651957329286315305642004821462161904;
40
+ var t = n ** 81540058820840996586704275553141814055101440848469862132140264610111;
41
+ var r = n ** ((81540058820840996586704275553141814055101440848469862132140264610111+1)>>1);
42
+ var sq;
43
+ var i;
44
+ var b;
45
+ var j;
46
+
47
+ while ((r != 0)&&(t != 1)) {
48
+ sq = t*t;
49
+ i = 1;
50
+ while (sq!=1) {
51
+ i++;
52
+ sq = sq*sq;
53
+ }
54
+
55
+ // b = c ^ m-i-1
56
+ b = c;
57
+ for (j=0; j< m-i-1; j ++) b = b*b;
58
+
59
+ m = i;
60
+ c = b*b;
61
+ t = t*c;
62
+ r = r*b;
63
+ }
64
+
65
+ if (r < 0 ) {
66
+ r = -r;
67
+ }
68
+
69
+ return r;
70
+ }
71
+
72
+
73
+ template Bits2Point() {
74
+ signal input in[256];
75
+ signal output out[2];
76
+ }
77
+
78
+ template Bits2Point_Strict() {
79
+ signal input in[256];
80
+ signal output out[2];
81
+
82
+ var i;
83
+
84
+ // Check aliasing
85
+ component aliasCheckY = AliasCheck();
86
+ for (i=0; i<254; i++) {
87
+ aliasCheckY.in[i] <== in[i];
88
+ }
89
+ in[254] === 0;
90
+
91
+ component b2nY = Bits2Num(254);
92
+ for (i=0; i<254; i++) {
93
+ b2nY.in[i] <== in[i];
94
+ }
95
+
96
+ out[1] <== b2nY.out;
97
+
98
+ var a = 168700;
99
+ var d = 168696;
100
+
101
+ var y2 = out[1] * out[1];
102
+
103
+ var x = sqrt( (1-y2)/(a - d*y2) );
104
+
105
+ if (in[255] == 1) x = -x;
106
+
107
+ out[0] <-- x;
108
+
109
+ component babyCheck = BabyCheck();
110
+ babyCheck.x <== out[0];
111
+ babyCheck.y <== out[1];
112
+
113
+ component n2bX = Num2Bits(254);
114
+ n2bX.in <== out[0];
115
+ component aliasCheckX = AliasCheck();
116
+ for (i=0; i<254; i++) {
117
+ aliasCheckX.in[i] <== n2bX.out[i];
118
+ }
119
+
120
+ component signCalc = CompConstant(10944121435919637611123202872628637544274182200208017171849102093287904247808);
121
+ for (i=0; i<254; i++) {
122
+ signCalc.in[i] <== n2bX.out[i];
123
+ }
124
+
125
+ signCalc.out === in[255];
126
+ }
127
+
128
+
129
+ template Point2Bits() {
130
+ signal input in[2];
131
+ signal output out[256];
132
+
133
+
134
+ }
135
+
136
+ template Point2Bits_Strict() {
137
+ signal input in[2];
138
+ signal output out[256];
139
+
140
+ var i;
141
+
142
+ component n2bX = Num2Bits(254);
143
+ n2bX.in <== in[0];
144
+ component n2bY = Num2Bits(254);
145
+ n2bY.in <== in[1];
146
+
147
+ component aliasCheckX = AliasCheck();
148
+ component aliasCheckY = AliasCheck();
149
+ for (i=0; i<254; i++) {
150
+ aliasCheckX.in[i] <== n2bX.out[i];
151
+ aliasCheckY.in[i] <== n2bY.out[i];
152
+ }
153
+
154
+ component signCalc = CompConstant(10944121435919637611123202872628637544274182200208017171849102093287904247808);
155
+ for (i=0; i<254; i++) {
156
+ signCalc.in[i] <== n2bX.out[i];
157
+ }
158
+
159
+ for (i=0; i<254; i++) {
160
+ out[i] <== n2bY.out[i];
161
+ }
162
+ out[254] <== 0;
163
+ out[255] <== signCalc.out;
164
+ }
@@ -0,0 +1,208 @@
1
+ pragma circom 2.0.0;
2
+
3
+ include "./poseidon_constants.circom";
4
+
5
+ template Sigma() {
6
+ signal input in;
7
+ signal output out;
8
+
9
+ signal in2;
10
+ signal in4;
11
+
12
+ in2 <== in*in;
13
+ in4 <== in2*in2;
14
+
15
+ out <== in4*in;
16
+ }
17
+
18
+ template Ark(t, C, r) {
19
+ signal input in[t];
20
+ signal output out[t];
21
+
22
+ for (var i=0; i<t; i++) {
23
+ out[i] <== in[i] + C[i + r];
24
+ }
25
+ }
26
+
27
+ template Mix(t, M) {
28
+ signal input in[t];
29
+ signal output out[t];
30
+
31
+ var lc;
32
+ for (var i=0; i<t; i++) {
33
+ lc = 0;
34
+ for (var j=0; j<t; j++) {
35
+ lc += M[j][i]*in[j];
36
+ }
37
+ out[i] <== lc;
38
+ }
39
+ }
40
+
41
+ template MixLast(t, M, s) {
42
+ signal input in[t];
43
+ signal output out;
44
+
45
+ var lc = 0;
46
+ for (var j=0; j<t; j++) {
47
+ lc += M[j][s]*in[j];
48
+ }
49
+ out <== lc;
50
+ }
51
+
52
+ template MixS(t, S, r) {
53
+ signal input in[t];
54
+ signal output out[t];
55
+
56
+
57
+ var lc = 0;
58
+ for (var i=0; i<t; i++) {
59
+ lc += S[(t*2-1)*r+i]*in[i];
60
+ }
61
+ out[0] <== lc;
62
+ for (var i=1; i<t; i++) {
63
+ out[i] <== in[i] + in[0] * S[(t*2-1)*r + t + i -1];
64
+ }
65
+ }
66
+
67
+ template PoseidonEx(nInputs, nOuts) {
68
+ signal input inputs[nInputs];
69
+ signal input initialState;
70
+ signal output out[nOuts];
71
+
72
+ // Using recommended parameters from whitepaper https://eprint.iacr.org/2019/458.pdf (table 2, table 8)
73
+ // Generated by https://extgit.iaik.tugraz.at/krypto/hadeshash/-/blob/master/code/calc_round_numbers.py
74
+ // And rounded up to nearest integer that divides by t
75
+ var N_ROUNDS_P[16] = [56, 57, 56, 60, 60, 63, 64, 63, 60, 66, 60, 65, 70, 60, 64, 68];
76
+ var t = nInputs + 1;
77
+ var nRoundsF = 8;
78
+ var nRoundsP = N_ROUNDS_P[t - 2];
79
+ var C[t*nRoundsF + nRoundsP] = POSEIDON_C(t);
80
+ var S[ N_ROUNDS_P[t-2] * (t*2-1) ] = POSEIDON_S(t);
81
+ var M[t][t] = POSEIDON_M(t);
82
+ var P[t][t] = POSEIDON_P(t);
83
+
84
+ component ark[nRoundsF];
85
+ component sigmaF[nRoundsF][t];
86
+ component sigmaP[nRoundsP];
87
+ component mix[nRoundsF-1];
88
+ component mixS[nRoundsP];
89
+ component mixLast[nOuts];
90
+
91
+
92
+ ark[0] = Ark(t, C, 0);
93
+ for (var j=0; j<t; j++) {
94
+ if (j>0) {
95
+ ark[0].in[j] <== inputs[j-1];
96
+ } else {
97
+ ark[0].in[j] <== initialState;
98
+ }
99
+ }
100
+
101
+ for (var r = 0; r < nRoundsF\2-1; r++) {
102
+ for (var j=0; j<t; j++) {
103
+ sigmaF[r][j] = Sigma();
104
+ if(r==0) {
105
+ sigmaF[r][j].in <== ark[0].out[j];
106
+ } else {
107
+ sigmaF[r][j].in <== mix[r-1].out[j];
108
+ }
109
+ }
110
+
111
+ ark[r+1] = Ark(t, C, (r+1)*t);
112
+ for (var j=0; j<t; j++) {
113
+ ark[r+1].in[j] <== sigmaF[r][j].out;
114
+ }
115
+
116
+ mix[r] = Mix(t,M);
117
+ for (var j=0; j<t; j++) {
118
+ mix[r].in[j] <== ark[r+1].out[j];
119
+ }
120
+
121
+ }
122
+
123
+ for (var j=0; j<t; j++) {
124
+ sigmaF[nRoundsF\2-1][j] = Sigma();
125
+ sigmaF[nRoundsF\2-1][j].in <== mix[nRoundsF\2-2].out[j];
126
+ }
127
+
128
+ ark[nRoundsF\2] = Ark(t, C, (nRoundsF\2)*t );
129
+ for (var j=0; j<t; j++) {
130
+ ark[nRoundsF\2].in[j] <== sigmaF[nRoundsF\2-1][j].out;
131
+ }
132
+
133
+ mix[nRoundsF\2-1] = Mix(t,P);
134
+ for (var j=0; j<t; j++) {
135
+ mix[nRoundsF\2-1].in[j] <== ark[nRoundsF\2].out[j];
136
+ }
137
+
138
+
139
+ for (var r = 0; r < nRoundsP; r++) {
140
+ sigmaP[r] = Sigma();
141
+ if (r==0) {
142
+ sigmaP[r].in <== mix[nRoundsF\2-1].out[0];
143
+ } else {
144
+ sigmaP[r].in <== mixS[r-1].out[0];
145
+ }
146
+
147
+ mixS[r] = MixS(t, S, r);
148
+ for (var j=0; j<t; j++) {
149
+ if (j==0) {
150
+ mixS[r].in[j] <== sigmaP[r].out + C[(nRoundsF\2+1)*t + r];
151
+ } else {
152
+ if (r==0) {
153
+ mixS[r].in[j] <== mix[nRoundsF\2-1].out[j];
154
+ } else {
155
+ mixS[r].in[j] <== mixS[r-1].out[j];
156
+ }
157
+ }
158
+ }
159
+ }
160
+
161
+ for (var r = 0; r < nRoundsF\2-1; r++) {
162
+ for (var j=0; j<t; j++) {
163
+ sigmaF[nRoundsF\2 + r][j] = Sigma();
164
+ if (r==0) {
165
+ sigmaF[nRoundsF\2 + r][j].in <== mixS[nRoundsP-1].out[j];
166
+ } else {
167
+ sigmaF[nRoundsF\2 + r][j].in <== mix[nRoundsF\2+r-1].out[j];
168
+ }
169
+ }
170
+
171
+ ark[ nRoundsF\2 + r + 1] = Ark(t, C, (nRoundsF\2+1)*t + nRoundsP + r*t );
172
+ for (var j=0; j<t; j++) {
173
+ ark[nRoundsF\2 + r + 1].in[j] <== sigmaF[nRoundsF\2 + r][j].out;
174
+ }
175
+
176
+ mix[nRoundsF\2 + r] = Mix(t,M);
177
+ for (var j=0; j<t; j++) {
178
+ mix[nRoundsF\2 + r].in[j] <== ark[nRoundsF\2 + r + 1].out[j];
179
+ }
180
+
181
+ }
182
+
183
+ for (var j=0; j<t; j++) {
184
+ sigmaF[nRoundsF-1][j] = Sigma();
185
+ sigmaF[nRoundsF-1][j].in <== mix[nRoundsF-2].out[j];
186
+ }
187
+
188
+ for (var i=0; i<nOuts; i++) {
189
+ mixLast[i] = MixLast(t,M,i);
190
+ for (var j=0; j<t; j++) {
191
+ mixLast[i].in[j] <== sigmaF[nRoundsF-1][j].out;
192
+ }
193
+ out[i] <== mixLast[i].out;
194
+ }
195
+
196
+ }
197
+
198
+ template Poseidon(nInputs) {
199
+ signal input inputs[nInputs];
200
+ signal output out;
201
+
202
+ component pEx = PoseidonEx(nInputs, 1);
203
+ pEx.initialState <== 0;
204
+ for (var i=0; i<nInputs; i++) {
205
+ pEx.inputs[i] <== inputs[i];
206
+ }
207
+ out <== pEx.out[0];
208
+ }