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,112 @@
1
+ // signal input hin[256];
2
+ // signal input inp[512];
3
+ // signal output out[256];
4
+ pragma circom 2.0.0;
5
+
6
+ function rrot(x, n) {
7
+ return ((x >> n) | (x << (32-n))) & 0xFFFFFFFF;
8
+ }
9
+
10
+ function bsigma0(x) {
11
+ return rrot(x,2) ^ rrot(x,13) ^ rrot(x,22);
12
+ }
13
+
14
+ function bsigma1(x) {
15
+ return rrot(x,6) ^ rrot(x,11) ^ rrot(x,25);
16
+ }
17
+
18
+ function ssigma0(x) {
19
+ return rrot(x,7) ^ rrot(x,18) ^ (x >> 3);
20
+ }
21
+
22
+ function ssigma1(x) {
23
+ return rrot(x,17) ^ rrot(x,19) ^ (x >> 10);
24
+ }
25
+
26
+ function Maj(x, y, z) {
27
+ return (x&y) ^ (x&z) ^ (y&z);
28
+ }
29
+
30
+ function Ch(x, y, z) {
31
+ return (x & y) ^ ((0xFFFFFFFF ^x) & z);
32
+ }
33
+
34
+ function sha256K(i) {
35
+ var k[64] = [
36
+ 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
37
+ 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
38
+ 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
39
+ 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
40
+ 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
41
+ 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
42
+ 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
43
+ 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2
44
+ ];
45
+ return k[i];
46
+ }
47
+
48
+ function sha256compression(hin, inp) {
49
+ var H[8];
50
+ var a;
51
+ var b;
52
+ var c;
53
+ var d;
54
+ var e;
55
+ var f;
56
+ var g;
57
+ var h;
58
+ var out[256];
59
+ for (var i=0; i<8; i++) {
60
+ H[i] = 0;
61
+ for (var j=0; j<32; j++) {
62
+ H[i] += hin[i*32+j] << j;
63
+ }
64
+ }
65
+ a=H[0];
66
+ b=H[1];
67
+ c=H[2];
68
+ d=H[3];
69
+ e=H[4];
70
+ f=H[5];
71
+ g=H[6];
72
+ h=H[7];
73
+ var w[64];
74
+ var T1;
75
+ var T2;
76
+ for (var i=0; i<64; i++) {
77
+ if (i<16) {
78
+ w[i]=0;
79
+ for (var j=0; j<32; j++) {
80
+ w[i] += inp[i*32+31-j]<<j;
81
+ }
82
+ } else {
83
+ w[i] = (ssigma1(w[i-2]) + w[i-7] + ssigma0(w[i-15]) + w[i-16]) & 0xFFFFFFFF;
84
+ }
85
+ T1 = (h + bsigma1(e) + Ch(e,f,g) + sha256K(i) + w[i]) & 0xFFFFFFFF;
86
+ T2 = (bsigma0(a) + Maj(a,b,c)) & 0xFFFFFFFF;
87
+
88
+ h=g;
89
+ g=f;
90
+ f=e;
91
+ e=(d+T1) & 0xFFFFFFFF;
92
+ d=c;
93
+ c=b;
94
+ b=a;
95
+ a=(T1+T2) & 0xFFFFFFFF;
96
+
97
+ }
98
+ H[0] = H[0] + a;
99
+ H[1] = H[1] + b;
100
+ H[2] = H[2] + c;
101
+ H[3] = H[3] + d;
102
+ H[4] = H[4] + e;
103
+ H[5] = H[5] + f;
104
+ H[6] = H[6] + g;
105
+ H[7] = H[7] + h;
106
+ for (var i=0; i<8; i++) {
107
+ for (var j=0; j<32; j++) {
108
+ out[i*32+31-j] = (H[i] >> j) & 1;
109
+ }
110
+ }
111
+ return out;
112
+ }
@@ -0,0 +1,33 @@
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 ShR(n, r) {
22
+ signal input in[n];
23
+ signal output out[n];
24
+
25
+ for (var i=0; i<n; i++) {
26
+ if (i+r >= n) {
27
+ out[i] <== 0;
28
+ } else {
29
+ out[i] <== in[ i+r ];
30
+ }
31
+ }
32
+ }
33
+
@@ -0,0 +1,77 @@
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 "xor3.circom";
22
+ include "rotate.circom";
23
+ include "shift.circom";
24
+
25
+ template SmallSigma(ra, rb, rc) {
26
+ signal input in[32];
27
+ signal output out[32];
28
+ var k;
29
+
30
+ component rota = RotR(32, ra);
31
+ component rotb = RotR(32, rb);
32
+ component shrc = ShR(32, rc);
33
+
34
+ for (k=0; k<32; k++) {
35
+ rota.in[k] <== in[k];
36
+ rotb.in[k] <== in[k];
37
+ shrc.in[k] <== in[k];
38
+ }
39
+
40
+ component xor3 = Xor3(32);
41
+ for (k=0; k<32; k++) {
42
+ xor3.a[k] <== rota.out[k];
43
+ xor3.b[k] <== rotb.out[k];
44
+ xor3.c[k] <== shrc.out[k];
45
+ }
46
+
47
+ for (k=0; k<32; k++) {
48
+ out[k] <== xor3.out[k];
49
+ }
50
+ }
51
+
52
+ template BigSigma(ra, rb, rc) {
53
+ signal input in[32];
54
+ signal output out[32];
55
+ var k;
56
+
57
+ component rota = RotR(32, ra);
58
+ component rotb = RotR(32, rb);
59
+ component rotc = RotR(32, rc);
60
+ for (k=0; k<32; k++) {
61
+ rota.in[k] <== in[k];
62
+ rotb.in[k] <== in[k];
63
+ rotc.in[k] <== in[k];
64
+ }
65
+
66
+ component xor3 = Xor3(32);
67
+
68
+ for (k=0; k<32; k++) {
69
+ xor3.a[k] <== rota.out[k];
70
+ xor3.b[k] <== rotb.out[k];
71
+ xor3.c[k] <== rotc.out[k];
72
+ }
73
+
74
+ for (k=0; k<32; k++) {
75
+ out[k] <== xor3.out[k];
76
+ }
77
+ }
@@ -0,0 +1,50 @@
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 "../binsum.circom";
22
+ include "sigma.circom";
23
+
24
+ template SigmaPlus() {
25
+ signal input in2[32];
26
+ signal input in7[32];
27
+ signal input in15[32];
28
+ signal input in16[32];
29
+ signal output out[32];
30
+ var k;
31
+
32
+ component sigma1 = SmallSigma(17,19,10);
33
+ component sigma0 = SmallSigma(7, 18, 3);
34
+ for (k=0; k<32; k++) {
35
+ sigma1.in[k] <== in2[k];
36
+ sigma0.in[k] <== in15[k];
37
+ }
38
+
39
+ component sum = BinSum(32, 4);
40
+ for (k=0; k<32; k++) {
41
+ sum.in[0][k] <== sigma1.out[k];
42
+ sum.in[1][k] <== in7[k];
43
+ sum.in[2][k] <== sigma0.out[k];
44
+ sum.in[3][k] <== in16[k];
45
+ }
46
+
47
+ for (k=0; k<32; k++) {
48
+ out[k] <== sum.out[k];
49
+ }
50
+ }
@@ -0,0 +1,58 @@
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 "../binsum.circom";
22
+ include "sigma.circom";
23
+ include "ch.circom";
24
+
25
+ template T1() {
26
+ signal input h[32];
27
+ signal input e[32];
28
+ signal input f[32];
29
+ signal input g[32];
30
+ signal input k[32];
31
+ signal input w[32];
32
+ signal output out[32];
33
+
34
+ var ki;
35
+
36
+ component ch = Ch_t(32);
37
+ component bigsigma1 = BigSigma(6, 11, 25);
38
+
39
+ for (ki=0; ki<32; ki++) {
40
+ bigsigma1.in[ki] <== e[ki];
41
+ ch.a[ki] <== e[ki];
42
+ ch.b[ki] <== f[ki];
43
+ ch.c[ki] <== g[ki];
44
+ }
45
+
46
+ component sum = BinSum(32, 5);
47
+ for (ki=0; ki<32; ki++) {
48
+ sum.in[0][ki] <== h[ki];
49
+ sum.in[1][ki] <== bigsigma1.out[ki];
50
+ sum.in[2][ki] <== ch.out[ki];
51
+ sum.in[3][ki] <== k[ki];
52
+ sum.in[4][ki] <== w[ki];
53
+ }
54
+
55
+ for (ki=0; ki<32; ki++) {
56
+ out[ki] <== sum.out[ki];
57
+ }
58
+ }
@@ -0,0 +1,51 @@
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 "../binsum.circom";
22
+ include "sigma.circom";
23
+ include "maj.circom";
24
+
25
+ template T2() {
26
+ signal input a[32];
27
+ signal input b[32];
28
+ signal input c[32];
29
+ signal output out[32];
30
+ var k;
31
+
32
+ component bigsigma0 = BigSigma(2, 13, 22);
33
+ component maj = Maj_t(32);
34
+ for (k=0; k<32; k++) {
35
+ bigsigma0.in[k] <== a[k];
36
+ maj.a[k] <== a[k];
37
+ maj.b[k] <== b[k];
38
+ maj.c[k] <== c[k];
39
+ }
40
+
41
+ component sum = BinSum(32, 2);
42
+
43
+ for (k=0; k<32; k++) {
44
+ sum.in[0][k] <== bigsigma0.out[k];
45
+ sum.in[1][k] <== maj.out[k];
46
+ }
47
+
48
+ for (k=0; k<32; k++) {
49
+ out[k] <== sum.out[k];
50
+ }
51
+ }
@@ -0,0 +1,45 @@
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
+ /* Xor3 function for sha256
21
+
22
+ out = a ^ b ^ c =>
23
+
24
+ out = a+b+c - 2*a*b - 2*a*c - 2*b*c + 4*a*b*c =>
25
+
26
+ out = a*( 1 - 2*b - 2*c + 4*b*c ) + b + c - 2*b*c =>
27
+
28
+ mid = b*c
29
+ out = a*( 1 - 2*b -2*c + 4*mid ) + b + c - 2 * mid
30
+
31
+ */
32
+ pragma circom 2.0.0;
33
+
34
+ template Xor3(n) {
35
+ signal input a[n];
36
+ signal input b[n];
37
+ signal input c[n];
38
+ signal output out[n];
39
+ signal mid[n];
40
+
41
+ for (var k=0; k<n; k++) {
42
+ mid[k] <== b[k]*c[k];
43
+ out[k] <== a[k] * (1 -2*b[k] -2*c[k] +4*mid[k]) + b[k] + c[k] -2*mid[k];
44
+ }
45
+ }
@@ -0,0 +1,36 @@
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 "compconstant.circom";
22
+
23
+ template Sign() {
24
+ signal input in[254];
25
+ signal output sign;
26
+
27
+ component comp = CompConstant(10944121435919637611123202872628637544274182200208017171849102093287904247808);
28
+
29
+ var i;
30
+
31
+ for (i=0; i<254; i++) {
32
+ comp.in[i] <== in[i];
33
+ }
34
+
35
+ sign <== comp.out;
36
+ }
@@ -0,0 +1,58 @@
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 "../mimc.circom";
22
+
23
+
24
+ /*
25
+ Hash1 = H(1 | key | value)
26
+ */
27
+
28
+ template SMTHash1() {
29
+ signal input key;
30
+ signal input value;
31
+ signal output out;
32
+
33
+ component h = MultiMiMC7(2, 91); // Constant
34
+ h.in[0] <== key;
35
+ h.in[1] <== value;
36
+ h.k <== 1;
37
+
38
+ out <== h.out;
39
+ }
40
+
41
+ /*
42
+ This component is used to create the 2 nodes.
43
+
44
+ Hash2 = H(Hl | Hr)
45
+ */
46
+
47
+ template SMTHash2() {
48
+ signal input L;
49
+ signal input R;
50
+ signal output out;
51
+
52
+ component h = MultiMiMC7(2, 91); // Constant
53
+ h.in[0] <== L;
54
+ h.in[1] <== R;
55
+ h.k <== 0;
56
+
57
+ out <== h.out;
58
+ }
@@ -0,0 +1,57 @@
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 "../poseidon.circom";
22
+
23
+
24
+ /*
25
+ Hash1 = H(1 | key | value)
26
+ */
27
+
28
+ template SMTHash1() {
29
+ signal input key;
30
+ signal input value;
31
+ signal output out;
32
+
33
+ component h = Poseidon(3); // Constant
34
+ h.inputs[0] <== key;
35
+ h.inputs[1] <== value;
36
+ h.inputs[2] <== 1;
37
+
38
+ out <== h.out;
39
+ }
40
+
41
+ /*
42
+ This component is used to create the 2 nodes.
43
+
44
+ Hash2 = H(Hl | Hr)
45
+ */
46
+
47
+ template SMTHash2() {
48
+ signal input L;
49
+ signal input R;
50
+ signal output out;
51
+
52
+ component h = Poseidon(2); // Constant
53
+ h.inputs[0] <== L;
54
+ h.inputs[1] <== R;
55
+
56
+ out <== h.out;
57
+ }
@@ -0,0 +1,103 @@
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
+
22
+ This component finds the level where the oldInsert is done.
23
+ The rules are:
24
+
25
+ levIns[i] == 1 if its level and all the child levels have a sibling of 0 and
26
+ the parent level has a sibling != 0. Considere that the root level always has
27
+ a parent with a sibling != 0.
28
+
29
+
30
+ ┌──────────────┐
31
+ │ │
32
+ │ │───▶ levIns[0] <== (1-done[i])
33
+ │ │
34
+ └──────────────┘
35
+
36
+
37
+
38
+ done[0]
39
+
40
+
41
+
42
+ done[i-1] <== levIns[i] + done[i]
43
+
44
+
45
+
46
+ ┌───────────┐ ┌──────────────┐
47
+ │ │ │ │
48
+ sibling[i-1]───▶│IsZero[i-1]│─▶│ │───▶ levIns[i] <== (1-done[i])*(1-isZero[i-1].out)
49
+ │ │ │ │
50
+ └───────────┘ └──────────────┘
51
+
52
+
53
+
54
+ done[i]
55
+
56
+
57
+
58
+ done[n-2] <== levIns[n-1]
59
+
60
+
61
+
62
+ ┌───────────┐ ┌──────────────┐
63
+ │ │ │ │
64
+ sibling[n-2]───▶│IsZero[n-2]│─▶│ │────▶ levIns[n-1] <== (1-isZero[n-2].out)
65
+ │ │ │ │
66
+ └───────────┘ └──────────────┘
67
+
68
+ ┌───────────┐
69
+ │ │
70
+ sibling[n-1]───▶│IsZero[n-1]│────▶ === 0
71
+ │ │
72
+ └───────────┘
73
+
74
+ */
75
+ pragma circom 2.0.0;
76
+
77
+ template SMTLevIns(nLevels) {
78
+ signal input enabled;
79
+ signal input siblings[nLevels];
80
+ signal output levIns[nLevels];
81
+ signal done[nLevels-1]; // Indicates if the insLevel has aready been detected.
82
+
83
+ var i;
84
+
85
+ component isZero[nLevels];
86
+
87
+ for (i=0; i<nLevels; i++) {
88
+ isZero[i] = IsZero();
89
+ isZero[i].in <== siblings[i];
90
+ }
91
+
92
+ // The last level must always have a sibling of 0. If not, then it cannot be inserted.
93
+ (isZero[nLevels-1].out - 1) * enabled === 0;
94
+
95
+ levIns[nLevels-1] <== (1-isZero[nLevels-2].out);
96
+ done[nLevels-2] <== levIns[nLevels-1];
97
+ for (i=nLevels-2; i>0; i--) {
98
+ levIns[i] <== (1-done[i])*(1-isZero[i-1].out);
99
+ done[i-1] <== levIns[i] + done[i];
100
+ }
101
+
102
+ levIns[0] <== (1-done[0]);
103
+ }