From 7aab16cb8fc3f781276436370407856f724ebc3f Mon Sep 17 00:00:00 2001
From: Enrico Bottazzi <85900164+enricobottazzi@users.noreply.github.com>
Date: Mon, 18 Sep 2023 08:28:50 +0200
Subject: [PATCH] chore: add circomlib as node module
---
zk_prover/.gitignore | 1 +
zk_prover/README.md | 4 +-
.../circomlib/circuits/aliascheck.circom | 33 -
.../circom/circomlib/circuits/binsum.circom | 101 -
.../circom/circomlib/circuits/bitify.circom | 106 -
.../circomlib/circuits/comparators.circom | 141 -
.../circomlib/circuits/compconstant.circom | 74 -
.../src/circom/circomlib/circuits/mux1.circom | 48 -
.../circom/circomlib/circuits/poseidon.circom | 208 -
.../circuits/poseidon_constants.circom | 24959 ----------------
.../circom/incremental_mst_inclusion.circom | 2 +-
zk_prover/src/circom/merkle_sum_tree.circom | 6 +-
zk_prover/src/circom/package-lock.json | 21 +
zk_prover/src/circom/package.json | 9 +
14 files changed, 38 insertions(+), 25675 deletions(-)
delete mode 100644 zk_prover/src/circom/circomlib/circuits/aliascheck.circom
delete mode 100644 zk_prover/src/circom/circomlib/circuits/binsum.circom
delete mode 100644 zk_prover/src/circom/circomlib/circuits/bitify.circom
delete mode 100644 zk_prover/src/circom/circomlib/circuits/comparators.circom
delete mode 100644 zk_prover/src/circom/circomlib/circuits/compconstant.circom
delete mode 100644 zk_prover/src/circom/circomlib/circuits/mux1.circom
delete mode 100644 zk_prover/src/circom/circomlib/circuits/poseidon.circom
delete mode 100644 zk_prover/src/circom/circomlib/circuits/poseidon_constants.circom
create mode 100644 zk_prover/src/circom/package-lock.json
create mode 100644 zk_prover/src/circom/package.json
diff --git a/zk_prover/.gitignore b/zk_prover/.gitignore
index a4d400f4..8d790640 100644
--- a/zk_prover/.gitignore
+++ b/zk_prover/.gitignore
@@ -5,3 +5,4 @@
/benches/csv
circuit_parameters_gen/generate_parameters_grain.sage.py
circuit_parameters_gen/__pycache__
+node_modules
diff --git a/zk_prover/README.md b/zk_prover/README.md
index b3fbf64d..04c5876e 100644
--- a/zk_prover/README.md
+++ b/zk_prover/README.md
@@ -65,7 +65,9 @@ The Incremental Nova Verifier is an experimental feature that allows a user to v
We provide an example to test the Nova verifier. The build folder already contains the artifacts generated by the circuit compilation. If you want to recompile the circuit, you can run the following command:
```
-circom src/circom/incremental_mst_inclusion.circom --r1cs --wasm -o examples/build --prime bn128
+$ cd src/circom
+$ npm install
+$ circom incremental_mst_inclusion.circom --r1cs --wasm -o ../../examples/build --prime bn128
```
To run the Nova Incremental Verifier example run:
diff --git a/zk_prover/src/circom/circomlib/circuits/aliascheck.circom b/zk_prover/src/circom/circomlib/circuits/aliascheck.circom
deleted file mode 100644
index 1c5a5f87..00000000
--- a/zk_prover/src/circom/circomlib/circuits/aliascheck.circom
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- Copyright 2018 0KIMS association.
-
- This file is part of circom (Zero Knowledge Circuit Compiler).
-
- circom is a free software: you can redistribute it and/or modify it
- under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- circom is distributed in the hope that it will be useful, but WITHOUT
- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
- License for more details.
-
- You should have received a copy of the GNU General Public License
- along with circom. If not, see .
-*/
-pragma circom 2.0.0;
-
-include "compconstant.circom";
-
-
-template AliasCheck() {
-
- signal input in[254];
-
- component compConstant = CompConstant(-1);
-
- for (var i=0; i<254; i++) in[i] ==> compConstant.in[i];
-
- compConstant.out === 0;
-}
diff --git a/zk_prover/src/circom/circomlib/circuits/binsum.circom b/zk_prover/src/circom/circomlib/circuits/binsum.circom
deleted file mode 100644
index 28c7fcce..00000000
--- a/zk_prover/src/circom/circomlib/circuits/binsum.circom
+++ /dev/null
@@ -1,101 +0,0 @@
-/*
- Copyright 2018 0KIMS association.
-
- This file is part of circom (Zero Knowledge Circuit Compiler).
-
- circom is a free software: you can redistribute it and/or modify it
- under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- circom is distributed in the hope that it will be useful, but WITHOUT
- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
- License for more details.
-
- You should have received a copy of the GNU General Public License
- along with circom. If not, see .
-*/
-
-/*
-
-Binary Sum
-==========
-
-This component creates a binary sum componet of ops operands and n bits each operand.
-
-e is Number of carries: Depends on the number of operands in the input.
-
-Main Constraint:
- in[0][0] * 2^0 + in[0][1] * 2^1 + ..... + in[0][n-1] * 2^(n-1) +
- + in[1][0] * 2^0 + in[1][1] * 2^1 + ..... + in[1][n-1] * 2^(n-1) +
- + ..
- + in[ops-1][0] * 2^0 + in[ops-1][1] * 2^1 + ..... + in[ops-1][n-1] * 2^(n-1) +
- ===
- out[0] * 2^0 + out[1] * 2^1 + + out[n+e-1] *2(n+e-1)
-
-To waranty binary outputs:
-
- out[0] * (out[0] - 1) === 0
- out[1] * (out[0] - 1) === 0
- .
- .
- .
- out[n+e-1] * (out[n+e-1] - 1) == 0
-
- */
-
-
-/*
- 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;
- var r = 0;
- while (n-1> k) & 1;
-
- // Ensure out is binary
- out[k] * (out[k] - 1) === 0;
-
- lout += out[k] * e2;
-
- e2 = e2+e2;
- }
-
- // Ensure the sum;
-
- lin === lout;
-}
diff --git a/zk_prover/src/circom/circomlib/circuits/bitify.circom b/zk_prover/src/circom/circomlib/circuits/bitify.circom
deleted file mode 100644
index bfdd4e82..00000000
--- a/zk_prover/src/circom/circomlib/circuits/bitify.circom
+++ /dev/null
@@ -1,106 +0,0 @@
-/*
- Copyright 2018 0KIMS association.
-
- This file is part of circom (Zero Knowledge Circuit Compiler).
-
- circom is a free software: you can redistribute it and/or modify it
- under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- circom is distributed in the hope that it will be useful, but WITHOUT
- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
- License for more details.
-
- You should have received a copy of the GNU General Public License
- along with circom. If not, see .
-*/
-pragma circom 2.0.0;
-
-include "comparators.circom";
-include "aliascheck.circom";
-
-
-template Num2Bits(n) {
- signal input in;
- signal output out[n];
- var lc1=0;
-
- var e2=1;
- for (var i = 0; i> i) & 1;
- out[i] * (out[i] -1 ) === 0;
- lc1 += out[i] * e2;
- e2 = e2+e2;
- }
-
- lc1 === in;
-}
-
-template Num2Bits_strict() {
- signal input in;
- signal output out[254];
-
- component aliasCheck = AliasCheck();
- component n2b = Num2Bits(254);
- in ==> n2b.in;
-
- for (var i=0; i<254; i++) {
- n2b.out[i] ==> out[i];
- n2b.out[i] ==> aliasCheck.in[i];
- }
-}
-
-template Bits2Num(n) {
- signal input in[n];
- signal output out;
- var lc1=0;
-
- var e2 = 1;
- for (var i = 0; i out;
-}
-
-template Bits2Num_strict() {
- signal input in[254];
- signal output out;
-
- component aliasCheck = AliasCheck();
- component b2n = Bits2Num(254);
-
- for (var i=0; i<254; i++) {
- in[i] ==> b2n.in[i];
- in[i] ==> aliasCheck.in[i];
- }
-
- b2n.out ==> out;
-}
-
-template Num2BitsNeg(n) {
- signal input in;
- signal output out[n];
- var lc1=0;
-
- component isZero;
-
- isZero = IsZero();
-
- var neg = n == 0 ? 0 : 2**n - in;
-
- for (var i = 0; i> i) & 1;
- out[i] * (out[i] -1 ) === 0;
- lc1 += out[i] * 2**i;
- }
-
- in ==> isZero.in;
-
-
-
- lc1 + isZero.out * 2**n === 2**n - in;
-}
diff --git a/zk_prover/src/circom/circomlib/circuits/comparators.circom b/zk_prover/src/circom/circomlib/circuits/comparators.circom
deleted file mode 100644
index bfed0320..00000000
--- a/zk_prover/src/circom/circomlib/circuits/comparators.circom
+++ /dev/null
@@ -1,141 +0,0 @@
-/*
- Copyright 2018 0KIMS association.
-
- This file is part of circom (Zero Knowledge Circuit Compiler).
-
- circom is a free software: you can redistribute it and/or modify it
- under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- circom is distributed in the hope that it will be useful, but WITHOUT
- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
- License for more details.
-
- You should have received a copy of the GNU General Public License
- along with circom. If not, see .
-*/
-pragma circom 2.0.0;
-
-include "bitify.circom";
-include "binsum.circom";
-
-template IsZero() {
- signal input in;
- signal output out;
-
- signal inv;
-
- inv <-- in!=0 ? 1/in : 0;
-
- out <== -in*inv +1;
- in*out === 0;
-}
-
-
-template IsEqual() {
- signal input in[2];
- signal output out;
-
- component isz = IsZero();
-
- in[1] - in[0] ==> isz.in;
-
- isz.out ==> out;
-}
-
-template ForceEqualIfEnabled() {
- signal input enabled;
- signal input in[2];
-
- component isz = IsZero();
-
- in[1] - in[0] ==> isz.in;
-
- (1 - isz.out)*enabled === 0;
-}
-
-/*
-// N is the number of bits the input have.
-// The MSF is the sign bit.
-template LessThan(n) {
- signal input in[2];
- signal output out;
-
- component num2Bits0;
- component num2Bits1;
-
- component adder;
-
- adder = BinSum(n, 2);
-
- num2Bits0 = Num2Bits(n);
- num2Bits1 = Num2BitsNeg(n);
-
- in[0] ==> num2Bits0.in;
- in[1] ==> num2Bits1.in;
-
- var i;
- for (i=0;i adder.in[0][i];
- num2Bits1.out[i] ==> adder.in[1][i];
- }
-
- adder.out[n-1] ==> out;
-}
-*/
-
-template LessThan(n) {
- assert(n <= 252);
- signal input in[2];
- signal output out;
-
- component n2b = Num2Bits(n+1);
-
- n2b.in <== in[0]+ (1< out;
-}
-
-// N is the number of bits the input have.
-// The MSF is the sign bit.
-template GreaterThan(n) {
- signal input in[2];
- signal output out;
-
- component lt = LessThan(n);
-
- lt.in[0] <== in[1];
- lt.in[1] <== in[0];
- lt.out ==> out;
-}
-
-// N is the number of bits the input have.
-// The MSF is the sign bit.
-template GreaterEqThan(n) {
- signal input in[2];
- signal output out;
-
- component lt = LessThan(n);
-
- lt.in[0] <== in[1];
- lt.in[1] <== in[0]+1;
- lt.out ==> out;
-}
-
diff --git a/zk_prover/src/circom/circomlib/circuits/compconstant.circom b/zk_prover/src/circom/circomlib/circuits/compconstant.circom
deleted file mode 100644
index 1bca83a5..00000000
--- a/zk_prover/src/circom/circomlib/circuits/compconstant.circom
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- Copyright 2018 0KIMS association.
-
- This file is part of circom (Zero Knowledge Circuit Compiler).
-
- circom is a free software: you can redistribute it and/or modify it
- under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- circom is distributed in the hope that it will be useful, but WITHOUT
- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
- License for more details.
-
- You should have received a copy of the GNU General Public License
- along with circom. If not, see .
-*/
-pragma circom 2.0.0;
-
-include "bitify.circom";
-
-// Returns 1 if in (in binary) > ct
-
-template CompConstant(ct) {
- signal input in[254];
- signal output out;
-
- signal parts[127];
- signal sout;
-
- var clsb;
- var cmsb;
- var slsb;
- var smsb;
-
- var sum=0;
-
- var b = (1 << 128) -1;
- var a = 1;
- var e = 1;
- var i;
-
- for (i=0;i<127; i++) {
- clsb = (ct >> (i*2)) & 1;
- cmsb = (ct >> (i*2+1)) & 1;
- slsb = in[i*2];
- smsb = in[i*2+1];
-
- if ((cmsb==0)&&(clsb==0)) {
- parts[i] <== -b*smsb*slsb + b*smsb + b*slsb;
- } else if ((cmsb==0)&&(clsb==1)) {
- parts[i] <== a*smsb*slsb - a*slsb + b*smsb - a*smsb + a;
- } else if ((cmsb==1)&&(clsb==0)) {
- parts[i] <== b*smsb*slsb - a*smsb + a;
- } else {
- parts[i] <== -a*smsb*slsb + a;
- }
-
- sum = sum + parts[i];
-
- b = b -e;
- a = a +e;
- e = e*2;
- }
-
- sout <== sum;
-
- component num2bits = Num2Bits(135);
-
- num2bits.in <== sout;
-
- out <== num2bits.out[127];
-}
diff --git a/zk_prover/src/circom/circomlib/circuits/mux1.circom b/zk_prover/src/circom/circomlib/circuits/mux1.circom
deleted file mode 100644
index 444cb849..00000000
--- a/zk_prover/src/circom/circomlib/circuits/mux1.circom
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- Copyright 2018 0KIMS association.
-
- This file is part of circom (Zero Knowledge Circuit Compiler).
-
- circom is a free software: you can redistribute it and/or modify it
- under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- circom is distributed in the hope that it will be useful, but WITHOUT
- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
- License for more details.
-
- You should have received a copy of the GNU General Public License
- along with circom. If not, see .
-*/
-pragma circom 2.0.0;
-
-template MultiMux1(n) {
- signal input c[n][2]; // Constants
- signal input s; // Selector
- signal output out[n];
-
- for (var i=0; i mux.s;
-
- mux.out[0] ==> out;
-}
diff --git a/zk_prover/src/circom/circomlib/circuits/poseidon.circom b/zk_prover/src/circom/circomlib/circuits/poseidon.circom
deleted file mode 100644
index 1c45ab95..00000000
--- a/zk_prover/src/circom/circomlib/circuits/poseidon.circom
+++ /dev/null
@@ -1,208 +0,0 @@
-pragma circom 2.0.0;
-
-include "./poseidon_constants.circom";
-
-template Sigma() {
- signal input in;
- signal output out;
-
- signal in2;
- signal in4;
-
- in2 <== in*in;
- in4 <== in2*in2;
-
- out <== in4*in;
-}
-
-template Ark(t, C, r) {
- signal input in[t];
- signal output out[t];
-
- for (var i=0; i0) {
- ark[0].in[j] <== inputs[j-1];
- } else {
- ark[0].in[j] <== initialState;
- }
- }
-
- for (var r = 0; r < nRoundsF\2-1; r++) {
- for (var j=0; j