-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathround.circom
77 lines (52 loc) · 1.33 KB
/
round.circom
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
pragma circom 2.0.0;
template Num2Bits(n) {
signal input in;
signal output out[n];
var lc1=0;
var e2=1;
for (var i = 0; i<n; i++) {
out[i] <-- (in >> i) & 1;
out[i] * (out[i] -1 ) === 0;
lc1 += out[i] * e2;
e2 = e2+e2;
}
lc1 === in;
}
template LessThan(n) {
assert(n <= 252);
signal input in[2];
signal output out;
component n2b = Num2Bits(n+1);
n2b.in <== in[0]+ (1<<n) - in[1];
out <== 1-n2b.out[n];
}
template LessEqThan(n) {
signal input in[2];
signal output out;
component lt = LessThan(n);
lt.in[0] <== in[0];
lt.in[1] <== in[1]+1;
lt.out ==> out;
}
template GrayscaleChecker(n) {
signal input orig[n][3];
signal input gray[n];
signal output n_check;
component lt[n][2];
/* = LessEqThan(16);
component lt2 = LessEqThan(16);
*/
for (var i = 0; i < n; i++) {
var inter = 30 * orig[i][0] + 59 * orig[i][1] + 11 * orig[i][2];
lt[i][0] = LessEqThan(16);
lt[i][1] = LessEqThan(16);
lt[i][0].in[1] <== 100;
lt[i][0].in[0] <== inter - 100 * gray[i];
lt[i][0].out === 1;
lt[i][1].in[1] <== 100;
lt[i][1].in[0] <== 100 * gray[i] - inter;
lt[i][1].out === 1;
}
n_check <== n;
}
component main = GrayscaleChecker(8000);