From 2587b53ceb3d500122d28f1624691bf017717256 Mon Sep 17 00:00:00 2001 From: James Farrell Date: Fri, 13 Oct 2023 17:24:33 +0200 Subject: [PATCH] feat: WIP email confirmation, pushing for Ayo to take a look --- libs/regex_to_circom/halo2_regex_lookup.txt | 163 +++++++++ libs/regex_to_circom/regex_to_dfa.js | 7 +- output.circom | 356 ++++++++++++++++++++ 3 files changed, 525 insertions(+), 1 deletion(-) create mode 100644 libs/regex_to_circom/halo2_regex_lookup.txt create mode 100644 output.circom diff --git a/libs/regex_to_circom/halo2_regex_lookup.txt b/libs/regex_to_circom/halo2_regex_lookup.txt new file mode 100644 index 000000000..c9a13a830 --- /dev/null +++ b/libs/regex_to_circom/halo2_regex_lookup.txt @@ -0,0 +1,163 @@ +8 +0 6 47 +1 2 111 +2 3 102 +3 4 32 +4 5 46 +4 5 48 +4 5 49 +4 5 50 +4 5 51 +4 5 52 +4 5 53 +4 5 54 +4 5 55 +4 5 56 +4 5 57 +4 5 61 +4 5 65 +4 5 66 +4 5 67 +4 5 68 +4 5 69 +4 5 70 +4 5 71 +4 5 72 +4 5 73 +4 5 74 +4 5 75 +4 5 76 +4 5 77 +4 5 78 +4 5 79 +4 5 80 +4 5 81 +4 5 82 +4 5 83 +4 5 84 +4 5 85 +4 5 86 +4 5 87 +4 5 88 +4 5 89 +4 5 90 +4 5 97 +4 5 98 +4 5 99 +4 5 100 +4 5 101 +4 5 102 +4 5 103 +4 5 104 +4 5 105 +4 5 106 +4 5 107 +4 5 108 +4 5 109 +4 5 110 +4 5 111 +4 5 112 +4 5 113 +4 5 114 +4 5 115 +4 5 116 +4 5 117 +4 5 118 +4 5 119 +4 5 120 +4 5 121 +4 5 122 +5 5 46 +5 5 48 +5 5 49 +5 5 50 +5 5 51 +5 5 52 +5 5 53 +5 5 54 +5 5 55 +5 5 56 +5 5 57 +5 5 61 +5 5 65 +5 5 66 +5 5 67 +5 5 68 +5 5 69 +5 5 70 +5 5 71 +5 5 72 +5 5 73 +5 5 74 +5 5 75 +5 5 76 +5 5 77 +5 5 78 +5 5 79 +5 5 80 +5 5 81 +5 5 82 +5 5 83 +5 5 84 +5 5 85 +5 5 86 +5 5 87 +5 5 88 +5 5 89 +5 5 90 +5 5 97 +5 5 98 +5 5 99 +5 5 100 +5 5 101 +5 5 102 +5 5 103 +5 5 104 +5 5 105 +5 5 106 +5 5 107 +5 5 108 +5 5 109 +5 5 110 +5 5 111 +5 5 112 +5 5 113 +5 5 114 +5 5 115 +5 5 116 +5 5 117 +5 5 118 +5 5 119 +5 5 120 +5 5 121 +5 5 122 +5 8 47 +6 7 60 +7 9 116 +9 10 100 +10 11 62 +10 10 94 +11 11 62 +11 12 80 +11 10 94 +11 13 115 +12 14 97 +13 12 80 +13 13 115 +14 15 121 +15 16 109 +16 17 101 +17 18 110 +18 19 116 +19 20 32 +20 21 116 +21 22 111 +22 23 32 +23 24 101 +24 25 97 +25 26 115 +26 27 121 +27 28 74 +28 29 101 +29 30 116 +30 1 32 diff --git a/libs/regex_to_circom/regex_to_dfa.js b/libs/regex_to_circom/regex_to_dfa.js index 1bb87beed..75c47203d 100644 --- a/libs/regex_to_circom/regex_to_dfa.js +++ b/libs/regex_to_circom/regex_to_dfa.js @@ -1,6 +1,9 @@ /*jslint browser: true*/ /*global require, exports*/ +<<<<<<< Updated upstream // import { STRING_PRESELECTOR } from "../src/helpers/constants.ts"; +======= +>>>>>>> Stashed changes import { minDfa, nfaToDfa, regexToNfa } from "./lexical"; /** This section defines helper regex components -- to edit the regex used, edit the return @@ -69,7 +72,9 @@ function test_regex() { // console.log(raw_subject_regex); // -- GENERIC SUBJECT COMMANDS -- - let raw_subject_regex = `((\r\n)|^)subject:[a-zA-Z]+ (\\$)?[0-9]+(.[0-9]+)? [a-zA-Z]+ to (${email_address_regex}|0x[0-9a-fA_F]+)\r\n`; + // let raw_subject_regex = `((\r\n)|^)subject:[a-zA-Z]+ (\\$)?[0-9]+(.[0-9]+)? [a-zA-Z]+ to (${email_address_regex}|0x[0-9a-fA_F]+)\r\n`; + let raw_subject_regex = `/]*>\s*Payment to easyJet of [=A-Za-z0-9\.]+/`; + // -------- OTHER FIELD REGEXES -------- let raw_from_regex = `(\r\n|^)from:([A-Za-z0-9 _.,"@-]+)<[a-zA-Z0-9_.-]+@[a-zA-Z0-9_.-]+>\r\n`; diff --git a/output.circom b/output.circom new file mode 100644 index 000000000..66948c4d9 --- /dev/null +++ b/output.circom @@ -0,0 +1,356 @@ +component eq[38][num_bytes]; +component lt[12][num_bytes]; +component and[42][num_bytes]; +component multi_or[7][num_bytes]; +signal states[num_bytes+1][31]; + +for (var i = 0; i < num_bytes; i++) { + states[i][0] <== 1; +} +for (var i = 1; i < 31; i++) { + states[0][i] <== 0; +} + +for (var i = 0; i < num_bytes; i++) { + eq[0][i] = IsEqual(); + eq[0][i].in[0] <== in[i]; + eq[0][i].in[1] <== 32; + and[0][i] = AND(); + and[0][i].a <== states[i][30]; + and[0][i].b <== eq[0][i].out; + states[i+1][1] <== and[0][i].out; + eq[1][i] = IsEqual(); + eq[1][i].in[0] <== in[i]; + eq[1][i].in[1] <== 111; + and[1][i] = AND(); + and[1][i].a <== states[i][1]; + and[1][i].b <== eq[1][i].out; + states[i+1][2] <== and[1][i].out; + eq[2][i] = IsEqual(); + eq[2][i].in[0] <== in[i]; + eq[2][i].in[1] <== 102; + and[2][i] = AND(); + and[2][i].a <== states[i][2]; + and[2][i].b <== eq[2][i].out; + states[i+1][3] <== and[2][i].out; + eq[3][i] = IsEqual(); + eq[3][i].in[0] <== in[i]; + eq[3][i].in[1] <== 32; + and[3][i] = AND(); + and[3][i].a <== states[i][3]; + and[3][i].b <== eq[3][i].out; + states[i+1][4] <== and[3][i].out; + lt[0][i] = LessThan(8); + lt[0][i].in[0] <== 64; + lt[0][i].in[1] <== in[i]; + lt[1][i] = LessThan(8); + lt[1][i].in[0] <== in[i]; + lt[1][i].in[1] <== 91; + and[4][i] = AND(); + and[4][i].a <== lt[0][i].out; + and[4][i].b <== lt[1][i].out; + lt[2][i] = LessThan(8); + lt[2][i].in[0] <== 96; + lt[2][i].in[1] <== in[i]; + lt[3][i] = LessThan(8); + lt[3][i].in[0] <== in[i]; + lt[3][i].in[1] <== 123; + and[5][i] = AND(); + and[5][i].a <== lt[2][i].out; + and[5][i].b <== lt[3][i].out; + lt[4][i] = LessThan(8); + lt[4][i].in[0] <== 47; + lt[4][i].in[1] <== in[i]; + lt[5][i] = LessThan(8); + lt[5][i].in[0] <== in[i]; + lt[5][i].in[1] <== 58; + and[6][i] = AND(); + and[6][i].a <== lt[4][i].out; + and[6][i].b <== lt[5][i].out; + eq[4][i] = IsEqual(); + eq[4][i].in[0] <== in[i]; + eq[4][i].in[1] <== 61; + eq[5][i] = IsEqual(); + eq[5][i].in[0] <== in[i]; + eq[5][i].in[1] <== 46; + and[7][i] = AND(); + and[7][i].a <== states[i][4]; + multi_or[0][i] = MultiOR(5); + multi_or[0][i].in[0] <== and[4][i].out; + multi_or[0][i].in[1] <== and[5][i].out; + multi_or[0][i].in[2] <== and[6][i].out; + multi_or[0][i].in[3] <== eq[4][i].out; + multi_or[0][i].in[4] <== eq[5][i].out; + and[7][i].b <== multi_or[0][i].out; + lt[6][i] = LessThan(8); + lt[6][i].in[0] <== 64; + lt[6][i].in[1] <== in[i]; + lt[7][i] = LessThan(8); + lt[7][i].in[0] <== in[i]; + lt[7][i].in[1] <== 91; + and[8][i] = AND(); + and[8][i].a <== lt[6][i].out; + and[8][i].b <== lt[7][i].out; + lt[8][i] = LessThan(8); + lt[8][i].in[0] <== 96; + lt[8][i].in[1] <== in[i]; + lt[9][i] = LessThan(8); + lt[9][i].in[0] <== in[i]; + lt[9][i].in[1] <== 123; + and[9][i] = AND(); + and[9][i].a <== lt[8][i].out; + and[9][i].b <== lt[9][i].out; + lt[10][i] = LessThan(8); + lt[10][i].in[0] <== 47; + lt[10][i].in[1] <== in[i]; + lt[11][i] = LessThan(8); + lt[11][i].in[0] <== in[i]; + lt[11][i].in[1] <== 58; + and[10][i] = AND(); + and[10][i].a <== lt[10][i].out; + and[10][i].b <== lt[11][i].out; + eq[6][i] = IsEqual(); + eq[6][i].in[0] <== in[i]; + eq[6][i].in[1] <== 61; + eq[7][i] = IsEqual(); + eq[7][i].in[0] <== in[i]; + eq[7][i].in[1] <== 46; + and[11][i] = AND(); + and[11][i].a <== states[i][5]; + multi_or[1][i] = MultiOR(5); + 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[10][i].out; + multi_or[1][i].in[3] <== eq[6][i].out; + multi_or[1][i].in[4] <== eq[7][i].out; + and[11][i].b <== multi_or[1][i].out; + multi_or[2][i] = MultiOR(2); + multi_or[2][i].in[0] <== and[7][i].out; + multi_or[2][i].in[1] <== and[11][i].out; + states[i+1][5] <== multi_or[2][i].out; + eq[8][i] = IsEqual(); + eq[8][i].in[0] <== in[i]; + eq[8][i].in[1] <== 47; + and[12][i] = AND(); + and[12][i].a <== states[i][0]; + and[12][i].b <== eq[8][i].out; + states[i+1][6] <== and[12][i].out; + eq[9][i] = IsEqual(); + eq[9][i].in[0] <== in[i]; + eq[9][i].in[1] <== 60; + and[13][i] = AND(); + and[13][i].a <== states[i][6]; + and[13][i].b <== eq[9][i].out; + states[i+1][7] <== and[13][i].out; + eq[10][i] = IsEqual(); + eq[10][i].in[0] <== in[i]; + eq[10][i].in[1] <== 47; + and[14][i] = AND(); + and[14][i].a <== states[i][5]; + and[14][i].b <== eq[10][i].out; + states[i+1][8] <== and[14][i].out; + eq[11][i] = IsEqual(); + eq[11][i].in[0] <== in[i]; + eq[11][i].in[1] <== 116; + and[15][i] = AND(); + and[15][i].a <== states[i][7]; + and[15][i].b <== eq[11][i].out; + states[i+1][9] <== and[15][i].out; + eq[12][i] = IsEqual(); + eq[12][i].in[0] <== in[i]; + eq[12][i].in[1] <== 100; + and[16][i] = AND(); + and[16][i].a <== states[i][9]; + and[16][i].b <== eq[12][i].out; + eq[13][i] = IsEqual(); + eq[13][i].in[0] <== in[i]; + eq[13][i].in[1] <== 94; + and[17][i] = AND(); + and[17][i].a <== states[i][10]; + and[17][i].b <== eq[13][i].out; + eq[14][i] = IsEqual(); + eq[14][i].in[0] <== in[i]; + eq[14][i].in[1] <== 94; + and[18][i] = AND(); + and[18][i].a <== states[i][11]; + and[18][i].b <== eq[14][i].out; + multi_or[3][i] = MultiOR(3); + multi_or[3][i].in[0] <== and[16][i].out; + multi_or[3][i].in[1] <== and[17][i].out; + multi_or[3][i].in[2] <== and[18][i].out; + states[i+1][10] <== multi_or[3][i].out; + eq[15][i] = IsEqual(); + eq[15][i].in[0] <== in[i]; + eq[15][i].in[1] <== 62; + and[19][i] = AND(); + and[19][i].a <== states[i][10]; + and[19][i].b <== eq[15][i].out; + eq[16][i] = IsEqual(); + eq[16][i].in[0] <== in[i]; + eq[16][i].in[1] <== 62; + and[20][i] = AND(); + and[20][i].a <== states[i][11]; + and[20][i].b <== eq[16][i].out; + multi_or[4][i] = MultiOR(2); + multi_or[4][i].in[0] <== and[19][i].out; + multi_or[4][i].in[1] <== and[20][i].out; + states[i+1][11] <== multi_or[4][i].out; + eq[17][i] = IsEqual(); + eq[17][i].in[0] <== in[i]; + eq[17][i].in[1] <== 80; + and[21][i] = AND(); + and[21][i].a <== states[i][11]; + and[21][i].b <== eq[17][i].out; + eq[18][i] = IsEqual(); + eq[18][i].in[0] <== in[i]; + eq[18][i].in[1] <== 80; + and[22][i] = AND(); + and[22][i].a <== states[i][13]; + and[22][i].b <== eq[18][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[i+1][12] <== multi_or[5][i].out; + eq[19][i] = IsEqual(); + eq[19][i].in[0] <== in[i]; + eq[19][i].in[1] <== 115; + and[23][i] = AND(); + and[23][i].a <== states[i][11]; + and[23][i].b <== eq[19][i].out; + eq[20][i] = IsEqual(); + eq[20][i].in[0] <== in[i]; + eq[20][i].in[1] <== 115; + and[24][i] = AND(); + and[24][i].a <== states[i][13]; + and[24][i].b <== eq[20][i].out; + multi_or[6][i] = MultiOR(2); + multi_or[6][i].in[0] <== and[23][i].out; + multi_or[6][i].in[1] <== and[24][i].out; + states[i+1][13] <== multi_or[6][i].out; + eq[21][i] = IsEqual(); + eq[21][i].in[0] <== in[i]; + eq[21][i].in[1] <== 97; + and[25][i] = AND(); + and[25][i].a <== states[i][12]; + and[25][i].b <== eq[21][i].out; + states[i+1][14] <== and[25][i].out; + eq[22][i] = IsEqual(); + eq[22][i].in[0] <== in[i]; + eq[22][i].in[1] <== 121; + and[26][i] = AND(); + and[26][i].a <== states[i][14]; + and[26][i].b <== eq[22][i].out; + states[i+1][15] <== and[26][i].out; + eq[23][i] = IsEqual(); + eq[23][i].in[0] <== in[i]; + eq[23][i].in[1] <== 109; + and[27][i] = AND(); + and[27][i].a <== states[i][15]; + and[27][i].b <== eq[23][i].out; + states[i+1][16] <== and[27][i].out; + eq[24][i] = IsEqual(); + eq[24][i].in[0] <== in[i]; + eq[24][i].in[1] <== 101; + and[28][i] = AND(); + and[28][i].a <== states[i][16]; + and[28][i].b <== eq[24][i].out; + states[i+1][17] <== and[28][i].out; + eq[25][i] = IsEqual(); + eq[25][i].in[0] <== in[i]; + eq[25][i].in[1] <== 110; + and[29][i] = AND(); + and[29][i].a <== states[i][17]; + and[29][i].b <== eq[25][i].out; + states[i+1][18] <== and[29][i].out; + eq[26][i] = IsEqual(); + eq[26][i].in[0] <== in[i]; + eq[26][i].in[1] <== 116; + and[30][i] = AND(); + and[30][i].a <== states[i][18]; + and[30][i].b <== eq[26][i].out; + states[i+1][19] <== and[30][i].out; + eq[27][i] = IsEqual(); + eq[27][i].in[0] <== in[i]; + eq[27][i].in[1] <== 32; + and[31][i] = AND(); + and[31][i].a <== states[i][19]; + and[31][i].b <== eq[27][i].out; + states[i+1][20] <== and[31][i].out; + eq[28][i] = IsEqual(); + eq[28][i].in[0] <== in[i]; + eq[28][i].in[1] <== 116; + and[32][i] = AND(); + and[32][i].a <== states[i][20]; + and[32][i].b <== eq[28][i].out; + states[i+1][21] <== and[32][i].out; + eq[29][i] = IsEqual(); + eq[29][i].in[0] <== in[i]; + eq[29][i].in[1] <== 111; + and[33][i] = AND(); + and[33][i].a <== states[i][21]; + and[33][i].b <== eq[29][i].out; + states[i+1][22] <== and[33][i].out; + eq[30][i] = IsEqual(); + eq[30][i].in[0] <== in[i]; + eq[30][i].in[1] <== 32; + and[34][i] = AND(); + and[34][i].a <== states[i][22]; + and[34][i].b <== eq[30][i].out; + states[i+1][23] <== and[34][i].out; + eq[31][i] = IsEqual(); + eq[31][i].in[0] <== in[i]; + eq[31][i].in[1] <== 101; + and[35][i] = AND(); + and[35][i].a <== states[i][23]; + and[35][i].b <== eq[31][i].out; + states[i+1][24] <== and[35][i].out; + eq[32][i] = IsEqual(); + eq[32][i].in[0] <== in[i]; + eq[32][i].in[1] <== 97; + and[36][i] = AND(); + and[36][i].a <== states[i][24]; + and[36][i].b <== eq[32][i].out; + states[i+1][25] <== and[36][i].out; + eq[33][i] = IsEqual(); + eq[33][i].in[0] <== in[i]; + eq[33][i].in[1] <== 115; + and[37][i] = AND(); + and[37][i].a <== states[i][25]; + and[37][i].b <== eq[33][i].out; + states[i+1][26] <== and[37][i].out; + eq[34][i] = IsEqual(); + eq[34][i].in[0] <== in[i]; + eq[34][i].in[1] <== 121; + and[38][i] = AND(); + and[38][i].a <== states[i][26]; + and[38][i].b <== eq[34][i].out; + states[i+1][27] <== and[38][i].out; + eq[35][i] = IsEqual(); + eq[35][i].in[0] <== in[i]; + eq[35][i].in[1] <== 74; + and[39][i] = AND(); + and[39][i].a <== states[i][27]; + and[39][i].b <== eq[35][i].out; + states[i+1][28] <== and[39][i].out; + eq[36][i] = IsEqual(); + eq[36][i].in[0] <== in[i]; + eq[36][i].in[1] <== 101; + and[40][i] = AND(); + and[40][i].a <== states[i][28]; + and[40][i].b <== eq[36][i].out; + states[i+1][29] <== and[40][i].out; + eq[37][i] = IsEqual(); + eq[37][i].in[0] <== in[i]; + eq[37][i].in[1] <== 116; + and[41][i] = AND(); + and[41][i].a <== states[i][29]; + and[41][i].b <== eq[37][i].out; + states[i+1][30] <== and[41][i].out; +} + +signal final_state_sum[num_bytes+1]; +final_state_sum[0] <== states[0][8]; +for (var i = 1; i <= num_bytes; i++) { + final_state_sum[i] <== final_state_sum[i-1] + states[i][8]; +} +out <== final_state_sum[num_bytes];