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.
- package/README.md +101 -0
- package/bin/circom +0 -0
- package/bin/cli.js +36 -0
- package/bin/index.js +13 -0
- package/circomlib/.vscode/launch.json +63 -0
- package/circomlib/README.md +18 -0
- package/circomlib/circuits/README.md +830 -0
- package/circomlib/circuits/aliascheck.circom +33 -0
- package/circomlib/circuits/babyjub.circom +107 -0
- package/circomlib/circuits/binsub.circom +74 -0
- package/circomlib/circuits/binsum.circom +101 -0
- package/circomlib/circuits/bitify.circom +106 -0
- package/circomlib/circuits/comparators.circom +141 -0
- package/circomlib/circuits/compconstant.circom +74 -0
- package/circomlib/circuits/eddsa.circom +139 -0
- package/circomlib/circuits/eddsamimc.circom +124 -0
- package/circomlib/circuits/eddsamimcsponge.circom +124 -0
- package/circomlib/circuits/eddsaposeidon.circom +123 -0
- package/circomlib/circuits/escalarmul.circom +166 -0
- package/circomlib/circuits/escalarmulany.circom +197 -0
- package/circomlib/circuits/escalarmulfix.circom +299 -0
- package/circomlib/circuits/escalarmulw4table.circom +52 -0
- package/circomlib/circuits/gates.circom +96 -0
- package/circomlib/circuits/mimc.circom +156 -0
- package/circomlib/circuits/mimcsponge.circom +293 -0
- package/circomlib/circuits/montgomery.circom +142 -0
- package/circomlib/circuits/multiplexer.circom +115 -0
- package/circomlib/circuits/mux1.circom +48 -0
- package/circomlib/circuits/mux2.circom +63 -0
- package/circomlib/circuits/mux3.circom +75 -0
- package/circomlib/circuits/mux4.circom +119 -0
- package/circomlib/circuits/pedersen.circom +257 -0
- package/circomlib/circuits/pedersen_old.circom +68 -0
- package/circomlib/circuits/pointbits.circom +164 -0
- package/circomlib/circuits/poseidon.circom +208 -0
- package/circomlib/circuits/poseidon_constants.circom +24959 -0
- package/circomlib/circuits/poseidon_constants_old.circom +252 -0
- package/circomlib/circuits/poseidon_old.circom +97 -0
- package/circomlib/circuits/sha256/ch.circom +47 -0
- package/circomlib/circuits/sha256/constants.circom +53 -0
- package/circomlib/circuits/sha256/main.circom +35 -0
- package/circomlib/circuits/sha256/maj.circom +45 -0
- package/circomlib/circuits/sha256/rotate.circom +28 -0
- package/circomlib/circuits/sha256/sha256.circom +81 -0
- package/circomlib/circuits/sha256/sha256_2.circom +91 -0
- package/circomlib/circuits/sha256/sha256compression.circom +166 -0
- package/circomlib/circuits/sha256/sha256compression_function.circom +112 -0
- package/circomlib/circuits/sha256/shift.circom +33 -0
- package/circomlib/circuits/sha256/sigma.circom +77 -0
- package/circomlib/circuits/sha256/sigmaplus.circom +50 -0
- package/circomlib/circuits/sha256/t1.circom +58 -0
- package/circomlib/circuits/sha256/t2.circom +51 -0
- package/circomlib/circuits/sha256/xor3.circom +45 -0
- package/circomlib/circuits/sign.circom +36 -0
- package/circomlib/circuits/smt/smthash_mimc.circom +58 -0
- package/circomlib/circuits/smt/smthash_poseidon.circom +57 -0
- package/circomlib/circuits/smt/smtlevins.circom +103 -0
- package/circomlib/circuits/smt/smtprocessor.circom +261 -0
- package/circomlib/circuits/smt/smtprocessorlevel.circom +95 -0
- package/circomlib/circuits/smt/smtprocessorsm.circom +165 -0
- package/circomlib/circuits/smt/smtverifier.circom +138 -0
- package/circomlib/circuits/smt/smtverifierlevel.circom +71 -0
- package/circomlib/circuits/smt/smtverifiersm.circom +106 -0
- package/circomlib/circuits/switcher.circom +42 -0
- package/circomlib/doc/root_transfer.monopic +0 -0
- package/circomlib/doc/smt_diagram_0.monopic +0 -0
- package/circomlib/doc/smt_diagram_1.monopic +0 -0
- package/circomlib/doc/smt_hash.monopic +0 -0
- package/circomlib/doc/smt_levins.monopic +0 -0
- package/circomlib/doc/smt_sm.monopic +0 -0
- package/circomlib/doc/smt_verifier_sm.monopic +0 -0
- package/circomlib/doc/voting.monopic +0 -0
- package/circomlib/doc/window.monopic +0 -0
- package/circomlib/doc/window_chain.monopic +0 -0
- package/circomlib/index.js +2 -0
- package/circomlib/package.json +33 -0
- package/circomlib/test/aliascheck.js +77 -0
- package/circomlib/test/babyjub.js +118 -0
- package/circomlib/test/binsub.js +52 -0
- package/circomlib/test/binsum.js +38 -0
- package/circomlib/test/circuits/aliascheck_test.circom +4 -0
- package/circomlib/test/circuits/babyadd_tester.circom +4 -0
- package/circomlib/test/circuits/babycheck_test.circom +4 -0
- package/circomlib/test/circuits/babypbk_test.circom +4 -0
- package/circomlib/test/circuits/binsub_test.circom +33 -0
- package/circomlib/test/circuits/constants_test.circom +20 -0
- package/circomlib/test/circuits/eddsa_test.circom +5 -0
- package/circomlib/test/circuits/eddsamimc_test.circom +5 -0
- package/circomlib/test/circuits/eddsaposeidon_test.circom +5 -0
- package/circomlib/test/circuits/edwards2montgomery.circom +5 -0
- package/circomlib/test/circuits/escalarmul_min_test.circom +27 -0
- package/circomlib/test/circuits/escalarmul_test.circom +33 -0
- package/circomlib/test/circuits/escalarmul_test_min.circom +28 -0
- package/circomlib/test/circuits/escalarmulany_test.circom +30 -0
- package/circomlib/test/circuits/escalarmulfix_test.circom +31 -0
- package/circomlib/test/circuits/escalarmulw4table.circom +20 -0
- package/circomlib/test/circuits/escalarmulw4table_test.circom +19 -0
- package/circomlib/test/circuits/escalarmulw4table_test3.circom +19 -0
- package/circomlib/test/circuits/greatereqthan.circom +5 -0
- package/circomlib/test/circuits/greaterthan.circom +5 -0
- package/circomlib/test/circuits/isequal.circom +5 -0
- package/circomlib/test/circuits/iszero.circom +5 -0
- package/circomlib/test/circuits/lesseqthan.circom +5 -0
- package/circomlib/test/circuits/lessthan.circom +5 -0
- package/circomlib/test/circuits/mimc_sponge_hash_test.circom +5 -0
- package/circomlib/test/circuits/mimc_sponge_test.circom +5 -0
- package/circomlib/test/circuits/mimc_test.circom +5 -0
- package/circomlib/test/circuits/montgomery2edwards.circom +5 -0
- package/circomlib/test/circuits/montgomeryadd.circom +5 -0
- package/circomlib/test/circuits/montgomerydouble.circom +5 -0
- package/circomlib/test/circuits/mux1_1.circom +33 -0
- package/circomlib/test/circuits/mux2_1.circom +37 -0
- package/circomlib/test/circuits/mux3_1.circom +41 -0
- package/circomlib/test/circuits/mux4_1.circom +56 -0
- package/circomlib/test/circuits/pedersen2_test.circom +34 -0
- package/circomlib/test/circuits/pedersen_test.circom +31 -0
- package/circomlib/test/circuits/pointbits_loopback.circom +25 -0
- package/circomlib/test/circuits/poseidon3_test.circom +5 -0
- package/circomlib/test/circuits/poseidon6_test.circom +5 -0
- package/circomlib/test/circuits/poseidonex_test.circom +5 -0
- package/circomlib/test/circuits/sha256_2_test.circom +17 -0
- package/circomlib/test/circuits/sha256_test448.circom +5 -0
- package/circomlib/test/circuits/sha256_test512.circom +5 -0
- package/circomlib/test/circuits/sign_test.circom +5 -0
- package/circomlib/test/circuits/smtprocessor10_test.circom +5 -0
- package/circomlib/test/circuits/smtverifier10_test.circom +5 -0
- package/circomlib/test/circuits/sum_test.circom +33 -0
- package/circomlib/test/comparators.js +187 -0
- package/circomlib/test/eddsa.js +75 -0
- package/circomlib/test/eddsamimc.js +102 -0
- package/circomlib/test/eddsaposeidon.js +103 -0
- package/circomlib/test/escalarmul.js +121 -0
- package/circomlib/test/escalarmulany.js +51 -0
- package/circomlib/test/escalarmulfix.js +95 -0
- package/circomlib/test/helpers/printsignal.js +22 -0
- package/circomlib/test/helpers/sha256.js +178 -0
- package/circomlib/test/mimccircuit.js +27 -0
- package/circomlib/test/mimcspongecircuit.js +47 -0
- package/circomlib/test/montgomery.js +101 -0
- package/circomlib/test/multiplexer.js +101 -0
- package/circomlib/test/pedersen.js +83 -0
- package/circomlib/test/pedersen2.js +56 -0
- package/circomlib/test/point2bits.js +30 -0
- package/circomlib/test/poseidoncircuit.js +80 -0
- package/circomlib/test/sha256.js +118 -0
- package/circomlib/test/sign.js +82 -0
- package/circomlib/test/smtprocessor.js +219 -0
- package/circomlib/test/smtverifier.js +141 -0
- package/lib/compile.js +82 -0
- package/lib/deploy.js +391 -0
- package/lib/test.js +47 -0
- package/lib/verify.js +153 -0
- package/package.json +43 -0
- package/pot12_0000.ptau +0 -0
- package/pot12_0001.ptau +0 -0
- package/ptau/pot12_final.ptau +0 -0
|
@@ -0,0 +1,97 @@
|
|
|
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[i][j]*in[j];
|
|
36
|
+
}
|
|
37
|
+
out[i] <== lc;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
template Poseidon(nInputs) {
|
|
42
|
+
signal input inputs[nInputs];
|
|
43
|
+
signal output out;
|
|
44
|
+
|
|
45
|
+
// Using recommended parameters from whitepaper https://eprint.iacr.org/2019/458.pdf (table 2, table 8)
|
|
46
|
+
// Generated by https://extgit.iaik.tugraz.at/krypto/hadeshash/-/blob/master/code/calc_round_numbers.py
|
|
47
|
+
// And rounded up to nearest integer that divides by t
|
|
48
|
+
var N_ROUNDS_P[16] = [56, 57, 56, 60, 60, 63, 64, 63, 60, 66, 60, 65, 70, 60, 64, 68];
|
|
49
|
+
var t = nInputs + 1;
|
|
50
|
+
var nRoundsF = 8;
|
|
51
|
+
var nRoundsP = N_ROUNDS_P[t - 2];
|
|
52
|
+
var C[t*(nRoundsF + nRoundsP)] = POSEIDON_C(t);
|
|
53
|
+
var M[t][t] = POSEIDON_M(t);
|
|
54
|
+
|
|
55
|
+
component ark[nRoundsF + nRoundsP];
|
|
56
|
+
component sigmaF[nRoundsF][t];
|
|
57
|
+
component sigmaP[nRoundsP];
|
|
58
|
+
component mix[nRoundsF + nRoundsP];
|
|
59
|
+
|
|
60
|
+
var k;
|
|
61
|
+
|
|
62
|
+
for (var i=0; i<nRoundsF + nRoundsP; i++) {
|
|
63
|
+
ark[i] = Ark(t, C, t*i);
|
|
64
|
+
for (var j=0; j<t; j++) {
|
|
65
|
+
if (i==0) {
|
|
66
|
+
if (j>0) {
|
|
67
|
+
ark[i].in[j] <== inputs[j-1];
|
|
68
|
+
} else {
|
|
69
|
+
ark[i].in[j] <== 0;
|
|
70
|
+
}
|
|
71
|
+
} else {
|
|
72
|
+
ark[i].in[j] <== mix[i-1].out[j];
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (i < nRoundsF/2 || i >= nRoundsP + nRoundsF/2) {
|
|
77
|
+
k = i < nRoundsF/2 ? i : i - nRoundsP;
|
|
78
|
+
mix[i] = Mix(t, M);
|
|
79
|
+
for (var j=0; j<t; j++) {
|
|
80
|
+
sigmaF[k][j] = Sigma();
|
|
81
|
+
sigmaF[k][j].in <== ark[i].out[j];
|
|
82
|
+
mix[i].in[j] <== sigmaF[k][j].out;
|
|
83
|
+
}
|
|
84
|
+
} else {
|
|
85
|
+
k = i - nRoundsF/2;
|
|
86
|
+
mix[i] = Mix(t, M);
|
|
87
|
+
sigmaP[k] = Sigma();
|
|
88
|
+
sigmaP[k].in <== ark[i].out[0];
|
|
89
|
+
mix[i].in[0] <== sigmaP[k].out;
|
|
90
|
+
for (var j=1; j<t; j++) {
|
|
91
|
+
mix[i].in[j] <== ark[i].out[j];
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
out <== mix[nRoundsF + nRoundsP -1].out[0];
|
|
97
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
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
|
+
/* Ch
|
|
21
|
+
|
|
22
|
+
000 0
|
|
23
|
+
001 1
|
|
24
|
+
010 0
|
|
25
|
+
011 1
|
|
26
|
+
100 0
|
|
27
|
+
101 0
|
|
28
|
+
110 1
|
|
29
|
+
111 1
|
|
30
|
+
|
|
31
|
+
out = a&b ^ (!a)&c =>
|
|
32
|
+
|
|
33
|
+
out = a*(b-c) + c
|
|
34
|
+
|
|
35
|
+
*/
|
|
36
|
+
pragma circom 2.0.0;
|
|
37
|
+
|
|
38
|
+
template Ch_t(n) {
|
|
39
|
+
signal input a[n];
|
|
40
|
+
signal input b[n];
|
|
41
|
+
signal input c[n];
|
|
42
|
+
signal output out[n];
|
|
43
|
+
|
|
44
|
+
for (var k=0; k<n; k++) {
|
|
45
|
+
out[k] <== a[k] * (b[k]-c[k]) + c[k];
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
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 H(x) {
|
|
22
|
+
signal output out[32];
|
|
23
|
+
var c[8] = [0x6a09e667,
|
|
24
|
+
0xbb67ae85,
|
|
25
|
+
0x3c6ef372,
|
|
26
|
+
0xa54ff53a,
|
|
27
|
+
0x510e527f,
|
|
28
|
+
0x9b05688c,
|
|
29
|
+
0x1f83d9ab,
|
|
30
|
+
0x5be0cd19];
|
|
31
|
+
|
|
32
|
+
for (var i=0; i<32; i++) {
|
|
33
|
+
out[i] <== (c[x] >> i) & 1;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
template K(x) {
|
|
38
|
+
signal output out[32];
|
|
39
|
+
var c[64] = [
|
|
40
|
+
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
|
|
41
|
+
0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
|
|
42
|
+
0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
|
|
43
|
+
0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
|
|
44
|
+
0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
|
|
45
|
+
0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
|
|
46
|
+
0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
|
|
47
|
+
0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2
|
|
48
|
+
];
|
|
49
|
+
|
|
50
|
+
for (var i=0; i<32; i++) {
|
|
51
|
+
out[i] <== (c[x] >> i) & 1;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
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 "sha256_2.circom";
|
|
22
|
+
|
|
23
|
+
template Main() {
|
|
24
|
+
signal input a;
|
|
25
|
+
signal input b;
|
|
26
|
+
signal output out;
|
|
27
|
+
|
|
28
|
+
component sha256_2 = Sha256_2();
|
|
29
|
+
|
|
30
|
+
sha256_2.a <== a;
|
|
31
|
+
sha256_2.b <== a;
|
|
32
|
+
out <== sha256_2.out;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
component main = Main();
|
|
@@ -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
|
+
/* Maj function for sha256
|
|
21
|
+
|
|
22
|
+
out = a&b ^ a&c ^ b&c =>
|
|
23
|
+
|
|
24
|
+
out = a*b + a*c + b*c - 2*a*b*c =>
|
|
25
|
+
|
|
26
|
+
out = a*( b + c - 2*b*c ) + b*c =>
|
|
27
|
+
|
|
28
|
+
mid = b*c
|
|
29
|
+
out = a*( b + c - 2*mid ) + mid
|
|
30
|
+
|
|
31
|
+
*/
|
|
32
|
+
pragma circom 2.0.0;
|
|
33
|
+
|
|
34
|
+
template Maj_t(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] * (b[k]+c[k]-2*mid[k]) + mid[k];
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
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 RotR(n, r) {
|
|
22
|
+
signal input in[n];
|
|
23
|
+
signal output out[n];
|
|
24
|
+
|
|
25
|
+
for (var i=0; i<n; i++) {
|
|
26
|
+
out[i] <== in[ (i+r)%n ];
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
pragma circom 2.0.0;
|
|
2
|
+
|
|
3
|
+
include "constants.circom";
|
|
4
|
+
include "sha256compression.circom";
|
|
5
|
+
|
|
6
|
+
template Sha256(nBits) {
|
|
7
|
+
signal input in[nBits];
|
|
8
|
+
signal output out[256];
|
|
9
|
+
|
|
10
|
+
var i;
|
|
11
|
+
var k;
|
|
12
|
+
var nBlocks;
|
|
13
|
+
var bitsLastBlock;
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
nBlocks = ((nBits + 64)\512)+1;
|
|
17
|
+
|
|
18
|
+
signal paddedIn[nBlocks*512];
|
|
19
|
+
|
|
20
|
+
for (k=0; k<nBits; k++) {
|
|
21
|
+
paddedIn[k] <== in[k];
|
|
22
|
+
}
|
|
23
|
+
paddedIn[nBits] <== 1;
|
|
24
|
+
|
|
25
|
+
for (k=nBits+1; k<nBlocks*512-64; k++) {
|
|
26
|
+
paddedIn[k] <== 0;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
for (k = 0; k< 64; k++) {
|
|
30
|
+
paddedIn[nBlocks*512 - k -1] <== (nBits >> k)&1;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
component ha0 = H(0);
|
|
34
|
+
component hb0 = H(1);
|
|
35
|
+
component hc0 = H(2);
|
|
36
|
+
component hd0 = H(3);
|
|
37
|
+
component he0 = H(4);
|
|
38
|
+
component hf0 = H(5);
|
|
39
|
+
component hg0 = H(6);
|
|
40
|
+
component hh0 = H(7);
|
|
41
|
+
|
|
42
|
+
component sha256compression[nBlocks];
|
|
43
|
+
|
|
44
|
+
for (i=0; i<nBlocks; i++) {
|
|
45
|
+
|
|
46
|
+
sha256compression[i] = Sha256compression() ;
|
|
47
|
+
|
|
48
|
+
if (i==0) {
|
|
49
|
+
for (k=0; k<32; k++ ) {
|
|
50
|
+
sha256compression[i].hin[0*32+k] <== ha0.out[k];
|
|
51
|
+
sha256compression[i].hin[1*32+k] <== hb0.out[k];
|
|
52
|
+
sha256compression[i].hin[2*32+k] <== hc0.out[k];
|
|
53
|
+
sha256compression[i].hin[3*32+k] <== hd0.out[k];
|
|
54
|
+
sha256compression[i].hin[4*32+k] <== he0.out[k];
|
|
55
|
+
sha256compression[i].hin[5*32+k] <== hf0.out[k];
|
|
56
|
+
sha256compression[i].hin[6*32+k] <== hg0.out[k];
|
|
57
|
+
sha256compression[i].hin[7*32+k] <== hh0.out[k];
|
|
58
|
+
}
|
|
59
|
+
} else {
|
|
60
|
+
for (k=0; k<32; k++ ) {
|
|
61
|
+
sha256compression[i].hin[32*0+k] <== sha256compression[i-1].out[32*0+31-k];
|
|
62
|
+
sha256compression[i].hin[32*1+k] <== sha256compression[i-1].out[32*1+31-k];
|
|
63
|
+
sha256compression[i].hin[32*2+k] <== sha256compression[i-1].out[32*2+31-k];
|
|
64
|
+
sha256compression[i].hin[32*3+k] <== sha256compression[i-1].out[32*3+31-k];
|
|
65
|
+
sha256compression[i].hin[32*4+k] <== sha256compression[i-1].out[32*4+31-k];
|
|
66
|
+
sha256compression[i].hin[32*5+k] <== sha256compression[i-1].out[32*5+31-k];
|
|
67
|
+
sha256compression[i].hin[32*6+k] <== sha256compression[i-1].out[32*6+31-k];
|
|
68
|
+
sha256compression[i].hin[32*7+k] <== sha256compression[i-1].out[32*7+31-k];
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
for (k=0; k<512; k++) {
|
|
73
|
+
sha256compression[i].inp[k] <== paddedIn[i*512+k];
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
for (k=0; k<256; k++) {
|
|
78
|
+
out[k] <== sha256compression[nBlocks-1].out[k];
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
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 "constants.circom";
|
|
22
|
+
include "sha256compression.circom";
|
|
23
|
+
include "../bitify.circom";
|
|
24
|
+
|
|
25
|
+
template Sha256_2() {
|
|
26
|
+
signal input a;
|
|
27
|
+
signal input b;
|
|
28
|
+
signal output out;
|
|
29
|
+
|
|
30
|
+
var i;
|
|
31
|
+
var k;
|
|
32
|
+
|
|
33
|
+
component bits2num = Bits2Num(216);
|
|
34
|
+
component num2bits[2];
|
|
35
|
+
|
|
36
|
+
num2bits[0] = Num2Bits(216);
|
|
37
|
+
num2bits[1] = Num2Bits(216);
|
|
38
|
+
|
|
39
|
+
num2bits[0].in <== a;
|
|
40
|
+
num2bits[1].in <== b;
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
component sha256compression = Sha256compression() ;
|
|
44
|
+
|
|
45
|
+
component ha0 = H(0);
|
|
46
|
+
component hb0 = H(1);
|
|
47
|
+
component hc0 = H(2);
|
|
48
|
+
component hd0 = H(3);
|
|
49
|
+
component he0 = H(4);
|
|
50
|
+
component hf0 = H(5);
|
|
51
|
+
component hg0 = H(6);
|
|
52
|
+
component hh0 = H(7);
|
|
53
|
+
|
|
54
|
+
for (k=0; k<32; k++ ) {
|
|
55
|
+
sha256compression.hin[0*32+k] <== ha0.out[k];
|
|
56
|
+
sha256compression.hin[1*32+k] <== hb0.out[k];
|
|
57
|
+
sha256compression.hin[2*32+k] <== hc0.out[k];
|
|
58
|
+
sha256compression.hin[3*32+k] <== hd0.out[k];
|
|
59
|
+
sha256compression.hin[4*32+k] <== he0.out[k];
|
|
60
|
+
sha256compression.hin[5*32+k] <== hf0.out[k];
|
|
61
|
+
sha256compression.hin[6*32+k] <== hg0.out[k];
|
|
62
|
+
sha256compression.hin[7*32+k] <== hh0.out[k];
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
for (i=0; i<216; i++) {
|
|
66
|
+
sha256compression.inp[i] <== num2bits[0].out[215-i];
|
|
67
|
+
sha256compression.inp[i+216] <== num2bits[1].out[215-i];
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
sha256compression.inp[432] <== 1;
|
|
71
|
+
|
|
72
|
+
for (i=433; i<503; i++) {
|
|
73
|
+
sha256compression.inp[i] <== 0;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
sha256compression.inp[503] <== 1;
|
|
77
|
+
sha256compression.inp[504] <== 1;
|
|
78
|
+
sha256compression.inp[505] <== 0;
|
|
79
|
+
sha256compression.inp[506] <== 1;
|
|
80
|
+
sha256compression.inp[507] <== 1;
|
|
81
|
+
sha256compression.inp[508] <== 0;
|
|
82
|
+
sha256compression.inp[509] <== 0;
|
|
83
|
+
sha256compression.inp[510] <== 0;
|
|
84
|
+
sha256compression.inp[511] <== 0;
|
|
85
|
+
|
|
86
|
+
for (i=0; i<216; i++) {
|
|
87
|
+
bits2num.in[i] <== sha256compression.out[255-i];
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
out <== bits2num.out;
|
|
91
|
+
}
|
|
@@ -0,0 +1,166 @@
|
|
|
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 "constants.circom";
|
|
22
|
+
include "t1.circom";
|
|
23
|
+
include "t2.circom";
|
|
24
|
+
include "../binsum.circom";
|
|
25
|
+
include "sigmaplus.circom";
|
|
26
|
+
include "sha256compression_function.circom";
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
template Sha256compression() {
|
|
30
|
+
signal input hin[256];
|
|
31
|
+
signal input inp[512];
|
|
32
|
+
signal output out[256];
|
|
33
|
+
signal a[65][32];
|
|
34
|
+
signal b[65][32];
|
|
35
|
+
signal c[65][32];
|
|
36
|
+
signal d[65][32];
|
|
37
|
+
signal e[65][32];
|
|
38
|
+
signal f[65][32];
|
|
39
|
+
signal g[65][32];
|
|
40
|
+
signal h[65][32];
|
|
41
|
+
signal w[64][32];
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
var outCalc[256] = sha256compression(hin, inp);
|
|
45
|
+
|
|
46
|
+
var i;
|
|
47
|
+
for (i=0; i<256; i++) out[i] <-- outCalc[i];
|
|
48
|
+
|
|
49
|
+
component sigmaPlus[48];
|
|
50
|
+
for (i=0; i<48; i++) sigmaPlus[i] = SigmaPlus();
|
|
51
|
+
|
|
52
|
+
component ct_k[64];
|
|
53
|
+
for (i=0; i<64; i++) ct_k[i] = K(i);
|
|
54
|
+
|
|
55
|
+
component t1[64];
|
|
56
|
+
for (i=0; i<64; i++) t1[i] = T1();
|
|
57
|
+
|
|
58
|
+
component t2[64];
|
|
59
|
+
for (i=0; i<64; i++) t2[i] = T2();
|
|
60
|
+
|
|
61
|
+
component suma[64];
|
|
62
|
+
for (i=0; i<64; i++) suma[i] = BinSum(32, 2);
|
|
63
|
+
|
|
64
|
+
component sume[64];
|
|
65
|
+
for (i=0; i<64; i++) sume[i] = BinSum(32, 2);
|
|
66
|
+
|
|
67
|
+
component fsum[8];
|
|
68
|
+
for (i=0; i<8; i++) fsum[i] = BinSum(32, 2);
|
|
69
|
+
|
|
70
|
+
var k;
|
|
71
|
+
var t;
|
|
72
|
+
|
|
73
|
+
for (t=0; t<64; t++) {
|
|
74
|
+
if (t<16) {
|
|
75
|
+
for (k=0; k<32; k++) {
|
|
76
|
+
w[t][k] <== inp[t*32+31-k];
|
|
77
|
+
}
|
|
78
|
+
} else {
|
|
79
|
+
for (k=0; k<32; k++) {
|
|
80
|
+
sigmaPlus[t-16].in2[k] <== w[t-2][k];
|
|
81
|
+
sigmaPlus[t-16].in7[k] <== w[t-7][k];
|
|
82
|
+
sigmaPlus[t-16].in15[k] <== w[t-15][k];
|
|
83
|
+
sigmaPlus[t-16].in16[k] <== w[t-16][k];
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
for (k=0; k<32; k++) {
|
|
87
|
+
w[t][k] <== sigmaPlus[t-16].out[k];
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
for (k=0; k<32; k++ ) {
|
|
93
|
+
a[0][k] <== hin[k];
|
|
94
|
+
b[0][k] <== hin[32*1 + k];
|
|
95
|
+
c[0][k] <== hin[32*2 + k];
|
|
96
|
+
d[0][k] <== hin[32*3 + k];
|
|
97
|
+
e[0][k] <== hin[32*4 + k];
|
|
98
|
+
f[0][k] <== hin[32*5 + k];
|
|
99
|
+
g[0][k] <== hin[32*6 + k];
|
|
100
|
+
h[0][k] <== hin[32*7 + k];
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
for (t = 0; t<64; t++) {
|
|
104
|
+
for (k=0; k<32; k++) {
|
|
105
|
+
t1[t].h[k] <== h[t][k];
|
|
106
|
+
t1[t].e[k] <== e[t][k];
|
|
107
|
+
t1[t].f[k] <== f[t][k];
|
|
108
|
+
t1[t].g[k] <== g[t][k];
|
|
109
|
+
t1[t].k[k] <== ct_k[t].out[k];
|
|
110
|
+
t1[t].w[k] <== w[t][k];
|
|
111
|
+
|
|
112
|
+
t2[t].a[k] <== a[t][k];
|
|
113
|
+
t2[t].b[k] <== b[t][k];
|
|
114
|
+
t2[t].c[k] <== c[t][k];
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
for (k=0; k<32; k++) {
|
|
118
|
+
sume[t].in[0][k] <== d[t][k];
|
|
119
|
+
sume[t].in[1][k] <== t1[t].out[k];
|
|
120
|
+
|
|
121
|
+
suma[t].in[0][k] <== t1[t].out[k];
|
|
122
|
+
suma[t].in[1][k] <== t2[t].out[k];
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
for (k=0; k<32; k++) {
|
|
126
|
+
h[t+1][k] <== g[t][k];
|
|
127
|
+
g[t+1][k] <== f[t][k];
|
|
128
|
+
f[t+1][k] <== e[t][k];
|
|
129
|
+
e[t+1][k] <== sume[t].out[k];
|
|
130
|
+
d[t+1][k] <== c[t][k];
|
|
131
|
+
c[t+1][k] <== b[t][k];
|
|
132
|
+
b[t+1][k] <== a[t][k];
|
|
133
|
+
a[t+1][k] <== suma[t].out[k];
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
for (k=0; k<32; k++) {
|
|
138
|
+
fsum[0].in[0][k] <== hin[32*0+k];
|
|
139
|
+
fsum[0].in[1][k] <== a[64][k];
|
|
140
|
+
fsum[1].in[0][k] <== hin[32*1+k];
|
|
141
|
+
fsum[1].in[1][k] <== b[64][k];
|
|
142
|
+
fsum[2].in[0][k] <== hin[32*2+k];
|
|
143
|
+
fsum[2].in[1][k] <== c[64][k];
|
|
144
|
+
fsum[3].in[0][k] <== hin[32*3+k];
|
|
145
|
+
fsum[3].in[1][k] <== d[64][k];
|
|
146
|
+
fsum[4].in[0][k] <== hin[32*4+k];
|
|
147
|
+
fsum[4].in[1][k] <== e[64][k];
|
|
148
|
+
fsum[5].in[0][k] <== hin[32*5+k];
|
|
149
|
+
fsum[5].in[1][k] <== f[64][k];
|
|
150
|
+
fsum[6].in[0][k] <== hin[32*6+k];
|
|
151
|
+
fsum[6].in[1][k] <== g[64][k];
|
|
152
|
+
fsum[7].in[0][k] <== hin[32*7+k];
|
|
153
|
+
fsum[7].in[1][k] <== h[64][k];
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
for (k=0; k<32; k++) {
|
|
157
|
+
out[31-k] === fsum[0].out[k];
|
|
158
|
+
out[32+31-k] === fsum[1].out[k];
|
|
159
|
+
out[64+31-k] === fsum[2].out[k];
|
|
160
|
+
out[96+31-k] === fsum[3].out[k];
|
|
161
|
+
out[128+31-k] === fsum[4].out[k];
|
|
162
|
+
out[160+31-k] === fsum[5].out[k];
|
|
163
|
+
out[192+31-k] === fsum[6].out[k];
|
|
164
|
+
out[224+31-k] === fsum[7].out[k];
|
|
165
|
+
}
|
|
166
|
+
}
|