-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add circom * add circom grammar * add circom grammar * Apply suggestions from code review Co-authored-by: Colin Seymour <colin@github.com> * fix CI --------- Co-authored-by: Colin Seymour <colin@github.com>
- Loading branch information
1 parent
e5533fa
commit 2e9ce8b
Showing
9 changed files
with
235 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
/* | ||
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 <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
/* | ||
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<a) { | ||
r++; | ||
n *= 2; | ||
} | ||
return r; | ||
} | ||
|
||
|
||
template BinSum(n, ops) { | ||
var nout = nbits((2**n -1)*ops); | ||
signal input in[ops][n]; | ||
signal output out[nout]; | ||
|
||
var lin = 0; | ||
var lout = 0; | ||
|
||
var k; | ||
var j; | ||
|
||
var e2; | ||
|
||
e2 = 1; | ||
for (k=0; k<n; k++) { | ||
for (j=0; j<ops; j++) { | ||
lin += in[j][k] * e2; | ||
} | ||
e2 = e2 + e2; | ||
} | ||
|
||
e2 = 1; | ||
for (k=0; k<nout; k++) { | ||
out[k] <-- (lin >> k) & 1; | ||
|
||
// Ensure out is binary | ||
out[k] * (out[k] - 1) === 0; | ||
|
||
lout += out[k] * e2; | ||
|
||
e2 = e2+e2; | ||
} | ||
|
||
// Ensure the sum; | ||
|
||
lin === lout; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
|
||
/* | ||
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 <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
/* | ||
Assume sel is binary. | ||
If sel == 0 then outL = L and outR=R | ||
If sel == 1 then outL = R and outR=L | ||
*/ | ||
|
||
pragma circom 2.0.0; | ||
|
||
template Switcher() { | ||
signal input sel; | ||
signal input L; | ||
signal input R; | ||
signal output outL; | ||
signal output outR; | ||
|
||
signal aux; | ||
|
||
aux <== (R-L)*sel; // We create aux in order to have only one multiplication | ||
outL <== aux + L; | ||
outR <== -aux + R; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
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 <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
/* Xor3 function for sha256 | ||
out = a ^ b ^ c => | ||
out = a+b+c - 2*a*b - 2*a*c - 2*b*c + 4*a*b*c => | ||
out = a*( 1 - 2*b - 2*c + 4*b*c ) + b + c - 2*b*c => | ||
mid = b*c | ||
out = a*( 1 - 2*b -2*c + 4*mid ) + b + c - 2 * mid | ||
*/ | ||
pragma circom 2.0.0; | ||
|
||
template Xor3(n) { | ||
signal input a[n]; | ||
signal input b[n]; | ||
signal input c[n]; | ||
signal output out[n]; | ||
signal mid[n]; | ||
|
||
for (var k=0; k<n; k++) { | ||
mid[k] <== b[k]*c[k]; | ||
out[k] <== a[k] * (1 -2*b[k] -2*c[k] +4*mid[k]) + b[k] + c[k] -2*mid[k]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule circom-highlighting-vscode
added at
1e292d
31 changes: 31 additions & 0 deletions
31
vendor/licenses/git_submodule/circom-highlighting-vscode.dep.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
--- | ||
name: circom-highlighting-vscode | ||
version: 1e292d5457d9ba3a3e9832b5e4378cdd65a6cfb7 | ||
type: git_submodule | ||
homepage: https://github.com/iden3/circom-highlighting-vscode.git | ||
license: mit | ||
licenses: | ||
- sources: COPYING | ||
text: |- | ||
MIT License | ||
Copyright (c) 2022 0Kims Association <https://0kims.org> | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. | ||
notices: [] |