From a36df338f84c13bdfdd6ff190d6fbee4412c9d19 Mon Sep 17 00:00:00 2001 From: SoraSuegami Date: Mon, 26 Aug 2024 22:25:26 +0900 Subject: [PATCH 1/4] fixing email address regex --- .../circom/circuits/common/email_addr.json | 4 +- .../circuits/common/email_addr_regex.circom | 69 +- .../circuits/common/email_addr_with_name.json | 2 +- .../common/email_addr_with_name_regex.circom | 814 +++++++++--------- .../circom/circuits/common/from_addr.json | 4 +- .../circuits/common/from_all_regex.circom | 532 ++++++------ .../circuits/common/subject_all_regex.circom | 532 ++++++------ packages/circom/circuits/common/to_addr.json | 4 +- .../circuits/common/to_all_regex.circom | 532 ++++++------ .../circom/tests/circuits/caret5_regex.circom | 384 ++++----- .../circom/tests/circuits/dot1_regex.circom | 410 ++++----- .../circom/tests/circuits/dot2_regex.circom | 404 ++++----- .../international_chars_decomposed.circom | 100 +-- .../invitation_code_with_prefix_regex.circom | 46 +- .../tests/circuits/negate1_regex.circom | 484 +++++------ .../tests/circuits/negate2_regex.circom | 316 +++---- .../circom/tests/circuits/plus4_regex.circom | 38 +- 17 files changed, 2338 insertions(+), 2337 deletions(-) diff --git a/packages/circom/circuits/common/email_addr.json b/packages/circom/circuits/common/email_addr.json index ed2489e..09a363c 100644 --- a/packages/circom/circuits/common/email_addr.json +++ b/packages/circom/circuits/common/email_addr.json @@ -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.\\-]+" } ] -} +} \ No newline at end of file diff --git a/packages/circom/circuits/common/email_addr_regex.circom b/packages/circom/circuits/common/email_addr_regex.circom index b42d937..fc8e062 100644 --- a/packages/circom/circuits/common/email_addr_regex.circom +++ b/packages/circom/circuits/common/email_addr_regex.circom @@ -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; @@ -75,46 +75,49 @@ template EmailAddrRegex(msg_bytes) { eq[7][i].in[1] <== 43; eq[8][i] = IsEqual(); eq[8][i].in[0] <== in[i]; - eq[8][i].in[1] <== 46; + eq[8][i].in[1] <== 45; eq[9][i] = IsEqual(); eq[9][i].in[0] <== in[i]; - eq[9][i].in[1] <== 48; + eq[9][i].in[1] <== 46; eq[10][i] = IsEqual(); eq[10][i].in[0] <== in[i]; - eq[10][i].in[1] <== 49; + eq[10][i].in[1] <== 48; eq[11][i] = IsEqual(); eq[11][i].in[0] <== in[i]; - eq[11][i].in[1] <== 50; + eq[11][i].in[1] <== 49; eq[12][i] = IsEqual(); eq[12][i].in[0] <== in[i]; - eq[12][i].in[1] <== 51; + eq[12][i].in[1] <== 50; eq[13][i] = IsEqual(); eq[13][i].in[0] <== in[i]; - eq[13][i].in[1] <== 52; + eq[13][i].in[1] <== 51; eq[14][i] = IsEqual(); eq[14][i].in[0] <== in[i]; - eq[14][i].in[1] <== 53; + eq[14][i].in[1] <== 52; eq[15][i] = IsEqual(); eq[15][i].in[0] <== in[i]; - eq[15][i].in[1] <== 54; + eq[15][i].in[1] <== 53; eq[16][i] = IsEqual(); eq[16][i].in[0] <== in[i]; - eq[16][i].in[1] <== 55; + eq[16][i].in[1] <== 54; eq[17][i] = IsEqual(); eq[17][i].in[0] <== in[i]; - eq[17][i].in[1] <== 56; + eq[17][i].in[1] <== 55; eq[18][i] = IsEqual(); eq[18][i].in[0] <== in[i]; - eq[18][i].in[1] <== 57; + eq[18][i].in[1] <== 56; eq[19][i] = IsEqual(); eq[19][i].in[0] <== in[i]; - eq[19][i].in[1] <== 61; + eq[19][i].in[1] <== 57; eq[20][i] = IsEqual(); eq[20][i].in[0] <== in[i]; - eq[20][i].in[1] <== 63; + eq[20][i].in[1] <== 61; + eq[21][i] = IsEqual(); + eq[21][i].in[0] <== in[i]; + eq[21][i].in[1] <== 63; 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; @@ -138,17 +141,18 @@ 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; and[3][i] = AND(); and[3][i].a <== states[i][1]; and[3][i].b <== multi_or[0][i].out; states_tmp[i+1][1] <== and[3][i].out; - eq[21][i] = IsEqual(); - eq[21][i].in[0] <== in[i]; - eq[21][i].in[1] <== 64; + eq[22][i] = IsEqual(); + eq[22][i].in[0] <== in[i]; + eq[22][i].in[1] <== 64; and[4][i] = AND(); and[4][i].a <== states[i][1]; - and[4][i].b <== eq[21][i].out; + and[4][i].b <== eq[22][i].out; states[i+1][2] <== and[4][i].out; lt[4][i] = LessEqThan(8); lt[4][i].in[0] <== 97; @@ -159,26 +163,23 @@ template EmailAddrRegex(msg_bytes) { and[5][i] = AND(); and[5][i].a <== lt[4][i].out; and[5][i].b <== lt[5][i].out; - eq[22][i] = IsEqual(); - eq[22][i].in[0] <== in[i]; - eq[22][i].in[1] <== 45; and[6][i] = AND(); and[6][i].a <== states[i][2]; multi_or[1][i] = MultiOR(14); multi_or[1][i].in[0] <== and[0][i].out; multi_or[1][i].in[1] <== and[5][i].out; - multi_or[1][i].in[2] <== eq[22][i].out; - multi_or[1][i].in[3] <== eq[8][i].out; - multi_or[1][i].in[4] <== eq[9][i].out; - multi_or[1][i].in[5] <== eq[10][i].out; - multi_or[1][i].in[6] <== eq[11][i].out; - multi_or[1][i].in[7] <== eq[12][i].out; - multi_or[1][i].in[8] <== eq[13][i].out; - multi_or[1][i].in[9] <== eq[14][i].out; - multi_or[1][i].in[10] <== eq[15][i].out; - multi_or[1][i].in[11] <== eq[16][i].out; - multi_or[1][i].in[12] <== eq[17][i].out; - multi_or[1][i].in[13] <== eq[18][i].out; + multi_or[1][i].in[2] <== eq[8][i].out; + multi_or[1][i].in[3] <== eq[9][i].out; + multi_or[1][i].in[4] <== eq[10][i].out; + multi_or[1][i].in[5] <== eq[11][i].out; + multi_or[1][i].in[6] <== eq[12][i].out; + multi_or[1][i].in[7] <== eq[13][i].out; + multi_or[1][i].in[8] <== eq[14][i].out; + multi_or[1][i].in[9] <== eq[15][i].out; + multi_or[1][i].in[10] <== eq[16][i].out; + multi_or[1][i].in[11] <== eq[17][i].out; + multi_or[1][i].in[12] <== eq[18][i].out; + multi_or[1][i].in[13] <== eq[19][i].out; and[6][i].b <== multi_or[1][i].out; and[7][i] = AND(); and[7][i].a <== states[i][3]; diff --git a/packages/circom/circuits/common/email_addr_with_name.json b/packages/circom/circuits/common/email_addr_with_name.json index d1bd578..1039792 100644 --- a/packages/circom/circuits/common/email_addr_with_name.json +++ b/packages/circom/circuits/common/email_addr_with_name.json @@ -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, diff --git a/packages/circom/circuits/common/email_addr_with_name_regex.circom b/packages/circom/circuits/common/email_addr_with_name_regex.circom index 0ac23ef..5a0aa8a 100644 --- a/packages/circom/circuits/common/email_addr_with_name_regex.circom +++ b/packages/circom/circuits/common/email_addr_with_name_regex.circom @@ -2,7 +2,7 @@ pragma circom 2.1.5; include "@zk-email/zk-regex-circom/circuits/regex_helpers.circom"; -// regex: [^\r\n]+<[a-zA-Z0-9!#$%&'*+-/=?^_`{\|}~\.]+@[a-zA-Z0-9_\.-]+> +// regex: [^\r\n]+<[A-Za-z0-9!#$%&'*+=?\-\^_`{|}~.]+@[a-zA-Z0-9_.\-]+> template EmailAddrWithNameRegex(msg_bytes) { signal input msg[msg_bytes]; signal output out; @@ -32,491 +32,499 @@ template EmailAddrWithNameRegex(msg_bytes) { state_changed[i] = MultiOR(13); states[i][0] <== 1; lt[0][i] = LessEqThan(8); - lt[0][i].in[0] <== 194; + lt[0][i].in[0] <== 14; lt[0][i].in[1] <== in[i]; lt[1][i] = LessEqThan(8); lt[1][i].in[0] <== in[i]; - lt[1][i].in[1] <== 223; + lt[1][i].in[1] <== 127; and[0][i] = AND(); and[0][i].a <== lt[0][i].out; and[0][i].b <== lt[1][i].out; - and[1][i] = AND(); - and[1][i].a <== states[i][0]; - and[1][i].b <== and[0][i].out; - lt[2][i] = LessEqThan(8); - lt[2][i].in[0] <== 160; - lt[2][i].in[1] <== in[i]; - lt[3][i] = LessEqThan(8); - lt[3][i].in[0] <== in[i]; - lt[3][i].in[1] <== 191; - and[2][i] = AND(); - and[2][i].a <== lt[2][i].out; - and[2][i].b <== lt[3][i].out; - and[3][i] = AND(); - and[3][i].a <== states[i][2]; - and[3][i].b <== and[2][i].out; - lt[4][i] = LessEqThan(8); - lt[4][i].in[0] <== 128; - lt[4][i].in[1] <== in[i]; - lt[5][i] = LessEqThan(8); - lt[5][i].in[0] <== in[i]; - lt[5][i].in[1] <== 191; - and[4][i] = AND(); - and[4][i].a <== lt[4][i].out; - and[4][i].b <== lt[5][i].out; - and[5][i] = AND(); - and[5][i].a <== states[i][3]; - and[5][i].b <== and[4][i].out; - lt[6][i] = LessEqThan(8); - lt[6][i].in[0] <== 128; - lt[6][i].in[1] <== in[i]; - lt[7][i] = LessEqThan(8); - lt[7][i].in[0] <== in[i]; - lt[7][i].in[1] <== 159; - and[6][i] = AND(); - and[6][i].a <== lt[6][i].out; - and[6][i].b <== lt[7][i].out; - and[7][i] = AND(); - and[7][i].a <== states[i][4]; - and[7][i].b <== and[6][i].out; - and[8][i] = AND(); - and[8][i].a <== states[i][8]; - and[8][i].b <== and[0][i].out; - and[9][i] = AND(); - and[9][i].a <== states[i][9]; - and[9][i].b <== and[0][i].out; - multi_or[0][i] = MultiOR(5); - multi_or[0][i].in[0] <== and[3][i].out; - multi_or[0][i].in[1] <== and[5][i].out; - multi_or[0][i].in[2] <== and[7][i].out; - multi_or[0][i].in[3] <== and[8][i].out; - multi_or[0][i].in[4] <== and[9][i].out; - states_tmp[i+1][1] <== multi_or[0][i].out; eq[0][i] = IsEqual(); eq[0][i].in[0] <== in[i]; - eq[0][i].in[1] <== 224; - and[10][i] = AND(); - and[10][i].a <== states[i][0]; - and[10][i].b <== eq[0][i].out; - and[11][i] = AND(); - and[11][i].a <== states[i][8]; - and[11][i].b <== eq[0][i].out; - and[12][i] = AND(); - and[12][i].a <== states[i][9]; - and[12][i].b <== eq[0][i].out; - multi_or[1][i] = MultiOR(2); - multi_or[1][i].in[0] <== and[11][i].out; - multi_or[1][i].in[1] <== and[12][i].out; - states_tmp[i+1][2] <== multi_or[1][i].out; + eq[0][i].in[1] <== 1; eq[1][i] = IsEqual(); eq[1][i].in[0] <== in[i]; - eq[1][i].in[1] <== 225; + eq[1][i].in[1] <== 2; eq[2][i] = IsEqual(); eq[2][i].in[0] <== in[i]; - eq[2][i].in[1] <== 226; + eq[2][i].in[1] <== 3; eq[3][i] = IsEqual(); eq[3][i].in[0] <== in[i]; - eq[3][i].in[1] <== 227; + eq[3][i].in[1] <== 4; eq[4][i] = IsEqual(); eq[4][i].in[0] <== in[i]; - eq[4][i].in[1] <== 228; + eq[4][i].in[1] <== 5; eq[5][i] = IsEqual(); eq[5][i].in[0] <== in[i]; - eq[5][i].in[1] <== 229; + eq[5][i].in[1] <== 6; eq[6][i] = IsEqual(); eq[6][i].in[0] <== in[i]; - eq[6][i].in[1] <== 230; + eq[6][i].in[1] <== 7; eq[7][i] = IsEqual(); eq[7][i].in[0] <== in[i]; - eq[7][i].in[1] <== 231; + eq[7][i].in[1] <== 8; eq[8][i] = IsEqual(); eq[8][i].in[0] <== in[i]; - eq[8][i].in[1] <== 232; + eq[8][i].in[1] <== 9; eq[9][i] = IsEqual(); eq[9][i].in[0] <== in[i]; - eq[9][i].in[1] <== 233; + eq[9][i].in[1] <== 11; eq[10][i] = IsEqual(); eq[10][i].in[0] <== in[i]; - eq[10][i].in[1] <== 234; + eq[10][i].in[1] <== 12; + and[1][i] = AND(); + and[1][i].a <== states[i][0]; + multi_or[0][i] = MultiOR(12); + multi_or[0][i].in[0] <== and[0][i].out; + multi_or[0][i].in[1] <== eq[0][i].out; + multi_or[0][i].in[2] <== eq[1][i].out; + multi_or[0][i].in[3] <== eq[2][i].out; + multi_or[0][i].in[4] <== eq[3][i].out; + multi_or[0][i].in[5] <== eq[4][i].out; + multi_or[0][i].in[6] <== eq[5][i].out; + multi_or[0][i].in[7] <== eq[6][i].out; + multi_or[0][i].in[8] <== eq[7][i].out; + multi_or[0][i].in[9] <== eq[8][i].out; + multi_or[0][i].in[10] <== eq[9][i].out; + multi_or[0][i].in[11] <== eq[10][i].out; + and[1][i].b <== multi_or[0][i].out; + lt[2][i] = LessEqThan(8); + lt[2][i].in[0] <== 14; + lt[2][i].in[1] <== in[i]; + lt[3][i] = LessEqThan(8); + lt[3][i].in[0] <== in[i]; + lt[3][i].in[1] <== 59; + and[2][i] = AND(); + and[2][i].a <== lt[2][i].out; + and[2][i].b <== lt[3][i].out; + lt[4][i] = LessEqThan(8); + lt[4][i].in[0] <== 61; + lt[4][i].in[1] <== in[i]; + lt[5][i] = LessEqThan(8); + lt[5][i].in[0] <== in[i]; + lt[5][i].in[1] <== 127; + and[3][i] = AND(); + and[3][i].a <== lt[4][i].out; + and[3][i].b <== lt[5][i].out; + and[4][i] = AND(); + and[4][i].a <== states[i][1]; + multi_or[1][i] = MultiOR(13); + multi_or[1][i].in[0] <== and[2][i].out; + multi_or[1][i].in[1] <== and[3][i].out; + multi_or[1][i].in[2] <== eq[0][i].out; + multi_or[1][i].in[3] <== eq[1][i].out; + multi_or[1][i].in[4] <== eq[2][i].out; + multi_or[1][i].in[5] <== eq[3][i].out; + multi_or[1][i].in[6] <== eq[4][i].out; + multi_or[1][i].in[7] <== eq[5][i].out; + multi_or[1][i].in[8] <== eq[6][i].out; + multi_or[1][i].in[9] <== eq[7][i].out; + multi_or[1][i].in[10] <== eq[8][i].out; + multi_or[1][i].in[11] <== eq[9][i].out; + multi_or[1][i].in[12] <== eq[10][i].out; + and[4][i].b <== multi_or[1][i].out; + lt[6][i] = LessEqThan(8); + lt[6][i].in[0] <== 128; + lt[6][i].in[1] <== in[i]; + lt[7][i] = LessEqThan(8); + lt[7][i].in[0] <== in[i]; + lt[7][i].in[1] <== 191; + and[5][i] = AND(); + and[5][i].a <== lt[6][i].out; + and[5][i].b <== lt[7][i].out; + and[6][i] = AND(); + and[6][i].a <== states[i][2]; + and[6][i].b <== and[5][i].out; + lt[8][i] = LessEqThan(8); + lt[8][i].in[0] <== 14; + lt[8][i].in[1] <== in[i]; + lt[9][i] = LessEqThan(8); + lt[9][i].in[0] <== in[i]; + lt[9][i].in[1] <== 32; + and[7][i] = AND(); + and[7][i].a <== lt[8][i].out; + and[7][i].b <== lt[9][i].out; eq[11][i] = IsEqual(); eq[11][i].in[0] <== in[i]; - eq[11][i].in[1] <== 235; + eq[11][i].in[1] <== 34; eq[12][i] = IsEqual(); eq[12][i].in[0] <== in[i]; - eq[12][i].in[1] <== 236; + eq[12][i].in[1] <== 40; eq[13][i] = IsEqual(); eq[13][i].in[0] <== in[i]; - eq[13][i].in[1] <== 238; + eq[13][i].in[1] <== 41; eq[14][i] = IsEqual(); eq[14][i].in[0] <== in[i]; - eq[14][i].in[1] <== 239; - and[13][i] = AND(); - and[13][i].a <== states[i][0]; - multi_or[2][i] = MultiOR(14); - multi_or[2][i].in[0] <== eq[1][i].out; - multi_or[2][i].in[1] <== eq[2][i].out; - multi_or[2][i].in[2] <== eq[3][i].out; - multi_or[2][i].in[3] <== eq[4][i].out; - multi_or[2][i].in[4] <== eq[5][i].out; - multi_or[2][i].in[5] <== eq[6][i].out; - multi_or[2][i].in[6] <== eq[7][i].out; - multi_or[2][i].in[7] <== eq[8][i].out; - multi_or[2][i].in[8] <== eq[9][i].out; - multi_or[2][i].in[9] <== eq[10][i].out; - multi_or[2][i].in[10] <== eq[11][i].out; - multi_or[2][i].in[11] <== eq[12][i].out; - multi_or[2][i].in[12] <== eq[13][i].out; - multi_or[2][i].in[13] <== eq[14][i].out; - and[13][i].b <== multi_or[2][i].out; - lt[8][i] = LessEqThan(8); - lt[8][i].in[0] <== 144; - lt[8][i].in[1] <== in[i]; - lt[9][i] = LessEqThan(8); - lt[9][i].in[0] <== in[i]; - lt[9][i].in[1] <== 191; - and[14][i] = AND(); - and[14][i].a <== lt[8][i].out; - and[14][i].b <== lt[9][i].out; - and[15][i] = AND(); - and[15][i].a <== states[i][5]; - and[15][i].b <== and[14][i].out; - and[16][i] = AND(); - and[16][i].a <== states[i][6]; - and[16][i].b <== and[4][i].out; + eq[14][i].in[1] <== 44; eq[15][i] = IsEqual(); eq[15][i].in[0] <== in[i]; - eq[15][i].in[1] <== 128; + eq[15][i].in[1] <== 47; eq[16][i] = IsEqual(); eq[16][i].in[0] <== in[i]; - eq[16][i].in[1] <== 129; + eq[16][i].in[1] <== 58; eq[17][i] = IsEqual(); eq[17][i].in[0] <== in[i]; - eq[17][i].in[1] <== 130; + eq[17][i].in[1] <== 59; eq[18][i] = IsEqual(); eq[18][i].in[0] <== in[i]; - eq[18][i].in[1] <== 131; + eq[18][i].in[1] <== 62; eq[19][i] = IsEqual(); eq[19][i].in[0] <== in[i]; - eq[19][i].in[1] <== 132; + eq[19][i].in[1] <== 64; eq[20][i] = IsEqual(); eq[20][i].in[0] <== in[i]; - eq[20][i].in[1] <== 133; + eq[20][i].in[1] <== 91; eq[21][i] = IsEqual(); eq[21][i].in[0] <== in[i]; - eq[21][i].in[1] <== 134; + eq[21][i].in[1] <== 92; eq[22][i] = IsEqual(); eq[22][i].in[0] <== in[i]; - eq[22][i].in[1] <== 135; + eq[22][i].in[1] <== 93; eq[23][i] = IsEqual(); eq[23][i].in[0] <== in[i]; - eq[23][i].in[1] <== 136; + eq[23][i].in[1] <== 127; + and[8][i] = AND(); + and[8][i].a <== states[i][9]; + multi_or[2][i] = MultiOR(25); + multi_or[2][i].in[0] <== and[7][i].out; + multi_or[2][i].in[1] <== eq[0][i].out; + multi_or[2][i].in[2] <== eq[1][i].out; + multi_or[2][i].in[3] <== eq[2][i].out; + multi_or[2][i].in[4] <== eq[3][i].out; + multi_or[2][i].in[5] <== eq[4][i].out; + multi_or[2][i].in[6] <== eq[5][i].out; + multi_or[2][i].in[7] <== eq[6][i].out; + multi_or[2][i].in[8] <== eq[7][i].out; + multi_or[2][i].in[9] <== eq[8][i].out; + multi_or[2][i].in[10] <== eq[9][i].out; + multi_or[2][i].in[11] <== eq[10][i].out; + multi_or[2][i].in[12] <== eq[11][i].out; + multi_or[2][i].in[13] <== eq[12][i].out; + multi_or[2][i].in[14] <== eq[13][i].out; + multi_or[2][i].in[15] <== eq[14][i].out; + multi_or[2][i].in[16] <== eq[15][i].out; + multi_or[2][i].in[17] <== eq[16][i].out; + multi_or[2][i].in[18] <== eq[17][i].out; + multi_or[2][i].in[19] <== eq[18][i].out; + multi_or[2][i].in[20] <== eq[19][i].out; + multi_or[2][i].in[21] <== eq[20][i].out; + multi_or[2][i].in[22] <== eq[21][i].out; + multi_or[2][i].in[23] <== eq[22][i].out; + multi_or[2][i].in[24] <== eq[23][i].out; + and[8][i].b <== multi_or[2][i].out; + multi_or[3][i] = MultiOR(3); + multi_or[3][i].in[0] <== and[4][i].out; + multi_or[3][i].in[1] <== and[6][i].out; + multi_or[3][i].in[2] <== and[8][i].out; + states_tmp[i+1][1] <== multi_or[3][i].out; + lt[10][i] = LessEqThan(8); + lt[10][i].in[0] <== 194; + lt[10][i].in[1] <== in[i]; + lt[11][i] = LessEqThan(8); + lt[11][i].in[0] <== in[i]; + lt[11][i].in[1] <== 223; + and[9][i] = AND(); + and[9][i].a <== lt[10][i].out; + and[9][i].b <== lt[11][i].out; + and[10][i] = AND(); + and[10][i].a <== states[i][0]; + and[10][i].b <== and[9][i].out; + and[11][i] = AND(); + and[11][i].a <== states[i][1]; + and[11][i].b <== and[9][i].out; + lt[12][i] = LessEqThan(8); + lt[12][i].in[0] <== 160; + lt[12][i].in[1] <== in[i]; + lt[13][i] = LessEqThan(8); + lt[13][i].in[0] <== in[i]; + lt[13][i].in[1] <== 191; + and[12][i] = AND(); + and[12][i].a <== lt[12][i].out; + and[12][i].b <== lt[13][i].out; + and[13][i] = AND(); + and[13][i].a <== states[i][3]; + and[13][i].b <== and[12][i].out; + and[14][i] = AND(); + and[14][i].a <== states[i][4]; + and[14][i].b <== and[5][i].out; + lt[14][i] = LessEqThan(8); + lt[14][i].in[0] <== 128; + lt[14][i].in[1] <== in[i]; + lt[15][i] = LessEqThan(8); + lt[15][i].in[0] <== in[i]; + lt[15][i].in[1] <== 159; + and[15][i] = AND(); + and[15][i].a <== lt[14][i].out; + and[15][i].b <== lt[15][i].out; + and[16][i] = AND(); + and[16][i].a <== states[i][5]; + and[16][i].b <== and[15][i].out; + and[17][i] = AND(); + and[17][i].a <== states[i][9]; + and[17][i].b <== and[9][i].out; + multi_or[4][i] = MultiOR(5); + multi_or[4][i].in[0] <== and[11][i].out; + multi_or[4][i].in[1] <== and[13][i].out; + multi_or[4][i].in[2] <== and[14][i].out; + multi_or[4][i].in[3] <== and[16][i].out; + multi_or[4][i].in[4] <== and[17][i].out; + states_tmp[i+1][2] <== multi_or[4][i].out; eq[24][i] = IsEqual(); eq[24][i].in[0] <== in[i]; - eq[24][i].in[1] <== 137; + eq[24][i].in[1] <== 224; + and[18][i] = AND(); + and[18][i].a <== states[i][0]; + and[18][i].b <== eq[24][i].out; + and[19][i] = AND(); + and[19][i].a <== states[i][1]; + and[19][i].b <== eq[24][i].out; + and[20][i] = AND(); + and[20][i].a <== states[i][9]; + and[20][i].b <== eq[24][i].out; + multi_or[5][i] = MultiOR(2); + multi_or[5][i].in[0] <== and[19][i].out; + multi_or[5][i].in[1] <== and[20][i].out; + states_tmp[i+1][3] <== multi_or[5][i].out; eq[25][i] = IsEqual(); eq[25][i].in[0] <== in[i]; - eq[25][i].in[1] <== 138; + eq[25][i].in[1] <== 225; eq[26][i] = IsEqual(); eq[26][i].in[0] <== in[i]; - eq[26][i].in[1] <== 139; + eq[26][i].in[1] <== 226; eq[27][i] = IsEqual(); eq[27][i].in[0] <== in[i]; - eq[27][i].in[1] <== 140; + eq[27][i].in[1] <== 227; eq[28][i] = IsEqual(); eq[28][i].in[0] <== in[i]; - eq[28][i].in[1] <== 141; + eq[28][i].in[1] <== 228; eq[29][i] = IsEqual(); eq[29][i].in[0] <== in[i]; - eq[29][i].in[1] <== 142; + eq[29][i].in[1] <== 229; eq[30][i] = IsEqual(); eq[30][i].in[0] <== in[i]; - eq[30][i].in[1] <== 143; - and[17][i] = AND(); - and[17][i].a <== states[i][7]; - multi_or[3][i] = MultiOR(16); - multi_or[3][i].in[0] <== eq[15][i].out; - multi_or[3][i].in[1] <== eq[16][i].out; - multi_or[3][i].in[2] <== eq[17][i].out; - multi_or[3][i].in[3] <== eq[18][i].out; - multi_or[3][i].in[4] <== eq[19][i].out; - multi_or[3][i].in[5] <== eq[20][i].out; - multi_or[3][i].in[6] <== eq[21][i].out; - multi_or[3][i].in[7] <== eq[22][i].out; - multi_or[3][i].in[8] <== eq[23][i].out; - multi_or[3][i].in[9] <== eq[24][i].out; - multi_or[3][i].in[10] <== eq[25][i].out; - multi_or[3][i].in[11] <== eq[26][i].out; - multi_or[3][i].in[12] <== eq[27][i].out; - multi_or[3][i].in[13] <== eq[28][i].out; - multi_or[3][i].in[14] <== eq[29][i].out; - multi_or[3][i].in[15] <== eq[30][i].out; - and[17][i].b <== multi_or[3][i].out; - and[18][i] = AND(); - and[18][i].a <== states[i][8]; - and[18][i].b <== multi_or[2][i].out; - and[19][i] = AND(); - and[19][i].a <== states[i][9]; - and[19][i].b <== multi_or[2][i].out; - multi_or[4][i] = MultiOR(5); - multi_or[4][i].in[0] <== and[15][i].out; - multi_or[4][i].in[1] <== and[16][i].out; - multi_or[4][i].in[2] <== and[17][i].out; - multi_or[4][i].in[3] <== and[18][i].out; - multi_or[4][i].in[4] <== and[19][i].out; - states_tmp[i+1][3] <== multi_or[4][i].out; + eq[30][i].in[1] <== 230; eq[31][i] = IsEqual(); eq[31][i].in[0] <== in[i]; - eq[31][i].in[1] <== 237; - and[20][i] = AND(); - and[20][i].a <== states[i][0]; - and[20][i].b <== eq[31][i].out; - and[21][i] = AND(); - and[21][i].a <== states[i][8]; - and[21][i].b <== eq[31][i].out; - and[22][i] = AND(); - and[22][i].a <== states[i][9]; - and[22][i].b <== eq[31][i].out; - multi_or[5][i] = MultiOR(2); - multi_or[5][i].in[0] <== and[21][i].out; - multi_or[5][i].in[1] <== and[22][i].out; - states_tmp[i+1][4] <== multi_or[5][i].out; + eq[31][i].in[1] <== 231; eq[32][i] = IsEqual(); eq[32][i].in[0] <== in[i]; - eq[32][i].in[1] <== 240; - and[23][i] = AND(); - and[23][i].a <== states[i][0]; - and[23][i].b <== eq[32][i].out; - and[24][i] = AND(); - and[24][i].a <== states[i][8]; - and[24][i].b <== eq[32][i].out; - and[25][i] = AND(); - and[25][i].a <== states[i][9]; - and[25][i].b <== eq[32][i].out; - multi_or[6][i] = MultiOR(2); - multi_or[6][i].in[0] <== and[24][i].out; - multi_or[6][i].in[1] <== and[25][i].out; - states_tmp[i+1][5] <== multi_or[6][i].out; + eq[32][i].in[1] <== 232; eq[33][i] = IsEqual(); eq[33][i].in[0] <== in[i]; - eq[33][i].in[1] <== 241; + eq[33][i].in[1] <== 233; eq[34][i] = IsEqual(); eq[34][i].in[0] <== in[i]; - eq[34][i].in[1] <== 242; + eq[34][i].in[1] <== 234; eq[35][i] = IsEqual(); eq[35][i].in[0] <== in[i]; - eq[35][i].in[1] <== 243; - and[26][i] = AND(); - and[26][i].a <== states[i][0]; - multi_or[7][i] = MultiOR(3); - multi_or[7][i].in[0] <== eq[33][i].out; - multi_or[7][i].in[1] <== eq[34][i].out; - multi_or[7][i].in[2] <== eq[35][i].out; - and[26][i].b <== multi_or[7][i].out; - and[27][i] = AND(); - and[27][i].a <== states[i][8]; - and[27][i].b <== multi_or[7][i].out; - and[28][i] = AND(); - and[28][i].a <== states[i][9]; - and[28][i].b <== multi_or[7][i].out; - multi_or[8][i] = MultiOR(2); - multi_or[8][i].in[0] <== and[27][i].out; - multi_or[8][i].in[1] <== and[28][i].out; - states_tmp[i+1][6] <== multi_or[8][i].out; + eq[35][i].in[1] <== 235; eq[36][i] = IsEqual(); eq[36][i].in[0] <== in[i]; - eq[36][i].in[1] <== 244; - and[29][i] = AND(); - and[29][i].a <== states[i][0]; - and[29][i].b <== eq[36][i].out; - and[30][i] = AND(); - and[30][i].a <== states[i][8]; - and[30][i].b <== eq[36][i].out; - and[31][i] = AND(); - and[31][i].a <== states[i][9]; - and[31][i].b <== eq[36][i].out; - multi_or[9][i] = MultiOR(2); - multi_or[9][i].in[0] <== and[30][i].out; - multi_or[9][i].in[1] <== and[31][i].out; - states_tmp[i+1][7] <== multi_or[9][i].out; - lt[10][i] = LessEqThan(8); - lt[10][i].in[0] <== 14; - lt[10][i].in[1] <== in[i]; - lt[11][i] = LessEqThan(8); - lt[11][i].in[0] <== in[i]; - lt[11][i].in[1] <== 127; - and[32][i] = AND(); - and[32][i].a <== lt[10][i].out; - and[32][i].b <== lt[11][i].out; + eq[36][i].in[1] <== 236; eq[37][i] = IsEqual(); eq[37][i].in[0] <== in[i]; - eq[37][i].in[1] <== 1; + eq[37][i].in[1] <== 238; eq[38][i] = IsEqual(); eq[38][i].in[0] <== in[i]; - eq[38][i].in[1] <== 2; + eq[38][i].in[1] <== 239; + and[21][i] = AND(); + and[21][i].a <== states[i][0]; + multi_or[6][i] = MultiOR(14); + multi_or[6][i].in[0] <== eq[25][i].out; + multi_or[6][i].in[1] <== eq[26][i].out; + multi_or[6][i].in[2] <== eq[27][i].out; + multi_or[6][i].in[3] <== eq[28][i].out; + multi_or[6][i].in[4] <== eq[29][i].out; + multi_or[6][i].in[5] <== eq[30][i].out; + multi_or[6][i].in[6] <== eq[31][i].out; + multi_or[6][i].in[7] <== eq[32][i].out; + multi_or[6][i].in[8] <== eq[33][i].out; + multi_or[6][i].in[9] <== eq[34][i].out; + multi_or[6][i].in[10] <== eq[35][i].out; + multi_or[6][i].in[11] <== eq[36][i].out; + multi_or[6][i].in[12] <== eq[37][i].out; + multi_or[6][i].in[13] <== eq[38][i].out; + and[21][i].b <== multi_or[6][i].out; + and[22][i] = AND(); + and[22][i].a <== states[i][1]; + and[22][i].b <== multi_or[6][i].out; + lt[16][i] = LessEqThan(8); + lt[16][i].in[0] <== 144; + lt[16][i].in[1] <== in[i]; + lt[17][i] = LessEqThan(8); + lt[17][i].in[0] <== in[i]; + lt[17][i].in[1] <== 191; + and[23][i] = AND(); + and[23][i].a <== lt[16][i].out; + and[23][i].b <== lt[17][i].out; + and[24][i] = AND(); + and[24][i].a <== states[i][6]; + and[24][i].b <== and[23][i].out; + and[25][i] = AND(); + and[25][i].a <== states[i][7]; + and[25][i].b <== and[5][i].out; eq[39][i] = IsEqual(); eq[39][i].in[0] <== in[i]; - eq[39][i].in[1] <== 3; + eq[39][i].in[1] <== 128; eq[40][i] = IsEqual(); eq[40][i].in[0] <== in[i]; - eq[40][i].in[1] <== 4; + eq[40][i].in[1] <== 129; eq[41][i] = IsEqual(); eq[41][i].in[0] <== in[i]; - eq[41][i].in[1] <== 5; + eq[41][i].in[1] <== 130; eq[42][i] = IsEqual(); eq[42][i].in[0] <== in[i]; - eq[42][i].in[1] <== 6; + eq[42][i].in[1] <== 131; eq[43][i] = IsEqual(); eq[43][i].in[0] <== in[i]; - eq[43][i].in[1] <== 7; + eq[43][i].in[1] <== 132; eq[44][i] = IsEqual(); eq[44][i].in[0] <== in[i]; - eq[44][i].in[1] <== 8; + eq[44][i].in[1] <== 133; eq[45][i] = IsEqual(); eq[45][i].in[0] <== in[i]; - eq[45][i].in[1] <== 9; + eq[45][i].in[1] <== 134; eq[46][i] = IsEqual(); eq[46][i].in[0] <== in[i]; - eq[46][i].in[1] <== 11; + eq[46][i].in[1] <== 135; eq[47][i] = IsEqual(); eq[47][i].in[0] <== in[i]; - eq[47][i].in[1] <== 12; - and[33][i] = AND(); - and[33][i].a <== states[i][0]; - multi_or[10][i] = MultiOR(12); - multi_or[10][i].in[0] <== and[32][i].out; - multi_or[10][i].in[1] <== eq[37][i].out; - multi_or[10][i].in[2] <== eq[38][i].out; - multi_or[10][i].in[3] <== eq[39][i].out; - multi_or[10][i].in[4] <== eq[40][i].out; - multi_or[10][i].in[5] <== eq[41][i].out; - multi_or[10][i].in[6] <== eq[42][i].out; - multi_or[10][i].in[7] <== eq[43][i].out; - multi_or[10][i].in[8] <== eq[44][i].out; - multi_or[10][i].in[9] <== eq[45][i].out; - multi_or[10][i].in[10] <== eq[46][i].out; - multi_or[10][i].in[11] <== eq[47][i].out; - and[33][i].b <== multi_or[10][i].out; - and[34][i] = AND(); - and[34][i].a <== states[i][1]; - and[34][i].b <== and[4][i].out; - lt[12][i] = LessEqThan(8); - lt[12][i].in[0] <== 14; - lt[12][i].in[1] <== in[i]; - lt[13][i] = LessEqThan(8); - lt[13][i].in[0] <== in[i]; - lt[13][i].in[1] <== 59; - and[35][i] = AND(); - and[35][i].a <== lt[12][i].out; - and[35][i].b <== lt[13][i].out; - lt[14][i] = LessEqThan(8); - lt[14][i].in[0] <== 61; - lt[14][i].in[1] <== in[i]; - lt[15][i] = LessEqThan(8); - lt[15][i].in[0] <== in[i]; - lt[15][i].in[1] <== 127; - and[36][i] = AND(); - and[36][i].a <== lt[14][i].out; - and[36][i].b <== lt[15][i].out; - and[37][i] = AND(); - and[37][i].a <== states[i][8]; - multi_or[11][i] = MultiOR(13); - multi_or[11][i].in[0] <== and[35][i].out; - multi_or[11][i].in[1] <== and[36][i].out; - multi_or[11][i].in[2] <== eq[37][i].out; - multi_or[11][i].in[3] <== eq[38][i].out; - multi_or[11][i].in[4] <== eq[39][i].out; - multi_or[11][i].in[5] <== eq[40][i].out; - multi_or[11][i].in[6] <== eq[41][i].out; - multi_or[11][i].in[7] <== eq[42][i].out; - multi_or[11][i].in[8] <== eq[43][i].out; - multi_or[11][i].in[9] <== eq[44][i].out; - multi_or[11][i].in[10] <== eq[45][i].out; - multi_or[11][i].in[11] <== eq[46][i].out; - multi_or[11][i].in[12] <== eq[47][i].out; - and[37][i].b <== multi_or[11][i].out; - lt[16][i] = LessEqThan(8); - lt[16][i].in[0] <== 14; - lt[16][i].in[1] <== in[i]; - lt[17][i] = LessEqThan(8); - lt[17][i].in[0] <== in[i]; - lt[17][i].in[1] <== 32; - and[38][i] = AND(); - and[38][i].a <== lt[16][i].out; - and[38][i].b <== lt[17][i].out; + eq[47][i].in[1] <== 136; eq[48][i] = IsEqual(); eq[48][i].in[0] <== in[i]; - eq[48][i].in[1] <== 34; + eq[48][i].in[1] <== 137; eq[49][i] = IsEqual(); eq[49][i].in[0] <== in[i]; - eq[49][i].in[1] <== 40; + eq[49][i].in[1] <== 138; eq[50][i] = IsEqual(); eq[50][i].in[0] <== in[i]; - eq[50][i].in[1] <== 41; + eq[50][i].in[1] <== 139; eq[51][i] = IsEqual(); eq[51][i].in[0] <== in[i]; - eq[51][i].in[1] <== 58; + eq[51][i].in[1] <== 140; eq[52][i] = IsEqual(); eq[52][i].in[0] <== in[i]; - eq[52][i].in[1] <== 59; + eq[52][i].in[1] <== 141; eq[53][i] = IsEqual(); eq[53][i].in[0] <== in[i]; - eq[53][i].in[1] <== 62; + eq[53][i].in[1] <== 142; eq[54][i] = IsEqual(); eq[54][i].in[0] <== in[i]; - eq[54][i].in[1] <== 64; + eq[54][i].in[1] <== 143; + and[26][i] = AND(); + and[26][i].a <== states[i][8]; + multi_or[7][i] = MultiOR(16); + multi_or[7][i].in[0] <== eq[39][i].out; + multi_or[7][i].in[1] <== eq[40][i].out; + multi_or[7][i].in[2] <== eq[41][i].out; + multi_or[7][i].in[3] <== eq[42][i].out; + multi_or[7][i].in[4] <== eq[43][i].out; + multi_or[7][i].in[5] <== eq[44][i].out; + multi_or[7][i].in[6] <== eq[45][i].out; + multi_or[7][i].in[7] <== eq[46][i].out; + multi_or[7][i].in[8] <== eq[47][i].out; + multi_or[7][i].in[9] <== eq[48][i].out; + multi_or[7][i].in[10] <== eq[49][i].out; + multi_or[7][i].in[11] <== eq[50][i].out; + multi_or[7][i].in[12] <== eq[51][i].out; + multi_or[7][i].in[13] <== eq[52][i].out; + multi_or[7][i].in[14] <== eq[53][i].out; + multi_or[7][i].in[15] <== eq[54][i].out; + and[26][i].b <== multi_or[7][i].out; + and[27][i] = AND(); + and[27][i].a <== states[i][9]; + and[27][i].b <== multi_or[6][i].out; + multi_or[8][i] = MultiOR(5); + multi_or[8][i].in[0] <== and[22][i].out; + multi_or[8][i].in[1] <== and[24][i].out; + multi_or[8][i].in[2] <== and[25][i].out; + multi_or[8][i].in[3] <== and[26][i].out; + multi_or[8][i].in[4] <== and[27][i].out; + states_tmp[i+1][4] <== multi_or[8][i].out; eq[55][i] = IsEqual(); eq[55][i].in[0] <== in[i]; - eq[55][i].in[1] <== 91; + eq[55][i].in[1] <== 237; + and[28][i] = AND(); + and[28][i].a <== states[i][0]; + and[28][i].b <== eq[55][i].out; + and[29][i] = AND(); + and[29][i].a <== states[i][1]; + and[29][i].b <== eq[55][i].out; + and[30][i] = AND(); + and[30][i].a <== states[i][9]; + and[30][i].b <== eq[55][i].out; + multi_or[9][i] = MultiOR(2); + multi_or[9][i].in[0] <== and[29][i].out; + multi_or[9][i].in[1] <== and[30][i].out; + states_tmp[i+1][5] <== multi_or[9][i].out; eq[56][i] = IsEqual(); eq[56][i].in[0] <== in[i]; - eq[56][i].in[1] <== 92; + eq[56][i].in[1] <== 240; + and[31][i] = AND(); + and[31][i].a <== states[i][0]; + and[31][i].b <== eq[56][i].out; + and[32][i] = AND(); + and[32][i].a <== states[i][1]; + and[32][i].b <== eq[56][i].out; + and[33][i] = AND(); + and[33][i].a <== states[i][9]; + and[33][i].b <== eq[56][i].out; + multi_or[10][i] = MultiOR(2); + multi_or[10][i].in[0] <== and[32][i].out; + multi_or[10][i].in[1] <== and[33][i].out; + states_tmp[i+1][6] <== multi_or[10][i].out; eq[57][i] = IsEqual(); eq[57][i].in[0] <== in[i]; - eq[57][i].in[1] <== 93; + eq[57][i].in[1] <== 241; eq[58][i] = IsEqual(); eq[58][i].in[0] <== in[i]; - eq[58][i].in[1] <== 127; + eq[58][i].in[1] <== 242; + eq[59][i] = IsEqual(); + eq[59][i].in[0] <== in[i]; + eq[59][i].in[1] <== 243; + and[34][i] = AND(); + and[34][i].a <== states[i][0]; + multi_or[11][i] = MultiOR(3); + multi_or[11][i].in[0] <== eq[57][i].out; + multi_or[11][i].in[1] <== eq[58][i].out; + multi_or[11][i].in[2] <== eq[59][i].out; + and[34][i].b <== multi_or[11][i].out; + and[35][i] = AND(); + and[35][i].a <== states[i][1]; + and[35][i].b <== multi_or[11][i].out; + and[36][i] = AND(); + and[36][i].a <== states[i][9]; + and[36][i].b <== multi_or[11][i].out; + multi_or[12][i] = MultiOR(2); + multi_or[12][i].in[0] <== and[35][i].out; + multi_or[12][i].in[1] <== and[36][i].out; + states_tmp[i+1][7] <== multi_or[12][i].out; + eq[60][i] = IsEqual(); + eq[60][i].in[0] <== in[i]; + eq[60][i].in[1] <== 244; + and[37][i] = AND(); + and[37][i].a <== states[i][0]; + and[37][i].b <== eq[60][i].out; + and[38][i] = AND(); + and[38][i].a <== states[i][1]; + and[38][i].b <== eq[60][i].out; and[39][i] = AND(); and[39][i].a <== states[i][9]; - multi_or[12][i] = MultiOR(23); - multi_or[12][i].in[0] <== and[38][i].out; - multi_or[12][i].in[1] <== eq[37][i].out; - multi_or[12][i].in[2] <== eq[38][i].out; - multi_or[12][i].in[3] <== eq[39][i].out; - multi_or[12][i].in[4] <== eq[40][i].out; - multi_or[12][i].in[5] <== eq[41][i].out; - multi_or[12][i].in[6] <== eq[42][i].out; - multi_or[12][i].in[7] <== eq[43][i].out; - multi_or[12][i].in[8] <== eq[44][i].out; - multi_or[12][i].in[9] <== eq[45][i].out; - multi_or[12][i].in[10] <== eq[46][i].out; - multi_or[12][i].in[11] <== eq[47][i].out; - multi_or[12][i].in[12] <== eq[48][i].out; - multi_or[12][i].in[13] <== eq[49][i].out; - multi_or[12][i].in[14] <== eq[50][i].out; - multi_or[12][i].in[15] <== eq[51][i].out; - multi_or[12][i].in[16] <== eq[52][i].out; - multi_or[12][i].in[17] <== eq[53][i].out; - multi_or[12][i].in[18] <== eq[54][i].out; - multi_or[12][i].in[19] <== eq[55][i].out; - multi_or[12][i].in[20] <== eq[56][i].out; - multi_or[12][i].in[21] <== eq[57][i].out; - multi_or[12][i].in[22] <== eq[58][i].out; - and[39][i].b <== multi_or[12][i].out; - multi_or[13][i] = MultiOR(3); - multi_or[13][i].in[0] <== and[34][i].out; - multi_or[13][i].in[1] <== and[37][i].out; - multi_or[13][i].in[2] <== and[39][i].out; + and[39][i].b <== eq[60][i].out; + multi_or[13][i] = MultiOR(2); + multi_or[13][i].in[0] <== and[38][i].out; + multi_or[13][i].in[1] <== and[39][i].out; states_tmp[i+1][8] <== multi_or[13][i].out; - eq[59][i] = IsEqual(); - eq[59][i].in[0] <== in[i]; - eq[59][i].in[1] <== 60; + eq[61][i] = IsEqual(); + eq[61][i].in[0] <== in[i]; + eq[61][i].in[1] <== 60; and[40][i] = AND(); - and[40][i].a <== states[i][8]; - and[40][i].b <== eq[59][i].out; + and[40][i].a <== states[i][1]; + and[40][i].b <== eq[61][i].out; and[41][i] = AND(); and[41][i].a <== states[i][9]; - and[41][i].b <== eq[59][i].out; + and[41][i].b <== eq[61][i].out; multi_or[14][i] = MultiOR(2); multi_or[14][i].in[0] <== and[40][i].out; multi_or[14][i].in[1] <== and[41][i].out; @@ -539,42 +547,36 @@ template EmailAddrWithNameRegex(msg_bytes) { and[43][i] = AND(); and[43][i].a <== lt[20][i].out; and[43][i].b <== lt[21][i].out; - eq[60][i] = IsEqual(); - eq[60][i].in[0] <== in[i]; - eq[60][i].in[1] <== 33; - eq[61][i] = IsEqual(); - eq[61][i].in[0] <== in[i]; - eq[61][i].in[1] <== 35; eq[62][i] = IsEqual(); eq[62][i].in[0] <== in[i]; - eq[62][i].in[1] <== 36; + eq[62][i].in[1] <== 33; eq[63][i] = IsEqual(); eq[63][i].in[0] <== in[i]; - eq[63][i].in[1] <== 37; + eq[63][i].in[1] <== 35; eq[64][i] = IsEqual(); eq[64][i].in[0] <== in[i]; - eq[64][i].in[1] <== 38; + eq[64][i].in[1] <== 36; eq[65][i] = IsEqual(); eq[65][i].in[0] <== in[i]; - eq[65][i].in[1] <== 39; + eq[65][i].in[1] <== 37; eq[66][i] = IsEqual(); eq[66][i].in[0] <== in[i]; - eq[66][i].in[1] <== 42; + eq[66][i].in[1] <== 38; eq[67][i] = IsEqual(); eq[67][i].in[0] <== in[i]; - eq[67][i].in[1] <== 43; + eq[67][i].in[1] <== 39; eq[68][i] = IsEqual(); eq[68][i].in[0] <== in[i]; - eq[68][i].in[1] <== 44; + eq[68][i].in[1] <== 42; eq[69][i] = IsEqual(); eq[69][i].in[0] <== in[i]; - eq[69][i].in[1] <== 45; + eq[69][i].in[1] <== 43; eq[70][i] = IsEqual(); eq[70][i].in[0] <== in[i]; - eq[70][i].in[1] <== 46; + eq[70][i].in[1] <== 45; eq[71][i] = IsEqual(); eq[71][i].in[0] <== in[i]; - eq[71][i].in[1] <== 47; + eq[71][i].in[1] <== 46; eq[72][i] = IsEqual(); eq[72][i].in[0] <== in[i]; eq[72][i].in[1] <== 48; @@ -613,33 +615,31 @@ template EmailAddrWithNameRegex(msg_bytes) { eq[83][i].in[1] <== 63; and[44][i] = AND(); and[44][i].a <== states[i][9]; - multi_or[15][i] = MultiOR(26); + multi_or[15][i] = MultiOR(24); multi_or[15][i].in[0] <== and[42][i].out; multi_or[15][i].in[1] <== and[43][i].out; - multi_or[15][i].in[2] <== eq[60][i].out; - multi_or[15][i].in[3] <== eq[61][i].out; - multi_or[15][i].in[4] <== eq[62][i].out; - multi_or[15][i].in[5] <== eq[63][i].out; - multi_or[15][i].in[6] <== eq[64][i].out; - multi_or[15][i].in[7] <== eq[65][i].out; - multi_or[15][i].in[8] <== eq[66][i].out; - multi_or[15][i].in[9] <== eq[67][i].out; - multi_or[15][i].in[10] <== eq[68][i].out; - multi_or[15][i].in[11] <== eq[69][i].out; - multi_or[15][i].in[12] <== eq[70][i].out; - multi_or[15][i].in[13] <== eq[71][i].out; - multi_or[15][i].in[14] <== eq[72][i].out; - multi_or[15][i].in[15] <== eq[73][i].out; - multi_or[15][i].in[16] <== eq[74][i].out; - multi_or[15][i].in[17] <== eq[75][i].out; - multi_or[15][i].in[18] <== eq[76][i].out; - multi_or[15][i].in[19] <== eq[77][i].out; - multi_or[15][i].in[20] <== eq[78][i].out; - multi_or[15][i].in[21] <== eq[79][i].out; - multi_or[15][i].in[22] <== eq[80][i].out; - multi_or[15][i].in[23] <== eq[81][i].out; - multi_or[15][i].in[24] <== eq[82][i].out; - multi_or[15][i].in[25] <== eq[83][i].out; + multi_or[15][i].in[2] <== eq[62][i].out; + multi_or[15][i].in[3] <== eq[63][i].out; + multi_or[15][i].in[4] <== eq[64][i].out; + multi_or[15][i].in[5] <== eq[65][i].out; + multi_or[15][i].in[6] <== eq[66][i].out; + multi_or[15][i].in[7] <== eq[67][i].out; + multi_or[15][i].in[8] <== eq[68][i].out; + multi_or[15][i].in[9] <== eq[69][i].out; + multi_or[15][i].in[10] <== eq[70][i].out; + multi_or[15][i].in[11] <== eq[71][i].out; + multi_or[15][i].in[12] <== eq[72][i].out; + multi_or[15][i].in[13] <== eq[73][i].out; + multi_or[15][i].in[14] <== eq[74][i].out; + multi_or[15][i].in[15] <== eq[75][i].out; + multi_or[15][i].in[16] <== eq[76][i].out; + multi_or[15][i].in[17] <== eq[77][i].out; + multi_or[15][i].in[18] <== eq[78][i].out; + multi_or[15][i].in[19] <== eq[79][i].out; + multi_or[15][i].in[20] <== eq[80][i].out; + multi_or[15][i].in[21] <== eq[81][i].out; + multi_or[15][i].in[22] <== eq[82][i].out; + multi_or[15][i].in[23] <== eq[83][i].out; and[44][i].b <== multi_or[15][i].out; and[45][i] = AND(); and[45][i].a <== states[i][10]; @@ -650,7 +650,7 @@ template EmailAddrWithNameRegex(msg_bytes) { states[i+1][10] <== multi_or[16][i].out; and[46][i] = AND(); and[46][i].a <== states[i][10]; - and[46][i].b <== eq[54][i].out; + and[46][i].b <== eq[19][i].out; states[i+1][11] <== and[46][i].out; lt[22][i] = LessEqThan(8); lt[22][i].in[0] <== 97; @@ -669,8 +669,8 @@ template EmailAddrWithNameRegex(msg_bytes) { multi_or[17][i] = MultiOR(15); multi_or[17][i].in[0] <== and[42][i].out; multi_or[17][i].in[1] <== and[47][i].out; - multi_or[17][i].in[2] <== eq[69][i].out; - multi_or[17][i].in[3] <== eq[70][i].out; + multi_or[17][i].in[2] <== eq[70][i].out; + multi_or[17][i].in[3] <== eq[71][i].out; multi_or[17][i].in[4] <== eq[72][i].out; multi_or[17][i].in[5] <== eq[73][i].out; multi_or[17][i].in[6] <== eq[74][i].out; @@ -692,17 +692,17 @@ template EmailAddrWithNameRegex(msg_bytes) { states[i+1][12] <== multi_or[18][i].out; and[50][i] = AND(); and[50][i].a <== states[i][12]; - and[50][i].b <== eq[53][i].out; + and[50][i].b <== eq[18][i].out; states[i+1][13] <== and[50][i].out; from_zero_enabled[i] <== MultiNOR(13)([states_tmp[i+1][1], states_tmp[i+1][2], states_tmp[i+1][3], states_tmp[i+1][4], states_tmp[i+1][5], states_tmp[i+1][6], states_tmp[i+1][7], states_tmp[i+1][8], states[i+1][9], states[i+1][10], states[i+1][11], states[i+1][12], states[i+1][13]]); states[i+1][1] <== MultiOR(2)([states_tmp[i+1][1], from_zero_enabled[i] * and[1][i].out]); states[i+1][2] <== MultiOR(2)([states_tmp[i+1][2], from_zero_enabled[i] * and[10][i].out]); - states[i+1][3] <== MultiOR(2)([states_tmp[i+1][3], from_zero_enabled[i] * and[13][i].out]); - states[i+1][4] <== MultiOR(2)([states_tmp[i+1][4], from_zero_enabled[i] * and[20][i].out]); - states[i+1][5] <== MultiOR(2)([states_tmp[i+1][5], from_zero_enabled[i] * and[23][i].out]); - states[i+1][6] <== MultiOR(2)([states_tmp[i+1][6], from_zero_enabled[i] * and[26][i].out]); - states[i+1][7] <== MultiOR(2)([states_tmp[i+1][7], from_zero_enabled[i] * and[29][i].out]); - states[i+1][8] <== MultiOR(2)([states_tmp[i+1][8], from_zero_enabled[i] * and[33][i].out]); + states[i+1][3] <== MultiOR(2)([states_tmp[i+1][3], from_zero_enabled[i] * and[18][i].out]); + states[i+1][4] <== MultiOR(2)([states_tmp[i+1][4], from_zero_enabled[i] * and[21][i].out]); + states[i+1][5] <== MultiOR(2)([states_tmp[i+1][5], from_zero_enabled[i] * and[28][i].out]); + states[i+1][6] <== MultiOR(2)([states_tmp[i+1][6], from_zero_enabled[i] * and[31][i].out]); + states[i+1][7] <== MultiOR(2)([states_tmp[i+1][7], from_zero_enabled[i] * and[34][i].out]); + states[i+1][8] <== MultiOR(2)([states_tmp[i+1][8], from_zero_enabled[i] * and[37][i].out]); state_changed[i].in[0] <== states[i+1][1]; state_changed[i].in[1] <== states[i+1][2]; state_changed[i].in[2] <== states[i+1][3]; diff --git a/packages/circom/circuits/common/from_addr.json b/packages/circom/circuits/common/from_addr.json index 3019ca0..56a5e2a 100644 --- a/packages/circom/circuits/common/from_addr.json +++ b/packages/circom/circuits/common/from_addr.json @@ -10,11 +10,11 @@ }, { "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, "regex_def": ">?\r\n" } ] -} +} \ No newline at end of file diff --git a/packages/circom/circuits/common/from_all_regex.circom b/packages/circom/circuits/common/from_all_regex.circom index bdafa99..0326ca7 100644 --- a/packages/circom/circuits/common/from_all_regex.circom +++ b/packages/circom/circuits/common/from_all_regex.circom @@ -87,362 +87,362 @@ template FromAllRegex(msg_bytes) { and[7][i].b <== eq[7][i].out; states[i+1][7] <== and[7][i].out; lt[0][i] = LessEqThan(8); - lt[0][i].in[0] <== 194; + lt[0][i].in[0] <== 14; lt[0][i].in[1] <== in[i]; lt[1][i] = LessEqThan(8); lt[1][i].in[0] <== in[i]; - lt[1][i].in[1] <== 223; + lt[1][i].in[1] <== 127; and[8][i] = AND(); and[8][i].a <== lt[0][i].out; and[8][i].b <== lt[1][i].out; - and[9][i] = AND(); - and[9][i].a <== states[i][7]; - and[9][i].b <== and[8][i].out; - lt[2][i] = LessEqThan(8); - lt[2][i].in[0] <== 160; - lt[2][i].in[1] <== in[i]; - lt[3][i] = LessEqThan(8); - lt[3][i].in[0] <== in[i]; - lt[3][i].in[1] <== 191; - and[10][i] = AND(); - and[10][i].a <== lt[2][i].out; - and[10][i].b <== lt[3][i].out; - and[11][i] = AND(); - and[11][i].a <== states[i][9]; - and[11][i].b <== and[10][i].out; - lt[4][i] = LessEqThan(8); - lt[4][i].in[0] <== 128; - lt[4][i].in[1] <== in[i]; - lt[5][i] = LessEqThan(8); - lt[5][i].in[0] <== in[i]; - lt[5][i].in[1] <== 191; - and[12][i] = AND(); - and[12][i].a <== lt[4][i].out; - and[12][i].b <== lt[5][i].out; - and[13][i] = AND(); - and[13][i].a <== states[i][10]; - and[13][i].b <== and[12][i].out; - lt[6][i] = LessEqThan(8); - lt[6][i].in[0] <== 128; - lt[6][i].in[1] <== in[i]; - lt[7][i] = LessEqThan(8); - lt[7][i].in[0] <== in[i]; - lt[7][i].in[1] <== 159; - and[14][i] = AND(); - and[14][i].a <== lt[6][i].out; - and[14][i].b <== lt[7][i].out; - and[15][i] = AND(); - and[15][i].a <== states[i][11]; - and[15][i].b <== and[14][i].out; - and[16][i] = AND(); - and[16][i].a <== states[i][15]; - and[16][i].b <== and[8][i].out; - multi_or[0][i] = MultiOR(5); - multi_or[0][i].in[0] <== and[9][i].out; - multi_or[0][i].in[1] <== and[11][i].out; - multi_or[0][i].in[2] <== and[13][i].out; - multi_or[0][i].in[3] <== and[15][i].out; - multi_or[0][i].in[4] <== and[16][i].out; - states[i+1][8] <== multi_or[0][i].out; eq[8][i] = IsEqual(); eq[8][i].in[0] <== in[i]; - eq[8][i].in[1] <== 224; - and[17][i] = AND(); - and[17][i].a <== states[i][7]; - and[17][i].b <== eq[8][i].out; - and[18][i] = AND(); - and[18][i].a <== states[i][15]; - and[18][i].b <== eq[8][i].out; - multi_or[1][i] = MultiOR(2); - multi_or[1][i].in[0] <== and[17][i].out; - multi_or[1][i].in[1] <== and[18][i].out; - states[i+1][9] <== multi_or[1][i].out; + eq[8][i].in[1] <== 1; eq[9][i] = IsEqual(); eq[9][i].in[0] <== in[i]; - eq[9][i].in[1] <== 225; + eq[9][i].in[1] <== 2; eq[10][i] = IsEqual(); eq[10][i].in[0] <== in[i]; - eq[10][i].in[1] <== 226; + eq[10][i].in[1] <== 3; eq[11][i] = IsEqual(); eq[11][i].in[0] <== in[i]; - eq[11][i].in[1] <== 227; + eq[11][i].in[1] <== 4; eq[12][i] = IsEqual(); eq[12][i].in[0] <== in[i]; - eq[12][i].in[1] <== 228; + eq[12][i].in[1] <== 5; eq[13][i] = IsEqual(); eq[13][i].in[0] <== in[i]; - eq[13][i].in[1] <== 229; + eq[13][i].in[1] <== 6; eq[14][i] = IsEqual(); eq[14][i].in[0] <== in[i]; - eq[14][i].in[1] <== 230; + eq[14][i].in[1] <== 7; eq[15][i] = IsEqual(); eq[15][i].in[0] <== in[i]; - eq[15][i].in[1] <== 231; + eq[15][i].in[1] <== 8; eq[16][i] = IsEqual(); eq[16][i].in[0] <== in[i]; - eq[16][i].in[1] <== 232; + eq[16][i].in[1] <== 9; eq[17][i] = IsEqual(); eq[17][i].in[0] <== in[i]; - eq[17][i].in[1] <== 233; + eq[17][i].in[1] <== 11; eq[18][i] = IsEqual(); eq[18][i].in[0] <== in[i]; - eq[18][i].in[1] <== 234; + eq[18][i].in[1] <== 12; + and[9][i] = AND(); + and[9][i].a <== states[i][7]; + multi_or[0][i] = MultiOR(12); + multi_or[0][i].in[0] <== and[8][i].out; + multi_or[0][i].in[1] <== eq[8][i].out; + multi_or[0][i].in[2] <== eq[9][i].out; + multi_or[0][i].in[3] <== eq[10][i].out; + multi_or[0][i].in[4] <== eq[11][i].out; + multi_or[0][i].in[5] <== eq[12][i].out; + multi_or[0][i].in[6] <== eq[13][i].out; + multi_or[0][i].in[7] <== eq[14][i].out; + multi_or[0][i].in[8] <== eq[15][i].out; + multi_or[0][i].in[9] <== eq[16][i].out; + multi_or[0][i].in[10] <== eq[17][i].out; + multi_or[0][i].in[11] <== eq[18][i].out; + and[9][i].b <== multi_or[0][i].out; + and[10][i] = AND(); + and[10][i].a <== states[i][8]; + and[10][i].b <== multi_or[0][i].out; + lt[2][i] = LessEqThan(8); + lt[2][i].in[0] <== 128; + lt[2][i].in[1] <== in[i]; + lt[3][i] = LessEqThan(8); + lt[3][i].in[0] <== in[i]; + lt[3][i].in[1] <== 191; + and[11][i] = AND(); + and[11][i].a <== lt[2][i].out; + and[11][i].b <== lt[3][i].out; + and[12][i] = AND(); + and[12][i].a <== states[i][9]; + and[12][i].b <== and[11][i].out; + multi_or[1][i] = MultiOR(3); + multi_or[1][i].in[0] <== and[9][i].out; + multi_or[1][i].in[1] <== and[10][i].out; + multi_or[1][i].in[2] <== and[12][i].out; + states[i+1][8] <== multi_or[1][i].out; + lt[4][i] = LessEqThan(8); + lt[4][i].in[0] <== 194; + lt[4][i].in[1] <== in[i]; + lt[5][i] = LessEqThan(8); + lt[5][i].in[0] <== in[i]; + lt[5][i].in[1] <== 223; + and[13][i] = AND(); + and[13][i].a <== lt[4][i].out; + and[13][i].b <== lt[5][i].out; + and[14][i] = AND(); + and[14][i].a <== states[i][7]; + and[14][i].b <== and[13][i].out; + and[15][i] = AND(); + and[15][i].a <== states[i][8]; + and[15][i].b <== and[13][i].out; + lt[6][i] = LessEqThan(8); + lt[6][i].in[0] <== 160; + lt[6][i].in[1] <== in[i]; + lt[7][i] = LessEqThan(8); + lt[7][i].in[0] <== in[i]; + lt[7][i].in[1] <== 191; + and[16][i] = AND(); + and[16][i].a <== lt[6][i].out; + and[16][i].b <== lt[7][i].out; + and[17][i] = AND(); + and[17][i].a <== states[i][10]; + and[17][i].b <== and[16][i].out; + and[18][i] = AND(); + and[18][i].a <== states[i][11]; + and[18][i].b <== and[11][i].out; + lt[8][i] = LessEqThan(8); + lt[8][i].in[0] <== 128; + lt[8][i].in[1] <== in[i]; + lt[9][i] = LessEqThan(8); + lt[9][i].in[0] <== in[i]; + lt[9][i].in[1] <== 159; + and[19][i] = AND(); + and[19][i].a <== lt[8][i].out; + and[19][i].b <== lt[9][i].out; + and[20][i] = AND(); + and[20][i].a <== states[i][12]; + and[20][i].b <== and[19][i].out; + multi_or[2][i] = MultiOR(5); + multi_or[2][i].in[0] <== and[14][i].out; + multi_or[2][i].in[1] <== and[15][i].out; + multi_or[2][i].in[2] <== and[17][i].out; + multi_or[2][i].in[3] <== and[18][i].out; + multi_or[2][i].in[4] <== and[20][i].out; + states[i+1][9] <== multi_or[2][i].out; eq[19][i] = IsEqual(); eq[19][i].in[0] <== in[i]; - eq[19][i].in[1] <== 235; + eq[19][i].in[1] <== 224; + and[21][i] = AND(); + and[21][i].a <== states[i][7]; + and[21][i].b <== eq[19][i].out; + and[22][i] = AND(); + and[22][i].a <== states[i][8]; + and[22][i].b <== eq[19][i].out; + multi_or[3][i] = MultiOR(2); + multi_or[3][i].in[0] <== and[21][i].out; + multi_or[3][i].in[1] <== and[22][i].out; + states[i+1][10] <== multi_or[3][i].out; eq[20][i] = IsEqual(); eq[20][i].in[0] <== in[i]; - eq[20][i].in[1] <== 236; + eq[20][i].in[1] <== 225; eq[21][i] = IsEqual(); eq[21][i].in[0] <== in[i]; - eq[21][i].in[1] <== 238; + eq[21][i].in[1] <== 226; eq[22][i] = IsEqual(); eq[22][i].in[0] <== in[i]; - eq[22][i].in[1] <== 239; - and[19][i] = AND(); - and[19][i].a <== states[i][7]; - multi_or[2][i] = MultiOR(14); - multi_or[2][i].in[0] <== eq[9][i].out; - multi_or[2][i].in[1] <== eq[10][i].out; - multi_or[2][i].in[2] <== eq[11][i].out; - multi_or[2][i].in[3] <== eq[12][i].out; - multi_or[2][i].in[4] <== eq[13][i].out; - multi_or[2][i].in[5] <== eq[14][i].out; - multi_or[2][i].in[6] <== eq[15][i].out; - multi_or[2][i].in[7] <== eq[16][i].out; - multi_or[2][i].in[8] <== eq[17][i].out; - multi_or[2][i].in[9] <== eq[18][i].out; - multi_or[2][i].in[10] <== eq[19][i].out; - multi_or[2][i].in[11] <== eq[20][i].out; - multi_or[2][i].in[12] <== eq[21][i].out; - multi_or[2][i].in[13] <== eq[22][i].out; - and[19][i].b <== multi_or[2][i].out; - lt[8][i] = LessEqThan(8); - lt[8][i].in[0] <== 144; - lt[8][i].in[1] <== in[i]; - lt[9][i] = LessEqThan(8); - lt[9][i].in[0] <== in[i]; - lt[9][i].in[1] <== 191; - and[20][i] = AND(); - and[20][i].a <== lt[8][i].out; - and[20][i].b <== lt[9][i].out; - and[21][i] = AND(); - and[21][i].a <== states[i][12]; - and[21][i].b <== and[20][i].out; - and[22][i] = AND(); - and[22][i].a <== states[i][13]; - and[22][i].b <== and[12][i].out; + eq[22][i].in[1] <== 227; eq[23][i] = IsEqual(); eq[23][i].in[0] <== in[i]; - eq[23][i].in[1] <== 128; + eq[23][i].in[1] <== 228; eq[24][i] = IsEqual(); eq[24][i].in[0] <== in[i]; - eq[24][i].in[1] <== 129; + eq[24][i].in[1] <== 229; eq[25][i] = IsEqual(); eq[25][i].in[0] <== in[i]; - eq[25][i].in[1] <== 130; + eq[25][i].in[1] <== 230; eq[26][i] = IsEqual(); eq[26][i].in[0] <== in[i]; - eq[26][i].in[1] <== 131; + eq[26][i].in[1] <== 231; eq[27][i] = IsEqual(); eq[27][i].in[0] <== in[i]; - eq[27][i].in[1] <== 132; + eq[27][i].in[1] <== 232; eq[28][i] = IsEqual(); eq[28][i].in[0] <== in[i]; - eq[28][i].in[1] <== 133; + eq[28][i].in[1] <== 233; eq[29][i] = IsEqual(); eq[29][i].in[0] <== in[i]; - eq[29][i].in[1] <== 134; + eq[29][i].in[1] <== 234; eq[30][i] = IsEqual(); eq[30][i].in[0] <== in[i]; - eq[30][i].in[1] <== 135; + eq[30][i].in[1] <== 235; eq[31][i] = IsEqual(); eq[31][i].in[0] <== in[i]; - eq[31][i].in[1] <== 136; + eq[31][i].in[1] <== 236; eq[32][i] = IsEqual(); eq[32][i].in[0] <== in[i]; - eq[32][i].in[1] <== 137; + eq[32][i].in[1] <== 238; eq[33][i] = IsEqual(); eq[33][i].in[0] <== in[i]; - eq[33][i].in[1] <== 138; + eq[33][i].in[1] <== 239; + and[23][i] = AND(); + and[23][i].a <== states[i][7]; + multi_or[4][i] = MultiOR(14); + multi_or[4][i].in[0] <== eq[20][i].out; + multi_or[4][i].in[1] <== eq[21][i].out; + multi_or[4][i].in[2] <== eq[22][i].out; + multi_or[4][i].in[3] <== eq[23][i].out; + multi_or[4][i].in[4] <== eq[24][i].out; + multi_or[4][i].in[5] <== eq[25][i].out; + multi_or[4][i].in[6] <== eq[26][i].out; + multi_or[4][i].in[7] <== eq[27][i].out; + multi_or[4][i].in[8] <== eq[28][i].out; + multi_or[4][i].in[9] <== eq[29][i].out; + multi_or[4][i].in[10] <== eq[30][i].out; + multi_or[4][i].in[11] <== eq[31][i].out; + multi_or[4][i].in[12] <== eq[32][i].out; + multi_or[4][i].in[13] <== eq[33][i].out; + and[23][i].b <== multi_or[4][i].out; + and[24][i] = AND(); + and[24][i].a <== states[i][8]; + and[24][i].b <== multi_or[4][i].out; + lt[10][i] = LessEqThan(8); + lt[10][i].in[0] <== 144; + lt[10][i].in[1] <== in[i]; + lt[11][i] = LessEqThan(8); + lt[11][i].in[0] <== in[i]; + lt[11][i].in[1] <== 191; + and[25][i] = AND(); + and[25][i].a <== lt[10][i].out; + and[25][i].b <== lt[11][i].out; + and[26][i] = AND(); + and[26][i].a <== states[i][13]; + and[26][i].b <== and[25][i].out; + and[27][i] = AND(); + and[27][i].a <== states[i][14]; + and[27][i].b <== and[11][i].out; eq[34][i] = IsEqual(); eq[34][i].in[0] <== in[i]; - eq[34][i].in[1] <== 139; + eq[34][i].in[1] <== 128; eq[35][i] = IsEqual(); eq[35][i].in[0] <== in[i]; - eq[35][i].in[1] <== 140; + eq[35][i].in[1] <== 129; eq[36][i] = IsEqual(); eq[36][i].in[0] <== in[i]; - eq[36][i].in[1] <== 141; + eq[36][i].in[1] <== 130; eq[37][i] = IsEqual(); eq[37][i].in[0] <== in[i]; - eq[37][i].in[1] <== 142; + eq[37][i].in[1] <== 131; eq[38][i] = IsEqual(); eq[38][i].in[0] <== in[i]; - eq[38][i].in[1] <== 143; - and[23][i] = AND(); - and[23][i].a <== states[i][14]; - multi_or[3][i] = MultiOR(16); - multi_or[3][i].in[0] <== eq[23][i].out; - multi_or[3][i].in[1] <== eq[24][i].out; - multi_or[3][i].in[2] <== eq[25][i].out; - multi_or[3][i].in[3] <== eq[26][i].out; - multi_or[3][i].in[4] <== eq[27][i].out; - multi_or[3][i].in[5] <== eq[28][i].out; - multi_or[3][i].in[6] <== eq[29][i].out; - multi_or[3][i].in[7] <== eq[30][i].out; - multi_or[3][i].in[8] <== eq[31][i].out; - multi_or[3][i].in[9] <== eq[32][i].out; - multi_or[3][i].in[10] <== eq[33][i].out; - multi_or[3][i].in[11] <== eq[34][i].out; - multi_or[3][i].in[12] <== eq[35][i].out; - multi_or[3][i].in[13] <== eq[36][i].out; - multi_or[3][i].in[14] <== eq[37][i].out; - multi_or[3][i].in[15] <== eq[38][i].out; - and[23][i].b <== multi_or[3][i].out; - and[24][i] = AND(); - and[24][i].a <== states[i][15]; - and[24][i].b <== multi_or[2][i].out; - multi_or[4][i] = MultiOR(5); - multi_or[4][i].in[0] <== and[19][i].out; - multi_or[4][i].in[1] <== and[21][i].out; - multi_or[4][i].in[2] <== and[22][i].out; - multi_or[4][i].in[3] <== and[23][i].out; - multi_or[4][i].in[4] <== and[24][i].out; - states[i+1][10] <== multi_or[4][i].out; + eq[38][i].in[1] <== 132; eq[39][i] = IsEqual(); eq[39][i].in[0] <== in[i]; - eq[39][i].in[1] <== 237; - and[25][i] = AND(); - and[25][i].a <== states[i][7]; - and[25][i].b <== eq[39][i].out; - and[26][i] = AND(); - and[26][i].a <== states[i][15]; - and[26][i].b <== eq[39][i].out; - multi_or[5][i] = MultiOR(2); - multi_or[5][i].in[0] <== and[25][i].out; - multi_or[5][i].in[1] <== and[26][i].out; - states[i+1][11] <== multi_or[5][i].out; + eq[39][i].in[1] <== 133; eq[40][i] = IsEqual(); eq[40][i].in[0] <== in[i]; - eq[40][i].in[1] <== 240; - and[27][i] = AND(); - and[27][i].a <== states[i][7]; - and[27][i].b <== eq[40][i].out; - and[28][i] = AND(); - and[28][i].a <== states[i][15]; - and[28][i].b <== eq[40][i].out; - multi_or[6][i] = MultiOR(2); - multi_or[6][i].in[0] <== and[27][i].out; - multi_or[6][i].in[1] <== and[28][i].out; - states[i+1][12] <== multi_or[6][i].out; + eq[40][i].in[1] <== 134; eq[41][i] = IsEqual(); eq[41][i].in[0] <== in[i]; - eq[41][i].in[1] <== 241; + eq[41][i].in[1] <== 135; eq[42][i] = IsEqual(); eq[42][i].in[0] <== in[i]; - eq[42][i].in[1] <== 242; + eq[42][i].in[1] <== 136; eq[43][i] = IsEqual(); eq[43][i].in[0] <== in[i]; - eq[43][i].in[1] <== 243; - and[29][i] = AND(); - and[29][i].a <== states[i][7]; - multi_or[7][i] = MultiOR(3); - multi_or[7][i].in[0] <== eq[41][i].out; - multi_or[7][i].in[1] <== eq[42][i].out; - multi_or[7][i].in[2] <== eq[43][i].out; - and[29][i].b <== multi_or[7][i].out; - and[30][i] = AND(); - and[30][i].a <== states[i][15]; - and[30][i].b <== multi_or[7][i].out; - multi_or[8][i] = MultiOR(2); - multi_or[8][i].in[0] <== and[29][i].out; - multi_or[8][i].in[1] <== and[30][i].out; - states[i+1][13] <== multi_or[8][i].out; + eq[43][i].in[1] <== 137; eq[44][i] = IsEqual(); eq[44][i].in[0] <== in[i]; - eq[44][i].in[1] <== 244; - and[31][i] = AND(); - and[31][i].a <== states[i][7]; - and[31][i].b <== eq[44][i].out; - and[32][i] = AND(); - and[32][i].a <== states[i][15]; - and[32][i].b <== eq[44][i].out; - multi_or[9][i] = MultiOR(2); - multi_or[9][i].in[0] <== and[31][i].out; - multi_or[9][i].in[1] <== and[32][i].out; - states[i+1][14] <== multi_or[9][i].out; - lt[10][i] = LessEqThan(8); - lt[10][i].in[0] <== 14; - lt[10][i].in[1] <== in[i]; - lt[11][i] = LessEqThan(8); - lt[11][i].in[0] <== in[i]; - lt[11][i].in[1] <== 127; - and[33][i] = AND(); - and[33][i].a <== lt[10][i].out; - and[33][i].b <== lt[11][i].out; + eq[44][i].in[1] <== 138; eq[45][i] = IsEqual(); eq[45][i].in[0] <== in[i]; - eq[45][i].in[1] <== 1; + eq[45][i].in[1] <== 139; eq[46][i] = IsEqual(); eq[46][i].in[0] <== in[i]; - eq[46][i].in[1] <== 2; + eq[46][i].in[1] <== 140; eq[47][i] = IsEqual(); eq[47][i].in[0] <== in[i]; - eq[47][i].in[1] <== 3; + eq[47][i].in[1] <== 141; eq[48][i] = IsEqual(); eq[48][i].in[0] <== in[i]; - eq[48][i].in[1] <== 4; + eq[48][i].in[1] <== 142; eq[49][i] = IsEqual(); eq[49][i].in[0] <== in[i]; - eq[49][i].in[1] <== 5; + eq[49][i].in[1] <== 143; + and[28][i] = AND(); + and[28][i].a <== states[i][15]; + multi_or[5][i] = MultiOR(16); + multi_or[5][i].in[0] <== eq[34][i].out; + multi_or[5][i].in[1] <== eq[35][i].out; + multi_or[5][i].in[2] <== eq[36][i].out; + multi_or[5][i].in[3] <== eq[37][i].out; + multi_or[5][i].in[4] <== eq[38][i].out; + multi_or[5][i].in[5] <== eq[39][i].out; + multi_or[5][i].in[6] <== eq[40][i].out; + multi_or[5][i].in[7] <== eq[41][i].out; + multi_or[5][i].in[8] <== eq[42][i].out; + multi_or[5][i].in[9] <== eq[43][i].out; + multi_or[5][i].in[10] <== eq[44][i].out; + multi_or[5][i].in[11] <== eq[45][i].out; + multi_or[5][i].in[12] <== eq[46][i].out; + multi_or[5][i].in[13] <== eq[47][i].out; + multi_or[5][i].in[14] <== eq[48][i].out; + multi_or[5][i].in[15] <== eq[49][i].out; + and[28][i].b <== multi_or[5][i].out; + multi_or[6][i] = MultiOR(5); + multi_or[6][i].in[0] <== and[23][i].out; + multi_or[6][i].in[1] <== and[24][i].out; + multi_or[6][i].in[2] <== and[26][i].out; + multi_or[6][i].in[3] <== and[27][i].out; + multi_or[6][i].in[4] <== and[28][i].out; + states[i+1][11] <== multi_or[6][i].out; eq[50][i] = IsEqual(); eq[50][i].in[0] <== in[i]; - eq[50][i].in[1] <== 6; + eq[50][i].in[1] <== 237; + and[29][i] = AND(); + and[29][i].a <== states[i][7]; + and[29][i].b <== eq[50][i].out; + and[30][i] = AND(); + and[30][i].a <== states[i][8]; + and[30][i].b <== eq[50][i].out; + multi_or[7][i] = MultiOR(2); + multi_or[7][i].in[0] <== and[29][i].out; + multi_or[7][i].in[1] <== and[30][i].out; + states[i+1][12] <== multi_or[7][i].out; eq[51][i] = IsEqual(); eq[51][i].in[0] <== in[i]; - eq[51][i].in[1] <== 7; + eq[51][i].in[1] <== 240; + and[31][i] = AND(); + and[31][i].a <== states[i][7]; + and[31][i].b <== eq[51][i].out; + and[32][i] = AND(); + and[32][i].a <== states[i][8]; + and[32][i].b <== eq[51][i].out; + multi_or[8][i] = MultiOR(2); + multi_or[8][i].in[0] <== and[31][i].out; + multi_or[8][i].in[1] <== and[32][i].out; + states[i+1][13] <== multi_or[8][i].out; eq[52][i] = IsEqual(); eq[52][i].in[0] <== in[i]; - eq[52][i].in[1] <== 8; + eq[52][i].in[1] <== 241; eq[53][i] = IsEqual(); eq[53][i].in[0] <== in[i]; - eq[53][i].in[1] <== 9; + eq[53][i].in[1] <== 242; eq[54][i] = IsEqual(); eq[54][i].in[0] <== in[i]; - eq[54][i].in[1] <== 11; - eq[55][i] = IsEqual(); - eq[55][i].in[0] <== in[i]; - eq[55][i].in[1] <== 12; + eq[54][i].in[1] <== 243; + and[33][i] = AND(); + and[33][i].a <== states[i][7]; + multi_or[9][i] = MultiOR(3); + multi_or[9][i].in[0] <== eq[52][i].out; + multi_or[9][i].in[1] <== eq[53][i].out; + multi_or[9][i].in[2] <== eq[54][i].out; + and[33][i].b <== multi_or[9][i].out; and[34][i] = AND(); - and[34][i].a <== states[i][7]; - multi_or[10][i] = MultiOR(12); + and[34][i].a <== states[i][8]; + and[34][i].b <== multi_or[9][i].out; + multi_or[10][i] = MultiOR(2); multi_or[10][i].in[0] <== and[33][i].out; - multi_or[10][i].in[1] <== eq[45][i].out; - multi_or[10][i].in[2] <== eq[46][i].out; - multi_or[10][i].in[3] <== eq[47][i].out; - multi_or[10][i].in[4] <== eq[48][i].out; - multi_or[10][i].in[5] <== eq[49][i].out; - multi_or[10][i].in[6] <== eq[50][i].out; - multi_or[10][i].in[7] <== eq[51][i].out; - multi_or[10][i].in[8] <== eq[52][i].out; - multi_or[10][i].in[9] <== eq[53][i].out; - multi_or[10][i].in[10] <== eq[54][i].out; - multi_or[10][i].in[11] <== eq[55][i].out; - and[34][i].b <== multi_or[10][i].out; + multi_or[10][i].in[1] <== and[34][i].out; + states[i+1][14] <== multi_or[10][i].out; + eq[55][i] = IsEqual(); + eq[55][i].in[0] <== in[i]; + eq[55][i].in[1] <== 244; and[35][i] = AND(); - and[35][i].a <== states[i][8]; - and[35][i].b <== and[12][i].out; + and[35][i].a <== states[i][7]; + and[35][i].b <== eq[55][i].out; and[36][i] = AND(); - and[36][i].a <== states[i][15]; - and[36][i].b <== multi_or[10][i].out; - multi_or[11][i] = MultiOR(3); - multi_or[11][i].in[0] <== and[34][i].out; - multi_or[11][i].in[1] <== and[35][i].out; - multi_or[11][i].in[2] <== and[36][i].out; + and[36][i].a <== states[i][8]; + and[36][i].b <== eq[55][i].out; + multi_or[11][i] = MultiOR(2); + multi_or[11][i].in[0] <== and[35][i].out; + multi_or[11][i].in[1] <== and[36][i].out; states[i+1][15] <== multi_or[11][i].out; and[37][i] = AND(); - and[37][i].a <== states[i][15]; + and[37][i].a <== states[i][8]; and[37][i].b <== eq[0][i].out; states[i+1][16] <== and[37][i].out; and[38][i] = AND(); @@ -483,13 +483,13 @@ template FromAllRegex(msg_bytes) { is_consecutive[msg_bytes-1-i][1] <== state_changed[msg_bytes-i].out * is_consecutive[msg_bytes-1-i][0]; is_consecutive[msg_bytes-1-i][2] <== ORAnd()([(1 - from_zero_enabled[msg_bytes-i+1]), states[num_bytes-i][17], is_consecutive[msg_bytes-1-i][1]]); } - // substrings calculated: [{(7, 8), (7, 9), (7, 10), (7, 11), (7, 12), (7, 13), (7, 14), (7, 15), (8, 15), (9, 8), (10, 8), (11, 8), (12, 10), (13, 10), (14, 10), (15, 8), (15, 9), (15, 10), (15, 11), (15, 12), (15, 13), (15, 14), (15, 15)}] + // substrings calculated: [{(7, 8), (7, 9), (7, 10), (7, 11), (7, 12), (7, 13), (7, 14), (7, 15), (8, 8), (8, 9), (8, 10), (8, 11), (8, 12), (8, 13), (8, 14), (8, 15), (9, 8), (10, 9), (11, 9), (12, 9), (13, 11), (14, 11), (15, 11)}] signal prev_states0[23][msg_bytes]; signal is_substr0[msg_bytes]; signal is_reveal0[msg_bytes]; signal output reveal0[msg_bytes]; for (var i = 0; i < msg_bytes; i++) { - // the 0-th substring transitions: [(7, 8), (7, 9), (7, 10), (7, 11), (7, 12), (7, 13), (7, 14), (7, 15), (8, 15), (9, 8), (10, 8), (11, 8), (12, 10), (13, 10), (14, 10), (15, 8), (15, 9), (15, 10), (15, 11), (15, 12), (15, 13), (15, 14), (15, 15)] + // the 0-th substring transitions: [(7, 8), (7, 9), (7, 10), (7, 11), (7, 12), (7, 13), (7, 14), (7, 15), (8, 8), (8, 9), (8, 10), (8, 11), (8, 12), (8, 13), (8, 14), (8, 15), (9, 8), (10, 9), (11, 9), (12, 9), (13, 11), (14, 11), (15, 11)] prev_states0[0][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][7]; prev_states0[1][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][7]; prev_states0[2][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][7]; @@ -499,21 +499,21 @@ template FromAllRegex(msg_bytes) { prev_states0[6][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][7]; prev_states0[7][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][7]; prev_states0[8][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][8]; - prev_states0[9][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][9]; - prev_states0[10][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][10]; - prev_states0[11][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][11]; - prev_states0[12][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][12]; - prev_states0[13][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][13]; - prev_states0[14][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][14]; - prev_states0[15][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][15]; - prev_states0[16][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][15]; - prev_states0[17][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][15]; - prev_states0[18][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][15]; - prev_states0[19][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][15]; - prev_states0[20][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][15]; - prev_states0[21][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][15]; + prev_states0[9][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][8]; + prev_states0[10][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][8]; + prev_states0[11][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][8]; + prev_states0[12][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][8]; + prev_states0[13][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][8]; + prev_states0[14][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][8]; + prev_states0[15][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][8]; + prev_states0[16][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][9]; + prev_states0[17][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][10]; + prev_states0[18][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][11]; + prev_states0[19][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][12]; + prev_states0[20][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][13]; + prev_states0[21][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][14]; prev_states0[22][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][15]; - is_substr0[i] <== MultiOR(23)([prev_states0[0][i] * states[i+2][8], prev_states0[1][i] * states[i+2][9], prev_states0[2][i] * states[i+2][10], prev_states0[3][i] * states[i+2][11], prev_states0[4][i] * states[i+2][12], prev_states0[5][i] * states[i+2][13], prev_states0[6][i] * states[i+2][14], prev_states0[7][i] * states[i+2][15], prev_states0[8][i] * states[i+2][15], prev_states0[9][i] * states[i+2][8], prev_states0[10][i] * states[i+2][8], prev_states0[11][i] * states[i+2][8], prev_states0[12][i] * states[i+2][10], prev_states0[13][i] * states[i+2][10], prev_states0[14][i] * states[i+2][10], prev_states0[15][i] * states[i+2][8], prev_states0[16][i] * states[i+2][9], prev_states0[17][i] * states[i+2][10], prev_states0[18][i] * states[i+2][11], prev_states0[19][i] * states[i+2][12], prev_states0[20][i] * states[i+2][13], prev_states0[21][i] * states[i+2][14], prev_states0[22][i] * states[i+2][15]]); + is_substr0[i] <== MultiOR(23)([prev_states0[0][i] * states[i+2][8], prev_states0[1][i] * states[i+2][9], prev_states0[2][i] * states[i+2][10], prev_states0[3][i] * states[i+2][11], prev_states0[4][i] * states[i+2][12], prev_states0[5][i] * states[i+2][13], prev_states0[6][i] * states[i+2][14], prev_states0[7][i] * states[i+2][15], prev_states0[8][i] * states[i+2][8], prev_states0[9][i] * states[i+2][9], prev_states0[10][i] * states[i+2][10], prev_states0[11][i] * states[i+2][11], prev_states0[12][i] * states[i+2][12], prev_states0[13][i] * states[i+2][13], prev_states0[14][i] * states[i+2][14], prev_states0[15][i] * states[i+2][15], prev_states0[16][i] * states[i+2][8], prev_states0[17][i] * states[i+2][9], prev_states0[18][i] * states[i+2][9], prev_states0[19][i] * states[i+2][9], prev_states0[20][i] * states[i+2][11], prev_states0[21][i] * states[i+2][11], prev_states0[22][i] * states[i+2][11]]); is_reveal0[i] <== MultiAND(3)([out, is_substr0[i], is_consecutive[i][2]]); reveal0[i] <== in[i+1] * is_reveal0[i]; } diff --git a/packages/circom/circuits/common/subject_all_regex.circom b/packages/circom/circuits/common/subject_all_regex.circom index e3d5b41..e66edcc 100644 --- a/packages/circom/circuits/common/subject_all_regex.circom +++ b/packages/circom/circuits/common/subject_all_regex.circom @@ -108,362 +108,362 @@ template SubjectAllRegex(msg_bytes) { and[10][i].b <== eq[10][i].out; states[i+1][10] <== and[10][i].out; lt[0][i] = LessEqThan(8); - lt[0][i].in[0] <== 194; + lt[0][i].in[0] <== 14; lt[0][i].in[1] <== in[i]; lt[1][i] = LessEqThan(8); lt[1][i].in[0] <== in[i]; - lt[1][i].in[1] <== 223; + lt[1][i].in[1] <== 127; and[11][i] = AND(); and[11][i].a <== lt[0][i].out; and[11][i].b <== lt[1][i].out; - and[12][i] = AND(); - and[12][i].a <== states[i][10]; - and[12][i].b <== and[11][i].out; - lt[2][i] = LessEqThan(8); - lt[2][i].in[0] <== 160; - lt[2][i].in[1] <== in[i]; - lt[3][i] = LessEqThan(8); - lt[3][i].in[0] <== in[i]; - lt[3][i].in[1] <== 191; - and[13][i] = AND(); - and[13][i].a <== lt[2][i].out; - and[13][i].b <== lt[3][i].out; - and[14][i] = AND(); - and[14][i].a <== states[i][12]; - and[14][i].b <== and[13][i].out; - lt[4][i] = LessEqThan(8); - lt[4][i].in[0] <== 128; - lt[4][i].in[1] <== in[i]; - lt[5][i] = LessEqThan(8); - lt[5][i].in[0] <== in[i]; - lt[5][i].in[1] <== 191; - and[15][i] = AND(); - and[15][i].a <== lt[4][i].out; - and[15][i].b <== lt[5][i].out; - and[16][i] = AND(); - and[16][i].a <== states[i][13]; - and[16][i].b <== and[15][i].out; - lt[6][i] = LessEqThan(8); - lt[6][i].in[0] <== 128; - lt[6][i].in[1] <== in[i]; - lt[7][i] = LessEqThan(8); - lt[7][i].in[0] <== in[i]; - lt[7][i].in[1] <== 159; - and[17][i] = AND(); - and[17][i].a <== lt[6][i].out; - and[17][i].b <== lt[7][i].out; - and[18][i] = AND(); - and[18][i].a <== states[i][14]; - and[18][i].b <== and[17][i].out; - and[19][i] = AND(); - and[19][i].a <== states[i][18]; - and[19][i].b <== and[11][i].out; - multi_or[0][i] = MultiOR(5); - multi_or[0][i].in[0] <== and[12][i].out; - multi_or[0][i].in[1] <== and[14][i].out; - multi_or[0][i].in[2] <== and[16][i].out; - multi_or[0][i].in[3] <== and[18][i].out; - multi_or[0][i].in[4] <== and[19][i].out; - states[i+1][11] <== multi_or[0][i].out; eq[11][i] = IsEqual(); eq[11][i].in[0] <== in[i]; - eq[11][i].in[1] <== 224; - and[20][i] = AND(); - and[20][i].a <== states[i][10]; - and[20][i].b <== eq[11][i].out; - and[21][i] = AND(); - and[21][i].a <== states[i][18]; - and[21][i].b <== eq[11][i].out; - multi_or[1][i] = MultiOR(2); - multi_or[1][i].in[0] <== and[20][i].out; - multi_or[1][i].in[1] <== and[21][i].out; - states[i+1][12] <== multi_or[1][i].out; + eq[11][i].in[1] <== 1; eq[12][i] = IsEqual(); eq[12][i].in[0] <== in[i]; - eq[12][i].in[1] <== 225; + eq[12][i].in[1] <== 2; eq[13][i] = IsEqual(); eq[13][i].in[0] <== in[i]; - eq[13][i].in[1] <== 226; + eq[13][i].in[1] <== 3; eq[14][i] = IsEqual(); eq[14][i].in[0] <== in[i]; - eq[14][i].in[1] <== 227; + eq[14][i].in[1] <== 4; eq[15][i] = IsEqual(); eq[15][i].in[0] <== in[i]; - eq[15][i].in[1] <== 228; + eq[15][i].in[1] <== 5; eq[16][i] = IsEqual(); eq[16][i].in[0] <== in[i]; - eq[16][i].in[1] <== 229; + eq[16][i].in[1] <== 6; eq[17][i] = IsEqual(); eq[17][i].in[0] <== in[i]; - eq[17][i].in[1] <== 230; + eq[17][i].in[1] <== 7; eq[18][i] = IsEqual(); eq[18][i].in[0] <== in[i]; - eq[18][i].in[1] <== 231; + eq[18][i].in[1] <== 8; eq[19][i] = IsEqual(); eq[19][i].in[0] <== in[i]; - eq[19][i].in[1] <== 232; + eq[19][i].in[1] <== 9; eq[20][i] = IsEqual(); eq[20][i].in[0] <== in[i]; - eq[20][i].in[1] <== 233; + eq[20][i].in[1] <== 11; eq[21][i] = IsEqual(); eq[21][i].in[0] <== in[i]; - eq[21][i].in[1] <== 234; + eq[21][i].in[1] <== 12; + and[12][i] = AND(); + and[12][i].a <== states[i][10]; + multi_or[0][i] = MultiOR(12); + multi_or[0][i].in[0] <== and[11][i].out; + multi_or[0][i].in[1] <== eq[11][i].out; + multi_or[0][i].in[2] <== eq[12][i].out; + multi_or[0][i].in[3] <== eq[13][i].out; + multi_or[0][i].in[4] <== eq[14][i].out; + multi_or[0][i].in[5] <== eq[15][i].out; + multi_or[0][i].in[6] <== eq[16][i].out; + multi_or[0][i].in[7] <== eq[17][i].out; + multi_or[0][i].in[8] <== eq[18][i].out; + multi_or[0][i].in[9] <== eq[19][i].out; + multi_or[0][i].in[10] <== eq[20][i].out; + multi_or[0][i].in[11] <== eq[21][i].out; + and[12][i].b <== multi_or[0][i].out; + and[13][i] = AND(); + and[13][i].a <== states[i][11]; + and[13][i].b <== multi_or[0][i].out; + lt[2][i] = LessEqThan(8); + lt[2][i].in[0] <== 128; + lt[2][i].in[1] <== in[i]; + lt[3][i] = LessEqThan(8); + lt[3][i].in[0] <== in[i]; + lt[3][i].in[1] <== 191; + and[14][i] = AND(); + and[14][i].a <== lt[2][i].out; + and[14][i].b <== lt[3][i].out; + and[15][i] = AND(); + and[15][i].a <== states[i][12]; + and[15][i].b <== and[14][i].out; + multi_or[1][i] = MultiOR(3); + multi_or[1][i].in[0] <== and[12][i].out; + multi_or[1][i].in[1] <== and[13][i].out; + multi_or[1][i].in[2] <== and[15][i].out; + states[i+1][11] <== multi_or[1][i].out; + lt[4][i] = LessEqThan(8); + lt[4][i].in[0] <== 194; + lt[4][i].in[1] <== in[i]; + lt[5][i] = LessEqThan(8); + lt[5][i].in[0] <== in[i]; + lt[5][i].in[1] <== 223; + and[16][i] = AND(); + and[16][i].a <== lt[4][i].out; + and[16][i].b <== lt[5][i].out; + and[17][i] = AND(); + and[17][i].a <== states[i][10]; + and[17][i].b <== and[16][i].out; + and[18][i] = AND(); + and[18][i].a <== states[i][11]; + and[18][i].b <== and[16][i].out; + lt[6][i] = LessEqThan(8); + lt[6][i].in[0] <== 160; + lt[6][i].in[1] <== in[i]; + lt[7][i] = LessEqThan(8); + lt[7][i].in[0] <== in[i]; + lt[7][i].in[1] <== 191; + and[19][i] = AND(); + and[19][i].a <== lt[6][i].out; + and[19][i].b <== lt[7][i].out; + and[20][i] = AND(); + and[20][i].a <== states[i][13]; + and[20][i].b <== and[19][i].out; + and[21][i] = AND(); + and[21][i].a <== states[i][14]; + and[21][i].b <== and[14][i].out; + lt[8][i] = LessEqThan(8); + lt[8][i].in[0] <== 128; + lt[8][i].in[1] <== in[i]; + lt[9][i] = LessEqThan(8); + lt[9][i].in[0] <== in[i]; + lt[9][i].in[1] <== 159; + and[22][i] = AND(); + and[22][i].a <== lt[8][i].out; + and[22][i].b <== lt[9][i].out; + and[23][i] = AND(); + and[23][i].a <== states[i][15]; + and[23][i].b <== and[22][i].out; + multi_or[2][i] = MultiOR(5); + multi_or[2][i].in[0] <== and[17][i].out; + multi_or[2][i].in[1] <== and[18][i].out; + multi_or[2][i].in[2] <== and[20][i].out; + multi_or[2][i].in[3] <== and[21][i].out; + multi_or[2][i].in[4] <== and[23][i].out; + states[i+1][12] <== multi_or[2][i].out; eq[22][i] = IsEqual(); eq[22][i].in[0] <== in[i]; - eq[22][i].in[1] <== 235; + eq[22][i].in[1] <== 224; + and[24][i] = AND(); + and[24][i].a <== states[i][10]; + and[24][i].b <== eq[22][i].out; + and[25][i] = AND(); + and[25][i].a <== states[i][11]; + and[25][i].b <== eq[22][i].out; + multi_or[3][i] = MultiOR(2); + multi_or[3][i].in[0] <== and[24][i].out; + multi_or[3][i].in[1] <== and[25][i].out; + states[i+1][13] <== multi_or[3][i].out; eq[23][i] = IsEqual(); eq[23][i].in[0] <== in[i]; - eq[23][i].in[1] <== 236; + eq[23][i].in[1] <== 225; eq[24][i] = IsEqual(); eq[24][i].in[0] <== in[i]; - eq[24][i].in[1] <== 238; + eq[24][i].in[1] <== 226; eq[25][i] = IsEqual(); eq[25][i].in[0] <== in[i]; - eq[25][i].in[1] <== 239; - and[22][i] = AND(); - and[22][i].a <== states[i][10]; - multi_or[2][i] = MultiOR(14); - multi_or[2][i].in[0] <== eq[12][i].out; - multi_or[2][i].in[1] <== eq[13][i].out; - multi_or[2][i].in[2] <== eq[14][i].out; - multi_or[2][i].in[3] <== eq[15][i].out; - multi_or[2][i].in[4] <== eq[16][i].out; - multi_or[2][i].in[5] <== eq[17][i].out; - multi_or[2][i].in[6] <== eq[18][i].out; - multi_or[2][i].in[7] <== eq[19][i].out; - multi_or[2][i].in[8] <== eq[20][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; - multi_or[2][i].in[12] <== eq[24][i].out; - multi_or[2][i].in[13] <== eq[25][i].out; - and[22][i].b <== multi_or[2][i].out; - lt[8][i] = LessEqThan(8); - lt[8][i].in[0] <== 144; - lt[8][i].in[1] <== in[i]; - lt[9][i] = LessEqThan(8); - lt[9][i].in[0] <== in[i]; - lt[9][i].in[1] <== 191; - and[23][i] = AND(); - and[23][i].a <== lt[8][i].out; - and[23][i].b <== lt[9][i].out; - and[24][i] = AND(); - and[24][i].a <== states[i][15]; - and[24][i].b <== and[23][i].out; - and[25][i] = AND(); - and[25][i].a <== states[i][16]; - and[25][i].b <== and[15][i].out; + eq[25][i].in[1] <== 227; eq[26][i] = IsEqual(); eq[26][i].in[0] <== in[i]; - eq[26][i].in[1] <== 128; + eq[26][i].in[1] <== 228; eq[27][i] = IsEqual(); eq[27][i].in[0] <== in[i]; - eq[27][i].in[1] <== 129; + eq[27][i].in[1] <== 229; eq[28][i] = IsEqual(); eq[28][i].in[0] <== in[i]; - eq[28][i].in[1] <== 130; + eq[28][i].in[1] <== 230; eq[29][i] = IsEqual(); eq[29][i].in[0] <== in[i]; - eq[29][i].in[1] <== 131; + eq[29][i].in[1] <== 231; eq[30][i] = IsEqual(); eq[30][i].in[0] <== in[i]; - eq[30][i].in[1] <== 132; + eq[30][i].in[1] <== 232; eq[31][i] = IsEqual(); eq[31][i].in[0] <== in[i]; - eq[31][i].in[1] <== 133; + eq[31][i].in[1] <== 233; eq[32][i] = IsEqual(); eq[32][i].in[0] <== in[i]; - eq[32][i].in[1] <== 134; + eq[32][i].in[1] <== 234; eq[33][i] = IsEqual(); eq[33][i].in[0] <== in[i]; - eq[33][i].in[1] <== 135; + eq[33][i].in[1] <== 235; eq[34][i] = IsEqual(); eq[34][i].in[0] <== in[i]; - eq[34][i].in[1] <== 136; + eq[34][i].in[1] <== 236; eq[35][i] = IsEqual(); eq[35][i].in[0] <== in[i]; - eq[35][i].in[1] <== 137; + eq[35][i].in[1] <== 238; eq[36][i] = IsEqual(); eq[36][i].in[0] <== in[i]; - eq[36][i].in[1] <== 138; + eq[36][i].in[1] <== 239; + and[26][i] = AND(); + and[26][i].a <== states[i][10]; + multi_or[4][i] = MultiOR(14); + multi_or[4][i].in[0] <== eq[23][i].out; + multi_or[4][i].in[1] <== eq[24][i].out; + multi_or[4][i].in[2] <== eq[25][i].out; + multi_or[4][i].in[3] <== eq[26][i].out; + multi_or[4][i].in[4] <== eq[27][i].out; + multi_or[4][i].in[5] <== eq[28][i].out; + multi_or[4][i].in[6] <== eq[29][i].out; + multi_or[4][i].in[7] <== eq[30][i].out; + multi_or[4][i].in[8] <== eq[31][i].out; + multi_or[4][i].in[9] <== eq[32][i].out; + multi_or[4][i].in[10] <== eq[33][i].out; + multi_or[4][i].in[11] <== eq[34][i].out; + multi_or[4][i].in[12] <== eq[35][i].out; + multi_or[4][i].in[13] <== eq[36][i].out; + and[26][i].b <== multi_or[4][i].out; + and[27][i] = AND(); + and[27][i].a <== states[i][11]; + and[27][i].b <== multi_or[4][i].out; + lt[10][i] = LessEqThan(8); + lt[10][i].in[0] <== 144; + lt[10][i].in[1] <== in[i]; + lt[11][i] = LessEqThan(8); + lt[11][i].in[0] <== in[i]; + lt[11][i].in[1] <== 191; + and[28][i] = AND(); + and[28][i].a <== lt[10][i].out; + and[28][i].b <== lt[11][i].out; + and[29][i] = AND(); + and[29][i].a <== states[i][16]; + and[29][i].b <== and[28][i].out; + and[30][i] = AND(); + and[30][i].a <== states[i][17]; + and[30][i].b <== and[14][i].out; eq[37][i] = IsEqual(); eq[37][i].in[0] <== in[i]; - eq[37][i].in[1] <== 139; + eq[37][i].in[1] <== 128; eq[38][i] = IsEqual(); eq[38][i].in[0] <== in[i]; - eq[38][i].in[1] <== 140; + eq[38][i].in[1] <== 129; eq[39][i] = IsEqual(); eq[39][i].in[0] <== in[i]; - eq[39][i].in[1] <== 141; + eq[39][i].in[1] <== 130; eq[40][i] = IsEqual(); eq[40][i].in[0] <== in[i]; - eq[40][i].in[1] <== 142; + eq[40][i].in[1] <== 131; eq[41][i] = IsEqual(); eq[41][i].in[0] <== in[i]; - eq[41][i].in[1] <== 143; - and[26][i] = AND(); - and[26][i].a <== states[i][17]; - multi_or[3][i] = MultiOR(16); - multi_or[3][i].in[0] <== eq[26][i].out; - multi_or[3][i].in[1] <== eq[27][i].out; - multi_or[3][i].in[2] <== eq[28][i].out; - multi_or[3][i].in[3] <== eq[29][i].out; - multi_or[3][i].in[4] <== eq[30][i].out; - multi_or[3][i].in[5] <== eq[31][i].out; - multi_or[3][i].in[6] <== eq[32][i].out; - multi_or[3][i].in[7] <== eq[33][i].out; - multi_or[3][i].in[8] <== eq[34][i].out; - multi_or[3][i].in[9] <== eq[35][i].out; - multi_or[3][i].in[10] <== eq[36][i].out; - multi_or[3][i].in[11] <== eq[37][i].out; - multi_or[3][i].in[12] <== eq[38][i].out; - multi_or[3][i].in[13] <== eq[39][i].out; - multi_or[3][i].in[14] <== eq[40][i].out; - multi_or[3][i].in[15] <== eq[41][i].out; - and[26][i].b <== multi_or[3][i].out; - and[27][i] = AND(); - and[27][i].a <== states[i][18]; - and[27][i].b <== multi_or[2][i].out; - multi_or[4][i] = MultiOR(5); - multi_or[4][i].in[0] <== and[22][i].out; - multi_or[4][i].in[1] <== and[24][i].out; - multi_or[4][i].in[2] <== and[25][i].out; - multi_or[4][i].in[3] <== and[26][i].out; - multi_or[4][i].in[4] <== and[27][i].out; - states[i+1][13] <== multi_or[4][i].out; + eq[41][i].in[1] <== 132; eq[42][i] = IsEqual(); eq[42][i].in[0] <== in[i]; - eq[42][i].in[1] <== 237; - and[28][i] = AND(); - and[28][i].a <== states[i][10]; - and[28][i].b <== eq[42][i].out; - and[29][i] = AND(); - and[29][i].a <== states[i][18]; - and[29][i].b <== eq[42][i].out; - multi_or[5][i] = MultiOR(2); - multi_or[5][i].in[0] <== and[28][i].out; - multi_or[5][i].in[1] <== and[29][i].out; - states[i+1][14] <== multi_or[5][i].out; + eq[42][i].in[1] <== 133; eq[43][i] = IsEqual(); eq[43][i].in[0] <== in[i]; - eq[43][i].in[1] <== 240; - and[30][i] = AND(); - and[30][i].a <== states[i][10]; - and[30][i].b <== eq[43][i].out; - and[31][i] = AND(); - and[31][i].a <== states[i][18]; - and[31][i].b <== eq[43][i].out; - multi_or[6][i] = MultiOR(2); - multi_or[6][i].in[0] <== and[30][i].out; - multi_or[6][i].in[1] <== and[31][i].out; - states[i+1][15] <== multi_or[6][i].out; + eq[43][i].in[1] <== 134; eq[44][i] = IsEqual(); eq[44][i].in[0] <== in[i]; - eq[44][i].in[1] <== 241; + eq[44][i].in[1] <== 135; eq[45][i] = IsEqual(); eq[45][i].in[0] <== in[i]; - eq[45][i].in[1] <== 242; + eq[45][i].in[1] <== 136; eq[46][i] = IsEqual(); eq[46][i].in[0] <== in[i]; - eq[46][i].in[1] <== 243; - and[32][i] = AND(); - and[32][i].a <== states[i][10]; - multi_or[7][i] = MultiOR(3); - multi_or[7][i].in[0] <== eq[44][i].out; - multi_or[7][i].in[1] <== eq[45][i].out; - multi_or[7][i].in[2] <== eq[46][i].out; - and[32][i].b <== multi_or[7][i].out; - and[33][i] = AND(); - and[33][i].a <== states[i][18]; - and[33][i].b <== multi_or[7][i].out; - multi_or[8][i] = MultiOR(2); - multi_or[8][i].in[0] <== and[32][i].out; - multi_or[8][i].in[1] <== and[33][i].out; - states[i+1][16] <== multi_or[8][i].out; + eq[46][i].in[1] <== 137; eq[47][i] = IsEqual(); eq[47][i].in[0] <== in[i]; - eq[47][i].in[1] <== 244; - and[34][i] = AND(); - and[34][i].a <== states[i][10]; - and[34][i].b <== eq[47][i].out; - and[35][i] = AND(); - and[35][i].a <== states[i][18]; - and[35][i].b <== eq[47][i].out; - multi_or[9][i] = MultiOR(2); - multi_or[9][i].in[0] <== and[34][i].out; - multi_or[9][i].in[1] <== and[35][i].out; - states[i+1][17] <== multi_or[9][i].out; - lt[10][i] = LessEqThan(8); - lt[10][i].in[0] <== 14; - lt[10][i].in[1] <== in[i]; - lt[11][i] = LessEqThan(8); - lt[11][i].in[0] <== in[i]; - lt[11][i].in[1] <== 127; - and[36][i] = AND(); - and[36][i].a <== lt[10][i].out; - and[36][i].b <== lt[11][i].out; + eq[47][i].in[1] <== 138; eq[48][i] = IsEqual(); eq[48][i].in[0] <== in[i]; - eq[48][i].in[1] <== 1; + eq[48][i].in[1] <== 139; eq[49][i] = IsEqual(); eq[49][i].in[0] <== in[i]; - eq[49][i].in[1] <== 2; + eq[49][i].in[1] <== 140; eq[50][i] = IsEqual(); eq[50][i].in[0] <== in[i]; - eq[50][i].in[1] <== 3; + eq[50][i].in[1] <== 141; eq[51][i] = IsEqual(); eq[51][i].in[0] <== in[i]; - eq[51][i].in[1] <== 4; + eq[51][i].in[1] <== 142; eq[52][i] = IsEqual(); eq[52][i].in[0] <== in[i]; - eq[52][i].in[1] <== 5; + eq[52][i].in[1] <== 143; + and[31][i] = AND(); + and[31][i].a <== states[i][18]; + multi_or[5][i] = MultiOR(16); + multi_or[5][i].in[0] <== eq[37][i].out; + multi_or[5][i].in[1] <== eq[38][i].out; + multi_or[5][i].in[2] <== eq[39][i].out; + multi_or[5][i].in[3] <== eq[40][i].out; + multi_or[5][i].in[4] <== eq[41][i].out; + multi_or[5][i].in[5] <== eq[42][i].out; + multi_or[5][i].in[6] <== eq[43][i].out; + multi_or[5][i].in[7] <== eq[44][i].out; + multi_or[5][i].in[8] <== eq[45][i].out; + multi_or[5][i].in[9] <== eq[46][i].out; + multi_or[5][i].in[10] <== eq[47][i].out; + multi_or[5][i].in[11] <== eq[48][i].out; + multi_or[5][i].in[12] <== eq[49][i].out; + multi_or[5][i].in[13] <== eq[50][i].out; + multi_or[5][i].in[14] <== eq[51][i].out; + multi_or[5][i].in[15] <== eq[52][i].out; + and[31][i].b <== multi_or[5][i].out; + multi_or[6][i] = MultiOR(5); + multi_or[6][i].in[0] <== and[26][i].out; + multi_or[6][i].in[1] <== and[27][i].out; + multi_or[6][i].in[2] <== and[29][i].out; + multi_or[6][i].in[3] <== and[30][i].out; + multi_or[6][i].in[4] <== and[31][i].out; + states[i+1][14] <== multi_or[6][i].out; eq[53][i] = IsEqual(); eq[53][i].in[0] <== in[i]; - eq[53][i].in[1] <== 6; + eq[53][i].in[1] <== 237; + and[32][i] = AND(); + and[32][i].a <== states[i][10]; + and[32][i].b <== eq[53][i].out; + and[33][i] = AND(); + and[33][i].a <== states[i][11]; + and[33][i].b <== eq[53][i].out; + multi_or[7][i] = MultiOR(2); + multi_or[7][i].in[0] <== and[32][i].out; + multi_or[7][i].in[1] <== and[33][i].out; + states[i+1][15] <== multi_or[7][i].out; eq[54][i] = IsEqual(); eq[54][i].in[0] <== in[i]; - eq[54][i].in[1] <== 7; + eq[54][i].in[1] <== 240; + and[34][i] = AND(); + and[34][i].a <== states[i][10]; + and[34][i].b <== eq[54][i].out; + and[35][i] = AND(); + and[35][i].a <== states[i][11]; + and[35][i].b <== eq[54][i].out; + multi_or[8][i] = MultiOR(2); + multi_or[8][i].in[0] <== and[34][i].out; + multi_or[8][i].in[1] <== and[35][i].out; + states[i+1][16] <== multi_or[8][i].out; eq[55][i] = IsEqual(); eq[55][i].in[0] <== in[i]; - eq[55][i].in[1] <== 8; + eq[55][i].in[1] <== 241; eq[56][i] = IsEqual(); eq[56][i].in[0] <== in[i]; - eq[56][i].in[1] <== 9; + eq[56][i].in[1] <== 242; eq[57][i] = IsEqual(); eq[57][i].in[0] <== in[i]; - eq[57][i].in[1] <== 11; - eq[58][i] = IsEqual(); - eq[58][i].in[0] <== in[i]; - eq[58][i].in[1] <== 12; + eq[57][i].in[1] <== 243; + and[36][i] = AND(); + and[36][i].a <== states[i][10]; + multi_or[9][i] = MultiOR(3); + multi_or[9][i].in[0] <== eq[55][i].out; + multi_or[9][i].in[1] <== eq[56][i].out; + multi_or[9][i].in[2] <== eq[57][i].out; + and[36][i].b <== multi_or[9][i].out; and[37][i] = AND(); - and[37][i].a <== states[i][10]; - multi_or[10][i] = MultiOR(12); + and[37][i].a <== states[i][11]; + and[37][i].b <== multi_or[9][i].out; + multi_or[10][i] = MultiOR(2); multi_or[10][i].in[0] <== and[36][i].out; - multi_or[10][i].in[1] <== eq[48][i].out; - multi_or[10][i].in[2] <== eq[49][i].out; - multi_or[10][i].in[3] <== eq[50][i].out; - multi_or[10][i].in[4] <== eq[51][i].out; - multi_or[10][i].in[5] <== eq[52][i].out; - multi_or[10][i].in[6] <== eq[53][i].out; - multi_or[10][i].in[7] <== eq[54][i].out; - multi_or[10][i].in[8] <== eq[55][i].out; - multi_or[10][i].in[9] <== eq[56][i].out; - multi_or[10][i].in[10] <== eq[57][i].out; - multi_or[10][i].in[11] <== eq[58][i].out; - and[37][i].b <== multi_or[10][i].out; + multi_or[10][i].in[1] <== and[37][i].out; + states[i+1][17] <== multi_or[10][i].out; + eq[58][i] = IsEqual(); + eq[58][i].in[0] <== in[i]; + eq[58][i].in[1] <== 244; and[38][i] = AND(); - and[38][i].a <== states[i][11]; - and[38][i].b <== and[15][i].out; + and[38][i].a <== states[i][10]; + and[38][i].b <== eq[58][i].out; and[39][i] = AND(); - and[39][i].a <== states[i][18]; - and[39][i].b <== multi_or[10][i].out; - multi_or[11][i] = MultiOR(3); - multi_or[11][i].in[0] <== and[37][i].out; - multi_or[11][i].in[1] <== and[38][i].out; - multi_or[11][i].in[2] <== and[39][i].out; + and[39][i].a <== states[i][11]; + and[39][i].b <== eq[58][i].out; + multi_or[11][i] = MultiOR(2); + multi_or[11][i].in[0] <== and[38][i].out; + multi_or[11][i].in[1] <== and[39][i].out; states[i+1][18] <== multi_or[11][i].out; and[40][i] = AND(); - and[40][i].a <== states[i][18]; + and[40][i].a <== states[i][11]; and[40][i].b <== eq[0][i].out; states[i+1][19] <== and[40][i].out; and[41][i] = AND(); @@ -507,13 +507,13 @@ template SubjectAllRegex(msg_bytes) { is_consecutive[msg_bytes-1-i][1] <== state_changed[msg_bytes-i].out * is_consecutive[msg_bytes-1-i][0]; is_consecutive[msg_bytes-1-i][2] <== ORAnd()([(1 - from_zero_enabled[msg_bytes-i+1]), states[num_bytes-i][20], is_consecutive[msg_bytes-1-i][1]]); } - // substrings calculated: [{(10, 11), (10, 12), (10, 13), (10, 14), (10, 15), (10, 16), (10, 17), (10, 18), (11, 18), (12, 11), (13, 11), (14, 11), (15, 13), (16, 13), (17, 13), (18, 11), (18, 12), (18, 13), (18, 14), (18, 15), (18, 16), (18, 17), (18, 18)}] + // substrings calculated: [{(10, 11), (10, 12), (10, 13), (10, 14), (10, 15), (10, 16), (10, 17), (10, 18), (11, 11), (11, 12), (11, 13), (11, 14), (11, 15), (11, 16), (11, 17), (11, 18), (12, 11), (13, 12), (14, 12), (15, 12), (16, 14), (17, 14), (18, 14)}] signal prev_states0[23][msg_bytes]; signal is_substr0[msg_bytes]; signal is_reveal0[msg_bytes]; signal output reveal0[msg_bytes]; for (var i = 0; i < msg_bytes; i++) { - // the 0-th substring transitions: [(10, 11), (10, 12), (10, 13), (10, 14), (10, 15), (10, 16), (10, 17), (10, 18), (11, 18), (12, 11), (13, 11), (14, 11), (15, 13), (16, 13), (17, 13), (18, 11), (18, 12), (18, 13), (18, 14), (18, 15), (18, 16), (18, 17), (18, 18)] + // the 0-th substring transitions: [(10, 11), (10, 12), (10, 13), (10, 14), (10, 15), (10, 16), (10, 17), (10, 18), (11, 11), (11, 12), (11, 13), (11, 14), (11, 15), (11, 16), (11, 17), (11, 18), (12, 11), (13, 12), (14, 12), (15, 12), (16, 14), (17, 14), (18, 14)] prev_states0[0][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][10]; prev_states0[1][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][10]; prev_states0[2][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][10]; @@ -523,21 +523,21 @@ template SubjectAllRegex(msg_bytes) { prev_states0[6][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][10]; prev_states0[7][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][10]; prev_states0[8][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][11]; - prev_states0[9][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][12]; - prev_states0[10][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][13]; - prev_states0[11][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][14]; - prev_states0[12][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][15]; - prev_states0[13][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][16]; - prev_states0[14][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][17]; - prev_states0[15][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][18]; - prev_states0[16][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][18]; - prev_states0[17][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][18]; - prev_states0[18][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][18]; - prev_states0[19][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][18]; - prev_states0[20][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][18]; - prev_states0[21][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][18]; + prev_states0[9][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][11]; + prev_states0[10][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][11]; + prev_states0[11][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][11]; + prev_states0[12][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][11]; + prev_states0[13][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][11]; + prev_states0[14][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][11]; + prev_states0[15][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][11]; + prev_states0[16][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][12]; + prev_states0[17][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][13]; + prev_states0[18][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][14]; + prev_states0[19][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][15]; + prev_states0[20][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][16]; + prev_states0[21][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][17]; prev_states0[22][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][18]; - is_substr0[i] <== MultiOR(23)([prev_states0[0][i] * states[i+2][11], prev_states0[1][i] * states[i+2][12], prev_states0[2][i] * states[i+2][13], prev_states0[3][i] * states[i+2][14], prev_states0[4][i] * states[i+2][15], prev_states0[5][i] * states[i+2][16], prev_states0[6][i] * states[i+2][17], prev_states0[7][i] * states[i+2][18], prev_states0[8][i] * states[i+2][18], prev_states0[9][i] * states[i+2][11], prev_states0[10][i] * states[i+2][11], prev_states0[11][i] * states[i+2][11], prev_states0[12][i] * states[i+2][13], prev_states0[13][i] * states[i+2][13], prev_states0[14][i] * states[i+2][13], prev_states0[15][i] * states[i+2][11], prev_states0[16][i] * states[i+2][12], prev_states0[17][i] * states[i+2][13], prev_states0[18][i] * states[i+2][14], prev_states0[19][i] * states[i+2][15], prev_states0[20][i] * states[i+2][16], prev_states0[21][i] * states[i+2][17], prev_states0[22][i] * states[i+2][18]]); + is_substr0[i] <== MultiOR(23)([prev_states0[0][i] * states[i+2][11], prev_states0[1][i] * states[i+2][12], prev_states0[2][i] * states[i+2][13], prev_states0[3][i] * states[i+2][14], prev_states0[4][i] * states[i+2][15], prev_states0[5][i] * states[i+2][16], prev_states0[6][i] * states[i+2][17], prev_states0[7][i] * states[i+2][18], prev_states0[8][i] * states[i+2][11], prev_states0[9][i] * states[i+2][12], prev_states0[10][i] * states[i+2][13], prev_states0[11][i] * states[i+2][14], prev_states0[12][i] * states[i+2][15], prev_states0[13][i] * states[i+2][16], prev_states0[14][i] * states[i+2][17], prev_states0[15][i] * states[i+2][18], prev_states0[16][i] * states[i+2][11], prev_states0[17][i] * states[i+2][12], prev_states0[18][i] * states[i+2][12], prev_states0[19][i] * states[i+2][12], prev_states0[20][i] * states[i+2][14], prev_states0[21][i] * states[i+2][14], prev_states0[22][i] * states[i+2][14]]); is_reveal0[i] <== MultiAND(3)([out, is_substr0[i], is_consecutive[i][2]]); reveal0[i] <== in[i+1] * is_reveal0[i]; } diff --git a/packages/circom/circuits/common/to_addr.json b/packages/circom/circuits/common/to_addr.json index a41aca3..618c55f 100644 --- a/packages/circom/circuits/common/to_addr.json +++ b/packages/circom/circuits/common/to_addr.json @@ -10,11 +10,11 @@ }, { "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, "regex_def": ">?\r\n" } ] -} +} \ No newline at end of file diff --git a/packages/circom/circuits/common/to_all_regex.circom b/packages/circom/circuits/common/to_all_regex.circom index 456b6dc..2dbbca8 100644 --- a/packages/circom/circuits/common/to_all_regex.circom +++ b/packages/circom/circuits/common/to_all_regex.circom @@ -73,362 +73,362 @@ template ToAllRegex(msg_bytes) { and[5][i].b <== eq[5][i].out; states[i+1][5] <== and[5][i].out; lt[0][i] = LessEqThan(8); - lt[0][i].in[0] <== 194; + lt[0][i].in[0] <== 14; lt[0][i].in[1] <== in[i]; lt[1][i] = LessEqThan(8); lt[1][i].in[0] <== in[i]; - lt[1][i].in[1] <== 223; + lt[1][i].in[1] <== 127; and[6][i] = AND(); and[6][i].a <== lt[0][i].out; and[6][i].b <== lt[1][i].out; - and[7][i] = AND(); - and[7][i].a <== states[i][5]; - and[7][i].b <== and[6][i].out; - lt[2][i] = LessEqThan(8); - lt[2][i].in[0] <== 160; - lt[2][i].in[1] <== in[i]; - lt[3][i] = LessEqThan(8); - lt[3][i].in[0] <== in[i]; - lt[3][i].in[1] <== 191; - and[8][i] = AND(); - and[8][i].a <== lt[2][i].out; - and[8][i].b <== lt[3][i].out; - and[9][i] = AND(); - and[9][i].a <== states[i][7]; - and[9][i].b <== and[8][i].out; - lt[4][i] = LessEqThan(8); - lt[4][i].in[0] <== 128; - lt[4][i].in[1] <== in[i]; - lt[5][i] = LessEqThan(8); - lt[5][i].in[0] <== in[i]; - lt[5][i].in[1] <== 191; - and[10][i] = AND(); - and[10][i].a <== lt[4][i].out; - and[10][i].b <== lt[5][i].out; - and[11][i] = AND(); - and[11][i].a <== states[i][8]; - and[11][i].b <== and[10][i].out; - lt[6][i] = LessEqThan(8); - lt[6][i].in[0] <== 128; - lt[6][i].in[1] <== in[i]; - lt[7][i] = LessEqThan(8); - lt[7][i].in[0] <== in[i]; - lt[7][i].in[1] <== 159; - and[12][i] = AND(); - and[12][i].a <== lt[6][i].out; - and[12][i].b <== lt[7][i].out; - and[13][i] = AND(); - and[13][i].a <== states[i][9]; - and[13][i].b <== and[12][i].out; - and[14][i] = AND(); - and[14][i].a <== states[i][13]; - and[14][i].b <== and[6][i].out; - multi_or[0][i] = MultiOR(5); - multi_or[0][i].in[0] <== and[7][i].out; - multi_or[0][i].in[1] <== and[9][i].out; - multi_or[0][i].in[2] <== and[11][i].out; - multi_or[0][i].in[3] <== and[13][i].out; - multi_or[0][i].in[4] <== and[14][i].out; - states[i+1][6] <== multi_or[0][i].out; eq[6][i] = IsEqual(); eq[6][i].in[0] <== in[i]; - eq[6][i].in[1] <== 224; - and[15][i] = AND(); - and[15][i].a <== states[i][5]; - and[15][i].b <== eq[6][i].out; - and[16][i] = AND(); - and[16][i].a <== states[i][13]; - and[16][i].b <== eq[6][i].out; - multi_or[1][i] = MultiOR(2); - multi_or[1][i].in[0] <== and[15][i].out; - multi_or[1][i].in[1] <== and[16][i].out; - states[i+1][7] <== multi_or[1][i].out; + eq[6][i].in[1] <== 1; eq[7][i] = IsEqual(); eq[7][i].in[0] <== in[i]; - eq[7][i].in[1] <== 225; + eq[7][i].in[1] <== 2; eq[8][i] = IsEqual(); eq[8][i].in[0] <== in[i]; - eq[8][i].in[1] <== 226; + eq[8][i].in[1] <== 3; eq[9][i] = IsEqual(); eq[9][i].in[0] <== in[i]; - eq[9][i].in[1] <== 227; + eq[9][i].in[1] <== 4; eq[10][i] = IsEqual(); eq[10][i].in[0] <== in[i]; - eq[10][i].in[1] <== 228; + eq[10][i].in[1] <== 5; eq[11][i] = IsEqual(); eq[11][i].in[0] <== in[i]; - eq[11][i].in[1] <== 229; + eq[11][i].in[1] <== 6; eq[12][i] = IsEqual(); eq[12][i].in[0] <== in[i]; - eq[12][i].in[1] <== 230; + eq[12][i].in[1] <== 7; eq[13][i] = IsEqual(); eq[13][i].in[0] <== in[i]; - eq[13][i].in[1] <== 231; + eq[13][i].in[1] <== 8; eq[14][i] = IsEqual(); eq[14][i].in[0] <== in[i]; - eq[14][i].in[1] <== 232; + eq[14][i].in[1] <== 9; eq[15][i] = IsEqual(); eq[15][i].in[0] <== in[i]; - eq[15][i].in[1] <== 233; + eq[15][i].in[1] <== 11; eq[16][i] = IsEqual(); eq[16][i].in[0] <== in[i]; - eq[16][i].in[1] <== 234; + eq[16][i].in[1] <== 12; + and[7][i] = AND(); + and[7][i].a <== states[i][5]; + multi_or[0][i] = MultiOR(12); + multi_or[0][i].in[0] <== and[6][i].out; + multi_or[0][i].in[1] <== eq[6][i].out; + multi_or[0][i].in[2] <== eq[7][i].out; + multi_or[0][i].in[3] <== eq[8][i].out; + multi_or[0][i].in[4] <== eq[9][i].out; + multi_or[0][i].in[5] <== eq[10][i].out; + multi_or[0][i].in[6] <== eq[11][i].out; + multi_or[0][i].in[7] <== eq[12][i].out; + multi_or[0][i].in[8] <== eq[13][i].out; + multi_or[0][i].in[9] <== eq[14][i].out; + multi_or[0][i].in[10] <== eq[15][i].out; + multi_or[0][i].in[11] <== eq[16][i].out; + and[7][i].b <== multi_or[0][i].out; + and[8][i] = AND(); + and[8][i].a <== states[i][6]; + and[8][i].b <== multi_or[0][i].out; + lt[2][i] = LessEqThan(8); + lt[2][i].in[0] <== 128; + lt[2][i].in[1] <== in[i]; + lt[3][i] = LessEqThan(8); + lt[3][i].in[0] <== in[i]; + lt[3][i].in[1] <== 191; + and[9][i] = AND(); + and[9][i].a <== lt[2][i].out; + and[9][i].b <== lt[3][i].out; + and[10][i] = AND(); + and[10][i].a <== states[i][7]; + and[10][i].b <== and[9][i].out; + multi_or[1][i] = MultiOR(3); + multi_or[1][i].in[0] <== and[7][i].out; + multi_or[1][i].in[1] <== and[8][i].out; + multi_or[1][i].in[2] <== and[10][i].out; + states[i+1][6] <== multi_or[1][i].out; + lt[4][i] = LessEqThan(8); + lt[4][i].in[0] <== 194; + lt[4][i].in[1] <== in[i]; + lt[5][i] = LessEqThan(8); + lt[5][i].in[0] <== in[i]; + lt[5][i].in[1] <== 223; + and[11][i] = AND(); + and[11][i].a <== lt[4][i].out; + and[11][i].b <== lt[5][i].out; + and[12][i] = AND(); + and[12][i].a <== states[i][5]; + and[12][i].b <== and[11][i].out; + and[13][i] = AND(); + and[13][i].a <== states[i][6]; + and[13][i].b <== and[11][i].out; + lt[6][i] = LessEqThan(8); + lt[6][i].in[0] <== 160; + lt[6][i].in[1] <== in[i]; + lt[7][i] = LessEqThan(8); + lt[7][i].in[0] <== in[i]; + lt[7][i].in[1] <== 191; + and[14][i] = AND(); + and[14][i].a <== lt[6][i].out; + and[14][i].b <== lt[7][i].out; + and[15][i] = AND(); + and[15][i].a <== states[i][8]; + and[15][i].b <== and[14][i].out; + and[16][i] = AND(); + and[16][i].a <== states[i][9]; + and[16][i].b <== and[9][i].out; + lt[8][i] = LessEqThan(8); + lt[8][i].in[0] <== 128; + lt[8][i].in[1] <== in[i]; + lt[9][i] = LessEqThan(8); + lt[9][i].in[0] <== in[i]; + lt[9][i].in[1] <== 159; + and[17][i] = AND(); + and[17][i].a <== lt[8][i].out; + and[17][i].b <== lt[9][i].out; + and[18][i] = AND(); + and[18][i].a <== states[i][10]; + and[18][i].b <== and[17][i].out; + multi_or[2][i] = MultiOR(5); + multi_or[2][i].in[0] <== and[12][i].out; + multi_or[2][i].in[1] <== and[13][i].out; + multi_or[2][i].in[2] <== and[15][i].out; + multi_or[2][i].in[3] <== and[16][i].out; + multi_or[2][i].in[4] <== and[18][i].out; + states[i+1][7] <== multi_or[2][i].out; eq[17][i] = IsEqual(); eq[17][i].in[0] <== in[i]; - eq[17][i].in[1] <== 235; + eq[17][i].in[1] <== 224; + and[19][i] = AND(); + and[19][i].a <== states[i][5]; + and[19][i].b <== eq[17][i].out; + and[20][i] = AND(); + and[20][i].a <== states[i][6]; + and[20][i].b <== eq[17][i].out; + multi_or[3][i] = MultiOR(2); + multi_or[3][i].in[0] <== and[19][i].out; + multi_or[3][i].in[1] <== and[20][i].out; + states[i+1][8] <== multi_or[3][i].out; eq[18][i] = IsEqual(); eq[18][i].in[0] <== in[i]; - eq[18][i].in[1] <== 236; + eq[18][i].in[1] <== 225; eq[19][i] = IsEqual(); eq[19][i].in[0] <== in[i]; - eq[19][i].in[1] <== 238; + eq[19][i].in[1] <== 226; eq[20][i] = IsEqual(); eq[20][i].in[0] <== in[i]; - eq[20][i].in[1] <== 239; - and[17][i] = AND(); - and[17][i].a <== states[i][5]; - multi_or[2][i] = MultiOR(14); - multi_or[2][i].in[0] <== eq[7][i].out; - multi_or[2][i].in[1] <== eq[8][i].out; - multi_or[2][i].in[2] <== eq[9][i].out; - multi_or[2][i].in[3] <== eq[10][i].out; - multi_or[2][i].in[4] <== eq[11][i].out; - multi_or[2][i].in[5] <== eq[12][i].out; - multi_or[2][i].in[6] <== eq[13][i].out; - multi_or[2][i].in[7] <== eq[14][i].out; - multi_or[2][i].in[8] <== eq[15][i].out; - multi_or[2][i].in[9] <== eq[16][i].out; - multi_or[2][i].in[10] <== eq[17][i].out; - multi_or[2][i].in[11] <== eq[18][i].out; - multi_or[2][i].in[12] <== eq[19][i].out; - multi_or[2][i].in[13] <== eq[20][i].out; - and[17][i].b <== multi_or[2][i].out; - lt[8][i] = LessEqThan(8); - lt[8][i].in[0] <== 144; - lt[8][i].in[1] <== in[i]; - lt[9][i] = LessEqThan(8); - lt[9][i].in[0] <== in[i]; - lt[9][i].in[1] <== 191; - and[18][i] = AND(); - and[18][i].a <== lt[8][i].out; - and[18][i].b <== lt[9][i].out; - and[19][i] = AND(); - and[19][i].a <== states[i][10]; - and[19][i].b <== and[18][i].out; - and[20][i] = AND(); - and[20][i].a <== states[i][11]; - and[20][i].b <== and[10][i].out; + eq[20][i].in[1] <== 227; eq[21][i] = IsEqual(); eq[21][i].in[0] <== in[i]; - eq[21][i].in[1] <== 128; + eq[21][i].in[1] <== 228; eq[22][i] = IsEqual(); eq[22][i].in[0] <== in[i]; - eq[22][i].in[1] <== 129; + eq[22][i].in[1] <== 229; eq[23][i] = IsEqual(); eq[23][i].in[0] <== in[i]; - eq[23][i].in[1] <== 130; + eq[23][i].in[1] <== 230; eq[24][i] = IsEqual(); eq[24][i].in[0] <== in[i]; - eq[24][i].in[1] <== 131; + eq[24][i].in[1] <== 231; eq[25][i] = IsEqual(); eq[25][i].in[0] <== in[i]; - eq[25][i].in[1] <== 132; + eq[25][i].in[1] <== 232; eq[26][i] = IsEqual(); eq[26][i].in[0] <== in[i]; - eq[26][i].in[1] <== 133; + eq[26][i].in[1] <== 233; eq[27][i] = IsEqual(); eq[27][i].in[0] <== in[i]; - eq[27][i].in[1] <== 134; + eq[27][i].in[1] <== 234; eq[28][i] = IsEqual(); eq[28][i].in[0] <== in[i]; - eq[28][i].in[1] <== 135; + eq[28][i].in[1] <== 235; eq[29][i] = IsEqual(); eq[29][i].in[0] <== in[i]; - eq[29][i].in[1] <== 136; + eq[29][i].in[1] <== 236; eq[30][i] = IsEqual(); eq[30][i].in[0] <== in[i]; - eq[30][i].in[1] <== 137; + eq[30][i].in[1] <== 238; eq[31][i] = IsEqual(); eq[31][i].in[0] <== in[i]; - eq[31][i].in[1] <== 138; + eq[31][i].in[1] <== 239; + and[21][i] = AND(); + and[21][i].a <== states[i][5]; + multi_or[4][i] = MultiOR(14); + multi_or[4][i].in[0] <== eq[18][i].out; + multi_or[4][i].in[1] <== eq[19][i].out; + multi_or[4][i].in[2] <== eq[20][i].out; + multi_or[4][i].in[3] <== eq[21][i].out; + multi_or[4][i].in[4] <== eq[22][i].out; + multi_or[4][i].in[5] <== eq[23][i].out; + multi_or[4][i].in[6] <== eq[24][i].out; + multi_or[4][i].in[7] <== eq[25][i].out; + multi_or[4][i].in[8] <== eq[26][i].out; + multi_or[4][i].in[9] <== eq[27][i].out; + multi_or[4][i].in[10] <== eq[28][i].out; + multi_or[4][i].in[11] <== eq[29][i].out; + multi_or[4][i].in[12] <== eq[30][i].out; + multi_or[4][i].in[13] <== eq[31][i].out; + and[21][i].b <== multi_or[4][i].out; + and[22][i] = AND(); + and[22][i].a <== states[i][6]; + and[22][i].b <== multi_or[4][i].out; + lt[10][i] = LessEqThan(8); + lt[10][i].in[0] <== 144; + lt[10][i].in[1] <== in[i]; + lt[11][i] = LessEqThan(8); + lt[11][i].in[0] <== in[i]; + lt[11][i].in[1] <== 191; + and[23][i] = AND(); + and[23][i].a <== lt[10][i].out; + and[23][i].b <== lt[11][i].out; + and[24][i] = AND(); + and[24][i].a <== states[i][11]; + and[24][i].b <== and[23][i].out; + and[25][i] = AND(); + and[25][i].a <== states[i][12]; + and[25][i].b <== and[9][i].out; eq[32][i] = IsEqual(); eq[32][i].in[0] <== in[i]; - eq[32][i].in[1] <== 139; + eq[32][i].in[1] <== 128; eq[33][i] = IsEqual(); eq[33][i].in[0] <== in[i]; - eq[33][i].in[1] <== 140; + eq[33][i].in[1] <== 129; eq[34][i] = IsEqual(); eq[34][i].in[0] <== in[i]; - eq[34][i].in[1] <== 141; + eq[34][i].in[1] <== 130; eq[35][i] = IsEqual(); eq[35][i].in[0] <== in[i]; - eq[35][i].in[1] <== 142; + eq[35][i].in[1] <== 131; eq[36][i] = IsEqual(); eq[36][i].in[0] <== in[i]; - eq[36][i].in[1] <== 143; - and[21][i] = AND(); - and[21][i].a <== states[i][12]; - multi_or[3][i] = MultiOR(16); - multi_or[3][i].in[0] <== eq[21][i].out; - multi_or[3][i].in[1] <== eq[22][i].out; - multi_or[3][i].in[2] <== eq[23][i].out; - multi_or[3][i].in[3] <== eq[24][i].out; - multi_or[3][i].in[4] <== eq[25][i].out; - multi_or[3][i].in[5] <== eq[26][i].out; - multi_or[3][i].in[6] <== eq[27][i].out; - multi_or[3][i].in[7] <== eq[28][i].out; - multi_or[3][i].in[8] <== eq[29][i].out; - multi_or[3][i].in[9] <== eq[30][i].out; - multi_or[3][i].in[10] <== eq[31][i].out; - multi_or[3][i].in[11] <== eq[32][i].out; - multi_or[3][i].in[12] <== eq[33][i].out; - multi_or[3][i].in[13] <== eq[34][i].out; - multi_or[3][i].in[14] <== eq[35][i].out; - multi_or[3][i].in[15] <== eq[36][i].out; - and[21][i].b <== multi_or[3][i].out; - and[22][i] = AND(); - and[22][i].a <== states[i][13]; - and[22][i].b <== multi_or[2][i].out; - multi_or[4][i] = MultiOR(5); - multi_or[4][i].in[0] <== and[17][i].out; - multi_or[4][i].in[1] <== and[19][i].out; - multi_or[4][i].in[2] <== and[20][i].out; - multi_or[4][i].in[3] <== and[21][i].out; - multi_or[4][i].in[4] <== and[22][i].out; - states[i+1][8] <== multi_or[4][i].out; + eq[36][i].in[1] <== 132; eq[37][i] = IsEqual(); eq[37][i].in[0] <== in[i]; - eq[37][i].in[1] <== 237; - and[23][i] = AND(); - and[23][i].a <== states[i][5]; - and[23][i].b <== eq[37][i].out; - and[24][i] = AND(); - and[24][i].a <== states[i][13]; - and[24][i].b <== eq[37][i].out; - multi_or[5][i] = MultiOR(2); - multi_or[5][i].in[0] <== and[23][i].out; - multi_or[5][i].in[1] <== and[24][i].out; - states[i+1][9] <== multi_or[5][i].out; + eq[37][i].in[1] <== 133; eq[38][i] = IsEqual(); eq[38][i].in[0] <== in[i]; - eq[38][i].in[1] <== 240; - and[25][i] = AND(); - and[25][i].a <== states[i][5]; - and[25][i].b <== eq[38][i].out; - and[26][i] = AND(); - and[26][i].a <== states[i][13]; - and[26][i].b <== eq[38][i].out; - multi_or[6][i] = MultiOR(2); - multi_or[6][i].in[0] <== and[25][i].out; - multi_or[6][i].in[1] <== and[26][i].out; - states[i+1][10] <== multi_or[6][i].out; + eq[38][i].in[1] <== 134; eq[39][i] = IsEqual(); eq[39][i].in[0] <== in[i]; - eq[39][i].in[1] <== 241; + eq[39][i].in[1] <== 135; eq[40][i] = IsEqual(); eq[40][i].in[0] <== in[i]; - eq[40][i].in[1] <== 242; + eq[40][i].in[1] <== 136; eq[41][i] = IsEqual(); eq[41][i].in[0] <== in[i]; - eq[41][i].in[1] <== 243; - and[27][i] = AND(); - and[27][i].a <== states[i][5]; - multi_or[7][i] = MultiOR(3); - multi_or[7][i].in[0] <== eq[39][i].out; - multi_or[7][i].in[1] <== eq[40][i].out; - multi_or[7][i].in[2] <== eq[41][i].out; - and[27][i].b <== multi_or[7][i].out; - and[28][i] = AND(); - and[28][i].a <== states[i][13]; - and[28][i].b <== multi_or[7][i].out; - multi_or[8][i] = MultiOR(2); - multi_or[8][i].in[0] <== and[27][i].out; - multi_or[8][i].in[1] <== and[28][i].out; - states[i+1][11] <== multi_or[8][i].out; + eq[41][i].in[1] <== 137; eq[42][i] = IsEqual(); eq[42][i].in[0] <== in[i]; - eq[42][i].in[1] <== 244; - and[29][i] = AND(); - and[29][i].a <== states[i][5]; - and[29][i].b <== eq[42][i].out; - and[30][i] = AND(); - and[30][i].a <== states[i][13]; - and[30][i].b <== eq[42][i].out; - multi_or[9][i] = MultiOR(2); - multi_or[9][i].in[0] <== and[29][i].out; - multi_or[9][i].in[1] <== and[30][i].out; - states[i+1][12] <== multi_or[9][i].out; - lt[10][i] = LessEqThan(8); - lt[10][i].in[0] <== 14; - lt[10][i].in[1] <== in[i]; - lt[11][i] = LessEqThan(8); - lt[11][i].in[0] <== in[i]; - lt[11][i].in[1] <== 127; - and[31][i] = AND(); - and[31][i].a <== lt[10][i].out; - and[31][i].b <== lt[11][i].out; + eq[42][i].in[1] <== 138; eq[43][i] = IsEqual(); eq[43][i].in[0] <== in[i]; - eq[43][i].in[1] <== 1; + eq[43][i].in[1] <== 139; eq[44][i] = IsEqual(); eq[44][i].in[0] <== in[i]; - eq[44][i].in[1] <== 2; + eq[44][i].in[1] <== 140; eq[45][i] = IsEqual(); eq[45][i].in[0] <== in[i]; - eq[45][i].in[1] <== 3; + eq[45][i].in[1] <== 141; eq[46][i] = IsEqual(); eq[46][i].in[0] <== in[i]; - eq[46][i].in[1] <== 4; + eq[46][i].in[1] <== 142; eq[47][i] = IsEqual(); eq[47][i].in[0] <== in[i]; - eq[47][i].in[1] <== 5; + eq[47][i].in[1] <== 143; + and[26][i] = AND(); + and[26][i].a <== states[i][13]; + multi_or[5][i] = MultiOR(16); + multi_or[5][i].in[0] <== eq[32][i].out; + multi_or[5][i].in[1] <== eq[33][i].out; + multi_or[5][i].in[2] <== eq[34][i].out; + multi_or[5][i].in[3] <== eq[35][i].out; + multi_or[5][i].in[4] <== eq[36][i].out; + multi_or[5][i].in[5] <== eq[37][i].out; + multi_or[5][i].in[6] <== eq[38][i].out; + multi_or[5][i].in[7] <== eq[39][i].out; + multi_or[5][i].in[8] <== eq[40][i].out; + multi_or[5][i].in[9] <== eq[41][i].out; + multi_or[5][i].in[10] <== eq[42][i].out; + multi_or[5][i].in[11] <== eq[43][i].out; + multi_or[5][i].in[12] <== eq[44][i].out; + multi_or[5][i].in[13] <== eq[45][i].out; + multi_or[5][i].in[14] <== eq[46][i].out; + multi_or[5][i].in[15] <== eq[47][i].out; + and[26][i].b <== multi_or[5][i].out; + multi_or[6][i] = MultiOR(5); + multi_or[6][i].in[0] <== and[21][i].out; + multi_or[6][i].in[1] <== and[22][i].out; + multi_or[6][i].in[2] <== and[24][i].out; + multi_or[6][i].in[3] <== and[25][i].out; + multi_or[6][i].in[4] <== and[26][i].out; + states[i+1][9] <== multi_or[6][i].out; eq[48][i] = IsEqual(); eq[48][i].in[0] <== in[i]; - eq[48][i].in[1] <== 6; + eq[48][i].in[1] <== 237; + and[27][i] = AND(); + and[27][i].a <== states[i][5]; + and[27][i].b <== eq[48][i].out; + and[28][i] = AND(); + and[28][i].a <== states[i][6]; + and[28][i].b <== eq[48][i].out; + multi_or[7][i] = MultiOR(2); + multi_or[7][i].in[0] <== and[27][i].out; + multi_or[7][i].in[1] <== and[28][i].out; + states[i+1][10] <== multi_or[7][i].out; eq[49][i] = IsEqual(); eq[49][i].in[0] <== in[i]; - eq[49][i].in[1] <== 7; + eq[49][i].in[1] <== 240; + and[29][i] = AND(); + and[29][i].a <== states[i][5]; + and[29][i].b <== eq[49][i].out; + and[30][i] = AND(); + and[30][i].a <== states[i][6]; + and[30][i].b <== eq[49][i].out; + multi_or[8][i] = MultiOR(2); + multi_or[8][i].in[0] <== and[29][i].out; + multi_or[8][i].in[1] <== and[30][i].out; + states[i+1][11] <== multi_or[8][i].out; eq[50][i] = IsEqual(); eq[50][i].in[0] <== in[i]; - eq[50][i].in[1] <== 8; + eq[50][i].in[1] <== 241; eq[51][i] = IsEqual(); eq[51][i].in[0] <== in[i]; - eq[51][i].in[1] <== 9; + eq[51][i].in[1] <== 242; eq[52][i] = IsEqual(); eq[52][i].in[0] <== in[i]; - eq[52][i].in[1] <== 11; - eq[53][i] = IsEqual(); - eq[53][i].in[0] <== in[i]; - eq[53][i].in[1] <== 12; + eq[52][i].in[1] <== 243; + and[31][i] = AND(); + and[31][i].a <== states[i][5]; + multi_or[9][i] = MultiOR(3); + multi_or[9][i].in[0] <== eq[50][i].out; + multi_or[9][i].in[1] <== eq[51][i].out; + multi_or[9][i].in[2] <== eq[52][i].out; + and[31][i].b <== multi_or[9][i].out; and[32][i] = AND(); - and[32][i].a <== states[i][5]; - multi_or[10][i] = MultiOR(12); + and[32][i].a <== states[i][6]; + and[32][i].b <== multi_or[9][i].out; + multi_or[10][i] = MultiOR(2); multi_or[10][i].in[0] <== and[31][i].out; - multi_or[10][i].in[1] <== eq[43][i].out; - multi_or[10][i].in[2] <== eq[44][i].out; - multi_or[10][i].in[3] <== eq[45][i].out; - multi_or[10][i].in[4] <== eq[46][i].out; - multi_or[10][i].in[5] <== eq[47][i].out; - multi_or[10][i].in[6] <== eq[48][i].out; - multi_or[10][i].in[7] <== eq[49][i].out; - multi_or[10][i].in[8] <== eq[50][i].out; - multi_or[10][i].in[9] <== eq[51][i].out; - multi_or[10][i].in[10] <== eq[52][i].out; - multi_or[10][i].in[11] <== eq[53][i].out; - and[32][i].b <== multi_or[10][i].out; + multi_or[10][i].in[1] <== and[32][i].out; + states[i+1][12] <== multi_or[10][i].out; + eq[53][i] = IsEqual(); + eq[53][i].in[0] <== in[i]; + eq[53][i].in[1] <== 244; and[33][i] = AND(); - and[33][i].a <== states[i][6]; - and[33][i].b <== and[10][i].out; + and[33][i].a <== states[i][5]; + and[33][i].b <== eq[53][i].out; and[34][i] = AND(); - and[34][i].a <== states[i][13]; - and[34][i].b <== multi_or[10][i].out; - multi_or[11][i] = MultiOR(3); - multi_or[11][i].in[0] <== and[32][i].out; - multi_or[11][i].in[1] <== and[33][i].out; - multi_or[11][i].in[2] <== and[34][i].out; + and[34][i].a <== states[i][6]; + and[34][i].b <== eq[53][i].out; + multi_or[11][i] = MultiOR(2); + multi_or[11][i].in[0] <== and[33][i].out; + multi_or[11][i].in[1] <== and[34][i].out; states[i+1][13] <== multi_or[11][i].out; and[35][i] = AND(); - and[35][i].a <== states[i][13]; + and[35][i].a <== states[i][6]; and[35][i].b <== eq[0][i].out; states[i+1][14] <== and[35][i].out; and[36][i] = AND(); @@ -467,13 +467,13 @@ template ToAllRegex(msg_bytes) { is_consecutive[msg_bytes-1-i][1] <== state_changed[msg_bytes-i].out * is_consecutive[msg_bytes-1-i][0]; is_consecutive[msg_bytes-1-i][2] <== ORAnd()([(1 - from_zero_enabled[msg_bytes-i+1]), states[num_bytes-i][15], is_consecutive[msg_bytes-1-i][1]]); } - // substrings calculated: [{(5, 6), (5, 7), (5, 8), (5, 9), (5, 10), (5, 11), (5, 12), (5, 13), (6, 13), (7, 6), (8, 6), (9, 6), (10, 8), (11, 8), (12, 8), (13, 6), (13, 7), (13, 8), (13, 9), (13, 10), (13, 11), (13, 12), (13, 13)}] + // substrings calculated: [{(5, 6), (5, 7), (5, 8), (5, 9), (5, 10), (5, 11), (5, 12), (5, 13), (6, 6), (6, 7), (6, 8), (6, 9), (6, 10), (6, 11), (6, 12), (6, 13), (7, 6), (8, 7), (9, 7), (10, 7), (11, 9), (12, 9), (13, 9)}] signal prev_states0[23][msg_bytes]; signal is_substr0[msg_bytes]; signal is_reveal0[msg_bytes]; signal output reveal0[msg_bytes]; for (var i = 0; i < msg_bytes; i++) { - // the 0-th substring transitions: [(5, 6), (5, 7), (5, 8), (5, 9), (5, 10), (5, 11), (5, 12), (5, 13), (6, 13), (7, 6), (8, 6), (9, 6), (10, 8), (11, 8), (12, 8), (13, 6), (13, 7), (13, 8), (13, 9), (13, 10), (13, 11), (13, 12), (13, 13)] + // the 0-th substring transitions: [(5, 6), (5, 7), (5, 8), (5, 9), (5, 10), (5, 11), (5, 12), (5, 13), (6, 6), (6, 7), (6, 8), (6, 9), (6, 10), (6, 11), (6, 12), (6, 13), (7, 6), (8, 7), (9, 7), (10, 7), (11, 9), (12, 9), (13, 9)] prev_states0[0][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][5]; prev_states0[1][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][5]; prev_states0[2][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][5]; @@ -483,21 +483,21 @@ template ToAllRegex(msg_bytes) { prev_states0[6][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][5]; prev_states0[7][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][5]; prev_states0[8][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][6]; - prev_states0[9][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][7]; - prev_states0[10][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][8]; - prev_states0[11][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][9]; - prev_states0[12][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][10]; - prev_states0[13][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][11]; - prev_states0[14][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][12]; - prev_states0[15][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][13]; - prev_states0[16][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][13]; - prev_states0[17][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][13]; - prev_states0[18][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][13]; - prev_states0[19][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][13]; - prev_states0[20][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][13]; - prev_states0[21][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][13]; + prev_states0[9][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][6]; + prev_states0[10][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][6]; + prev_states0[11][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][6]; + prev_states0[12][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][6]; + prev_states0[13][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][6]; + prev_states0[14][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][6]; + prev_states0[15][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][6]; + prev_states0[16][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][7]; + prev_states0[17][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][8]; + prev_states0[18][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][9]; + prev_states0[19][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][10]; + prev_states0[20][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][11]; + prev_states0[21][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][12]; prev_states0[22][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][13]; - is_substr0[i] <== MultiOR(23)([prev_states0[0][i] * states[i+2][6], prev_states0[1][i] * states[i+2][7], prev_states0[2][i] * states[i+2][8], prev_states0[3][i] * states[i+2][9], prev_states0[4][i] * states[i+2][10], prev_states0[5][i] * states[i+2][11], prev_states0[6][i] * states[i+2][12], prev_states0[7][i] * states[i+2][13], prev_states0[8][i] * states[i+2][13], prev_states0[9][i] * states[i+2][6], prev_states0[10][i] * states[i+2][6], prev_states0[11][i] * states[i+2][6], prev_states0[12][i] * states[i+2][8], prev_states0[13][i] * states[i+2][8], prev_states0[14][i] * states[i+2][8], prev_states0[15][i] * states[i+2][6], prev_states0[16][i] * states[i+2][7], prev_states0[17][i] * states[i+2][8], prev_states0[18][i] * states[i+2][9], prev_states0[19][i] * states[i+2][10], prev_states0[20][i] * states[i+2][11], prev_states0[21][i] * states[i+2][12], prev_states0[22][i] * states[i+2][13]]); + is_substr0[i] <== MultiOR(23)([prev_states0[0][i] * states[i+2][6], prev_states0[1][i] * states[i+2][7], prev_states0[2][i] * states[i+2][8], prev_states0[3][i] * states[i+2][9], prev_states0[4][i] * states[i+2][10], prev_states0[5][i] * states[i+2][11], prev_states0[6][i] * states[i+2][12], prev_states0[7][i] * states[i+2][13], prev_states0[8][i] * states[i+2][6], prev_states0[9][i] * states[i+2][7], prev_states0[10][i] * states[i+2][8], prev_states0[11][i] * states[i+2][9], prev_states0[12][i] * states[i+2][10], prev_states0[13][i] * states[i+2][11], prev_states0[14][i] * states[i+2][12], prev_states0[15][i] * states[i+2][13], prev_states0[16][i] * states[i+2][6], prev_states0[17][i] * states[i+2][7], prev_states0[18][i] * states[i+2][7], prev_states0[19][i] * states[i+2][7], prev_states0[20][i] * states[i+2][9], prev_states0[21][i] * states[i+2][9], prev_states0[22][i] * states[i+2][9]]); is_reveal0[i] <== MultiAND(3)([out, is_substr0[i], is_consecutive[i][2]]); reveal0[i] <== in[i+1] * is_reveal0[i]; } diff --git a/packages/circom/tests/circuits/caret5_regex.circom b/packages/circom/tests/circuits/caret5_regex.circom index 6bcbda4..2c189b3 100644 --- a/packages/circom/tests/circuits/caret5_regex.circom +++ b/packages/circom/tests/circuits/caret5_regex.circom @@ -52,29 +52,32 @@ template Caret5Regex(msg_bytes) { and[1][i].b <== eq[2][i].out; states[i+1][2] <== and[1][i].out; lt[0][i] = LessEqThan(8); - lt[0][i].in[0] <== 194; + lt[0][i].in[0] <== 1; lt[0][i].in[1] <== in[i]; lt[1][i] = LessEqThan(8); lt[1][i].in[0] <== in[i]; - lt[1][i].in[1] <== 223; + lt[1][i].in[1] <== 96; and[2][i] = AND(); and[2][i].a <== lt[0][i].out; and[2][i].b <== lt[1][i].out; - and[3][i] = AND(); - and[3][i].a <== states[i][2]; - and[3][i].b <== and[2][i].out; lt[2][i] = LessEqThan(8); - lt[2][i].in[0] <== 160; + lt[2][i].in[0] <== 100; lt[2][i].in[1] <== in[i]; lt[3][i] = LessEqThan(8); lt[3][i].in[0] <== in[i]; - lt[3][i].in[1] <== 191; + lt[3][i].in[1] <== 127; + and[3][i] = AND(); + and[3][i].a <== lt[2][i].out; + and[3][i].b <== lt[3][i].out; and[4][i] = AND(); - and[4][i].a <== lt[2][i].out; - and[4][i].b <== lt[3][i].out; + and[4][i].a <== states[i][2]; + multi_or[1][i] = MultiOR(2); + multi_or[1][i].in[0] <== and[2][i].out; + multi_or[1][i].in[1] <== and[3][i].out; + and[4][i].b <== multi_or[1][i].out; and[5][i] = AND(); - and[5][i].a <== states[i][4]; - and[5][i].b <== and[4][i].out; + and[5][i].a <== states[i][3]; + and[5][i].b <== multi_or[1][i].out; lt[4][i] = LessEqThan(8); lt[4][i].in[0] <== 128; lt[4][i].in[1] <== in[i]; @@ -85,43 +88,75 @@ template Caret5Regex(msg_bytes) { and[6][i].a <== lt[4][i].out; and[6][i].b <== lt[5][i].out; and[7][i] = AND(); - and[7][i].a <== states[i][5]; + and[7][i].a <== states[i][4]; and[7][i].b <== and[6][i].out; + multi_or[2][i] = MultiOR(3); + multi_or[2][i].in[0] <== and[4][i].out; + multi_or[2][i].in[1] <== and[5][i].out; + multi_or[2][i].in[2] <== and[7][i].out; + states[i+1][3] <== multi_or[2][i].out; lt[6][i] = LessEqThan(8); - lt[6][i].in[0] <== 128; + lt[6][i].in[0] <== 194; lt[6][i].in[1] <== in[i]; lt[7][i] = LessEqThan(8); lt[7][i].in[0] <== in[i]; - lt[7][i].in[1] <== 159; + lt[7][i].in[1] <== 223; and[8][i] = AND(); and[8][i].a <== lt[6][i].out; and[8][i].b <== lt[7][i].out; and[9][i] = AND(); - and[9][i].a <== states[i][6]; + and[9][i].a <== states[i][2]; and[9][i].b <== and[8][i].out; and[10][i] = AND(); - and[10][i].a <== states[i][10]; - and[10][i].b <== and[2][i].out; - multi_or[1][i] = MultiOR(5); - multi_or[1][i].in[0] <== and[3][i].out; - multi_or[1][i].in[1] <== and[5][i].out; - multi_or[1][i].in[2] <== and[7][i].out; - multi_or[1][i].in[3] <== and[9][i].out; - multi_or[1][i].in[4] <== and[10][i].out; - states[i+1][3] <== multi_or[1][i].out; + and[10][i].a <== states[i][3]; + and[10][i].b <== and[8][i].out; + lt[8][i] = LessEqThan(8); + lt[8][i].in[0] <== 160; + lt[8][i].in[1] <== in[i]; + lt[9][i] = LessEqThan(8); + lt[9][i].in[0] <== in[i]; + lt[9][i].in[1] <== 191; + and[11][i] = AND(); + and[11][i].a <== lt[8][i].out; + and[11][i].b <== lt[9][i].out; + and[12][i] = AND(); + and[12][i].a <== states[i][5]; + and[12][i].b <== and[11][i].out; + and[13][i] = AND(); + and[13][i].a <== states[i][6]; + and[13][i].b <== and[6][i].out; + lt[10][i] = LessEqThan(8); + lt[10][i].in[0] <== 128; + lt[10][i].in[1] <== in[i]; + lt[11][i] = LessEqThan(8); + lt[11][i].in[0] <== in[i]; + lt[11][i].in[1] <== 159; + and[14][i] = AND(); + and[14][i].a <== lt[10][i].out; + and[14][i].b <== lt[11][i].out; + and[15][i] = AND(); + and[15][i].a <== states[i][7]; + and[15][i].b <== and[14][i].out; + multi_or[3][i] = MultiOR(5); + multi_or[3][i].in[0] <== and[9][i].out; + multi_or[3][i].in[1] <== and[10][i].out; + multi_or[3][i].in[2] <== and[12][i].out; + multi_or[3][i].in[3] <== and[13][i].out; + multi_or[3][i].in[4] <== and[15][i].out; + states[i+1][4] <== multi_or[3][i].out; eq[3][i] = IsEqual(); eq[3][i].in[0] <== in[i]; eq[3][i].in[1] <== 224; - and[11][i] = AND(); - and[11][i].a <== states[i][2]; - and[11][i].b <== eq[3][i].out; - and[12][i] = AND(); - and[12][i].a <== states[i][10]; - and[12][i].b <== eq[3][i].out; - multi_or[2][i] = MultiOR(2); - multi_or[2][i].in[0] <== and[11][i].out; - multi_or[2][i].in[1] <== and[12][i].out; - states[i+1][4] <== multi_or[2][i].out; + and[16][i] = AND(); + and[16][i].a <== states[i][2]; + and[16][i].b <== eq[3][i].out; + and[17][i] = AND(); + and[17][i].a <== states[i][3]; + and[17][i].b <== eq[3][i].out; + multi_or[4][i] = MultiOR(2); + multi_or[4][i].in[0] <== and[16][i].out; + multi_or[4][i].in[1] <== and[17][i].out; + states[i+1][5] <== multi_or[4][i].out; eq[4][i] = IsEqual(); eq[4][i].in[0] <== in[i]; eq[4][i].in[1] <== 225; @@ -164,39 +199,42 @@ template Caret5Regex(msg_bytes) { eq[17][i] = IsEqual(); eq[17][i].in[0] <== in[i]; eq[17][i].in[1] <== 239; - and[13][i] = AND(); - and[13][i].a <== states[i][2]; - multi_or[3][i] = MultiOR(14); - multi_or[3][i].in[0] <== eq[4][i].out; - multi_or[3][i].in[1] <== eq[5][i].out; - multi_or[3][i].in[2] <== eq[6][i].out; - multi_or[3][i].in[3] <== eq[7][i].out; - multi_or[3][i].in[4] <== eq[8][i].out; - multi_or[3][i].in[5] <== eq[9][i].out; - multi_or[3][i].in[6] <== eq[10][i].out; - multi_or[3][i].in[7] <== eq[11][i].out; - multi_or[3][i].in[8] <== eq[12][i].out; - multi_or[3][i].in[9] <== eq[13][i].out; - multi_or[3][i].in[10] <== eq[14][i].out; - multi_or[3][i].in[11] <== eq[15][i].out; - multi_or[3][i].in[12] <== eq[16][i].out; - multi_or[3][i].in[13] <== eq[17][i].out; - and[13][i].b <== multi_or[3][i].out; - lt[8][i] = LessEqThan(8); - lt[8][i].in[0] <== 144; - lt[8][i].in[1] <== in[i]; - lt[9][i] = LessEqThan(8); - lt[9][i].in[0] <== in[i]; - lt[9][i].in[1] <== 191; - and[14][i] = AND(); - and[14][i].a <== lt[8][i].out; - and[14][i].b <== lt[9][i].out; - and[15][i] = AND(); - and[15][i].a <== states[i][7]; - and[15][i].b <== and[14][i].out; - and[16][i] = AND(); - and[16][i].a <== states[i][8]; - and[16][i].b <== and[6][i].out; + and[18][i] = AND(); + and[18][i].a <== states[i][2]; + multi_or[5][i] = MultiOR(14); + multi_or[5][i].in[0] <== eq[4][i].out; + multi_or[5][i].in[1] <== eq[5][i].out; + multi_or[5][i].in[2] <== eq[6][i].out; + multi_or[5][i].in[3] <== eq[7][i].out; + multi_or[5][i].in[4] <== eq[8][i].out; + multi_or[5][i].in[5] <== eq[9][i].out; + multi_or[5][i].in[6] <== eq[10][i].out; + multi_or[5][i].in[7] <== eq[11][i].out; + multi_or[5][i].in[8] <== eq[12][i].out; + multi_or[5][i].in[9] <== eq[13][i].out; + multi_or[5][i].in[10] <== eq[14][i].out; + multi_or[5][i].in[11] <== eq[15][i].out; + multi_or[5][i].in[12] <== eq[16][i].out; + multi_or[5][i].in[13] <== eq[17][i].out; + and[18][i].b <== multi_or[5][i].out; + and[19][i] = AND(); + and[19][i].a <== states[i][3]; + and[19][i].b <== multi_or[5][i].out; + lt[12][i] = LessEqThan(8); + lt[12][i].in[0] <== 144; + lt[12][i].in[1] <== in[i]; + lt[13][i] = LessEqThan(8); + lt[13][i].in[0] <== in[i]; + lt[13][i].in[1] <== 191; + and[20][i] = AND(); + and[20][i].a <== lt[12][i].out; + and[20][i].b <== lt[13][i].out; + and[21][i] = AND(); + and[21][i].a <== states[i][8]; + and[21][i].b <== and[20][i].out; + and[22][i] = AND(); + and[22][i].a <== states[i][9]; + and[22][i].b <== and[6][i].out; eq[18][i] = IsEqual(); eq[18][i].in[0] <== in[i]; eq[18][i].in[1] <== 128; @@ -245,62 +283,59 @@ template Caret5Regex(msg_bytes) { eq[33][i] = IsEqual(); eq[33][i].in[0] <== in[i]; eq[33][i].in[1] <== 143; - and[17][i] = AND(); - and[17][i].a <== states[i][9]; - multi_or[4][i] = MultiOR(16); - multi_or[4][i].in[0] <== eq[18][i].out; - multi_or[4][i].in[1] <== eq[19][i].out; - multi_or[4][i].in[2] <== eq[20][i].out; - multi_or[4][i].in[3] <== eq[21][i].out; - multi_or[4][i].in[4] <== eq[22][i].out; - multi_or[4][i].in[5] <== eq[23][i].out; - multi_or[4][i].in[6] <== eq[24][i].out; - multi_or[4][i].in[7] <== eq[25][i].out; - multi_or[4][i].in[8] <== eq[26][i].out; - multi_or[4][i].in[9] <== eq[27][i].out; - multi_or[4][i].in[10] <== eq[28][i].out; - multi_or[4][i].in[11] <== eq[29][i].out; - multi_or[4][i].in[12] <== eq[30][i].out; - multi_or[4][i].in[13] <== eq[31][i].out; - multi_or[4][i].in[14] <== eq[32][i].out; - multi_or[4][i].in[15] <== eq[33][i].out; - and[17][i].b <== multi_or[4][i].out; - and[18][i] = AND(); - and[18][i].a <== states[i][10]; - and[18][i].b <== multi_or[3][i].out; - multi_or[5][i] = MultiOR(5); - multi_or[5][i].in[0] <== and[13][i].out; - multi_or[5][i].in[1] <== and[15][i].out; - multi_or[5][i].in[2] <== and[16][i].out; - multi_or[5][i].in[3] <== and[17][i].out; - multi_or[5][i].in[4] <== and[18][i].out; - states[i+1][5] <== multi_or[5][i].out; + and[23][i] = AND(); + and[23][i].a <== states[i][10]; + multi_or[6][i] = MultiOR(16); + multi_or[6][i].in[0] <== eq[18][i].out; + multi_or[6][i].in[1] <== eq[19][i].out; + multi_or[6][i].in[2] <== eq[20][i].out; + multi_or[6][i].in[3] <== eq[21][i].out; + multi_or[6][i].in[4] <== eq[22][i].out; + multi_or[6][i].in[5] <== eq[23][i].out; + multi_or[6][i].in[6] <== eq[24][i].out; + multi_or[6][i].in[7] <== eq[25][i].out; + multi_or[6][i].in[8] <== eq[26][i].out; + multi_or[6][i].in[9] <== eq[27][i].out; + multi_or[6][i].in[10] <== eq[28][i].out; + multi_or[6][i].in[11] <== eq[29][i].out; + multi_or[6][i].in[12] <== eq[30][i].out; + multi_or[6][i].in[13] <== eq[31][i].out; + multi_or[6][i].in[14] <== eq[32][i].out; + multi_or[6][i].in[15] <== eq[33][i].out; + and[23][i].b <== multi_or[6][i].out; + multi_or[7][i] = MultiOR(5); + multi_or[7][i].in[0] <== and[18][i].out; + multi_or[7][i].in[1] <== and[19][i].out; + multi_or[7][i].in[2] <== and[21][i].out; + multi_or[7][i].in[3] <== and[22][i].out; + multi_or[7][i].in[4] <== and[23][i].out; + states[i+1][6] <== multi_or[7][i].out; eq[34][i] = IsEqual(); eq[34][i].in[0] <== in[i]; eq[34][i].in[1] <== 237; - and[19][i] = AND(); - and[19][i].a <== states[i][2]; - and[19][i].b <== eq[34][i].out; - and[20][i] = AND(); - and[20][i].a <== states[i][10]; - and[20][i].b <== eq[34][i].out; - multi_or[6][i] = MultiOR(2); - multi_or[6][i].in[0] <== and[19][i].out; - multi_or[6][i].in[1] <== and[20][i].out; - states[i+1][6] <== multi_or[6][i].out; + and[24][i] = AND(); + and[24][i].a <== states[i][2]; + and[24][i].b <== eq[34][i].out; + and[25][i] = AND(); + and[25][i].a <== states[i][3]; + and[25][i].b <== eq[34][i].out; + multi_or[8][i] = MultiOR(2); + multi_or[8][i].in[0] <== and[24][i].out; + multi_or[8][i].in[1] <== and[25][i].out; + states[i+1][7] <== multi_or[8][i].out; eq[35][i] = IsEqual(); eq[35][i].in[0] <== in[i]; eq[35][i].in[1] <== 240; - and[21][i] = AND(); - and[21][i].a <== states[i][2]; - and[21][i].b <== eq[35][i].out; - and[22][i] = AND(); - and[22][i].a <== states[i][10]; - and[22][i].b <== eq[35][i].out; - multi_or[7][i] = MultiOR(2); - multi_or[7][i].in[0] <== and[21][i].out; - multi_or[7][i].in[1] <== and[22][i].out; - states[i+1][7] <== multi_or[7][i].out; + and[26][i] = AND(); + and[26][i].a <== states[i][2]; + and[26][i].b <== eq[35][i].out; + and[27][i] = AND(); + and[27][i].a <== states[i][3]; + and[27][i].b <== eq[35][i].out; + multi_or[9][i] = MultiOR(2); + multi_or[9][i].in[0] <== and[26][i].out; + multi_or[9][i].in[1] <== and[27][i].out; + states[i+1][8] <== multi_or[9][i].out; eq[36][i] = IsEqual(); eq[36][i].in[0] <== in[i]; eq[36][i].in[1] <== 241; @@ -310,67 +345,32 @@ template Caret5Regex(msg_bytes) { eq[38][i] = IsEqual(); eq[38][i].in[0] <== in[i]; eq[38][i].in[1] <== 243; - and[23][i] = AND(); - and[23][i].a <== states[i][2]; - multi_or[8][i] = MultiOR(3); - multi_or[8][i].in[0] <== eq[36][i].out; - multi_or[8][i].in[1] <== eq[37][i].out; - multi_or[8][i].in[2] <== eq[38][i].out; - and[23][i].b <== multi_or[8][i].out; - and[24][i] = AND(); - and[24][i].a <== states[i][10]; - and[24][i].b <== multi_or[8][i].out; - multi_or[9][i] = MultiOR(2); - multi_or[9][i].in[0] <== and[23][i].out; - multi_or[9][i].in[1] <== and[24][i].out; - states[i+1][8] <== multi_or[9][i].out; - eq[39][i] = IsEqual(); - eq[39][i].in[0] <== in[i]; - eq[39][i].in[1] <== 244; - and[25][i] = AND(); - and[25][i].a <== states[i][2]; - and[25][i].b <== eq[39][i].out; - and[26][i] = AND(); - and[26][i].a <== states[i][10]; - and[26][i].b <== eq[39][i].out; - multi_or[10][i] = MultiOR(2); - multi_or[10][i].in[0] <== and[25][i].out; - multi_or[10][i].in[1] <== and[26][i].out; - states[i+1][9] <== multi_or[10][i].out; - lt[10][i] = LessEqThan(8); - lt[10][i].in[0] <== 1; - lt[10][i].in[1] <== in[i]; - lt[11][i] = LessEqThan(8); - lt[11][i].in[0] <== in[i]; - lt[11][i].in[1] <== 96; - and[27][i] = AND(); - and[27][i].a <== lt[10][i].out; - and[27][i].b <== lt[11][i].out; - lt[12][i] = LessEqThan(8); - lt[12][i].in[0] <== 100; - lt[12][i].in[1] <== in[i]; - lt[13][i] = LessEqThan(8); - lt[13][i].in[0] <== in[i]; - lt[13][i].in[1] <== 127; and[28][i] = AND(); - and[28][i].a <== lt[12][i].out; - and[28][i].b <== lt[13][i].out; + and[28][i].a <== states[i][2]; + multi_or[10][i] = MultiOR(3); + multi_or[10][i].in[0] <== eq[36][i].out; + multi_or[10][i].in[1] <== eq[37][i].out; + multi_or[10][i].in[2] <== eq[38][i].out; + and[28][i].b <== multi_or[10][i].out; and[29][i] = AND(); - and[29][i].a <== states[i][2]; + and[29][i].a <== states[i][3]; + and[29][i].b <== multi_or[10][i].out; multi_or[11][i] = MultiOR(2); - multi_or[11][i].in[0] <== and[27][i].out; - multi_or[11][i].in[1] <== and[28][i].out; - and[29][i].b <== multi_or[11][i].out; + multi_or[11][i].in[0] <== and[28][i].out; + multi_or[11][i].in[1] <== and[29][i].out; + states[i+1][9] <== multi_or[11][i].out; + eq[39][i] = IsEqual(); + eq[39][i].in[0] <== in[i]; + eq[39][i].in[1] <== 244; and[30][i] = AND(); - and[30][i].a <== states[i][3]; - and[30][i].b <== and[6][i].out; + and[30][i].a <== states[i][2]; + and[30][i].b <== eq[39][i].out; and[31][i] = AND(); - and[31][i].a <== states[i][10]; - and[31][i].b <== multi_or[11][i].out; - multi_or[12][i] = MultiOR(3); - multi_or[12][i].in[0] <== and[29][i].out; - multi_or[12][i].in[1] <== and[30][i].out; - multi_or[12][i].in[2] <== and[31][i].out; + and[31][i].a <== states[i][3]; + and[31][i].b <== eq[39][i].out; + multi_or[12][i] = MultiOR(2); + multi_or[12][i].in[0] <== and[30][i].out; + multi_or[12][i].in[1] <== and[31][i].out; states[i+1][10] <== multi_or[12][i].out; from_zero_enabled[i] <== MultiNOR(10)([states_tmp[i+1][1], states[i+1][2], states[i+1][3], states[i+1][4], states[i+1][5], states[i+1][6], states[i+1][7], states[i+1][8], states[i+1][9], states[i+1][10]]); states[i+1][1] <== MultiOR(2)([states_tmp[i+1][1], from_zero_enabled[i] * and[0][i].out]); @@ -388,23 +388,23 @@ template Caret5Regex(msg_bytes) { component is_accepted = MultiOR(num_bytes+1); for (var i = 0; i <= num_bytes; i++) { - is_accepted.in[i] <== states[i][10]; + is_accepted.in[i] <== states[i][3]; } out <== is_accepted.out; signal is_consecutive[msg_bytes+1][3]; is_consecutive[msg_bytes][2] <== 0; for (var i = 0; i < msg_bytes; i++) { - is_consecutive[msg_bytes-1-i][0] <== states[num_bytes-i][10] * (1 - is_consecutive[msg_bytes-i][2]) + is_consecutive[msg_bytes-i][2]; + is_consecutive[msg_bytes-1-i][0] <== states[num_bytes-i][3] * (1 - is_consecutive[msg_bytes-i][2]) + is_consecutive[msg_bytes-i][2]; is_consecutive[msg_bytes-1-i][1] <== state_changed[msg_bytes-i].out * is_consecutive[msg_bytes-1-i][0]; - is_consecutive[msg_bytes-1-i][2] <== ORAnd()([(1 - from_zero_enabled[msg_bytes-i+1]), states[num_bytes-i][10], is_consecutive[msg_bytes-1-i][1]]); + is_consecutive[msg_bytes-1-i][2] <== ORAnd()([(1 - from_zero_enabled[msg_bytes-i+1]), states[num_bytes-i][3], is_consecutive[msg_bytes-1-i][1]]); } - // substrings calculated: [{(2, 3), (2, 4), (2, 5), (2, 6), (2, 7), (2, 8), (2, 9), (2, 10), (3, 10), (4, 3), (5, 3), (6, 3), (7, 5), (8, 5), (9, 5), (10, 3), (10, 4), (10, 5), (10, 6), (10, 7), (10, 8), (10, 9), (10, 10)}] + // substrings calculated: [{(2, 3), (2, 4), (2, 5), (2, 6), (2, 7), (2, 8), (2, 9), (2, 10), (3, 3), (3, 4), (3, 5), (3, 6), (3, 7), (3, 8), (3, 9), (3, 10), (4, 3), (5, 4), (6, 4), (7, 4), (8, 6), (9, 6), (10, 6)}] signal prev_states0[23][msg_bytes]; signal is_substr0[msg_bytes]; signal is_reveal0[msg_bytes]; signal output reveal0[msg_bytes]; for (var i = 0; i < msg_bytes; i++) { - // the 0-th substring transitions: [(2, 3), (2, 4), (2, 5), (2, 6), (2, 7), (2, 8), (2, 9), (2, 10), (3, 10), (4, 3), (5, 3), (6, 3), (7, 5), (8, 5), (9, 5), (10, 3), (10, 4), (10, 5), (10, 6), (10, 7), (10, 8), (10, 9), (10, 10)] + // the 0-th substring transitions: [(2, 3), (2, 4), (2, 5), (2, 6), (2, 7), (2, 8), (2, 9), (2, 10), (3, 3), (3, 4), (3, 5), (3, 6), (3, 7), (3, 8), (3, 9), (3, 10), (4, 3), (5, 4), (6, 4), (7, 4), (8, 6), (9, 6), (10, 6)] prev_states0[0][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][2]; prev_states0[1][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][2]; prev_states0[2][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][2]; @@ -414,21 +414,21 @@ template Caret5Regex(msg_bytes) { prev_states0[6][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][2]; prev_states0[7][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][2]; prev_states0[8][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][3]; - prev_states0[9][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][4]; - prev_states0[10][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][5]; - prev_states0[11][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][6]; - prev_states0[12][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][7]; - prev_states0[13][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][8]; - prev_states0[14][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][9]; - prev_states0[15][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][10]; - prev_states0[16][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][10]; - prev_states0[17][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][10]; - prev_states0[18][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][10]; - prev_states0[19][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][10]; - prev_states0[20][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][10]; - prev_states0[21][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][10]; + prev_states0[9][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][3]; + prev_states0[10][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][3]; + prev_states0[11][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][3]; + prev_states0[12][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][3]; + prev_states0[13][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][3]; + prev_states0[14][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][3]; + prev_states0[15][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][3]; + prev_states0[16][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][4]; + prev_states0[17][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][5]; + prev_states0[18][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][6]; + prev_states0[19][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][7]; + prev_states0[20][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][8]; + prev_states0[21][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][9]; prev_states0[22][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][10]; - is_substr0[i] <== MultiOR(23)([prev_states0[0][i] * states[i+2][3], prev_states0[1][i] * states[i+2][4], prev_states0[2][i] * states[i+2][5], prev_states0[3][i] * states[i+2][6], prev_states0[4][i] * states[i+2][7], prev_states0[5][i] * states[i+2][8], prev_states0[6][i] * states[i+2][9], prev_states0[7][i] * states[i+2][10], prev_states0[8][i] * states[i+2][10], prev_states0[9][i] * states[i+2][3], prev_states0[10][i] * states[i+2][3], prev_states0[11][i] * states[i+2][3], prev_states0[12][i] * states[i+2][5], prev_states0[13][i] * states[i+2][5], prev_states0[14][i] * states[i+2][5], prev_states0[15][i] * states[i+2][3], prev_states0[16][i] * states[i+2][4], prev_states0[17][i] * states[i+2][5], prev_states0[18][i] * states[i+2][6], prev_states0[19][i] * states[i+2][7], prev_states0[20][i] * states[i+2][8], prev_states0[21][i] * states[i+2][9], prev_states0[22][i] * states[i+2][10]]); + is_substr0[i] <== MultiOR(23)([prev_states0[0][i] * states[i+2][3], prev_states0[1][i] * states[i+2][4], prev_states0[2][i] * states[i+2][5], prev_states0[3][i] * states[i+2][6], prev_states0[4][i] * states[i+2][7], prev_states0[5][i] * states[i+2][8], prev_states0[6][i] * states[i+2][9], prev_states0[7][i] * states[i+2][10], prev_states0[8][i] * states[i+2][3], prev_states0[9][i] * states[i+2][4], prev_states0[10][i] * states[i+2][5], prev_states0[11][i] * states[i+2][6], prev_states0[12][i] * states[i+2][7], prev_states0[13][i] * states[i+2][8], prev_states0[14][i] * states[i+2][9], prev_states0[15][i] * states[i+2][10], prev_states0[16][i] * states[i+2][3], prev_states0[17][i] * states[i+2][4], prev_states0[18][i] * states[i+2][4], prev_states0[19][i] * states[i+2][4], prev_states0[20][i] * states[i+2][6], prev_states0[21][i] * states[i+2][6], prev_states0[22][i] * states[i+2][6]]); is_reveal0[i] <== MultiAND(3)([out, is_substr0[i], is_consecutive[i][2]]); reveal0[i] <== in[i+1] * is_reveal0[i]; } diff --git a/packages/circom/tests/circuits/dot1_regex.circom b/packages/circom/tests/circuits/dot1_regex.circom index 774b9a0..80f137f 100644 --- a/packages/circom/tests/circuits/dot1_regex.circom +++ b/packages/circom/tests/circuits/dot1_regex.circom @@ -32,19 +32,57 @@ template Dot1Regex(msg_bytes) { state_changed[i] = MultiOR(8); states[i][0] <== 1; lt[0][i] = LessEqThan(8); - lt[0][i].in[0] <== 194; + lt[0][i].in[0] <== 11; lt[0][i].in[1] <== in[i]; lt[1][i] = LessEqThan(8); lt[1][i].in[0] <== in[i]; - lt[1][i].in[1] <== 223; + lt[1][i].in[1] <== 127; and[0][i] = AND(); and[0][i].a <== lt[0][i].out; and[0][i].b <== lt[1][i].out; + eq[0][i] = IsEqual(); + eq[0][i].in[0] <== in[i]; + eq[0][i].in[1] <== 1; + eq[1][i] = IsEqual(); + eq[1][i].in[0] <== in[i]; + eq[1][i].in[1] <== 2; + eq[2][i] = IsEqual(); + eq[2][i].in[0] <== in[i]; + eq[2][i].in[1] <== 3; + eq[3][i] = IsEqual(); + eq[3][i].in[0] <== in[i]; + eq[3][i].in[1] <== 4; + eq[4][i] = IsEqual(); + eq[4][i].in[0] <== in[i]; + eq[4][i].in[1] <== 5; + eq[5][i] = IsEqual(); + eq[5][i].in[0] <== in[i]; + eq[5][i].in[1] <== 6; + eq[6][i] = IsEqual(); + eq[6][i].in[0] <== in[i]; + eq[6][i].in[1] <== 7; + eq[7][i] = IsEqual(); + eq[7][i].in[0] <== in[i]; + eq[7][i].in[1] <== 8; + eq[8][i] = IsEqual(); + eq[8][i].in[0] <== in[i]; + eq[8][i].in[1] <== 9; and[1][i] = AND(); and[1][i].a <== states[i][0]; - and[1][i].b <== and[0][i].out; + multi_or[0][i] = MultiOR(10); + multi_or[0][i].in[0] <== and[0][i].out; + multi_or[0][i].in[1] <== eq[0][i].out; + multi_or[0][i].in[2] <== eq[1][i].out; + multi_or[0][i].in[3] <== eq[2][i].out; + multi_or[0][i].in[4] <== eq[3][i].out; + multi_or[0][i].in[5] <== eq[4][i].out; + multi_or[0][i].in[6] <== eq[5][i].out; + multi_or[0][i].in[7] <== eq[6][i].out; + multi_or[0][i].in[8] <== eq[7][i].out; + multi_or[0][i].in[9] <== eq[8][i].out; + and[1][i].b <== multi_or[0][i].out; lt[2][i] = LessEqThan(8); - lt[2][i].in[0] <== 160; + lt[2][i].in[0] <== 128; lt[2][i].in[1] <== in[i]; lt[3][i] = LessEqThan(8); lt[3][i].in[0] <== in[i]; @@ -55,291 +93,253 @@ template Dot1Regex(msg_bytes) { and[3][i] = AND(); and[3][i].a <== states[i][2]; and[3][i].b <== and[2][i].out; + states_tmp[i+1][1] <== and[3][i].out; lt[4][i] = LessEqThan(8); - lt[4][i].in[0] <== 128; + lt[4][i].in[0] <== 194; lt[4][i].in[1] <== in[i]; lt[5][i] = LessEqThan(8); lt[5][i].in[0] <== in[i]; - lt[5][i].in[1] <== 191; + lt[5][i].in[1] <== 223; and[4][i] = AND(); and[4][i].a <== lt[4][i].out; and[4][i].b <== lt[5][i].out; and[5][i] = AND(); - and[5][i].a <== states[i][3]; + and[5][i].a <== states[i][0]; and[5][i].b <== and[4][i].out; lt[6][i] = LessEqThan(8); - lt[6][i].in[0] <== 128; + lt[6][i].in[0] <== 160; lt[6][i].in[1] <== in[i]; lt[7][i] = LessEqThan(8); lt[7][i].in[0] <== in[i]; - lt[7][i].in[1] <== 159; + lt[7][i].in[1] <== 191; and[6][i] = AND(); and[6][i].a <== lt[6][i].out; and[6][i].b <== lt[7][i].out; and[7][i] = AND(); - and[7][i].a <== states[i][4]; + and[7][i].a <== states[i][3]; and[7][i].b <== and[6][i].out; - multi_or[0][i] = MultiOR(3); - multi_or[0][i].in[0] <== and[3][i].out; - multi_or[0][i].in[1] <== and[5][i].out; - multi_or[0][i].in[2] <== and[7][i].out; - states_tmp[i+1][1] <== multi_or[0][i].out; - eq[0][i] = IsEqual(); - eq[0][i].in[0] <== in[i]; - eq[0][i].in[1] <== 224; and[8][i] = AND(); - and[8][i].a <== states[i][0]; - and[8][i].b <== eq[0][i].out; - states_tmp[i+1][2] <== 0; - eq[1][i] = IsEqual(); - eq[1][i].in[0] <== in[i]; - eq[1][i].in[1] <== 225; - eq[2][i] = IsEqual(); - eq[2][i].in[0] <== in[i]; - eq[2][i].in[1] <== 226; - eq[3][i] = IsEqual(); - eq[3][i].in[0] <== in[i]; - eq[3][i].in[1] <== 227; - eq[4][i] = IsEqual(); - eq[4][i].in[0] <== in[i]; - eq[4][i].in[1] <== 228; - eq[5][i] = IsEqual(); - eq[5][i].in[0] <== in[i]; - eq[5][i].in[1] <== 229; - eq[6][i] = IsEqual(); - eq[6][i].in[0] <== in[i]; - eq[6][i].in[1] <== 230; - eq[7][i] = IsEqual(); - eq[7][i].in[0] <== in[i]; - eq[7][i].in[1] <== 231; - eq[8][i] = IsEqual(); - eq[8][i].in[0] <== in[i]; - eq[8][i].in[1] <== 232; + and[8][i].a <== states[i][4]; + and[8][i].b <== and[2][i].out; + lt[8][i] = LessEqThan(8); + lt[8][i].in[0] <== 128; + lt[8][i].in[1] <== in[i]; + lt[9][i] = LessEqThan(8); + lt[9][i].in[0] <== in[i]; + lt[9][i].in[1] <== 159; + and[9][i] = AND(); + and[9][i].a <== lt[8][i].out; + and[9][i].b <== lt[9][i].out; + and[10][i] = AND(); + and[10][i].a <== states[i][5]; + and[10][i].b <== and[9][i].out; + multi_or[1][i] = MultiOR(3); + multi_or[1][i].in[0] <== and[7][i].out; + multi_or[1][i].in[1] <== and[8][i].out; + multi_or[1][i].in[2] <== and[10][i].out; + states_tmp[i+1][2] <== multi_or[1][i].out; eq[9][i] = IsEqual(); eq[9][i].in[0] <== in[i]; - eq[9][i].in[1] <== 233; + eq[9][i].in[1] <== 224; + and[11][i] = AND(); + and[11][i].a <== states[i][0]; + and[11][i].b <== eq[9][i].out; + states_tmp[i+1][3] <== 0; eq[10][i] = IsEqual(); eq[10][i].in[0] <== in[i]; - eq[10][i].in[1] <== 234; + eq[10][i].in[1] <== 225; eq[11][i] = IsEqual(); eq[11][i].in[0] <== in[i]; - eq[11][i].in[1] <== 235; + eq[11][i].in[1] <== 226; eq[12][i] = IsEqual(); eq[12][i].in[0] <== in[i]; - eq[12][i].in[1] <== 236; + eq[12][i].in[1] <== 227; eq[13][i] = IsEqual(); eq[13][i].in[0] <== in[i]; - eq[13][i].in[1] <== 238; + eq[13][i].in[1] <== 228; eq[14][i] = IsEqual(); eq[14][i].in[0] <== in[i]; - eq[14][i].in[1] <== 239; - and[9][i] = AND(); - and[9][i].a <== states[i][0]; - multi_or[1][i] = MultiOR(14); - multi_or[1][i].in[0] <== eq[1][i].out; - multi_or[1][i].in[1] <== eq[2][i].out; - multi_or[1][i].in[2] <== eq[3][i].out; - multi_or[1][i].in[3] <== eq[4][i].out; - multi_or[1][i].in[4] <== eq[5][i].out; - multi_or[1][i].in[5] <== eq[6][i].out; - multi_or[1][i].in[6] <== eq[7][i].out; - multi_or[1][i].in[7] <== eq[8][i].out; - multi_or[1][i].in[8] <== eq[9][i].out; - multi_or[1][i].in[9] <== eq[10][i].out; - multi_or[1][i].in[10] <== eq[11][i].out; - multi_or[1][i].in[11] <== eq[12][i].out; - multi_or[1][i].in[12] <== eq[13][i].out; - multi_or[1][i].in[13] <== eq[14][i].out; - and[9][i].b <== multi_or[1][i].out; - lt[8][i] = LessEqThan(8); - lt[8][i].in[0] <== 144; - lt[8][i].in[1] <== in[i]; - lt[9][i] = LessEqThan(8); - lt[9][i].in[0] <== in[i]; - lt[9][i].in[1] <== 191; - and[10][i] = AND(); - and[10][i].a <== lt[8][i].out; - and[10][i].b <== lt[9][i].out; - and[11][i] = AND(); - and[11][i].a <== states[i][5]; - and[11][i].b <== and[10][i].out; - and[12][i] = AND(); - and[12][i].a <== states[i][6]; - and[12][i].b <== and[4][i].out; + eq[14][i].in[1] <== 229; eq[15][i] = IsEqual(); eq[15][i].in[0] <== in[i]; - eq[15][i].in[1] <== 128; + eq[15][i].in[1] <== 230; eq[16][i] = IsEqual(); eq[16][i].in[0] <== in[i]; - eq[16][i].in[1] <== 129; + eq[16][i].in[1] <== 231; eq[17][i] = IsEqual(); eq[17][i].in[0] <== in[i]; - eq[17][i].in[1] <== 130; + eq[17][i].in[1] <== 232; eq[18][i] = IsEqual(); eq[18][i].in[0] <== in[i]; - eq[18][i].in[1] <== 131; + eq[18][i].in[1] <== 233; eq[19][i] = IsEqual(); eq[19][i].in[0] <== in[i]; - eq[19][i].in[1] <== 132; + eq[19][i].in[1] <== 234; eq[20][i] = IsEqual(); eq[20][i].in[0] <== in[i]; - eq[20][i].in[1] <== 133; + eq[20][i].in[1] <== 235; eq[21][i] = IsEqual(); eq[21][i].in[0] <== in[i]; - eq[21][i].in[1] <== 134; + eq[21][i].in[1] <== 236; eq[22][i] = IsEqual(); eq[22][i].in[0] <== in[i]; - eq[22][i].in[1] <== 135; + eq[22][i].in[1] <== 238; eq[23][i] = IsEqual(); eq[23][i].in[0] <== in[i]; - eq[23][i].in[1] <== 136; + eq[23][i].in[1] <== 239; + and[12][i] = AND(); + and[12][i].a <== states[i][0]; + multi_or[2][i] = MultiOR(14); + multi_or[2][i].in[0] <== eq[10][i].out; + multi_or[2][i].in[1] <== eq[11][i].out; + multi_or[2][i].in[2] <== eq[12][i].out; + multi_or[2][i].in[3] <== eq[13][i].out; + multi_or[2][i].in[4] <== eq[14][i].out; + multi_or[2][i].in[5] <== eq[15][i].out; + multi_or[2][i].in[6] <== eq[16][i].out; + multi_or[2][i].in[7] <== eq[17][i].out; + multi_or[2][i].in[8] <== eq[18][i].out; + multi_or[2][i].in[9] <== eq[19][i].out; + multi_or[2][i].in[10] <== eq[20][i].out; + multi_or[2][i].in[11] <== eq[21][i].out; + multi_or[2][i].in[12] <== eq[22][i].out; + multi_or[2][i].in[13] <== eq[23][i].out; + and[12][i].b <== multi_or[2][i].out; + lt[10][i] = LessEqThan(8); + lt[10][i].in[0] <== 144; + lt[10][i].in[1] <== in[i]; + lt[11][i] = LessEqThan(8); + lt[11][i].in[0] <== in[i]; + lt[11][i].in[1] <== 191; + and[13][i] = AND(); + and[13][i].a <== lt[10][i].out; + and[13][i].b <== lt[11][i].out; + and[14][i] = AND(); + and[14][i].a <== states[i][6]; + and[14][i].b <== and[13][i].out; + and[15][i] = AND(); + and[15][i].a <== states[i][7]; + and[15][i].b <== and[2][i].out; eq[24][i] = IsEqual(); eq[24][i].in[0] <== in[i]; - eq[24][i].in[1] <== 137; + eq[24][i].in[1] <== 128; eq[25][i] = IsEqual(); eq[25][i].in[0] <== in[i]; - eq[25][i].in[1] <== 138; + eq[25][i].in[1] <== 129; eq[26][i] = IsEqual(); eq[26][i].in[0] <== in[i]; - eq[26][i].in[1] <== 139; + eq[26][i].in[1] <== 130; eq[27][i] = IsEqual(); eq[27][i].in[0] <== in[i]; - eq[27][i].in[1] <== 140; + eq[27][i].in[1] <== 131; eq[28][i] = IsEqual(); eq[28][i].in[0] <== in[i]; - eq[28][i].in[1] <== 141; + eq[28][i].in[1] <== 132; eq[29][i] = IsEqual(); eq[29][i].in[0] <== in[i]; - eq[29][i].in[1] <== 142; + eq[29][i].in[1] <== 133; eq[30][i] = IsEqual(); eq[30][i].in[0] <== in[i]; - eq[30][i].in[1] <== 143; - and[13][i] = AND(); - and[13][i].a <== states[i][7]; - multi_or[2][i] = MultiOR(16); - multi_or[2][i].in[0] <== eq[15][i].out; - multi_or[2][i].in[1] <== eq[16][i].out; - multi_or[2][i].in[2] <== eq[17][i].out; - multi_or[2][i].in[3] <== eq[18][i].out; - multi_or[2][i].in[4] <== eq[19][i].out; - multi_or[2][i].in[5] <== eq[20][i].out; - multi_or[2][i].in[6] <== eq[21][i].out; - multi_or[2][i].in[7] <== eq[22][i].out; - multi_or[2][i].in[8] <== eq[23][i].out; - multi_or[2][i].in[9] <== eq[24][i].out; - multi_or[2][i].in[10] <== eq[25][i].out; - multi_or[2][i].in[11] <== eq[26][i].out; - multi_or[2][i].in[12] <== eq[27][i].out; - multi_or[2][i].in[13] <== eq[28][i].out; - multi_or[2][i].in[14] <== eq[29][i].out; - multi_or[2][i].in[15] <== eq[30][i].out; - and[13][i].b <== multi_or[2][i].out; - multi_or[3][i] = MultiOR(3); - multi_or[3][i].in[0] <== and[11][i].out; - multi_or[3][i].in[1] <== and[12][i].out; - multi_or[3][i].in[2] <== and[13][i].out; - states_tmp[i+1][3] <== multi_or[3][i].out; + eq[30][i].in[1] <== 134; eq[31][i] = IsEqual(); eq[31][i].in[0] <== in[i]; - eq[31][i].in[1] <== 237; - and[14][i] = AND(); - and[14][i].a <== states[i][0]; - and[14][i].b <== eq[31][i].out; - states_tmp[i+1][4] <== 0; + eq[31][i].in[1] <== 135; eq[32][i] = IsEqual(); eq[32][i].in[0] <== in[i]; - eq[32][i].in[1] <== 240; - and[15][i] = AND(); - and[15][i].a <== states[i][0]; - and[15][i].b <== eq[32][i].out; - states_tmp[i+1][5] <== 0; + eq[32][i].in[1] <== 136; eq[33][i] = IsEqual(); eq[33][i].in[0] <== in[i]; - eq[33][i].in[1] <== 241; + eq[33][i].in[1] <== 137; eq[34][i] = IsEqual(); eq[34][i].in[0] <== in[i]; - eq[34][i].in[1] <== 242; + eq[34][i].in[1] <== 138; eq[35][i] = IsEqual(); eq[35][i].in[0] <== in[i]; - eq[35][i].in[1] <== 243; - and[16][i] = AND(); - and[16][i].a <== states[i][0]; - multi_or[4][i] = MultiOR(3); - multi_or[4][i].in[0] <== eq[33][i].out; - multi_or[4][i].in[1] <== eq[34][i].out; - multi_or[4][i].in[2] <== eq[35][i].out; - and[16][i].b <== multi_or[4][i].out; - states_tmp[i+1][6] <== 0; + eq[35][i].in[1] <== 139; eq[36][i] = IsEqual(); eq[36][i].in[0] <== in[i]; - eq[36][i].in[1] <== 244; - and[17][i] = AND(); - and[17][i].a <== states[i][0]; - and[17][i].b <== eq[36][i].out; - states_tmp[i+1][7] <== 0; - lt[10][i] = LessEqThan(8); - lt[10][i].in[0] <== 11; - lt[10][i].in[1] <== in[i]; - lt[11][i] = LessEqThan(8); - lt[11][i].in[0] <== in[i]; - lt[11][i].in[1] <== 127; - and[18][i] = AND(); - and[18][i].a <== lt[10][i].out; - and[18][i].b <== lt[11][i].out; + eq[36][i].in[1] <== 140; eq[37][i] = IsEqual(); eq[37][i].in[0] <== in[i]; - eq[37][i].in[1] <== 1; + eq[37][i].in[1] <== 141; eq[38][i] = IsEqual(); eq[38][i].in[0] <== in[i]; - eq[38][i].in[1] <== 2; + eq[38][i].in[1] <== 142; eq[39][i] = IsEqual(); eq[39][i].in[0] <== in[i]; - eq[39][i].in[1] <== 3; + eq[39][i].in[1] <== 143; + and[16][i] = AND(); + and[16][i].a <== states[i][8]; + multi_or[3][i] = MultiOR(16); + multi_or[3][i].in[0] <== eq[24][i].out; + multi_or[3][i].in[1] <== eq[25][i].out; + multi_or[3][i].in[2] <== eq[26][i].out; + multi_or[3][i].in[3] <== eq[27][i].out; + multi_or[3][i].in[4] <== eq[28][i].out; + multi_or[3][i].in[5] <== eq[29][i].out; + multi_or[3][i].in[6] <== eq[30][i].out; + multi_or[3][i].in[7] <== eq[31][i].out; + multi_or[3][i].in[8] <== eq[32][i].out; + multi_or[3][i].in[9] <== eq[33][i].out; + multi_or[3][i].in[10] <== eq[34][i].out; + multi_or[3][i].in[11] <== eq[35][i].out; + multi_or[3][i].in[12] <== eq[36][i].out; + multi_or[3][i].in[13] <== eq[37][i].out; + multi_or[3][i].in[14] <== eq[38][i].out; + multi_or[3][i].in[15] <== eq[39][i].out; + and[16][i].b <== multi_or[3][i].out; + multi_or[4][i] = MultiOR(3); + multi_or[4][i].in[0] <== and[14][i].out; + multi_or[4][i].in[1] <== and[15][i].out; + multi_or[4][i].in[2] <== and[16][i].out; + states_tmp[i+1][4] <== multi_or[4][i].out; eq[40][i] = IsEqual(); eq[40][i].in[0] <== in[i]; - eq[40][i].in[1] <== 4; + eq[40][i].in[1] <== 237; + and[17][i] = AND(); + and[17][i].a <== states[i][0]; + and[17][i].b <== eq[40][i].out; + states_tmp[i+1][5] <== 0; eq[41][i] = IsEqual(); eq[41][i].in[0] <== in[i]; - eq[41][i].in[1] <== 5; + eq[41][i].in[1] <== 240; + and[18][i] = AND(); + and[18][i].a <== states[i][0]; + and[18][i].b <== eq[41][i].out; + states_tmp[i+1][6] <== 0; eq[42][i] = IsEqual(); eq[42][i].in[0] <== in[i]; - eq[42][i].in[1] <== 6; + eq[42][i].in[1] <== 241; eq[43][i] = IsEqual(); eq[43][i].in[0] <== in[i]; - eq[43][i].in[1] <== 7; + eq[43][i].in[1] <== 242; eq[44][i] = IsEqual(); eq[44][i].in[0] <== in[i]; - eq[44][i].in[1] <== 8; - eq[45][i] = IsEqual(); - eq[45][i].in[0] <== in[i]; - eq[45][i].in[1] <== 9; + eq[44][i].in[1] <== 243; and[19][i] = AND(); and[19][i].a <== states[i][0]; - multi_or[5][i] = MultiOR(10); - multi_or[5][i].in[0] <== and[18][i].out; - multi_or[5][i].in[1] <== eq[37][i].out; - multi_or[5][i].in[2] <== eq[38][i].out; - multi_or[5][i].in[3] <== eq[39][i].out; - multi_or[5][i].in[4] <== eq[40][i].out; - multi_or[5][i].in[5] <== eq[41][i].out; - multi_or[5][i].in[6] <== eq[42][i].out; - multi_or[5][i].in[7] <== eq[43][i].out; - multi_or[5][i].in[8] <== eq[44][i].out; - multi_or[5][i].in[9] <== eq[45][i].out; + multi_or[5][i] = MultiOR(3); + multi_or[5][i].in[0] <== eq[42][i].out; + multi_or[5][i].in[1] <== eq[43][i].out; + multi_or[5][i].in[2] <== eq[44][i].out; and[19][i].b <== multi_or[5][i].out; + states_tmp[i+1][7] <== 0; + eq[45][i] = IsEqual(); + eq[45][i].in[0] <== in[i]; + eq[45][i].in[1] <== 244; and[20][i] = AND(); - and[20][i].a <== states[i][1]; - and[20][i].b <== and[4][i].out; - states_tmp[i+1][8] <== and[20][i].out; + and[20][i].a <== states[i][0]; + and[20][i].b <== eq[45][i].out; + states_tmp[i+1][8] <== 0; from_zero_enabled[i] <== MultiNOR(8)([states_tmp[i+1][1], states_tmp[i+1][2], states_tmp[i+1][3], states_tmp[i+1][4], states_tmp[i+1][5], states_tmp[i+1][6], states_tmp[i+1][7], states_tmp[i+1][8]]); states[i+1][1] <== MultiOR(2)([states_tmp[i+1][1], from_zero_enabled[i] * and[1][i].out]); - states[i+1][2] <== MultiOR(2)([states_tmp[i+1][2], from_zero_enabled[i] * and[8][i].out]); - states[i+1][3] <== MultiOR(2)([states_tmp[i+1][3], from_zero_enabled[i] * and[9][i].out]); - states[i+1][4] <== MultiOR(2)([states_tmp[i+1][4], from_zero_enabled[i] * and[14][i].out]); - states[i+1][5] <== MultiOR(2)([states_tmp[i+1][5], from_zero_enabled[i] * and[15][i].out]); - states[i+1][6] <== MultiOR(2)([states_tmp[i+1][6], from_zero_enabled[i] * and[16][i].out]); - states[i+1][7] <== MultiOR(2)([states_tmp[i+1][7], from_zero_enabled[i] * and[17][i].out]); - states[i+1][8] <== MultiOR(2)([states_tmp[i+1][8], from_zero_enabled[i] * and[19][i].out]); + states[i+1][2] <== MultiOR(2)([states_tmp[i+1][2], from_zero_enabled[i] * and[5][i].out]); + states[i+1][3] <== MultiOR(2)([states_tmp[i+1][3], from_zero_enabled[i] * and[11][i].out]); + states[i+1][4] <== MultiOR(2)([states_tmp[i+1][4], from_zero_enabled[i] * and[12][i].out]); + states[i+1][5] <== MultiOR(2)([states_tmp[i+1][5], from_zero_enabled[i] * and[17][i].out]); + states[i+1][6] <== MultiOR(2)([states_tmp[i+1][6], from_zero_enabled[i] * and[18][i].out]); + states[i+1][7] <== MultiOR(2)([states_tmp[i+1][7], from_zero_enabled[i] * and[19][i].out]); + states[i+1][8] <== MultiOR(2)([states_tmp[i+1][8], from_zero_enabled[i] * and[20][i].out]); state_changed[i].in[0] <== states[i+1][1]; state_changed[i].in[1] <== states[i+1][2]; state_changed[i].in[2] <== states[i+1][3]; @@ -352,23 +352,23 @@ template Dot1Regex(msg_bytes) { component is_accepted = MultiOR(num_bytes+1); for (var i = 0; i <= num_bytes; i++) { - is_accepted.in[i] <== states[i][8]; + is_accepted.in[i] <== states[i][1]; } out <== is_accepted.out; signal is_consecutive[msg_bytes+1][3]; is_consecutive[msg_bytes][2] <== 0; for (var i = 0; i < msg_bytes; i++) { - is_consecutive[msg_bytes-1-i][0] <== states[num_bytes-i][8] * (1 - is_consecutive[msg_bytes-i][2]) + is_consecutive[msg_bytes-i][2]; + is_consecutive[msg_bytes-1-i][0] <== states[num_bytes-i][1] * (1 - is_consecutive[msg_bytes-i][2]) + is_consecutive[msg_bytes-i][2]; is_consecutive[msg_bytes-1-i][1] <== state_changed[msg_bytes-i].out * is_consecutive[msg_bytes-1-i][0]; - is_consecutive[msg_bytes-1-i][2] <== ORAnd()([(1 - from_zero_enabled[msg_bytes-i+1]), states[num_bytes-i][8], is_consecutive[msg_bytes-1-i][1]]); + is_consecutive[msg_bytes-1-i][2] <== ORAnd()([(1 - from_zero_enabled[msg_bytes-i+1]), states[num_bytes-i][1], is_consecutive[msg_bytes-1-i][1]]); } - // substrings calculated: [{(0, 1), (0, 2), (0, 3), (0, 4), (0, 5), (0, 6), (0, 7), (0, 8), (1, 8), (2, 1), (3, 1), (4, 1), (5, 3), (6, 3), (7, 3)}] + // substrings calculated: [{(0, 1), (0, 2), (0, 3), (0, 4), (0, 5), (0, 6), (0, 7), (0, 8), (2, 1), (3, 2), (4, 2), (5, 2), (6, 4), (7, 4), (8, 4)}] signal prev_states0[15][msg_bytes]; signal is_substr0[msg_bytes]; signal is_reveal0[msg_bytes]; signal output reveal0[msg_bytes]; for (var i = 0; i < msg_bytes; i++) { - // the 0-th substring transitions: [(0, 1), (0, 2), (0, 3), (0, 4), (0, 5), (0, 6), (0, 7), (0, 8), (1, 8), (2, 1), (3, 1), (4, 1), (5, 3), (6, 3), (7, 3)] + // the 0-th substring transitions: [(0, 1), (0, 2), (0, 3), (0, 4), (0, 5), (0, 6), (0, 7), (0, 8), (2, 1), (3, 2), (4, 2), (5, 2), (6, 4), (7, 4), (8, 4)] prev_states0[0][i] <== from_zero_enabled[i+1] * states[i+1][0]; prev_states0[1][i] <== from_zero_enabled[i+1] * states[i+1][0]; prev_states0[2][i] <== from_zero_enabled[i+1] * states[i+1][0]; @@ -377,14 +377,14 @@ template Dot1Regex(msg_bytes) { prev_states0[5][i] <== from_zero_enabled[i+1] * states[i+1][0]; prev_states0[6][i] <== from_zero_enabled[i+1] * states[i+1][0]; prev_states0[7][i] <== from_zero_enabled[i+1] * states[i+1][0]; - prev_states0[8][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][1]; - prev_states0[9][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][2]; - prev_states0[10][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][3]; - prev_states0[11][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][4]; - prev_states0[12][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][5]; - prev_states0[13][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][6]; - prev_states0[14][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][7]; - is_substr0[i] <== MultiOR(15)([prev_states0[0][i] * states[i+2][1], prev_states0[1][i] * states[i+2][2], prev_states0[2][i] * states[i+2][3], prev_states0[3][i] * states[i+2][4], prev_states0[4][i] * states[i+2][5], prev_states0[5][i] * states[i+2][6], prev_states0[6][i] * states[i+2][7], prev_states0[7][i] * states[i+2][8], prev_states0[8][i] * states[i+2][8], prev_states0[9][i] * states[i+2][1], prev_states0[10][i] * states[i+2][1], prev_states0[11][i] * states[i+2][1], prev_states0[12][i] * states[i+2][3], prev_states0[13][i] * states[i+2][3], prev_states0[14][i] * states[i+2][3]]); + prev_states0[8][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][2]; + prev_states0[9][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][3]; + prev_states0[10][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][4]; + prev_states0[11][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][5]; + prev_states0[12][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][6]; + prev_states0[13][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][7]; + prev_states0[14][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][8]; + is_substr0[i] <== MultiOR(15)([prev_states0[0][i] * states[i+2][1], prev_states0[1][i] * states[i+2][2], prev_states0[2][i] * states[i+2][3], prev_states0[3][i] * states[i+2][4], prev_states0[4][i] * states[i+2][5], prev_states0[5][i] * states[i+2][6], prev_states0[6][i] * states[i+2][7], prev_states0[7][i] * states[i+2][8], prev_states0[8][i] * states[i+2][1], prev_states0[9][i] * states[i+2][2], prev_states0[10][i] * states[i+2][2], prev_states0[11][i] * states[i+2][2], prev_states0[12][i] * states[i+2][4], prev_states0[13][i] * states[i+2][4], prev_states0[14][i] * states[i+2][4]]); is_reveal0[i] <== MultiAND(3)([out, is_substr0[i], is_consecutive[i][2]]); reveal0[i] <== in[i+1] * is_reveal0[i]; } diff --git a/packages/circom/tests/circuits/dot2_regex.circom b/packages/circom/tests/circuits/dot2_regex.circom index 855b946..366ac40 100644 --- a/packages/circom/tests/circuits/dot2_regex.circom +++ b/packages/circom/tests/circuits/dot2_regex.circom @@ -39,19 +39,57 @@ template Dot2Regex(msg_bytes) { and[0][i].b <== eq[0][i].out; states_tmp[i+1][1] <== 0; lt[0][i] = LessEqThan(8); - lt[0][i].in[0] <== 194; + lt[0][i].in[0] <== 11; lt[0][i].in[1] <== in[i]; lt[1][i] = LessEqThan(8); lt[1][i].in[0] <== in[i]; - lt[1][i].in[1] <== 223; + lt[1][i].in[1] <== 127; and[1][i] = AND(); and[1][i].a <== lt[0][i].out; and[1][i].b <== lt[1][i].out; + eq[1][i] = IsEqual(); + eq[1][i].in[0] <== in[i]; + eq[1][i].in[1] <== 1; + eq[2][i] = IsEqual(); + eq[2][i].in[0] <== in[i]; + eq[2][i].in[1] <== 2; + eq[3][i] = IsEqual(); + eq[3][i].in[0] <== in[i]; + eq[3][i].in[1] <== 3; + eq[4][i] = IsEqual(); + eq[4][i].in[0] <== in[i]; + eq[4][i].in[1] <== 4; + eq[5][i] = IsEqual(); + eq[5][i].in[0] <== in[i]; + eq[5][i].in[1] <== 5; + eq[6][i] = IsEqual(); + eq[6][i].in[0] <== in[i]; + eq[6][i].in[1] <== 6; + eq[7][i] = IsEqual(); + eq[7][i].in[0] <== in[i]; + eq[7][i].in[1] <== 7; + eq[8][i] = IsEqual(); + eq[8][i].in[0] <== in[i]; + eq[8][i].in[1] <== 8; + eq[9][i] = IsEqual(); + eq[9][i].in[0] <== in[i]; + eq[9][i].in[1] <== 9; and[2][i] = AND(); and[2][i].a <== states[i][1]; - and[2][i].b <== and[1][i].out; + multi_or[0][i] = MultiOR(10); + multi_or[0][i].in[0] <== and[1][i].out; + multi_or[0][i].in[1] <== eq[1][i].out; + multi_or[0][i].in[2] <== eq[2][i].out; + multi_or[0][i].in[3] <== eq[3][i].out; + multi_or[0][i].in[4] <== eq[4][i].out; + multi_or[0][i].in[5] <== eq[5][i].out; + multi_or[0][i].in[6] <== eq[6][i].out; + multi_or[0][i].in[7] <== eq[7][i].out; + multi_or[0][i].in[8] <== eq[8][i].out; + multi_or[0][i].in[9] <== eq[9][i].out; + and[2][i].b <== multi_or[0][i].out; lt[2][i] = LessEqThan(8); - lt[2][i].in[0] <== 160; + lt[2][i].in[0] <== 128; lt[2][i].in[1] <== in[i]; lt[3][i] = LessEqThan(8); lt[3][i].in[0] <== in[i]; @@ -62,292 +100,254 @@ template Dot2Regex(msg_bytes) { and[4][i] = AND(); and[4][i].a <== states[i][3]; and[4][i].b <== and[3][i].out; + multi_or[1][i] = MultiOR(2); + multi_or[1][i].in[0] <== and[2][i].out; + multi_or[1][i].in[1] <== and[4][i].out; + states[i+1][2] <== multi_or[1][i].out; lt[4][i] = LessEqThan(8); - lt[4][i].in[0] <== 128; + lt[4][i].in[0] <== 194; lt[4][i].in[1] <== in[i]; lt[5][i] = LessEqThan(8); lt[5][i].in[0] <== in[i]; - lt[5][i].in[1] <== 191; + lt[5][i].in[1] <== 223; and[5][i] = AND(); and[5][i].a <== lt[4][i].out; and[5][i].b <== lt[5][i].out; and[6][i] = AND(); - and[6][i].a <== states[i][4]; + and[6][i].a <== states[i][1]; and[6][i].b <== and[5][i].out; lt[6][i] = LessEqThan(8); - lt[6][i].in[0] <== 128; + lt[6][i].in[0] <== 160; lt[6][i].in[1] <== in[i]; lt[7][i] = LessEqThan(8); lt[7][i].in[0] <== in[i]; - lt[7][i].in[1] <== 159; + lt[7][i].in[1] <== 191; and[7][i] = AND(); and[7][i].a <== lt[6][i].out; and[7][i].b <== lt[7][i].out; and[8][i] = AND(); - and[8][i].a <== states[i][5]; + and[8][i].a <== states[i][4]; and[8][i].b <== and[7][i].out; - multi_or[0][i] = MultiOR(4); - multi_or[0][i].in[0] <== and[2][i].out; - multi_or[0][i].in[1] <== and[4][i].out; - multi_or[0][i].in[2] <== and[6][i].out; - multi_or[0][i].in[3] <== and[8][i].out; - states[i+1][2] <== multi_or[0][i].out; - eq[1][i] = IsEqual(); - eq[1][i].in[0] <== in[i]; - eq[1][i].in[1] <== 224; and[9][i] = AND(); - and[9][i].a <== states[i][1]; - and[9][i].b <== eq[1][i].out; - states[i+1][3] <== and[9][i].out; - eq[2][i] = IsEqual(); - eq[2][i].in[0] <== in[i]; - eq[2][i].in[1] <== 225; - eq[3][i] = IsEqual(); - eq[3][i].in[0] <== in[i]; - eq[3][i].in[1] <== 226; - eq[4][i] = IsEqual(); - eq[4][i].in[0] <== in[i]; - eq[4][i].in[1] <== 227; - eq[5][i] = IsEqual(); - eq[5][i].in[0] <== in[i]; - eq[5][i].in[1] <== 228; - eq[6][i] = IsEqual(); - eq[6][i].in[0] <== in[i]; - eq[6][i].in[1] <== 229; - eq[7][i] = IsEqual(); - eq[7][i].in[0] <== in[i]; - eq[7][i].in[1] <== 230; - eq[8][i] = IsEqual(); - eq[8][i].in[0] <== in[i]; - eq[8][i].in[1] <== 231; - eq[9][i] = IsEqual(); - eq[9][i].in[0] <== in[i]; - eq[9][i].in[1] <== 232; + and[9][i].a <== states[i][5]; + and[9][i].b <== and[3][i].out; + lt[8][i] = LessEqThan(8); + lt[8][i].in[0] <== 128; + lt[8][i].in[1] <== in[i]; + lt[9][i] = LessEqThan(8); + lt[9][i].in[0] <== in[i]; + lt[9][i].in[1] <== 159; + and[10][i] = AND(); + and[10][i].a <== lt[8][i].out; + and[10][i].b <== lt[9][i].out; + and[11][i] = AND(); + and[11][i].a <== states[i][6]; + and[11][i].b <== and[10][i].out; + multi_or[2][i] = MultiOR(4); + multi_or[2][i].in[0] <== and[6][i].out; + multi_or[2][i].in[1] <== and[8][i].out; + multi_or[2][i].in[2] <== and[9][i].out; + multi_or[2][i].in[3] <== and[11][i].out; + states[i+1][3] <== multi_or[2][i].out; eq[10][i] = IsEqual(); eq[10][i].in[0] <== in[i]; - eq[10][i].in[1] <== 233; + eq[10][i].in[1] <== 224; + and[12][i] = AND(); + and[12][i].a <== states[i][1]; + and[12][i].b <== eq[10][i].out; + states[i+1][4] <== and[12][i].out; eq[11][i] = IsEqual(); eq[11][i].in[0] <== in[i]; - eq[11][i].in[1] <== 234; + eq[11][i].in[1] <== 225; eq[12][i] = IsEqual(); eq[12][i].in[0] <== in[i]; - eq[12][i].in[1] <== 235; + eq[12][i].in[1] <== 226; eq[13][i] = IsEqual(); eq[13][i].in[0] <== in[i]; - eq[13][i].in[1] <== 236; + eq[13][i].in[1] <== 227; eq[14][i] = IsEqual(); eq[14][i].in[0] <== in[i]; - eq[14][i].in[1] <== 238; + eq[14][i].in[1] <== 228; eq[15][i] = IsEqual(); eq[15][i].in[0] <== in[i]; - eq[15][i].in[1] <== 239; - and[10][i] = AND(); - and[10][i].a <== states[i][1]; - multi_or[1][i] = MultiOR(14); - multi_or[1][i].in[0] <== eq[2][i].out; - multi_or[1][i].in[1] <== eq[3][i].out; - multi_or[1][i].in[2] <== eq[4][i].out; - multi_or[1][i].in[3] <== eq[5][i].out; - multi_or[1][i].in[4] <== eq[6][i].out; - multi_or[1][i].in[5] <== eq[7][i].out; - multi_or[1][i].in[6] <== eq[8][i].out; - multi_or[1][i].in[7] <== eq[9][i].out; - multi_or[1][i].in[8] <== eq[10][i].out; - multi_or[1][i].in[9] <== eq[11][i].out; - multi_or[1][i].in[10] <== eq[12][i].out; - multi_or[1][i].in[11] <== eq[13][i].out; - multi_or[1][i].in[12] <== eq[14][i].out; - multi_or[1][i].in[13] <== eq[15][i].out; - and[10][i].b <== multi_or[1][i].out; - lt[8][i] = LessEqThan(8); - lt[8][i].in[0] <== 144; - lt[8][i].in[1] <== in[i]; - lt[9][i] = LessEqThan(8); - lt[9][i].in[0] <== in[i]; - lt[9][i].in[1] <== 191; - and[11][i] = AND(); - and[11][i].a <== lt[8][i].out; - and[11][i].b <== lt[9][i].out; - and[12][i] = AND(); - and[12][i].a <== states[i][6]; - and[12][i].b <== and[11][i].out; - and[13][i] = AND(); - and[13][i].a <== states[i][7]; - and[13][i].b <== and[5][i].out; + eq[15][i].in[1] <== 229; eq[16][i] = IsEqual(); eq[16][i].in[0] <== in[i]; - eq[16][i].in[1] <== 128; + eq[16][i].in[1] <== 230; eq[17][i] = IsEqual(); eq[17][i].in[0] <== in[i]; - eq[17][i].in[1] <== 129; + eq[17][i].in[1] <== 231; eq[18][i] = IsEqual(); eq[18][i].in[0] <== in[i]; - eq[18][i].in[1] <== 130; + eq[18][i].in[1] <== 232; eq[19][i] = IsEqual(); eq[19][i].in[0] <== in[i]; - eq[19][i].in[1] <== 131; + eq[19][i].in[1] <== 233; eq[20][i] = IsEqual(); eq[20][i].in[0] <== in[i]; - eq[20][i].in[1] <== 132; + eq[20][i].in[1] <== 234; eq[21][i] = IsEqual(); eq[21][i].in[0] <== in[i]; - eq[21][i].in[1] <== 133; + eq[21][i].in[1] <== 235; eq[22][i] = IsEqual(); eq[22][i].in[0] <== in[i]; - eq[22][i].in[1] <== 134; + eq[22][i].in[1] <== 236; eq[23][i] = IsEqual(); eq[23][i].in[0] <== in[i]; - eq[23][i].in[1] <== 135; + eq[23][i].in[1] <== 238; eq[24][i] = IsEqual(); eq[24][i].in[0] <== in[i]; - eq[24][i].in[1] <== 136; + eq[24][i].in[1] <== 239; + and[13][i] = AND(); + and[13][i].a <== states[i][1]; + multi_or[3][i] = MultiOR(14); + multi_or[3][i].in[0] <== eq[11][i].out; + multi_or[3][i].in[1] <== eq[12][i].out; + multi_or[3][i].in[2] <== eq[13][i].out; + multi_or[3][i].in[3] <== eq[14][i].out; + multi_or[3][i].in[4] <== eq[15][i].out; + multi_or[3][i].in[5] <== eq[16][i].out; + multi_or[3][i].in[6] <== eq[17][i].out; + multi_or[3][i].in[7] <== eq[18][i].out; + multi_or[3][i].in[8] <== eq[19][i].out; + multi_or[3][i].in[9] <== eq[20][i].out; + multi_or[3][i].in[10] <== eq[21][i].out; + multi_or[3][i].in[11] <== eq[22][i].out; + multi_or[3][i].in[12] <== eq[23][i].out; + multi_or[3][i].in[13] <== eq[24][i].out; + and[13][i].b <== multi_or[3][i].out; + lt[10][i] = LessEqThan(8); + lt[10][i].in[0] <== 144; + lt[10][i].in[1] <== in[i]; + lt[11][i] = LessEqThan(8); + lt[11][i].in[0] <== in[i]; + lt[11][i].in[1] <== 191; + and[14][i] = AND(); + and[14][i].a <== lt[10][i].out; + and[14][i].b <== lt[11][i].out; + and[15][i] = AND(); + and[15][i].a <== states[i][7]; + and[15][i].b <== and[14][i].out; + and[16][i] = AND(); + and[16][i].a <== states[i][8]; + and[16][i].b <== and[3][i].out; eq[25][i] = IsEqual(); eq[25][i].in[0] <== in[i]; - eq[25][i].in[1] <== 137; + eq[25][i].in[1] <== 128; eq[26][i] = IsEqual(); eq[26][i].in[0] <== in[i]; - eq[26][i].in[1] <== 138; + eq[26][i].in[1] <== 129; eq[27][i] = IsEqual(); eq[27][i].in[0] <== in[i]; - eq[27][i].in[1] <== 139; + eq[27][i].in[1] <== 130; eq[28][i] = IsEqual(); eq[28][i].in[0] <== in[i]; - eq[28][i].in[1] <== 140; + eq[28][i].in[1] <== 131; eq[29][i] = IsEqual(); eq[29][i].in[0] <== in[i]; - eq[29][i].in[1] <== 141; + eq[29][i].in[1] <== 132; eq[30][i] = IsEqual(); eq[30][i].in[0] <== in[i]; - eq[30][i].in[1] <== 142; + eq[30][i].in[1] <== 133; eq[31][i] = IsEqual(); eq[31][i].in[0] <== in[i]; - eq[31][i].in[1] <== 143; - and[14][i] = AND(); - and[14][i].a <== states[i][8]; - multi_or[2][i] = MultiOR(16); - multi_or[2][i].in[0] <== eq[16][i].out; - multi_or[2][i].in[1] <== eq[17][i].out; - multi_or[2][i].in[2] <== eq[18][i].out; - multi_or[2][i].in[3] <== eq[19][i].out; - multi_or[2][i].in[4] <== eq[20][i].out; - multi_or[2][i].in[5] <== eq[21][i].out; - multi_or[2][i].in[6] <== eq[22][i].out; - multi_or[2][i].in[7] <== eq[23][i].out; - multi_or[2][i].in[8] <== eq[24][i].out; - multi_or[2][i].in[9] <== eq[25][i].out; - multi_or[2][i].in[10] <== eq[26][i].out; - multi_or[2][i].in[11] <== eq[27][i].out; - multi_or[2][i].in[12] <== eq[28][i].out; - multi_or[2][i].in[13] <== eq[29][i].out; - multi_or[2][i].in[14] <== eq[30][i].out; - multi_or[2][i].in[15] <== eq[31][i].out; - and[14][i].b <== multi_or[2][i].out; - multi_or[3][i] = MultiOR(4); - multi_or[3][i].in[0] <== and[10][i].out; - multi_or[3][i].in[1] <== and[12][i].out; - multi_or[3][i].in[2] <== and[13][i].out; - multi_or[3][i].in[3] <== and[14][i].out; - states[i+1][4] <== multi_or[3][i].out; + eq[31][i].in[1] <== 134; eq[32][i] = IsEqual(); eq[32][i].in[0] <== in[i]; - eq[32][i].in[1] <== 237; - and[15][i] = AND(); - and[15][i].a <== states[i][1]; - and[15][i].b <== eq[32][i].out; - states[i+1][5] <== and[15][i].out; + eq[32][i].in[1] <== 135; eq[33][i] = IsEqual(); eq[33][i].in[0] <== in[i]; - eq[33][i].in[1] <== 240; - and[16][i] = AND(); - and[16][i].a <== states[i][1]; - and[16][i].b <== eq[33][i].out; - states[i+1][6] <== and[16][i].out; + eq[33][i].in[1] <== 136; eq[34][i] = IsEqual(); eq[34][i].in[0] <== in[i]; - eq[34][i].in[1] <== 241; + eq[34][i].in[1] <== 137; eq[35][i] = IsEqual(); eq[35][i].in[0] <== in[i]; - eq[35][i].in[1] <== 242; + eq[35][i].in[1] <== 138; eq[36][i] = IsEqual(); eq[36][i].in[0] <== in[i]; - eq[36][i].in[1] <== 243; - and[17][i] = AND(); - and[17][i].a <== states[i][1]; - multi_or[4][i] = MultiOR(3); - multi_or[4][i].in[0] <== eq[34][i].out; - multi_or[4][i].in[1] <== eq[35][i].out; - multi_or[4][i].in[2] <== eq[36][i].out; - and[17][i].b <== multi_or[4][i].out; - states[i+1][7] <== and[17][i].out; + eq[36][i].in[1] <== 139; eq[37][i] = IsEqual(); eq[37][i].in[0] <== in[i]; - eq[37][i].in[1] <== 244; - and[18][i] = AND(); - and[18][i].a <== states[i][1]; - and[18][i].b <== eq[37][i].out; - states[i+1][8] <== and[18][i].out; - lt[10][i] = LessEqThan(8); - lt[10][i].in[0] <== 11; - lt[10][i].in[1] <== in[i]; - lt[11][i] = LessEqThan(8); - lt[11][i].in[0] <== in[i]; - lt[11][i].in[1] <== 127; - and[19][i] = AND(); - and[19][i].a <== lt[10][i].out; - and[19][i].b <== lt[11][i].out; + eq[37][i].in[1] <== 140; eq[38][i] = IsEqual(); eq[38][i].in[0] <== in[i]; - eq[38][i].in[1] <== 1; + eq[38][i].in[1] <== 141; eq[39][i] = IsEqual(); eq[39][i].in[0] <== in[i]; - eq[39][i].in[1] <== 2; + eq[39][i].in[1] <== 142; eq[40][i] = IsEqual(); eq[40][i].in[0] <== in[i]; - eq[40][i].in[1] <== 3; + eq[40][i].in[1] <== 143; + and[17][i] = AND(); + and[17][i].a <== states[i][9]; + multi_or[4][i] = MultiOR(16); + multi_or[4][i].in[0] <== eq[25][i].out; + multi_or[4][i].in[1] <== eq[26][i].out; + multi_or[4][i].in[2] <== eq[27][i].out; + multi_or[4][i].in[3] <== eq[28][i].out; + multi_or[4][i].in[4] <== eq[29][i].out; + multi_or[4][i].in[5] <== eq[30][i].out; + multi_or[4][i].in[6] <== eq[31][i].out; + multi_or[4][i].in[7] <== eq[32][i].out; + multi_or[4][i].in[8] <== eq[33][i].out; + multi_or[4][i].in[9] <== eq[34][i].out; + multi_or[4][i].in[10] <== eq[35][i].out; + multi_or[4][i].in[11] <== eq[36][i].out; + multi_or[4][i].in[12] <== eq[37][i].out; + multi_or[4][i].in[13] <== eq[38][i].out; + multi_or[4][i].in[14] <== eq[39][i].out; + multi_or[4][i].in[15] <== eq[40][i].out; + and[17][i].b <== multi_or[4][i].out; + multi_or[5][i] = MultiOR(4); + multi_or[5][i].in[0] <== and[13][i].out; + multi_or[5][i].in[1] <== and[15][i].out; + multi_or[5][i].in[2] <== and[16][i].out; + multi_or[5][i].in[3] <== and[17][i].out; + states[i+1][5] <== multi_or[5][i].out; eq[41][i] = IsEqual(); eq[41][i].in[0] <== in[i]; - eq[41][i].in[1] <== 4; + eq[41][i].in[1] <== 237; + and[18][i] = AND(); + and[18][i].a <== states[i][1]; + and[18][i].b <== eq[41][i].out; + states[i+1][6] <== and[18][i].out; eq[42][i] = IsEqual(); eq[42][i].in[0] <== in[i]; - eq[42][i].in[1] <== 5; + eq[42][i].in[1] <== 240; + and[19][i] = AND(); + and[19][i].a <== states[i][1]; + and[19][i].b <== eq[42][i].out; + states[i+1][7] <== and[19][i].out; eq[43][i] = IsEqual(); eq[43][i].in[0] <== in[i]; - eq[43][i].in[1] <== 6; + eq[43][i].in[1] <== 241; eq[44][i] = IsEqual(); eq[44][i].in[0] <== in[i]; - eq[44][i].in[1] <== 7; + eq[44][i].in[1] <== 242; eq[45][i] = IsEqual(); eq[45][i].in[0] <== in[i]; - eq[45][i].in[1] <== 8; - eq[46][i] = IsEqual(); - eq[46][i].in[0] <== in[i]; - eq[46][i].in[1] <== 9; + eq[45][i].in[1] <== 243; and[20][i] = AND(); and[20][i].a <== states[i][1]; - multi_or[5][i] = MultiOR(10); - multi_or[5][i].in[0] <== and[19][i].out; - multi_or[5][i].in[1] <== eq[38][i].out; - multi_or[5][i].in[2] <== eq[39][i].out; - multi_or[5][i].in[3] <== eq[40][i].out; - multi_or[5][i].in[4] <== eq[41][i].out; - multi_or[5][i].in[5] <== eq[42][i].out; - multi_or[5][i].in[6] <== eq[43][i].out; - multi_or[5][i].in[7] <== eq[44][i].out; - multi_or[5][i].in[8] <== eq[45][i].out; - multi_or[5][i].in[9] <== eq[46][i].out; - and[20][i].b <== multi_or[5][i].out; + multi_or[6][i] = MultiOR(3); + multi_or[6][i].in[0] <== eq[43][i].out; + multi_or[6][i].in[1] <== eq[44][i].out; + multi_or[6][i].in[2] <== eq[45][i].out; + and[20][i].b <== multi_or[6][i].out; + states[i+1][8] <== and[20][i].out; + eq[46][i] = IsEqual(); + eq[46][i].in[0] <== in[i]; + eq[46][i].in[1] <== 244; and[21][i] = AND(); - and[21][i].a <== states[i][2]; - and[21][i].b <== and[5][i].out; - multi_or[6][i] = MultiOR(2); - multi_or[6][i].in[0] <== and[20][i].out; - multi_or[6][i].in[1] <== and[21][i].out; - states[i+1][9] <== multi_or[6][i].out; + and[21][i].a <== states[i][1]; + and[21][i].b <== eq[46][i].out; + states[i+1][9] <== and[21][i].out; eq[47][i] = IsEqual(); eq[47][i].in[0] <== in[i]; eq[47][i].in[1] <== 98; and[22][i] = AND(); - and[22][i].a <== states[i][9]; + and[22][i].a <== states[i][2]; and[22][i].b <== eq[47][i].out; states[i+1][10] <== and[22][i].out; from_zero_enabled[i] <== MultiNOR(10)([states_tmp[i+1][1], states[i+1][2], states[i+1][3], states[i+1][4], states[i+1][5], states[i+1][6], states[i+1][7], states[i+1][8], states[i+1][9], states[i+1][10]]); @@ -376,13 +376,13 @@ template Dot2Regex(msg_bytes) { is_consecutive[msg_bytes-1-i][1] <== state_changed[msg_bytes-i].out * is_consecutive[msg_bytes-1-i][0]; is_consecutive[msg_bytes-1-i][2] <== ORAnd()([(1 - from_zero_enabled[msg_bytes-i+1]), states[num_bytes-i][10], is_consecutive[msg_bytes-1-i][1]]); } - // substrings calculated: [{(1, 2), (1, 3), (1, 4), (1, 5), (1, 6), (1, 7), (1, 8), (1, 9), (2, 9), (3, 2), (4, 2), (5, 2), (6, 4), (7, 4), (8, 4)}] + // substrings calculated: [{(1, 2), (1, 3), (1, 4), (1, 5), (1, 6), (1, 7), (1, 8), (1, 9), (3, 2), (4, 3), (5, 3), (6, 3), (7, 5), (8, 5), (9, 5)}] signal prev_states0[15][msg_bytes]; signal is_substr0[msg_bytes]; signal is_reveal0[msg_bytes]; signal output reveal0[msg_bytes]; for (var i = 0; i < msg_bytes; i++) { - // the 0-th substring transitions: [(1, 2), (1, 3), (1, 4), (1, 5), (1, 6), (1, 7), (1, 8), (1, 9), (2, 9), (3, 2), (4, 2), (5, 2), (6, 4), (7, 4), (8, 4)] + // the 0-th substring transitions: [(1, 2), (1, 3), (1, 4), (1, 5), (1, 6), (1, 7), (1, 8), (1, 9), (3, 2), (4, 3), (5, 3), (6, 3), (7, 5), (8, 5), (9, 5)] prev_states0[0][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][1]; prev_states0[1][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][1]; prev_states0[2][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][1]; @@ -391,14 +391,14 @@ template Dot2Regex(msg_bytes) { prev_states0[5][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][1]; prev_states0[6][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][1]; prev_states0[7][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][1]; - prev_states0[8][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][2]; - prev_states0[9][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][3]; - prev_states0[10][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][4]; - prev_states0[11][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][5]; - prev_states0[12][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][6]; - prev_states0[13][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][7]; - prev_states0[14][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][8]; - is_substr0[i] <== MultiOR(15)([prev_states0[0][i] * states[i+2][2], prev_states0[1][i] * states[i+2][3], prev_states0[2][i] * states[i+2][4], prev_states0[3][i] * states[i+2][5], prev_states0[4][i] * states[i+2][6], prev_states0[5][i] * states[i+2][7], prev_states0[6][i] * states[i+2][8], prev_states0[7][i] * states[i+2][9], prev_states0[8][i] * states[i+2][9], prev_states0[9][i] * states[i+2][2], prev_states0[10][i] * states[i+2][2], prev_states0[11][i] * states[i+2][2], prev_states0[12][i] * states[i+2][4], prev_states0[13][i] * states[i+2][4], prev_states0[14][i] * states[i+2][4]]); + prev_states0[8][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][3]; + prev_states0[9][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][4]; + prev_states0[10][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][5]; + prev_states0[11][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][6]; + prev_states0[12][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][7]; + prev_states0[13][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][8]; + prev_states0[14][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][9]; + is_substr0[i] <== MultiOR(15)([prev_states0[0][i] * states[i+2][2], prev_states0[1][i] * states[i+2][3], prev_states0[2][i] * states[i+2][4], prev_states0[3][i] * states[i+2][5], prev_states0[4][i] * states[i+2][6], prev_states0[5][i] * states[i+2][7], prev_states0[6][i] * states[i+2][8], prev_states0[7][i] * states[i+2][9], prev_states0[8][i] * states[i+2][2], prev_states0[9][i] * states[i+2][3], prev_states0[10][i] * states[i+2][3], prev_states0[11][i] * states[i+2][3], prev_states0[12][i] * states[i+2][5], prev_states0[13][i] * states[i+2][5], prev_states0[14][i] * states[i+2][5]]); is_reveal0[i] <== MultiAND(3)([out, is_substr0[i], is_consecutive[i][2]]); reveal0[i] <== in[i+1] * is_reveal0[i]; } diff --git a/packages/circom/tests/circuits/international_chars_decomposed.circom b/packages/circom/tests/circuits/international_chars_decomposed.circom index a663ca8..95e53db 100644 --- a/packages/circom/tests/circuits/international_chars_decomposed.circom +++ b/packages/circom/tests/circuits/international_chars_decomposed.circom @@ -133,46 +133,46 @@ template InternationalCharsDecomposed(msg_bytes) { states[i+1][16] <== and[15][i].out; eq[12][i] = IsEqual(); eq[12][i].in[0] <== in[i]; - eq[12][i].in[1] <== 195; + eq[12][i].in[1] <== 194; + and[16][i] = AND(); + and[16][i].a <== states[i][16]; + and[16][i].b <== eq[12][i].out; + and[17][i] = AND(); + and[17][i].a <== states[i][19]; + and[17][i].b <== eq[12][i].out; + multi_or[0][i] = MultiOR(2); + multi_or[0][i].in[0] <== and[16][i].out; + multi_or[0][i].in[1] <== and[17][i].out; + states[i+1][17] <== multi_or[0][i].out; eq[13][i] = IsEqual(); eq[13][i].in[0] <== in[i]; - eq[13][i].in[1] <== 196; + eq[13][i].in[1] <== 195; eq[14][i] = IsEqual(); eq[14][i].in[0] <== in[i]; - eq[14][i].in[1] <== 197; + eq[14][i].in[1] <== 196; eq[15][i] = IsEqual(); eq[15][i].in[0] <== in[i]; - eq[15][i].in[1] <== 198; - and[16][i] = AND(); - and[16][i].a <== states[i][16]; - multi_or[0][i] = MultiOR(4); - multi_or[0][i].in[0] <== eq[12][i].out; - multi_or[0][i].in[1] <== eq[13][i].out; - multi_or[0][i].in[2] <== eq[14][i].out; - multi_or[0][i].in[3] <== eq[15][i].out; - and[16][i].b <== multi_or[0][i].out; - and[17][i] = AND(); - and[17][i].a <== states[i][19]; - and[17][i].b <== multi_or[0][i].out; - multi_or[1][i] = MultiOR(2); - multi_or[1][i].in[0] <== and[16][i].out; - multi_or[1][i].in[1] <== and[17][i].out; - states[i+1][17] <== multi_or[1][i].out; + eq[15][i].in[1] <== 197; eq[16][i] = IsEqual(); eq[16][i].in[0] <== in[i]; - eq[16][i].in[1] <== 194; + eq[16][i].in[1] <== 198; and[18][i] = AND(); and[18][i].a <== states[i][16]; - and[18][i].b <== eq[16][i].out; + multi_or[1][i] = MultiOR(4); + multi_or[1][i].in[0] <== eq[13][i].out; + multi_or[1][i].in[1] <== eq[14][i].out; + multi_or[1][i].in[2] <== eq[15][i].out; + multi_or[1][i].in[3] <== eq[16][i].out; + and[18][i].b <== multi_or[1][i].out; and[19][i] = AND(); and[19][i].a <== states[i][19]; - and[19][i].b <== eq[16][i].out; + and[19][i].b <== multi_or[1][i].out; multi_or[2][i] = MultiOR(2); multi_or[2][i].in[0] <== and[18][i].out; multi_or[2][i].in[1] <== and[19][i].out; states[i+1][18] <== multi_or[2][i].out; lt[0][i] = LessEqThan(8); - lt[0][i].in[0] <== 128; + lt[0][i].in[0] <== 161; lt[0][i].in[1] <== in[i]; lt[1][i] = LessEqThan(8); lt[1][i].in[0] <== in[i]; @@ -184,7 +184,7 @@ template InternationalCharsDecomposed(msg_bytes) { and[21][i].a <== states[i][17]; and[21][i].b <== and[20][i].out; lt[2][i] = LessEqThan(8); - lt[2][i].in[0] <== 161; + lt[2][i].in[0] <== 128; lt[2][i].in[1] <== in[i]; lt[3][i] = LessEqThan(8); lt[3][i].in[0] <== in[i]; @@ -241,39 +241,36 @@ template InternationalCharsDecomposed(msg_bytes) { states[i+1][26] <== and[30][i].out; eq[21][i] = IsEqual(); eq[21][i].in[0] <== in[i]; - eq[21][i].in[1] <== 206; - eq[22][i] = IsEqual(); - eq[22][i].in[0] <== in[i]; - eq[22][i].in[1] <== 207; + eq[21][i].in[1] <== 205; and[31][i] = AND(); and[31][i].a <== states[i][26]; - multi_or[4][i] = MultiOR(2); - multi_or[4][i].in[0] <== eq[21][i].out; - multi_or[4][i].in[1] <== eq[22][i].out; - and[31][i].b <== multi_or[4][i].out; + and[31][i].b <== eq[21][i].out; and[32][i] = AND(); and[32][i].a <== states[i][29]; - and[32][i].b <== multi_or[4][i].out; - multi_or[5][i] = MultiOR(2); - multi_or[5][i].in[0] <== and[31][i].out; - multi_or[5][i].in[1] <== and[32][i].out; - states[i+1][27] <== multi_or[5][i].out; + and[32][i].b <== eq[21][i].out; + multi_or[4][i] = MultiOR(2); + multi_or[4][i].in[0] <== and[31][i].out; + multi_or[4][i].in[1] <== and[32][i].out; + states[i+1][27] <== multi_or[4][i].out; + eq[22][i] = IsEqual(); + eq[22][i].in[0] <== in[i]; + eq[22][i].in[1] <== 206; eq[23][i] = IsEqual(); eq[23][i].in[0] <== in[i]; - eq[23][i].in[1] <== 205; + eq[23][i].in[1] <== 207; and[33][i] = AND(); and[33][i].a <== states[i][26]; - and[33][i].b <== eq[23][i].out; + multi_or[5][i] = MultiOR(2); + multi_or[5][i].in[0] <== eq[22][i].out; + multi_or[5][i].in[1] <== eq[23][i].out; + and[33][i].b <== multi_or[5][i].out; and[34][i] = AND(); and[34][i].a <== states[i][29]; - and[34][i].b <== eq[23][i].out; + and[34][i].b <== multi_or[5][i].out; multi_or[6][i] = MultiOR(2); multi_or[6][i].in[0] <== and[33][i].out; multi_or[6][i].in[1] <== and[34][i].out; states[i+1][28] <== multi_or[6][i].out; - and[35][i] = AND(); - and[35][i].a <== states[i][27]; - and[35][i].b <== and[20][i].out; eq[24][i] = IsEqual(); eq[24][i].in[0] <== in[i]; eq[24][i].in[1] <== 176; @@ -322,8 +319,8 @@ template InternationalCharsDecomposed(msg_bytes) { eq[39][i] = IsEqual(); eq[39][i].in[0] <== in[i]; eq[39][i].in[1] <== 191; - and[36][i] = AND(); - and[36][i].a <== states[i][28]; + and[35][i] = AND(); + and[35][i].a <== states[i][27]; multi_or[7][i] = MultiOR(16); multi_or[7][i].in[0] <== eq[24][i].out; multi_or[7][i].in[1] <== eq[25][i].out; @@ -341,7 +338,10 @@ template InternationalCharsDecomposed(msg_bytes) { multi_or[7][i].in[13] <== eq[37][i].out; multi_or[7][i].in[14] <== eq[38][i].out; multi_or[7][i].in[15] <== eq[39][i].out; - and[36][i].b <== multi_or[7][i].out; + and[35][i].b <== multi_or[7][i].out; + and[36][i] = AND(); + and[36][i].a <== states[i][28]; + and[36][i].b <== and[22][i].out; multi_or[8][i] = MultiOR(2); multi_or[8][i].in[0] <== and[35][i].out; multi_or[8][i].in[1] <== and[36][i].out; @@ -427,7 +427,7 @@ template InternationalCharsDecomposed(msg_bytes) { states[i+1][40] <== multi_or[10][i].out; and[49][i] = AND(); and[49][i].a <== states[i][40]; - and[49][i].b <== and[20][i].out; + and[49][i].b <== and[22][i].out; states[i+1][41] <== and[49][i].out; and[50][i] = AND(); and[50][i].a <== states[i][41]; @@ -496,7 +496,7 @@ template InternationalCharsDecomposed(msg_bytes) { states[i+1][50] <== multi_or[12][i].out; and[60][i] = AND(); and[60][i].a <== states[i][50]; - and[60][i].b <== and[20][i].out; + and[60][i].b <== and[22][i].out; states[i+1][51] <== and[60][i].out; and[61][i] = AND(); and[61][i].a <== states[i][51]; @@ -583,7 +583,7 @@ template InternationalCharsDecomposed(msg_bytes) { states[i+1][65] <== and[75][i].out; and[76][i] = AND(); and[76][i].a <== states[i][65]; - and[76][i].b <== and[20][i].out; + and[76][i].b <== and[22][i].out; states[i+1][66] <== and[76][i].out; and[77][i] = AND(); and[77][i].a <== states[i][66]; @@ -717,7 +717,7 @@ template InternationalCharsDecomposed(msg_bytes) { and[101][i].b <== and[100][i].out; and[102][i] = AND(); and[102][i].a <== states[i][88]; - and[102][i].b <== and[20][i].out; + and[102][i].b <== and[22][i].out; multi_or[17][i] = MultiOR(2); multi_or[17][i].in[0] <== and[101][i].out; multi_or[17][i].in[1] <== and[102][i].out; diff --git a/packages/circom/tests/circuits/invitation_code_with_prefix_regex.circom b/packages/circom/tests/circuits/invitation_code_with_prefix_regex.circom index 979a9a5..8c31790 100644 --- a/packages/circom/tests/circuits/invitation_code_with_prefix_regex.circom +++ b/packages/circom/tests/circuits/invitation_code_with_prefix_regex.circom @@ -32,32 +32,32 @@ template InvitationCodeWithPrefixRegex(msg_bytes) { states[i][0] <== 1; eq[0][i] = IsEqual(); eq[0][i].in[0] <== in[i]; - eq[0][i].in[1] <== 67; - eq[1][i] = IsEqual(); - eq[1][i].in[0] <== in[i]; - eq[1][i].in[1] <== 99; + eq[0][i].in[1] <== 32; and[0][i] = AND(); and[0][i].a <== states[i][0]; - multi_or[0][i] = MultiOR(2); - multi_or[0][i].in[0] <== eq[0][i].out; - multi_or[0][i].in[1] <== eq[1][i].out; - and[0][i].b <== multi_or[0][i].out; - and[1][i] = AND(); - and[1][i].a <== states[i][2]; - and[1][i].b <== multi_or[0][i].out; - states_tmp[i+1][1] <== and[1][i].out; + and[0][i].b <== eq[0][i].out; + states_tmp[i+1][1] <== 0; + eq[1][i] = IsEqual(); + eq[1][i].in[0] <== in[i]; + eq[1][i].in[1] <== 67; eq[2][i] = IsEqual(); eq[2][i].in[0] <== in[i]; - eq[2][i].in[1] <== 32; + eq[2][i].in[1] <== 99; + and[1][i] = AND(); + and[1][i].a <== states[i][0]; + multi_or[0][i] = MultiOR(2); + multi_or[0][i].in[0] <== eq[1][i].out; + multi_or[0][i].in[1] <== eq[2][i].out; + and[1][i].b <== multi_or[0][i].out; and[2][i] = AND(); - and[2][i].a <== states[i][0]; - and[2][i].b <== eq[2][i].out; - states_tmp[i+1][2] <== 0; + and[2][i].a <== states[i][1]; + and[2][i].b <== multi_or[0][i].out; + states_tmp[i+1][2] <== and[2][i].out; eq[3][i] = IsEqual(); eq[3][i].in[0] <== in[i]; eq[3][i].in[1] <== 111; and[3][i] = AND(); - and[3][i].a <== states[i][1]; + and[3][i].a <== states[i][2]; and[3][i].b <== eq[3][i].out; states[i+1][3] <== and[3][i].out; eq[4][i] = IsEqual(); @@ -76,7 +76,7 @@ template InvitationCodeWithPrefixRegex(msg_bytes) { states[i+1][5] <== and[5][i].out; and[6][i] = AND(); and[6][i].a <== states[i][5]; - and[6][i].b <== eq[2][i].out; + and[6][i].b <== eq[0][i].out; states[i+1][6] <== and[6][i].out; eq[6][i] = IsEqual(); eq[6][i].in[0] <== in[i]; @@ -132,7 +132,7 @@ template InvitationCodeWithPrefixRegex(msg_bytes) { multi_or[1][i].in[9] <== eq[15][i].out; multi_or[1][i].in[10] <== eq[16][i].out; multi_or[1][i].in[11] <== eq[17][i].out; - multi_or[1][i].in[12] <== eq[1][i].out; + multi_or[1][i].in[12] <== eq[2][i].out; multi_or[1][i].in[13] <== eq[4][i].out; multi_or[1][i].in[14] <== eq[5][i].out; multi_or[1][i].in[15] <== eq[18][i].out; @@ -150,7 +150,7 @@ template InvitationCodeWithPrefixRegex(msg_bytes) { states[i+1][7] <== multi_or[2][i].out; from_zero_enabled[i] <== MultiNOR(7)([states_tmp[i+1][1], states_tmp[i+1][2], states[i+1][3], states[i+1][4], states[i+1][5], states[i+1][6], states[i+1][7]]); states[i+1][1] <== MultiOR(2)([states_tmp[i+1][1], from_zero_enabled[i] * and[0][i].out]); - states[i+1][2] <== MultiOR(2)([states_tmp[i+1][2], from_zero_enabled[i] * and[2][i].out]); + states[i+1][2] <== MultiOR(2)([states_tmp[i+1][2], from_zero_enabled[i] * and[1][i].out]); state_changed[i].in[0] <== states[i+1][1]; state_changed[i].in[1] <== states[i+1][2]; state_changed[i].in[2] <== states[i+1][3]; @@ -172,13 +172,13 @@ template InvitationCodeWithPrefixRegex(msg_bytes) { is_consecutive[msg_bytes-1-i][1] <== state_changed[msg_bytes-i].out * is_consecutive[msg_bytes-1-i][0]; is_consecutive[msg_bytes-1-i][2] <== ORAnd()([(1 - from_zero_enabled[msg_bytes-i+1]), states[num_bytes-i][7], is_consecutive[msg_bytes-1-i][1]]); } - // substrings calculated: [{(0, 1), (0, 2), (1, 3), (2, 1), (3, 4), (4, 5), (5, 6), (5, 7), (6, 7), (7, 7)}] + // substrings calculated: [{(0, 1), (0, 2), (1, 2), (2, 3), (3, 4), (4, 5), (5, 6), (5, 7), (6, 7), (7, 7)}] signal prev_states0[10][msg_bytes]; signal is_substr0[msg_bytes]; signal is_reveal0[msg_bytes]; signal output reveal0[msg_bytes]; for (var i = 0; i < msg_bytes; i++) { - // the 0-th substring transitions: [(0, 1), (0, 2), (1, 3), (2, 1), (3, 4), (4, 5), (5, 6), (5, 7), (6, 7), (7, 7)] + // the 0-th substring transitions: [(0, 1), (0, 2), (1, 2), (2, 3), (3, 4), (4, 5), (5, 6), (5, 7), (6, 7), (7, 7)] prev_states0[0][i] <== from_zero_enabled[i+1] * states[i+1][0]; prev_states0[1][i] <== from_zero_enabled[i+1] * states[i+1][0]; prev_states0[2][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][1]; @@ -189,7 +189,7 @@ template InvitationCodeWithPrefixRegex(msg_bytes) { prev_states0[7][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][5]; prev_states0[8][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][6]; prev_states0[9][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][7]; - is_substr0[i] <== MultiOR(10)([prev_states0[0][i] * states[i+2][1], prev_states0[1][i] * states[i+2][2], prev_states0[2][i] * states[i+2][3], prev_states0[3][i] * states[i+2][1], prev_states0[4][i] * states[i+2][4], prev_states0[5][i] * states[i+2][5], prev_states0[6][i] * states[i+2][6], prev_states0[7][i] * states[i+2][7], prev_states0[8][i] * states[i+2][7], prev_states0[9][i] * states[i+2][7]]); + is_substr0[i] <== MultiOR(10)([prev_states0[0][i] * states[i+2][1], prev_states0[1][i] * states[i+2][2], prev_states0[2][i] * states[i+2][2], prev_states0[3][i] * states[i+2][3], prev_states0[4][i] * states[i+2][4], prev_states0[5][i] * states[i+2][5], prev_states0[6][i] * states[i+2][6], prev_states0[7][i] * states[i+2][7], prev_states0[8][i] * states[i+2][7], prev_states0[9][i] * states[i+2][7]]); is_reveal0[i] <== MultiAND(3)([out, is_substr0[i], is_consecutive[i][2]]); reveal0[i] <== in[i+1] * is_reveal0[i]; } diff --git a/packages/circom/tests/circuits/negate1_regex.circom b/packages/circom/tests/circuits/negate1_regex.circom index e54b21f..e5c7572 100644 --- a/packages/circom/tests/circuits/negate1_regex.circom +++ b/packages/circom/tests/circuits/negate1_regex.circom @@ -46,29 +46,52 @@ template Negate1Regex(msg_bytes) { and[1][i].b <== eq[1][i].out; states[i+1][2] <== and[1][i].out; lt[0][i] = LessEqThan(8); - lt[0][i].in[0] <== 194; + lt[0][i].in[0] <== 1; lt[0][i].in[1] <== in[i]; lt[1][i] = LessEqThan(8); lt[1][i].in[0] <== in[i]; - lt[1][i].in[1] <== 223; + lt[1][i].in[1] <== 45; and[2][i] = AND(); and[2][i].a <== lt[0][i].out; and[2][i].b <== lt[1][i].out; - and[3][i] = AND(); - and[3][i].a <== states[i][2]; - and[3][i].b <== and[2][i].out; lt[2][i] = LessEqThan(8); - lt[2][i].in[0] <== 160; + lt[2][i].in[0] <== 47; lt[2][i].in[1] <== in[i]; lt[3][i] = LessEqThan(8); lt[3][i].in[0] <== in[i]; - lt[3][i].in[1] <== 191; + lt[3][i].in[1] <== 96; + and[3][i] = AND(); + and[3][i].a <== lt[2][i].out; + and[3][i].b <== lt[3][i].out; + eq[2][i] = IsEqual(); + eq[2][i].in[0] <== in[i]; + eq[2][i].in[1] <== 123; + eq[3][i] = IsEqual(); + eq[3][i].in[0] <== in[i]; + eq[3][i].in[1] <== 124; + eq[4][i] = IsEqual(); + eq[4][i].in[0] <== in[i]; + eq[4][i].in[1] <== 125; + eq[5][i] = IsEqual(); + eq[5][i].in[0] <== in[i]; + eq[5][i].in[1] <== 126; + eq[6][i] = IsEqual(); + eq[6][i].in[0] <== in[i]; + eq[6][i].in[1] <== 127; and[4][i] = AND(); - and[4][i].a <== lt[2][i].out; - and[4][i].b <== lt[3][i].out; + and[4][i].a <== states[i][2]; + multi_or[0][i] = MultiOR(7); + multi_or[0][i].in[0] <== and[2][i].out; + multi_or[0][i].in[1] <== and[3][i].out; + multi_or[0][i].in[2] <== eq[2][i].out; + multi_or[0][i].in[3] <== eq[3][i].out; + multi_or[0][i].in[4] <== eq[4][i].out; + multi_or[0][i].in[5] <== eq[5][i].out; + multi_or[0][i].in[6] <== eq[6][i].out; + and[4][i].b <== multi_or[0][i].out; and[5][i] = AND(); - and[5][i].a <== states[i][4]; - and[5][i].b <== and[4][i].out; + and[5][i].a <== states[i][3]; + and[5][i].b <== multi_or[0][i].out; lt[4][i] = LessEqThan(8); lt[4][i].in[0] <== 128; lt[4][i].in[1] <== in[i]; @@ -79,318 +102,295 @@ template Negate1Regex(msg_bytes) { and[6][i].a <== lt[4][i].out; and[6][i].b <== lt[5][i].out; and[7][i] = AND(); - and[7][i].a <== states[i][5]; + and[7][i].a <== states[i][4]; and[7][i].b <== and[6][i].out; + multi_or[1][i] = MultiOR(3); + multi_or[1][i].in[0] <== and[4][i].out; + multi_or[1][i].in[1] <== and[5][i].out; + multi_or[1][i].in[2] <== and[7][i].out; + states[i+1][3] <== multi_or[1][i].out; lt[6][i] = LessEqThan(8); - lt[6][i].in[0] <== 128; + lt[6][i].in[0] <== 194; lt[6][i].in[1] <== in[i]; lt[7][i] = LessEqThan(8); lt[7][i].in[0] <== in[i]; - lt[7][i].in[1] <== 159; + lt[7][i].in[1] <== 223; and[8][i] = AND(); and[8][i].a <== lt[6][i].out; and[8][i].b <== lt[7][i].out; and[9][i] = AND(); - and[9][i].a <== states[i][6]; + and[9][i].a <== states[i][2]; and[9][i].b <== and[8][i].out; and[10][i] = AND(); - and[10][i].a <== states[i][10]; - and[10][i].b <== and[2][i].out; - multi_or[0][i] = MultiOR(5); - multi_or[0][i].in[0] <== and[3][i].out; - multi_or[0][i].in[1] <== and[5][i].out; - multi_or[0][i].in[2] <== and[7][i].out; - multi_or[0][i].in[3] <== and[9][i].out; - multi_or[0][i].in[4] <== and[10][i].out; - states[i+1][3] <== multi_or[0][i].out; - eq[2][i] = IsEqual(); - eq[2][i].in[0] <== in[i]; - eq[2][i].in[1] <== 224; + and[10][i].a <== states[i][3]; + and[10][i].b <== and[8][i].out; + lt[8][i] = LessEqThan(8); + lt[8][i].in[0] <== 160; + lt[8][i].in[1] <== in[i]; + lt[9][i] = LessEqThan(8); + lt[9][i].in[0] <== in[i]; + lt[9][i].in[1] <== 191; and[11][i] = AND(); - and[11][i].a <== states[i][2]; - and[11][i].b <== eq[2][i].out; + and[11][i].a <== lt[8][i].out; + and[11][i].b <== lt[9][i].out; and[12][i] = AND(); - and[12][i].a <== states[i][10]; - and[12][i].b <== eq[2][i].out; - multi_or[1][i] = MultiOR(2); - multi_or[1][i].in[0] <== and[11][i].out; - multi_or[1][i].in[1] <== and[12][i].out; - states[i+1][4] <== multi_or[1][i].out; - eq[3][i] = IsEqual(); - eq[3][i].in[0] <== in[i]; - eq[3][i].in[1] <== 225; - eq[4][i] = IsEqual(); - eq[4][i].in[0] <== in[i]; - eq[4][i].in[1] <== 226; - eq[5][i] = IsEqual(); - eq[5][i].in[0] <== in[i]; - eq[5][i].in[1] <== 227; - eq[6][i] = IsEqual(); - eq[6][i].in[0] <== in[i]; - eq[6][i].in[1] <== 228; + and[12][i].a <== states[i][5]; + and[12][i].b <== and[11][i].out; + and[13][i] = AND(); + and[13][i].a <== states[i][6]; + and[13][i].b <== and[6][i].out; + lt[10][i] = LessEqThan(8); + lt[10][i].in[0] <== 128; + lt[10][i].in[1] <== in[i]; + lt[11][i] = LessEqThan(8); + lt[11][i].in[0] <== in[i]; + lt[11][i].in[1] <== 159; + and[14][i] = AND(); + and[14][i].a <== lt[10][i].out; + and[14][i].b <== lt[11][i].out; + and[15][i] = AND(); + and[15][i].a <== states[i][7]; + and[15][i].b <== and[14][i].out; + multi_or[2][i] = MultiOR(5); + multi_or[2][i].in[0] <== and[9][i].out; + multi_or[2][i].in[1] <== and[10][i].out; + multi_or[2][i].in[2] <== and[12][i].out; + multi_or[2][i].in[3] <== and[13][i].out; + multi_or[2][i].in[4] <== and[15][i].out; + states[i+1][4] <== multi_or[2][i].out; eq[7][i] = IsEqual(); eq[7][i].in[0] <== in[i]; - eq[7][i].in[1] <== 229; + eq[7][i].in[1] <== 224; + and[16][i] = AND(); + and[16][i].a <== states[i][2]; + and[16][i].b <== eq[7][i].out; + and[17][i] = AND(); + and[17][i].a <== states[i][3]; + and[17][i].b <== eq[7][i].out; + multi_or[3][i] = MultiOR(2); + multi_or[3][i].in[0] <== and[16][i].out; + multi_or[3][i].in[1] <== and[17][i].out; + states[i+1][5] <== multi_or[3][i].out; eq[8][i] = IsEqual(); eq[8][i].in[0] <== in[i]; - eq[8][i].in[1] <== 230; + eq[8][i].in[1] <== 225; eq[9][i] = IsEqual(); eq[9][i].in[0] <== in[i]; - eq[9][i].in[1] <== 231; + eq[9][i].in[1] <== 226; eq[10][i] = IsEqual(); eq[10][i].in[0] <== in[i]; - eq[10][i].in[1] <== 232; + eq[10][i].in[1] <== 227; eq[11][i] = IsEqual(); eq[11][i].in[0] <== in[i]; - eq[11][i].in[1] <== 233; + eq[11][i].in[1] <== 228; eq[12][i] = IsEqual(); eq[12][i].in[0] <== in[i]; - eq[12][i].in[1] <== 234; + eq[12][i].in[1] <== 229; eq[13][i] = IsEqual(); eq[13][i].in[0] <== in[i]; - eq[13][i].in[1] <== 235; + eq[13][i].in[1] <== 230; eq[14][i] = IsEqual(); eq[14][i].in[0] <== in[i]; - eq[14][i].in[1] <== 236; + eq[14][i].in[1] <== 231; eq[15][i] = IsEqual(); eq[15][i].in[0] <== in[i]; - eq[15][i].in[1] <== 238; + eq[15][i].in[1] <== 232; eq[16][i] = IsEqual(); eq[16][i].in[0] <== in[i]; - eq[16][i].in[1] <== 239; - and[13][i] = AND(); - and[13][i].a <== states[i][2]; - multi_or[2][i] = MultiOR(14); - multi_or[2][i].in[0] <== eq[3][i].out; - multi_or[2][i].in[1] <== eq[4][i].out; - multi_or[2][i].in[2] <== eq[5][i].out; - multi_or[2][i].in[3] <== eq[6][i].out; - multi_or[2][i].in[4] <== eq[7][i].out; - multi_or[2][i].in[5] <== eq[8][i].out; - multi_or[2][i].in[6] <== eq[9][i].out; - multi_or[2][i].in[7] <== eq[10][i].out; - multi_or[2][i].in[8] <== eq[11][i].out; - multi_or[2][i].in[9] <== eq[12][i].out; - multi_or[2][i].in[10] <== eq[13][i].out; - multi_or[2][i].in[11] <== eq[14][i].out; - multi_or[2][i].in[12] <== eq[15][i].out; - multi_or[2][i].in[13] <== eq[16][i].out; - and[13][i].b <== multi_or[2][i].out; - lt[8][i] = LessEqThan(8); - lt[8][i].in[0] <== 144; - lt[8][i].in[1] <== in[i]; - lt[9][i] = LessEqThan(8); - lt[9][i].in[0] <== in[i]; - lt[9][i].in[1] <== 191; - and[14][i] = AND(); - and[14][i].a <== lt[8][i].out; - and[14][i].b <== lt[9][i].out; - and[15][i] = AND(); - and[15][i].a <== states[i][7]; - and[15][i].b <== and[14][i].out; - and[16][i] = AND(); - and[16][i].a <== states[i][8]; - and[16][i].b <== and[6][i].out; + eq[16][i].in[1] <== 233; eq[17][i] = IsEqual(); eq[17][i].in[0] <== in[i]; - eq[17][i].in[1] <== 128; + eq[17][i].in[1] <== 234; eq[18][i] = IsEqual(); eq[18][i].in[0] <== in[i]; - eq[18][i].in[1] <== 129; + eq[18][i].in[1] <== 235; eq[19][i] = IsEqual(); eq[19][i].in[0] <== in[i]; - eq[19][i].in[1] <== 130; + eq[19][i].in[1] <== 236; eq[20][i] = IsEqual(); eq[20][i].in[0] <== in[i]; - eq[20][i].in[1] <== 131; + eq[20][i].in[1] <== 238; eq[21][i] = IsEqual(); eq[21][i].in[0] <== in[i]; - eq[21][i].in[1] <== 132; + eq[21][i].in[1] <== 239; + and[18][i] = AND(); + and[18][i].a <== states[i][2]; + multi_or[4][i] = MultiOR(14); + multi_or[4][i].in[0] <== eq[8][i].out; + multi_or[4][i].in[1] <== eq[9][i].out; + multi_or[4][i].in[2] <== eq[10][i].out; + multi_or[4][i].in[3] <== eq[11][i].out; + multi_or[4][i].in[4] <== eq[12][i].out; + multi_or[4][i].in[5] <== eq[13][i].out; + multi_or[4][i].in[6] <== eq[14][i].out; + multi_or[4][i].in[7] <== eq[15][i].out; + multi_or[4][i].in[8] <== eq[16][i].out; + multi_or[4][i].in[9] <== eq[17][i].out; + multi_or[4][i].in[10] <== eq[18][i].out; + multi_or[4][i].in[11] <== eq[19][i].out; + multi_or[4][i].in[12] <== eq[20][i].out; + multi_or[4][i].in[13] <== eq[21][i].out; + and[18][i].b <== multi_or[4][i].out; + and[19][i] = AND(); + and[19][i].a <== states[i][3]; + and[19][i].b <== multi_or[4][i].out; + lt[12][i] = LessEqThan(8); + lt[12][i].in[0] <== 144; + lt[12][i].in[1] <== in[i]; + lt[13][i] = LessEqThan(8); + lt[13][i].in[0] <== in[i]; + lt[13][i].in[1] <== 191; + and[20][i] = AND(); + and[20][i].a <== lt[12][i].out; + and[20][i].b <== lt[13][i].out; + and[21][i] = AND(); + and[21][i].a <== states[i][8]; + and[21][i].b <== and[20][i].out; + and[22][i] = AND(); + and[22][i].a <== states[i][9]; + and[22][i].b <== and[6][i].out; eq[22][i] = IsEqual(); eq[22][i].in[0] <== in[i]; - eq[22][i].in[1] <== 133; + eq[22][i].in[1] <== 128; eq[23][i] = IsEqual(); eq[23][i].in[0] <== in[i]; - eq[23][i].in[1] <== 134; + eq[23][i].in[1] <== 129; eq[24][i] = IsEqual(); eq[24][i].in[0] <== in[i]; - eq[24][i].in[1] <== 135; + eq[24][i].in[1] <== 130; eq[25][i] = IsEqual(); eq[25][i].in[0] <== in[i]; - eq[25][i].in[1] <== 136; + eq[25][i].in[1] <== 131; eq[26][i] = IsEqual(); eq[26][i].in[0] <== in[i]; - eq[26][i].in[1] <== 137; + eq[26][i].in[1] <== 132; eq[27][i] = IsEqual(); eq[27][i].in[0] <== in[i]; - eq[27][i].in[1] <== 138; + eq[27][i].in[1] <== 133; eq[28][i] = IsEqual(); eq[28][i].in[0] <== in[i]; - eq[28][i].in[1] <== 139; + eq[28][i].in[1] <== 134; eq[29][i] = IsEqual(); eq[29][i].in[0] <== in[i]; - eq[29][i].in[1] <== 140; + eq[29][i].in[1] <== 135; eq[30][i] = IsEqual(); eq[30][i].in[0] <== in[i]; - eq[30][i].in[1] <== 141; + eq[30][i].in[1] <== 136; eq[31][i] = IsEqual(); eq[31][i].in[0] <== in[i]; - eq[31][i].in[1] <== 142; + eq[31][i].in[1] <== 137; eq[32][i] = IsEqual(); eq[32][i].in[0] <== in[i]; - eq[32][i].in[1] <== 143; - and[17][i] = AND(); - and[17][i].a <== states[i][9]; - multi_or[3][i] = MultiOR(16); - multi_or[3][i].in[0] <== eq[17][i].out; - multi_or[3][i].in[1] <== eq[18][i].out; - multi_or[3][i].in[2] <== eq[19][i].out; - multi_or[3][i].in[3] <== eq[20][i].out; - multi_or[3][i].in[4] <== eq[21][i].out; - multi_or[3][i].in[5] <== eq[22][i].out; - multi_or[3][i].in[6] <== eq[23][i].out; - multi_or[3][i].in[7] <== eq[24][i].out; - multi_or[3][i].in[8] <== eq[25][i].out; - multi_or[3][i].in[9] <== eq[26][i].out; - multi_or[3][i].in[10] <== eq[27][i].out; - multi_or[3][i].in[11] <== eq[28][i].out; - multi_or[3][i].in[12] <== eq[29][i].out; - multi_or[3][i].in[13] <== eq[30][i].out; - multi_or[3][i].in[14] <== eq[31][i].out; - multi_or[3][i].in[15] <== eq[32][i].out; - and[17][i].b <== multi_or[3][i].out; - and[18][i] = AND(); - and[18][i].a <== states[i][10]; - and[18][i].b <== multi_or[2][i].out; - multi_or[4][i] = MultiOR(5); - multi_or[4][i].in[0] <== and[13][i].out; - multi_or[4][i].in[1] <== and[15][i].out; - multi_or[4][i].in[2] <== and[16][i].out; - multi_or[4][i].in[3] <== and[17][i].out; - multi_or[4][i].in[4] <== and[18][i].out; - states[i+1][5] <== multi_or[4][i].out; + eq[32][i].in[1] <== 138; eq[33][i] = IsEqual(); eq[33][i].in[0] <== in[i]; - eq[33][i].in[1] <== 237; - and[19][i] = AND(); - and[19][i].a <== states[i][2]; - and[19][i].b <== eq[33][i].out; - and[20][i] = AND(); - and[20][i].a <== states[i][10]; - and[20][i].b <== eq[33][i].out; - multi_or[5][i] = MultiOR(2); - multi_or[5][i].in[0] <== and[19][i].out; - multi_or[5][i].in[1] <== and[20][i].out; - states[i+1][6] <== multi_or[5][i].out; + eq[33][i].in[1] <== 139; eq[34][i] = IsEqual(); eq[34][i].in[0] <== in[i]; - eq[34][i].in[1] <== 240; - and[21][i] = AND(); - and[21][i].a <== states[i][2]; - and[21][i].b <== eq[34][i].out; - and[22][i] = AND(); - and[22][i].a <== states[i][10]; - and[22][i].b <== eq[34][i].out; - multi_or[6][i] = MultiOR(2); - multi_or[6][i].in[0] <== and[21][i].out; - multi_or[6][i].in[1] <== and[22][i].out; - states[i+1][7] <== multi_or[6][i].out; + eq[34][i].in[1] <== 140; eq[35][i] = IsEqual(); eq[35][i].in[0] <== in[i]; - eq[35][i].in[1] <== 241; + eq[35][i].in[1] <== 141; eq[36][i] = IsEqual(); eq[36][i].in[0] <== in[i]; - eq[36][i].in[1] <== 242; + eq[36][i].in[1] <== 142; eq[37][i] = IsEqual(); eq[37][i].in[0] <== in[i]; - eq[37][i].in[1] <== 243; + eq[37][i].in[1] <== 143; and[23][i] = AND(); - and[23][i].a <== states[i][2]; - multi_or[7][i] = MultiOR(3); - multi_or[7][i].in[0] <== eq[35][i].out; - multi_or[7][i].in[1] <== eq[36][i].out; - multi_or[7][i].in[2] <== eq[37][i].out; - and[23][i].b <== multi_or[7][i].out; - and[24][i] = AND(); - and[24][i].a <== states[i][10]; - and[24][i].b <== multi_or[7][i].out; - multi_or[8][i] = MultiOR(2); - multi_or[8][i].in[0] <== and[23][i].out; - multi_or[8][i].in[1] <== and[24][i].out; - states[i+1][8] <== multi_or[8][i].out; + and[23][i].a <== states[i][10]; + multi_or[5][i] = MultiOR(16); + multi_or[5][i].in[0] <== eq[22][i].out; + multi_or[5][i].in[1] <== eq[23][i].out; + multi_or[5][i].in[2] <== eq[24][i].out; + multi_or[5][i].in[3] <== eq[25][i].out; + multi_or[5][i].in[4] <== eq[26][i].out; + multi_or[5][i].in[5] <== eq[27][i].out; + multi_or[5][i].in[6] <== eq[28][i].out; + multi_or[5][i].in[7] <== eq[29][i].out; + multi_or[5][i].in[8] <== eq[30][i].out; + multi_or[5][i].in[9] <== eq[31][i].out; + multi_or[5][i].in[10] <== eq[32][i].out; + multi_or[5][i].in[11] <== eq[33][i].out; + multi_or[5][i].in[12] <== eq[34][i].out; + multi_or[5][i].in[13] <== eq[35][i].out; + multi_or[5][i].in[14] <== eq[36][i].out; + multi_or[5][i].in[15] <== eq[37][i].out; + and[23][i].b <== multi_or[5][i].out; + multi_or[6][i] = MultiOR(5); + multi_or[6][i].in[0] <== and[18][i].out; + multi_or[6][i].in[1] <== and[19][i].out; + multi_or[6][i].in[2] <== and[21][i].out; + multi_or[6][i].in[3] <== and[22][i].out; + multi_or[6][i].in[4] <== and[23][i].out; + states[i+1][6] <== multi_or[6][i].out; eq[38][i] = IsEqual(); eq[38][i].in[0] <== in[i]; - eq[38][i].in[1] <== 244; + eq[38][i].in[1] <== 237; + and[24][i] = AND(); + and[24][i].a <== states[i][2]; + and[24][i].b <== eq[38][i].out; and[25][i] = AND(); - and[25][i].a <== states[i][2]; + and[25][i].a <== states[i][3]; and[25][i].b <== eq[38][i].out; - and[26][i] = AND(); - and[26][i].a <== states[i][10]; - and[26][i].b <== eq[38][i].out; - multi_or[9][i] = MultiOR(2); - multi_or[9][i].in[0] <== and[25][i].out; - multi_or[9][i].in[1] <== and[26][i].out; - states[i+1][9] <== multi_or[9][i].out; - lt[10][i] = LessEqThan(8); - lt[10][i].in[0] <== 1; - lt[10][i].in[1] <== in[i]; - lt[11][i] = LessEqThan(8); - lt[11][i].in[0] <== in[i]; - lt[11][i].in[1] <== 45; - and[27][i] = AND(); - and[27][i].a <== lt[10][i].out; - and[27][i].b <== lt[11][i].out; - lt[12][i] = LessEqThan(8); - lt[12][i].in[0] <== 47; - lt[12][i].in[1] <== in[i]; - lt[13][i] = LessEqThan(8); - lt[13][i].in[0] <== in[i]; - lt[13][i].in[1] <== 96; - and[28][i] = AND(); - and[28][i].a <== lt[12][i].out; - and[28][i].b <== lt[13][i].out; + multi_or[7][i] = MultiOR(2); + multi_or[7][i].in[0] <== and[24][i].out; + multi_or[7][i].in[1] <== and[25][i].out; + states[i+1][7] <== multi_or[7][i].out; eq[39][i] = IsEqual(); eq[39][i].in[0] <== in[i]; - eq[39][i].in[1] <== 123; + eq[39][i].in[1] <== 240; + and[26][i] = AND(); + and[26][i].a <== states[i][2]; + and[26][i].b <== eq[39][i].out; + and[27][i] = AND(); + and[27][i].a <== states[i][3]; + and[27][i].b <== eq[39][i].out; + multi_or[8][i] = MultiOR(2); + multi_or[8][i].in[0] <== and[26][i].out; + multi_or[8][i].in[1] <== and[27][i].out; + states[i+1][8] <== multi_or[8][i].out; eq[40][i] = IsEqual(); eq[40][i].in[0] <== in[i]; - eq[40][i].in[1] <== 124; + eq[40][i].in[1] <== 241; eq[41][i] = IsEqual(); eq[41][i].in[0] <== in[i]; - eq[41][i].in[1] <== 125; + eq[41][i].in[1] <== 242; eq[42][i] = IsEqual(); eq[42][i].in[0] <== in[i]; - eq[42][i].in[1] <== 126; + eq[42][i].in[1] <== 243; + and[28][i] = AND(); + and[28][i].a <== states[i][2]; + multi_or[9][i] = MultiOR(3); + multi_or[9][i].in[0] <== eq[40][i].out; + multi_or[9][i].in[1] <== eq[41][i].out; + multi_or[9][i].in[2] <== eq[42][i].out; + and[28][i].b <== multi_or[9][i].out; + and[29][i] = AND(); + and[29][i].a <== states[i][3]; + and[29][i].b <== multi_or[9][i].out; + multi_or[10][i] = MultiOR(2); + multi_or[10][i].in[0] <== and[28][i].out; + multi_or[10][i].in[1] <== and[29][i].out; + states[i+1][9] <== multi_or[10][i].out; eq[43][i] = IsEqual(); eq[43][i].in[0] <== in[i]; - eq[43][i].in[1] <== 127; - and[29][i] = AND(); - and[29][i].a <== states[i][2]; - multi_or[10][i] = MultiOR(7); - multi_or[10][i].in[0] <== and[27][i].out; - multi_or[10][i].in[1] <== and[28][i].out; - multi_or[10][i].in[2] <== eq[39][i].out; - multi_or[10][i].in[3] <== eq[40][i].out; - multi_or[10][i].in[4] <== eq[41][i].out; - multi_or[10][i].in[5] <== eq[42][i].out; - multi_or[10][i].in[6] <== eq[43][i].out; - and[29][i].b <== multi_or[10][i].out; + eq[43][i].in[1] <== 244; and[30][i] = AND(); - and[30][i].a <== states[i][3]; - and[30][i].b <== and[6][i].out; + and[30][i].a <== states[i][2]; + and[30][i].b <== eq[43][i].out; and[31][i] = AND(); - and[31][i].a <== states[i][10]; - and[31][i].b <== multi_or[10][i].out; - multi_or[11][i] = MultiOR(3); - multi_or[11][i].in[0] <== and[29][i].out; - multi_or[11][i].in[1] <== and[30][i].out; - multi_or[11][i].in[2] <== and[31][i].out; + and[31][i].a <== states[i][3]; + and[31][i].b <== eq[43][i].out; + multi_or[11][i] = MultiOR(2); + multi_or[11][i].in[0] <== and[30][i].out; + multi_or[11][i].in[1] <== and[31][i].out; states[i+1][10] <== multi_or[11][i].out; eq[44][i] = IsEqual(); eq[44][i].in[0] <== in[i]; eq[44][i].in[1] <== 46; and[32][i] = AND(); - and[32][i].a <== states[i][10]; + and[32][i].a <== states[i][3]; and[32][i].b <== eq[44][i].out; states[i+1][11] <== and[32][i].out; from_zero_enabled[i] <== MultiNOR(11)([states_tmp[i+1][1], states[i+1][2], states[i+1][3], states[i+1][4], states[i+1][5], states[i+1][6], states[i+1][7], states[i+1][8], states[i+1][9], states[i+1][10], states[i+1][11]]); @@ -420,13 +420,13 @@ template Negate1Regex(msg_bytes) { is_consecutive[msg_bytes-1-i][1] <== state_changed[msg_bytes-i].out * is_consecutive[msg_bytes-1-i][0]; is_consecutive[msg_bytes-1-i][2] <== ORAnd()([(1 - from_zero_enabled[msg_bytes-i+1]), states[num_bytes-i][11], is_consecutive[msg_bytes-1-i][1]]); } - // substrings calculated: [{(2, 3), (2, 4), (2, 5), (2, 6), (2, 7), (2, 8), (2, 9), (2, 10), (3, 10), (4, 3), (5, 3), (6, 3), (7, 5), (8, 5), (9, 5), (10, 3), (10, 4), (10, 5), (10, 6), (10, 7), (10, 8), (10, 9), (10, 10)}] + // substrings calculated: [{(2, 3), (2, 4), (2, 5), (2, 6), (2, 7), (2, 8), (2, 9), (2, 10), (3, 3), (3, 4), (3, 5), (3, 6), (3, 7), (3, 8), (3, 9), (3, 10), (4, 3), (5, 4), (6, 4), (7, 4), (8, 6), (9, 6), (10, 6)}] signal prev_states0[23][msg_bytes]; signal is_substr0[msg_bytes]; signal is_reveal0[msg_bytes]; signal output reveal0[msg_bytes]; for (var i = 0; i < msg_bytes; i++) { - // the 0-th substring transitions: [(2, 3), (2, 4), (2, 5), (2, 6), (2, 7), (2, 8), (2, 9), (2, 10), (3, 10), (4, 3), (5, 3), (6, 3), (7, 5), (8, 5), (9, 5), (10, 3), (10, 4), (10, 5), (10, 6), (10, 7), (10, 8), (10, 9), (10, 10)] + // the 0-th substring transitions: [(2, 3), (2, 4), (2, 5), (2, 6), (2, 7), (2, 8), (2, 9), (2, 10), (3, 3), (3, 4), (3, 5), (3, 6), (3, 7), (3, 8), (3, 9), (3, 10), (4, 3), (5, 4), (6, 4), (7, 4), (8, 6), (9, 6), (10, 6)] prev_states0[0][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][2]; prev_states0[1][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][2]; prev_states0[2][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][2]; @@ -436,21 +436,21 @@ template Negate1Regex(msg_bytes) { prev_states0[6][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][2]; prev_states0[7][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][2]; prev_states0[8][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][3]; - prev_states0[9][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][4]; - prev_states0[10][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][5]; - prev_states0[11][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][6]; - prev_states0[12][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][7]; - prev_states0[13][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][8]; - prev_states0[14][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][9]; - prev_states0[15][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][10]; - prev_states0[16][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][10]; - prev_states0[17][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][10]; - prev_states0[18][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][10]; - prev_states0[19][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][10]; - prev_states0[20][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][10]; - prev_states0[21][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][10]; + prev_states0[9][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][3]; + prev_states0[10][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][3]; + prev_states0[11][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][3]; + prev_states0[12][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][3]; + prev_states0[13][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][3]; + prev_states0[14][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][3]; + prev_states0[15][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][3]; + prev_states0[16][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][4]; + prev_states0[17][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][5]; + prev_states0[18][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][6]; + prev_states0[19][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][7]; + prev_states0[20][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][8]; + prev_states0[21][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][9]; prev_states0[22][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][10]; - is_substr0[i] <== MultiOR(23)([prev_states0[0][i] * states[i+2][3], prev_states0[1][i] * states[i+2][4], prev_states0[2][i] * states[i+2][5], prev_states0[3][i] * states[i+2][6], prev_states0[4][i] * states[i+2][7], prev_states0[5][i] * states[i+2][8], prev_states0[6][i] * states[i+2][9], prev_states0[7][i] * states[i+2][10], prev_states0[8][i] * states[i+2][10], prev_states0[9][i] * states[i+2][3], prev_states0[10][i] * states[i+2][3], prev_states0[11][i] * states[i+2][3], prev_states0[12][i] * states[i+2][5], prev_states0[13][i] * states[i+2][5], prev_states0[14][i] * states[i+2][5], prev_states0[15][i] * states[i+2][3], prev_states0[16][i] * states[i+2][4], prev_states0[17][i] * states[i+2][5], prev_states0[18][i] * states[i+2][6], prev_states0[19][i] * states[i+2][7], prev_states0[20][i] * states[i+2][8], prev_states0[21][i] * states[i+2][9], prev_states0[22][i] * states[i+2][10]]); + is_substr0[i] <== MultiOR(23)([prev_states0[0][i] * states[i+2][3], prev_states0[1][i] * states[i+2][4], prev_states0[2][i] * states[i+2][5], prev_states0[3][i] * states[i+2][6], prev_states0[4][i] * states[i+2][7], prev_states0[5][i] * states[i+2][8], prev_states0[6][i] * states[i+2][9], prev_states0[7][i] * states[i+2][10], prev_states0[8][i] * states[i+2][3], prev_states0[9][i] * states[i+2][4], prev_states0[10][i] * states[i+2][5], prev_states0[11][i] * states[i+2][6], prev_states0[12][i] * states[i+2][7], prev_states0[13][i] * states[i+2][8], prev_states0[14][i] * states[i+2][9], prev_states0[15][i] * states[i+2][10], prev_states0[16][i] * states[i+2][3], prev_states0[17][i] * states[i+2][4], prev_states0[18][i] * states[i+2][4], prev_states0[19][i] * states[i+2][4], prev_states0[20][i] * states[i+2][6], prev_states0[21][i] * states[i+2][6], prev_states0[22][i] * states[i+2][6]]); is_reveal0[i] <== MultiAND(3)([out, is_substr0[i], is_consecutive[i][2]]); reveal0[i] <== in[i+1] * is_reveal0[i]; } diff --git a/packages/circom/tests/circuits/negate2_regex.circom b/packages/circom/tests/circuits/negate2_regex.circom index ecfefec..1ed57f6 100644 --- a/packages/circom/tests/circuits/negate2_regex.circom +++ b/packages/circom/tests/circuits/negate2_regex.circom @@ -32,65 +32,93 @@ template Negate2Regex(msg_bytes) { state_changed[i] = MultiOR(8); states[i][0] <== 1; lt[0][i] = LessEqThan(8); - lt[0][i].in[0] <== 194; + lt[0][i].in[0] <== 1; lt[0][i].in[1] <== in[i]; lt[1][i] = LessEqThan(8); lt[1][i].in[0] <== in[i]; - lt[1][i].in[1] <== 223; + lt[1][i].in[1] <== 96; and[0][i] = AND(); and[0][i].a <== lt[0][i].out; and[0][i].b <== lt[1][i].out; - and[1][i] = AND(); - and[1][i].a <== states[i][0]; - and[1][i].b <== and[0][i].out; lt[2][i] = LessEqThan(8); - lt[2][i].in[0] <== 160; + lt[2][i].in[0] <== 99; lt[2][i].in[1] <== in[i]; lt[3][i] = LessEqThan(8); lt[3][i].in[0] <== in[i]; - lt[3][i].in[1] <== 191; + lt[3][i].in[1] <== 127; + and[1][i] = AND(); + and[1][i].a <== lt[2][i].out; + and[1][i].b <== lt[3][i].out; and[2][i] = AND(); - and[2][i].a <== lt[2][i].out; - and[2][i].b <== lt[3][i].out; - and[3][i] = AND(); - and[3][i].a <== states[i][2]; - and[3][i].b <== and[2][i].out; + and[2][i].a <== states[i][0]; + multi_or[0][i] = MultiOR(2); + multi_or[0][i].in[0] <== and[0][i].out; + multi_or[0][i].in[1] <== and[1][i].out; + and[2][i].b <== multi_or[0][i].out; lt[4][i] = LessEqThan(8); lt[4][i].in[0] <== 128; lt[4][i].in[1] <== in[i]; lt[5][i] = LessEqThan(8); lt[5][i].in[0] <== in[i]; lt[5][i].in[1] <== 191; + and[3][i] = AND(); + and[3][i].a <== lt[4][i].out; + and[3][i].b <== lt[5][i].out; and[4][i] = AND(); - and[4][i].a <== lt[4][i].out; - and[4][i].b <== lt[5][i].out; - and[5][i] = AND(); - and[5][i].a <== states[i][3]; - and[5][i].b <== and[4][i].out; + and[4][i].a <== states[i][2]; + and[4][i].b <== and[3][i].out; + states_tmp[i+1][1] <== and[4][i].out; lt[6][i] = LessEqThan(8); - lt[6][i].in[0] <== 128; + lt[6][i].in[0] <== 194; lt[6][i].in[1] <== in[i]; lt[7][i] = LessEqThan(8); lt[7][i].in[0] <== in[i]; - lt[7][i].in[1] <== 159; + lt[7][i].in[1] <== 223; + and[5][i] = AND(); + and[5][i].a <== lt[6][i].out; + and[5][i].b <== lt[7][i].out; and[6][i] = AND(); - and[6][i].a <== lt[6][i].out; - and[6][i].b <== lt[7][i].out; + and[6][i].a <== states[i][0]; + and[6][i].b <== and[5][i].out; + lt[8][i] = LessEqThan(8); + lt[8][i].in[0] <== 160; + lt[8][i].in[1] <== in[i]; + lt[9][i] = LessEqThan(8); + lt[9][i].in[0] <== in[i]; + lt[9][i].in[1] <== 191; and[7][i] = AND(); - and[7][i].a <== states[i][4]; - and[7][i].b <== and[6][i].out; - multi_or[0][i] = MultiOR(3); - multi_or[0][i].in[0] <== and[3][i].out; - multi_or[0][i].in[1] <== and[5][i].out; - multi_or[0][i].in[2] <== and[7][i].out; - states_tmp[i+1][1] <== multi_or[0][i].out; + and[7][i].a <== lt[8][i].out; + and[7][i].b <== lt[9][i].out; + and[8][i] = AND(); + and[8][i].a <== states[i][3]; + and[8][i].b <== and[7][i].out; + and[9][i] = AND(); + and[9][i].a <== states[i][4]; + and[9][i].b <== and[3][i].out; + lt[10][i] = LessEqThan(8); + lt[10][i].in[0] <== 128; + lt[10][i].in[1] <== in[i]; + lt[11][i] = LessEqThan(8); + lt[11][i].in[0] <== in[i]; + lt[11][i].in[1] <== 159; + and[10][i] = AND(); + and[10][i].a <== lt[10][i].out; + and[10][i].b <== lt[11][i].out; + and[11][i] = AND(); + and[11][i].a <== states[i][5]; + and[11][i].b <== and[10][i].out; + multi_or[1][i] = MultiOR(3); + multi_or[1][i].in[0] <== and[8][i].out; + multi_or[1][i].in[1] <== and[9][i].out; + multi_or[1][i].in[2] <== and[11][i].out; + states_tmp[i+1][2] <== multi_or[1][i].out; eq[0][i] = IsEqual(); eq[0][i].in[0] <== in[i]; eq[0][i].in[1] <== 224; - and[8][i] = AND(); - and[8][i].a <== states[i][0]; - and[8][i].b <== eq[0][i].out; - states_tmp[i+1][2] <== 0; + and[12][i] = AND(); + and[12][i].a <== states[i][0]; + and[12][i].b <== eq[0][i].out; + states_tmp[i+1][3] <== 0; eq[1][i] = IsEqual(); eq[1][i].in[0] <== in[i]; eq[1][i].in[1] <== 225; @@ -133,39 +161,39 @@ template Negate2Regex(msg_bytes) { eq[14][i] = IsEqual(); eq[14][i].in[0] <== in[i]; eq[14][i].in[1] <== 239; - and[9][i] = AND(); - and[9][i].a <== states[i][0]; - multi_or[1][i] = MultiOR(14); - multi_or[1][i].in[0] <== eq[1][i].out; - multi_or[1][i].in[1] <== eq[2][i].out; - multi_or[1][i].in[2] <== eq[3][i].out; - multi_or[1][i].in[3] <== eq[4][i].out; - multi_or[1][i].in[4] <== eq[5][i].out; - multi_or[1][i].in[5] <== eq[6][i].out; - multi_or[1][i].in[6] <== eq[7][i].out; - multi_or[1][i].in[7] <== eq[8][i].out; - multi_or[1][i].in[8] <== eq[9][i].out; - multi_or[1][i].in[9] <== eq[10][i].out; - multi_or[1][i].in[10] <== eq[11][i].out; - multi_or[1][i].in[11] <== eq[12][i].out; - multi_or[1][i].in[12] <== eq[13][i].out; - multi_or[1][i].in[13] <== eq[14][i].out; - and[9][i].b <== multi_or[1][i].out; - lt[8][i] = LessEqThan(8); - lt[8][i].in[0] <== 144; - lt[8][i].in[1] <== in[i]; - lt[9][i] = LessEqThan(8); - lt[9][i].in[0] <== in[i]; - lt[9][i].in[1] <== 191; - and[10][i] = AND(); - and[10][i].a <== lt[8][i].out; - and[10][i].b <== lt[9][i].out; - and[11][i] = AND(); - and[11][i].a <== states[i][5]; - and[11][i].b <== and[10][i].out; - and[12][i] = AND(); - and[12][i].a <== states[i][6]; - and[12][i].b <== and[4][i].out; + and[13][i] = AND(); + and[13][i].a <== states[i][0]; + multi_or[2][i] = MultiOR(14); + multi_or[2][i].in[0] <== eq[1][i].out; + multi_or[2][i].in[1] <== eq[2][i].out; + multi_or[2][i].in[2] <== eq[3][i].out; + multi_or[2][i].in[3] <== eq[4][i].out; + multi_or[2][i].in[4] <== eq[5][i].out; + multi_or[2][i].in[5] <== eq[6][i].out; + multi_or[2][i].in[6] <== eq[7][i].out; + multi_or[2][i].in[7] <== eq[8][i].out; + multi_or[2][i].in[8] <== eq[9][i].out; + multi_or[2][i].in[9] <== eq[10][i].out; + multi_or[2][i].in[10] <== eq[11][i].out; + multi_or[2][i].in[11] <== eq[12][i].out; + multi_or[2][i].in[12] <== eq[13][i].out; + multi_or[2][i].in[13] <== eq[14][i].out; + and[13][i].b <== multi_or[2][i].out; + lt[12][i] = LessEqThan(8); + lt[12][i].in[0] <== 144; + lt[12][i].in[1] <== in[i]; + lt[13][i] = LessEqThan(8); + lt[13][i].in[0] <== in[i]; + lt[13][i].in[1] <== 191; + and[14][i] = AND(); + and[14][i].a <== lt[12][i].out; + and[14][i].b <== lt[13][i].out; + and[15][i] = AND(); + and[15][i].a <== states[i][6]; + and[15][i].b <== and[14][i].out; + and[16][i] = AND(); + and[16][i].a <== states[i][7]; + and[16][i].b <== and[3][i].out; eq[15][i] = IsEqual(); eq[15][i].in[0] <== in[i]; eq[15][i].in[1] <== 128; @@ -214,45 +242,45 @@ template Negate2Regex(msg_bytes) { eq[30][i] = IsEqual(); eq[30][i].in[0] <== in[i]; eq[30][i].in[1] <== 143; - and[13][i] = AND(); - and[13][i].a <== states[i][7]; - multi_or[2][i] = MultiOR(16); - multi_or[2][i].in[0] <== eq[15][i].out; - multi_or[2][i].in[1] <== eq[16][i].out; - multi_or[2][i].in[2] <== eq[17][i].out; - multi_or[2][i].in[3] <== eq[18][i].out; - multi_or[2][i].in[4] <== eq[19][i].out; - multi_or[2][i].in[5] <== eq[20][i].out; - multi_or[2][i].in[6] <== eq[21][i].out; - multi_or[2][i].in[7] <== eq[22][i].out; - multi_or[2][i].in[8] <== eq[23][i].out; - multi_or[2][i].in[9] <== eq[24][i].out; - multi_or[2][i].in[10] <== eq[25][i].out; - multi_or[2][i].in[11] <== eq[26][i].out; - multi_or[2][i].in[12] <== eq[27][i].out; - multi_or[2][i].in[13] <== eq[28][i].out; - multi_or[2][i].in[14] <== eq[29][i].out; - multi_or[2][i].in[15] <== eq[30][i].out; - and[13][i].b <== multi_or[2][i].out; - multi_or[3][i] = MultiOR(3); - multi_or[3][i].in[0] <== and[11][i].out; - multi_or[3][i].in[1] <== and[12][i].out; - multi_or[3][i].in[2] <== and[13][i].out; - states_tmp[i+1][3] <== multi_or[3][i].out; + and[17][i] = AND(); + and[17][i].a <== states[i][8]; + multi_or[3][i] = MultiOR(16); + multi_or[3][i].in[0] <== eq[15][i].out; + multi_or[3][i].in[1] <== eq[16][i].out; + multi_or[3][i].in[2] <== eq[17][i].out; + multi_or[3][i].in[3] <== eq[18][i].out; + multi_or[3][i].in[4] <== eq[19][i].out; + multi_or[3][i].in[5] <== eq[20][i].out; + multi_or[3][i].in[6] <== eq[21][i].out; + multi_or[3][i].in[7] <== eq[22][i].out; + multi_or[3][i].in[8] <== eq[23][i].out; + multi_or[3][i].in[9] <== eq[24][i].out; + multi_or[3][i].in[10] <== eq[25][i].out; + multi_or[3][i].in[11] <== eq[26][i].out; + multi_or[3][i].in[12] <== eq[27][i].out; + multi_or[3][i].in[13] <== eq[28][i].out; + multi_or[3][i].in[14] <== eq[29][i].out; + multi_or[3][i].in[15] <== eq[30][i].out; + and[17][i].b <== multi_or[3][i].out; + multi_or[4][i] = MultiOR(3); + multi_or[4][i].in[0] <== and[15][i].out; + multi_or[4][i].in[1] <== and[16][i].out; + multi_or[4][i].in[2] <== and[17][i].out; + states_tmp[i+1][4] <== multi_or[4][i].out; eq[31][i] = IsEqual(); eq[31][i].in[0] <== in[i]; eq[31][i].in[1] <== 237; - and[14][i] = AND(); - and[14][i].a <== states[i][0]; - and[14][i].b <== eq[31][i].out; - states_tmp[i+1][4] <== 0; + and[18][i] = AND(); + and[18][i].a <== states[i][0]; + and[18][i].b <== eq[31][i].out; + states_tmp[i+1][5] <== 0; eq[32][i] = IsEqual(); eq[32][i].in[0] <== in[i]; eq[32][i].in[1] <== 240; - and[15][i] = AND(); - and[15][i].a <== states[i][0]; - and[15][i].b <== eq[32][i].out; - states_tmp[i+1][5] <== 0; + and[19][i] = AND(); + and[19][i].a <== states[i][0]; + and[19][i].b <== eq[32][i].out; + states_tmp[i+1][6] <== 0; eq[33][i] = IsEqual(); eq[33][i].in[0] <== in[i]; eq[33][i].in[1] <== 241; @@ -262,58 +290,30 @@ template Negate2Regex(msg_bytes) { eq[35][i] = IsEqual(); eq[35][i].in[0] <== in[i]; eq[35][i].in[1] <== 243; - and[16][i] = AND(); - and[16][i].a <== states[i][0]; - multi_or[4][i] = MultiOR(3); - multi_or[4][i].in[0] <== eq[33][i].out; - multi_or[4][i].in[1] <== eq[34][i].out; - multi_or[4][i].in[2] <== eq[35][i].out; - and[16][i].b <== multi_or[4][i].out; - states_tmp[i+1][6] <== 0; - eq[36][i] = IsEqual(); - eq[36][i].in[0] <== in[i]; - eq[36][i].in[1] <== 244; - and[17][i] = AND(); - and[17][i].a <== states[i][0]; - and[17][i].b <== eq[36][i].out; - states_tmp[i+1][7] <== 0; - lt[10][i] = LessEqThan(8); - lt[10][i].in[0] <== 1; - lt[10][i].in[1] <== in[i]; - lt[11][i] = LessEqThan(8); - lt[11][i].in[0] <== in[i]; - lt[11][i].in[1] <== 96; - and[18][i] = AND(); - and[18][i].a <== lt[10][i].out; - and[18][i].b <== lt[11][i].out; - lt[12][i] = LessEqThan(8); - lt[12][i].in[0] <== 99; - lt[12][i].in[1] <== in[i]; - lt[13][i] = LessEqThan(8); - lt[13][i].in[0] <== in[i]; - lt[13][i].in[1] <== 127; - and[19][i] = AND(); - and[19][i].a <== lt[12][i].out; - and[19][i].b <== lt[13][i].out; and[20][i] = AND(); and[20][i].a <== states[i][0]; - multi_or[5][i] = MultiOR(2); - multi_or[5][i].in[0] <== and[18][i].out; - multi_or[5][i].in[1] <== and[19][i].out; + multi_or[5][i] = MultiOR(3); + multi_or[5][i].in[0] <== eq[33][i].out; + multi_or[5][i].in[1] <== eq[34][i].out; + multi_or[5][i].in[2] <== eq[35][i].out; and[20][i].b <== multi_or[5][i].out; + states_tmp[i+1][7] <== 0; + eq[36][i] = IsEqual(); + eq[36][i].in[0] <== in[i]; + eq[36][i].in[1] <== 244; and[21][i] = AND(); - and[21][i].a <== states[i][1]; - and[21][i].b <== and[4][i].out; - states_tmp[i+1][8] <== and[21][i].out; + and[21][i].a <== states[i][0]; + and[21][i].b <== eq[36][i].out; + states_tmp[i+1][8] <== 0; from_zero_enabled[i] <== MultiNOR(8)([states_tmp[i+1][1], states_tmp[i+1][2], states_tmp[i+1][3], states_tmp[i+1][4], states_tmp[i+1][5], states_tmp[i+1][6], states_tmp[i+1][7], states_tmp[i+1][8]]); - states[i+1][1] <== MultiOR(2)([states_tmp[i+1][1], from_zero_enabled[i] * and[1][i].out]); - states[i+1][2] <== MultiOR(2)([states_tmp[i+1][2], from_zero_enabled[i] * and[8][i].out]); - states[i+1][3] <== MultiOR(2)([states_tmp[i+1][3], from_zero_enabled[i] * and[9][i].out]); - states[i+1][4] <== MultiOR(2)([states_tmp[i+1][4], from_zero_enabled[i] * and[14][i].out]); - states[i+1][5] <== MultiOR(2)([states_tmp[i+1][5], from_zero_enabled[i] * and[15][i].out]); - states[i+1][6] <== MultiOR(2)([states_tmp[i+1][6], from_zero_enabled[i] * and[16][i].out]); - states[i+1][7] <== MultiOR(2)([states_tmp[i+1][7], from_zero_enabled[i] * and[17][i].out]); - states[i+1][8] <== MultiOR(2)([states_tmp[i+1][8], from_zero_enabled[i] * and[20][i].out]); + states[i+1][1] <== MultiOR(2)([states_tmp[i+1][1], from_zero_enabled[i] * and[2][i].out]); + states[i+1][2] <== MultiOR(2)([states_tmp[i+1][2], from_zero_enabled[i] * and[6][i].out]); + states[i+1][3] <== MultiOR(2)([states_tmp[i+1][3], from_zero_enabled[i] * and[12][i].out]); + states[i+1][4] <== MultiOR(2)([states_tmp[i+1][4], from_zero_enabled[i] * and[13][i].out]); + states[i+1][5] <== MultiOR(2)([states_tmp[i+1][5], from_zero_enabled[i] * and[18][i].out]); + states[i+1][6] <== MultiOR(2)([states_tmp[i+1][6], from_zero_enabled[i] * and[19][i].out]); + states[i+1][7] <== MultiOR(2)([states_tmp[i+1][7], from_zero_enabled[i] * and[20][i].out]); + states[i+1][8] <== MultiOR(2)([states_tmp[i+1][8], from_zero_enabled[i] * and[21][i].out]); state_changed[i].in[0] <== states[i+1][1]; state_changed[i].in[1] <== states[i+1][2]; state_changed[i].in[2] <== states[i+1][3]; @@ -326,23 +326,23 @@ template Negate2Regex(msg_bytes) { component is_accepted = MultiOR(num_bytes+1); for (var i = 0; i <= num_bytes; i++) { - is_accepted.in[i] <== states[i][8]; + is_accepted.in[i] <== states[i][1]; } out <== is_accepted.out; signal is_consecutive[msg_bytes+1][3]; is_consecutive[msg_bytes][2] <== 0; for (var i = 0; i < msg_bytes; i++) { - is_consecutive[msg_bytes-1-i][0] <== states[num_bytes-i][8] * (1 - is_consecutive[msg_bytes-i][2]) + is_consecutive[msg_bytes-i][2]; + is_consecutive[msg_bytes-1-i][0] <== states[num_bytes-i][1] * (1 - is_consecutive[msg_bytes-i][2]) + is_consecutive[msg_bytes-i][2]; is_consecutive[msg_bytes-1-i][1] <== state_changed[msg_bytes-i].out * is_consecutive[msg_bytes-1-i][0]; - is_consecutive[msg_bytes-1-i][2] <== ORAnd()([(1 - from_zero_enabled[msg_bytes-i+1]), states[num_bytes-i][8], is_consecutive[msg_bytes-1-i][1]]); + is_consecutive[msg_bytes-1-i][2] <== ORAnd()([(1 - from_zero_enabled[msg_bytes-i+1]), states[num_bytes-i][1], is_consecutive[msg_bytes-1-i][1]]); } - // substrings calculated: [{(0, 1), (0, 2), (0, 3), (0, 4), (0, 5), (0, 6), (0, 7), (0, 8), (1, 8), (2, 1), (3, 1), (4, 1), (5, 3), (6, 3), (7, 3)}] + // substrings calculated: [{(0, 1), (0, 2), (0, 3), (0, 4), (0, 5), (0, 6), (0, 7), (0, 8), (2, 1), (3, 2), (4, 2), (5, 2), (6, 4), (7, 4), (8, 4)}] signal prev_states0[15][msg_bytes]; signal is_substr0[msg_bytes]; signal is_reveal0[msg_bytes]; signal output reveal0[msg_bytes]; for (var i = 0; i < msg_bytes; i++) { - // the 0-th substring transitions: [(0, 1), (0, 2), (0, 3), (0, 4), (0, 5), (0, 6), (0, 7), (0, 8), (1, 8), (2, 1), (3, 1), (4, 1), (5, 3), (6, 3), (7, 3)] + // the 0-th substring transitions: [(0, 1), (0, 2), (0, 3), (0, 4), (0, 5), (0, 6), (0, 7), (0, 8), (2, 1), (3, 2), (4, 2), (5, 2), (6, 4), (7, 4), (8, 4)] prev_states0[0][i] <== from_zero_enabled[i+1] * states[i+1][0]; prev_states0[1][i] <== from_zero_enabled[i+1] * states[i+1][0]; prev_states0[2][i] <== from_zero_enabled[i+1] * states[i+1][0]; @@ -351,14 +351,14 @@ template Negate2Regex(msg_bytes) { prev_states0[5][i] <== from_zero_enabled[i+1] * states[i+1][0]; prev_states0[6][i] <== from_zero_enabled[i+1] * states[i+1][0]; prev_states0[7][i] <== from_zero_enabled[i+1] * states[i+1][0]; - prev_states0[8][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][1]; - prev_states0[9][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][2]; - prev_states0[10][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][3]; - prev_states0[11][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][4]; - prev_states0[12][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][5]; - prev_states0[13][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][6]; - prev_states0[14][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][7]; - is_substr0[i] <== MultiOR(15)([prev_states0[0][i] * states[i+2][1], prev_states0[1][i] * states[i+2][2], prev_states0[2][i] * states[i+2][3], prev_states0[3][i] * states[i+2][4], prev_states0[4][i] * states[i+2][5], prev_states0[5][i] * states[i+2][6], prev_states0[6][i] * states[i+2][7], prev_states0[7][i] * states[i+2][8], prev_states0[8][i] * states[i+2][8], prev_states0[9][i] * states[i+2][1], prev_states0[10][i] * states[i+2][1], prev_states0[11][i] * states[i+2][1], prev_states0[12][i] * states[i+2][3], prev_states0[13][i] * states[i+2][3], prev_states0[14][i] * states[i+2][3]]); + prev_states0[8][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][2]; + prev_states0[9][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][3]; + prev_states0[10][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][4]; + prev_states0[11][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][5]; + prev_states0[12][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][6]; + prev_states0[13][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][7]; + prev_states0[14][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][8]; + is_substr0[i] <== MultiOR(15)([prev_states0[0][i] * states[i+2][1], prev_states0[1][i] * states[i+2][2], prev_states0[2][i] * states[i+2][3], prev_states0[3][i] * states[i+2][4], prev_states0[4][i] * states[i+2][5], prev_states0[5][i] * states[i+2][6], prev_states0[6][i] * states[i+2][7], prev_states0[7][i] * states[i+2][8], prev_states0[8][i] * states[i+2][1], prev_states0[9][i] * states[i+2][2], prev_states0[10][i] * states[i+2][2], prev_states0[11][i] * states[i+2][2], prev_states0[12][i] * states[i+2][4], prev_states0[13][i] * states[i+2][4], prev_states0[14][i] * states[i+2][4]]); is_reveal0[i] <== MultiAND(3)([out, is_substr0[i], is_consecutive[i][2]]); reveal0[i] <== in[i+1] * is_reveal0[i]; } diff --git a/packages/circom/tests/circuits/plus4_regex.circom b/packages/circom/tests/circuits/plus4_regex.circom index b8ec65e..38ee5c4 100644 --- a/packages/circom/tests/circuits/plus4_regex.circom +++ b/packages/circom/tests/circuits/plus4_regex.circom @@ -32,52 +32,52 @@ template Plus4Regex(msg_bytes) { states[i][0] <== 1; eq[0][i] = IsEqual(); eq[0][i].in[0] <== in[i]; - eq[0][i].in[1] <== 51; + eq[0][i].in[1] <== 49; and[0][i] = AND(); and[0][i].a <== states[i][0]; and[0][i].b <== eq[0][i].out; and[1][i] = AND(); - and[1][i].a <== states[i][4]; + and[1][i].a <== states[i][3]; and[1][i].b <== eq[0][i].out; states_tmp[i+1][1] <== and[1][i].out; eq[1][i] = IsEqual(); eq[1][i].in[0] <== in[i]; - eq[1][i].in[1] <== 49; + eq[1][i].in[1] <== 51; and[2][i] = AND(); and[2][i].a <== states[i][0]; and[2][i].b <== eq[1][i].out; and[3][i] = AND(); - and[3][i].a <== states[i][4]; + and[3][i].a <== states[i][3]; and[3][i].b <== eq[1][i].out; states_tmp[i+1][2] <== and[3][i].out; eq[2][i] = IsEqual(); eq[2][i].in[0] <== in[i]; - eq[2][i].in[1] <== 52; + eq[2][i].in[1] <== 50; and[4][i] = AND(); and[4][i].a <== states[i][1]; and[4][i].b <== eq[2][i].out; - states[i+1][3] <== and[4][i].out; eq[3][i] = IsEqual(); eq[3][i].in[0] <== in[i]; - eq[3][i].in[1] <== 50; + eq[3][i].in[1] <== 53; and[5][i] = AND(); - and[5][i].a <== states[i][2]; + and[5][i].a <== states[i][4]; and[5][i].b <== eq[3][i].out; + multi_or[0][i] = MultiOR(2); + multi_or[0][i].in[0] <== and[4][i].out; + multi_or[0][i].in[1] <== and[5][i].out; + states[i+1][3] <== multi_or[0][i].out; eq[4][i] = IsEqual(); eq[4][i].in[0] <== in[i]; - eq[4][i].in[1] <== 53; + eq[4][i].in[1] <== 52; and[6][i] = AND(); - and[6][i].a <== states[i][3]; + and[6][i].a <== states[i][2]; and[6][i].b <== eq[4][i].out; - multi_or[0][i] = MultiOR(2); - multi_or[0][i].in[0] <== and[5][i].out; - multi_or[0][i].in[1] <== and[6][i].out; - states[i+1][4] <== multi_or[0][i].out; + states[i+1][4] <== and[6][i].out; eq[5][i] = IsEqual(); eq[5][i].in[0] <== in[i]; eq[5][i].in[1] <== 98; and[7][i] = AND(); - and[7][i].a <== states[i][4]; + and[7][i].a <== states[i][3]; and[7][i].b <== eq[5][i].out; states[i+1][5] <== and[7][i].out; from_zero_enabled[i] <== MultiNOR(5)([states_tmp[i+1][1], states_tmp[i+1][2], states[i+1][3], states[i+1][4], states[i+1][5]]); @@ -102,21 +102,21 @@ template Plus4Regex(msg_bytes) { is_consecutive[msg_bytes-1-i][1] <== state_changed[msg_bytes-i].out * is_consecutive[msg_bytes-1-i][0]; is_consecutive[msg_bytes-1-i][2] <== ORAnd()([(1 - from_zero_enabled[msg_bytes-i+1]), states[num_bytes-i][5], is_consecutive[msg_bytes-1-i][1]]); } - // substrings calculated: [{(0, 1), (0, 2), (1, 3), (2, 4), (3, 4), (4, 1), (4, 2)}] + // substrings calculated: [{(0, 1), (0, 2), (1, 3), (2, 4), (3, 1), (3, 2), (4, 3)}] signal prev_states0[7][msg_bytes]; signal is_substr0[msg_bytes]; signal is_reveal0[msg_bytes]; signal output reveal0[msg_bytes]; for (var i = 0; i < msg_bytes; i++) { - // the 0-th substring transitions: [(0, 1), (0, 2), (1, 3), (2, 4), (3, 4), (4, 1), (4, 2)] + // the 0-th substring transitions: [(0, 1), (0, 2), (1, 3), (2, 4), (3, 1), (3, 2), (4, 3)] prev_states0[0][i] <== from_zero_enabled[i+1] * states[i+1][0]; prev_states0[1][i] <== from_zero_enabled[i+1] * states[i+1][0]; prev_states0[2][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][1]; prev_states0[3][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][2]; prev_states0[4][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][3]; - prev_states0[5][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][4]; + prev_states0[5][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][3]; prev_states0[6][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][4]; - is_substr0[i] <== MultiOR(7)([prev_states0[0][i] * states[i+2][1], prev_states0[1][i] * states[i+2][2], prev_states0[2][i] * states[i+2][3], prev_states0[3][i] * states[i+2][4], prev_states0[4][i] * states[i+2][4], prev_states0[5][i] * states[i+2][1], prev_states0[6][i] * states[i+2][2]]); + is_substr0[i] <== MultiOR(7)([prev_states0[0][i] * states[i+2][1], prev_states0[1][i] * states[i+2][2], prev_states0[2][i] * states[i+2][3], prev_states0[3][i] * states[i+2][4], prev_states0[4][i] * states[i+2][1], prev_states0[5][i] * states[i+2][2], prev_states0[6][i] * states[i+2][3]]); is_reveal0[i] <== MultiAND(3)([out, is_substr0[i], is_consecutive[i][2]]); reveal0[i] <== in[i+1] * is_reveal0[i]; } From 1205e6512d23c2dce783a37108b638a4d1b66718 Mon Sep 17 00:00:00 2001 From: SoraSuegami Date: Tue, 27 Aug 2024 17:04:30 +0900 Subject: [PATCH 2/4] Add new tests for email address and domain regexes. --- .../apis/src/decomposed_defs/body_hash.json | 2 +- .../apis/src/decomposed_defs/email_addr.json | 4 +- .../decomposed_defs/email_addr_with_name.json | 4 +- .../src/decomposed_defs/email_domain.json | 10 +- .../apis/src/decomposed_defs/from_addr.json | 6 +- .../apis/src/decomposed_defs/from_all.json | 30 +- .../apis/src/decomposed_defs/message_id.json | 2 +- .../apis/src/decomposed_defs/subject_all.json | 2 +- .../apis/src/decomposed_defs/timestamp.json | 2 +- .../apis/src/decomposed_defs/to_addr.json | 6 +- packages/apis/src/decomposed_defs/to_all.json | 30 +- .../circom/circuits/common/email_addr.json | 2 +- .../circuits/common/email_addr_regex.circom | 204 +++++-- .../circuits/common/email_addr_with_name.json | 2 +- .../common/email_addr_with_name_regex.circom | 555 ++++++++++-------- .../circom/circuits/common/email_domain.json | 10 +- .../circuits/common/email_domain_regex.circom | 107 ++-- .../circom/circuits/common/from_addr.json | 2 +- packages/circom/circuits/common/to_addr.json | 2 +- packages/circom/tests/email_addr.test.js | 44 ++ packages/circom/tests/email_domain.test.js | 41 +- packages/circom/tests/from_addr.test.js | 40 ++ packages/circom/tests/to_addr.test.js | 40 ++ 23 files changed, 729 insertions(+), 418 deletions(-) diff --git a/packages/apis/src/decomposed_defs/body_hash.json b/packages/apis/src/decomposed_defs/body_hash.json index f53b8a5..354421e 100644 --- a/packages/apis/src/decomposed_defs/body_hash.json +++ b/packages/apis/src/decomposed_defs/body_hash.json @@ -2,7 +2,7 @@ "parts": [ { "is_public": false, - "regex_def": "((\r\n)|^)dkim-signature:" + "regex_def": "(\r\n|^)dkim-signature:" }, { "is_public": false, diff --git a/packages/apis/src/decomposed_defs/email_addr.json b/packages/apis/src/decomposed_defs/email_addr.json index 0842165..b2f4f39 100644 --- a/packages/apis/src/decomposed_defs/email_addr.json +++ b/packages/apis/src/decomposed_defs/email_addr.json @@ -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.\\-]+" } ] -} +} \ No newline at end of file diff --git a/packages/apis/src/decomposed_defs/email_addr_with_name.json b/packages/apis/src/decomposed_defs/email_addr_with_name.json index 31607a3..bff6d58 100644 --- a/packages/apis/src/decomposed_defs/email_addr_with_name.json +++ b/packages/apis/src/decomposed_defs/email_addr_with_name.json @@ -6,11 +6,11 @@ }, { "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, "regex_def": ">" } ] -} +} \ No newline at end of file diff --git a/packages/apis/src/decomposed_defs/email_domain.json b/packages/apis/src/decomposed_defs/email_domain.json index 82f0330..0ed11e3 100644 --- a/packages/apis/src/decomposed_defs/email_domain.json +++ b/packages/apis/src/decomposed_defs/email_domain.json @@ -2,15 +2,11 @@ "parts": [ { "is_public": false, - "regex_def": "[A-Za-z0-9!#$%&'*+-/=?^_`{\\|}~\\.]+" - }, - { - "is_public": false, - "regex_def": "@" + "regex_def": "[A-Za-z0-9!#$%&'*+=?\\-\\^_`{|}~.]+@" }, { "is_public": true, - "regex_def": "[A-Za-z0-9\\.-]+" + "regex_def": "[A-Za-z0-9.\\-@]+" } ] -} +} \ No newline at end of file diff --git a/packages/apis/src/decomposed_defs/from_addr.json b/packages/apis/src/decomposed_defs/from_addr.json index 7fdc28e..e4ca91d 100644 --- a/packages/apis/src/decomposed_defs/from_addr.json +++ b/packages/apis/src/decomposed_defs/from_addr.json @@ -2,7 +2,7 @@ "parts": [ { "is_public": false, - "regex_def": "((\r\n)|^)from:" + "regex_def": "(\r\n|^)from:" }, { "is_public": false, @@ -10,11 +10,11 @@ }, { "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, "regex_def": ">?\r\n" } ] -} +} \ No newline at end of file diff --git a/packages/apis/src/decomposed_defs/from_all.json b/packages/apis/src/decomposed_defs/from_all.json index a774997..a38aa7e 100644 --- a/packages/apis/src/decomposed_defs/from_all.json +++ b/packages/apis/src/decomposed_defs/from_all.json @@ -1,16 +1,16 @@ { - "parts": [ - { - "is_public": false, - "regex_def": "((\r\n)|^)from:" - }, - { - "is_public": true, - "regex_def": "[^\r\n]+" - }, - { - "is_public": false, - "regex_def": "\r\n" - } - ] -} + "parts": [ + { + "is_public": false, + "regex_def": "(\r\n|^)from:" + }, + { + "is_public": true, + "regex_def": "[^\r\n]+" + }, + { + "is_public": false, + "regex_def": "\r\n" + } + ] +} \ No newline at end of file diff --git a/packages/apis/src/decomposed_defs/message_id.json b/packages/apis/src/decomposed_defs/message_id.json index f71f0ee..b9d1227 100644 --- a/packages/apis/src/decomposed_defs/message_id.json +++ b/packages/apis/src/decomposed_defs/message_id.json @@ -2,7 +2,7 @@ "parts": [ { "is_public": false, - "regex_def": "((\r\n)|^)message-id:" + "regex_def": "(\r\n|^)message-id:" }, { "is_public": true, diff --git a/packages/apis/src/decomposed_defs/subject_all.json b/packages/apis/src/decomposed_defs/subject_all.json index ed7d761..9b54447 100644 --- a/packages/apis/src/decomposed_defs/subject_all.json +++ b/packages/apis/src/decomposed_defs/subject_all.json @@ -2,7 +2,7 @@ "parts": [ { "is_public": false, - "regex_def": "((\r\n)|^)subject:" + "regex_def": "(\r\n|^)subject:" }, { "is_public": true, diff --git a/packages/apis/src/decomposed_defs/timestamp.json b/packages/apis/src/decomposed_defs/timestamp.json index 4e2895e..a3c945b 100644 --- a/packages/apis/src/decomposed_defs/timestamp.json +++ b/packages/apis/src/decomposed_defs/timestamp.json @@ -2,7 +2,7 @@ "parts": [ { "is_public": false, - "regex_def": "((\r\n)|^)dkim-signature:" + "regex_def": "(\r\n|^)dkim-signature:" }, { "is_public": false, diff --git a/packages/apis/src/decomposed_defs/to_addr.json b/packages/apis/src/decomposed_defs/to_addr.json index 43384d7..0744491 100644 --- a/packages/apis/src/decomposed_defs/to_addr.json +++ b/packages/apis/src/decomposed_defs/to_addr.json @@ -2,7 +2,7 @@ "parts": [ { "is_public": false, - "regex_def": "((\r\n)|^)to:" + "regex_def": "(\r\n|^)to:" }, { "is_public": false, @@ -10,11 +10,11 @@ }, { "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, "regex_def": ">?\r\n" } ] -} +} \ No newline at end of file diff --git a/packages/apis/src/decomposed_defs/to_all.json b/packages/apis/src/decomposed_defs/to_all.json index eeb616f..76be9fd 100644 --- a/packages/apis/src/decomposed_defs/to_all.json +++ b/packages/apis/src/decomposed_defs/to_all.json @@ -1,16 +1,16 @@ { - "parts": [ - { - "is_public": false, - "regex_def": "((\r\n)|^)to:" - }, - { - "is_public": true, - "regex_def": "[^\r\n]+" - }, - { - "is_public": false, - "regex_def": "\r\n" - } - ] -} + "parts": [ + { + "is_public": false, + "regex_def": "(\r\n|^)to:" + }, + { + "is_public": true, + "regex_def": "[^\r\n]+" + }, + { + "is_public": false, + "regex_def": "\r\n" + } + ] +} \ No newline at end of file diff --git a/packages/circom/circuits/common/email_addr.json b/packages/circom/circuits/common/email_addr.json index 09a363c..b2f4f39 100644 --- a/packages/circom/circuits/common/email_addr.json +++ b/packages/circom/circuits/common/email_addr.json @@ -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.\\-]+" } ] } \ No newline at end of file diff --git a/packages/circom/circuits/common/email_addr_regex.circom b/packages/circom/circuits/common/email_addr_regex.circom index fc8e062..411ab2d 100644 --- a/packages/circom/circuits/common/email_addr_regex.circom +++ b/packages/circom/circuits/common/email_addr_regex.circom @@ -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; @@ -14,10 +14,10 @@ template EmailAddrRegex(msg_bytes) { in[i+1] <== msg[i]; } - component eq[23][num_bytes]; - component lt[6][num_bytes]; - component and[8][num_bytes]; - component multi_or[3][num_bytes]; + component eq[30][num_bytes]; + component lt[8][num_bytes]; + component and[13][num_bytes]; + component multi_or[7][num_bytes]; signal states[num_bytes+1][4]; signal states_tmp[num_bytes+1][4]; signal from_zero_enabled[num_bytes+1]; @@ -32,7 +32,7 @@ template EmailAddrRegex(msg_bytes) { state_changed[i] = MultiOR(3); states[i][0] <== 1; lt[0][i] = LessEqThan(8); - lt[0][i].in[0] <== 65; + lt[0][i].in[0] <== 63; lt[0][i].in[1] <== in[i]; lt[1][i] = LessEqThan(8); lt[1][i].in[0] <== in[i]; @@ -112,12 +112,9 @@ template EmailAddrRegex(msg_bytes) { eq[20][i] = IsEqual(); eq[20][i].in[0] <== in[i]; eq[20][i].in[1] <== 61; - eq[21][i] = IsEqual(); - eq[21][i].in[0] <== in[i]; - eq[21][i].in[1] <== 63; and[2][i] = AND(); and[2][i].a <== states[i][0]; - multi_or[0][i] = MultiOR(24); + multi_or[0][i] = MultiOR(23); 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; @@ -141,53 +138,148 @@ 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; - and[3][i] = AND(); - and[3][i].a <== states[i][1]; - and[3][i].b <== multi_or[0][i].out; - states_tmp[i+1][1] <== and[3][i].out; - eq[22][i] = IsEqual(); - eq[22][i].in[0] <== in[i]; - eq[22][i].in[1] <== 64; - and[4][i] = AND(); - and[4][i].a <== states[i][1]; - and[4][i].b <== eq[22][i].out; - states[i+1][2] <== and[4][i].out; lt[4][i] = LessEqThan(8); - lt[4][i].in[0] <== 97; + lt[4][i].in[0] <== 65; lt[4][i].in[1] <== in[i]; lt[5][i] = LessEqThan(8); lt[5][i].in[0] <== in[i]; - lt[5][i].in[1] <== 122; + lt[5][i].in[1] <== 90; + 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; + and[4][i] = AND(); + and[4][i].a <== states[i][1]; + multi_or[1][i] = MultiOR(24); + 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; + multi_or[1][i].in[3] <== eq[1][i].out; + multi_or[1][i].in[4] <== eq[2][i].out; + multi_or[1][i].in[5] <== eq[3][i].out; + multi_or[1][i].in[6] <== eq[4][i].out; + multi_or[1][i].in[7] <== eq[5][i].out; + multi_or[1][i].in[8] <== eq[6][i].out; + multi_or[1][i].in[9] <== eq[7][i].out; + multi_or[1][i].in[10] <== eq[8][i].out; + multi_or[1][i].in[11] <== eq[9][i].out; + multi_or[1][i].in[12] <== eq[10][i].out; + multi_or[1][i].in[13] <== eq[11][i].out; + multi_or[1][i].in[14] <== eq[12][i].out; + multi_or[1][i].in[15] <== eq[13][i].out; + multi_or[1][i].in[16] <== eq[14][i].out; + multi_or[1][i].in[17] <== eq[15][i].out; + multi_or[1][i].in[18] <== eq[16][i].out; + multi_or[1][i].in[19] <== eq[17][i].out; + multi_or[1][i].in[20] <== eq[18][i].out; + 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; + 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[24][i] = IsEqual(); + eq[24][i].in[0] <== in[i]; + eq[24][i].in[1] <== 96; + eq[25][i] = IsEqual(); + eq[25][i].in[0] <== in[i]; + eq[25][i].in[1] <== 123; + eq[26][i] = IsEqual(); + eq[26][i].in[0] <== in[i]; + eq[26][i].in[1] <== 124; + eq[27][i] = IsEqual(); + eq[27][i].in[0] <== in[i]; + eq[27][i].in[1] <== 125; + eq[28][i] = IsEqual(); + eq[28][i].in[0] <== in[i]; + eq[28][i].in[1] <== 126; and[5][i] = AND(); - and[5][i].a <== lt[4][i].out; - and[5][i].b <== lt[5][i].out; + and[5][i].a <== states[i][2]; + multi_or[2][i] = MultiOR(17); + 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; + multi_or[2][i].in[3] <== eq[3][i].out; + multi_or[2][i].in[4] <== eq[4][i].out; + 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[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; + multi_or[2][i].in[12] <== eq[24][i].out; + multi_or[2][i].in[13] <== eq[25][i].out; + 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; + and[5][i].b <== multi_or[2][i].out; and[6][i] = AND(); - and[6][i].a <== states[i][2]; - multi_or[1][i] = MultiOR(14); - multi_or[1][i].in[0] <== and[0][i].out; - multi_or[1][i].in[1] <== and[5][i].out; - multi_or[1][i].in[2] <== eq[8][i].out; - multi_or[1][i].in[3] <== eq[9][i].out; - multi_or[1][i].in[4] <== eq[10][i].out; - multi_or[1][i].in[5] <== eq[11][i].out; - multi_or[1][i].in[6] <== eq[12][i].out; - multi_or[1][i].in[7] <== eq[13][i].out; - multi_or[1][i].in[8] <== eq[14][i].out; - multi_or[1][i].in[9] <== eq[15][i].out; - multi_or[1][i].in[10] <== eq[16][i].out; - multi_or[1][i].in[11] <== eq[17][i].out; - multi_or[1][i].in[12] <== eq[18][i].out; - multi_or[1][i].in[13] <== eq[19][i].out; - and[6][i].b <== multi_or[1][i].out; + and[6][i].a <== states[i][3]; + and[6][i].b <== multi_or[2][i].out; + multi_or[3][i] = MultiOR(3); + multi_or[3][i].in[0] <== and[4][i].out; + 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; and[7][i] = AND(); - and[7][i].a <== states[i][3]; - and[7][i].b <== multi_or[1][i].out; - multi_or[2][i] = MultiOR(2); - multi_or[2][i].in[0] <== and[6][i].out; - multi_or[2][i].in[1] <== and[7][i].out; - states[i+1][3] <== multi_or[2][i].out; + and[7][i].a <== states[i][1]; + and[7][i].b <== eq[29][i].out; + and[8][i] = AND(); + and[8][i].a <== states[i][2]; + and[8][i].b <== eq[29][i].out; + and[9][i] = AND(); + and[9][i].a <== states[i][3]; + and[9][i].b <== eq[29][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; + multi_or[4][i].in[2] <== and[9][i].out; + states[i+1][2] <== multi_or[4][i].out; + lt[6][i] = LessEqThan(8); + lt[6][i].in[0] <== 97; + lt[6][i].in[1] <== in[i]; + lt[7][i] = LessEqThan(8); + lt[7][i].in[0] <== in[i]; + lt[7][i].in[1] <== 122; + and[10][i] = AND(); + and[10][i].a <== lt[6][i].out; + and[10][i].b <== lt[7][i].out; + and[11][i] = AND(); + and[11][i].a <== states[i][2]; + multi_or[5][i] = MultiOR(14); + multi_or[5][i].in[0] <== and[3][i].out; + 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; + and[11][i].b <== multi_or[5][i].out; + and[12][i] = AND(); + and[12][i].a <== states[i][3]; + and[12][i].b <== multi_or[5][i].out; + multi_or[6][i] = MultiOR(2); + multi_or[6][i].in[0] <== and[11][i].out; + multi_or[6][i].in[1] <== and[12][i].out; + states[i+1][3] <== multi_or[6][i].out; from_zero_enabled[i] <== MultiNOR(3)([states_tmp[i+1][1], states[i+1][2], states[i+1][3]]); states[i+1][1] <== MultiOR(2)([states_tmp[i+1][1], from_zero_enabled[i] * and[2][i].out]); state_changed[i].in[0] <== states[i+1][1]; @@ -207,19 +299,23 @@ template EmailAddrRegex(msg_bytes) { is_consecutive[msg_bytes-1-i][1] <== state_changed[msg_bytes-i].out * is_consecutive[msg_bytes-1-i][0]; is_consecutive[msg_bytes-1-i][2] <== ORAnd()([(1 - from_zero_enabled[msg_bytes-i+1]), states[num_bytes-i][3], is_consecutive[msg_bytes-1-i][1]]); } - // substrings calculated: [{(0, 1), (1, 1), (1, 2), (2, 3), (3, 3)}] - signal prev_states0[5][msg_bytes]; + // substrings calculated: [{(0, 1), (1, 1), (1, 2), (2, 1), (2, 2), (2, 3), (3, 1), (3, 2), (3, 3)}] + signal prev_states0[9][msg_bytes]; signal is_substr0[msg_bytes]; signal is_reveal0[msg_bytes]; signal output reveal0[msg_bytes]; for (var i = 0; i < msg_bytes; i++) { - // the 0-th substring transitions: [(0, 1), (1, 1), (1, 2), (2, 3), (3, 3)] + // the 0-th substring transitions: [(0, 1), (1, 1), (1, 2), (2, 1), (2, 2), (2, 3), (3, 1), (3, 2), (3, 3)] prev_states0[0][i] <== from_zero_enabled[i+1] * states[i+1][0]; prev_states0[1][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][1]; prev_states0[2][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][1]; prev_states0[3][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][2]; - prev_states0[4][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][3]; - is_substr0[i] <== MultiOR(5)([prev_states0[0][i] * states[i+2][1], prev_states0[1][i] * states[i+2][1], prev_states0[2][i] * states[i+2][2], prev_states0[3][i] * states[i+2][3], prev_states0[4][i] * states[i+2][3]]); + prev_states0[4][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][2]; + prev_states0[5][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][2]; + prev_states0[6][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][3]; + prev_states0[7][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][3]; + prev_states0[8][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][3]; + is_substr0[i] <== MultiOR(9)([prev_states0[0][i] * states[i+2][1], prev_states0[1][i] * states[i+2][1], prev_states0[2][i] * states[i+2][2], prev_states0[3][i] * states[i+2][1], prev_states0[4][i] * states[i+2][2], prev_states0[5][i] * states[i+2][3], prev_states0[6][i] * states[i+2][1], prev_states0[7][i] * states[i+2][2], prev_states0[8][i] * states[i+2][3]]); is_reveal0[i] <== MultiAND(3)([out, is_substr0[i], is_consecutive[i][2]]); reveal0[i] <== in[i+1] * is_reveal0[i]; } diff --git a/packages/circom/circuits/common/email_addr_with_name.json b/packages/circom/circuits/common/email_addr_with_name.json index 1039792..bff6d58 100644 --- a/packages/circom/circuits/common/email_addr_with_name.json +++ b/packages/circom/circuits/common/email_addr_with_name.json @@ -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, diff --git a/packages/circom/circuits/common/email_addr_with_name_regex.circom b/packages/circom/circuits/common/email_addr_with_name_regex.circom index 90341bc..6325a09 100644 --- a/packages/circom/circuits/common/email_addr_with_name_regex.circom +++ b/packages/circom/circuits/common/email_addr_with_name_regex.circom @@ -2,7 +2,7 @@ pragma circom 2.1.5; include "@zk-email/zk-regex-circom/circuits/regex_helpers.circom"; -// regex: [^\r\n]+<[A-Za-z0-9!#$%&'*+=?\-\^_`{|}~.]+@[a-zA-Z0-9_.\-]+> +// regex: [^\r\n]+<[A-Za-z0-9!#$%&'*+=?\-\^_`{|}~.@]+@[a-zA-Z0-9_.\-]+> template EmailAddrWithNameRegex(msg_bytes) { signal input msg[msg_bytes]; signal output out; @@ -14,10 +14,10 @@ template EmailAddrWithNameRegex(msg_bytes) { in[i+1] <== msg[i]; } - component eq[85][num_bytes]; - component lt[24][num_bytes]; - component and[51][num_bytes]; - component multi_or[19][num_bytes]; + component eq[91][num_bytes]; + component lt[26][num_bytes]; + component and[56][num_bytes]; + component multi_or[22][num_bytes]; signal states[num_bytes+1][14]; signal states_tmp[num_bytes+1][14]; signal from_zero_enabled[num_bytes+1]; @@ -156,31 +156,34 @@ template EmailAddrWithNameRegex(msg_bytes) { eq[13][i].in[1] <== 41; eq[14][i] = IsEqual(); eq[14][i].in[0] <== in[i]; - eq[14][i].in[1] <== 58; + eq[14][i].in[1] <== 44; eq[15][i] = IsEqual(); eq[15][i].in[0] <== in[i]; - eq[15][i].in[1] <== 59; + eq[15][i].in[1] <== 47; eq[16][i] = IsEqual(); eq[16][i].in[0] <== in[i]; - eq[16][i].in[1] <== 62; + eq[16][i].in[1] <== 58; eq[17][i] = IsEqual(); eq[17][i].in[0] <== in[i]; - eq[17][i].in[1] <== 64; + eq[17][i].in[1] <== 59; eq[18][i] = IsEqual(); eq[18][i].in[0] <== in[i]; - eq[18][i].in[1] <== 91; + eq[18][i].in[1] <== 62; eq[19][i] = IsEqual(); eq[19][i].in[0] <== in[i]; - eq[19][i].in[1] <== 92; + eq[19][i].in[1] <== 91; eq[20][i] = IsEqual(); eq[20][i].in[0] <== in[i]; - eq[20][i].in[1] <== 93; + eq[20][i].in[1] <== 92; eq[21][i] = IsEqual(); eq[21][i].in[0] <== in[i]; - eq[21][i].in[1] <== 127; + eq[21][i].in[1] <== 93; + eq[22][i] = IsEqual(); + eq[22][i].in[0] <== in[i]; + eq[22][i].in[1] <== 127; and[8][i] = AND(); and[8][i].a <== states[i][9]; - multi_or[2][i] = MultiOR(23); + multi_or[2][i] = MultiOR(24); multi_or[2][i].in[0] <== and[7][i].out; multi_or[2][i].in[1] <== eq[0][i].out; multi_or[2][i].in[2] <== eq[1][i].out; @@ -204,6 +207,7 @@ template EmailAddrWithNameRegex(msg_bytes) { multi_or[2][i].in[20] <== eq[19][i].out; multi_or[2][i].in[21] <== eq[20][i].out; multi_or[2][i].in[22] <== eq[21][i].out; + multi_or[2][i].in[23] <== eq[22][i].out; and[8][i].b <== multi_or[2][i].out; multi_or[3][i] = MultiOR(3); multi_or[3][i].in[0] <== and[4][i].out; @@ -262,81 +266,81 @@ template EmailAddrWithNameRegex(msg_bytes) { multi_or[4][i].in[3] <== and[16][i].out; multi_or[4][i].in[4] <== and[17][i].out; states_tmp[i+1][2] <== multi_or[4][i].out; - eq[22][i] = IsEqual(); - eq[22][i].in[0] <== in[i]; - eq[22][i].in[1] <== 224; + eq[23][i] = IsEqual(); + eq[23][i].in[0] <== in[i]; + eq[23][i].in[1] <== 224; and[18][i] = AND(); and[18][i].a <== states[i][0]; - and[18][i].b <== eq[22][i].out; + and[18][i].b <== eq[23][i].out; and[19][i] = AND(); and[19][i].a <== states[i][1]; - and[19][i].b <== eq[22][i].out; + and[19][i].b <== eq[23][i].out; and[20][i] = AND(); and[20][i].a <== states[i][9]; - and[20][i].b <== eq[22][i].out; + and[20][i].b <== eq[23][i].out; multi_or[5][i] = MultiOR(2); multi_or[5][i].in[0] <== and[19][i].out; multi_or[5][i].in[1] <== and[20][i].out; states_tmp[i+1][3] <== multi_or[5][i].out; - eq[23][i] = IsEqual(); - eq[23][i].in[0] <== in[i]; - eq[23][i].in[1] <== 225; eq[24][i] = IsEqual(); eq[24][i].in[0] <== in[i]; - eq[24][i].in[1] <== 226; + eq[24][i].in[1] <== 225; eq[25][i] = IsEqual(); eq[25][i].in[0] <== in[i]; - eq[25][i].in[1] <== 227; + eq[25][i].in[1] <== 226; eq[26][i] = IsEqual(); eq[26][i].in[0] <== in[i]; - eq[26][i].in[1] <== 228; + eq[26][i].in[1] <== 227; eq[27][i] = IsEqual(); eq[27][i].in[0] <== in[i]; - eq[27][i].in[1] <== 229; + eq[27][i].in[1] <== 228; eq[28][i] = IsEqual(); eq[28][i].in[0] <== in[i]; - eq[28][i].in[1] <== 230; + eq[28][i].in[1] <== 229; eq[29][i] = IsEqual(); eq[29][i].in[0] <== in[i]; - eq[29][i].in[1] <== 231; + eq[29][i].in[1] <== 230; eq[30][i] = IsEqual(); eq[30][i].in[0] <== in[i]; - eq[30][i].in[1] <== 232; + eq[30][i].in[1] <== 231; eq[31][i] = IsEqual(); eq[31][i].in[0] <== in[i]; - eq[31][i].in[1] <== 233; + eq[31][i].in[1] <== 232; eq[32][i] = IsEqual(); eq[32][i].in[0] <== in[i]; - eq[32][i].in[1] <== 234; + eq[32][i].in[1] <== 233; eq[33][i] = IsEqual(); eq[33][i].in[0] <== in[i]; - eq[33][i].in[1] <== 235; + eq[33][i].in[1] <== 234; eq[34][i] = IsEqual(); eq[34][i].in[0] <== in[i]; - eq[34][i].in[1] <== 236; + eq[34][i].in[1] <== 235; eq[35][i] = IsEqual(); eq[35][i].in[0] <== in[i]; - eq[35][i].in[1] <== 238; + eq[35][i].in[1] <== 236; eq[36][i] = IsEqual(); eq[36][i].in[0] <== in[i]; - eq[36][i].in[1] <== 239; + eq[36][i].in[1] <== 238; + eq[37][i] = IsEqual(); + eq[37][i].in[0] <== in[i]; + eq[37][i].in[1] <== 239; and[21][i] = AND(); and[21][i].a <== states[i][0]; multi_or[6][i] = MultiOR(14); - multi_or[6][i].in[0] <== eq[23][i].out; - multi_or[6][i].in[1] <== eq[24][i].out; - multi_or[6][i].in[2] <== eq[25][i].out; - multi_or[6][i].in[3] <== eq[26][i].out; - multi_or[6][i].in[4] <== eq[27][i].out; - multi_or[6][i].in[5] <== eq[28][i].out; - multi_or[6][i].in[6] <== eq[29][i].out; - multi_or[6][i].in[7] <== eq[30][i].out; - multi_or[6][i].in[8] <== eq[31][i].out; - multi_or[6][i].in[9] <== eq[32][i].out; - multi_or[6][i].in[10] <== eq[33][i].out; - multi_or[6][i].in[11] <== eq[34][i].out; - multi_or[6][i].in[12] <== eq[35][i].out; - multi_or[6][i].in[13] <== eq[36][i].out; + multi_or[6][i].in[0] <== eq[24][i].out; + multi_or[6][i].in[1] <== eq[25][i].out; + multi_or[6][i].in[2] <== eq[26][i].out; + multi_or[6][i].in[3] <== eq[27][i].out; + multi_or[6][i].in[4] <== eq[28][i].out; + multi_or[6][i].in[5] <== eq[29][i].out; + multi_or[6][i].in[6] <== eq[30][i].out; + multi_or[6][i].in[7] <== eq[31][i].out; + multi_or[6][i].in[8] <== eq[32][i].out; + multi_or[6][i].in[9] <== eq[33][i].out; + multi_or[6][i].in[10] <== eq[34][i].out; + multi_or[6][i].in[11] <== eq[35][i].out; + multi_or[6][i].in[12] <== eq[36][i].out; + multi_or[6][i].in[13] <== eq[37][i].out; and[21][i].b <== multi_or[6][i].out; and[22][i] = AND(); and[22][i].a <== states[i][1]; @@ -356,73 +360,73 @@ template EmailAddrWithNameRegex(msg_bytes) { and[25][i] = AND(); and[25][i].a <== states[i][7]; and[25][i].b <== and[5][i].out; - eq[37][i] = IsEqual(); - eq[37][i].in[0] <== in[i]; - eq[37][i].in[1] <== 128; eq[38][i] = IsEqual(); eq[38][i].in[0] <== in[i]; - eq[38][i].in[1] <== 129; + eq[38][i].in[1] <== 128; eq[39][i] = IsEqual(); eq[39][i].in[0] <== in[i]; - eq[39][i].in[1] <== 130; + eq[39][i].in[1] <== 129; eq[40][i] = IsEqual(); eq[40][i].in[0] <== in[i]; - eq[40][i].in[1] <== 131; + eq[40][i].in[1] <== 130; eq[41][i] = IsEqual(); eq[41][i].in[0] <== in[i]; - eq[41][i].in[1] <== 132; + eq[41][i].in[1] <== 131; eq[42][i] = IsEqual(); eq[42][i].in[0] <== in[i]; - eq[42][i].in[1] <== 133; + eq[42][i].in[1] <== 132; eq[43][i] = IsEqual(); eq[43][i].in[0] <== in[i]; - eq[43][i].in[1] <== 134; + eq[43][i].in[1] <== 133; eq[44][i] = IsEqual(); eq[44][i].in[0] <== in[i]; - eq[44][i].in[1] <== 135; + eq[44][i].in[1] <== 134; eq[45][i] = IsEqual(); eq[45][i].in[0] <== in[i]; - eq[45][i].in[1] <== 136; + eq[45][i].in[1] <== 135; eq[46][i] = IsEqual(); eq[46][i].in[0] <== in[i]; - eq[46][i].in[1] <== 137; + eq[46][i].in[1] <== 136; eq[47][i] = IsEqual(); eq[47][i].in[0] <== in[i]; - eq[47][i].in[1] <== 138; + eq[47][i].in[1] <== 137; eq[48][i] = IsEqual(); eq[48][i].in[0] <== in[i]; - eq[48][i].in[1] <== 139; + eq[48][i].in[1] <== 138; eq[49][i] = IsEqual(); eq[49][i].in[0] <== in[i]; - eq[49][i].in[1] <== 140; + eq[49][i].in[1] <== 139; eq[50][i] = IsEqual(); eq[50][i].in[0] <== in[i]; - eq[50][i].in[1] <== 141; + eq[50][i].in[1] <== 140; eq[51][i] = IsEqual(); eq[51][i].in[0] <== in[i]; - eq[51][i].in[1] <== 142; + eq[51][i].in[1] <== 141; eq[52][i] = IsEqual(); eq[52][i].in[0] <== in[i]; - eq[52][i].in[1] <== 143; + eq[52][i].in[1] <== 142; + eq[53][i] = IsEqual(); + eq[53][i].in[0] <== in[i]; + eq[53][i].in[1] <== 143; and[26][i] = AND(); and[26][i].a <== states[i][8]; multi_or[7][i] = MultiOR(16); - multi_or[7][i].in[0] <== eq[37][i].out; - multi_or[7][i].in[1] <== eq[38][i].out; - multi_or[7][i].in[2] <== eq[39][i].out; - multi_or[7][i].in[3] <== eq[40][i].out; - multi_or[7][i].in[4] <== eq[41][i].out; - multi_or[7][i].in[5] <== eq[42][i].out; - multi_or[7][i].in[6] <== eq[43][i].out; - multi_or[7][i].in[7] <== eq[44][i].out; - multi_or[7][i].in[8] <== eq[45][i].out; - multi_or[7][i].in[9] <== eq[46][i].out; - multi_or[7][i].in[10] <== eq[47][i].out; - multi_or[7][i].in[11] <== eq[48][i].out; - multi_or[7][i].in[12] <== eq[49][i].out; - multi_or[7][i].in[13] <== eq[50][i].out; - multi_or[7][i].in[14] <== eq[51][i].out; - multi_or[7][i].in[15] <== eq[52][i].out; + multi_or[7][i].in[0] <== eq[38][i].out; + multi_or[7][i].in[1] <== eq[39][i].out; + multi_or[7][i].in[2] <== eq[40][i].out; + multi_or[7][i].in[3] <== eq[41][i].out; + multi_or[7][i].in[4] <== eq[42][i].out; + multi_or[7][i].in[5] <== eq[43][i].out; + multi_or[7][i].in[6] <== eq[44][i].out; + multi_or[7][i].in[7] <== eq[45][i].out; + multi_or[7][i].in[8] <== eq[46][i].out; + multi_or[7][i].in[9] <== eq[47][i].out; + multi_or[7][i].in[10] <== eq[48][i].out; + multi_or[7][i].in[11] <== eq[49][i].out; + multi_or[7][i].in[12] <== eq[50][i].out; + multi_or[7][i].in[13] <== eq[51][i].out; + multi_or[7][i].in[14] <== eq[52][i].out; + multi_or[7][i].in[15] <== eq[53][i].out; and[26][i].b <== multi_or[7][i].out; and[27][i] = AND(); and[27][i].a <== states[i][9]; @@ -434,89 +438,53 @@ template EmailAddrWithNameRegex(msg_bytes) { multi_or[8][i].in[3] <== and[26][i].out; multi_or[8][i].in[4] <== and[27][i].out; states_tmp[i+1][4] <== multi_or[8][i].out; - eq[53][i] = IsEqual(); - eq[53][i].in[0] <== in[i]; - eq[53][i].in[1] <== 237; + eq[54][i] = IsEqual(); + eq[54][i].in[0] <== in[i]; + eq[54][i].in[1] <== 237; and[28][i] = AND(); and[28][i].a <== states[i][0]; - and[28][i].b <== eq[53][i].out; + and[28][i].b <== eq[54][i].out; and[29][i] = AND(); and[29][i].a <== states[i][1]; - and[29][i].b <== eq[53][i].out; + and[29][i].b <== eq[54][i].out; and[30][i] = AND(); and[30][i].a <== states[i][9]; - and[30][i].b <== eq[53][i].out; + and[30][i].b <== eq[54][i].out; multi_or[9][i] = MultiOR(2); multi_or[9][i].in[0] <== and[29][i].out; multi_or[9][i].in[1] <== and[30][i].out; states_tmp[i+1][5] <== multi_or[9][i].out; - eq[54][i] = IsEqual(); - eq[54][i].in[0] <== in[i]; - eq[54][i].in[1] <== 240; + eq[55][i] = IsEqual(); + eq[55][i].in[0] <== in[i]; + eq[55][i].in[1] <== 240; and[31][i] = AND(); and[31][i].a <== states[i][0]; - and[31][i].b <== eq[54][i].out; + and[31][i].b <== eq[55][i].out; and[32][i] = AND(); and[32][i].a <== states[i][1]; - and[32][i].b <== eq[54][i].out; + and[32][i].b <== eq[55][i].out; and[33][i] = AND(); and[33][i].a <== states[i][9]; - and[33][i].b <== eq[54][i].out; + and[33][i].b <== eq[55][i].out; multi_or[10][i] = MultiOR(2); multi_or[10][i].in[0] <== and[32][i].out; multi_or[10][i].in[1] <== and[33][i].out; states_tmp[i+1][6] <== multi_or[10][i].out; - eq[55][i] = IsEqual(); - eq[55][i].in[0] <== in[i]; - eq[55][i].in[1] <== 241; eq[56][i] = IsEqual(); eq[56][i].in[0] <== in[i]; - eq[56][i].in[1] <== 242; + eq[56][i].in[1] <== 241; eq[57][i] = IsEqual(); eq[57][i].in[0] <== in[i]; - eq[57][i].in[1] <== 243; - and[34][i] = AND(); - and[34][i].a <== states[i][0]; - multi_or[11][i] = MultiOR(3); - multi_or[11][i].in[0] <== eq[55][i].out; - multi_or[11][i].in[1] <== eq[56][i].out; - multi_or[11][i].in[2] <== eq[57][i].out; - and[34][i].b <== multi_or[11][i].out; - and[35][i] = AND(); - and[35][i].a <== states[i][1]; - and[35][i].b <== multi_or[11][i].out; - and[36][i] = AND(); - and[36][i].a <== states[i][9]; - and[36][i].b <== multi_or[11][i].out; - multi_or[12][i] = MultiOR(2); - multi_or[12][i].in[0] <== and[35][i].out; - multi_or[12][i].in[1] <== and[36][i].out; - states_tmp[i+1][7] <== multi_or[12][i].out; + eq[57][i].in[1] <== 242; eq[58][i] = IsEqual(); eq[58][i].in[0] <== in[i]; - eq[58][i].in[1] <== 244; - and[37][i] = AND(); - and[37][i].a <== states[i][0]; - and[37][i].b <== eq[58][i].out; - and[38][i] = AND(); - and[38][i].a <== states[i][1]; - and[38][i].b <== eq[58][i].out; - and[39][i] = AND(); - and[39][i].a <== states[i][9]; - and[39][i].b <== eq[58][i].out; - multi_or[13][i] = MultiOR(2); - multi_or[13][i].in[0] <== and[38][i].out; - multi_or[13][i].in[1] <== and[39][i].out; - states_tmp[i+1][8] <== multi_or[13][i].out; - eq[59][i] = IsEqual(); - eq[59][i].in[0] <== in[i]; - eq[59][i].in[1] <== 243; + eq[58][i].in[1] <== 243; and[34][i] = AND(); and[34][i].a <== states[i][0]; multi_or[11][i] = MultiOR(3); - multi_or[11][i].in[0] <== eq[57][i].out; - multi_or[11][i].in[1] <== eq[58][i].out; - multi_or[11][i].in[2] <== eq[59][i].out; + multi_or[11][i].in[0] <== eq[56][i].out; + multi_or[11][i].in[1] <== eq[57][i].out; + multi_or[11][i].in[2] <== eq[58][i].out; and[34][i].b <== multi_or[11][i].out; and[35][i] = AND(); and[35][i].a <== states[i][1]; @@ -528,37 +496,37 @@ template EmailAddrWithNameRegex(msg_bytes) { multi_or[12][i].in[0] <== and[35][i].out; multi_or[12][i].in[1] <== and[36][i].out; states_tmp[i+1][7] <== multi_or[12][i].out; - eq[60][i] = IsEqual(); - eq[60][i].in[0] <== in[i]; - eq[60][i].in[1] <== 244; + eq[59][i] = IsEqual(); + eq[59][i].in[0] <== in[i]; + eq[59][i].in[1] <== 244; and[37][i] = AND(); and[37][i].a <== states[i][0]; - and[37][i].b <== eq[60][i].out; + and[37][i].b <== eq[59][i].out; and[38][i] = AND(); and[38][i].a <== states[i][1]; - and[38][i].b <== eq[60][i].out; + and[38][i].b <== eq[59][i].out; and[39][i] = AND(); and[39][i].a <== states[i][9]; - and[39][i].b <== eq[60][i].out; + and[39][i].b <== eq[59][i].out; multi_or[13][i] = MultiOR(2); multi_or[13][i].in[0] <== and[38][i].out; multi_or[13][i].in[1] <== and[39][i].out; states_tmp[i+1][8] <== multi_or[13][i].out; - eq[61][i] = IsEqual(); - eq[61][i].in[0] <== in[i]; - eq[61][i].in[1] <== 60; + eq[60][i] = IsEqual(); + eq[60][i].in[0] <== in[i]; + eq[60][i].in[1] <== 60; and[40][i] = AND(); and[40][i].a <== states[i][1]; - and[40][i].b <== eq[59][i].out; + and[40][i].b <== eq[60][i].out; and[41][i] = AND(); and[41][i].a <== states[i][9]; - and[41][i].b <== eq[61][i].out; + and[41][i].b <== eq[60][i].out; multi_or[14][i] = MultiOR(2); multi_or[14][i].in[0] <== and[40][i].out; multi_or[14][i].in[1] <== and[41][i].out; states[i+1][9] <== multi_or[14][i].out; lt[18][i] = LessEqThan(8); - lt[18][i].in[0] <== 65; + lt[18][i].in[0] <== 63; lt[18][i].in[1] <== in[i]; lt[19][i] = LessEqThan(8); lt[19][i].in[0] <== in[i]; @@ -575,153 +543,242 @@ template EmailAddrWithNameRegex(msg_bytes) { and[43][i] = AND(); and[43][i].a <== lt[20][i].out; and[43][i].b <== lt[21][i].out; + eq[61][i] = IsEqual(); + eq[61][i].in[0] <== in[i]; + eq[61][i].in[1] <== 33; eq[62][i] = IsEqual(); eq[62][i].in[0] <== in[i]; - eq[62][i].in[1] <== 33; + eq[62][i].in[1] <== 35; eq[63][i] = IsEqual(); eq[63][i].in[0] <== in[i]; - eq[63][i].in[1] <== 35; + eq[63][i].in[1] <== 36; eq[64][i] = IsEqual(); eq[64][i].in[0] <== in[i]; - eq[64][i].in[1] <== 36; + eq[64][i].in[1] <== 37; eq[65][i] = IsEqual(); eq[65][i].in[0] <== in[i]; - eq[65][i].in[1] <== 37; + eq[65][i].in[1] <== 38; eq[66][i] = IsEqual(); eq[66][i].in[0] <== in[i]; - eq[66][i].in[1] <== 38; + eq[66][i].in[1] <== 39; eq[67][i] = IsEqual(); eq[67][i].in[0] <== in[i]; - eq[67][i].in[1] <== 39; + eq[67][i].in[1] <== 42; eq[68][i] = IsEqual(); eq[68][i].in[0] <== in[i]; - eq[68][i].in[1] <== 42; + eq[68][i].in[1] <== 43; eq[69][i] = IsEqual(); eq[69][i].in[0] <== in[i]; - eq[69][i].in[1] <== 43; + eq[69][i].in[1] <== 45; eq[70][i] = IsEqual(); eq[70][i].in[0] <== in[i]; - eq[70][i].in[1] <== 45; + eq[70][i].in[1] <== 46; eq[71][i] = IsEqual(); eq[71][i].in[0] <== in[i]; - eq[71][i].in[1] <== 46; + eq[71][i].in[1] <== 48; eq[72][i] = IsEqual(); eq[72][i].in[0] <== in[i]; - eq[72][i].in[1] <== 48; + eq[72][i].in[1] <== 49; eq[73][i] = IsEqual(); eq[73][i].in[0] <== in[i]; - eq[73][i].in[1] <== 49; + eq[73][i].in[1] <== 50; eq[74][i] = IsEqual(); eq[74][i].in[0] <== in[i]; - eq[74][i].in[1] <== 50; + eq[74][i].in[1] <== 51; eq[75][i] = IsEqual(); eq[75][i].in[0] <== in[i]; - eq[75][i].in[1] <== 51; + eq[75][i].in[1] <== 52; eq[76][i] = IsEqual(); eq[76][i].in[0] <== in[i]; - eq[76][i].in[1] <== 52; + eq[76][i].in[1] <== 53; eq[77][i] = IsEqual(); eq[77][i].in[0] <== in[i]; - eq[77][i].in[1] <== 53; + eq[77][i].in[1] <== 54; eq[78][i] = IsEqual(); eq[78][i].in[0] <== in[i]; - eq[78][i].in[1] <== 54; + eq[78][i].in[1] <== 55; eq[79][i] = IsEqual(); eq[79][i].in[0] <== in[i]; - eq[79][i].in[1] <== 55; + eq[79][i].in[1] <== 56; eq[80][i] = IsEqual(); eq[80][i].in[0] <== in[i]; - eq[80][i].in[1] <== 56; + eq[80][i].in[1] <== 57; eq[81][i] = IsEqual(); eq[81][i].in[0] <== in[i]; - eq[81][i].in[1] <== 57; - eq[82][i] = IsEqual(); - eq[82][i].in[0] <== in[i]; - eq[82][i].in[1] <== 61; - eq[83][i] = IsEqual(); - eq[83][i].in[0] <== in[i]; - eq[83][i].in[1] <== 63; + eq[81][i].in[1] <== 61; and[44][i] = AND(); and[44][i].a <== states[i][9]; - multi_or[15][i] = MultiOR(24); + multi_or[15][i] = MultiOR(23); multi_or[15][i].in[0] <== and[42][i].out; multi_or[15][i].in[1] <== and[43][i].out; - multi_or[15][i].in[2] <== eq[62][i].out; - multi_or[15][i].in[3] <== eq[63][i].out; - multi_or[15][i].in[4] <== eq[64][i].out; - multi_or[15][i].in[5] <== eq[65][i].out; - multi_or[15][i].in[6] <== eq[66][i].out; - multi_or[15][i].in[7] <== eq[67][i].out; - multi_or[15][i].in[8] <== eq[68][i].out; - multi_or[15][i].in[9] <== eq[69][i].out; - multi_or[15][i].in[10] <== eq[70][i].out; - multi_or[15][i].in[11] <== eq[71][i].out; - multi_or[15][i].in[12] <== eq[72][i].out; - multi_or[15][i].in[13] <== eq[73][i].out; - multi_or[15][i].in[14] <== eq[74][i].out; - multi_or[15][i].in[15] <== eq[75][i].out; - multi_or[15][i].in[16] <== eq[76][i].out; - multi_or[15][i].in[17] <== eq[77][i].out; - multi_or[15][i].in[18] <== eq[78][i].out; - multi_or[15][i].in[19] <== eq[79][i].out; - multi_or[15][i].in[20] <== eq[80][i].out; - multi_or[15][i].in[21] <== eq[81][i].out; - multi_or[15][i].in[22] <== eq[82][i].out; - multi_or[15][i].in[23] <== eq[83][i].out; + multi_or[15][i].in[2] <== eq[61][i].out; + multi_or[15][i].in[3] <== eq[62][i].out; + multi_or[15][i].in[4] <== eq[63][i].out; + multi_or[15][i].in[5] <== eq[64][i].out; + multi_or[15][i].in[6] <== eq[65][i].out; + multi_or[15][i].in[7] <== eq[66][i].out; + multi_or[15][i].in[8] <== eq[67][i].out; + multi_or[15][i].in[9] <== eq[68][i].out; + multi_or[15][i].in[10] <== eq[69][i].out; + multi_or[15][i].in[11] <== eq[70][i].out; + multi_or[15][i].in[12] <== eq[71][i].out; + multi_or[15][i].in[13] <== eq[72][i].out; + multi_or[15][i].in[14] <== eq[73][i].out; + multi_or[15][i].in[15] <== eq[74][i].out; + multi_or[15][i].in[16] <== eq[75][i].out; + multi_or[15][i].in[17] <== eq[76][i].out; + multi_or[15][i].in[18] <== eq[77][i].out; + multi_or[15][i].in[19] <== eq[78][i].out; + multi_or[15][i].in[20] <== eq[79][i].out; + multi_or[15][i].in[21] <== eq[80][i].out; + multi_or[15][i].in[22] <== eq[81][i].out; and[44][i].b <== multi_or[15][i].out; - and[45][i] = AND(); - and[45][i].a <== states[i][10]; - and[45][i].b <== multi_or[15][i].out; - multi_or[16][i] = MultiOR(2); - multi_or[16][i].in[0] <== and[44][i].out; - multi_or[16][i].in[1] <== and[45][i].out; - states[i+1][10] <== multi_or[16][i].out; - and[46][i] = AND(); - and[46][i].a <== states[i][10]; - and[46][i].b <== eq[17][i].out; - states[i+1][11] <== and[46][i].out; lt[22][i] = LessEqThan(8); - lt[22][i].in[0] <== 97; + lt[22][i].in[0] <== 65; lt[22][i].in[1] <== in[i]; lt[23][i] = LessEqThan(8); lt[23][i].in[0] <== in[i]; - lt[23][i].in[1] <== 122; - and[47][i] = AND(); - and[47][i].a <== lt[22][i].out; - and[47][i].b <== lt[23][i].out; + lt[23][i].in[1] <== 90; + and[45][i] = AND(); + and[45][i].a <== lt[22][i].out; + and[45][i].b <== lt[23][i].out; + eq[82][i] = IsEqual(); + eq[82][i].in[0] <== in[i]; + eq[82][i].in[1] <== 63; + and[46][i] = AND(); + and[46][i].a <== states[i][10]; + multi_or[16][i] = MultiOR(24); + multi_or[16][i].in[0] <== and[45][i].out; + multi_or[16][i].in[1] <== and[43][i].out; + multi_or[16][i].in[2] <== eq[61][i].out; + multi_or[16][i].in[3] <== eq[62][i].out; + multi_or[16][i].in[4] <== eq[63][i].out; + multi_or[16][i].in[5] <== eq[64][i].out; + multi_or[16][i].in[6] <== eq[65][i].out; + multi_or[16][i].in[7] <== eq[66][i].out; + multi_or[16][i].in[8] <== eq[67][i].out; + multi_or[16][i].in[9] <== eq[68][i].out; + multi_or[16][i].in[10] <== eq[69][i].out; + multi_or[16][i].in[11] <== eq[70][i].out; + multi_or[16][i].in[12] <== eq[71][i].out; + multi_or[16][i].in[13] <== eq[72][i].out; + multi_or[16][i].in[14] <== eq[73][i].out; + multi_or[16][i].in[15] <== eq[74][i].out; + multi_or[16][i].in[16] <== eq[75][i].out; + multi_or[16][i].in[17] <== eq[76][i].out; + multi_or[16][i].in[18] <== eq[77][i].out; + multi_or[16][i].in[19] <== eq[78][i].out; + multi_or[16][i].in[20] <== eq[79][i].out; + multi_or[16][i].in[21] <== eq[80][i].out; + multi_or[16][i].in[22] <== eq[81][i].out; + multi_or[16][i].in[23] <== eq[82][i].out; + and[46][i].b <== multi_or[16][i].out; + eq[83][i] = IsEqual(); + eq[83][i].in[0] <== in[i]; + eq[83][i].in[1] <== 94; eq[84][i] = IsEqual(); eq[84][i].in[0] <== in[i]; - eq[84][i].in[1] <== 95; + eq[84][i].in[1] <== 96; + eq[85][i] = IsEqual(); + eq[85][i].in[0] <== in[i]; + eq[85][i].in[1] <== 123; + eq[86][i] = IsEqual(); + eq[86][i].in[0] <== in[i]; + eq[86][i].in[1] <== 124; + eq[87][i] = IsEqual(); + eq[87][i].in[0] <== in[i]; + eq[87][i].in[1] <== 125; + eq[88][i] = IsEqual(); + eq[88][i].in[0] <== in[i]; + eq[88][i].in[1] <== 126; + and[47][i] = AND(); + and[47][i].a <== states[i][11]; + multi_or[17][i] = MultiOR(16); + multi_or[17][i].in[0] <== eq[61][i].out; + multi_or[17][i].in[1] <== eq[62][i].out; + multi_or[17][i].in[2] <== eq[63][i].out; + multi_or[17][i].in[3] <== eq[64][i].out; + multi_or[17][i].in[4] <== eq[65][i].out; + multi_or[17][i].in[5] <== eq[66][i].out; + multi_or[17][i].in[6] <== eq[67][i].out; + multi_or[17][i].in[7] <== eq[68][i].out; + multi_or[17][i].in[8] <== eq[81][i].out; + multi_or[17][i].in[9] <== eq[82][i].out; + multi_or[17][i].in[10] <== eq[83][i].out; + multi_or[17][i].in[11] <== eq[84][i].out; + multi_or[17][i].in[12] <== eq[85][i].out; + multi_or[17][i].in[13] <== eq[86][i].out; + multi_or[17][i].in[14] <== eq[87][i].out; + multi_or[17][i].in[15] <== eq[88][i].out; + and[47][i].b <== multi_or[17][i].out; and[48][i] = AND(); - and[48][i].a <== states[i][11]; - multi_or[17][i] = MultiOR(15); - multi_or[17][i].in[0] <== and[42][i].out; - multi_or[17][i].in[1] <== and[47][i].out; - multi_or[17][i].in[2] <== eq[70][i].out; - multi_or[17][i].in[3] <== eq[71][i].out; - multi_or[17][i].in[4] <== eq[72][i].out; - multi_or[17][i].in[5] <== eq[73][i].out; - multi_or[17][i].in[6] <== eq[74][i].out; - multi_or[17][i].in[7] <== eq[75][i].out; - multi_or[17][i].in[8] <== eq[76][i].out; - multi_or[17][i].in[9] <== eq[77][i].out; - multi_or[17][i].in[10] <== eq[78][i].out; - multi_or[17][i].in[11] <== eq[79][i].out; - multi_or[17][i].in[12] <== eq[80][i].out; - multi_or[17][i].in[13] <== eq[81][i].out; - multi_or[17][i].in[14] <== eq[84][i].out; + and[48][i].a <== states[i][12]; and[48][i].b <== multi_or[17][i].out; + multi_or[18][i] = MultiOR(4); + multi_or[18][i].in[0] <== and[44][i].out; + multi_or[18][i].in[1] <== and[46][i].out; + multi_or[18][i].in[2] <== and[47][i].out; + multi_or[18][i].in[3] <== and[48][i].out; + states[i+1][10] <== multi_or[18][i].out; + eq[89][i] = IsEqual(); + eq[89][i].in[0] <== in[i]; + eq[89][i].in[1] <== 64; and[49][i] = AND(); - and[49][i].a <== states[i][12]; - and[49][i].b <== multi_or[17][i].out; - multi_or[18][i] = MultiOR(2); - multi_or[18][i].in[0] <== and[48][i].out; - multi_or[18][i].in[1] <== and[49][i].out; - states[i+1][12] <== multi_or[18][i].out; + and[49][i].a <== states[i][10]; + and[49][i].b <== eq[89][i].out; and[50][i] = AND(); - and[50][i].a <== states[i][12]; - and[50][i].b <== eq[16][i].out; - states[i+1][13] <== and[50][i].out; + and[50][i].a <== states[i][11]; + and[50][i].b <== eq[89][i].out; + and[51][i] = AND(); + and[51][i].a <== states[i][12]; + and[51][i].b <== eq[89][i].out; + multi_or[19][i] = MultiOR(3); + multi_or[19][i].in[0] <== and[49][i].out; + multi_or[19][i].in[1] <== and[50][i].out; + multi_or[19][i].in[2] <== and[51][i].out; + states[i+1][11] <== multi_or[19][i].out; + lt[24][i] = LessEqThan(8); + lt[24][i].in[0] <== 97; + lt[24][i].in[1] <== in[i]; + lt[25][i] = LessEqThan(8); + lt[25][i].in[0] <== in[i]; + lt[25][i].in[1] <== 122; + and[52][i] = AND(); + and[52][i].a <== lt[24][i].out; + and[52][i].b <== lt[25][i].out; + eq[90][i] = IsEqual(); + eq[90][i].in[0] <== in[i]; + eq[90][i].in[1] <== 95; + and[53][i] = AND(); + and[53][i].a <== states[i][11]; + multi_or[20][i] = MultiOR(15); + multi_or[20][i].in[0] <== and[45][i].out; + multi_or[20][i].in[1] <== and[52][i].out; + multi_or[20][i].in[2] <== eq[69][i].out; + multi_or[20][i].in[3] <== eq[70][i].out; + multi_or[20][i].in[4] <== eq[71][i].out; + multi_or[20][i].in[5] <== eq[72][i].out; + multi_or[20][i].in[6] <== eq[73][i].out; + multi_or[20][i].in[7] <== eq[74][i].out; + multi_or[20][i].in[8] <== eq[75][i].out; + multi_or[20][i].in[9] <== eq[76][i].out; + multi_or[20][i].in[10] <== eq[77][i].out; + multi_or[20][i].in[11] <== eq[78][i].out; + multi_or[20][i].in[12] <== eq[79][i].out; + multi_or[20][i].in[13] <== eq[80][i].out; + multi_or[20][i].in[14] <== eq[90][i].out; + and[53][i].b <== multi_or[20][i].out; + and[54][i] = AND(); + and[54][i].a <== states[i][12]; + and[54][i].b <== multi_or[20][i].out; + multi_or[21][i] = MultiOR(2); + multi_or[21][i].in[0] <== and[53][i].out; + multi_or[21][i].in[1] <== and[54][i].out; + states[i+1][12] <== multi_or[21][i].out; + and[55][i] = AND(); + and[55][i].a <== states[i][12]; + and[55][i].b <== eq[18][i].out; + states[i+1][13] <== and[55][i].out; from_zero_enabled[i] <== MultiNOR(13)([states_tmp[i+1][1], states_tmp[i+1][2], states_tmp[i+1][3], states_tmp[i+1][4], states_tmp[i+1][5], states_tmp[i+1][6], states_tmp[i+1][7], states_tmp[i+1][8], states[i+1][9], states[i+1][10], states[i+1][11], states[i+1][12], states[i+1][13]]); states[i+1][1] <== MultiOR(2)([states_tmp[i+1][1], from_zero_enabled[i] * and[1][i].out]); states[i+1][2] <== MultiOR(2)([states_tmp[i+1][2], from_zero_enabled[i] * and[10][i].out]); @@ -758,19 +815,23 @@ template EmailAddrWithNameRegex(msg_bytes) { is_consecutive[msg_bytes-1-i][1] <== state_changed[msg_bytes-i].out * is_consecutive[msg_bytes-1-i][0]; is_consecutive[msg_bytes-1-i][2] <== ORAnd()([(1 - from_zero_enabled[msg_bytes-i+1]), states[num_bytes-i][13], is_consecutive[msg_bytes-1-i][1]]); } - // substrings calculated: [{(9, 10), (10, 10), (10, 11), (11, 12), (12, 12)}] - signal prev_states0[5][msg_bytes]; + // substrings calculated: [{(9, 10), (10, 10), (10, 11), (11, 10), (11, 11), (11, 12), (12, 10), (12, 11), (12, 12)}] + signal prev_states0[9][msg_bytes]; signal is_substr0[msg_bytes]; signal is_reveal0[msg_bytes]; signal output reveal0[msg_bytes]; for (var i = 0; i < msg_bytes; i++) { - // the 0-th substring transitions: [(9, 10), (10, 10), (10, 11), (11, 12), (12, 12)] + // the 0-th substring transitions: [(9, 10), (10, 10), (10, 11), (11, 10), (11, 11), (11, 12), (12, 10), (12, 11), (12, 12)] prev_states0[0][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][9]; prev_states0[1][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][10]; prev_states0[2][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][10]; prev_states0[3][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][11]; - prev_states0[4][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][12]; - is_substr0[i] <== MultiOR(5)([prev_states0[0][i] * states[i+2][10], prev_states0[1][i] * states[i+2][10], prev_states0[2][i] * states[i+2][11], prev_states0[3][i] * states[i+2][12], prev_states0[4][i] * states[i+2][12]]); + prev_states0[4][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][11]; + prev_states0[5][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][11]; + prev_states0[6][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][12]; + prev_states0[7][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][12]; + prev_states0[8][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][12]; + is_substr0[i] <== MultiOR(9)([prev_states0[0][i] * states[i+2][10], prev_states0[1][i] * states[i+2][10], prev_states0[2][i] * states[i+2][11], prev_states0[3][i] * states[i+2][10], prev_states0[4][i] * states[i+2][11], prev_states0[5][i] * states[i+2][12], prev_states0[6][i] * states[i+2][10], prev_states0[7][i] * states[i+2][11], prev_states0[8][i] * states[i+2][12]]); is_reveal0[i] <== MultiAND(3)([out, is_substr0[i], is_consecutive[i][2]]); reveal0[i] <== in[i+1] * is_reveal0[i]; } diff --git a/packages/circom/circuits/common/email_domain.json b/packages/circom/circuits/common/email_domain.json index e20587e..0ed11e3 100644 --- a/packages/circom/circuits/common/email_domain.json +++ b/packages/circom/circuits/common/email_domain.json @@ -2,15 +2,11 @@ "parts": [ { "is_public": false, - "regex_def": "[A-Za-z0-9!#$%&'*+-/=?\\^_`{\\|}~\\.]+" - }, - { - "is_public": false, - "regex_def": "@" + "regex_def": "[A-Za-z0-9!#$%&'*+=?\\-\\^_`{|}~.]+@" }, { "is_public": true, - "regex_def": "[A-Za-z0-9\\.-]+" + "regex_def": "[A-Za-z0-9.\\-@]+" } ] -} +} \ No newline at end of file diff --git a/packages/circom/circuits/common/email_domain_regex.circom b/packages/circom/circuits/common/email_domain_regex.circom index 8fd4ca7..d30291d 100644 --- a/packages/circom/circuits/common/email_domain_regex.circom +++ b/packages/circom/circuits/common/email_domain_regex.circom @@ -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 EmailDomainRegex(msg_bytes) { signal input msg[msg_bytes]; signal output out; @@ -14,9 +14,9 @@ template EmailDomainRegex(msg_bytes) { in[i+1] <== msg[i]; } - component eq[25][num_bytes]; - component lt[6][num_bytes]; - component and[8][num_bytes]; + component eq[23][num_bytes]; + component lt[8][num_bytes]; + component and[9][num_bytes]; component multi_or[3][num_bytes]; signal states[num_bytes+1][4]; signal states_tmp[num_bytes+1][4]; @@ -75,55 +75,49 @@ template EmailDomainRegex(msg_bytes) { eq[7][i].in[1] <== 43; eq[8][i] = IsEqual(); eq[8][i].in[0] <== in[i]; - eq[8][i].in[1] <== 44; + eq[8][i].in[1] <== 45; eq[9][i] = IsEqual(); eq[9][i].in[0] <== in[i]; - eq[9][i].in[1] <== 45; + eq[9][i].in[1] <== 46; eq[10][i] = IsEqual(); eq[10][i].in[0] <== in[i]; - eq[10][i].in[1] <== 46; + eq[10][i].in[1] <== 48; eq[11][i] = IsEqual(); eq[11][i].in[0] <== in[i]; - eq[11][i].in[1] <== 47; + eq[11][i].in[1] <== 49; eq[12][i] = IsEqual(); eq[12][i].in[0] <== in[i]; - eq[12][i].in[1] <== 48; + eq[12][i].in[1] <== 50; eq[13][i] = IsEqual(); eq[13][i].in[0] <== in[i]; - eq[13][i].in[1] <== 49; + eq[13][i].in[1] <== 51; eq[14][i] = IsEqual(); eq[14][i].in[0] <== in[i]; - eq[14][i].in[1] <== 50; + eq[14][i].in[1] <== 52; eq[15][i] = IsEqual(); eq[15][i].in[0] <== in[i]; - eq[15][i].in[1] <== 51; + eq[15][i].in[1] <== 53; eq[16][i] = IsEqual(); eq[16][i].in[0] <== in[i]; - eq[16][i].in[1] <== 52; + eq[16][i].in[1] <== 54; eq[17][i] = IsEqual(); eq[17][i].in[0] <== in[i]; - eq[17][i].in[1] <== 53; + eq[17][i].in[1] <== 55; eq[18][i] = IsEqual(); eq[18][i].in[0] <== in[i]; - eq[18][i].in[1] <== 54; + eq[18][i].in[1] <== 56; eq[19][i] = IsEqual(); eq[19][i].in[0] <== in[i]; - eq[19][i].in[1] <== 55; + eq[19][i].in[1] <== 57; eq[20][i] = IsEqual(); eq[20][i].in[0] <== in[i]; - eq[20][i].in[1] <== 56; + eq[20][i].in[1] <== 61; eq[21][i] = IsEqual(); eq[21][i].in[0] <== in[i]; - eq[21][i].in[1] <== 57; - eq[22][i] = IsEqual(); - eq[22][i].in[0] <== in[i]; - eq[22][i].in[1] <== 61; - eq[23][i] = IsEqual(); - eq[23][i].in[0] <== in[i]; - eq[23][i].in[1] <== 63; + eq[21][i].in[1] <== 63; and[2][i] = AND(); and[2][i].a <== states[i][0]; - multi_or[0][i] = MultiOR(26); + 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; @@ -148,53 +142,60 @@ template EmailDomainRegex(msg_bytes) { 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; - multi_or[0][i].in[24] <== eq[22][i].out; - multi_or[0][i].in[25] <== eq[23][i].out; and[2][i].b <== multi_or[0][i].out; and[3][i] = AND(); and[3][i].a <== states[i][1]; and[3][i].b <== multi_or[0][i].out; states_tmp[i+1][1] <== and[3][i].out; - eq[24][i] = IsEqual(); - eq[24][i].in[0] <== in[i]; - eq[24][i].in[1] <== 64; + eq[22][i] = IsEqual(); + eq[22][i].in[0] <== in[i]; + eq[22][i].in[1] <== 64; and[4][i] = AND(); and[4][i].a <== states[i][1]; - and[4][i].b <== eq[24][i].out; + and[4][i].b <== eq[22][i].out; states[i+1][2] <== and[4][i].out; lt[4][i] = LessEqThan(8); - lt[4][i].in[0] <== 97; + lt[4][i].in[0] <== 64; lt[4][i].in[1] <== in[i]; lt[5][i] = LessEqThan(8); lt[5][i].in[0] <== in[i]; - lt[5][i].in[1] <== 122; + lt[5][i].in[1] <== 90; and[5][i] = AND(); and[5][i].a <== lt[4][i].out; and[5][i].b <== lt[5][i].out; + lt[6][i] = LessEqThan(8); + lt[6][i].in[0] <== 97; + lt[6][i].in[1] <== in[i]; + lt[7][i] = LessEqThan(8); + lt[7][i].in[0] <== in[i]; + lt[7][i].in[1] <== 122; and[6][i] = AND(); - and[6][i].a <== states[i][2]; - multi_or[1][i] = MultiOR(14); - multi_or[1][i].in[0] <== and[0][i].out; - multi_or[1][i].in[1] <== and[5][i].out; - multi_or[1][i].in[2] <== eq[9][i].out; - multi_or[1][i].in[3] <== eq[10][i].out; - multi_or[1][i].in[4] <== eq[12][i].out; - multi_or[1][i].in[5] <== eq[13][i].out; - multi_or[1][i].in[6] <== eq[14][i].out; - multi_or[1][i].in[7] <== eq[15][i].out; - multi_or[1][i].in[8] <== eq[16][i].out; - multi_or[1][i].in[9] <== eq[17][i].out; - multi_or[1][i].in[10] <== eq[18][i].out; - multi_or[1][i].in[11] <== eq[19][i].out; - multi_or[1][i].in[12] <== eq[20][i].out; - multi_or[1][i].in[13] <== eq[21][i].out; - and[6][i].b <== multi_or[1][i].out; + and[6][i].a <== lt[6][i].out; + and[6][i].b <== lt[7][i].out; and[7][i] = AND(); - and[7][i].a <== states[i][3]; + and[7][i].a <== states[i][2]; + multi_or[1][i] = MultiOR(14); + multi_or[1][i].in[0] <== and[5][i].out; + multi_or[1][i].in[1] <== and[6][i].out; + multi_or[1][i].in[2] <== eq[8][i].out; + multi_or[1][i].in[3] <== eq[9][i].out; + multi_or[1][i].in[4] <== eq[10][i].out; + multi_or[1][i].in[5] <== eq[11][i].out; + multi_or[1][i].in[6] <== eq[12][i].out; + multi_or[1][i].in[7] <== eq[13][i].out; + multi_or[1][i].in[8] <== eq[14][i].out; + multi_or[1][i].in[9] <== eq[15][i].out; + multi_or[1][i].in[10] <== eq[16][i].out; + multi_or[1][i].in[11] <== eq[17][i].out; + multi_or[1][i].in[12] <== eq[18][i].out; + multi_or[1][i].in[13] <== eq[19][i].out; and[7][i].b <== multi_or[1][i].out; + and[8][i] = AND(); + and[8][i].a <== states[i][3]; + and[8][i].b <== multi_or[1][i].out; multi_or[2][i] = MultiOR(2); - multi_or[2][i].in[0] <== and[6][i].out; - multi_or[2][i].in[1] <== and[7][i].out; + multi_or[2][i].in[0] <== and[7][i].out; + multi_or[2][i].in[1] <== and[8][i].out; states[i+1][3] <== multi_or[2][i].out; from_zero_enabled[i] <== MultiNOR(3)([states_tmp[i+1][1], states[i+1][2], states[i+1][3]]); states[i+1][1] <== MultiOR(2)([states_tmp[i+1][1], from_zero_enabled[i] * and[2][i].out]); diff --git a/packages/circom/circuits/common/from_addr.json b/packages/circom/circuits/common/from_addr.json index 56a5e2a..e4ca91d 100644 --- a/packages/circom/circuits/common/from_addr.json +++ b/packages/circom/circuits/common/from_addr.json @@ -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, diff --git a/packages/circom/circuits/common/to_addr.json b/packages/circom/circuits/common/to_addr.json index 618c55f..0744491 100644 --- a/packages/circom/circuits/common/to_addr.json +++ b/packages/circom/circuits/common/to_addr.json @@ -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, diff --git a/packages/circom/tests/email_addr.test.js b/packages/circom/tests/email_addr.test.js index dcf9999..5556252 100644 --- a/packages/circom/tests/email_addr.test.js +++ b/packages/circom/tests/email_addr.test.js @@ -69,4 +69,48 @@ describe("Email Address Regex", () => { } } }); + + it("@ inside the name part", async () => { + const prefix = "subject:"; + const emailAddr = "suegamisora@gmail.com@dummy.com"; + const string = prefix + emailAddr; + const paddedStr = apis.padString(string, 256); + const circuitInputs = { + msg: paddedStr, + }; + const witness = await circuit.calculateWitness(circuitInputs); + await circuit.checkConstraints(witness); + expect(1n).toEqual(witness[1]); + const prefixIdxes = apis.extractEmailAddrIdxes(string)[0]; + for (let idx = 0; idx < 256; ++idx) { + console.log(idx, witness[2 + idx]) + if (idx >= prefixIdxes[0] && idx < prefixIdxes[1]) { + expect(BigInt(paddedStr[idx])).toEqual(witness[2 + idx]); + } else { + expect(0n).toEqual(witness[2 + idx]); + } + } + }); + + it("starts from @", async () => { + const prefix = "subject:"; + const emailAddr = "@gmail.com@dummy.com"; + const string = prefix + emailAddr; + const paddedStr = apis.padString(string, 256); + const circuitInputs = { + msg: paddedStr, + }; + const witness = await circuit.calculateWitness(circuitInputs); + await circuit.checkConstraints(witness); + expect(1n).toEqual(witness[1]); + const prefixIdxes = apis.extractEmailAddrIdxes(string)[0]; + for (let idx = 0; idx < 256; ++idx) { + console.log(idx, witness[2 + idx]) + if (idx >= prefixIdxes[0] && idx < prefixIdxes[1]) { + expect(BigInt(paddedStr[idx])).toEqual(witness[2 + idx]); + } else { + expect(0n).toEqual(witness[2 + idx]); + } + } + }); }); diff --git a/packages/circom/tests/email_domain.test.js b/packages/circom/tests/email_domain.test.js index a73173b..0c33612 100644 --- a/packages/circom/tests/email_domain.test.js +++ b/packages/circom/tests/email_domain.test.js @@ -39,10 +39,47 @@ describe("Email Domain Regex", () => { const witness = await circuit.calculateWitness(circuitInputs); await circuit.checkConstraints(witness); expect(1n).toEqual(witness[1]); - for (let idx = 0; idx < 12; ++idx) { - expect(0n).toEqual(witness[2 + idx]); + const prefixIdxes = apis.extractEmailDomainIdxes(emailAddr)[0]; + for (let idx = 0; idx < 256; ++idx) { + if (idx >= prefixIdxes[0] && idx < prefixIdxes[1]) { + expect(BigInt(paddedStr[idx])).toEqual(witness[2 + idx]); + } else { + expect(0n).toEqual(witness[2 + idx]); + } } + }); + + it("@ inside the name part", async () => { + const emailAddr = "suegamisora@gmail.com@dummy.com"; + const paddedStr = apis.padString(emailAddr, 256); + const circuitInputs = { + msg: paddedStr, + }; + const witness = await circuit.calculateWitness(circuitInputs); + await circuit.checkConstraints(witness); + expect(1n).toEqual(witness[1]); + const prefixIdxes = apis.extractEmailDomainIdxes(emailAddr)[0]; + expect("gmail.com@dummy.com").toEqual(emailAddr.slice(prefixIdxes[0], prefixIdxes[1])); + for (let idx = 0; idx < 256; ++idx) { + if (idx >= prefixIdxes[0] && idx < prefixIdxes[1]) { + expect(BigInt(paddedStr[idx])).toEqual(witness[2 + idx]); + } else { + expect(0n).toEqual(witness[2 + idx]); + } + } + }); + + it("starts from @", async () => { + const emailAddr = "@gmail.com@dummy.com"; + const paddedStr = apis.padString(emailAddr, 256); + const circuitInputs = { + msg: paddedStr, + }; + const witness = await circuit.calculateWitness(circuitInputs); + await circuit.checkConstraints(witness); + expect(1n).toEqual(witness[1]); const prefixIdxes = apis.extractEmailDomainIdxes(emailAddr)[0]; + expect("dummy.com").toEqual(emailAddr.slice(prefixIdxes[0], prefixIdxes[1])); for (let idx = 0; idx < 256; ++idx) { if (idx >= prefixIdxes[0] && idx < prefixIdxes[1]) { expect(BigInt(paddedStr[idx])).toEqual(witness[2 + idx]); diff --git a/packages/circom/tests/from_addr.test.js b/packages/circom/tests/from_addr.test.js index 234abd9..dba8b0a 100644 --- a/packages/circom/tests/from_addr.test.js +++ b/packages/circom/tests/from_addr.test.js @@ -228,4 +228,44 @@ describe("From Addr Regex", () => { await expect(failFn).rejects.toThrow(); }); + it("from field containing @ in the name part", async () => { + const fromStr = "from:Sora Suegami \r\n"; + const paddedStr = apis.padString(fromStr, 1024); + const circuitInputs = { + msg: paddedStr, + }; + const witness = await circuit.calculateWitness(circuitInputs); + await circuit.checkConstraints(witness); + expect(1n).toEqual(witness[1]); + const prefixIdxes = apis.extractFromAddrIdxes(fromStr)[0]; + expect("suegamisora@gmail.com@dummy.com").toEqual(fromStr.slice(prefixIdxes[0], prefixIdxes[1])); + for (let idx = 0; idx < 1024; ++idx) { + if (idx >= prefixIdxes[0] && idx < prefixIdxes[1]) { + expect(BigInt(paddedStr[idx])).toEqual(witness[2 + idx]); + } else { + expect(0n).toEqual(witness[2 + idx]); + } + } + }); + + it("from field starting from @", async () => { + const fromStr = "from:Sora Suegami <@gmail.com@dummy.com>\r\n"; + const paddedStr = apis.padString(fromStr, 1024); + const circuitInputs = { + msg: paddedStr, + }; + const witness = await circuit.calculateWitness(circuitInputs); + await circuit.checkConstraints(witness); + expect(1n).toEqual(witness[1]); + const prefixIdxes = apis.extractFromAddrIdxes(fromStr)[0]; + expect("@gmail.com@dummy.com").toEqual(fromStr.slice(prefixIdxes[0], prefixIdxes[1])); + for (let idx = 0; idx < 1024; ++idx) { + if (idx >= prefixIdxes[0] && idx < prefixIdxes[1]) { + expect(BigInt(paddedStr[idx])).toEqual(witness[2 + idx]); + } else { + expect(0n).toEqual(witness[2 + idx]); + } + } + }); + }); diff --git a/packages/circom/tests/to_addr.test.js b/packages/circom/tests/to_addr.test.js index e981147..f6b3a62 100644 --- a/packages/circom/tests/to_addr.test.js +++ b/packages/circom/tests/to_addr.test.js @@ -226,4 +226,44 @@ describe("To Addr Regex", () => { } await expect(failFn).rejects.toThrow(); }); + + it("to field containing @ in the name part", async () => { + const toStr = "to:Aditya Bisht \r\n"; + const paddedStr = apis.padString(toStr, 1024); + const circuitInputs = { + msg: paddedStr, + }; + const witness = await circuit.calculateWitness(circuitInputs); + await circuit.checkConstraints(witness); + expect(1n).toEqual(witness[1]); + const prefixIdxes = apis.extractToAddrIdxes(toStr)[0]; + expect("adityabisht@gmail.com@dummy.com").toEqual(toStr.slice(prefixIdxes[0], prefixIdxes[1])); + for (let idx = 0; idx < 1024; ++idx) { + if (idx >= prefixIdxes[0] && idx < prefixIdxes[1]) { + expect(BigInt(paddedStr[idx])).toEqual(witness[2 + idx]); + } else { + expect(0n).toEqual(witness[2 + idx]); + } + } + }); + + it("to field starting from @", async () => { + const toStr = "to:Aditya Bisht <@gmail.com@dummy.com>\r\n"; + const paddedStr = apis.padString(toStr, 1024); + const circuitInputs = { + msg: paddedStr, + }; + const witness = await circuit.calculateWitness(circuitInputs); + await circuit.checkConstraints(witness); + expect(1n).toEqual(witness[1]); + const prefixIdxes = apis.extractToAddrIdxes(toStr)[0]; + expect("@gmail.com@dummy.com").toEqual(toStr.slice(prefixIdxes[0], prefixIdxes[1])); + for (let idx = 0; idx < 1024; ++idx) { + if (idx >= prefixIdxes[0] && idx < prefixIdxes[1]) { + expect(BigInt(paddedStr[idx])).toEqual(witness[2 + idx]); + } else { + expect(0n).toEqual(witness[2 + idx]); + } + } + }); }); From 9db767d1657f5a3b911558779d12f7a049ff5f15 Mon Sep 17 00:00:00 2001 From: SoraSuegami Date: Tue, 27 Aug 2024 17:14:15 +0900 Subject: [PATCH 3/4] Add note about email domain circuit to README --- packages/circom/README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/circom/README.md b/packages/circom/README.md index 5a6589a..eb9bffb 100644 --- a/packages/circom/README.md +++ b/packages/circom/README.md @@ -2,4 +2,6 @@ Circom circuits for regex verification in [zk-regex](https://github.com/zkemail/zk-regex/tree/main). This package contains circom circuits and decomposed regex definitions for common regexes in `./circuits/common` folder. - \ No newline at end of file + +## Note +Our `email_domain_regex.circom` circuit cannot capture an email address that contains "@" in the name part before the domain part, e.g., "alice@gmail.com@dummy.com", due to limitation of our circuit construction. For example, when "alice@gmail.com@dummy.com" is given, that circuit outputs not "dummy.com" but "gmail.com@dummy.com" as an exposed substring for the domain. However, an adversary cannot exploit this feature to expose a fake domain since the true domain at the end will also be revealed along with it. \ No newline at end of file From f71b30bde3fc2a2ba79fe151711552882ea4e707 Mon Sep 17 00:00:00 2001 From: SoraSuegami Date: Fri, 30 Aug 2024 22:34:20 +0900 Subject: [PATCH 4/4] Fix email address regex --- .../apis/src/decomposed_defs/email_addr.json | 2 +- .../decomposed_defs/email_addr_with_name.json | 2 +- .../src/decomposed_defs/email_domain.json | 2 +- .../apis/src/decomposed_defs/from_addr.json | 2 +- .../apis/src/decomposed_defs/to_addr.json | 2 +- .../circom/circuits/common/email_addr.json | 2 +- .../circuits/common/email_addr_regex.circom | 96 ++-- .../circuits/common/email_addr_with_name.json | 2 +- .../common/email_addr_with_name_regex.circom | 412 +++++++++--------- .../circom/circuits/common/email_domain.json | 2 +- .../circuits/common/email_domain_regex.circom | 62 +-- .../circom/circuits/common/from_addr.json | 2 +- packages/circom/circuits/common/to_addr.json | 2 +- packages/circom/tests/email_addr.test.js | 2 - 14 files changed, 301 insertions(+), 291 deletions(-) diff --git a/packages/apis/src/decomposed_defs/email_addr.json b/packages/apis/src/decomposed_defs/email_addr.json index b2f4f39..2b45be1 100644 --- a/packages/apis/src/decomposed_defs/email_addr.json +++ b/packages/apis/src/decomposed_defs/email_addr.json @@ -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.\\-]+" } ] } \ No newline at end of file diff --git a/packages/apis/src/decomposed_defs/email_addr_with_name.json b/packages/apis/src/decomposed_defs/email_addr_with_name.json index bff6d58..999ea3e 100644 --- a/packages/apis/src/decomposed_defs/email_addr_with_name.json +++ b/packages/apis/src/decomposed_defs/email_addr_with_name.json @@ -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, diff --git a/packages/apis/src/decomposed_defs/email_domain.json b/packages/apis/src/decomposed_defs/email_domain.json index 0ed11e3..7051e3a 100644 --- a/packages/apis/src/decomposed_defs/email_domain.json +++ b/packages/apis/src/decomposed_defs/email_domain.json @@ -2,7 +2,7 @@ "parts": [ { "is_public": false, - "regex_def": "[A-Za-z0-9!#$%&'*+=?\\-\\^_`{|}~.]+@" + "regex_def": "[A-Za-z0-9!#$%&'*+=?\\-\\^_`{|}~./]+@" }, { "is_public": true, diff --git a/packages/apis/src/decomposed_defs/from_addr.json b/packages/apis/src/decomposed_defs/from_addr.json index e4ca91d..82fefdd 100644 --- a/packages/apis/src/decomposed_defs/from_addr.json +++ b/packages/apis/src/decomposed_defs/from_addr.json @@ -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, diff --git a/packages/apis/src/decomposed_defs/to_addr.json b/packages/apis/src/decomposed_defs/to_addr.json index 0744491..9c7a4b1 100644 --- a/packages/apis/src/decomposed_defs/to_addr.json +++ b/packages/apis/src/decomposed_defs/to_addr.json @@ -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, diff --git a/packages/circom/circuits/common/email_addr.json b/packages/circom/circuits/common/email_addr.json index b2f4f39..2b45be1 100644 --- a/packages/circom/circuits/common/email_addr.json +++ b/packages/circom/circuits/common/email_addr.json @@ -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.\\-]+" } ] } \ No newline at end of file diff --git a/packages/circom/circuits/common/email_addr_regex.circom b/packages/circom/circuits/common/email_addr_regex.circom index 411ab2d..8f7005f 100644 --- a/packages/circom/circuits/common/email_addr_regex.circom +++ b/packages/circom/circuits/common/email_addr_regex.circom @@ -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; @@ -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]; @@ -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; @@ -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; @@ -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; @@ -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; @@ -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; @@ -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]; @@ -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; @@ -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]; diff --git a/packages/circom/circuits/common/email_addr_with_name.json b/packages/circom/circuits/common/email_addr_with_name.json index bff6d58..999ea3e 100644 --- a/packages/circom/circuits/common/email_addr_with_name.json +++ b/packages/circom/circuits/common/email_addr_with_name.json @@ -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, diff --git a/packages/circom/circuits/common/email_addr_with_name_regex.circom b/packages/circom/circuits/common/email_addr_with_name_regex.circom index 6325a09..f212271 100644 --- a/packages/circom/circuits/common/email_addr_with_name_regex.circom +++ b/packages/circom/circuits/common/email_addr_with_name_regex.circom @@ -2,7 +2,7 @@ pragma circom 2.1.5; include "@zk-email/zk-regex-circom/circuits/regex_helpers.circom"; -// regex: [^\r\n]+<[A-Za-z0-9!#$%&'*+=?\-\^_`{|}~.@]+@[a-zA-Z0-9_.\-]+> +// regex: [^\r\n]+<[A-Za-z0-9!#$%&'*+=?\-\^_`{|}~./@]+@[a-zA-Z0-9.\-]+> template EmailAddrWithNameRegex(msg_bytes) { signal input msg[msg_bytes]; signal output out; @@ -159,31 +159,28 @@ template EmailAddrWithNameRegex(msg_bytes) { eq[14][i].in[1] <== 44; eq[15][i] = IsEqual(); eq[15][i].in[0] <== in[i]; - eq[15][i].in[1] <== 47; + eq[15][i].in[1] <== 58; eq[16][i] = IsEqual(); eq[16][i].in[0] <== in[i]; - eq[16][i].in[1] <== 58; + eq[16][i].in[1] <== 59; eq[17][i] = IsEqual(); eq[17][i].in[0] <== in[i]; - eq[17][i].in[1] <== 59; + eq[17][i].in[1] <== 62; eq[18][i] = IsEqual(); eq[18][i].in[0] <== in[i]; - eq[18][i].in[1] <== 62; + eq[18][i].in[1] <== 91; eq[19][i] = IsEqual(); eq[19][i].in[0] <== in[i]; - eq[19][i].in[1] <== 91; + eq[19][i].in[1] <== 92; eq[20][i] = IsEqual(); eq[20][i].in[0] <== in[i]; - eq[20][i].in[1] <== 92; + eq[20][i].in[1] <== 93; eq[21][i] = IsEqual(); eq[21][i].in[0] <== in[i]; - eq[21][i].in[1] <== 93; - eq[22][i] = IsEqual(); - eq[22][i].in[0] <== in[i]; - eq[22][i].in[1] <== 127; + eq[21][i].in[1] <== 127; and[8][i] = AND(); and[8][i].a <== states[i][9]; - multi_or[2][i] = MultiOR(24); + multi_or[2][i] = MultiOR(23); multi_or[2][i].in[0] <== and[7][i].out; multi_or[2][i].in[1] <== eq[0][i].out; multi_or[2][i].in[2] <== eq[1][i].out; @@ -207,7 +204,6 @@ template EmailAddrWithNameRegex(msg_bytes) { multi_or[2][i].in[20] <== eq[19][i].out; multi_or[2][i].in[21] <== eq[20][i].out; multi_or[2][i].in[22] <== eq[21][i].out; - multi_or[2][i].in[23] <== eq[22][i].out; and[8][i].b <== multi_or[2][i].out; multi_or[3][i] = MultiOR(3); multi_or[3][i].in[0] <== and[4][i].out; @@ -266,81 +262,81 @@ template EmailAddrWithNameRegex(msg_bytes) { multi_or[4][i].in[3] <== and[16][i].out; multi_or[4][i].in[4] <== and[17][i].out; states_tmp[i+1][2] <== multi_or[4][i].out; - eq[23][i] = IsEqual(); - eq[23][i].in[0] <== in[i]; - eq[23][i].in[1] <== 224; + eq[22][i] = IsEqual(); + eq[22][i].in[0] <== in[i]; + eq[22][i].in[1] <== 224; and[18][i] = AND(); and[18][i].a <== states[i][0]; - and[18][i].b <== eq[23][i].out; + and[18][i].b <== eq[22][i].out; and[19][i] = AND(); and[19][i].a <== states[i][1]; - and[19][i].b <== eq[23][i].out; + and[19][i].b <== eq[22][i].out; and[20][i] = AND(); and[20][i].a <== states[i][9]; - and[20][i].b <== eq[23][i].out; + and[20][i].b <== eq[22][i].out; multi_or[5][i] = MultiOR(2); multi_or[5][i].in[0] <== and[19][i].out; multi_or[5][i].in[1] <== and[20][i].out; states_tmp[i+1][3] <== multi_or[5][i].out; + eq[23][i] = IsEqual(); + eq[23][i].in[0] <== in[i]; + eq[23][i].in[1] <== 225; eq[24][i] = IsEqual(); eq[24][i].in[0] <== in[i]; - eq[24][i].in[1] <== 225; + eq[24][i].in[1] <== 226; eq[25][i] = IsEqual(); eq[25][i].in[0] <== in[i]; - eq[25][i].in[1] <== 226; + eq[25][i].in[1] <== 227; eq[26][i] = IsEqual(); eq[26][i].in[0] <== in[i]; - eq[26][i].in[1] <== 227; + eq[26][i].in[1] <== 228; eq[27][i] = IsEqual(); eq[27][i].in[0] <== in[i]; - eq[27][i].in[1] <== 228; + eq[27][i].in[1] <== 229; eq[28][i] = IsEqual(); eq[28][i].in[0] <== in[i]; - eq[28][i].in[1] <== 229; + eq[28][i].in[1] <== 230; eq[29][i] = IsEqual(); eq[29][i].in[0] <== in[i]; - eq[29][i].in[1] <== 230; + eq[29][i].in[1] <== 231; eq[30][i] = IsEqual(); eq[30][i].in[0] <== in[i]; - eq[30][i].in[1] <== 231; + eq[30][i].in[1] <== 232; eq[31][i] = IsEqual(); eq[31][i].in[0] <== in[i]; - eq[31][i].in[1] <== 232; + eq[31][i].in[1] <== 233; eq[32][i] = IsEqual(); eq[32][i].in[0] <== in[i]; - eq[32][i].in[1] <== 233; + eq[32][i].in[1] <== 234; eq[33][i] = IsEqual(); eq[33][i].in[0] <== in[i]; - eq[33][i].in[1] <== 234; + eq[33][i].in[1] <== 235; eq[34][i] = IsEqual(); eq[34][i].in[0] <== in[i]; - eq[34][i].in[1] <== 235; + eq[34][i].in[1] <== 236; eq[35][i] = IsEqual(); eq[35][i].in[0] <== in[i]; - eq[35][i].in[1] <== 236; + eq[35][i].in[1] <== 238; eq[36][i] = IsEqual(); eq[36][i].in[0] <== in[i]; - eq[36][i].in[1] <== 238; - eq[37][i] = IsEqual(); - eq[37][i].in[0] <== in[i]; - eq[37][i].in[1] <== 239; + eq[36][i].in[1] <== 239; and[21][i] = AND(); and[21][i].a <== states[i][0]; multi_or[6][i] = MultiOR(14); - multi_or[6][i].in[0] <== eq[24][i].out; - multi_or[6][i].in[1] <== eq[25][i].out; - multi_or[6][i].in[2] <== eq[26][i].out; - multi_or[6][i].in[3] <== eq[27][i].out; - multi_or[6][i].in[4] <== eq[28][i].out; - multi_or[6][i].in[5] <== eq[29][i].out; - multi_or[6][i].in[6] <== eq[30][i].out; - multi_or[6][i].in[7] <== eq[31][i].out; - multi_or[6][i].in[8] <== eq[32][i].out; - multi_or[6][i].in[9] <== eq[33][i].out; - multi_or[6][i].in[10] <== eq[34][i].out; - multi_or[6][i].in[11] <== eq[35][i].out; - multi_or[6][i].in[12] <== eq[36][i].out; - multi_or[6][i].in[13] <== eq[37][i].out; + multi_or[6][i].in[0] <== eq[23][i].out; + multi_or[6][i].in[1] <== eq[24][i].out; + multi_or[6][i].in[2] <== eq[25][i].out; + multi_or[6][i].in[3] <== eq[26][i].out; + multi_or[6][i].in[4] <== eq[27][i].out; + multi_or[6][i].in[5] <== eq[28][i].out; + multi_or[6][i].in[6] <== eq[29][i].out; + multi_or[6][i].in[7] <== eq[30][i].out; + multi_or[6][i].in[8] <== eq[31][i].out; + multi_or[6][i].in[9] <== eq[32][i].out; + multi_or[6][i].in[10] <== eq[33][i].out; + multi_or[6][i].in[11] <== eq[34][i].out; + multi_or[6][i].in[12] <== eq[35][i].out; + multi_or[6][i].in[13] <== eq[36][i].out; and[21][i].b <== multi_or[6][i].out; and[22][i] = AND(); and[22][i].a <== states[i][1]; @@ -360,73 +356,73 @@ template EmailAddrWithNameRegex(msg_bytes) { and[25][i] = AND(); and[25][i].a <== states[i][7]; and[25][i].b <== and[5][i].out; + eq[37][i] = IsEqual(); + eq[37][i].in[0] <== in[i]; + eq[37][i].in[1] <== 128; eq[38][i] = IsEqual(); eq[38][i].in[0] <== in[i]; - eq[38][i].in[1] <== 128; + eq[38][i].in[1] <== 129; eq[39][i] = IsEqual(); eq[39][i].in[0] <== in[i]; - eq[39][i].in[1] <== 129; + eq[39][i].in[1] <== 130; eq[40][i] = IsEqual(); eq[40][i].in[0] <== in[i]; - eq[40][i].in[1] <== 130; + eq[40][i].in[1] <== 131; eq[41][i] = IsEqual(); eq[41][i].in[0] <== in[i]; - eq[41][i].in[1] <== 131; + eq[41][i].in[1] <== 132; eq[42][i] = IsEqual(); eq[42][i].in[0] <== in[i]; - eq[42][i].in[1] <== 132; + eq[42][i].in[1] <== 133; eq[43][i] = IsEqual(); eq[43][i].in[0] <== in[i]; - eq[43][i].in[1] <== 133; + eq[43][i].in[1] <== 134; eq[44][i] = IsEqual(); eq[44][i].in[0] <== in[i]; - eq[44][i].in[1] <== 134; + eq[44][i].in[1] <== 135; eq[45][i] = IsEqual(); eq[45][i].in[0] <== in[i]; - eq[45][i].in[1] <== 135; + eq[45][i].in[1] <== 136; eq[46][i] = IsEqual(); eq[46][i].in[0] <== in[i]; - eq[46][i].in[1] <== 136; + eq[46][i].in[1] <== 137; eq[47][i] = IsEqual(); eq[47][i].in[0] <== in[i]; - eq[47][i].in[1] <== 137; + eq[47][i].in[1] <== 138; eq[48][i] = IsEqual(); eq[48][i].in[0] <== in[i]; - eq[48][i].in[1] <== 138; + eq[48][i].in[1] <== 139; eq[49][i] = IsEqual(); eq[49][i].in[0] <== in[i]; - eq[49][i].in[1] <== 139; + eq[49][i].in[1] <== 140; eq[50][i] = IsEqual(); eq[50][i].in[0] <== in[i]; - eq[50][i].in[1] <== 140; + eq[50][i].in[1] <== 141; eq[51][i] = IsEqual(); eq[51][i].in[0] <== in[i]; - eq[51][i].in[1] <== 141; + eq[51][i].in[1] <== 142; eq[52][i] = IsEqual(); eq[52][i].in[0] <== in[i]; - eq[52][i].in[1] <== 142; - eq[53][i] = IsEqual(); - eq[53][i].in[0] <== in[i]; - eq[53][i].in[1] <== 143; + eq[52][i].in[1] <== 143; and[26][i] = AND(); and[26][i].a <== states[i][8]; multi_or[7][i] = MultiOR(16); - multi_or[7][i].in[0] <== eq[38][i].out; - multi_or[7][i].in[1] <== eq[39][i].out; - multi_or[7][i].in[2] <== eq[40][i].out; - multi_or[7][i].in[3] <== eq[41][i].out; - multi_or[7][i].in[4] <== eq[42][i].out; - multi_or[7][i].in[5] <== eq[43][i].out; - multi_or[7][i].in[6] <== eq[44][i].out; - multi_or[7][i].in[7] <== eq[45][i].out; - multi_or[7][i].in[8] <== eq[46][i].out; - multi_or[7][i].in[9] <== eq[47][i].out; - multi_or[7][i].in[10] <== eq[48][i].out; - multi_or[7][i].in[11] <== eq[49][i].out; - multi_or[7][i].in[12] <== eq[50][i].out; - multi_or[7][i].in[13] <== eq[51][i].out; - multi_or[7][i].in[14] <== eq[52][i].out; - multi_or[7][i].in[15] <== eq[53][i].out; + multi_or[7][i].in[0] <== eq[37][i].out; + multi_or[7][i].in[1] <== eq[38][i].out; + multi_or[7][i].in[2] <== eq[39][i].out; + multi_or[7][i].in[3] <== eq[40][i].out; + multi_or[7][i].in[4] <== eq[41][i].out; + multi_or[7][i].in[5] <== eq[42][i].out; + multi_or[7][i].in[6] <== eq[43][i].out; + multi_or[7][i].in[7] <== eq[44][i].out; + multi_or[7][i].in[8] <== eq[45][i].out; + multi_or[7][i].in[9] <== eq[46][i].out; + multi_or[7][i].in[10] <== eq[47][i].out; + multi_or[7][i].in[11] <== eq[48][i].out; + multi_or[7][i].in[12] <== eq[49][i].out; + multi_or[7][i].in[13] <== eq[50][i].out; + multi_or[7][i].in[14] <== eq[51][i].out; + multi_or[7][i].in[15] <== eq[52][i].out; and[26][i].b <== multi_or[7][i].out; and[27][i] = AND(); and[27][i].a <== states[i][9]; @@ -438,53 +434,53 @@ template EmailAddrWithNameRegex(msg_bytes) { multi_or[8][i].in[3] <== and[26][i].out; multi_or[8][i].in[4] <== and[27][i].out; states_tmp[i+1][4] <== multi_or[8][i].out; - eq[54][i] = IsEqual(); - eq[54][i].in[0] <== in[i]; - eq[54][i].in[1] <== 237; + eq[53][i] = IsEqual(); + eq[53][i].in[0] <== in[i]; + eq[53][i].in[1] <== 237; and[28][i] = AND(); and[28][i].a <== states[i][0]; - and[28][i].b <== eq[54][i].out; + and[28][i].b <== eq[53][i].out; and[29][i] = AND(); and[29][i].a <== states[i][1]; - and[29][i].b <== eq[54][i].out; + and[29][i].b <== eq[53][i].out; and[30][i] = AND(); and[30][i].a <== states[i][9]; - and[30][i].b <== eq[54][i].out; + and[30][i].b <== eq[53][i].out; multi_or[9][i] = MultiOR(2); multi_or[9][i].in[0] <== and[29][i].out; multi_or[9][i].in[1] <== and[30][i].out; states_tmp[i+1][5] <== multi_or[9][i].out; - eq[55][i] = IsEqual(); - eq[55][i].in[0] <== in[i]; - eq[55][i].in[1] <== 240; + eq[54][i] = IsEqual(); + eq[54][i].in[0] <== in[i]; + eq[54][i].in[1] <== 240; and[31][i] = AND(); and[31][i].a <== states[i][0]; - and[31][i].b <== eq[55][i].out; + and[31][i].b <== eq[54][i].out; and[32][i] = AND(); and[32][i].a <== states[i][1]; - and[32][i].b <== eq[55][i].out; + and[32][i].b <== eq[54][i].out; and[33][i] = AND(); and[33][i].a <== states[i][9]; - and[33][i].b <== eq[55][i].out; + and[33][i].b <== eq[54][i].out; multi_or[10][i] = MultiOR(2); multi_or[10][i].in[0] <== and[32][i].out; multi_or[10][i].in[1] <== and[33][i].out; states_tmp[i+1][6] <== multi_or[10][i].out; + eq[55][i] = IsEqual(); + eq[55][i].in[0] <== in[i]; + eq[55][i].in[1] <== 241; eq[56][i] = IsEqual(); eq[56][i].in[0] <== in[i]; - eq[56][i].in[1] <== 241; + eq[56][i].in[1] <== 242; eq[57][i] = IsEqual(); eq[57][i].in[0] <== in[i]; - eq[57][i].in[1] <== 242; - eq[58][i] = IsEqual(); - eq[58][i].in[0] <== in[i]; - eq[58][i].in[1] <== 243; + eq[57][i].in[1] <== 243; and[34][i] = AND(); and[34][i].a <== states[i][0]; multi_or[11][i] = MultiOR(3); - multi_or[11][i].in[0] <== eq[56][i].out; - multi_or[11][i].in[1] <== eq[57][i].out; - multi_or[11][i].in[2] <== eq[58][i].out; + multi_or[11][i].in[0] <== eq[55][i].out; + multi_or[11][i].in[1] <== eq[56][i].out; + multi_or[11][i].in[2] <== eq[57][i].out; and[34][i].b <== multi_or[11][i].out; and[35][i] = AND(); and[35][i].a <== states[i][1]; @@ -496,31 +492,31 @@ template EmailAddrWithNameRegex(msg_bytes) { multi_or[12][i].in[0] <== and[35][i].out; multi_or[12][i].in[1] <== and[36][i].out; states_tmp[i+1][7] <== multi_or[12][i].out; - eq[59][i] = IsEqual(); - eq[59][i].in[0] <== in[i]; - eq[59][i].in[1] <== 244; + eq[58][i] = IsEqual(); + eq[58][i].in[0] <== in[i]; + eq[58][i].in[1] <== 244; and[37][i] = AND(); and[37][i].a <== states[i][0]; - and[37][i].b <== eq[59][i].out; + and[37][i].b <== eq[58][i].out; and[38][i] = AND(); and[38][i].a <== states[i][1]; - and[38][i].b <== eq[59][i].out; + and[38][i].b <== eq[58][i].out; and[39][i] = AND(); and[39][i].a <== states[i][9]; - and[39][i].b <== eq[59][i].out; + and[39][i].b <== eq[58][i].out; multi_or[13][i] = MultiOR(2); multi_or[13][i].in[0] <== and[38][i].out; multi_or[13][i].in[1] <== and[39][i].out; states_tmp[i+1][8] <== multi_or[13][i].out; - eq[60][i] = IsEqual(); - eq[60][i].in[0] <== in[i]; - eq[60][i].in[1] <== 60; + eq[59][i] = IsEqual(); + eq[59][i].in[0] <== in[i]; + eq[59][i].in[1] <== 60; and[40][i] = AND(); and[40][i].a <== states[i][1]; - and[40][i].b <== eq[60][i].out; + and[40][i].b <== eq[59][i].out; and[41][i] = AND(); and[41][i].a <== states[i][9]; - and[41][i].b <== eq[60][i].out; + and[41][i].b <== eq[59][i].out; multi_or[14][i] = MultiOR(2); multi_or[14][i].in[0] <== and[40][i].out; multi_or[14][i].in[1] <== and[41][i].out; @@ -543,36 +539,39 @@ template EmailAddrWithNameRegex(msg_bytes) { and[43][i] = AND(); and[43][i].a <== lt[20][i].out; and[43][i].b <== lt[21][i].out; + eq[60][i] = IsEqual(); + eq[60][i].in[0] <== in[i]; + eq[60][i].in[1] <== 33; eq[61][i] = IsEqual(); eq[61][i].in[0] <== in[i]; - eq[61][i].in[1] <== 33; + eq[61][i].in[1] <== 35; eq[62][i] = IsEqual(); eq[62][i].in[0] <== in[i]; - eq[62][i].in[1] <== 35; + eq[62][i].in[1] <== 36; eq[63][i] = IsEqual(); eq[63][i].in[0] <== in[i]; - eq[63][i].in[1] <== 36; + eq[63][i].in[1] <== 37; eq[64][i] = IsEqual(); eq[64][i].in[0] <== in[i]; - eq[64][i].in[1] <== 37; + eq[64][i].in[1] <== 38; eq[65][i] = IsEqual(); eq[65][i].in[0] <== in[i]; - eq[65][i].in[1] <== 38; + eq[65][i].in[1] <== 39; eq[66][i] = IsEqual(); eq[66][i].in[0] <== in[i]; - eq[66][i].in[1] <== 39; + eq[66][i].in[1] <== 42; eq[67][i] = IsEqual(); eq[67][i].in[0] <== in[i]; - eq[67][i].in[1] <== 42; + eq[67][i].in[1] <== 43; eq[68][i] = IsEqual(); eq[68][i].in[0] <== in[i]; - eq[68][i].in[1] <== 43; + eq[68][i].in[1] <== 45; eq[69][i] = IsEqual(); eq[69][i].in[0] <== in[i]; - eq[69][i].in[1] <== 45; + eq[69][i].in[1] <== 46; eq[70][i] = IsEqual(); eq[70][i].in[0] <== in[i]; - eq[70][i].in[1] <== 46; + eq[70][i].in[1] <== 47; eq[71][i] = IsEqual(); eq[71][i].in[0] <== in[i]; eq[71][i].in[1] <== 48; @@ -608,30 +607,31 @@ template EmailAddrWithNameRegex(msg_bytes) { eq[81][i].in[1] <== 61; and[44][i] = AND(); and[44][i].a <== states[i][9]; - multi_or[15][i] = MultiOR(23); + multi_or[15][i] = MultiOR(24); multi_or[15][i].in[0] <== and[42][i].out; multi_or[15][i].in[1] <== and[43][i].out; - multi_or[15][i].in[2] <== eq[61][i].out; - multi_or[15][i].in[3] <== eq[62][i].out; - multi_or[15][i].in[4] <== eq[63][i].out; - multi_or[15][i].in[5] <== eq[64][i].out; - multi_or[15][i].in[6] <== eq[65][i].out; - multi_or[15][i].in[7] <== eq[66][i].out; - multi_or[15][i].in[8] <== eq[67][i].out; - multi_or[15][i].in[9] <== eq[68][i].out; - multi_or[15][i].in[10] <== eq[69][i].out; - multi_or[15][i].in[11] <== eq[70][i].out; - multi_or[15][i].in[12] <== eq[71][i].out; - multi_or[15][i].in[13] <== eq[72][i].out; - multi_or[15][i].in[14] <== eq[73][i].out; - multi_or[15][i].in[15] <== eq[74][i].out; - multi_or[15][i].in[16] <== eq[75][i].out; - multi_or[15][i].in[17] <== eq[76][i].out; - multi_or[15][i].in[18] <== eq[77][i].out; - multi_or[15][i].in[19] <== eq[78][i].out; - multi_or[15][i].in[20] <== eq[79][i].out; - multi_or[15][i].in[21] <== eq[80][i].out; - multi_or[15][i].in[22] <== eq[81][i].out; + multi_or[15][i].in[2] <== eq[60][i].out; + multi_or[15][i].in[3] <== eq[61][i].out; + multi_or[15][i].in[4] <== eq[62][i].out; + multi_or[15][i].in[5] <== eq[63][i].out; + multi_or[15][i].in[6] <== eq[64][i].out; + multi_or[15][i].in[7] <== eq[65][i].out; + multi_or[15][i].in[8] <== eq[66][i].out; + multi_or[15][i].in[9] <== eq[67][i].out; + multi_or[15][i].in[10] <== eq[68][i].out; + multi_or[15][i].in[11] <== eq[69][i].out; + multi_or[15][i].in[12] <== eq[70][i].out; + multi_or[15][i].in[13] <== eq[71][i].out; + multi_or[15][i].in[14] <== eq[72][i].out; + multi_or[15][i].in[15] <== eq[73][i].out; + multi_or[15][i].in[16] <== eq[74][i].out; + multi_or[15][i].in[17] <== eq[75][i].out; + multi_or[15][i].in[18] <== eq[76][i].out; + multi_or[15][i].in[19] <== eq[77][i].out; + multi_or[15][i].in[20] <== eq[78][i].out; + multi_or[15][i].in[21] <== eq[79][i].out; + multi_or[15][i].in[22] <== eq[80][i].out; + multi_or[15][i].in[23] <== eq[81][i].out; and[44][i].b <== multi_or[15][i].out; lt[22][i] = LessEqThan(8); lt[22][i].in[0] <== 65; @@ -647,69 +647,75 @@ template EmailAddrWithNameRegex(msg_bytes) { eq[82][i].in[1] <== 63; and[46][i] = AND(); and[46][i].a <== states[i][10]; - multi_or[16][i] = MultiOR(24); + multi_or[16][i] = MultiOR(25); multi_or[16][i].in[0] <== and[45][i].out; multi_or[16][i].in[1] <== and[43][i].out; - multi_or[16][i].in[2] <== eq[61][i].out; - multi_or[16][i].in[3] <== eq[62][i].out; - multi_or[16][i].in[4] <== eq[63][i].out; - multi_or[16][i].in[5] <== eq[64][i].out; - multi_or[16][i].in[6] <== eq[65][i].out; - multi_or[16][i].in[7] <== eq[66][i].out; - multi_or[16][i].in[8] <== eq[67][i].out; - multi_or[16][i].in[9] <== eq[68][i].out; - multi_or[16][i].in[10] <== eq[69][i].out; - multi_or[16][i].in[11] <== eq[70][i].out; - multi_or[16][i].in[12] <== eq[71][i].out; - multi_or[16][i].in[13] <== eq[72][i].out; - multi_or[16][i].in[14] <== eq[73][i].out; - multi_or[16][i].in[15] <== eq[74][i].out; - multi_or[16][i].in[16] <== eq[75][i].out; - multi_or[16][i].in[17] <== eq[76][i].out; - multi_or[16][i].in[18] <== eq[77][i].out; - multi_or[16][i].in[19] <== eq[78][i].out; - multi_or[16][i].in[20] <== eq[79][i].out; - multi_or[16][i].in[21] <== eq[80][i].out; - multi_or[16][i].in[22] <== eq[81][i].out; - multi_or[16][i].in[23] <== eq[82][i].out; + multi_or[16][i].in[2] <== eq[60][i].out; + multi_or[16][i].in[3] <== eq[61][i].out; + multi_or[16][i].in[4] <== eq[62][i].out; + multi_or[16][i].in[5] <== eq[63][i].out; + multi_or[16][i].in[6] <== eq[64][i].out; + multi_or[16][i].in[7] <== eq[65][i].out; + multi_or[16][i].in[8] <== eq[66][i].out; + multi_or[16][i].in[9] <== eq[67][i].out; + multi_or[16][i].in[10] <== eq[68][i].out; + multi_or[16][i].in[11] <== eq[69][i].out; + multi_or[16][i].in[12] <== eq[70][i].out; + multi_or[16][i].in[13] <== eq[71][i].out; + multi_or[16][i].in[14] <== eq[72][i].out; + multi_or[16][i].in[15] <== eq[73][i].out; + multi_or[16][i].in[16] <== eq[74][i].out; + multi_or[16][i].in[17] <== eq[75][i].out; + multi_or[16][i].in[18] <== eq[76][i].out; + multi_or[16][i].in[19] <== eq[77][i].out; + multi_or[16][i].in[20] <== eq[78][i].out; + multi_or[16][i].in[21] <== eq[79][i].out; + multi_or[16][i].in[22] <== eq[80][i].out; + multi_or[16][i].in[23] <== eq[81][i].out; + multi_or[16][i].in[24] <== eq[82][i].out; and[46][i].b <== multi_or[16][i].out; eq[83][i] = IsEqual(); eq[83][i].in[0] <== in[i]; eq[83][i].in[1] <== 94; eq[84][i] = IsEqual(); eq[84][i].in[0] <== in[i]; - eq[84][i].in[1] <== 96; + eq[84][i].in[1] <== 95; eq[85][i] = IsEqual(); eq[85][i].in[0] <== in[i]; - eq[85][i].in[1] <== 123; + eq[85][i].in[1] <== 96; eq[86][i] = IsEqual(); eq[86][i].in[0] <== in[i]; - eq[86][i].in[1] <== 124; + eq[86][i].in[1] <== 123; eq[87][i] = IsEqual(); eq[87][i].in[0] <== in[i]; - eq[87][i].in[1] <== 125; + eq[87][i].in[1] <== 124; eq[88][i] = IsEqual(); eq[88][i].in[0] <== in[i]; - eq[88][i].in[1] <== 126; + eq[88][i].in[1] <== 125; + eq[89][i] = IsEqual(); + eq[89][i].in[0] <== in[i]; + eq[89][i].in[1] <== 126; and[47][i] = AND(); and[47][i].a <== states[i][11]; - multi_or[17][i] = MultiOR(16); - multi_or[17][i].in[0] <== eq[61][i].out; - multi_or[17][i].in[1] <== eq[62][i].out; - multi_or[17][i].in[2] <== eq[63][i].out; - multi_or[17][i].in[3] <== eq[64][i].out; - multi_or[17][i].in[4] <== eq[65][i].out; - multi_or[17][i].in[5] <== eq[66][i].out; - multi_or[17][i].in[6] <== eq[67][i].out; - multi_or[17][i].in[7] <== eq[68][i].out; - multi_or[17][i].in[8] <== eq[81][i].out; - multi_or[17][i].in[9] <== eq[82][i].out; - multi_or[17][i].in[10] <== eq[83][i].out; - multi_or[17][i].in[11] <== eq[84][i].out; - multi_or[17][i].in[12] <== eq[85][i].out; - multi_or[17][i].in[13] <== eq[86][i].out; - multi_or[17][i].in[14] <== eq[87][i].out; - multi_or[17][i].in[15] <== eq[88][i].out; + multi_or[17][i] = MultiOR(18); + multi_or[17][i].in[0] <== eq[60][i].out; + multi_or[17][i].in[1] <== eq[61][i].out; + multi_or[17][i].in[2] <== eq[62][i].out; + multi_or[17][i].in[3] <== eq[63][i].out; + multi_or[17][i].in[4] <== eq[64][i].out; + multi_or[17][i].in[5] <== eq[65][i].out; + multi_or[17][i].in[6] <== eq[66][i].out; + multi_or[17][i].in[7] <== eq[67][i].out; + multi_or[17][i].in[8] <== eq[70][i].out; + multi_or[17][i].in[9] <== eq[81][i].out; + multi_or[17][i].in[10] <== eq[82][i].out; + multi_or[17][i].in[11] <== eq[83][i].out; + multi_or[17][i].in[12] <== eq[84][i].out; + multi_or[17][i].in[13] <== eq[85][i].out; + multi_or[17][i].in[14] <== eq[86][i].out; + multi_or[17][i].in[15] <== eq[87][i].out; + multi_or[17][i].in[16] <== eq[88][i].out; + multi_or[17][i].in[17] <== eq[89][i].out; and[47][i].b <== multi_or[17][i].out; and[48][i] = AND(); and[48][i].a <== states[i][12]; @@ -720,18 +726,18 @@ template EmailAddrWithNameRegex(msg_bytes) { multi_or[18][i].in[2] <== and[47][i].out; multi_or[18][i].in[3] <== and[48][i].out; states[i+1][10] <== multi_or[18][i].out; - eq[89][i] = IsEqual(); - eq[89][i].in[0] <== in[i]; - eq[89][i].in[1] <== 64; + eq[90][i] = IsEqual(); + eq[90][i].in[0] <== in[i]; + eq[90][i].in[1] <== 64; and[49][i] = AND(); and[49][i].a <== states[i][10]; - and[49][i].b <== eq[89][i].out; + and[49][i].b <== eq[90][i].out; and[50][i] = AND(); and[50][i].a <== states[i][11]; - and[50][i].b <== eq[89][i].out; + and[50][i].b <== eq[90][i].out; and[51][i] = AND(); and[51][i].a <== states[i][12]; - and[51][i].b <== eq[89][i].out; + and[51][i].b <== eq[90][i].out; multi_or[19][i] = MultiOR(3); multi_or[19][i].in[0] <== and[49][i].out; multi_or[19][i].in[1] <== and[50][i].out; @@ -746,16 +752,13 @@ template EmailAddrWithNameRegex(msg_bytes) { and[52][i] = AND(); and[52][i].a <== lt[24][i].out; and[52][i].b <== lt[25][i].out; - eq[90][i] = IsEqual(); - eq[90][i].in[0] <== in[i]; - eq[90][i].in[1] <== 95; and[53][i] = AND(); and[53][i].a <== states[i][11]; - multi_or[20][i] = MultiOR(15); + multi_or[20][i] = MultiOR(14); multi_or[20][i].in[0] <== and[45][i].out; multi_or[20][i].in[1] <== and[52][i].out; - multi_or[20][i].in[2] <== eq[69][i].out; - multi_or[20][i].in[3] <== eq[70][i].out; + multi_or[20][i].in[2] <== eq[68][i].out; + multi_or[20][i].in[3] <== eq[69][i].out; multi_or[20][i].in[4] <== eq[71][i].out; multi_or[20][i].in[5] <== eq[72][i].out; multi_or[20][i].in[6] <== eq[73][i].out; @@ -766,7 +769,6 @@ template EmailAddrWithNameRegex(msg_bytes) { multi_or[20][i].in[11] <== eq[78][i].out; multi_or[20][i].in[12] <== eq[79][i].out; multi_or[20][i].in[13] <== eq[80][i].out; - multi_or[20][i].in[14] <== eq[90][i].out; and[53][i].b <== multi_or[20][i].out; and[54][i] = AND(); and[54][i].a <== states[i][12]; @@ -777,7 +779,7 @@ template EmailAddrWithNameRegex(msg_bytes) { states[i+1][12] <== multi_or[21][i].out; and[55][i] = AND(); and[55][i].a <== states[i][12]; - and[55][i].b <== eq[18][i].out; + and[55][i].b <== eq[17][i].out; states[i+1][13] <== and[55][i].out; from_zero_enabled[i] <== MultiNOR(13)([states_tmp[i+1][1], states_tmp[i+1][2], states_tmp[i+1][3], states_tmp[i+1][4], states_tmp[i+1][5], states_tmp[i+1][6], states_tmp[i+1][7], states_tmp[i+1][8], states[i+1][9], states[i+1][10], states[i+1][11], states[i+1][12], states[i+1][13]]); states[i+1][1] <== MultiOR(2)([states_tmp[i+1][1], from_zero_enabled[i] * and[1][i].out]); diff --git a/packages/circom/circuits/common/email_domain.json b/packages/circom/circuits/common/email_domain.json index 0ed11e3..7051e3a 100644 --- a/packages/circom/circuits/common/email_domain.json +++ b/packages/circom/circuits/common/email_domain.json @@ -2,7 +2,7 @@ "parts": [ { "is_public": false, - "regex_def": "[A-Za-z0-9!#$%&'*+=?\\-\\^_`{|}~.]+@" + "regex_def": "[A-Za-z0-9!#$%&'*+=?\\-\\^_`{|}~./]+@" }, { "is_public": true, diff --git a/packages/circom/circuits/common/email_domain_regex.circom b/packages/circom/circuits/common/email_domain_regex.circom index d30291d..a1e0e61 100644 --- a/packages/circom/circuits/common/email_domain_regex.circom +++ b/packages/circom/circuits/common/email_domain_regex.circom @@ -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 EmailDomainRegex(msg_bytes) { signal input msg[msg_bytes]; signal output out; @@ -14,7 +14,7 @@ template EmailDomainRegex(msg_bytes) { in[i+1] <== msg[i]; } - component eq[23][num_bytes]; + component eq[24][num_bytes]; component lt[8][num_bytes]; component and[9][num_bytes]; component multi_or[3][num_bytes]; @@ -81,43 +81,46 @@ template EmailDomainRegex(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] <== 63; + eq[21][i].in[1] <== 61; + eq[22][i] = IsEqual(); + eq[22][i].in[0] <== in[i]; + eq[22][i].in[1] <== 63; and[2][i] = AND(); and[2][i].a <== states[i][0]; - multi_or[0][i] = MultiOR(24); + multi_or[0][i] = MultiOR(25); 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; @@ -142,17 +145,18 @@ template EmailDomainRegex(msg_bytes) { 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; + multi_or[0][i].in[24] <== eq[22][i].out; and[2][i].b <== multi_or[0][i].out; and[3][i] = AND(); and[3][i].a <== states[i][1]; and[3][i].b <== multi_or[0][i].out; states_tmp[i+1][1] <== and[3][i].out; - eq[22][i] = IsEqual(); - eq[22][i].in[0] <== in[i]; - eq[22][i].in[1] <== 64; + eq[23][i] = IsEqual(); + eq[23][i].in[0] <== in[i]; + eq[23][i].in[1] <== 64; and[4][i] = AND(); and[4][i].a <== states[i][1]; - and[4][i].b <== eq[22][i].out; + and[4][i].b <== eq[23][i].out; states[i+1][2] <== and[4][i].out; lt[4][i] = LessEqThan(8); lt[4][i].in[0] <== 64; @@ -179,16 +183,16 @@ template EmailDomainRegex(msg_bytes) { multi_or[1][i].in[1] <== and[6][i].out; multi_or[1][i].in[2] <== eq[8][i].out; multi_or[1][i].in[3] <== eq[9][i].out; - multi_or[1][i].in[4] <== eq[10][i].out; - multi_or[1][i].in[5] <== eq[11][i].out; - multi_or[1][i].in[6] <== eq[12][i].out; - multi_or[1][i].in[7] <== eq[13][i].out; - multi_or[1][i].in[8] <== eq[14][i].out; - multi_or[1][i].in[9] <== eq[15][i].out; - multi_or[1][i].in[10] <== eq[16][i].out; - multi_or[1][i].in[11] <== eq[17][i].out; - multi_or[1][i].in[12] <== eq[18][i].out; - multi_or[1][i].in[13] <== eq[19][i].out; + multi_or[1][i].in[4] <== eq[11][i].out; + multi_or[1][i].in[5] <== eq[12][i].out; + multi_or[1][i].in[6] <== eq[13][i].out; + multi_or[1][i].in[7] <== eq[14][i].out; + multi_or[1][i].in[8] <== eq[15][i].out; + multi_or[1][i].in[9] <== eq[16][i].out; + multi_or[1][i].in[10] <== eq[17][i].out; + multi_or[1][i].in[11] <== eq[18][i].out; + multi_or[1][i].in[12] <== eq[19][i].out; + multi_or[1][i].in[13] <== eq[20][i].out; and[7][i].b <== multi_or[1][i].out; and[8][i] = AND(); and[8][i].a <== states[i][3]; diff --git a/packages/circom/circuits/common/from_addr.json b/packages/circom/circuits/common/from_addr.json index e4ca91d..82fefdd 100644 --- a/packages/circom/circuits/common/from_addr.json +++ b/packages/circom/circuits/common/from_addr.json @@ -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, diff --git a/packages/circom/circuits/common/to_addr.json b/packages/circom/circuits/common/to_addr.json index 0744491..9c7a4b1 100644 --- a/packages/circom/circuits/common/to_addr.json +++ b/packages/circom/circuits/common/to_addr.json @@ -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, diff --git a/packages/circom/tests/email_addr.test.js b/packages/circom/tests/email_addr.test.js index 5556252..a118930 100644 --- a/packages/circom/tests/email_addr.test.js +++ b/packages/circom/tests/email_addr.test.js @@ -83,7 +83,6 @@ describe("Email Address Regex", () => { expect(1n).toEqual(witness[1]); const prefixIdxes = apis.extractEmailAddrIdxes(string)[0]; for (let idx = 0; idx < 256; ++idx) { - console.log(idx, witness[2 + idx]) if (idx >= prefixIdxes[0] && idx < prefixIdxes[1]) { expect(BigInt(paddedStr[idx])).toEqual(witness[2 + idx]); } else { @@ -105,7 +104,6 @@ describe("Email Address Regex", () => { expect(1n).toEqual(witness[1]); const prefixIdxes = apis.extractEmailAddrIdxes(string)[0]; for (let idx = 0; idx < 256; ++idx) { - console.log(idx, witness[2 + idx]) if (idx >= prefixIdxes[0] && idx < prefixIdxes[1]) { expect(BigInt(paddedStr[idx])).toEqual(witness[2 + idx]); } else {