-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathutil.circom
More file actions
53 lines (46 loc) · 956 Bytes
/
util.circom
File metadata and controls
53 lines (46 loc) · 956 Bytes
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
pragma circom 2.1.0;
function min(x, y) {
if (x > y) {
return y;
} else {
return x;
}
}
function max(x, y) {
if (x > y) {
return x;
} else {
return y;
}
}
// assumes 0 <= a <= 2^252
function log2(a) {
return logb(a, 2);
}
// assumes 0 <= a <= b^k where k is the largest integer such that b^k < p/2,
// where p is circom's prime
function logb(a, b) {
if (a==0) {
return 0;
}
var n = 1;
var r = 0;
while (n<a) {
r++;
n *= b;
}
return r;
}
function extended_gcd(a, b) {
var old_r = a; var r = b;
var old_s = 1; var s = 0;
var old_t = 0; var t = 1;
var quotient;
while (r != 0) {
quotient = old_r \ r;
old_r = r; r = old_r - quotient * r;
old_s = s; s = old_s - quotient * s;
old_t = t; t = old_t - quotient * t;
}
return [old_s, old_t]; // old_s * a + old_t * b == 1
}