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,115 @@
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
+
20
+ /*
21
+ Copyright 2018 0KIMS association.
22
+
23
+ This file is part of circom (Zero Knowledge Circuit Compiler).
24
+
25
+ circom is a free software: you can redistribute it and/or modify it
26
+ under the terms of the GNU General Public License as published by
27
+ the Free Software Foundation, either version 3 of the License, or
28
+ (at your option) any later version.
29
+
30
+ circom is distributed in the hope that it will be useful, but WITHOUT
31
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
32
+ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
33
+ License for more details.
34
+
35
+ You should have received a copy of the GNU General Public License
36
+ along with circom. If not, see <https://www.gnu.org/licenses/>.
37
+ */
38
+
39
+ // --> Assignation without constraint
40
+ // <-- Assignation without constraint
41
+ // === Constraint
42
+ // <== Assignation with constraint
43
+ // ==> Assignation with constraint
44
+ // All variables are members of the field F[p]
45
+ // https://github.com/zcash-hackworks/sapling-crypto
46
+ // https://github.com/ebfull/bellman
47
+
48
+ /*
49
+ function log2(a) {
50
+ if (a==0) {
51
+ return 0;
52
+ }
53
+ let n = 1;
54
+ let r = 1;
55
+ while (n<a) {
56
+ r++;
57
+ n *= 2;
58
+ }
59
+ return r;
60
+ }
61
+ */
62
+
63
+ pragma circom 2.0.0;
64
+
65
+ template EscalarProduct(w) {
66
+ signal input in1[w];
67
+ signal input in2[w];
68
+ signal output out;
69
+ signal aux[w];
70
+ var lc = 0;
71
+ for (var i=0; i<w; i++) {
72
+ aux[i] <== in1[i]*in2[i];
73
+ lc = lc + aux[i];
74
+ }
75
+ out <== lc;
76
+ }
77
+
78
+ template Decoder(w) {
79
+ signal input inp;
80
+ signal output out[w];
81
+ signal output success;
82
+ var lc=0;
83
+
84
+ for (var i=0; i<w; i++) {
85
+ out[i] <-- (inp == i) ? 1 : 0;
86
+ out[i] * (inp-i) === 0;
87
+ lc = lc + out[i];
88
+ }
89
+
90
+ lc ==> success;
91
+ success * (success -1) === 0;
92
+ }
93
+
94
+
95
+ template Multiplexer(wIn, nIn) {
96
+ signal input inp[nIn][wIn];
97
+ signal input sel;
98
+ signal output out[wIn];
99
+ component dec = Decoder(nIn);
100
+ component ep[wIn];
101
+
102
+ for (var k=0; k<wIn; k++) {
103
+ ep[k] = EscalarProduct(nIn);
104
+ }
105
+
106
+ sel ==> dec.inp;
107
+ for (var j=0; j<wIn; j++) {
108
+ for (var k=0; k<nIn; k++) {
109
+ inp[k][j] ==> ep[j].in1[k];
110
+ dec.out[k] ==> ep[j].in2[k];
111
+ }
112
+ ep[j].out ==> out[j];
113
+ }
114
+ dec.success === 1;
115
+ }
@@ -0,0 +1,48 @@
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
+ template MultiMux1(n) {
22
+ signal input c[n][2]; // Constants
23
+ signal input s; // Selector
24
+ signal output out[n];
25
+
26
+ for (var i=0; i<n; i++) {
27
+
28
+ out[i] <== (c[i][1] - c[i][0])*s + c[i][0];
29
+
30
+ }
31
+ }
32
+
33
+ template Mux1() {
34
+ var i;
35
+ signal input c[2]; // Constants
36
+ signal input s; // Selector
37
+ signal output out;
38
+
39
+ component mux = MultiMux1(1);
40
+
41
+ for (i=0; i<2; i++) {
42
+ mux.c[0][i] <== c[i];
43
+ }
44
+
45
+ s ==> mux.s;
46
+
47
+ mux.out[0] ==> out;
48
+ }
@@ -0,0 +1,63 @@
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
+ template MultiMux2(n) {
22
+ signal input c[n][4]; // Constants
23
+ signal input s[2]; // Selector
24
+ signal output out[n];
25
+
26
+ signal a10[n];
27
+ signal a1[n];
28
+ signal a0[n];
29
+ signal a[n];
30
+
31
+ signal s10;
32
+ s10 <== s[1] * s[0];
33
+
34
+ for (var i=0; i<n; i++) {
35
+
36
+ a10[i] <== ( c[i][ 3]-c[i][ 2]-c[i][ 1]+c[i][ 0] ) * s10;
37
+ a1[i] <== ( c[i][ 2]-c[i][ 0] ) * s[1];
38
+ a0[i] <== ( c[i][ 1]-c[i][ 0] ) * s[0];
39
+ a[i] <== ( c[i][ 0] );
40
+
41
+ out[i] <== ( a10[i] + a1[i] + a0[i] + a[i] );
42
+
43
+ }
44
+ }
45
+
46
+ template Mux2() {
47
+ var i;
48
+ signal input c[4]; // Constants
49
+ signal input s[2]; // Selector
50
+ signal output out;
51
+
52
+ component mux = MultiMux2(1);
53
+
54
+ for (i=0; i<4; i++) {
55
+ mux.c[0][i] <== c[i];
56
+ }
57
+
58
+ for (i=0; i<2; i++) {
59
+ s[i] ==> mux.s[i];
60
+ }
61
+
62
+ mux.out[0] ==> out;
63
+ }
@@ -0,0 +1,75 @@
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
+ template MultiMux3(n) {
22
+ signal input c[n][8]; // Constants
23
+ signal input s[3]; // Selector
24
+ signal output out[n];
25
+
26
+ signal a210[n];
27
+ signal a21[n];
28
+ signal a20[n];
29
+ signal a2[n];
30
+
31
+ signal a10[n];
32
+ signal a1[n];
33
+ signal a0[n];
34
+ signal a[n];
35
+
36
+ // 4 constrains for the intermediary variables
37
+ signal s10;
38
+ s10 <== s[1] * s[0];
39
+
40
+ for (var i=0; i<n; i++) {
41
+
42
+ a210[i] <== ( c[i][ 7]-c[i][ 6]-c[i][ 5]+c[i][ 4] - c[i][ 3]+c[i][ 2]+c[i][ 1]-c[i][ 0] ) * s10;
43
+ a21[i] <== ( c[i][ 6]-c[i][ 4]-c[i][ 2]+c[i][ 0] ) * s[1];
44
+ a20[i] <== ( c[i][ 5]-c[i][ 4]-c[i][ 1]+c[i][ 0] ) * s[0];
45
+ a2[i] <== ( c[i][ 4]-c[i][ 0] );
46
+
47
+ a10[i] <== ( c[i][ 3]-c[i][ 2]-c[i][ 1]+c[i][ 0] ) * s10;
48
+ a1[i] <== ( c[i][ 2]-c[i][ 0] ) * s[1];
49
+ a0[i] <== ( c[i][ 1]-c[i][ 0] ) * s[0];
50
+ a[i] <== ( c[i][ 0] );
51
+
52
+ out[i] <== ( a210[i] + a21[i] + a20[i] + a2[i] ) * s[2] +
53
+ ( a10[i] + a1[i] + a0[i] + a[i] );
54
+
55
+ }
56
+ }
57
+
58
+ template Mux3() {
59
+ var i;
60
+ signal input c[8]; // Constants
61
+ signal input s[3]; // Selector
62
+ signal output out;
63
+
64
+ component mux = MultiMux3(1);
65
+
66
+ for (i=0; i<8; i++) {
67
+ mux.c[0][i] <== c[i];
68
+ }
69
+
70
+ for (i=0; i<3; i++) {
71
+ s[i] ==> mux.s[i];
72
+ }
73
+
74
+ mux.out[0] ==> out;
75
+ }
@@ -0,0 +1,119 @@
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
+ template MultiMux4(n) {
22
+ signal input c[n][16]; // Constants
23
+ signal input s[4]; // Selector
24
+ signal output out[n];
25
+
26
+ signal a3210[n];
27
+ signal a321[n];
28
+ signal a320[n];
29
+ signal a310[n];
30
+ signal a32[n];
31
+ signal a31[n];
32
+ signal a30[n];
33
+ signal a3[n];
34
+
35
+ signal a210[n];
36
+ signal a21[n];
37
+ signal a20[n];
38
+ signal a10[n];
39
+ signal a2[n];
40
+ signal a1[n];
41
+ signal a0[n];
42
+ signal a[n];
43
+
44
+ // 4 constrains for the intermediary variables
45
+ signal s10;
46
+ s10 <== s[1] * s[0];
47
+ signal s20;
48
+ s20 <== s[2] * s[0];
49
+ signal s21;
50
+ s21 <== s[2] * s[1];
51
+ signal s210;
52
+ s210 <== s21 * s[0];
53
+
54
+
55
+ for (var i=0; i<n; i++) {
56
+
57
+ a3210[i] <== ( c[i][15]-c[i][14]-c[i][13]+c[i][12] - c[i][11]+c[i][10]+c[i][ 9]-c[i][ 8]
58
+ -c[i][ 7]+c[i][ 6]+c[i][ 5]-c[i][ 4] + c[i][ 3]-c[i][ 2]-c[i][ 1]+c[i][ 0] ) * s210;
59
+ a321[i] <== ( c[i][14]-c[i][12]-c[i][10]+c[i][ 8] - c[i][ 6]+c[i][ 4]+c[i][ 2]-c[i][ 0] ) * s21;
60
+ a320[i] <== ( c[i][13]-c[i][12]-c[i][ 9]+c[i][ 8] - c[i][ 5]+c[i][ 4]+c[i][ 1]-c[i][ 0] ) * s20;
61
+ a310[i] <== ( c[i][11]-c[i][10]-c[i][ 9]+c[i][ 8] - c[i][ 3]+c[i][ 2]+c[i][ 1]-c[i][ 0] ) * s10;
62
+ a32[i] <== ( c[i][12]-c[i][ 8]-c[i][ 4]+c[i][ 0] ) * s[2];
63
+ a31[i] <== ( c[i][10]-c[i][ 8]-c[i][ 2]+c[i][ 0] ) * s[1];
64
+ a30[i] <== ( c[i][ 9]-c[i][ 8]-c[i][ 1]+c[i][ 0] ) * s[0];
65
+ a3[i] <== ( c[i][ 8]-c[i][ 0] );
66
+
67
+ a210[i] <== ( c[i][ 7]-c[i][ 6]-c[i][ 5]+c[i][ 4] - c[i][ 3]+c[i][ 2]+c[i][ 1]-c[i][ 0] ) * s210;
68
+ a21[i] <== ( c[i][ 6]-c[i][ 4]-c[i][ 2]+c[i][ 0] ) * s21;
69
+ a20[i] <== ( c[i][ 5]-c[i][ 4]-c[i][ 1]+c[i][ 0] ) * s20;
70
+ a10[i] <== ( c[i][ 3]-c[i][ 2]-c[i][ 1]+c[i][ 0] ) * s10;
71
+ a2[i] <== ( c[i][ 4]-c[i][ 0] ) * s[2];
72
+ a1[i] <== ( c[i][ 2]-c[i][ 0] ) * s[1];
73
+ a0[i] <== ( c[i][ 1]-c[i][ 0] ) * s[0];
74
+ a[i] <== ( c[i][ 0] );
75
+
76
+ out[i] <== ( a3210[i] + a321[i] + a320[i] + a310[i] + a32[i] + a31[i] + a30[i] + a3[i] ) * s[3] +
77
+ ( a210[i] + a21[i] + a20[i] + a10[i] + a2[i] + a1[i] + a0[i] + a[i] );
78
+
79
+ /*
80
+ out[i] <== ( s210 * ( c[i][15]-c[i][14]-c[i][13]+c[i][12] - c[i][11]+c[i][10]+c[i][ 9]-c[i][ 8]
81
+ -c[i][ 7]+c[i][ 6]+c[i][ 5]-c[i][ 4] + c[i][ 3]-c[i][ 2]-c[i][ 1]+c[i][ 0] ) +
82
+ s21 * ( c[i][14]-c[i][12]-c[i][10]+c[i][ 8] - c[i][ 6]+c[i][ 4]+c[i][ 2]-c[i][ 0] ) +
83
+ s20 * ( c[i][13]-c[i][12]-c[i][ 9]+c[i][ 8] - c[i][ 5]+c[i][ 4]+c[i][ 1]-c[i][ 0] ) +
84
+ s10 * ( c[i][11]-c[i][10]-c[i][ 9]+c[i][ 8] - c[i][ 3]+c[i][ 2]+c[i][ 1]-c[i][ 0] ) +
85
+ s[2] * ( c[i][12]-c[i][ 8]-c[i][ 4]+c[i][ 0] ) +
86
+ s[1] * ( c[i][10]-c[i][ 8]-c[i][ 2]+c[i][ 0] ) +
87
+ s[0] * ( c[i][ 9]-c[i][ 8]-c[i][ 1]+c[i][ 0] ) +
88
+ ( c[i][ 8]-c[i][ 0] ) ) * s[3] +
89
+ ( s210 * ( c[i][ 7]-c[i][ 6]-c[i][ 5]+c[i][ 4] - c[i][ 3]+c[i][ 2]+c[i][ 1]-c[i][ 0] ) +
90
+ s21 * ( c[i][ 6]-c[i][ 4]-c[i][ 2]+c[i][ 0] ) +
91
+ s20 * ( c[i][ 5]-c[i][ 4]-c[i][ 1]+c[i][ 0] ) +
92
+ s10 * ( c[i][ 3]-c[i][ 2]-c[i][ 1]+c[i][ 0] ) +
93
+ s[2] * ( c[i][ 4]-c[i][ 0] ) +
94
+ s[1] * ( c[i][ 2]-c[i][ 0] ) +
95
+ s[0] * ( c[i][ 1]-c[i][ 0] ) +
96
+ ( c[i][ 0] ));
97
+
98
+ */
99
+ }
100
+ }
101
+
102
+ template Mux4() {
103
+ var i;
104
+ signal input c[16]; // Constants
105
+ signal input s[4]; // Selector
106
+ signal output out;
107
+
108
+ component mux = MultiMux4(1);
109
+
110
+ for (i=0; i<16; i++) {
111
+ mux.c[0][i] <== c[i];
112
+ }
113
+
114
+ for (i=0; i<4; i++) {
115
+ s[i] ==> mux.s[i];
116
+ }
117
+
118
+ mux.out[0] ==> out;
119
+ }
@@ -0,0 +1,257 @@
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 "montgomery.circom";
22
+ include "mux3.circom";
23
+ include "babyjub.circom";
24
+
25
+ template Window4() {
26
+ signal input in[4];
27
+ signal input base[2];
28
+ signal output out[2];
29
+ signal output out8[2]; // Returns 8*Base (To be linked)
30
+
31
+ component mux = MultiMux3(2);
32
+
33
+ mux.s[0] <== in[0];
34
+ mux.s[1] <== in[1];
35
+ mux.s[2] <== in[2];
36
+
37
+ component dbl2 = MontgomeryDouble();
38
+ component adr3 = MontgomeryAdd();
39
+ component adr4 = MontgomeryAdd();
40
+ component adr5 = MontgomeryAdd();
41
+ component adr6 = MontgomeryAdd();
42
+ component adr7 = MontgomeryAdd();
43
+ component adr8 = MontgomeryAdd();
44
+
45
+ // in[0] -> 1*BASE
46
+
47
+ mux.c[0][0] <== base[0];
48
+ mux.c[1][0] <== base[1];
49
+
50
+ // in[1] -> 2*BASE
51
+ dbl2.in[0] <== base[0];
52
+ dbl2.in[1] <== base[1];
53
+ mux.c[0][1] <== dbl2.out[0];
54
+ mux.c[1][1] <== dbl2.out[1];
55
+
56
+ // in[2] -> 3*BASE
57
+ adr3.in1[0] <== base[0];
58
+ adr3.in1[1] <== base[1];
59
+ adr3.in2[0] <== dbl2.out[0];
60
+ adr3.in2[1] <== dbl2.out[1];
61
+ mux.c[0][2] <== adr3.out[0];
62
+ mux.c[1][2] <== adr3.out[1];
63
+
64
+ // in[3] -> 4*BASE
65
+ adr4.in1[0] <== base[0];
66
+ adr4.in1[1] <== base[1];
67
+ adr4.in2[0] <== adr3.out[0];
68
+ adr4.in2[1] <== adr3.out[1];
69
+ mux.c[0][3] <== adr4.out[0];
70
+ mux.c[1][3] <== adr4.out[1];
71
+
72
+ // in[4] -> 5*BASE
73
+ adr5.in1[0] <== base[0];
74
+ adr5.in1[1] <== base[1];
75
+ adr5.in2[0] <== adr4.out[0];
76
+ adr5.in2[1] <== adr4.out[1];
77
+ mux.c[0][4] <== adr5.out[0];
78
+ mux.c[1][4] <== adr5.out[1];
79
+
80
+ // in[5] -> 6*BASE
81
+ adr6.in1[0] <== base[0];
82
+ adr6.in1[1] <== base[1];
83
+ adr6.in2[0] <== adr5.out[0];
84
+ adr6.in2[1] <== adr5.out[1];
85
+ mux.c[0][5] <== adr6.out[0];
86
+ mux.c[1][5] <== adr6.out[1];
87
+
88
+ // in[6] -> 7*BASE
89
+ adr7.in1[0] <== base[0];
90
+ adr7.in1[1] <== base[1];
91
+ adr7.in2[0] <== adr6.out[0];
92
+ adr7.in2[1] <== adr6.out[1];
93
+ mux.c[0][6] <== adr7.out[0];
94
+ mux.c[1][6] <== adr7.out[1];
95
+
96
+ // in[7] -> 8*BASE
97
+ adr8.in1[0] <== base[0];
98
+ adr8.in1[1] <== base[1];
99
+ adr8.in2[0] <== adr7.out[0];
100
+ adr8.in2[1] <== adr7.out[1];
101
+ mux.c[0][7] <== adr8.out[0];
102
+ mux.c[1][7] <== adr8.out[1];
103
+
104
+ out8[0] <== adr8.out[0];
105
+ out8[1] <== adr8.out[1];
106
+
107
+ out[0] <== mux.out[0];
108
+ out[1] <== - mux.out[1]*2*in[3] + mux.out[1]; // Negate y if in[3] is one
109
+ }
110
+
111
+
112
+ template Segment(nWindows) {
113
+ signal input in[nWindows*4];
114
+ signal input base[2];
115
+ signal output out[2];
116
+
117
+ var i;
118
+ var j;
119
+
120
+ // Convert the base to montgomery
121
+
122
+ component e2m = Edwards2Montgomery();
123
+ e2m.in[0] <== base[0];
124
+ e2m.in[1] <== base[1];
125
+
126
+ component windows[nWindows];
127
+ component doublers1[nWindows-1];
128
+ component doublers2[nWindows-1];
129
+ component adders[nWindows-1];
130
+ for (i=0; i<nWindows; i++) {
131
+ windows[i] = Window4();
132
+ for (j=0; j<4; j++) {
133
+ windows[i].in[j] <== in[4*i+j];
134
+ }
135
+ if (i==0) {
136
+ windows[i].base[0] <== e2m.out[0];
137
+ windows[i].base[1] <== e2m.out[1];
138
+ } else {
139
+ doublers1[i-1] = MontgomeryDouble();
140
+ doublers2[i-1] = MontgomeryDouble();
141
+ doublers1[i-1].in[0] <== windows[i-1].out8[0];
142
+ doublers1[i-1].in[1] <== windows[i-1].out8[1];
143
+ doublers2[i-1].in[0] <== doublers1[i-1].out[0];
144
+ doublers2[i-1].in[1] <== doublers1[i-1].out[1];
145
+
146
+ windows[i].base[0] <== doublers2[i-1].out[0];
147
+ windows[i].base[1] <== doublers2[i-1].out[1];
148
+
149
+ adders[i-1] = MontgomeryAdd();
150
+ if (i==1) {
151
+ adders[i-1].in1[0] <== windows[0].out[0];
152
+ adders[i-1].in1[1] <== windows[0].out[1];
153
+ } else {
154
+ adders[i-1].in1[0] <== adders[i-2].out[0];
155
+ adders[i-1].in1[1] <== adders[i-2].out[1];
156
+ }
157
+ adders[i-1].in2[0] <== windows[i].out[0];
158
+ adders[i-1].in2[1] <== windows[i].out[1];
159
+ }
160
+ }
161
+
162
+ component m2e = Montgomery2Edwards();
163
+
164
+ if (nWindows > 1) {
165
+ m2e.in[0] <== adders[nWindows-2].out[0];
166
+ m2e.in[1] <== adders[nWindows-2].out[1];
167
+ } else {
168
+ m2e.in[0] <== windows[0].out[0];
169
+ m2e.in[1] <== windows[0].out[1];
170
+ }
171
+
172
+ out[0] <== m2e.out[0];
173
+ out[1] <== m2e.out[1];
174
+ }
175
+
176
+ template Pedersen(n) {
177
+ signal input in[n];
178
+ signal output out[2];
179
+
180
+ var BASE[10][2] = [
181
+ [10457101036533406547632367118273992217979173478358440826365724437999023779287,19824078218392094440610104313265183977899662750282163392862422243483260492317],
182
+ [2671756056509184035029146175565761955751135805354291559563293617232983272177,2663205510731142763556352975002641716101654201788071096152948830924149045094],
183
+ [5802099305472655231388284418920769829666717045250560929368476121199858275951,5980429700218124965372158798884772646841287887664001482443826541541529227896],
184
+ [7107336197374528537877327281242680114152313102022415488494307685842428166594,2857869773864086953506483169737724679646433914307247183624878062391496185654],
185
+ [20265828622013100949498132415626198973119240347465898028410217039057588424236,1160461593266035632937973507065134938065359936056410650153315956301179689506],
186
+ [1487999857809287756929114517587739322941449154962237464737694709326309567994,14017256862867289575056460215526364897734808720610101650676790868051368668003],
187
+ [14618644331049802168996997831720384953259095788558646464435263343433563860015,13115243279999696210147231297848654998887864576952244320558158620692603342236],
188
+ [6814338563135591367010655964669793483652536871717891893032616415581401894627,13660303521961041205824633772157003587453809761793065294055279768121314853695],
189
+ [3571615583211663069428808372184817973703476260057504149923239576077102575715,11981351099832644138306422070127357074117642951423551606012551622164230222506],
190
+ [18597552580465440374022635246985743886550544261632147935254624835147509493269,6753322320275422086923032033899357299485124665258735666995435957890214041481]
191
+
192
+ ];
193
+
194
+ var nSegments = ((n-1)\200)+1;
195
+
196
+ component segments[nSegments];
197
+
198
+ var i;
199
+ var j;
200
+ var nBits;
201
+ var nWindows;
202
+ for (i=0; i<nSegments; i++) {
203
+ nBits = (i == (nSegments-1)) ? n - (nSegments-1)*200 : 200;
204
+ nWindows = ((nBits - 1)\4)+1;
205
+ segments[i] = Segment(nWindows);
206
+ segments[i].base[0] <== BASE[i][0];
207
+ segments[i].base[1] <== BASE[i][1];
208
+ for (j = 0; j<nBits; j++) {
209
+ segments[i].in[j] <== in[i*200+j];
210
+ }
211
+ // Fill padding bits
212
+ for (j = nBits; j < nWindows*4; j++) {
213
+ segments[i].in[j] <== 0;
214
+ }
215
+ }
216
+
217
+ component adders[nSegments-1];
218
+
219
+ for (i=0; i<nSegments-1; i++) {
220
+ adders[i] = BabyAdd();
221
+ if (i==0) {
222
+ adders[i].x1 <== segments[0].out[0];
223
+ adders[i].y1 <== segments[0].out[1];
224
+ adders[i].x2 <== segments[1].out[0];
225
+ adders[i].y2 <== segments[1].out[1];
226
+ } else {
227
+ adders[i].x1 <== adders[i-1].xout;
228
+ adders[i].y1 <== adders[i-1].yout;
229
+ adders[i].x2 <== segments[i+1].out[0];
230
+ adders[i].y2 <== segments[i+1].out[1];
231
+ }
232
+ }
233
+
234
+ /*
235
+ coponent packPoint = PackPoint();
236
+
237
+ if (nSegments>1) {
238
+ packPoint.in[0] <== adders[nSegments-2].xout;
239
+ packPoint.in[1] <== adders[nSegments-2].yout;
240
+ } else {
241
+ packPoint.in[0] <== segments[0].out[0];
242
+ packPoint.in[1] <== segments[0].out[1];
243
+ }
244
+
245
+ out[0] <== packPoint.out[0];
246
+ out[1] <== packPoint.out[1];
247
+ */
248
+
249
+ if (nSegments>1) {
250
+ out[0] <== adders[nSegments-2].xout;
251
+ out[1] <== adders[nSegments-2].yout;
252
+ } else {
253
+ out[0] <== segments[0].out[0];
254
+ out[1] <== segments[0].out[1];
255
+ }
256
+ }
257
+