Skip to content

Commit

Permalink
Refactoring. V2.2.0 Circom Support (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
KyrylR authored Oct 31, 2024
1 parent 6440ff4 commit ca0f30f
Show file tree
Hide file tree
Showing 10 changed files with 273 additions and 122 deletions.
6 changes: 6 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,9 @@
[submodule "passport-zk-circuits"]
path = passport-zk-circuits
url = [email protected]:rarimo/passport-zk-circuits.git
[submodule "ed25519-circom"]
path = ed25519-circom
url = [email protected]:Electron-Labs/ed25519-circom.git
[submodule "maci"]
path = maci
url = [email protected]:privacy-scaling-explorations/maci.git
9 changes: 8 additions & 1 deletion base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,14 @@ import (

// TestParseAllCircuits recursively parses all circuit files in the directory
func TestParseAllCircuits(t *testing.T) {
baseDirs := []string{"iden3-circuits/circuits", "circomlib/circuits", "data", "passport-zk-circuits/circuits"}
baseDirs := []string{
"iden3-circuits/circuits",
"circomlib/circuits",
"data",
"passport-zk-circuits/circuits",
"ed25519-circom/circuits",
"maci/packages/circuits/circom",
}

for _, baseDir := range baseDirs {
err := filepath.Walk(baseDir, func(path string, info os.FileInfo, err error) error {
Expand Down
2 changes: 1 addition & 1 deletion circomlib
Submodule circomlib updated 1 files
+2 −1 test/binsum.js
9 changes: 9 additions & 0 deletions data/Example1.circom
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,16 @@ function nbits(a) {

template A(a, b, c) {}

function TestFunc() {
return [[1, 2, 3]];
}

template nbits(a) {
var i = 0;
for (kek.out[0] <-- 9; kek.out[0] < 10; i++) {}
for (9 --> kek.out[1]; kek.out[0] < 10; i++) {}
for (var some[1] = [0]; kek.out[0] < 10; i++) {}

var o_u_t;
var o$o;
var x[3] = [2,8,4];
Expand Down
74 changes: 74 additions & 0 deletions data/Example3.circom
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
bus B1(){
signal x;
}

bus B2() {
signal x;
}

template B1toB2(){
input B1() b1;
output B2() b2;
b2 <== b1;
}

bus Film() {
signal title[50];
signal director[50];
signal year;
}

bus Date() {
signal day;
signal month;
signal year;
}

bus Person() {
signal name[50];
Film() films[10];
Date() birthday;
}

bus Line(dim){
PointN(dim) start;
PointN(dim) end;
}

bus Figure(num_sides, dim){
Line(dim) side[num_sides];
}

bus Triangle2D(){
Figure(3,2) {well_defined} triangle;
}

bus Square3D(){
Figure(4,3) {well_defined} square;
}

template well_defined_figure(num_sides, dimension){
input Figure(num_sides,dimension) t;
output Figure(num_sides,dimension) {well_defined} correct_t;
var all_equals = 0;
var isequal = 0;
for(var i = 0; i < num_sides; i=i+1){
for(var j = 0; j < dimension; j=j+1){
isequal = IsEqual()([t.side[i].end.x[j],t.side[(i+1)%num_sides].start.x[j]]);
all_equals += isequal;
}
}
all_equals === num_sides;
correct_t <== t;
}

template Edwards2Montgomery () {
input Point() { edwards_point } in ;
output Point() { montgomery_point } out ;

out.x <-- (1 + in.y ) / (1 - in.y ) ;
out.y <-- out.x / in.x ;

out.x * (1 - in.y ) === (1 + in.y ) ;
out.y * in.x === out.x ;
}
1 change: 1 addition & 0 deletions ed25519-circom
Submodule ed25519-circom added at 99490f
17 changes: 11 additions & 6 deletions grammar/CircomLexer.g4
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
lexer grammar CircomLexer;

/*//////////////////////////////////////////////////////////////
COMMON STRUCTURES
COMMON STRUCTURES AND TERMINALS
//////////////////////////////////////////////////////////////*/

VERSION: NUMBER '.' NUMBER '.' NUMBER ;
Expand All @@ -22,6 +22,7 @@ INCLUDE: 'include' ;
CUSTOM: 'custom' ;
PARALLEL: 'parallel' ;

BUS: 'bus' ;
TEMPLATE: 'template' ;
FUNCTION: 'function' ;

Expand Down Expand Up @@ -75,8 +76,12 @@ TERNARY_CONDITION: '?' ;
TERNARY_ALTERNATIVE: ':' ;

EQ_CONSTRAINT: '===' ;
LEFT_CONSTRAINT: '<--' | '<==' ;
RIGHT_CONSTRAINT: '-->' | '==>' ;

LEFT_CONSTRAINT: '<==' ;
LEFT_ASSIGNMENT: '<--' ;

RIGHT_CONSTRAINT: '==>' ;
RIGHT_ASSIGNMENT: '-->' ;

// Unary operators
SELF_OP: '++' | '--' ;
Expand Down Expand Up @@ -118,17 +123,17 @@ OR: '||' ;
ASSIGNMENT: '=' ;
ASSIGNMENT_WITH_OP: '+=' | '-=' | '*=' | '**=' | '/=' | '\\=' | '%=' | '<<=' | '>>=' | '&=' | '^=' | '|=' ;

ID : ID_SYMBOL* LETTER (LETTER|DIGIT|ID_SYMBOL)*;
ID : ID_SYMBOL* LETTER (LETTER|ID_SYMBOL|DIGIT)* ; // r"[$_]*[a-zA-Z][a-zA-Z$_0-9]*"
fragment
LETTER : [a-zA-Z\u0080-\u00FF] ;
LETTER : [a-zA-Z] ;
fragment
ID_SYMBOL : [_$] ;

NUMBER: DIGIT+ | HEX;
fragment
DIGIT: [0-9] ;

HEX : '0' 'x' HEXDIGIT+ ;
HEX : '0' 'x' HEXDIGIT+ ; // 0x[0-9A-Fa-f]*
fragment
HEXDIGIT : ('0'..'9'|'a'..'f'|'A'..'F') ;

Expand Down
Loading

0 comments on commit ca0f30f

Please sign in to comment.