From 7efeb3bdec6723c094cf068c5846cd0f1a1ceade Mon Sep 17 00:00:00 2001 From: Kyryl Riabov Date: Mon, 14 Oct 2024 15:51:26 +0300 Subject: [PATCH 1/5] Optimized grammar. Fixed bug with component array access --- .gitignore | 3 ++- .gitmodules | 3 +++ base_test.go | 2 +- grammar/Circom.g4 | 38 ++++++++++++++++++++++---------------- passport-zk-circuits | 1 + 5 files changed, 29 insertions(+), 18 deletions(-) create mode 160000 passport-zk-circuits diff --git a/.gitignore b/.gitignore index af5234d..c287f45 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,5 @@ dist !parser/generate.go parser/* -iden3-circuits \ No newline at end of file +iden3-circuits +test-data \ No newline at end of file diff --git a/.gitmodules b/.gitmodules index abaf051..77bc779 100644 --- a/.gitmodules +++ b/.gitmodules @@ -4,3 +4,6 @@ [submodule "circomlib"] path = circomlib url = https://github.com/iden3/circomlib.git +[submodule "passport-zk-circuits"] + path = passport-zk-circuits + url = git@github.com:rarimo/passport-zk-circuits.git diff --git a/base_test.go b/base_test.go index 5c2738a..dab1b8a 100644 --- a/base_test.go +++ b/base_test.go @@ -9,7 +9,7 @@ import ( // TestParseAllCircuits recursively parses all circuit files in the directory func TestParseAllCircuits(t *testing.T) { - baseDirs := []string{"iden3-circuits/circuits", "circomlib/circuits", "data"} + baseDirs := []string{"iden3-circuits/circuits", "circomlib/circuits", "data", "passport-zk-circuits/circuits"} for _, baseDir := range baseDirs { err := filepath.Walk(baseDir, func(path string, info os.FileInfo, err error) error { diff --git a/grammar/Circom.g4 b/grammar/Circom.g4 index 109392f..c65e87d 100644 --- a/grammar/Circom.g4 +++ b/grammar/Circom.g4 @@ -30,17 +30,17 @@ functionBlock ; functionStmt - : functionBlock #FuncBlock - | ID SELF_OP ';' #FuncSelfOp - | varDeclaration ';' #FuncVarDeclaration - | identifier (ASSIGNMENT | ASSIGNMENT_OP) expression ';' #FuncAssignmentExpression - | '(' argsWithUnderscore ')' ASSIGNMENT expression ';' #FuncVariadicAssignment - | 'if' parExpression functionStmt ('else' functionStmt)? #IfFuncStmt - | 'while' parExpression functionStmt #WhileFuncStmt - | 'for' '(' forControl ')' functionStmt #ForFuncStmt - | 'return' expression ';' #ReturnFuncStmt - | 'assert' parExpression ';' #AssertFuncStmt - | logStmt ';' #LogFuncStmt + : functionBlock #FuncBlock + | ID SELF_OP ';' #FuncSelfOp + | varDeclaration ';' #FuncVarDeclaration + | identifier (ASSIGNMENT | ASSIGNMENT_OP) expression ';' #FuncAssignmentExpression + | '(' argsWithUnderscore ')' ASSIGNMENT ('(' expressionList ')' | expression) ';' #FuncVariadicAssignment + | 'if' parExpression functionStmt ('else' functionStmt)? #IfFuncStmt + | 'while' parExpression functionStmt #WhileFuncStmt + | 'for' '(' forControl ')' functionStmt #ForFuncStmt + | 'return' expression ';' #ReturnFuncStmt + | 'assert' parExpression ';' #AssertFuncStmt + | logStmt ';' #LogFuncStmt ; templateDeclaration @@ -66,15 +66,15 @@ templateStmt | signalDeclaration ';' | componentDeclaration ';' | blockInstantiation ';' - | (identifier ('.' ID)?) ASSIGNMENT expression ';' + | identifier ASSIGNMENT expression ';' | expression CONSTRAINT_EQ expression ';' | element (LEFT_ASSIGNMENT | ASSIGNMENT_OP) expression ';' - | '(' element (',' element)* ')' LEFT_ASSIGNMENT expression ';' + | '(' element (',' element)* ')' LEFT_ASSIGNMENT '(' expression (',' expression)* ')' ';' | expression RIGHT_ASSIGNMENT element ';' | expression RIGHT_ASSIGNMENT '(' element (',' element)* ')' ';' | '_' (ASSIGNMENT | LEFT_ASSIGNMENT) (expression | blockInstantiation) ';' | (expression | blockInstantiation) RIGHT_ASSIGNMENT '_' ';' - | '(' argsWithUnderscore ')' (ASSIGNMENT | LEFT_ASSIGNMENT) (blockInstantiation | expression) ';' + | '(' argsWithUnderscore ')' (ASSIGNMENT | LEFT_ASSIGNMENT) ('(' expressionList ')' | blockInstantiation | expression) ';' | blockInstantiation RIGHT_ASSIGNMENT '(' argsWithUnderscore ')' ';' | 'if' parExpression templateStmt ('else' templateStmt)? | 'while' parExpression templateStmt @@ -144,7 +144,11 @@ varDeclaration | varDefinition (',' identifier)* ; -rhsValue: expression | blockInstantiation ; +rhsValue + : '(' expressionList ')' + | expression + | blockInstantiation + ; componentCall : '(' expressionList? ')' @@ -156,7 +160,9 @@ blockInstantiation: 'parallel'? ID '(' expressionList? ')' componentCall? ; expressionList: expression (',' expression)* ; -identifier: (ID | (ID '.' ID)) arrayDimension* ; +identifier + : ID arrayDimension* ('.' ID)? arrayDimension* + ; arrayDimension: '[' expression ']' ; diff --git a/passport-zk-circuits b/passport-zk-circuits new file mode 160000 index 0000000..eddba80 --- /dev/null +++ b/passport-zk-circuits @@ -0,0 +1 @@ +Subproject commit eddba80ea73d2f9ed2dcae73ae62fe47c4cf6442 From 8c5780607cb7fada35e18d3c62c1bedd305c404a Mon Sep 17 00:00:00 2001 From: Kyryl Riabov Date: Mon, 14 Oct 2024 15:55:53 +0300 Subject: [PATCH 2/5] Updated submodule --- passport-zk-circuits | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/passport-zk-circuits b/passport-zk-circuits index eddba80..6fae74b 160000 --- a/passport-zk-circuits +++ b/passport-zk-circuits @@ -1 +1 @@ -Subproject commit eddba80ea73d2f9ed2dcae73ae62fe47c4cf6442 +Subproject commit 6fae74b7f60707f6816255d70776623c9405cf96 From 0a392df991dbb1b09444ef5bf0964105e5892ce9 Mon Sep 17 00:00:00 2001 From: Kyryl Riabov Date: Mon, 14 Oct 2024 16:13:45 +0300 Subject: [PATCH 3/5] Fix typo. More optimizations --- grammar/Circom.g4 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/grammar/Circom.g4 b/grammar/Circom.g4 index c65e87d..8e922cd 100644 --- a/grammar/Circom.g4 +++ b/grammar/Circom.g4 @@ -31,7 +31,7 @@ functionBlock functionStmt : functionBlock #FuncBlock - | ID SELF_OP ';' #FuncSelfOp + | ID arrayDimension* SELF_OP ';' #FuncSelfOp | varDeclaration ';' #FuncVarDeclaration | identifier (ASSIGNMENT | ASSIGNMENT_OP) expression ';' #FuncAssignmentExpression | '(' argsWithUnderscore ')' ASSIGNMENT ('(' expressionList ')' | expression) ';' #FuncVariadicAssignment @@ -61,7 +61,7 @@ publicInputsList templateStmt : templateBlock - | ID SELF_OP ';' + | ID arrayDimension* SELF_OP ';' | varDeclaration ';' | signalDeclaration ';' | componentDeclaration ';' @@ -161,7 +161,7 @@ blockInstantiation: 'parallel'? ID '(' expressionList? ')' componentCall? ; expressionList: expression (',' expression)* ; identifier - : ID arrayDimension* ('.' ID)? arrayDimension* + : ID arrayDimension* ('.' ID)? arrayDimension* ; arrayDimension: '[' expression ']' ; From 0b0677114cee8c45e8e88465eaa9220e5674bbc8 Mon Sep 17 00:00:00 2001 From: Kyryl Riabov Date: Mon, 14 Oct 2024 16:18:41 +0300 Subject: [PATCH 4/5] Fix typo --- grammar/Circom.g4 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/grammar/Circom.g4 b/grammar/Circom.g4 index 8e922cd..4562d65 100644 --- a/grammar/Circom.g4 +++ b/grammar/Circom.g4 @@ -31,7 +31,7 @@ functionBlock functionStmt : functionBlock #FuncBlock - | ID arrayDimension* SELF_OP ';' #FuncSelfOp + | ID arrayDimension* SELF_OP ';' #FuncSelfOp | varDeclaration ';' #FuncVarDeclaration | identifier (ASSIGNMENT | ASSIGNMENT_OP) expression ';' #FuncAssignmentExpression | '(' argsWithUnderscore ')' ASSIGNMENT ('(' expressionList ')' | expression) ';' #FuncVariadicAssignment From 95aa58bb31fe790d3ff53a1a17c6a920e331fad2 Mon Sep 17 00:00:00 2001 From: Kyryl Riabov Date: Mon, 14 Oct 2024 16:19:23 +0300 Subject: [PATCH 5/5] Updated submodule --- passport-zk-circuits | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/passport-zk-circuits b/passport-zk-circuits index 6fae74b..15c7217 160000 --- a/passport-zk-circuits +++ b/passport-zk-circuits @@ -1 +1 @@ -Subproject commit 6fae74b7f60707f6816255d70776623c9405cf96 +Subproject commit 15c721785b56e69e394475fa7382b8b625e05a0f