Skip to content

Commit 807f6ac

Browse files
committed
Format project
1 parent c3f568f commit 807f6ac

19 files changed

Lines changed: 1285 additions & 1132 deletions

File tree

.clang-format

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
BasedOnStyle: LLVM
2+
3+
IndentWidth: 4
4+
TabWidth: 4
5+
UseTab: Never
6+
7+
ColumnLimit: 100
8+
BreakBeforeBraces: Allman
9+
PointerAlignment: Left
10+
11+
SpaceAfterCStyleCast: true
12+
SpacesInParentheses: false
13+
SpaceBeforeParens: ControlStatements
14+
15+
AllowShortFunctionsOnASingleLine: false
16+
AllowShortIfStatementsOnASingleLine: false
17+
AllowShortLoopsOnASingleLine: false

circuits/eddsa.c

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -3,58 +3,58 @@
33
#include "mimc.c"
44
#include "utils.c"
55

6-
void verify_eddsa(eddsa_signature edsig, point B, point A, char *msg)
6+
void verify_eddsa(eddsa_signature edsig, point B, point A, char* msg)
77
{
8-
element out[4];
8+
element out[4];
99

10-
for (int i = 0; i < 4; ++i)
11-
{
12-
init(&out[i]);
13-
}
10+
for (int i = 0; i < 4; ++i)
11+
{
12+
init(&out[i]);
13+
}
1414

15-
element outPrivate[3];
16-
init_array(outPrivate, 3);
15+
element outPrivate[3];
16+
init_array(outPrivate, 3);
1717

18-
element Bx, By;
19-
init(&Bx);
20-
init(&By);
18+
element Bx, By;
19+
init(&Bx);
20+
init(&By);
2121

22-
input(&Bx, B.x);
23-
input(&By, B.y);
22+
input(&Bx, B.x);
23+
input(&By, B.y);
2424

25-
int arraySize = 5;
26-
element ram[arraySize];
27-
init_array(ram, arraySize);
28-
29-
input(&ram[0], edsig.R.x);
30-
input(&ram[1], edsig.R.y);
31-
input(&ram[2], A.x);
32-
input(&ram[3], A.y);
33-
input(&ram[4], msg);
25+
int arraySize = 5;
26+
element ram[arraySize];
27+
init_array(ram, arraySize);
3428

35-
element signature;
36-
init(&signature);
37-
input(&signature, edsig.S);
29+
input(&ram[0], edsig.R.x);
30+
input(&ram[1], edsig.R.y);
31+
input(&ram[2], A.x);
32+
input(&ram[3], A.y);
33+
input(&ram[4], msg);
3834

39-
multi_hash(outPrivate[0], ram, 5);
35+
element signature;
36+
init(&signature);
37+
input(&signature, edsig.S);
4038

41-
int size = 254;
42-
element hBits[size];
43-
element sBits[size];
39+
multi_hash(outPrivate[0], ram, 5);
4440

45-
init_array(hBits, size);
46-
init_array(sBits, size);
41+
int size = 254;
42+
element hBits[size];
43+
element sBits[size];
4744

48-
to_bits(hBits, outPrivate[0], size);
49-
to_bits(sBits, signature, size-1);
45+
init_array(hBits, size);
46+
init_array(sBits, size);
5047

51-
mul_scalar(outPrivate[1], outPrivate[2], ram[2], ram[3], hBits, size);
52-
add(out[0], out[1], outPrivate[1], outPrivate[2], ram[0], ram[1]);
48+
to_bits(hBits, outPrivate[0], size);
49+
to_bits(sBits, signature, size - 1);
5350

54-
mul_scalar(out[2], out[3], Bx, By, sBits, size-1);
51+
mul_scalar(outPrivate[1], outPrivate[2], ram[2], ram[3], hBits, size);
52+
add(out[0], out[1], outPrivate[1], outPrivate[2], ram[0], ram[1]);
5553

56-
assert_equal(&out[2], &out[0]);
57-
assert_equal(&out[3], &out[1]);
54+
mul_scalar(out[2], out[3], Bx, By, sBits, size - 1);
55+
56+
assert_equal(&out[2], &out[0]);
57+
assert_equal(&out[3], &out[1]);
5858
}
5959

