Construction phase redone

This commit is contained in:
Jordi Baylina
2019-12-23 19:34:52 +01:00
parent b564201170
commit da969a5e16
15 changed files with 1722 additions and 1981 deletions

View File

@@ -44,7 +44,8 @@ async function doTest(circuit, testVectors) {
describe("basic cases", function () {
this.timeout(100000);
/* it("inout", async () => {
/*
it("inout", async () => {
await doTest(
"inout.circom",
[
@@ -298,6 +299,17 @@ describe("basic cases", function () {
]
);
});
*/
it("Component array 2d", async () => {
await doTest(
"componentarray2.circom",
[
[{in: [1,2]}, {out: [1, 256]}],
[{in: [0,3]}, {out: [0, 6561]}],
]
);
});
/*
it("Constant circuit", async () => {
await doTest(
"constantcircuit.circom",
@@ -306,12 +318,11 @@ describe("basic cases", function () {
[{}, {out: [1,0,1,0, 0,0,0,1, 0,1,1,1, 0,1,0,1, 1,1,1,0, 0,1,1,0, 1,1,0,1, 1,1,0,1]}],
]
);
}); */
});
it("Constant internal circuit", async () => {
await doTest(
"constantinternalcircuit.circom",
[
// 0xbb67ae85
[{in: 1}, {out: 5}],
[{in: 0}, {out: 4}],
[{in: -2}, {out: 2}],
@@ -319,4 +330,14 @@ describe("basic cases", function () {
]
);
});
it("include", async () => {
await doTest(
"include.circom",
[
[{in: 3}, {out: 6}],
[{in: 6}, {out: 15}],
]
);
});
*/
});

View File

@@ -4,18 +4,15 @@
function Add3(arr1, arr2, arr3) {
var res[3];
var i;
var j;
res[0] = arr1;
res[1] = 0;
for (i=0; i<2; i += 1) {
for (var i=0; i<2; i += 1) {
res[1] = res[1] + arr2[i];
}
res[2] = 0;
for (i=0; i<2; i++) {
for (j=0; j<3; j += 1) {
for (var i=0; i<2; i++) {
for (var j=0; j<3; j += 1) {
res[2] = res[2] + arr3[i][j];
}
}
@@ -27,8 +24,8 @@ template Main() {
signal input in;
signal output out[3];
var c = Add3(1, [2,3], [[4,5,6], [7,8,9]]); // [1, 5, 39];
var d = Add3(in, [in+1, in+2], [[in+1, in+2, in+3], [in+1, in+2, in+3]]);
var c[3] = Add3(1, [2,3], [[4,5,6], [7,8,9]]); // [1, 5, 39];
var d[3] = Add3(in, [in+1, in+2], [[in+1, in+2, in+3], [in+1, in+2, in+3]]);
out[0] <-- d[0] + c[0];
out[0] === in+c[0];

View File

@@ -0,0 +1,27 @@
template Square() {
signal input in;
signal output out;
out <== in**2;
}
template Main(n, nrounds) {
signal input in[n];
signal output out[n];
component squares[n][nrounds];
for (var i=0; i<n; i++) {
for (var r=0; r<nrounds; r++) {
squares[i][r] = Square();
if (r==0) {
squares[i][r].in <== in[i];
} else {
squares[i][r].in <== squares[i][r-1].out;
}
}
squares[i][nrounds-1].out ==> out[i];
}
}
component main = Main(2, 3);

View File

@@ -1,6 +1,6 @@
template H(x) {
signal output out[32];
var c = [0x6a09e667,
var c[8] = [0x6a09e667,
0xbb67ae85,
0x3c6ef372,
0xa54ff53a,

View File

@@ -0,0 +1,16 @@
include "included.circom";
include "included.circom"; // Include twice is fine. The second one is not included
template Main() {
signal input in;
signal output out;
component t1 = T1();
var a = F1(3);
in ==> t1.in;
t1.out + a ==> out; /// out <-- in**2/3+3
}
component main = Main();

View File

@@ -0,0 +1,10 @@
template T1() {
signal input in;
signal output out;
out <== in**2/3;
}
function F1(a) {
return a**2/3;
}