-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsquares.circom
86 lines (63 loc) · 2.22 KB
/
squares.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
78
79
80
81
82
83
84
85
86
pragma circom 2.0.0;
template IsZero() {
signal input in;
signal output out;
signal inv;
inv <-- in!=0 ? 1/in : 0;
out <== -in*inv + 1;
in*out === 0;
}
template CheckBrightness() {
signal input calcVal;
signal input actualVal;
signal input remainder;
signal input x1;
signal input x2;
signal input x3;
signal input x4;
signal input x5;
signal input x6;
signal output out1;
signal output out2;
signal output out3;
component isZero1 = IsZero();
isZero1.in <== 4 * (2545 - calcVal) + 1 - x1 - x2 - x3;
out1 <== (1 - isZero1.out) * (actualVal - 255);
component isZero2 = IsZero();
isZero2.in <== 4 * (calcVal - 5) + 1 - x4 - x5 - x6;
out2 <== (1 - isZero2.out) * actualVal;
var x = isZero1.out + isZero2.out - 1;
var y = 10 * actualVal - calcVal + remainder;
out3 <== x * y;
}
template Bright(n) {
signal input orig[n][3];
signal input new[n][3];
signal input squares[n][3][6];
signal input positiveRemainder[n][3];
signal input negativeRemainder[n][3];
signal input alpha;
signal input posBeta;
signal input negBeta;
signal output n_check;
component checkBright[n][3];
for (var i = 0; i < n; i++) {
for (var j = 0; j < 3; j++) {
checkBright[i][j] = CheckBrightness();
checkBright[i][j].calcVal <== alpha * orig[i][j] + posBeta - negBeta;
checkBright[i][j].actualVal <== new[i][j];
checkBright[i][j].remainder <== positiveRemainder[i][j] - negativeRemainder[i][j];
checkBright[i][j].x1 <== squares[i][j][0] * squares[i][j][0];
checkBright[i][j].x2 <== squares[i][j][1] * squares[i][j][1];
checkBright[i][j].x3 <== squares[i][j][2] * squares[i][j][2];
checkBright[i][j].x4 <== squares[i][j][3] * squares[i][j][3];
checkBright[i][j].x5 <== squares[i][j][4] * squares[i][j][4];
checkBright[i][j].x6 <== squares[i][j][5] * squares[i][j][5];
checkBright[i][j].out1 === 0;
checkBright[i][j].out2 === 0;
checkBright[i][j].out3 === 0;
}
}
n_check <== n;
}
component main = Bright(2000);