6060
#endif

circuits/mimc.c

Lines changed: 38 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -3,50 +3,54 @@
33

44
#define NROUNDS 91
55

6-
void mimc7(element *h, element *x_in, element *k)
6+
void mimc7(element* h, element* x_in, element* k)
77
{
8-
element r[NROUNDS];
9-
element f[NROUNDS*3];
8+
element r[NROUNDS];
9+
element f[NROUNDS * 3];
1010

11-
init_array(r, NROUNDS);
12-
init_array(f, NROUNDS*3);
11+
init_array(r, NROUNDS);
12+
init_array(f, NROUNDS * 3);
1313

14-
int it = 0;
14+
int it = 0;
1515

16-
for (int i = 0; i < NROUNDS; i++)
17-
{
18-
if (i == 0) addmuladd(&f[it], k, x_in, k, x_in);
19-
else add3muladd3(&f[it], k, &r[i-1], &c_mimc[i], k, &r[i-1], &c_mimc[i]);
16+
for (int i = 0; i < NROUNDS; i++)
17+
{
18+
if (i == 0)
19+
addmuladd(&f[it], k, x_in, k, x_in);
20+
else
21+
add3muladd3(&f[it], k, &r[i - 1], &c_mimc[i], k, &r[i - 1], &c_mimc[i]);
2022

21-
mul(&f[it+1], &f[it], &f[it]);
22-
mul(&f[it+2], &f[it+1], &f[it]);
23-
if (i == 0) addmul(&r[i], k, x_in, &f[it+2]);
24-
else add3mul(&r[i], k, &r[i-1], &c_mimc[i], &f[it+2]);
23+
mul(&f[it + 1], &f[it], &f[it]);
24+
mul(&f[it + 2], &f[it + 1], &f[it]);
25+
if (i == 0)
26+
addmul(&r[i], k, x_in, &f[it + 2]);
27+
else
28+
add3mul(&r[i], k, &r[i - 1], &c_mimc[i], &f[it + 2]);
2529

26-
it = it + 3;
27-
}
30+
it = it + 3;
31+
}
2832

29-
addmul(h, k, &r[NROUNDS-1], &one);
33+
addmul(h, k, &r[NROUNDS - 1], &one);
3034
}
3135

32-
void multi_hash(element h, element *x_in, int arraySize)
36+
void multi_hash(element h, element* x_in, int arraySize)
3337
{
34-
element k[arraySize];
35-
init_array(k, arraySize);
36-
input(&k[0], "0");
37-
38-
for (int i = 0; i < arraySize-1; i++)
39-
{
40-
element hf;
41-
init(&hf);
42-
mimc7(&hf, &x_in[i], &k[i]);
43-
add3mul(&k[i+1], &x_in[i], &k[i], &hf, &one);
44-
}
45-
46-
element hf;
47-
init(&hf);
48-
mimc7(&hf, &x_in[arraySize-1], &k[arraySize-1]);
49-
add3mul(&h, &x_in[arraySize-1], &k[arraySize-1], &hf, &one);
38+
element k[arraySize];
39+
init_array(k, arraySize);
40+
input(&k[0], "0");
41+
42+
for (int i = 0; i < arraySize - 1; i++)
43+
{
44+
element hf;
45+
init(&hf);
46+
mimc7(&hf, &x_in[i], &k[i]);
47+
add3mul(&k[i + 1], &x_in[i], &k[i], &hf, &one);
48+
}
49+
50+
element hf;
51+
init(&hf);
52+
mimc7(&hf, &x_in[arraySize - 1], &k[arraySize - 1]);
53+
add3mul(&h, &x_in[arraySize - 1], &k[arraySize - 1], &hf, &one);
5054
}
5155

5256
#endif

0 commit comments

Comments
 (0)