Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integration 0.09 #32

Closed
wants to merge 10 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
200 changes: 156 additions & 44 deletions src/assets/circuit.circom
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ template ShiftRight(k) {
template Sign() {
signal input in;
signal output sign;
sign <== in < 0;
}

template div_relu(k) {
Expand All @@ -103,65 +104,176 @@ template div_relu(k) {
}

template network() {
// var in_len = 2;
// var out_len = 3;
signal input in[1];
signal output out[2];

component l0 = fc(1, 2);
signal input w0[2][1];
signal input b0[2];
for (var i = 0; i < 2; i++) {
for (var j = 0; j < 1; j++) {
// Structure from python example
// self.fc1 = nn.Linear(2, 32)
// self.fc2 = nn.Linear(32, 64)
// self.fc3 = nn.Linear(64, 128)
// self.fc4 = nn.Linear(128, 4)

var in_len = 2;
var out_len = 4;

var l0_w = in_len;
var l0_h = 32;

var l1_w = l0_h;
var l1_h = 64;

var l2_w = l1_h;
var l2_h = 128;

var l3_w = l2_h;
var l3_h = 256;

var l4_w = l3_h;
var l4_h = 512;

var l5_w = l4_h;
var l5_h = 1024;

var l6_w = l5_h;
var l6_h = 2048;

var l7_w = l6_h;
var l7_h = out_len;

signal input in[in_len];
signal output out[out_len];

component l0 = fc(l0_w, l0_h);
signal input w0[l0_h][l0_w];
signal input b0[l0_h];
for (var i = 0; i < l0_h; i++) {
for (var j = 0; j < l0_w; j++) {
l0.weights[i][j] <== w0[i][j];
}
l0.biases[i] <== b0[i];
}
// l0.weights <== w0;
// l0.biases <== b0;
for (var k = 0; k < 1; k++) {
for (var k = 0; k < in_len; k++) {
l0.in[k] <== in[k];
}

for (var k = 0; k < 2; k++) {
out[k] <== l0.out[k];
component l1 = fc(l1_w, l1_h);
signal input w1[l1_h][l1_w];
signal input b1[l1_h];
for (var i = 0; i < l1_h; i++) {
for (var j = 0; j < l1_w; j++) {
l1.weights[i][j] <== w1[i][j];
}
l1.biases[i] <== b1[i];
}
// l1.weights <== w1;
// l1.biases <== b1;
for (var k = 0; k < l0_h; k++) {
l1.in[k] <== l0.out[k];
}
// l1.in <== l0.out;

// component l1 = fc(3, 4);
// signal input w1[4][3];
// signal input b1[4];
// for (var i = 0; i < 4; i++) {
// for (var j = 0; j < 3; j++) {
// l1.weights[i][j] <== w1[i][j];
// }
// l1.biases[i] <== b1[i];
// }
// // l1.weights <== w1;
// // l1.biases <== b1;
// for (var k = 0; k < 3; k++) {
// l1.in[k] <== l0.out[k];
// }
// // l1.in <== l0.out;

// component l2 = fc_no_relu(4, 3);
// signal input w2[3][4];
// signal input b2[3];
// for (var i = 0; i < 3; i++) {
// for (var j = 0; j < 4; j++) {
// l2.weights[i][j] <== w2[i][j];
component l2 = fc(l2_w, l2_h);
signal input w2[l2_h][l2_w];
signal input b2[l2_h];
for (var i = 0; i < l2_h; i++) {
for (var j = 0; j < l2_w; j++) {
l2.weights[i][j] <== w2[i][j];
}
l2.biases[i] <== b2[i];
}
// l2.weights <== w2;
// l2.biases <== b2;
for (var k = 0; k < l1_h; k++) {
l2.in[k] <== l1.out[k];
}
// l2.in <== l1.out;

component l3 = fc(l3_w, l3_h);
signal input w3[l3_h][l3_w];
signal input b3[l3_h];
for (var i = 0; i < l3_h; i++) {
for (var j = 0; j < l3_w; j++) {
l3.weights[i][j] <== w3[i][j];
}
l3.biases[i] <== b3[i];
}
// l2.weights <== w2;
// l2.biases <== b2;
for (var k = 0; k < l2_h; k++) {
l3.in[k] <== l2.out[k];
}
// l2.in <== l1.out;

component l4 = fc(l4_w, l4_h);
signal input w4[l4_h][l4_w];
signal input b4[l4_h];
for (var i = 0; i < l4_h; i++) {
for (var j = 0; j < l4_w; j++) {
l4.weights[i][j] <== w4[i][j];
}
l4.biases[i] <== b4[i];
}
for (var k = 0; k < l4_h; k++) {
l4.in[k] <== l3.out[k];
}

component l5 = fc(l5_w, l5_h);
signal input w5[l5_h][l5_w];
signal input b5[l5_h];
for (var i = 0; i < l5_h; i++) {
for (var j = 0; j < l5_w; j++) {
l5.weights[i][j] <== w5[i][j];
}
l5.biases[i] <== b5[i];
}
for (var k = 0; k < l5_h; k++) {
l5.in[k] <== l4.out[k];
}

component l6 = fc(l6_w, l6_h);
signal input w6[l6_h][l6_w];
signal input b6[l6_h];
for (var i = 0; i < l6_h; i++) {
for (var j = 0; j < l6_w; j++) {
l6.weights[i][j] <== w6[i][j];
}
l6.biases[i] <== b6[i];
}
for (var k = 0; k < l6_h; k++) {
l6.in[k] <== l5.out[k];
}

component l7 = fc(l7_w, l7_h);
signal input w7[l7_h][l7_w];
signal input b7[l7_h];
for (var i = 0; i < l7_h; i++) {
for (var j = 0; j < l7_w; j++) {
l7.weights[i][j] <== w7[i][j];
}
l7.biases[i] <== b7[i];
}
for (var k = 0; k < l7_h; k++) {
l7.in[k] <== l6.out[k];
}

// component l8 = fc_no_relu(l8_w, l8_h);
// signal input w8[l8_h][l8_w];
// signal input b8[l8_h];
// for (var i = 0; i < l8_h; i++) {
// for (var j = 0; j < l8_w; j++) {
// l8.weights[i][j] <== w8[i][j];
// }
// l2.biases[i] <== b2[i];
// l8.biases[i] <== b8[i];
// }
// // l2.weights <== w2;
// // l2.biases <== b2;
// for (var k = 0; k < 4; k++) {
// l2.in[k] <== l1.out[k];
// // l3.weights <== w2;
// // l3.biases <== b2;
// for (var k = 0; k < l8_h; k++) {
// l8.in[k] <== l7.out[k];
// }
// // l2.in <== l1.out;
// // l3.in <== l1.out;

// for (var k = 0; k < 3; k++) {
// out[k] <== l2.out[k];
// }
for (var k = 0; k < out_len; k++) {
out[k] <== l7.out[k];
}
// out <== l2.out;
}

Expand Down
Loading
Loading