zkemail / zk-regex

A library to do regex verification in circom, adapted from the original zk-email. It additionally generates lookup tables for halo2-regex.
GNU General Public License v3.0
79 stars 27 forks source link

Optimize Regex via determining optimal cutoff to combine equalities into range checks #22

Open Divide-By-0 opened 1 year ago

Divide-By-0 commented 1 year ago

Determine the cutoff (currently 16) at which equalities convert into range checks.

We have constraint blocks like this:

eq[27][i].in[0] <== in[i];
eq[27][i].in[1] <== 126;
eq[28][i] = IsEqual();
eq[28][i].in[0] <== in[i];
eq[28][i].in[1] <== 60;
eq[29][i] = IsEqual();
eq[29][i].in[0] <== in[i];
eq[29][i].in[1] <== 37;
eq[30][i] = IsEqual();
eq[30][i].in[0] <== in[i];
eq[30][i].in[1] <== 96;
eq[31][i] = IsEqual();
eq[31][i].in[0] <== in[i];
eq[31][i].in[1] <== 11;
eq[32][i] = IsEqual();
eq[32][i].in[0] <== in[i];
eq[32][i].in[1] <== 58;
eq[33][i] = IsEqual();
eq[33][i].in[0] <== in[i];
eq[33][i].in[1] <== 10;
eq[34][i] = IsEqual();
eq[34][i].in[0] <== in[i];
eq[34][i].in[1] <== 39;
eq[35][i] = IsEqual();
eq[35][i].in[0] <== in[i];
eq[35][i].in[1] <== 41;
eq[36][i] = IsEqual();
eq[36][i].in[0] <== in[i];
eq[36][i].in[1] <== 47;
eq[37][i] = IsEqual();
eq[37][i].in[0] <== in[i];
eq[37][i].in[1] <== 93;
eq[38][i] = IsEqual();
eq[38][i].in[0] <== in[i];
eq[38][i].in[1] <== 36;
eq[39][i] = IsEqual();
eq[39][i].in[0] <== in[i];
eq[39][i].in[1] <== 64;
eq[40][i] = IsEqual();
eq[40][i].in[0] <== in[i];
eq[40][i].in[1] <== 63;
eq[41][i] = IsEqual();
eq[41][i].in[0] <== in[i];
eq[41][i].in[1] <== 12;
eq[42][i] = IsEqual();
eq[42][i].in[0] <== in[i];
eq[42][i].in[1] <== 61;
eq[43][i] = IsEqual();
eq[43][i].in[0] <== in[i];
eq[43][i].in[1] <== 95;
eq[44][i] = IsEqual();
eq[44][i].in[0] <== in[i];
eq[44][i].in[1] <== 9;
eq[45][i] = IsEqual();
eq[45][i].in[0] <== in[i];
eq[45][i].in[1] <== 43;
eq[46][i] = IsEqual();
eq[46][i].in[0] <== in[i];
eq[46][i].in[1] <== 35;
eq[47][i] = IsEqual();
eq[47][i].in[0] <== in[i];
eq[47][i].in[1] <== 94;
eq[48][i] = IsEqual();
eq[48][i].in[0] <== in[i];
eq[48][i].in[1] <== 13;
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] <== 123;
eq[51][i] = IsEqual();
eq[51][i].in[0] <== in[i];
eq[51][i].in[1] <== 92;
eq[52][i] = IsEqual();
eq[52][i].in[0] <== in[i];
eq[52][i].in[1] <== 40;
eq[53][i] = IsEqual();
eq[53][i].in[0] <== in[i];
eq[53][i].in[1] <== 44;
eq[54][i] = IsEqual();
eq[54][i].in[0] <== in[i];
eq[54][i].in[1] <== 38;
eq[55][i] = IsEqual();
eq[55][i].in[0] <== in[i];
eq[55][i].in[1] <== 45;
eq[56][i] = IsEqual();
eq[56][i].in[0] <== in[i];
eq[56][i].in[1] <== 62;
eq[57][i] = IsEqual();
eq[57][i].in[0] <== in[i];
eq[57][i].in[1] <== 32;
eq[58][i] = IsEqual();
eq[58][i].in[0] <== in[i];
eq[58][i].in[1] <== 34;
eq[59][i] = IsEqual();
eq[59][i].in[0] <== in[i];
eq[59][i].in[1] <== 91;
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] <== 42;
eq[62][i] = IsEqual();
eq[62][i].in[0] <== in[i];
eq[62][i].in[1] <== 125;
eq[63][i] = IsEqual();
eq[63][i].in[0] <== in[i];
eq[63][i].in[1] <== 124;

Order the accesses and make them range checks instead.