Skip to content

Commit

Permalink
circuits syntax and tests modified to be compatible with circom2
Browse files Browse the repository at this point in the history
  • Loading branch information
judiciouscoder committed Oct 6, 2021
1 parent 39a01fd commit a8cdb6c
Show file tree
Hide file tree
Showing 163 changed files with 700 additions and 39,351 deletions.
83 changes: 0 additions & 83 deletions calcpedersenbases/calcpedersenbases.js

This file was deleted.

1 change: 1 addition & 0 deletions circuits/aliascheck.circom
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
You should have received a copy of the GNU General Public License
along with circom. If not, see <https://www.gnu.org/licenses/>.
*/
pragma circom 2.0.0;

include "compconstant.circom";

Expand Down
7 changes: 4 additions & 3 deletions circuits/babyjub.circom
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
You should have received a copy of the GNU General Public License
along with circom. If not, see <https://www.gnu.org/licenses/>.
*/
pragma circom 2.0.0;

include "bitify.circom";
include "escalarmulfix.circom";
Expand Down Expand Up @@ -83,9 +84,9 @@ template BabyCheck() {

// Extracts the public key from private key
template BabyPbk() {
signal private input in;
signal output Ax;
signal output Ay;
signal input in;
signal output Ax;
signal output Ay;

var BASE8[2] = [
5299619240641551281634865583518297030282874472190772894086521144482721001553,
Expand Down
1 change: 1 addition & 0 deletions circuits/binsub.circom
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ Main Constraint:
aux * (aux-1) == 0
*/
pragma circom 2.0.0;

template BinSub(n) {
signal input in[2][n];
Expand Down
1 change: 1 addition & 0 deletions circuits/binsum.circom
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ To waranty binary outputs:
/*
This function calculates the number of extra bits in the output to do the full sum.
*/
pragma circom 2.0.0;

function nbits(a) {
var n = 1;
Expand Down
1 change: 1 addition & 0 deletions circuits/bitify.circom
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
You should have received a copy of the GNU General Public License
along with circom. If not, see <https://www.gnu.org/licenses/>.
*/
pragma circom 2.0.0;

include "comparators.circom";
include "aliascheck.circom";
Expand Down
1 change: 1 addition & 0 deletions circuits/comparators.circom
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
You should have received a copy of the GNU General Public License
along with circom. If not, see <https://www.gnu.org/licenses/>.
*/
pragma circom 2.0.0;

include "bitify.circom";
include "binsum.circom";
Expand Down
1 change: 1 addition & 0 deletions circuits/compconstant.circom
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
You should have received a copy of the GNU General Public License
along with circom. If not, see <https://www.gnu.org/licenses/>.
*/
pragma circom 2.0.0;

include "bitify.circom";

Expand Down
1 change: 1 addition & 0 deletions circuits/eddsa.circom
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
You should have received a copy of the GNU General Public License
along with circom. If not, see <https://www.gnu.org/licenses/>.
*/
pragma circom 2.0.0;

include "compconstant.circom";
include "pointbits.circom";
Expand Down
1 change: 1 addition & 0 deletions circuits/eddsamimc.circom
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
You should have received a copy of the GNU General Public License
along with circom. If not, see <https://www.gnu.org/licenses/>.
*/
pragma circom 2.0.0;

include "compconstant.circom";
include "pointbits.circom";
Expand Down
1 change: 1 addition & 0 deletions circuits/eddsamimcsponge.circom
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
You should have received a copy of the GNU General Public License
along with circom. If not, see <https://www.gnu.org/licenses/>.
*/
pragma circom 2.0.0;

include "compconstant.circom";
include "pointbits.circom";
Expand Down
1 change: 1 addition & 0 deletions circuits/eddsaposeidon.circom
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
You should have received a copy of the GNU General Public License
along with circom. If not, see <https://www.gnu.org/licenses/>.
*/
pragma circom 2.0.0;

include "compconstant.circom";
include "poseidon.circom";
Expand Down
1 change: 1 addition & 0 deletions circuits/escalarmul.circom
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
*/
pragma circom 2.0.0;

include "mux4.circom";
include "escalarmulw4table.circom";
Expand Down
17 changes: 9 additions & 8 deletions circuits/escalarmulany.circom
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
You should have received a copy of the GNU General Public License
along with circom. If not, see <https://www.gnu.org/licenses/>.
*/
pragma circom 2.0.0;

include "montgomery.circom";
include "babyjub.circom";
Expand Down Expand Up @@ -82,19 +83,19 @@ template SegmentMulAny(n) {
var i;

bits[0] = BitElementMulAny();
e2m.out[0] ==> bits[0].dblIn[0]
e2m.out[1] ==> bits[0].dblIn[1]
e2m.out[0] ==> bits[0].addIn[0]
e2m.out[1] ==> bits[0].addIn[1]
e2m.out[0] ==> bits[0].dblIn[0];
e2m.out[1] ==> bits[0].dblIn[1];
e2m.out[0] ==> bits[0].addIn[0];
e2m.out[1] ==> bits[0].addIn[1];
e[1] ==> bits[0].sel;

for (i=1; i<n-1; i++) {
bits[i] = BitElementMulAny();

bits[i-1].dblOut[0] ==> bits[i].dblIn[0]
bits[i-1].dblOut[1] ==> bits[i].dblIn[1]
bits[i-1].addOut[0] ==> bits[i].addIn[0]
bits[i-1].addOut[1] ==> bits[i].addIn[1]
bits[i-1].dblOut[0] ==> bits[i].dblIn[0];
bits[i-1].dblOut[1] ==> bits[i].dblIn[1];
bits[i-1].addOut[0] ==> bits[i].addIn[0];
bits[i-1].addOut[1] ==> bits[i].addIn[1];
e[i+1] ==> bits[i].sel;
}

Expand Down
1 change: 1 addition & 0 deletions circuits/escalarmulfix.circom
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
You should have received a copy of the GNU General Public License
along with circom. If not, see <https://www.gnu.org/licenses/>.
*/
pragma circom 2.0.0;

include "mux3.circom";
include "montgomery.circom";
Expand Down
1 change: 1 addition & 0 deletions circuits/escalarmulw4table.circom
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
You should have received a copy of the GNU General Public License
along with circom. If not, see <https://www.gnu.org/licenses/>.
*/
pragma circom 2.0.0;

function pointAdd(x1,y1,x2,y2) {
var a = 168700;
Expand Down
11 changes: 7 additions & 4 deletions circuits/gates.circom
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
You should have received a copy of the GNU General Public License
along with circom. If not, see <https://www.gnu.org/licenses/>.
*/
pragma circom 2.0.0;

template XOR() {
signal input a;
Expand Down Expand Up @@ -67,21 +68,23 @@ template NOR() {
template MultiAND(n) {
signal input in[n];
signal output out;
var i;
component and1;
component and2;
component ands[2];
if (n==1) {
out <== in[0];
} else if (n==2) {
component and1 = AND();
and1 = AND();
and1.a <== in[0];
and1.b <== in[1];
out <== and1.out;
} else {
component and2 = AND();
component ands[2];
and2 = AND();
var n1 = n\2;
var n2 = n-n\2;
ands[0] = MultiAND(n1);
ands[1] = MultiAND(n2);
var i;
for (i=0; i<n1; i++) ands[0].in[i] <== in[i];
for (i=0; i<n2; i++) ands[1].in[i] <== in[n1+i];
and2.a <== ands[0].out;
Expand Down
1 change: 1 addition & 0 deletions circuits/mimc.circom
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
You should have received a copy of the GNU General Public License
along with circom. If not, see <https://www.gnu.org/licenses/>.
*/
pragma circom 2.0.0;

template MiMC7(nrounds) {
signal input x_in;
Expand Down
5 changes: 4 additions & 1 deletion circuits/mimcsponge.circom
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
pragma circom 2.0.0;

// implements MiMC-2n/n as hash using a sponge construction.
// log_5(21888242871839275222246405745257275088548364400416034343698204186575808495617) ~= 110
// => nRounds should be 220
Expand Down Expand Up @@ -280,7 +282,8 @@ template MiMCFeistel(nrounds) {
t2[i] <== t*t;
t4[i] <== t2[i]*t2[i];
if (i<nrounds-1) {
xL[i] <== ((i==0) ? xR_in : xR[i-1]) + t4[i]*t;
var aux = (i==0) ? xR_in : xR[i-1] ;
xL[i] <== aux + t4[i]*t;
xR[i] <== (i==0) ? xL_in : xL[i-1];
} else {
xR_out <== xR[i-1] + t4[i]*t;
Expand Down
1 change: 1 addition & 0 deletions circuits/montgomery.circom
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
1 - y (1 - y)x
*/
pragma circom 2.0.0;

template Edwards2Montgomery() {
signal input in[2];
Expand Down
2 changes: 2 additions & 0 deletions circuits/multiplexer.circom
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ function log2(a) {
}
*/

pragma circom 2.0.0;

template EscalarProduct(w) {
signal input in1[w];
signal input in2[w];
Expand Down
1 change: 1 addition & 0 deletions circuits/mux1.circom
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
You should have received a copy of the GNU General Public License
along with circom. If not, see <https://www.gnu.org/licenses/>.
*/
pragma circom 2.0.0;

template MultiMux1(n) {
signal input c[n][2]; // Constants
Expand Down
3 changes: 2 additions & 1 deletion circuits/mux2.circom
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
You should have received a copy of the GNU General Public License
along with circom. If not, see <https://www.gnu.org/licenses/>.
*/
pragma circom 2.0.0;

template MultiMux2(n) {
signal input c[n][4]; // Constants
Expand All @@ -35,7 +36,7 @@ template MultiMux2(n) {
a10[i] <== ( c[i][ 3]-c[i][ 2]-c[i][ 1]+c[i][ 0] ) * s10;
a1[i] <== ( c[i][ 2]-c[i][ 0] ) * s[1];
a0[i] <== ( c[i][ 1]-c[i][ 0] ) * s[0];
a[i] <== ( c[i][ 0] )
a[i] <== ( c[i][ 0] );

out[i] <== ( a10[i] + a1[i] + a0[i] + a[i] );

Expand Down
3 changes: 2 additions & 1 deletion circuits/mux3.circom
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
You should have received a copy of the GNU General Public License
along with circom. If not, see <https://www.gnu.org/licenses/>.
*/
pragma circom 2.0.0;

template MultiMux3(n) {
signal input c[n][8]; // Constants
Expand Down Expand Up @@ -46,7 +47,7 @@ template MultiMux3(n) {
a10[i] <== ( c[i][ 3]-c[i][ 2]-c[i][ 1]+c[i][ 0] ) * s10;
a1[i] <== ( c[i][ 2]-c[i][ 0] ) * s[1];
a0[i] <== ( c[i][ 1]-c[i][ 0] ) * s[0];
a[i] <== ( c[i][ 0] )
a[i] <== ( c[i][ 0] );

out[i] <== ( a210[i] + a21[i] + a20[i] + a2[i] ) * s[2] +
( a10[i] + a1[i] + a0[i] + a[i] );
Expand Down
3 changes: 2 additions & 1 deletion circuits/mux4.circom
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
You should have received a copy of the GNU General Public License
along with circom. If not, see <https://www.gnu.org/licenses/>.
*/
pragma circom 2.0.0;

template MultiMux4(n) {
signal input c[n][16]; // Constants
Expand Down Expand Up @@ -70,7 +71,7 @@ template MultiMux4(n) {
a2[i] <== ( c[i][ 4]-c[i][ 0] ) * s[2];
a1[i] <== ( c[i][ 2]-c[i][ 0] ) * s[1];
a0[i] <== ( c[i][ 1]-c[i][ 0] ) * s[0];
a[i] <== ( c[i][ 0] )
a[i] <== ( c[i][ 0] );

out[i] <== ( a3210[i] + a321[i] + a320[i] + a310[i] + a32[i] + a31[i] + a30[i] + a3[i] ) * s[3] +
( a210[i] + a21[i] + a20[i] + a10[i] + a2[i] + a1[i] + a0[i] + a[i] );
Expand Down
1 change: 1 addition & 0 deletions circuits/pedersen.circom
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
You should have received a copy of the GNU General Public License
along with circom. If not, see <https://www.gnu.org/licenses/>.
*/
pragma circom 2.0.0;

include "montgomery.circom";
include "mux3.circom";
Expand Down
1 change: 1 addition & 0 deletions circuits/pedersen_old.circom
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
You should have received a copy of the GNU General Public License
along with circom. If not, see <https://www.gnu.org/licenses/>.
*/
pragma circom 2.0.0;

include "escalarmul.circom";

Expand Down
Loading

0 comments on commit a8cdb6c

Please sign in to comment.