From 10484877f287eb1ca84eb8d5be7d67d6ad4bb520 Mon Sep 17 00:00:00 2001 From: Waylon Jepsen Date: Mon, 9 Sep 2024 12:23:03 -0600 Subject: [PATCH] replace local lib with official circomlib --- RowShifting.r1cs | Bin 248 -> 0 bytes circuits/aes-gcm/aes-gcm.circom | 74 ++ circuits/aes-gcm/component | 1 - circuits/aes-gcm/helper_functions.circom | 6 +- circuits/lib_circuits/aliascheck.circom | 33 - circuits/lib_circuits/binsum.circom | 101 -- circuits/lib_circuits/bitify.circom | 106 -- circuits/lib_circuits/comparators.circom | 141 --- circuits/lib_circuits/compconstant.circom | 74 -- circuits/lib_circuits/gates.circom | 96 -- circuits/lib_circuits/mux1.circom | 48 - circuits/lib_circuits/sha256.circom | 81 -- tsconfig.json | 10 + yarn.lock | 1208 +++++++++++++++++++++ 14 files changed, 1295 insertions(+), 684 deletions(-) delete mode 100644 RowShifting.r1cs create mode 100644 circuits/aes-gcm/aes-gcm.circom delete mode 100644 circuits/aes-gcm/component delete mode 100644 circuits/lib_circuits/aliascheck.circom delete mode 100644 circuits/lib_circuits/binsum.circom delete mode 100644 circuits/lib_circuits/bitify.circom delete mode 100644 circuits/lib_circuits/comparators.circom delete mode 100644 circuits/lib_circuits/compconstant.circom delete mode 100644 circuits/lib_circuits/gates.circom delete mode 100644 circuits/lib_circuits/mux1.circom delete mode 100644 circuits/lib_circuits/sha256.circom create mode 100644 tsconfig.json create mode 100644 yarn.lock diff --git a/RowShifting.r1cs b/RowShifting.r1cs deleted file mode 100644 index b1061e2e6080151df950b728edfad4298576af07..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 248 zcmXRiOfF_*U|?VdVkRJl0g#vjl%oKof&34Xzdm%HSg^Cw. -*/ -pragma circom 2.1.9; - -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/circuits/lib_circuits/binsum.circom b/circuits/lib_circuits/binsum.circom deleted file mode 100644 index 0d8fb24..0000000 --- a/circuits/lib_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.1.9; - -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/circuits/lib_circuits/bitify.circom b/circuits/lib_circuits/bitify.circom deleted file mode 100644 index a6345d7..0000000 --- a/circuits/lib_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.1.9; - -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/circuits/lib_circuits/comparators.circom b/circuits/lib_circuits/comparators.circom deleted file mode 100644 index 8c507a2..0000000 --- a/circuits/lib_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.1.9; - -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/circuits/lib_circuits/compconstant.circom b/circuits/lib_circuits/compconstant.circom deleted file mode 100644 index 21aae11..0000000 --- a/circuits/lib_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.1.9; - -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/circuits/lib_circuits/gates.circom b/circuits/lib_circuits/gates.circom deleted file mode 100644 index a5d0992..0000000 --- a/circuits/lib_circuits/gates.circom +++ /dev/null @@ -1,96 +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.1.9; - -template XOR() { - signal input a; - signal input b; - signal output out; - - out <== a + b - 2*a*b; -} - -template AND() { - signal input a; - signal input b; - signal output out; - - out <== a*b; -} - -template OR() { - signal input a; - signal input b; - signal output out; - - out <== a + b - a*b; -} - -template NOT() { - signal input in; - signal output out; - - out <== 1 + in - 2*in; -} - -template NAND() { - signal input a; - signal input b; - signal output out; - - out <== 1 - a*b; -} - -template NOR() { - signal input a; - signal input b; - signal output out; - - out <== a*b + 1 - a - b; -} - -template MultiAND(n) { - signal input in[n]; - signal output out; - component and1; - component and2; - component ands[2]; - if (n==1) { - out <== in[0]; - } else if (n==2) { - and1 = AND(); - and1.a <== in[0]; - and1.b <== in[1]; - out <== and1.out; - } else { - 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. -*/ -pragma circom 2.1.9; - -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/circuits/lib_circuits/sha256.circom b/circuits/lib_circuits/sha256.circom deleted file mode 100644 index 86d2e46..0000000 --- a/circuits/lib_circuits/sha256.circom +++ /dev/null @@ -1,81 +0,0 @@ -pragma circom 2.1.9; - -include "constants.circom"; -include "sha256compression.circom"; - -template Sha256(nBits) { - signal input in[nBits]; - signal output out[256]; - - var i; - var k; - var nBlocks; - var bitsLastBlock; - - - nBlocks = ((nBits + 64)\512)+1; - - signal paddedIn[nBlocks*512]; - - for (k=0; k> k)&1; - } - - component ha0 = H(0); - component hb0 = H(1); - component hc0 = H(2); - component hd0 = H(3); - component he0 = H(4); - component hf0 = H(5); - component hg0 = H(6); - component hh0 = H(7); - - component sha256compression[nBlocks]; - - for (i=0; i