diff --git a/packages/apis/Cargo.toml b/packages/apis/Cargo.toml index 0fb183c..7ee1e3e 100644 --- a/packages/apis/Cargo.toml +++ b/packages/apis/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "zk-regex-apis" -version = "1.1.5" +version = "1.1.6" license = "MIT" edition = "2018" exclude = ["index.node"] diff --git a/packages/apis/package.json b/packages/apis/package.json index 1903d8e..14ef9d5 100644 --- a/packages/apis/package.json +++ b/packages/apis/package.json @@ -1,6 +1,6 @@ { "name": "@zk-email/zk-regex-apis", - "version": "1.1.5", + "version": "1.1.6", "description": "apis compatible with [zk-regex](https://github.com/zkemail/zk-regex/tree/main).", "contributors": [ "Javier Su ", diff --git a/packages/circom/circuits/common/body_hash_regex.circom b/packages/circom/circuits/common/body_hash_regex.circom index e841df5..b39ce37 100644 --- a/packages/circom/circuits/common/body_hash_regex.circom +++ b/packages/circom/circuits/common/body_hash_regex.circom @@ -16,7 +16,7 @@ template BodyHashRegex(msg_bytes) { component eq[48][num_bytes]; component lt[16][num_bytes]; component and[47][num_bytes]; - component multi_or[15][num_bytes]; + component multi_or[12][num_bytes]; signal states[num_bytes+1][28]; component state_changed[num_bytes]; @@ -216,36 +216,16 @@ template BodyHashRegex(msg_bytes) { and[13][i].b <== multi_or[4][i].out; and[14][i] = AND(); and[14][i].a <== states[i][5]; - multi_or[5][i] = MultiOR(16); - multi_or[5][i].in[0] <== and[11][i].out; - multi_or[5][i].in[1] <== and[12][i].out; - multi_or[5][i].in[2] <== eq[7][i].out; - multi_or[5][i].in[3] <== eq[8][i].out; - multi_or[5][i].in[4] <== eq[9][i].out; - multi_or[5][i].in[5] <== eq[10][i].out; - multi_or[5][i].in[6] <== eq[11][i].out; - multi_or[5][i].in[7] <== eq[12][i].out; - multi_or[5][i].in[8] <== eq[13][i].out; - multi_or[5][i].in[9] <== eq[14][i].out; - multi_or[5][i].in[10] <== eq[15][i].out; - multi_or[5][i].in[11] <== eq[16][i].out; - multi_or[5][i].in[12] <== eq[17][i].out; - multi_or[5][i].in[13] <== eq[18][i].out; - multi_or[5][i].in[14] <== eq[19][i].out; - multi_or[5][i].in[15] <== eq[20][i].out; - and[14][i].b <== multi_or[5][i].out; + and[14][i].b <== multi_or[4][i].out; and[15][i] = AND(); and[15][i].a <== states[i][6]; - multi_or[6][i] = MultiOR(2); - multi_or[6][i].in[0] <== and[8][i].out; - multi_or[6][i].in[1] <== and[9][i].out; - and[15][i].b <== multi_or[6][i].out; - multi_or[7][i] = MultiOR(4); - multi_or[7][i].in[0] <== and[10][i].out; - multi_or[7][i].in[1] <== and[13][i].out; - multi_or[7][i].in[2] <== and[14][i].out; - multi_or[7][i].in[3] <== and[15][i].out; - states[i+1][2] <== multi_or[7][i].out; + and[15][i].b <== multi_or[3][i].out; + multi_or[5][i] = MultiOR(4); + multi_or[5][i].in[0] <== and[10][i].out; + multi_or[5][i].in[1] <== and[13][i].out; + multi_or[5][i].in[2] <== and[14][i].out; + multi_or[5][i].in[3] <== and[15][i].out; + states[i+1][2] <== multi_or[5][i].out; state_changed[i].in[1] <== states[i+1][2]; eq[21][i] = IsEqual(); eq[21][i].in[0] <== in[i]; @@ -310,46 +290,30 @@ template BodyHashRegex(msg_bytes) { eq[34][i].in[1] <== 57; and[19][i] = AND(); and[19][i].a <== states[i][3]; - multi_or[8][i] = MultiOR(15); - multi_or[8][i].in[0] <== and[18][i].out; - multi_or[8][i].in[1] <== and[0][i].out; - multi_or[8][i].in[2] <== eq[23][i].out; - multi_or[8][i].in[3] <== eq[24][i].out; - multi_or[8][i].in[4] <== eq[25][i].out; - multi_or[8][i].in[5] <== eq[26][i].out; - multi_or[8][i].in[6] <== eq[27][i].out; - multi_or[8][i].in[7] <== eq[28][i].out; - multi_or[8][i].in[8] <== eq[29][i].out; - multi_or[8][i].in[9] <== eq[30][i].out; - multi_or[8][i].in[10] <== eq[31][i].out; - multi_or[8][i].in[11] <== eq[32][i].out; - multi_or[8][i].in[12] <== eq[33][i].out; - multi_or[8][i].in[13] <== eq[34][i].out; - multi_or[8][i].in[14] <== eq[21][i].out; - and[19][i].b <== multi_or[8][i].out; + multi_or[6][i] = MultiOR(15); + multi_or[6][i].in[0] <== and[18][i].out; + multi_or[6][i].in[1] <== and[0][i].out; + multi_or[6][i].in[2] <== eq[23][i].out; + multi_or[6][i].in[3] <== eq[24][i].out; + multi_or[6][i].in[4] <== eq[25][i].out; + multi_or[6][i].in[5] <== eq[26][i].out; + multi_or[6][i].in[6] <== eq[27][i].out; + multi_or[6][i].in[7] <== eq[28][i].out; + multi_or[6][i].in[8] <== eq[29][i].out; + multi_or[6][i].in[9] <== eq[30][i].out; + multi_or[6][i].in[10] <== eq[31][i].out; + multi_or[6][i].in[11] <== eq[32][i].out; + multi_or[6][i].in[12] <== eq[33][i].out; + multi_or[6][i].in[13] <== eq[34][i].out; + multi_or[6][i].in[14] <== eq[21][i].out; + and[19][i].b <== multi_or[6][i].out; and[20][i] = AND(); and[20][i].a <== states[i][5]; - multi_or[9][i] = MultiOR(15); - multi_or[9][i].in[0] <== and[18][i].out; - multi_or[9][i].in[1] <== and[0][i].out; - multi_or[9][i].in[2] <== eq[23][i].out; - multi_or[9][i].in[3] <== eq[24][i].out; - multi_or[9][i].in[4] <== eq[25][i].out; - multi_or[9][i].in[5] <== eq[26][i].out; - multi_or[9][i].in[6] <== eq[27][i].out; - multi_or[9][i].in[7] <== eq[28][i].out; - multi_or[9][i].in[8] <== eq[29][i].out; - multi_or[9][i].in[9] <== eq[30][i].out; - multi_or[9][i].in[10] <== eq[31][i].out; - multi_or[9][i].in[11] <== eq[32][i].out; - multi_or[9][i].in[12] <== eq[33][i].out; - multi_or[9][i].in[13] <== eq[34][i].out; - multi_or[9][i].in[14] <== eq[21][i].out; - and[20][i].b <== multi_or[9][i].out; - multi_or[10][i] = MultiOR(2); - multi_or[10][i].in[0] <== and[19][i].out; - multi_or[10][i].in[1] <== and[20][i].out; - states[i+1][5] <== multi_or[10][i].out; + and[20][i].b <== multi_or[6][i].out; + multi_or[7][i] = MultiOR(2); + multi_or[7][i].in[0] <== and[19][i].out; + multi_or[7][i].in[1] <== and[20][i].out; + states[i+1][5] <== multi_or[7][i].out; state_changed[i].in[4] <== states[i+1][5]; and[21][i] = AND(); and[21][i].a <== states[i][1]; @@ -357,10 +321,10 @@ template BodyHashRegex(msg_bytes) { and[22][i] = AND(); and[22][i].a <== states[i][26]; and[22][i].b <== eq[21][i].out; - multi_or[11][i] = MultiOR(2); - multi_or[11][i].in[0] <== and[21][i].out; - multi_or[11][i].in[1] <== and[22][i].out; - states[i+1][6] <== multi_or[11][i].out; + multi_or[8][i] = MultiOR(2); + multi_or[8][i].in[0] <== and[21][i].out; + multi_or[8][i].in[1] <== and[22][i].out; + states[i+1][6] <== multi_or[8][i].out; state_changed[i].in[5] <== states[i+1][6]; eq[35][i] = IsEqual(); eq[35][i].in[0] <== in[i]; @@ -371,10 +335,10 @@ template BodyHashRegex(msg_bytes) { and[24][i] = AND(); and[24][i].a <== states[i][8]; and[24][i].b <== eq[35][i].out; - multi_or[12][i] = MultiOR(2); - multi_or[12][i].in[0] <== and[23][i].out; - multi_or[12][i].in[1] <== and[24][i].out; - states[i+1][7] <== multi_or[12][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][7] <== multi_or[9][i].out; state_changed[i].in[6] <== states[i+1][7]; and[25][i] = AND(); and[25][i].a <== states[i][5]; @@ -390,10 +354,10 @@ template BodyHashRegex(msg_bytes) { and[27][i] = AND(); and[27][i].a <== states[i][10]; and[27][i].b <== eq[36][i].out; - multi_or[13][i] = MultiOR(2); - multi_or[13][i].in[0] <== and[26][i].out; - multi_or[13][i].in[1] <== and[27][i].out; - states[i+1][9] <== multi_or[13][i].out; + multi_or[10][i] = MultiOR(2); + multi_or[10][i].in[0] <== and[26][i].out; + multi_or[10][i].in[1] <== and[27][i].out; + states[i+1][9] <== multi_or[10][i].out; state_changed[i].in[8] <== states[i+1][9]; eq[37][i] = IsEqual(); eq[37][i].in[0] <== in[i]; @@ -407,10 +371,10 @@ template BodyHashRegex(msg_bytes) { and[29][i] = AND(); and[29][i].a <== states[i][9]; and[29][i].b <== eq[38][i].out; - multi_or[14][i] = MultiOR(2); - multi_or[14][i].in[0] <== and[28][i].out; - multi_or[14][i].in[1] <== and[29][i].out; - states[i+1][10] <== multi_or[14][i].out; + multi_or[11][i] = MultiOR(2); + multi_or[11][i].in[0] <== and[28][i].out; + multi_or[11][i].in[1] <== and[29][i].out; + states[i+1][10] <== multi_or[11][i].out; state_changed[i].in[9] <== states[i+1][10]; and[30][i] = AND(); and[30][i].a <== states[i][10]; diff --git a/packages/circom/circuits/common/email_addr_regex.circom b/packages/circom/circuits/common/email_addr_regex.circom index d7cd1c1..40072b4 100644 --- a/packages/circom/circuits/common/email_addr_regex.circom +++ b/packages/circom/circuits/common/email_addr_regex.circom @@ -16,7 +16,7 @@ template EmailAddrRegex(msg_bytes) { component eq[25][num_bytes]; component lt[8][num_bytes]; component and[9][num_bytes]; - component multi_or[6][num_bytes]; + component multi_or[5][num_bytes]; signal states[num_bytes+1][4]; component state_changed[num_bytes]; @@ -229,26 +229,11 @@ template EmailAddrRegex(msg_bytes) { 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[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[7][i].out; - multi_or[5][i].in[1] <== and[8][i].out; - states[i+1][3] <== multi_or[5][i].out; + and[8][i].b <== multi_or[3][i].out; + multi_or[4][i] = MultiOR(2); + multi_or[4][i].in[0] <== and[7][i].out; + multi_or[4][i].in[1] <== and[8][i].out; + states[i+1][3] <== multi_or[4][i].out; state_changed[i].in[2] <== states[i+1][3]; states[i+1][0] <== 1 - state_changed[i].out; } 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 232e1c4..632d817 100644 --- a/packages/circom/circuits/common/email_addr_with_name_regex.circom +++ b/packages/circom/circuits/common/email_addr_with_name_regex.circom @@ -16,7 +16,7 @@ template EmailAddrWithNameRegex(msg_bytes) { component eq[51][num_bytes]; component lt[22][num_bytes]; component and[30][num_bytes]; - component multi_or[15][num_bytes]; + component multi_or[13][num_bytes]; signal states[num_bytes+1][7]; component state_changed[num_bytes]; @@ -447,27 +447,11 @@ template EmailAddrWithNameRegex(msg_bytes) { and[17][i].b <== multi_or[8][i].out; and[18][i] = AND(); and[18][i].a <== states[i][6]; - multi_or[9][i] = MultiOR(15); - multi_or[9][i].in[0] <== and[15][i].out; - multi_or[9][i].in[1] <== and[16][i].out; - multi_or[9][i].in[2] <== eq[29][i].out; - multi_or[9][i].in[3] <== eq[30][i].out; - multi_or[9][i].in[4] <== eq[31][i].out; - multi_or[9][i].in[5] <== eq[32][i].out; - multi_or[9][i].in[6] <== eq[33][i].out; - multi_or[9][i].in[7] <== eq[34][i].out; - multi_or[9][i].in[8] <== eq[35][i].out; - multi_or[9][i].in[9] <== eq[36][i].out; - multi_or[9][i].in[10] <== eq[37][i].out; - multi_or[9][i].in[11] <== eq[38][i].out; - multi_or[9][i].in[12] <== eq[39][i].out; - multi_or[9][i].in[13] <== eq[40][i].out; - multi_or[9][i].in[14] <== eq[41][i].out; - and[18][i].b <== multi_or[9][i].out; - multi_or[10][i] = MultiOR(2); - multi_or[10][i].in[0] <== and[17][i].out; - multi_or[10][i].in[1] <== and[18][i].out; - states[i+1][2] <== multi_or[10][i].out; + and[18][i].b <== multi_or[8][i].out; + multi_or[9][i] = MultiOR(2); + multi_or[9][i].in[0] <== and[17][i].out; + multi_or[9][i].in[1] <== and[18][i].out; + states[i+1][2] <== multi_or[9][i].out; state_changed[i].in[1] <== states[i+1][2]; and[19][i] = AND(); and[19][i].a <== states[i][2]; @@ -495,14 +479,14 @@ template EmailAddrWithNameRegex(msg_bytes) { and[25][i] = AND(); and[25][i].a <== states[i][6]; and[25][i].b <== eq[42][i].out; - multi_or[11][i] = MultiOR(6); - multi_or[11][i].in[0] <== and[20][i].out; - multi_or[11][i].in[1] <== and[21][i].out; - multi_or[11][i].in[2] <== and[22][i].out; - multi_or[11][i].in[3] <== and[23][i].out; - multi_or[11][i].in[4] <== and[24][i].out; - multi_or[11][i].in[5] <== and[25][i].out; - states[i+1][4] <== multi_or[11][i].out; + multi_or[10][i] = MultiOR(6); + multi_or[10][i].in[0] <== and[20][i].out; + multi_or[10][i].in[1] <== and[21][i].out; + multi_or[10][i].in[2] <== and[22][i].out; + multi_or[10][i].in[3] <== and[23][i].out; + multi_or[10][i].in[4] <== and[24][i].out; + multi_or[10][i].in[5] <== and[25][i].out; + states[i+1][4] <== multi_or[10][i].out; state_changed[i].in[3] <== states[i+1][4]; lt[20][i] = LessEqThan(8); lt[20][i].in[0] <== 94; @@ -539,66 +523,40 @@ template EmailAddrWithNameRegex(msg_bytes) { eq[50][i].in[1] <== 43; and[27][i] = AND(); and[27][i].a <== states[i][4]; - multi_or[12][i] = MultiOR(25); - multi_or[12][i].in[0] <== and[15][i].out; - multi_or[12][i].in[1] <== and[26][i].out; - multi_or[12][i].in[2] <== eq[43][i].out; - multi_or[12][i].in[3] <== eq[44][i].out; - multi_or[12][i].in[4] <== eq[45][i].out; - multi_or[12][i].in[5] <== eq[46][i].out; - multi_or[12][i].in[6] <== eq[47][i].out; - multi_or[12][i].in[7] <== eq[48][i].out; - multi_or[12][i].in[8] <== eq[49][i].out; - multi_or[12][i].in[9] <== eq[50][i].out; - multi_or[12][i].in[10] <== eq[29][i].out; - multi_or[12][i].in[11] <== eq[30][i].out; - multi_or[12][i].in[12] <== eq[13][i].out; - multi_or[12][i].in[13] <== eq[31][i].out; - multi_or[12][i].in[14] <== eq[32][i].out; - multi_or[12][i].in[15] <== eq[33][i].out; - multi_or[12][i].in[16] <== eq[34][i].out; - multi_or[12][i].in[17] <== eq[35][i].out; - multi_or[12][i].in[18] <== eq[36][i].out; - multi_or[12][i].in[19] <== eq[37][i].out; - multi_or[12][i].in[20] <== eq[38][i].out; - multi_or[12][i].in[21] <== eq[39][i].out; - multi_or[12][i].in[22] <== eq[40][i].out; - multi_or[12][i].in[23] <== eq[16][i].out; - multi_or[12][i].in[24] <== eq[17][i].out; - and[27][i].b <== multi_or[12][i].out; + multi_or[11][i] = MultiOR(25); + multi_or[11][i].in[0] <== and[15][i].out; + multi_or[11][i].in[1] <== and[26][i].out; + multi_or[11][i].in[2] <== eq[43][i].out; + multi_or[11][i].in[3] <== eq[44][i].out; + multi_or[11][i].in[4] <== eq[45][i].out; + multi_or[11][i].in[5] <== eq[46][i].out; + multi_or[11][i].in[6] <== eq[47][i].out; + multi_or[11][i].in[7] <== eq[48][i].out; + multi_or[11][i].in[8] <== eq[49][i].out; + multi_or[11][i].in[9] <== eq[50][i].out; + multi_or[11][i].in[10] <== eq[29][i].out; + multi_or[11][i].in[11] <== eq[30][i].out; + multi_or[11][i].in[12] <== eq[13][i].out; + multi_or[11][i].in[13] <== eq[31][i].out; + multi_or[11][i].in[14] <== eq[32][i].out; + multi_or[11][i].in[15] <== eq[33][i].out; + multi_or[11][i].in[16] <== eq[34][i].out; + multi_or[11][i].in[17] <== eq[35][i].out; + multi_or[11][i].in[18] <== eq[36][i].out; + multi_or[11][i].in[19] <== eq[37][i].out; + multi_or[11][i].in[20] <== eq[38][i].out; + multi_or[11][i].in[21] <== eq[39][i].out; + multi_or[11][i].in[22] <== eq[40][i].out; + multi_or[11][i].in[23] <== eq[16][i].out; + multi_or[11][i].in[24] <== eq[17][i].out; + and[27][i].b <== multi_or[11][i].out; and[28][i] = AND(); and[28][i].a <== states[i][5]; - multi_or[13][i] = MultiOR(25); - multi_or[13][i].in[0] <== and[15][i].out; - multi_or[13][i].in[1] <== and[26][i].out; - multi_or[13][i].in[2] <== eq[43][i].out; - multi_or[13][i].in[3] <== eq[44][i].out; - multi_or[13][i].in[4] <== eq[45][i].out; - multi_or[13][i].in[5] <== eq[46][i].out; - multi_or[13][i].in[6] <== eq[47][i].out; - multi_or[13][i].in[7] <== eq[48][i].out; - multi_or[13][i].in[8] <== eq[49][i].out; - multi_or[13][i].in[9] <== eq[50][i].out; - multi_or[13][i].in[10] <== eq[29][i].out; - multi_or[13][i].in[11] <== eq[30][i].out; - multi_or[13][i].in[12] <== eq[13][i].out; - multi_or[13][i].in[13] <== eq[31][i].out; - multi_or[13][i].in[14] <== eq[32][i].out; - multi_or[13][i].in[15] <== eq[33][i].out; - multi_or[13][i].in[16] <== eq[34][i].out; - multi_or[13][i].in[17] <== eq[35][i].out; - multi_or[13][i].in[18] <== eq[36][i].out; - multi_or[13][i].in[19] <== eq[37][i].out; - multi_or[13][i].in[20] <== eq[38][i].out; - multi_or[13][i].in[21] <== eq[39][i].out; - multi_or[13][i].in[22] <== eq[40][i].out; - multi_or[13][i].in[23] <== eq[16][i].out; - multi_or[13][i].in[24] <== eq[17][i].out; - and[28][i].b <== multi_or[13][i].out; - multi_or[14][i] = MultiOR(2); - multi_or[14][i].in[0] <== and[27][i].out; - multi_or[14][i].in[1] <== and[28][i].out; - states[i+1][5] <== multi_or[14][i].out; + and[28][i].b <== multi_or[11][i].out; + multi_or[12][i] = MultiOR(2); + multi_or[12][i].in[0] <== and[27][i].out; + multi_or[12][i].in[1] <== and[28][i].out; + states[i+1][5] <== multi_or[12][i].out; state_changed[i].in[4] <== states[i+1][5]; and[29][i] = AND(); and[29][i].a <== states[i][5]; diff --git a/packages/circom/circuits/common/email_domain_regex.circom b/packages/circom/circuits/common/email_domain_regex.circom index 4bfddd6..c7e0bb9 100644 --- a/packages/circom/circuits/common/email_domain_regex.circom +++ b/packages/circom/circuits/common/email_domain_regex.circom @@ -16,7 +16,7 @@ template EmailDomainRegex(msg_bytes) { component eq[25][num_bytes]; component lt[8][num_bytes]; component and[9][num_bytes]; - component multi_or[6][num_bytes]; + component multi_or[5][num_bytes]; signal states[num_bytes+1][4]; component state_changed[num_bytes]; @@ -229,26 +229,11 @@ template EmailDomainRegex(msg_bytes) { 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[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[7][i].out; - multi_or[5][i].in[1] <== and[8][i].out; - states[i+1][3] <== multi_or[5][i].out; + and[8][i].b <== multi_or[3][i].out; + multi_or[4][i] = MultiOR(2); + multi_or[4][i].in[0] <== and[7][i].out; + multi_or[4][i].in[1] <== and[8][i].out; + states[i+1][3] <== multi_or[4][i].out; state_changed[i].in[2] <== states[i+1][3]; states[i+1][0] <== 1 - state_changed[i].out; } diff --git a/packages/circom/circuits/common/from_all_regex.circom b/packages/circom/circuits/common/from_all_regex.circom index 3fefad0..0a05e24 100644 --- a/packages/circom/circuits/common/from_all_regex.circom +++ b/packages/circom/circuits/common/from_all_regex.circom @@ -16,7 +16,7 @@ template FromAllRegex(msg_bytes) { component eq[20][num_bytes]; component lt[2][num_bytes]; component and[14][num_bytes]; - component multi_or[5][num_bytes]; + component multi_or[4][num_bytes]; signal states[num_bytes+1][11]; component state_changed[num_bytes]; @@ -91,25 +91,11 @@ template FromAllRegex(msg_bytes) { and[1][i].b <== multi_or[0][i].out; and[2][i] = AND(); and[2][i].a <== states[i][8]; - multi_or[1][i] = MultiOR(13); - multi_or[1][i].in[0] <== and[0][i].out; - multi_or[1][i].in[1] <== eq[0][i].out; - multi_or[1][i].in[2] <== eq[1][i].out; - multi_or[1][i].in[3] <== eq[2][i].out; - multi_or[1][i].in[4] <== eq[3][i].out; - multi_or[1][i].in[5] <== eq[4][i].out; - multi_or[1][i].in[6] <== eq[5][i].out; - multi_or[1][i].in[7] <== eq[6][i].out; - multi_or[1][i].in[8] <== eq[7][i].out; - multi_or[1][i].in[9] <== eq[8][i].out; - multi_or[1][i].in[10] <== eq[9][i].out; - multi_or[1][i].in[11] <== eq[10][i].out; - multi_or[1][i].in[12] <== eq[11][i].out; - and[2][i].b <== multi_or[1][i].out; - multi_or[2][i] = MultiOR(2); - multi_or[2][i].in[0] <== and[1][i].out; - multi_or[2][i].in[1] <== and[2][i].out; - states[i+1][1] <== multi_or[2][i].out; + and[2][i].b <== multi_or[0][i].out; + multi_or[1][i] = MultiOR(2); + multi_or[1][i].in[0] <== and[1][i].out; + multi_or[1][i].in[1] <== and[2][i].out; + states[i+1][1] <== multi_or[1][i].out; state_changed[i].in[0] <== states[i+1][1]; eq[12][i] = IsEqual(); eq[12][i].in[0] <== in[i]; @@ -120,10 +106,10 @@ template FromAllRegex(msg_bytes) { and[4][i] = AND(); and[4][i].a <== states[i][3]; and[4][i].b <== eq[12][i].out; - multi_or[3][i] = MultiOR(2); - multi_or[3][i].in[0] <== and[3][i].out; - multi_or[3][i].in[1] <== and[4][i].out; - states[i+1][2] <== multi_or[3][i].out; + multi_or[2][i] = MultiOR(2); + multi_or[2][i].in[0] <== and[3][i].out; + multi_or[2][i].in[1] <== and[4][i].out; + states[i+1][2] <== multi_or[2][i].out; state_changed[i].in[1] <== states[i+1][2]; eq[13][i] = IsEqual(); eq[13][i].in[0] <== in[i]; @@ -137,10 +123,10 @@ template FromAllRegex(msg_bytes) { and[6][i] = AND(); and[6][i].a <== states[i][2]; and[6][i].b <== eq[14][i].out; - multi_or[4][i] = MultiOR(2); - multi_or[4][i].in[0] <== and[5][i].out; - multi_or[4][i].in[1] <== and[6][i].out; - states[i+1][3] <== multi_or[4][i].out; + multi_or[3][i] = MultiOR(2); + multi_or[3][i].in[0] <== and[5][i].out; + multi_or[3][i].in[1] <== and[6][i].out; + states[i+1][3] <== multi_or[3][i].out; state_changed[i].in[2] <== states[i+1][3]; eq[15][i] = IsEqual(); eq[15][i].in[0] <== in[i]; diff --git a/packages/circom/circuits/common/message_id_regex.circom b/packages/circom/circuits/common/message_id_regex.circom index 3038867..f89299e 100644 --- a/packages/circom/circuits/common/message_id_regex.circom +++ b/packages/circom/circuits/common/message_id_regex.circom @@ -16,7 +16,7 @@ template MessageIdRegex(msg_bytes) { component eq[28][num_bytes]; component lt[4][num_bytes]; component and[23][num_bytes]; - component multi_or[5][num_bytes]; + component multi_or[4][num_bytes]; signal states[num_bytes+1][19]; component state_changed[num_bytes]; @@ -113,29 +113,11 @@ template MessageIdRegex(msg_bytes) { and[2][i].b <== multi_or[0][i].out; and[3][i] = AND(); and[3][i].a <== states[i][18]; - multi_or[1][i] = MultiOR(17); - multi_or[1][i].in[0] <== and[0][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; - and[3][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[3][i].out; - states[i+1][1] <== multi_or[2][i].out; + and[3][i].b <== multi_or[0][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[3][i].out; + states[i+1][1] <== multi_or[1][i].out; state_changed[i].in[0] <== states[i+1][1]; eq[15][i] = IsEqual(); eq[15][i].in[0] <== in[i]; @@ -146,10 +128,10 @@ template MessageIdRegex(msg_bytes) { and[5][i] = AND(); and[5][i].a <== states[i][3]; and[5][i].b <== eq[15][i].out; - multi_or[3][i] = MultiOR(2); - multi_or[3][i].in[0] <== and[4][i].out; - multi_or[3][i].in[1] <== and[5][i].out; - states[i+1][2] <== multi_or[3][i].out; + multi_or[2][i] = MultiOR(2); + multi_or[2][i].in[0] <== and[4][i].out; + multi_or[2][i].in[1] <== and[5][i].out; + states[i+1][2] <== multi_or[2][i].out; state_changed[i].in[1] <== states[i+1][2]; eq[16][i] = IsEqual(); eq[16][i].in[0] <== in[i]; @@ -163,10 +145,10 @@ template MessageIdRegex(msg_bytes) { and[7][i] = AND(); and[7][i].a <== states[i][2]; and[7][i].b <== eq[17][i].out; - multi_or[4][i] = MultiOR(2); - multi_or[4][i].in[0] <== and[6][i].out; - multi_or[4][i].in[1] <== and[7][i].out; - states[i+1][3] <== multi_or[4][i].out; + multi_or[3][i] = MultiOR(2); + multi_or[3][i].in[0] <== and[6][i].out; + multi_or[3][i].in[1] <== and[7][i].out; + states[i+1][3] <== multi_or[3][i].out; state_changed[i].in[2] <== states[i+1][3]; eq[18][i] = IsEqual(); eq[18][i].in[0] <== in[i]; diff --git a/packages/circom/circuits/common/subject_all_regex.circom b/packages/circom/circuits/common/subject_all_regex.circom index 6cf3c33..4d5aaa5 100644 --- a/packages/circom/circuits/common/subject_all_regex.circom +++ b/packages/circom/circuits/common/subject_all_regex.circom @@ -16,7 +16,7 @@ template SubjectAllRegex(msg_bytes) { component eq[23][num_bytes]; component lt[2][num_bytes]; component and[17][num_bytes]; - component multi_or[5][num_bytes]; + component multi_or[4][num_bytes]; signal states[num_bytes+1][14]; component state_changed[num_bytes]; @@ -91,25 +91,11 @@ template SubjectAllRegex(msg_bytes) { and[1][i].b <== multi_or[0][i].out; and[2][i] = AND(); and[2][i].a <== states[i][12]; - multi_or[1][i] = MultiOR(13); - multi_or[1][i].in[0] <== and[0][i].out; - multi_or[1][i].in[1] <== eq[0][i].out; - multi_or[1][i].in[2] <== eq[1][i].out; - multi_or[1][i].in[3] <== eq[2][i].out; - multi_or[1][i].in[4] <== eq[3][i].out; - multi_or[1][i].in[5] <== eq[4][i].out; - multi_or[1][i].in[6] <== eq[5][i].out; - multi_or[1][i].in[7] <== eq[6][i].out; - multi_or[1][i].in[8] <== eq[7][i].out; - multi_or[1][i].in[9] <== eq[8][i].out; - multi_or[1][i].in[10] <== eq[9][i].out; - multi_or[1][i].in[11] <== eq[10][i].out; - multi_or[1][i].in[12] <== eq[11][i].out; - and[2][i].b <== multi_or[1][i].out; - multi_or[2][i] = MultiOR(2); - multi_or[2][i].in[0] <== and[1][i].out; - multi_or[2][i].in[1] <== and[2][i].out; - states[i+1][1] <== multi_or[2][i].out; + and[2][i].b <== multi_or[0][i].out; + multi_or[1][i] = MultiOR(2); + multi_or[1][i].in[0] <== and[1][i].out; + multi_or[1][i].in[1] <== and[2][i].out; + states[i+1][1] <== multi_or[1][i].out; state_changed[i].in[0] <== states[i+1][1]; eq[12][i] = IsEqual(); eq[12][i].in[0] <== in[i]; @@ -120,10 +106,10 @@ template SubjectAllRegex(msg_bytes) { and[4][i] = AND(); and[4][i].a <== states[i][3]; and[4][i].b <== eq[12][i].out; - multi_or[3][i] = MultiOR(2); - multi_or[3][i].in[0] <== and[3][i].out; - multi_or[3][i].in[1] <== and[4][i].out; - states[i+1][2] <== multi_or[3][i].out; + multi_or[2][i] = MultiOR(2); + multi_or[2][i].in[0] <== and[3][i].out; + multi_or[2][i].in[1] <== and[4][i].out; + states[i+1][2] <== multi_or[2][i].out; state_changed[i].in[1] <== states[i+1][2]; eq[13][i] = IsEqual(); eq[13][i].in[0] <== in[i]; @@ -137,10 +123,10 @@ template SubjectAllRegex(msg_bytes) { and[6][i] = AND(); and[6][i].a <== states[i][2]; and[6][i].b <== eq[14][i].out; - multi_or[4][i] = MultiOR(2); - multi_or[4][i].in[0] <== and[5][i].out; - multi_or[4][i].in[1] <== and[6][i].out; - states[i+1][3] <== multi_or[4][i].out; + multi_or[3][i] = MultiOR(2); + multi_or[3][i].in[0] <== and[5][i].out; + multi_or[3][i].in[1] <== and[6][i].out; + states[i+1][3] <== multi_or[3][i].out; state_changed[i].in[2] <== states[i+1][3]; eq[15][i] = IsEqual(); eq[15][i].in[0] <== in[i]; diff --git a/packages/circom/circuits/common/timestamp_regex.circom b/packages/circom/circuits/common/timestamp_regex.circom index f68c045..5f2e99d 100644 --- a/packages/circom/circuits/common/timestamp_regex.circom +++ b/packages/circom/circuits/common/timestamp_regex.circom @@ -16,7 +16,7 @@ template TimestampRegex(msg_bytes) { component eq[35][num_bytes]; component lt[10][num_bytes]; component and[41][num_bytes]; - component multi_or[13][num_bytes]; + component multi_or[10][num_bytes]; signal states[num_bytes+1][27]; component state_changed[num_bytes]; @@ -135,23 +135,16 @@ template TimestampRegex(msg_bytes) { and[10][i].b <== multi_or[3][i].out; and[11][i] = AND(); and[11][i].a <== states[i][7]; - multi_or[4][i] = MultiOR(2); - multi_or[4][i].in[0] <== and[6][i].out; - multi_or[4][i].in[1] <== and[7][i].out; - and[11][i].b <== multi_or[4][i].out; + and[11][i].b <== multi_or[2][i].out; and[12][i] = AND(); and[12][i].a <== states[i][26]; - multi_or[5][i] = MultiOR(3); - multi_or[5][i].in[0] <== and[9][i].out; - multi_or[5][i].in[1] <== and[7][i].out; - multi_or[5][i].in[2] <== eq[6][i].out; - and[12][i].b <== multi_or[5][i].out; - multi_or[6][i] = MultiOR(4); - multi_or[6][i].in[0] <== and[8][i].out; - multi_or[6][i].in[1] <== and[10][i].out; - multi_or[6][i].in[2] <== and[11][i].out; - multi_or[6][i].in[3] <== and[12][i].out; - states[i+1][2] <== multi_or[6][i].out; + and[12][i].b <== multi_or[3][i].out; + multi_or[4][i] = MultiOR(4); + multi_or[4][i].in[0] <== and[8][i].out; + multi_or[4][i].in[1] <== and[10][i].out; + multi_or[4][i].in[2] <== and[11][i].out; + multi_or[4][i].in[3] <== and[12][i].out; + states[i+1][2] <== multi_or[4][i].out; state_changed[i].in[1] <== states[i+1][2]; eq[7][i] = IsEqual(); eq[7][i].in[0] <== in[i]; @@ -185,36 +178,25 @@ template TimestampRegex(msg_bytes) { eq[16][i].in[1] <== 57; and[13][i] = AND(); and[13][i].a <== states[i][3]; - multi_or[7][i] = MultiOR(10); - multi_or[7][i].in[0] <== eq[7][i].out; - multi_or[7][i].in[1] <== eq[8][i].out; - multi_or[7][i].in[2] <== eq[9][i].out; - multi_or[7][i].in[3] <== eq[10][i].out; - multi_or[7][i].in[4] <== eq[11][i].out; - multi_or[7][i].in[5] <== eq[12][i].out; - multi_or[7][i].in[6] <== eq[13][i].out; - multi_or[7][i].in[7] <== eq[14][i].out; - multi_or[7][i].in[8] <== eq[15][i].out; - multi_or[7][i].in[9] <== eq[16][i].out; - and[13][i].b <== multi_or[7][i].out; + multi_or[5][i] = MultiOR(10); + multi_or[5][i].in[0] <== eq[7][i].out; + multi_or[5][i].in[1] <== eq[8][i].out; + multi_or[5][i].in[2] <== eq[9][i].out; + multi_or[5][i].in[3] <== eq[10][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; + and[13][i].b <== multi_or[5][i].out; and[14][i] = AND(); and[14][i].a <== states[i][26]; - multi_or[8][i] = MultiOR(10); - multi_or[8][i].in[0] <== eq[7][i].out; - multi_or[8][i].in[1] <== eq[8][i].out; - multi_or[8][i].in[2] <== eq[9][i].out; - multi_or[8][i].in[3] <== eq[10][i].out; - multi_or[8][i].in[4] <== eq[11][i].out; - multi_or[8][i].in[5] <== eq[12][i].out; - multi_or[8][i].in[6] <== eq[13][i].out; - multi_or[8][i].in[7] <== eq[14][i].out; - multi_or[8][i].in[8] <== eq[15][i].out; - multi_or[8][i].in[9] <== eq[16][i].out; - and[14][i].b <== multi_or[8][i].out; - multi_or[9][i] = MultiOR(2); - multi_or[9][i].in[0] <== and[13][i].out; - multi_or[9][i].in[1] <== and[14][i].out; - states[i+1][3] <== multi_or[9][i].out; + and[14][i].b <== multi_or[5][i].out; + multi_or[6][i] = MultiOR(2); + multi_or[6][i].in[0] <== and[13][i].out; + multi_or[6][i].in[1] <== and[14][i].out; + states[i+1][3] <== multi_or[6][i].out; state_changed[i].in[2] <== states[i+1][3]; eq[17][i] = IsEqual(); eq[17][i].in[0] <== in[i]; @@ -238,10 +220,10 @@ template TimestampRegex(msg_bytes) { and[18][i] = AND(); and[18][i].a <== states[i][5]; and[18][i].b <== eq[18][i].out; - multi_or[10][i] = MultiOR(2); - multi_or[10][i].in[0] <== and[17][i].out; - multi_or[10][i].in[1] <== and[18][i].out; - states[i+1][6] <== multi_or[10][i].out; + multi_or[7][i] = MultiOR(2); + multi_or[7][i].in[0] <== and[17][i].out; + multi_or[7][i].in[1] <== and[18][i].out; + states[i+1][6] <== multi_or[7][i].out; state_changed[i].in[5] <== states[i+1][6]; eq[19][i] = IsEqual(); eq[19][i].in[0] <== in[i]; @@ -260,10 +242,10 @@ template TimestampRegex(msg_bytes) { and[21][i] = AND(); and[21][i].a <== states[i][9]; and[21][i].b <== eq[20][i].out; - multi_or[11][i] = MultiOR(2); - multi_or[11][i].in[0] <== and[20][i].out; - multi_or[11][i].in[1] <== and[21][i].out; - states[i+1][8] <== multi_or[11][i].out; + multi_or[8][i] = MultiOR(2); + multi_or[8][i].in[0] <== and[20][i].out; + multi_or[8][i].in[1] <== and[21][i].out; + states[i+1][8] <== multi_or[8][i].out; state_changed[i].in[7] <== states[i+1][8]; eq[21][i] = IsEqual(); eq[21][i].in[0] <== in[i]; @@ -277,10 +259,10 @@ template TimestampRegex(msg_bytes) { and[23][i] = AND(); and[23][i].a <== states[i][8]; and[23][i].b <== eq[22][i].out; - multi_or[12][i] = MultiOR(2); - multi_or[12][i].in[0] <== and[22][i].out; - multi_or[12][i].in[1] <== and[23][i].out; - states[i+1][9] <== multi_or[12][i].out; + multi_or[9][i] = MultiOR(2); + multi_or[9][i].in[0] <== and[22][i].out; + multi_or[9][i].in[1] <== and[23][i].out; + states[i+1][9] <== multi_or[9][i].out; state_changed[i].in[8] <== states[i+1][9]; eq[23][i] = IsEqual(); eq[23][i].in[0] <== in[i]; diff --git a/packages/circom/package.json b/packages/circom/package.json index 5ee3cbf..77abefb 100644 --- a/packages/circom/package.json +++ b/packages/circom/package.json @@ -1,6 +1,6 @@ { "name": "@zk-email/zk-regex-circom", - "version": "1.2.0", + "version": "1.2.1", "license": "MIT", "description": "regex verification circuits in circom for common regexes, generated with the compiler in [zk-regex](https://github.com/zkemail/zk-regex/tree/main).", "contributors": [ diff --git a/packages/circom/tests/circuits/negate1_regex.circom b/packages/circom/tests/circuits/negate1_regex.circom index 126aa8a..58e1ce6 100644 --- a/packages/circom/tests/circuits/negate1_regex.circom +++ b/packages/circom/tests/circuits/negate1_regex.circom @@ -16,7 +16,7 @@ template Negate1Regex(msg_bytes) { component eq[3][num_bytes]; component lt[6][num_bytes]; component and[8][num_bytes]; - component multi_or[3][num_bytes]; + component multi_or[2][num_bytes]; signal states[num_bytes+1][5]; component state_changed[num_bytes]; @@ -63,15 +63,11 @@ template Negate1Regex(msg_bytes) { and[3][i].b <== multi_or[0][i].out; and[4][i] = AND(); and[4][i].a <== states[i][3]; - multi_or[1][i] = MultiOR(3); - multi_or[1][i].in[0] <== and[0][i].out; - multi_or[1][i].in[1] <== and[1][i].out; - multi_or[1][i].in[2] <== and[2][i].out; - and[4][i].b <== multi_or[1][i].out; - multi_or[2][i] = MultiOR(2); - multi_or[2][i].in[0] <== and[3][i].out; - multi_or[2][i].in[1] <== and[4][i].out; - states[i+1][1] <== multi_or[2][i].out; + and[4][i].b <== multi_or[0][i].out; + multi_or[1][i] = MultiOR(2); + multi_or[1][i].in[0] <== and[3][i].out; + multi_or[1][i].in[1] <== and[4][i].out; + states[i+1][1] <== multi_or[1][i].out; state_changed[i].in[0] <== states[i+1][1]; eq[0][i] = IsEqual(); eq[0][i].in[0] <== in[i]; diff --git a/packages/circom/tests/circuits/simple_regex.circom b/packages/circom/tests/circuits/simple_regex.circom index 839df47..f24bced 100644 --- a/packages/circom/tests/circuits/simple_regex.circom +++ b/packages/circom/tests/circuits/simple_regex.circom @@ -15,7 +15,7 @@ template SimpleRegex(msg_bytes) { component eq[8][num_bytes]; component and[11][num_bytes]; - component multi_or[5][num_bytes]; + component multi_or[4][num_bytes]; signal states[num_bytes+1][10]; component state_changed[num_bytes]; @@ -94,14 +94,11 @@ template SimpleRegex(msg_bytes) { and[7][i].b <== multi_or[2][i].out; and[8][i] = AND(); and[8][i].a <== states[i][7]; + and[8][i].b <== multi_or[2][i].out; multi_or[3][i] = MultiOR(2); - multi_or[3][i].in[0] <== eq[3][i].out; - multi_or[3][i].in[1] <== eq[6][i].out; - and[8][i].b <== multi_or[3][i].out; - multi_or[4][i] = MultiOR(2); - multi_or[4][i].in[0] <== and[7][i].out; - multi_or[4][i].in[1] <== and[8][i].out; - states[i+1][7] <== multi_or[4][i].out; + multi_or[3][i].in[0] <== and[7][i].out; + multi_or[3][i].in[1] <== and[8][i].out; + states[i+1][7] <== multi_or[3][i].out; state_changed[i].in[6] <== states[i+1][7]; and[9][i] = AND(); and[9][i].a <== states[i][7]; diff --git a/packages/compiler/Cargo.toml b/packages/compiler/Cargo.toml index 3aa40ca..198d8db 100644 --- a/packages/compiler/Cargo.toml +++ b/packages/compiler/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "zk-regex-compiler" -version = "1.0.6" +version = "1.0.7" authors = [ "Javier Su ", "Kata Choi ", diff --git a/packages/compiler/package.json b/packages/compiler/package.json index 25c594d..3de3d3f 100644 --- a/packages/compiler/package.json +++ b/packages/compiler/package.json @@ -1,6 +1,6 @@ { "name": "@zk-email/zk-regex-compiler", - "version": "1.0.6", + "version": "1.0.7", "description": "a compiler to generate a regex verification circuit in circom from a user-defined regex. Please check [zk-regex](https://github.com/zkemail/zk-regex/tree/main) for the detail.", "main": "index.node", "contributors": [ diff --git a/packages/compiler/src/gen_circom.js b/packages/compiler/src/gen_circom.js index ffa817d..15939b8 100644 --- a/packages/compiler/src/gen_circom.js +++ b/packages/compiler/src/gen_circom.js @@ -62,6 +62,8 @@ function genCircomAllstr(graph_json, template_name) { range_checks[i] = new Array(256); } const eq_checks = new Array(256); + const multi_or_checks1 = {}; + const multi_or_checks2 = {}; let lines = []; @@ -208,17 +210,18 @@ function genCircomAllstr(graph_json, template_name) { // } lines.push(`\t\tand[${and_i}][i].b <== ${eq_outputs[0][0]}[${eq_outputs[0][1]}][i].out;`); } else if (eq_outputs.length > 1) { - lines.push(`\t\tmulti_or[${multi_or_i}][i] = MultiOR(${eq_outputs.length});`); - for (let output_i = 0; output_i < eq_outputs.length; output_i++) { - lines.push(`\t\tmulti_or[${multi_or_i}][i].in[${output_i}] <== ${eq_outputs[output_i][0]}[${eq_outputs[output_i][1]}][i].out;`); + const eq_outputs_key = JSON.stringify(eq_outputs); + if (multi_or_checks1[eq_outputs_key] === undefined) { + lines.push(`\t\tmulti_or[${multi_or_i}][i] = MultiOR(${eq_outputs.length});`); + for (let output_i = 0; output_i < eq_outputs.length; output_i++) { + lines.push(`\t\tmulti_or[${multi_or_i}][i].in[${output_i}] <== ${eq_outputs[output_i][0]}[${eq_outputs[output_i][1]}][i].out;`); + } + lines.push(`\t\tand[${and_i}][i].b <== multi_or[${multi_or_i}][i].out;`); + multi_or_checks1[eq_outputs_key] = multi_or_i; + multi_or_i += 1 + } else { + lines.push(`\t\tand[${and_i}][i].b <== multi_or[${multi_or_checks1[eq_outputs_key]}][i].out;`); } - // if (is_negate) { - // lines.push(`\t\tand[${and_i}][i].b <== 1 - multi_or[${multi_or_i}][i].out;`); - // } else { - // lines.push(`\t\tand[${and_i}][i].b <== multi_or[${multi_or_i}][i].out;`); - // } - lines.push(`\t\tand[${and_i}][i].b <== multi_or[${multi_or_i}][i].out;`); - multi_or_i += 1 } outputs.push(and_i); @@ -228,12 +231,19 @@ function genCircomAllstr(graph_json, template_name) { if (outputs.length === 1) { lines.push(`\t\tstates[i+1][${i}] <== and[${outputs[0]}][i].out;`); } else if (outputs.length > 1) { - lines.push(`\t\tmulti_or[${multi_or_i}][i] = MultiOR(${outputs.length});`); - for (let output_i = 0; output_i < outputs.length; output_i++) { - lines.push(`\t\tmulti_or[${multi_or_i}][i].in[${output_i}] <== and[${outputs[output_i]}][i].out;`); + const outputs_key = JSON.stringify(outputs); + if (multi_or_checks2[outputs_key] === undefined) { + lines.push(`\t\tmulti_or[${multi_or_i}][i] = MultiOR(${outputs.length});`); + for (let output_i = 0; output_i < outputs.length; output_i++) { + lines.push(`\t\tmulti_or[${multi_or_i}][i].in[${output_i}] <== and[${outputs[output_i]}][i].out;`); + } + lines.push(`\t\tstates[i+1][${i}] <== multi_or[${multi_or_i}][i].out;`); + multi_or_checks2[outputs_key] = multi_or_i; + multi_or_i += 1 + } else { + lines.push(`\t\tstates[i+1][${i}] <== multi_or[${multi_or_checks2[outputs_key]}][i].out;`); } - lines.push(`\t\tstates[i+1][${i}] <== multi_or[${multi_or_i}][i].out;`); - multi_or_i += 1 + } lines.push(`\t\tstate_changed[i].in[${i - 1}] <== states[i+1][${i}];`); }