Skip to content

Commit

Permalink
Fix email address regex
Browse files Browse the repository at this point in the history
  • Loading branch information
SoraSuegami committed Aug 30, 2024
1 parent 9db767d commit f71b30b
Show file tree
Hide file tree
Showing 14 changed files with 301 additions and 291 deletions.
2 changes: 1 addition & 1 deletion packages/apis/src/decomposed_defs/email_addr.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"parts": [
{
"is_public": true,
"regex_def": "[A-Za-z0-9!#$%&'*+=?\\-\\^_`{|}~.@]+@[A-Za-z0-9.\\-]+"
"regex_def": "[A-Za-z0-9!#$%&'*+=?\\-\\^_`{|}~./@]+@[A-Za-z0-9.\\-]+"
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
},
{
"is_public": true,
"regex_def": "[A-Za-z0-9!#$%&'*+=?\\-\\^_`{|}~.@]+@[a-zA-Z0-9_.\\-]+"
"regex_def": "[A-Za-z0-9!#$%&'*+=?\\-\\^_`{|}~./@]+@[a-zA-Z0-9.\\-]+"
},
{
"is_public": false,
Expand Down
2 changes: 1 addition & 1 deletion packages/apis/src/decomposed_defs/email_domain.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"parts": [
{
"is_public": false,
"regex_def": "[A-Za-z0-9!#$%&'*+=?\\-\\^_`{|}~.]+@"
"regex_def": "[A-Za-z0-9!#$%&'*+=?\\-\\^_`{|}~./]+@"
},
{
"is_public": true,
Expand Down
2 changes: 1 addition & 1 deletion packages/apis/src/decomposed_defs/from_addr.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
},
{
"is_public": true,
"regex_def": "[A-Za-z0-9!#$%&'*+=?\\-\\^_`{|}~.@]+@[A-Za-z0-9.\\-]+"
"regex_def": "[A-Za-z0-9!#$%&'*+=?\\-\\^_`{|}~./@]+@[A-Za-z0-9.\\-]+"
},
{
"is_public": false,
Expand Down
2 changes: 1 addition & 1 deletion packages/apis/src/decomposed_defs/to_addr.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
},
{
"is_public": true,
"regex_def": "[A-Za-z0-9!#$%&'*+=?\\-\\^_`{|}~.@]+@[a-zA-Z0-9_.\\-]+"
"regex_def": "[A-Za-z0-9!#$%&'*+=?\\-\\^_`{|}~./@]+@[a-zA-Z0-9.\\-]+"
},
{
"is_public": false,
Expand Down
2 changes: 1 addition & 1 deletion packages/circom/circuits/common/email_addr.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"parts": [
{
"is_public": true,
"regex_def": "[A-Za-z0-9!#$%&'*+=?\\-\\^_`{|}~.@]+@[A-Za-z0-9.\\-]+"
"regex_def": "[A-Za-z0-9!#$%&'*+=?\\-\\^_`{|}~./@]+@[A-Za-z0-9.\\-]+"
}
]
}
96 changes: 51 additions & 45 deletions packages/circom/circuits/common/email_addr_regex.circom
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ pragma circom 2.1.5;

include "@zk-email/zk-regex-circom/circuits/regex_helpers.circom";

// regex: [A-Za-z0-9!#$%&'*+=?\-\^_`{|}~.@]+@[A-Za-z0-9.\-]+
// regex: [A-Za-z0-9!#$%&'*+=?\-\^_`{|}~./@]+@[A-Za-z0-9.\-]+
template EmailAddrRegex(msg_bytes) {
signal input msg[msg_bytes];
signal output out;
Expand All @@ -14,7 +14,7 @@ template EmailAddrRegex(msg_bytes) {
in[i+1] <== msg[i];
}

component eq[30][num_bytes];
component eq[31][num_bytes];
component lt[8][num_bytes];
component and[13][num_bytes];
component multi_or[7][num_bytes];
Expand Down Expand Up @@ -81,40 +81,43 @@ template EmailAddrRegex(msg_bytes) {
eq[9][i].in[1] <== 46;
eq[10][i] = IsEqual();
eq[10][i].in[0] <== in[i];
eq[10][i].in[1] <== 48;
eq[10][i].in[1] <== 47;
eq[11][i] = IsEqual();
eq[11][i].in[0] <== in[i];
eq[11][i].in[1] <== 49;
eq[11][i].in[1] <== 48;
eq[12][i] = IsEqual();
eq[12][i].in[0] <== in[i];
eq[12][i].in[1] <== 50;
eq[12][i].in[1] <== 49;
eq[13][i] = IsEqual();
eq[13][i].in[0] <== in[i];
eq[13][i].in[1] <== 51;
eq[13][i].in[1] <== 50;
eq[14][i] = IsEqual();
eq[14][i].in[0] <== in[i];
eq[14][i].in[1] <== 52;
eq[14][i].in[1] <== 51;
eq[15][i] = IsEqual();
eq[15][i].in[0] <== in[i];
eq[15][i].in[1] <== 53;
eq[15][i].in[1] <== 52;
eq[16][i] = IsEqual();
eq[16][i].in[0] <== in[i];
eq[16][i].in[1] <== 54;
eq[16][i].in[1] <== 53;
eq[17][i] = IsEqual();
eq[17][i].in[0] <== in[i];
eq[17][i].in[1] <== 55;
eq[17][i].in[1] <== 54;
eq[18][i] = IsEqual();
eq[18][i].in[0] <== in[i];
eq[18][i].in[1] <== 56;
eq[18][i].in[1] <== 55;
eq[19][i] = IsEqual();
eq[19][i].in[0] <== in[i];
eq[19][i].in[1] <== 57;
eq[19][i].in[1] <== 56;
eq[20][i] = IsEqual();
eq[20][i].in[0] <== in[i];
eq[20][i].in[1] <== 61;
eq[20][i].in[1] <== 57;
eq[21][i] = IsEqual();
eq[21][i].in[0] <== in[i];
eq[21][i].in[1] <== 61;
and[2][i] = AND();
and[2][i].a <== states[i][0];
multi_or[0][i] = MultiOR(23);
multi_or[0][i] = MultiOR(24);
multi_or[0][i].in[0] <== and[0][i].out;
multi_or[0][i].in[1] <== and[1][i].out;
multi_or[0][i].in[2] <== eq[0][i].out;
Expand All @@ -138,6 +141,7 @@ template EmailAddrRegex(msg_bytes) {
multi_or[0][i].in[20] <== eq[18][i].out;
multi_or[0][i].in[21] <== eq[19][i].out;
multi_or[0][i].in[22] <== eq[20][i].out;
multi_or[0][i].in[23] <== eq[21][i].out;
and[2][i].b <== multi_or[0][i].out;
lt[4][i] = LessEqThan(8);
lt[4][i].in[0] <== 65;
Expand All @@ -148,12 +152,12 @@ template EmailAddrRegex(msg_bytes) {
and[3][i] = AND();
and[3][i].a <== lt[4][i].out;
and[3][i].b <== lt[5][i].out;
eq[21][i] = IsEqual();
eq[21][i].in[0] <== in[i];
eq[21][i].in[1] <== 63;
eq[22][i] = IsEqual();
eq[22][i].in[0] <== in[i];
eq[22][i].in[1] <== 63;
and[4][i] = AND();
and[4][i].a <== states[i][1];
multi_or[1][i] = MultiOR(24);
multi_or[1][i] = MultiOR(25);
multi_or[1][i].in[0] <== and[3][i].out;
multi_or[1][i].in[1] <== and[1][i].out;
multi_or[1][i].in[2] <== eq[0][i].out;
Expand All @@ -178,31 +182,32 @@ template EmailAddrRegex(msg_bytes) {
multi_or[1][i].in[21] <== eq[19][i].out;
multi_or[1][i].in[22] <== eq[20][i].out;
multi_or[1][i].in[23] <== eq[21][i].out;
multi_or[1][i].in[24] <== eq[22][i].out;
and[4][i].b <== multi_or[1][i].out;
eq[22][i] = IsEqual();
eq[22][i].in[0] <== in[i];
eq[22][i].in[1] <== 94;
eq[23][i] = IsEqual();
eq[23][i].in[0] <== in[i];
eq[23][i].in[1] <== 95;
eq[23][i].in[1] <== 94;
eq[24][i] = IsEqual();
eq[24][i].in[0] <== in[i];
eq[24][i].in[1] <== 96;
eq[24][i].in[1] <== 95;
eq[25][i] = IsEqual();
eq[25][i].in[0] <== in[i];
eq[25][i].in[1] <== 123;
eq[25][i].in[1] <== 96;
eq[26][i] = IsEqual();
eq[26][i].in[0] <== in[i];
eq[26][i].in[1] <== 124;
eq[26][i].in[1] <== 123;
eq[27][i] = IsEqual();
eq[27][i].in[0] <== in[i];
eq[27][i].in[1] <== 125;
eq[27][i].in[1] <== 124;
eq[28][i] = IsEqual();
eq[28][i].in[0] <== in[i];
eq[28][i].in[1] <== 126;
eq[28][i].in[1] <== 125;
eq[29][i] = IsEqual();
eq[29][i].in[0] <== in[i];
eq[29][i].in[1] <== 126;
and[5][i] = AND();
and[5][i].a <== states[i][2];
multi_or[2][i] = MultiOR(17);
multi_or[2][i] = MultiOR(18);
multi_or[2][i].in[0] <== eq[0][i].out;
multi_or[2][i].in[1] <== eq[1][i].out;
multi_or[2][i].in[2] <== eq[2][i].out;
Expand All @@ -211,7 +216,7 @@ template EmailAddrRegex(msg_bytes) {
multi_or[2][i].in[5] <== eq[5][i].out;
multi_or[2][i].in[6] <== eq[6][i].out;
multi_or[2][i].in[7] <== eq[7][i].out;
multi_or[2][i].in[8] <== eq[20][i].out;
multi_or[2][i].in[8] <== eq[10][i].out;
multi_or[2][i].in[9] <== eq[21][i].out;
multi_or[2][i].in[10] <== eq[22][i].out;
multi_or[2][i].in[11] <== eq[23][i].out;
Expand All @@ -220,6 +225,7 @@ template EmailAddrRegex(msg_bytes) {
multi_or[2][i].in[14] <== eq[26][i].out;
multi_or[2][i].in[15] <== eq[27][i].out;
multi_or[2][i].in[16] <== eq[28][i].out;
multi_or[2][i].in[17] <== eq[29][i].out;
and[5][i].b <== multi_or[2][i].out;
and[6][i] = AND();
and[6][i].a <== states[i][3];
Expand All @@ -229,18 +235,18 @@ template EmailAddrRegex(msg_bytes) {
multi_or[3][i].in[1] <== and[5][i].out;
multi_or[3][i].in[2] <== and[6][i].out;
states_tmp[i+1][1] <== multi_or[3][i].out;
eq[29][i] = IsEqual();
eq[29][i].in[0] <== in[i];
eq[29][i].in[1] <== 64;
eq[30][i] = IsEqual();
eq[30][i].in[0] <== in[i];
eq[30][i].in[1] <== 64;
and[7][i] = AND();
and[7][i].a <== states[i][1];
and[7][i].b <== eq[29][i].out;
and[7][i].b <== eq[30][i].out;
and[8][i] = AND();
and[8][i].a <== states[i][2];
and[8][i].b <== eq[29][i].out;
and[8][i].b <== eq[30][i].out;
and[9][i] = AND();
and[9][i].a <== states[i][3];
and[9][i].b <== eq[29][i].out;
and[9][i].b <== eq[30][i].out;
multi_or[4][i] = MultiOR(3);
multi_or[4][i].in[0] <== and[7][i].out;
multi_or[4][i].in[1] <== and[8][i].out;
Expand All @@ -262,16 +268,16 @@ template EmailAddrRegex(msg_bytes) {
multi_or[5][i].in[1] <== and[10][i].out;
multi_or[5][i].in[2] <== eq[8][i].out;
multi_or[5][i].in[3] <== eq[9][i].out;
multi_or[5][i].in[4] <== eq[10][i].out;
multi_or[5][i].in[5] <== eq[11][i].out;
multi_or[5][i].in[6] <== eq[12][i].out;
multi_or[5][i].in[7] <== eq[13][i].out;
multi_or[5][i].in[8] <== eq[14][i].out;
multi_or[5][i].in[9] <== eq[15][i].out;
multi_or[5][i].in[10] <== eq[16][i].out;
multi_or[5][i].in[11] <== eq[17][i].out;
multi_or[5][i].in[12] <== eq[18][i].out;
multi_or[5][i].in[13] <== eq[19][i].out;
multi_or[5][i].in[4] <== eq[11][i].out;
multi_or[5][i].in[5] <== eq[12][i].out;
multi_or[5][i].in[6] <== eq[13][i].out;
multi_or[5][i].in[7] <== eq[14][i].out;
multi_or[5][i].in[8] <== eq[15][i].out;
multi_or[5][i].in[9] <== eq[16][i].out;
multi_or[5][i].in[10] <== eq[17][i].out;
multi_or[5][i].in[11] <== eq[18][i].out;
multi_or[5][i].in[12] <== eq[19][i].out;
multi_or[5][i].in[13] <== eq[20][i].out;
and[11][i].b <== multi_or[5][i].out;
and[12][i] = AND();
and[12][i].a <== states[i][3];
Expand Down
2 changes: 1 addition & 1 deletion packages/circom/circuits/common/email_addr_with_name.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
},
{
"is_public": true,
"regex_def": "[A-Za-z0-9!#$%&'*+=?\\-\\^_`{|}~.@]+@[a-zA-Z0-9_.\\-]+"
"regex_def": "[A-Za-z0-9!#$%&'*+=?\\-\\^_`{|}~./@]+@[a-zA-Z0-9.\\-]+"
},
{
"is_public": false,
Expand Down
Loading

0 comments on commit f71b30b

Please sign in to comment.