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,139 @@
|
|
|
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
|
+
include "pointbits.circom";
|
|
23
|
+
include "pedersen.circom";
|
|
24
|
+
include "escalarmulany.circom";
|
|
25
|
+
include "escalarmulfix.circom";
|
|
26
|
+
|
|
27
|
+
template EdDSAVerifier(n) {
|
|
28
|
+
signal input msg[n];
|
|
29
|
+
|
|
30
|
+
signal input A[256];
|
|
31
|
+
signal input R8[256];
|
|
32
|
+
signal input S[256];
|
|
33
|
+
|
|
34
|
+
signal Ax;
|
|
35
|
+
signal Ay;
|
|
36
|
+
|
|
37
|
+
signal R8x;
|
|
38
|
+
signal R8y;
|
|
39
|
+
|
|
40
|
+
var i;
|
|
41
|
+
|
|
42
|
+
// Ensure S<Subgroup Order
|
|
43
|
+
|
|
44
|
+
component compConstant = CompConstant(2736030358979909402780800718157159386076813972158567259200215660948447373040);
|
|
45
|
+
|
|
46
|
+
for (i=0; i<254; i++) {
|
|
47
|
+
S[i] ==> compConstant.in[i];
|
|
48
|
+
}
|
|
49
|
+
compConstant.out === 0;
|
|
50
|
+
S[254] === 0;
|
|
51
|
+
S[255] === 0;
|
|
52
|
+
|
|
53
|
+
// Convert A to Field elements (And verify A)
|
|
54
|
+
|
|
55
|
+
component bits2pointA = Bits2Point_Strict();
|
|
56
|
+
|
|
57
|
+
for (i=0; i<256; i++) {
|
|
58
|
+
bits2pointA.in[i] <== A[i];
|
|
59
|
+
}
|
|
60
|
+
Ax <== bits2pointA.out[0];
|
|
61
|
+
Ay <== bits2pointA.out[1];
|
|
62
|
+
|
|
63
|
+
// Convert R8 to Field elements (And verify R8)
|
|
64
|
+
|
|
65
|
+
component bits2pointR8 = Bits2Point_Strict();
|
|
66
|
+
|
|
67
|
+
for (i=0; i<256; i++) {
|
|
68
|
+
bits2pointR8.in[i] <== R8[i];
|
|
69
|
+
}
|
|
70
|
+
R8x <== bits2pointR8.out[0];
|
|
71
|
+
R8y <== bits2pointR8.out[1];
|
|
72
|
+
|
|
73
|
+
// Calculate the h = H(R,A, msg)
|
|
74
|
+
|
|
75
|
+
component hash = Pedersen(512+n);
|
|
76
|
+
|
|
77
|
+
for (i=0; i<256; i++) {
|
|
78
|
+
hash.in[i] <== R8[i];
|
|
79
|
+
hash.in[256+i] <== A[i];
|
|
80
|
+
}
|
|
81
|
+
for (i=0; i<n; i++) {
|
|
82
|
+
hash.in[512+i] <== msg[i];
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
component point2bitsH = Point2Bits_Strict();
|
|
86
|
+
point2bitsH.in[0] <== hash.out[0];
|
|
87
|
+
point2bitsH.in[1] <== hash.out[1];
|
|
88
|
+
|
|
89
|
+
// Calculate second part of the right side: right2 = h*8*A
|
|
90
|
+
|
|
91
|
+
// Multiply by 8 by adding it 3 times. This also ensure that the result is in
|
|
92
|
+
// the subgroup.
|
|
93
|
+
component dbl1 = BabyDbl();
|
|
94
|
+
dbl1.x <== Ax;
|
|
95
|
+
dbl1.y <== Ay;
|
|
96
|
+
component dbl2 = BabyDbl();
|
|
97
|
+
dbl2.x <== dbl1.xout;
|
|
98
|
+
dbl2.y <== dbl1.yout;
|
|
99
|
+
component dbl3 = BabyDbl();
|
|
100
|
+
dbl3.x <== dbl2.xout;
|
|
101
|
+
dbl3.y <== dbl2.yout;
|
|
102
|
+
|
|
103
|
+
// We check that A is not zero.
|
|
104
|
+
component isZero = IsZero();
|
|
105
|
+
isZero.in <== dbl3.x;
|
|
106
|
+
isZero.out === 0;
|
|
107
|
+
|
|
108
|
+
component mulAny = EscalarMulAny(256);
|
|
109
|
+
for (i=0; i<256; i++) {
|
|
110
|
+
mulAny.e[i] <== point2bitsH.out[i];
|
|
111
|
+
}
|
|
112
|
+
mulAny.p[0] <== dbl3.xout;
|
|
113
|
+
mulAny.p[1] <== dbl3.yout;
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
// Compute the right side: right = R8 + right2
|
|
117
|
+
|
|
118
|
+
component addRight = BabyAdd();
|
|
119
|
+
addRight.x1 <== R8x;
|
|
120
|
+
addRight.y1 <== R8y;
|
|
121
|
+
addRight.x2 <== mulAny.out[0];
|
|
122
|
+
addRight.y2 <== mulAny.out[1];
|
|
123
|
+
|
|
124
|
+
// Calculate left side of equation left = S*B8
|
|
125
|
+
|
|
126
|
+
var BASE8[2] = [
|
|
127
|
+
5299619240641551281634865583518297030282874472190772894086521144482721001553,
|
|
128
|
+
16950150798460657717958625567821834550301663161624707787222815936182638968203
|
|
129
|
+
];
|
|
130
|
+
component mulFix = EscalarMulFix(256, BASE8);
|
|
131
|
+
for (i=0; i<256; i++) {
|
|
132
|
+
mulFix.e[i] <== S[i];
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// Do the comparation left == right
|
|
136
|
+
|
|
137
|
+
mulFix.out[0] === addRight.xout;
|
|
138
|
+
mulFix.out[1] === addRight.yout;
|
|
139
|
+
}
|
|
@@ -0,0 +1,124 @@
|
|
|
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
|
+
include "pointbits.circom";
|
|
23
|
+
include "mimc.circom";
|
|
24
|
+
include "bitify.circom";
|
|
25
|
+
include "escalarmulany.circom";
|
|
26
|
+
include "escalarmulfix.circom";
|
|
27
|
+
|
|
28
|
+
template EdDSAMiMCVerifier() {
|
|
29
|
+
signal input enabled;
|
|
30
|
+
signal input Ax;
|
|
31
|
+
signal input Ay;
|
|
32
|
+
|
|
33
|
+
signal input S;
|
|
34
|
+
signal input R8x;
|
|
35
|
+
signal input R8y;
|
|
36
|
+
|
|
37
|
+
signal input M;
|
|
38
|
+
|
|
39
|
+
var i;
|
|
40
|
+
|
|
41
|
+
// Ensure S<Subgroup Order
|
|
42
|
+
|
|
43
|
+
component snum2bits = Num2Bits(253);
|
|
44
|
+
snum2bits.in <== S;
|
|
45
|
+
|
|
46
|
+
component compConstant = CompConstant(2736030358979909402780800718157159386076813972158567259200215660948447373040);
|
|
47
|
+
|
|
48
|
+
for (i=0; i<253; i++) {
|
|
49
|
+
snum2bits.out[i] ==> compConstant.in[i];
|
|
50
|
+
}
|
|
51
|
+
compConstant.in[253] <== 0;
|
|
52
|
+
compConstant.out === 0;
|
|
53
|
+
|
|
54
|
+
// Calculate the h = H(R,A, msg)
|
|
55
|
+
|
|
56
|
+
component hash = MultiMiMC7(5, 91);
|
|
57
|
+
hash.in[0] <== R8x;
|
|
58
|
+
hash.in[1] <== R8y;
|
|
59
|
+
hash.in[2] <== Ax;
|
|
60
|
+
hash.in[3] <== Ay;
|
|
61
|
+
hash.in[4] <== M;
|
|
62
|
+
hash.k <== 0;
|
|
63
|
+
|
|
64
|
+
component h2bits = Num2Bits_strict();
|
|
65
|
+
h2bits.in <== hash.out;
|
|
66
|
+
|
|
67
|
+
// Calculate second part of the right side: right2 = h*8*A
|
|
68
|
+
|
|
69
|
+
// Multiply by 8 by adding it 3 times. This also ensure that the result is in
|
|
70
|
+
// the subgroup.
|
|
71
|
+
component dbl1 = BabyDbl();
|
|
72
|
+
dbl1.x <== Ax;
|
|
73
|
+
dbl1.y <== Ay;
|
|
74
|
+
component dbl2 = BabyDbl();
|
|
75
|
+
dbl2.x <== dbl1.xout;
|
|
76
|
+
dbl2.y <== dbl1.yout;
|
|
77
|
+
component dbl3 = BabyDbl();
|
|
78
|
+
dbl3.x <== dbl2.xout;
|
|
79
|
+
dbl3.y <== dbl2.yout;
|
|
80
|
+
|
|
81
|
+
// We check that A is not zero.
|
|
82
|
+
component isZero = IsZero();
|
|
83
|
+
isZero.in <== dbl3.x;
|
|
84
|
+
isZero.out === 0;
|
|
85
|
+
|
|
86
|
+
component mulAny = EscalarMulAny(254);
|
|
87
|
+
for (i=0; i<254; i++) {
|
|
88
|
+
mulAny.e[i] <== h2bits.out[i];
|
|
89
|
+
}
|
|
90
|
+
mulAny.p[0] <== dbl3.xout;
|
|
91
|
+
mulAny.p[1] <== dbl3.yout;
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
// Compute the right side: right = R8 + right2
|
|
95
|
+
|
|
96
|
+
component addRight = BabyAdd();
|
|
97
|
+
addRight.x1 <== R8x;
|
|
98
|
+
addRight.y1 <== R8y;
|
|
99
|
+
addRight.x2 <== mulAny.out[0];
|
|
100
|
+
addRight.y2 <== mulAny.out[1];
|
|
101
|
+
|
|
102
|
+
// Calculate left side of equation left = S*B8
|
|
103
|
+
|
|
104
|
+
var BASE8[2] = [
|
|
105
|
+
5299619240641551281634865583518297030282874472190772894086521144482721001553,
|
|
106
|
+
16950150798460657717958625567821834550301663161624707787222815936182638968203
|
|
107
|
+
];
|
|
108
|
+
component mulFix = EscalarMulFix(253, BASE8);
|
|
109
|
+
for (i=0; i<253; i++) {
|
|
110
|
+
mulFix.e[i] <== snum2bits.out[i];
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// Do the comparation left == right if enabled;
|
|
114
|
+
|
|
115
|
+
component eqCheckX = ForceEqualIfEnabled();
|
|
116
|
+
eqCheckX.enabled <== enabled;
|
|
117
|
+
eqCheckX.in[0] <== mulFix.out[0];
|
|
118
|
+
eqCheckX.in[1] <== addRight.xout;
|
|
119
|
+
|
|
120
|
+
component eqCheckY = ForceEqualIfEnabled();
|
|
121
|
+
eqCheckY.enabled <== enabled;
|
|
122
|
+
eqCheckY.in[0] <== mulFix.out[1];
|
|
123
|
+
eqCheckY.in[1] <== addRight.yout;
|
|
124
|
+
}
|
|
@@ -0,0 +1,124 @@
|
|
|
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
|
+
include "pointbits.circom";
|
|
23
|
+
include "mimcsponge.circom";
|
|
24
|
+
include "bitify.circom";
|
|
25
|
+
include "escalarmulany.circom";
|
|
26
|
+
include "escalarmulfix.circom";
|
|
27
|
+
|
|
28
|
+
template EdDSAMiMCSpongeVerifier() {
|
|
29
|
+
signal input enabled;
|
|
30
|
+
signal input Ax;
|
|
31
|
+
signal input Ay;
|
|
32
|
+
|
|
33
|
+
signal input S;
|
|
34
|
+
signal input R8x;
|
|
35
|
+
signal input R8y;
|
|
36
|
+
|
|
37
|
+
signal input M;
|
|
38
|
+
|
|
39
|
+
var i;
|
|
40
|
+
|
|
41
|
+
// Ensure S<Subgroup Order
|
|
42
|
+
|
|
43
|
+
component snum2bits = Num2Bits(253);
|
|
44
|
+
snum2bits.in <== S;
|
|
45
|
+
|
|
46
|
+
component compConstant = CompConstant(2736030358979909402780800718157159386076813972158567259200215660948447373040);
|
|
47
|
+
|
|
48
|
+
for (i=0; i<253; i++) {
|
|
49
|
+
snum2bits.out[i] ==> compConstant.in[i];
|
|
50
|
+
}
|
|
51
|
+
compConstant.in[253] <== 0;
|
|
52
|
+
compConstant.out === 0;
|
|
53
|
+
|
|
54
|
+
// Calculate the h = H(R,A, msg)
|
|
55
|
+
|
|
56
|
+
component hash = MiMCSponge(5, 220, 1);
|
|
57
|
+
hash.ins[0] <== R8x;
|
|
58
|
+
hash.ins[1] <== R8y;
|
|
59
|
+
hash.ins[2] <== Ax;
|
|
60
|
+
hash.ins[3] <== Ay;
|
|
61
|
+
hash.ins[4] <== M;
|
|
62
|
+
hash.k <== 0;
|
|
63
|
+
|
|
64
|
+
component h2bits = Num2Bits_strict();
|
|
65
|
+
h2bits.in <== hash.outs[0];
|
|
66
|
+
|
|
67
|
+
// Calculate second part of the right side: right2 = h*8*A
|
|
68
|
+
|
|
69
|
+
// Multiply by 8 by adding it 3 times. This also ensure that the result is in
|
|
70
|
+
// the subgroup.
|
|
71
|
+
component dbl1 = BabyDbl();
|
|
72
|
+
dbl1.x <== Ax;
|
|
73
|
+
dbl1.y <== Ay;
|
|
74
|
+
component dbl2 = BabyDbl();
|
|
75
|
+
dbl2.x <== dbl1.xout;
|
|
76
|
+
dbl2.y <== dbl1.yout;
|
|
77
|
+
component dbl3 = BabyDbl();
|
|
78
|
+
dbl3.x <== dbl2.xout;
|
|
79
|
+
dbl3.y <== dbl2.yout;
|
|
80
|
+
|
|
81
|
+
// We check that A is not zero.
|
|
82
|
+
component isZero = IsZero();
|
|
83
|
+
isZero.in <== dbl3.x;
|
|
84
|
+
isZero.out === 0;
|
|
85
|
+
|
|
86
|
+
component mulAny = EscalarMulAny(254);
|
|
87
|
+
for (i=0; i<254; i++) {
|
|
88
|
+
mulAny.e[i] <== h2bits.out[i];
|
|
89
|
+
}
|
|
90
|
+
mulAny.p[0] <== dbl3.xout;
|
|
91
|
+
mulAny.p[1] <== dbl3.yout;
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
// Compute the right side: right = R8 + right2
|
|
95
|
+
|
|
96
|
+
component addRight = BabyAdd();
|
|
97
|
+
addRight.x1 <== R8x;
|
|
98
|
+
addRight.y1 <== R8y;
|
|
99
|
+
addRight.x2 <== mulAny.out[0];
|
|
100
|
+
addRight.y2 <== mulAny.out[1];
|
|
101
|
+
|
|
102
|
+
// Calculate left side of equation left = S*B8
|
|
103
|
+
|
|
104
|
+
var BASE8[2] = [
|
|
105
|
+
5299619240641551281634865583518297030282874472190772894086521144482721001553,
|
|
106
|
+
16950150798460657717958625567821834550301663161624707787222815936182638968203
|
|
107
|
+
];
|
|
108
|
+
component mulFix = EscalarMulFix(253, BASE8);
|
|
109
|
+
for (i=0; i<253; i++) {
|
|
110
|
+
mulFix.e[i] <== snum2bits.out[i];
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// Do the comparation left == right if enabled;
|
|
114
|
+
|
|
115
|
+
component eqCheckX = ForceEqualIfEnabled();
|
|
116
|
+
eqCheckX.enabled <== enabled;
|
|
117
|
+
eqCheckX.in[0] <== mulFix.out[0];
|
|
118
|
+
eqCheckX.in[1] <== addRight.xout;
|
|
119
|
+
|
|
120
|
+
component eqCheckY = ForceEqualIfEnabled();
|
|
121
|
+
eqCheckY.enabled <== enabled;
|
|
122
|
+
eqCheckY.in[0] <== mulFix.out[1];
|
|
123
|
+
eqCheckY.in[1] <== addRight.yout;
|
|
124
|
+
}
|
|
@@ -0,0 +1,123 @@
|
|
|
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
|
+
include "poseidon.circom";
|
|
23
|
+
include "bitify.circom";
|
|
24
|
+
include "escalarmulany.circom";
|
|
25
|
+
include "escalarmulfix.circom";
|
|
26
|
+
|
|
27
|
+
template EdDSAPoseidonVerifier() {
|
|
28
|
+
signal input enabled;
|
|
29
|
+
signal input Ax;
|
|
30
|
+
signal input Ay;
|
|
31
|
+
|
|
32
|
+
signal input S;
|
|
33
|
+
signal input R8x;
|
|
34
|
+
signal input R8y;
|
|
35
|
+
|
|
36
|
+
signal input M;
|
|
37
|
+
|
|
38
|
+
var i;
|
|
39
|
+
|
|
40
|
+
// Ensure S<Subgroup Order
|
|
41
|
+
|
|
42
|
+
component snum2bits = Num2Bits(253);
|
|
43
|
+
snum2bits.in <== S;
|
|
44
|
+
|
|
45
|
+
component compConstant = CompConstant(2736030358979909402780800718157159386076813972158567259200215660948447373040);
|
|
46
|
+
|
|
47
|
+
for (i=0; i<253; i++) {
|
|
48
|
+
snum2bits.out[i] ==> compConstant.in[i];
|
|
49
|
+
}
|
|
50
|
+
compConstant.in[253] <== 0;
|
|
51
|
+
compConstant.out*enabled === 0;
|
|
52
|
+
|
|
53
|
+
// Calculate the h = H(R,A, msg)
|
|
54
|
+
|
|
55
|
+
component hash = Poseidon(5);
|
|
56
|
+
|
|
57
|
+
hash.inputs[0] <== R8x;
|
|
58
|
+
hash.inputs[1] <== R8y;
|
|
59
|
+
hash.inputs[2] <== Ax;
|
|
60
|
+
hash.inputs[3] <== Ay;
|
|
61
|
+
hash.inputs[4] <== M;
|
|
62
|
+
|
|
63
|
+
component h2bits = Num2Bits_strict();
|
|
64
|
+
h2bits.in <== hash.out;
|
|
65
|
+
|
|
66
|
+
// Calculate second part of the right side: right2 = h*8*A
|
|
67
|
+
|
|
68
|
+
// Multiply by 8 by adding it 3 times. This also ensure that the result is in
|
|
69
|
+
// the subgroup.
|
|
70
|
+
component dbl1 = BabyDbl();
|
|
71
|
+
dbl1.x <== Ax;
|
|
72
|
+
dbl1.y <== Ay;
|
|
73
|
+
component dbl2 = BabyDbl();
|
|
74
|
+
dbl2.x <== dbl1.xout;
|
|
75
|
+
dbl2.y <== dbl1.yout;
|
|
76
|
+
component dbl3 = BabyDbl();
|
|
77
|
+
dbl3.x <== dbl2.xout;
|
|
78
|
+
dbl3.y <== dbl2.yout;
|
|
79
|
+
|
|
80
|
+
// We check that A is not zero.
|
|
81
|
+
component isZero = IsZero();
|
|
82
|
+
isZero.in <== dbl3.x;
|
|
83
|
+
isZero.out*enabled === 0;
|
|
84
|
+
|
|
85
|
+
component mulAny = EscalarMulAny(254);
|
|
86
|
+
for (i=0; i<254; i++) {
|
|
87
|
+
mulAny.e[i] <== h2bits.out[i];
|
|
88
|
+
}
|
|
89
|
+
mulAny.p[0] <== dbl3.xout;
|
|
90
|
+
mulAny.p[1] <== dbl3.yout;
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
// Compute the right side: right = R8 + right2
|
|
94
|
+
|
|
95
|
+
component addRight = BabyAdd();
|
|
96
|
+
addRight.x1 <== R8x;
|
|
97
|
+
addRight.y1 <== R8y;
|
|
98
|
+
addRight.x2 <== mulAny.out[0];
|
|
99
|
+
addRight.y2 <== mulAny.out[1];
|
|
100
|
+
|
|
101
|
+
// Calculate left side of equation left = S*B8
|
|
102
|
+
|
|
103
|
+
var BASE8[2] = [
|
|
104
|
+
5299619240641551281634865583518297030282874472190772894086521144482721001553,
|
|
105
|
+
16950150798460657717958625567821834550301663161624707787222815936182638968203
|
|
106
|
+
];
|
|
107
|
+
component mulFix = EscalarMulFix(253, BASE8);
|
|
108
|
+
for (i=0; i<253; i++) {
|
|
109
|
+
mulFix.e[i] <== snum2bits.out[i];
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// Do the comparation left == right if enabled;
|
|
113
|
+
|
|
114
|
+
component eqCheckX = ForceEqualIfEnabled();
|
|
115
|
+
eqCheckX.enabled <== enabled;
|
|
116
|
+
eqCheckX.in[0] <== mulFix.out[0];
|
|
117
|
+
eqCheckX.in[1] <== addRight.xout;
|
|
118
|
+
|
|
119
|
+
component eqCheckY = ForceEqualIfEnabled();
|
|
120
|
+
eqCheckY.enabled <== enabled;
|
|
121
|
+
eqCheckY.in[0] <== mulFix.out[1];
|
|
122
|
+
eqCheckY.in[1] <== addRight.yout;
|
|
123
|
+
}
|
|
@@ -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
|
+
|
|
20
|
+
/*
|
|
21
|
+
|
|
22
|
+
┏━━━━━━━━━━━┓
|
|
23
|
+
┃ ┃
|
|
24
|
+
┃ ┃
|
|
25
|
+
(inx, iny) ══════════════════════════════════════════▶┃ EC Point ┃
|
|
26
|
+
┃ ╠═▶ (outx, outy)
|
|
27
|
+
╔══▶┃ Adder ┃
|
|
28
|
+
║ ┃ ┃
|
|
29
|
+
║ ┃ ┃
|
|
30
|
+
║ ┃ ┃
|
|
31
|
+
┏━━━━━━━━━━━┓ ┏━━━━━━━━━━━━┓ ║ ┗━━━━━━━━━━━┛
|
|
32
|
+
┃ ┃ ┃ ┃ ║
|
|
33
|
+
┃ ┃ ┃ ┃ ║
|
|
34
|
+
┃ ╠═══(p0x,p0y)═══▶┃ ┃ ║
|
|
35
|
+
┃ ╠═══(p1x,p1y)═══▶┃ ┃ ║
|
|
36
|
+
┃ ╠═══(p2x,p2y)═══▶┃ ┃ ║
|
|
37
|
+
┃ ╠═══(p3x,p3y)═══▶┃ ┃ ║
|
|
38
|
+
┃ ╠═══(p4x,p4y)═══▶┃ ┃ ║
|
|
39
|
+
┃ ╠═══(p5x,p5y)═══▶┃ ┃ ║
|
|
40
|
+
┃ ╠═══(p6x,p6y)═══▶┃ ┃ ║
|
|
41
|
+
┃ Constant ╠═══(p7x,p7y)═══▶┃ ┃ ║
|
|
42
|
+
┃ Points ┃ ┃ Mux4 ╠══╝
|
|
43
|
+
┃ ╠═══(p8x,p8y)═══▶┃ ┃
|
|
44
|
+
┃ ╠═══(p9x,p9y)═══▶┃ ┃
|
|
45
|
+
┃ ╠══(p10x,p10y)══▶┃ ┃
|
|
46
|
+
┃ ╠══(p11x,p11y)══▶┃ ┃
|
|
47
|
+
┃ ╠══(p12x,p12y)══▶┃ ┃
|
|
48
|
+
┃ ╠══(p13x,p13y)══▶┃ ┃
|
|
49
|
+
┃ ╠══(p14x,p14y)══▶┃ ┃
|
|
50
|
+
┃ ╠══(p15x,p15y)══▶┃ ┃
|
|
51
|
+
┃ ┃ ┃ ┃
|
|
52
|
+
┃ ┃ ┃ ┃
|
|
53
|
+
┗━━━━━━━━━━━┛ ┗━━━━━━━━━━━━┛
|
|
54
|
+
▲ ▲ ▲ ▲
|
|
55
|
+
│ │ │ │
|
|
56
|
+
s0 ─────────────────────────────────┘ │ │ │
|
|
57
|
+
s1 ────────────────────────────────────┘ │ │
|
|
58
|
+
s2 ───────────────────────────────────────┘ │
|
|
59
|
+
s3 ──────────────────────────────────────────┘
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
*/
|
|
63
|
+
pragma circom 2.0.0;
|
|
64
|
+
|
|
65
|
+
include "mux4.circom";
|
|
66
|
+
include "escalarmulw4table.circom";
|
|
67
|
+
include "babyjub.circom";
|
|
68
|
+
|
|
69
|
+
template EscalarMulWindow(base, k) {
|
|
70
|
+
|
|
71
|
+
signal input in[2];
|
|
72
|
+
signal input sel[4];
|
|
73
|
+
signal output out[2];
|
|
74
|
+
|
|
75
|
+
var table[16][2];
|
|
76
|
+
component mux;
|
|
77
|
+
component adder;
|
|
78
|
+
|
|
79
|
+
var i;
|
|
80
|
+
|
|
81
|
+
table = EscalarMulW4Table(base, k);
|
|
82
|
+
mux = MultiMux4(2);
|
|
83
|
+
adder = BabyAdd();
|
|
84
|
+
|
|
85
|
+
for (i=0; i<4; i++) {
|
|
86
|
+
sel[i] ==> mux.s[i];
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
for (i=0; i<16; i++) {
|
|
90
|
+
mux.c[0][i] <== table[i][0];
|
|
91
|
+
mux.c[1][i] <== table[i][1];
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
in[0] ==> adder.x1;
|
|
95
|
+
in[1] ==> adder.y1;
|
|
96
|
+
|
|
97
|
+
mux.out[0] ==> adder.x2;
|
|
98
|
+
mux.out[1] ==> adder.y2;
|
|
99
|
+
|
|
100
|
+
adder.xout ==> out[0];
|
|
101
|
+
adder.yout ==> out[1];
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/*
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
┏━━━━━━━━━┓ ┏━━━━━━━━━┓ ┏━━━━━━━━━━━━━━━━━━━┓
|
|
108
|
+
┃ ┃ ┃ ┃ ┃ ┃
|
|
109
|
+
inp ════▶┃Window(0)┃═════▶┃Window(1)┃════════ . . . . ═════════▶┃ Window(nBlocks-1) ┃═════▶ out
|
|
110
|
+
┃ ┃ ┃ ┃ ┃ ┃
|
|
111
|
+
┗━━━━━━━━━┛ ┗━━━━━━━━━┛ ┗━━━━━━━━━━━━━━━━━━━┛
|
|
112
|
+
▲ ▲ ▲ ▲ ▲ ▲ ▲ ▲ ▲ ▲ ▲ ▲
|
|
113
|
+
in[0]─────────┘ │ │ │ │ │ │ │ │ │ │ │
|
|
114
|
+
in[1]───────────┘ │ │ │ │ │ │ │ │ │ │
|
|
115
|
+
in[2]─────────────┘ │ │ │ │ │ │ │ 0 0
|
|
116
|
+
in[3]───────────────┘ │ │ │ │ │ │
|
|
117
|
+
in[4]──────────────────────────┘ │ │ │ │ │
|
|
118
|
+
in[5]────────────────────────────┘ │ │ │ │
|
|
119
|
+
in[6]──────────────────────────────┘ │ │ │
|
|
120
|
+
in[7]────────────────────────────────┘ │ │
|
|
121
|
+
. │ │
|
|
122
|
+
. │ │
|
|
123
|
+
in[n-2]─────────────────────────────────────────────────────────────────────┘ │
|
|
124
|
+
in[n-1]───────────────────────────────────────────────────────────────────────┘
|
|
125
|
+
|
|
126
|
+
*/
|
|
127
|
+
|
|
128
|
+
template EscalarMul(n, base) {
|
|
129
|
+
signal input in[n];
|
|
130
|
+
signal input inp[2]; // Point input to be added
|
|
131
|
+
signal output out[2];
|
|
132
|
+
|
|
133
|
+
var nBlocks = ((n-1)>>2)+1;
|
|
134
|
+
var i;
|
|
135
|
+
var j;
|
|
136
|
+
|
|
137
|
+
component windows[nBlocks];
|
|
138
|
+
|
|
139
|
+
// Construct the windows
|
|
140
|
+
for (i=0; i<nBlocks; i++) {
|
|
141
|
+
windows[i] = EscalarMulWindow(base, i);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// Connect the selectors
|
|
145
|
+
for (i=0; i<nBlocks; i++) {
|
|
146
|
+
for (j=0; j<4; j++) {
|
|
147
|
+
if (i*4+j >= n) {
|
|
148
|
+
windows[i].sel[j] <== 0;
|
|
149
|
+
} else {
|
|
150
|
+
windows[i].sel[j] <== in[i*4+j];
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// Start with generator
|
|
156
|
+
windows[0].in[0] <== inp[0];
|
|
157
|
+
windows[0].in[1] <== inp[1];
|
|
158
|
+
|
|
159
|
+
for(i=0; i<nBlocks-1; i++) {
|
|
160
|
+
windows[i].out[0] ==> windows[i+1].in[0];
|
|
161
|
+
windows[i].out[1] ==> windows[i+1].in[1];
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
windows[nBlocks-1].out[0] ==> out[0];
|
|
165
|
+
windows[nBlocks-1].out[1] ==> out[1];
|
|
166
|
+
}
|