Skip to content

Commit

Permalink
Optimize the compiler by removing duplicated check
Browse files Browse the repository at this point in the history
  • Loading branch information
SoraSuegami committed Nov 2, 2023
1 parent d7049ef commit 69eb7d0
Show file tree
Hide file tree
Showing 14 changed files with 1,550 additions and 3,071 deletions.
895 changes: 344 additions & 551 deletions packages/circom/circuits/common/body_hash_regex.circom

Large diffs are not rendered by default.

369 changes: 87 additions & 282 deletions packages/circom/circuits/common/email_addr_regex.circom
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ template EmailAddrRegex(msg_bytes) {
in[i+1] <== msg[i];
}

component eq[72][num_bytes];
component lt[20][num_bytes];
component and[15][num_bytes];
component eq[25][num_bytes];
component lt[8][num_bytes];
component and[9][num_bytes];
component multi_or[6][num_bytes];
signal states[num_bytes+1][4];
component state_changed[num_bytes];
Expand Down Expand Up @@ -148,301 +148,106 @@ template EmailAddrRegex(msg_bytes) {
multi_or[0][i].in[25] <== eq[23][i].out;
and[2][i].b <== multi_or[0][i].out;
lt[4][i] = LessEqThan(8);
lt[4][i].in[0] <== 65;
lt[4][i].in[0] <== 94;
lt[4][i].in[1] <== in[i];
lt[5][i] = LessEqThan(8);
lt[5][i].in[0] <== in[i];
lt[5][i].in[1] <== 90;
lt[5][i].in[1] <== 126;
and[3][i] = AND();
and[3][i].a <== lt[4][i].out;
and[3][i].b <== lt[5][i].out;
lt[6][i] = LessEqThan(8);
lt[6][i].in[0] <== 94;
lt[6][i].in[1] <== in[i];
lt[7][i] = LessEqThan(8);
lt[7][i].in[0] <== in[i];
lt[7][i].in[1] <== 126;
and[4][i] = AND();
and[4][i].a <== lt[6][i].out;
and[4][i].b <== lt[7][i].out;
lt[8][i] = LessEqThan(8);
lt[8][i].in[0] <== 65;
lt[8][i].in[1] <== in[i];
lt[9][i] = LessEqThan(8);
lt[9][i].in[0] <== in[i];
lt[9][i].in[1] <== 90;
and[5][i] = AND();
and[5][i].a <== lt[8][i].out;
and[5][i].b <== lt[9][i].out;
lt[10][i] = LessEqThan(8);
lt[10][i].in[0] <== 95;
lt[10][i].in[1] <== in[i];
lt[11][i] = LessEqThan(8);
lt[11][i].in[0] <== in[i];
lt[11][i].in[1] <== 126;
and[6][i] = AND();
and[6][i].a <== lt[10][i].out;
and[6][i].b <== lt[11][i].out;
eq[24][i] = IsEqual();
eq[24][i].in[0] <== in[i];
eq[24][i].in[1] <== 33;
eq[25][i] = IsEqual();
eq[25][i].in[0] <== in[i];
eq[25][i].in[1] <== 35;
eq[26][i] = IsEqual();
eq[26][i].in[0] <== in[i];
eq[26][i].in[1] <== 36;
eq[27][i] = IsEqual();
eq[27][i].in[0] <== in[i];
eq[27][i].in[1] <== 37;
eq[28][i] = IsEqual();
eq[28][i].in[0] <== in[i];
eq[28][i].in[1] <== 38;
eq[29][i] = IsEqual();
eq[29][i].in[0] <== in[i];
eq[29][i].in[1] <== 39;
eq[30][i] = IsEqual();
eq[30][i].in[0] <== in[i];
eq[30][i].in[1] <== 42;
eq[31][i] = IsEqual();
eq[31][i].in[0] <== in[i];
eq[31][i].in[1] <== 43;
eq[32][i] = IsEqual();
eq[32][i].in[0] <== in[i];
eq[32][i].in[1] <== 45;
eq[33][i] = IsEqual();
eq[33][i].in[0] <== in[i];
eq[33][i].in[1] <== 46;
eq[34][i] = IsEqual();
eq[34][i].in[0] <== in[i];
eq[34][i].in[1] <== 47;
eq[35][i] = IsEqual();
eq[35][i].in[0] <== in[i];
eq[35][i].in[1] <== 48;
eq[36][i] = IsEqual();
eq[36][i].in[0] <== in[i];
eq[36][i].in[1] <== 49;
eq[37][i] = IsEqual();
eq[37][i].in[0] <== in[i];
eq[37][i].in[1] <== 50;
eq[38][i] = IsEqual();
eq[38][i].in[0] <== in[i];
eq[38][i].in[1] <== 51;
eq[39][i] = IsEqual();
eq[39][i].in[0] <== in[i];
eq[39][i].in[1] <== 52;
eq[40][i] = IsEqual();
eq[40][i].in[0] <== in[i];
eq[40][i].in[1] <== 53;
eq[41][i] = IsEqual();
eq[41][i].in[0] <== in[i];
eq[41][i].in[1] <== 54;
eq[42][i] = IsEqual();
eq[42][i].in[0] <== in[i];
eq[42][i].in[1] <== 55;
eq[43][i] = IsEqual();
eq[43][i].in[0] <== in[i];
eq[43][i].in[1] <== 56;
eq[44][i] = IsEqual();
eq[44][i].in[0] <== in[i];
eq[44][i].in[1] <== 57;
eq[45][i] = IsEqual();
eq[45][i].in[0] <== in[i];
eq[45][i].in[1] <== 61;
eq[46][i] = IsEqual();
eq[46][i].in[0] <== in[i];
eq[46][i].in[1] <== 63;
and[7][i] = AND();
and[7][i].a <== states[i][1];
and[4][i].a <== states[i][1];
multi_or[1][i] = MultiOR(27);
multi_or[1][i].in[0] <== and[3][i].out;
multi_or[1][i].in[1] <== and[4][i].out;
multi_or[1][i].in[2] <== and[5][i].out;
multi_or[1][i].in[3] <== and[6][i].out;
multi_or[1][i].in[4] <== eq[24][i].out;
multi_or[1][i].in[5] <== eq[25][i].out;
multi_or[1][i].in[6] <== eq[26][i].out;
multi_or[1][i].in[7] <== eq[27][i].out;
multi_or[1][i].in[8] <== eq[28][i].out;
multi_or[1][i].in[9] <== eq[29][i].out;
multi_or[1][i].in[10] <== eq[30][i].out;
multi_or[1][i].in[11] <== eq[31][i].out;
multi_or[1][i].in[12] <== eq[32][i].out;
multi_or[1][i].in[13] <== eq[33][i].out;
multi_or[1][i].in[14] <== eq[34][i].out;
multi_or[1][i].in[15] <== eq[35][i].out;
multi_or[1][i].in[16] <== eq[36][i].out;
multi_or[1][i].in[17] <== eq[37][i].out;
multi_or[1][i].in[18] <== eq[38][i].out;
multi_or[1][i].in[19] <== eq[39][i].out;
multi_or[1][i].in[20] <== eq[40][i].out;
multi_or[1][i].in[21] <== eq[41][i].out;
multi_or[1][i].in[22] <== eq[42][i].out;
multi_or[1][i].in[23] <== eq[43][i].out;
multi_or[1][i].in[24] <== eq[44][i].out;
multi_or[1][i].in[25] <== eq[45][i].out;
multi_or[1][i].in[26] <== eq[46][i].out;
and[7][i].b <== multi_or[1][i].out;
multi_or[1][i].in[0] <== and[0][i].out;
multi_or[1][i].in[1] <== and[3][i].out;
multi_or[1][i].in[2] <== and[0][i].out;
multi_or[1][i].in[3] <== and[1][i].out;
multi_or[1][i].in[4] <== eq[0][i].out;
multi_or[1][i].in[5] <== eq[1][i].out;
multi_or[1][i].in[6] <== eq[2][i].out;
multi_or[1][i].in[7] <== eq[3][i].out;
multi_or[1][i].in[8] <== eq[4][i].out;
multi_or[1][i].in[9] <== eq[5][i].out;
multi_or[1][i].in[10] <== eq[6][i].out;
multi_or[1][i].in[11] <== eq[7][i].out;
multi_or[1][i].in[12] <== eq[8][i].out;
multi_or[1][i].in[13] <== eq[9][i].out;
multi_or[1][i].in[14] <== eq[10][i].out;
multi_or[1][i].in[15] <== eq[11][i].out;
multi_or[1][i].in[16] <== eq[12][i].out;
multi_or[1][i].in[17] <== eq[13][i].out;
multi_or[1][i].in[18] <== eq[14][i].out;
multi_or[1][i].in[19] <== eq[15][i].out;
multi_or[1][i].in[20] <== eq[16][i].out;
multi_or[1][i].in[21] <== eq[17][i].out;
multi_or[1][i].in[22] <== eq[18][i].out;
multi_or[1][i].in[23] <== eq[19][i].out;
multi_or[1][i].in[24] <== eq[20][i].out;
multi_or[1][i].in[25] <== eq[21][i].out;
multi_or[1][i].in[26] <== eq[22][i].out;
and[4][i].b <== multi_or[1][i].out;
multi_or[2][i] = MultiOR(2);
multi_or[2][i].in[0] <== and[2][i].out;
multi_or[2][i].in[1] <== and[7][i].out;
multi_or[2][i].in[1] <== and[4][i].out;
states[i+1][1] <== multi_or[2][i].out;
state_changed[i].in[0] <== states[i+1][1];
eq[47][i] = IsEqual();
eq[47][i].in[0] <== in[i];
eq[47][i].in[1] <== 64;
and[8][i] = AND();
and[8][i].a <== states[i][1];
and[8][i].b <== eq[47][i].out;
states[i+1][2] <== and[8][i].out;
eq[24][i] = IsEqual();
eq[24][i].in[0] <== in[i];
eq[24][i].in[1] <== 64;
and[5][i] = AND();
and[5][i].a <== states[i][1];
and[5][i].b <== eq[24][i].out;
states[i+1][2] <== and[5][i].out;
state_changed[i].in[1] <== states[i+1][2];
lt[12][i] = LessEqThan(8);
lt[12][i].in[0] <== 65;
lt[12][i].in[1] <== in[i];
lt[13][i] = LessEqThan(8);
lt[13][i].in[0] <== in[i];
lt[13][i].in[1] <== 90;
and[9][i] = AND();
and[9][i].a <== lt[12][i].out;
and[9][i].b <== lt[13][i].out;
lt[14][i] = LessEqThan(8);
lt[14][i].in[0] <== 97;
lt[14][i].in[1] <== in[i];
lt[15][i] = LessEqThan(8);
lt[15][i].in[0] <== in[i];
lt[15][i].in[1] <== 122;
and[10][i] = AND();
and[10][i].a <== lt[14][i].out;
and[10][i].b <== lt[15][i].out;
eq[48][i] = IsEqual();
eq[48][i].in[0] <== in[i];
eq[48][i].in[1] <== 45;
eq[49][i] = IsEqual();
eq[49][i].in[0] <== in[i];
eq[49][i].in[1] <== 46;
eq[50][i] = IsEqual();
eq[50][i].in[0] <== in[i];
eq[50][i].in[1] <== 48;
eq[51][i] = IsEqual();
eq[51][i].in[0] <== in[i];
eq[51][i].in[1] <== 49;
eq[52][i] = IsEqual();
eq[52][i].in[0] <== in[i];
eq[52][i].in[1] <== 50;
eq[53][i] = IsEqual();
eq[53][i].in[0] <== in[i];
eq[53][i].in[1] <== 51;
eq[54][i] = IsEqual();
eq[54][i].in[0] <== in[i];
eq[54][i].in[1] <== 52;
eq[55][i] = IsEqual();
eq[55][i].in[0] <== in[i];
eq[55][i].in[1] <== 53;
eq[56][i] = IsEqual();
eq[56][i].in[0] <== in[i];
eq[56][i].in[1] <== 54;
eq[57][i] = IsEqual();
eq[57][i].in[0] <== in[i];
eq[57][i].in[1] <== 55;
eq[58][i] = IsEqual();
eq[58][i].in[0] <== in[i];
eq[58][i].in[1] <== 56;
eq[59][i] = IsEqual();
eq[59][i].in[0] <== in[i];
eq[59][i].in[1] <== 57;
and[11][i] = AND();
and[11][i].a <== states[i][2];
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 <== lt[6][i].out;
and[6][i].b <== lt[7][i].out;
and[7][i] = AND();
and[7][i].a <== states[i][2];
multi_or[3][i] = MultiOR(14);
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] <== eq[48][i].out;
multi_or[3][i].in[3] <== eq[49][i].out;
multi_or[3][i].in[4] <== eq[50][i].out;
multi_or[3][i].in[5] <== eq[51][i].out;
multi_or[3][i].in[6] <== eq[52][i].out;
multi_or[3][i].in[7] <== eq[53][i].out;
multi_or[3][i].in[8] <== eq[54][i].out;
multi_or[3][i].in[9] <== eq[55][i].out;
multi_or[3][i].in[10] <== eq[56][i].out;
multi_or[3][i].in[11] <== eq[57][i].out;
multi_or[3][i].in[12] <== eq[58][i].out;
multi_or[3][i].in[13] <== eq[59][i].out;
and[11][i].b <== multi_or[3][i].out;
lt[16][i] = LessEqThan(8);
lt[16][i].in[0] <== 65;
lt[16][i].in[1] <== in[i];
lt[17][i] = LessEqThan(8);
lt[17][i].in[0] <== in[i];
lt[17][i].in[1] <== 90;
and[12][i] = AND();
and[12][i].a <== lt[16][i].out;
and[12][i].b <== lt[17][i].out;
lt[18][i] = LessEqThan(8);
lt[18][i].in[0] <== 97;
lt[18][i].in[1] <== in[i];
lt[19][i] = LessEqThan(8);
lt[19][i].in[0] <== in[i];
lt[19][i].in[1] <== 122;
and[13][i] = AND();
and[13][i].a <== lt[18][i].out;
and[13][i].b <== lt[19][i].out;
eq[60][i] = IsEqual();
eq[60][i].in[0] <== in[i];
eq[60][i].in[1] <== 45;
eq[61][i] = IsEqual();
eq[61][i].in[0] <== in[i];
eq[61][i].in[1] <== 46;
eq[62][i] = IsEqual();
eq[62][i].in[0] <== in[i];
eq[62][i].in[1] <== 48;
eq[63][i] = IsEqual();
eq[63][i].in[0] <== in[i];
eq[63][i].in[1] <== 49;
eq[64][i] = IsEqual();
eq[64][i].in[0] <== in[i];
eq[64][i].in[1] <== 50;
eq[65][i] = IsEqual();
eq[65][i].in[0] <== in[i];
eq[65][i].in[1] <== 51;
eq[66][i] = IsEqual();
eq[66][i].in[0] <== in[i];
eq[66][i].in[1] <== 52;
eq[67][i] = IsEqual();
eq[67][i].in[0] <== in[i];
eq[67][i].in[1] <== 53;
eq[68][i] = IsEqual();
eq[68][i].in[0] <== in[i];
eq[68][i].in[1] <== 54;
eq[69][i] = IsEqual();
eq[69][i].in[0] <== in[i];
eq[69][i].in[1] <== 55;
eq[70][i] = IsEqual();
eq[70][i].in[0] <== in[i];
eq[70][i].in[1] <== 56;
eq[71][i] = IsEqual();
eq[71][i].in[0] <== in[i];
eq[71][i].in[1] <== 57;
and[14][i] = AND();
and[14][i].a <== states[i][3];
multi_or[3][i].in[0] <== and[0][i].out;
multi_or[3][i].in[1] <== and[6][i].out;
multi_or[3][i].in[2] <== eq[8][i].out;
multi_or[3][i].in[3] <== eq[9][i].out;
multi_or[3][i].in[4] <== eq[11][i].out;
multi_or[3][i].in[5] <== eq[12][i].out;
multi_or[3][i].in[6] <== eq[13][i].out;
multi_or[3][i].in[7] <== eq[14][i].out;
multi_or[3][i].in[8] <== eq[15][i].out;
multi_or[3][i].in[9] <== eq[16][i].out;
multi_or[3][i].in[10] <== eq[17][i].out;
multi_or[3][i].in[11] <== eq[18][i].out;
multi_or[3][i].in[12] <== eq[19][i].out;
multi_or[3][i].in[13] <== eq[20][i].out;
and[7][i].b <== multi_or[3][i].out;
and[8][i] = AND();
and[8][i].a <== states[i][3];
multi_or[4][i] = MultiOR(14);
multi_or[4][i].in[0] <== and[12][i].out;
multi_or[4][i].in[1] <== and[13][i].out;
multi_or[4][i].in[2] <== eq[60][i].out;
multi_or[4][i].in[3] <== eq[61][i].out;
multi_or[4][i].in[4] <== eq[62][i].out;
multi_or[4][i].in[5] <== eq[63][i].out;
multi_or[4][i].in[6] <== eq[64][i].out;
multi_or[4][i].in[7] <== eq[65][i].out;
multi_or[4][i].in[8] <== eq[66][i].out;
multi_or[4][i].in[9] <== eq[67][i].out;
multi_or[4][i].in[10] <== eq[68][i].out;
multi_or[4][i].in[11] <== eq[69][i].out;
multi_or[4][i].in[12] <== eq[70][i].out;
multi_or[4][i].in[13] <== eq[71][i].out;
and[14][i].b <== multi_or[4][i].out;
multi_or[4][i].in[0] <== and[0][i].out;
multi_or[4][i].in[1] <== and[6][i].out;
multi_or[4][i].in[2] <== eq[8][i].out;
multi_or[4][i].in[3] <== eq[9][i].out;
multi_or[4][i].in[4] <== eq[11][i].out;
multi_or[4][i].in[5] <== eq[12][i].out;
multi_or[4][i].in[6] <== eq[13][i].out;
multi_or[4][i].in[7] <== eq[14][i].out;
multi_or[4][i].in[8] <== eq[15][i].out;
multi_or[4][i].in[9] <== eq[16][i].out;
multi_or[4][i].in[10] <== eq[17][i].out;
multi_or[4][i].in[11] <== eq[18][i].out;
multi_or[4][i].in[12] <== eq[19][i].out;
multi_or[4][i].in[13] <== eq[20][i].out;
and[8][i].b <== multi_or[4][i].out;
multi_or[5][i] = MultiOR(2);
multi_or[5][i].in[0] <== and[11][i].out;
multi_or[5][i].in[1] <== and[14][i].out;
multi_or[5][i].in[0] <== and[7][i].out;
multi_or[5][i].in[1] <== and[8][i].out;
states[i+1][3] <== multi_or[5][i].out;
state_changed[i].in[2] <== states[i+1][3];
states[i+1][0] <== 1 - state_changed[i].out;
Expand Down
Loading

0 comments on commit 69eb7d0

Please sign in to comment.