From 81d0299ed2b405c72138125385ea7f6bb6a680b2 Mon Sep 17 00:00:00 2001 From: Sora Suegami <31360991+SoraSuegami@users.noreply.github.com> Date: Thu, 17 Oct 2024 13:16:12 +0900 Subject: [PATCH] Feat/audit fix 2024 09 (#72) * Modify email_addr_with_name using reversed_email_addr_with_name * Pass all unit tests * Add range check to each input byte * Update circom_tester version * Add program to test circuits * Add --immutable to github action * Fix circom version in github action * fix circom version to 2.1.9 in github action * Add assumptions to README * Update versions --- .github/workflows/test.yaml | 10 +- README.md | 5 + packages/apis/Cargo.toml | 2 +- packages/apis/package.json | 2 +- .../decomposed_defs/email_addr_with_name.json | 16 - .../apis/src/decomposed_defs/from_addr.json | 2 +- .../apis/src/decomposed_defs/to_addr.json | 2 +- packages/apis/src/extract_substrs.rs | 40 +- packages/apis/src/wasm.rs | 12 +- .../circuits/common/body_hash_regex.circom | 1 + .../circuits/common/email_addr_regex.circom | 1 + .../circuits/common/email_addr_with_name.json | 16 - .../common/email_addr_with_name_regex.circom | 840 +----------------- .../circuits/common/email_domain_regex.circom | 1 + .../circom/circuits/common/from_addr.json | 20 - .../circuits/common/from_addr_regex.circom | 8 +- .../circuits/common/from_all_regex.circom | 1 + .../circuits/common/message_id_regex.circom | 1 + .../circuits/common/reversed_bracket.json | 16 + .../common/reversed_bracket_regex.circom | 554 ++++++++++++ ...reversed_email_addr_with_name_regex.circom | 566 ++++++++++++ .../circuits/common/subject_all_regex.circom | 1 + .../circuits/common/timestamp_regex.circom | 1 + packages/circom/circuits/common/to_addr.json | 20 - .../circuits/common/to_all_regex.circom | 1 + packages/circom/package.json | 4 +- .../tests/circuits/asterisk1_regex.circom | 1 + .../tests/circuits/asterisk2_regex.circom | 1 + .../tests/circuits/asterisk3_regex.circom | 1 + .../circom/tests/circuits/caret1_regex.circom | 1 + .../circom/tests/circuits/caret2_regex.circom | 1 + .../circom/tests/circuits/caret3_regex.circom | 1 + .../circom/tests/circuits/caret4_regex.circom | 1 + .../circom/tests/circuits/caret5_regex.circom | 1 + .../tests/circuits/dollar1_regex.circom | 1 + .../tests/circuits/dollar2_regex.circom | 1 + .../circom/tests/circuits/dot1_regex.circom | 1 + .../circom/tests/circuits/dot2_regex.circom | 1 + .../international_chars_decomposed.circom | 1 + .../invitation_code_with_prefix_regex.circom | 1 + .../tests/circuits/negate1_regex.circom | 1 + .../tests/circuits/negate2_regex.circom | 1 + .../circom/tests/circuits/plus1_regex.circom | 1 + .../circom/tests/circuits/plus2_regex.circom | 1 + .../circom/tests/circuits/plus3_regex.circom | 1 + .../circom/tests/circuits/plus4_regex.circom | 1 + .../tests/circuits/question1_regex.circom | 1 + .../tests/circuits/question2_regex.circom | 1 + .../tests/circuits/question3_regex.circom | 1 + .../tests/circuits/reveal_check1_regex.circom | 1 + .../tests/circuits/reveal_check2_regex.circom | 1 + .../circom/tests/circuits/simple_regex.circom | 1 + .../circuits/simple_regex_decomposed.circom | 1 + .../circuits/test_asterisk1_regex.circom | 2 + .../circuits/test_asterisk2_regex.circom | 2 + .../circuits/test_asterisk3_regex.circom | 2 + .../circuits/test_body_hash_regex.circom | 2 + .../tests/circuits/test_caret1_regex.circom | 2 + .../tests/circuits/test_caret2_regex.circom | 2 + .../tests/circuits/test_caret3_regex.circom | 2 + .../tests/circuits/test_caret4_regex.circom | 2 + .../tests/circuits/test_caret5_regex.circom | 2 + .../tests/circuits/test_dollar1_regex.circom | 2 + .../tests/circuits/test_dollar2_regex.circom | 2 + .../tests/circuits/test_dot1_regex.circom | 2 + .../tests/circuits/test_dot2_regex.circom | 2 + .../circuits/test_email_addr_regex.circom | 2 + .../circuits/test_email_domain_regex.circom | 2 + .../circuits/test_from_addr_regex.circom | 2 + ...t_invitation_code_with_prefix_regex.circom | 2 + .../circuits/test_message_id_regex.circom | 2 + .../tests/circuits/test_negate1_regex.circom | 2 + .../tests/circuits/test_negate2_regex.circom | 2 + .../tests/circuits/test_plus1_regex.circom | 2 + .../tests/circuits/test_plus2_regex.circom | 2 + .../tests/circuits/test_plus3_regex.circom | 2 + .../tests/circuits/test_plus4_regex.circom | 2 + .../circuits/test_question1_regex.circom | 2 + .../circuits/test_question2_regex.circom | 2 + .../circuits/test_question3_regex.circom | 2 + .../circuits/test_reveal_check1_regex.circom | 2 + .../circuits/test_reveal_check2_regex.circom | 2 + .../circuits/test_subject_all_regex.circom | 2 + .../circuits/test_timestamp_regex.circom | 2 + .../tests/circuits/test_to_addr_regex.circom | 2 + packages/circom/tests/from_addr.test.js | 92 +- packages/circom/tests/to_addr.test.js | 96 +- packages/compiler/Cargo.toml | 2 +- packages/compiler/package.json | 2 +- packages/compiler/src/circom.rs | 1 + 90 files changed, 1474 insertions(+), 953 deletions(-) delete mode 100644 packages/apis/src/decomposed_defs/email_addr_with_name.json delete mode 100644 packages/circom/circuits/common/email_addr_with_name.json delete mode 100644 packages/circom/circuits/common/from_addr.json create mode 100644 packages/circom/circuits/common/reversed_bracket.json create mode 100644 packages/circom/circuits/common/reversed_bracket_regex.circom create mode 100644 packages/circom/circuits/common/reversed_email_addr_with_name_regex.circom delete mode 100644 packages/circom/circuits/common/to_addr.json diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 8115498..e56399f 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -20,15 +20,11 @@ jobs: components: rustfmt, clippy - name: Install wasm-pack run: cargo install wasm-pack - - name: Download circom v2.1.8 (Linux) - run: wget https://github.com/iden3/circom/releases/download/v2.1.8/circom-linux-amd64 -O /usr/local/bin/circom && chmod +x /usr/local/bin/circom + - name: Download circom v2.1.9 (Linux) + run: wget https://github.com/iden3/circom/releases/download/v2.1.9/circom-linux-amd64 -O /usr/local/bin/circom && chmod +x /usr/local/bin/circom - name: Install yarn run: npm install -g yarn - name: Install dependencies - run: yarn - # - name: Create build folder - # run: mkdir build - # - name: Run Linters - # run: yarn lint + run: yarn install --immutable - name: Run tests run: yarn test diff --git a/README.md b/README.md index 58c06b5..eb5e83d 100644 --- a/README.md +++ b/README.md @@ -173,3 +173,8 @@ Use this bibtex citation. - [ ] support character class regex grammar (so as to simplify the regular expressions) - [ ] better compatibility with regex grammar (will need a set of different tests to assert the compatibility between circuit and regex in languages) --> + +## Assumptions +Some email providers put not only the sender's email address but also their username to the From field. +ALthough its concrete formats differ among email providers, our FromAddrRegex template assumes that the email address appears at the end of the From field. +If this assumption does not hold, i.e., the username appears after the email address, an adversary can output an arbitrary email address from that template by including a dummy email address in the username. \ No newline at end of file diff --git a/packages/apis/Cargo.toml b/packages/apis/Cargo.toml index 5a49b56..022af07 100644 --- a/packages/apis/Cargo.toml +++ b/packages/apis/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "zk-regex-apis" -version = "2.1.1" +version = "2.2.0" license = "MIT" edition = "2018" authors = [ diff --git a/packages/apis/package.json b/packages/apis/package.json index 9b03f61..9526418 100644 --- a/packages/apis/package.json +++ b/packages/apis/package.json @@ -1,6 +1,6 @@ { "name": "@zk-email/zk-regex-apis", - "version": "2.1.1", + "version": "2.2.0", "description": "apis compatible with [zk-regex](https://github.com/zkemail/zk-regex/tree/main).", "contributors": [ "Javier Su ", diff --git a/packages/apis/src/decomposed_defs/email_addr_with_name.json b/packages/apis/src/decomposed_defs/email_addr_with_name.json deleted file mode 100644 index 999ea3e..0000000 --- a/packages/apis/src/decomposed_defs/email_addr_with_name.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "parts": [ - { - "is_public": false, - "regex_def": "[^\r\n]+<" - }, - { - "is_public": true, - "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/from_addr.json b/packages/apis/src/decomposed_defs/from_addr.json index 82fefdd..6753257 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": "[^<>]+" }, { "is_public": false, diff --git a/packages/apis/src/decomposed_defs/to_addr.json b/packages/apis/src/decomposed_defs/to_addr.json index 9c7a4b1..394a26b 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": "[^<>]+" }, { "is_public": false, diff --git a/packages/apis/src/extract_substrs.rs b/packages/apis/src/extract_substrs.rs index fea936e..18e1a92 100644 --- a/packages/apis/src/extract_substrs.rs +++ b/packages/apis/src/extract_substrs.rs @@ -89,12 +89,12 @@ pub fn extract_email_domain_idxes( extract_substr_idxes(input_str, &serde_json::from_str(regex_config).unwrap()) } -pub fn extract_email_addr_with_name_idxes( - input_str: &str, -) -> Result, ExtractSubstrssError> { - let regex_config = include_str!("./decomposed_defs/email_addr_with_name.json"); - extract_substr_idxes(input_str, &serde_json::from_str(regex_config).unwrap()) -} +// pub fn extract_email_addr_with_name_idxes( +// input_str: &str, +// ) -> Result, ExtractSubstrssError> { +// let regex_config = include_str!("./decomposed_defs/email_addr_with_name.json"); +// extract_substr_idxes(input_str, &serde_json::from_str(regex_config).unwrap()) +// } pub fn extract_from_all_idxes( input_str: &str, @@ -166,20 +166,20 @@ mod test { assert_eq!(idxes, vec![(17, 38)]); } - #[test] - fn test_email_addr_with_name_valid1() { - let input_str = "from:dummy@a.com "; - let idxes = extract_email_addr_with_name_idxes(input_str).unwrap(); - assert_eq!(idxes, vec![(18, 39)]); - } - - #[test] - fn test_email_addr_with_name_valid2() { - // "末神 奏宙" has 13 bytes. - let input_str = "from:\"末神 奏宙\" "; - let idxes = extract_email_addr_with_name_idxes(input_str).unwrap(); - assert_eq!(idxes, vec![(22, 43)]); - } + // #[test] + // fn test_email_addr_with_name_valid1() { + // let input_str = "from:dummy@a.com "; + // let idxes = extract_email_addr_with_name_idxes(input_str).unwrap(); + // assert_eq!(idxes, vec![(18, 39)]); + // } + + // #[test] + // fn test_email_addr_with_name_valid2() { + // // "末神 奏宙" has 13 bytes. + // let input_str = "from:\"末神 奏宙\" "; + // let idxes = extract_email_addr_with_name_idxes(input_str).unwrap(); + // assert_eq!(idxes, vec![(22, 43)]); + // } #[test] fn test_email_from_all_valid() { diff --git a/packages/apis/src/wasm.rs b/packages/apis/src/wasm.rs index 5ce405a..9e5b0ff 100644 --- a/packages/apis/src/wasm.rs +++ b/packages/apis/src/wasm.rs @@ -47,12 +47,12 @@ pub fn extractEmailDomainIdxes(inputStr: &str) -> Array { extractSubstrIdxes(inputStr, JsValue::from_str(regex_config)) } -#[wasm_bindgen] -#[allow(non_snake_case)] -pub fn extractEmailAddrWithNameIdxes(inputStr: &str) -> Array { - let regex_config = include_str!("./decomposed_defs/email_addr_with_name.json"); - extractSubstrIdxes(inputStr, JsValue::from_str(regex_config)) -} +// #[wasm_bindgen] +// #[allow(non_snake_case)] +// pub fn extractEmailAddrWithNameIdxes(inputStr: &str) -> Array { +// let regex_config = include_str!("./decomposed_defs/email_addr_with_name.json"); +// extractSubstrIdxes(inputStr, JsValue::from_str(regex_config)) +// } #[wasm_bindgen] #[allow(non_snake_case)] diff --git a/packages/circom/circuits/common/body_hash_regex.circom b/packages/circom/circuits/common/body_hash_regex.circom index 97ea1ee..13613cf 100644 --- a/packages/circom/circuits/common/body_hash_regex.circom +++ b/packages/circom/circuits/common/body_hash_regex.circom @@ -11,6 +11,7 @@ template BodyHashRegex(msg_bytes) { signal in[num_bytes]; in[0]<==255; for (var i = 0; i < msg_bytes; i++) { + _ <== LessThan(8)([msg[i], 255]); in[i+1] <== msg[i]; } diff --git a/packages/circom/circuits/common/email_addr_regex.circom b/packages/circom/circuits/common/email_addr_regex.circom index 8f7005f..096c287 100644 --- a/packages/circom/circuits/common/email_addr_regex.circom +++ b/packages/circom/circuits/common/email_addr_regex.circom @@ -11,6 +11,7 @@ template EmailAddrRegex(msg_bytes) { signal in[num_bytes]; in[0]<==255; for (var i = 0; i < msg_bytes; i++) { + _ <== LessThan(8)([msg[i], 255]); in[i+1] <== msg[i]; } diff --git a/packages/circom/circuits/common/email_addr_with_name.json b/packages/circom/circuits/common/email_addr_with_name.json deleted file mode 100644 index 999ea3e..0000000 --- a/packages/circom/circuits/common/email_addr_with_name.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "parts": [ - { - "is_public": false, - "regex_def": "[^\r\n]+<" - }, - { - "is_public": true, - "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/circom/circuits/common/email_addr_with_name_regex.circom b/packages/circom/circuits/common/email_addr_with_name_regex.circom index f212271..94302f8 100644 --- a/packages/circom/circuits/common/email_addr_with_name_regex.circom +++ b/packages/circom/circuits/common/email_addr_with_name_regex.circom @@ -1,840 +1,20 @@ pragma circom 2.1.5; include "@zk-email/zk-regex-circom/circuits/regex_helpers.circom"; +include "./reversed_bracket_regex.circom"; -// regex: [^\r\n]+<[A-Za-z0-9!#$%&'*+=?\-\^_`{|}~./@]+@[a-zA-Z0-9.\-]+> template EmailAddrWithNameRegex(msg_bytes) { signal input msg[msg_bytes]; signal output out; - - var num_bytes = msg_bytes+1; - signal in[num_bytes]; - in[0]<==255; - for (var i = 0; i < msg_bytes; i++) { - in[i+1] <== msg[i]; - } - - 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]; - from_zero_enabled[num_bytes] <== 0; - component state_changed[num_bytes]; - - for (var i = 1; i < 14; i++) { - states[0][i] <== 0; - } - - for (var i = 0; i < num_bytes; i++) { - state_changed[i] = MultiOR(13); - states[i][0] <== 1; - lt[0][i] = LessEqThan(8); - 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] <== 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; - eq[9][i] = IsEqual(); - eq[9][i].in[0] <== in[i]; - eq[9][i].in[1] <== 11; - eq[10][i] = IsEqual(); - eq[10][i].in[0] <== in[i]; - 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] <== 34; - eq[12][i] = IsEqual(); - eq[12][i].in[0] <== in[i]; - eq[12][i].in[1] <== 40; - eq[13][i] = IsEqual(); - eq[13][i].in[0] <== in[i]; - eq[13][i].in[1] <== 41; - eq[14][i] = IsEqual(); - eq[14][i].in[0] <== in[i]; - eq[14][i].in[1] <== 44; - eq[15][i] = IsEqual(); - eq[15][i].in[0] <== in[i]; - eq[15][i].in[1] <== 58; - eq[16][i] = IsEqual(); - eq[16][i].in[0] <== in[i]; - eq[16][i].in[1] <== 59; - eq[17][i] = IsEqual(); - eq[17][i].in[0] <== in[i]; - eq[17][i].in[1] <== 62; - eq[18][i] = IsEqual(); - eq[18][i].in[0] <== in[i]; - eq[18][i].in[1] <== 91; - eq[19][i] = IsEqual(); - eq[19][i].in[0] <== in[i]; - eq[19][i].in[1] <== 92; - eq[20][i] = IsEqual(); - eq[20][i].in[0] <== in[i]; - eq[20][i].in[1] <== 93; - eq[21][i] = IsEqual(); - eq[21][i].in[0] <== in[i]; - eq[21][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].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; - 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[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[22][i].out; - and[19][i] = AND(); - and[19][i].a <== states[i][1]; - and[19][i].b <== eq[22][i].out; - and[20][i] = AND(); - and[20][i].a <== states[i][9]; - 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] <== 226; - eq[25][i] = IsEqual(); - eq[25][i].in[0] <== in[i]; - eq[25][i].in[1] <== 227; - eq[26][i] = IsEqual(); - eq[26][i].in[0] <== in[i]; - eq[26][i].in[1] <== 228; - eq[27][i] = IsEqual(); - eq[27][i].in[0] <== in[i]; - eq[27][i].in[1] <== 229; - eq[28][i] = IsEqual(); - eq[28][i].in[0] <== in[i]; - eq[28][i].in[1] <== 230; - eq[29][i] = IsEqual(); - eq[29][i].in[0] <== in[i]; - eq[29][i].in[1] <== 231; - eq[30][i] = IsEqual(); - eq[30][i].in[0] <== in[i]; - eq[30][i].in[1] <== 232; - eq[31][i] = IsEqual(); - eq[31][i].in[0] <== in[i]; - eq[31][i].in[1] <== 233; - eq[32][i] = IsEqual(); - eq[32][i].in[0] <== in[i]; - eq[32][i].in[1] <== 234; - eq[33][i] = IsEqual(); - eq[33][i].in[0] <== in[i]; - eq[33][i].in[1] <== 235; - eq[34][i] = IsEqual(); - eq[34][i].in[0] <== in[i]; - eq[34][i].in[1] <== 236; - eq[35][i] = IsEqual(); - eq[35][i].in[0] <== in[i]; - eq[35][i].in[1] <== 238; - eq[36][i] = IsEqual(); - eq[36][i].in[0] <== in[i]; - 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[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]; - 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[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[39][i] = IsEqual(); - eq[39][i].in[0] <== in[i]; - eq[39][i].in[1] <== 130; - eq[40][i] = IsEqual(); - eq[40][i].in[0] <== in[i]; - eq[40][i].in[1] <== 131; - eq[41][i] = IsEqual(); - eq[41][i].in[0] <== in[i]; - eq[41][i].in[1] <== 132; - eq[42][i] = IsEqual(); - eq[42][i].in[0] <== in[i]; - eq[42][i].in[1] <== 133; - eq[43][i] = IsEqual(); - eq[43][i].in[0] <== in[i]; - eq[43][i].in[1] <== 134; - eq[44][i] = IsEqual(); - eq[44][i].in[0] <== in[i]; - eq[44][i].in[1] <== 135; - eq[45][i] = IsEqual(); - eq[45][i].in[0] <== in[i]; - eq[45][i].in[1] <== 136; - eq[46][i] = IsEqual(); - eq[46][i].in[0] <== in[i]; - eq[46][i].in[1] <== 137; - eq[47][i] = IsEqual(); - eq[47][i].in[0] <== in[i]; - eq[47][i].in[1] <== 138; - eq[48][i] = IsEqual(); - eq[48][i].in[0] <== in[i]; - eq[48][i].in[1] <== 139; - eq[49][i] = IsEqual(); - eq[49][i].in[0] <== in[i]; - eq[49][i].in[1] <== 140; - eq[50][i] = IsEqual(); - eq[50][i].in[0] <== in[i]; - eq[50][i].in[1] <== 141; - eq[51][i] = IsEqual(); - eq[51][i].in[0] <== in[i]; - eq[51][i].in[1] <== 142; - eq[52][i] = IsEqual(); - eq[52][i].in[0] <== in[i]; - 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[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]; - 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[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[53][i].out; - and[29][i] = AND(); - and[29][i].a <== states[i][1]; - and[29][i].b <== eq[53][i].out; - and[30][i] = AND(); - and[30][i].a <== states[i][9]; - 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[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[54][i].out; - and[32][i] = AND(); - and[32][i].a <== states[i][1]; - and[32][i].b <== eq[54][i].out; - and[33][i] = AND(); - and[33][i].a <== states[i][9]; - 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] <== 242; - 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[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] <== 60; - and[40][i] = AND(); - and[40][i].a <== states[i][1]; - and[40][i].b <== eq[59][i].out; - and[41][i] = AND(); - and[41][i].a <== states[i][9]; - 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; - states[i+1][9] <== multi_or[14][i].out; - lt[18][i] = LessEqThan(8); - 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]; - lt[19][i].in[1] <== 90; - and[42][i] = AND(); - and[42][i].a <== lt[18][i].out; - and[42][i].b <== lt[19][i].out; - lt[20][i] = LessEqThan(8); - lt[20][i].in[0] <== 94; - lt[20][i].in[1] <== in[i]; - lt[21][i] = LessEqThan(8); - lt[21][i].in[0] <== in[i]; - lt[21][i].in[1] <== 126; - 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[63][i] = IsEqual(); - eq[63][i].in[0] <== in[i]; - eq[63][i].in[1] <== 37; - eq[64][i] = IsEqual(); - eq[64][i].in[0] <== in[i]; - eq[64][i].in[1] <== 38; - eq[65][i] = IsEqual(); - eq[65][i].in[0] <== in[i]; - eq[65][i].in[1] <== 39; - eq[66][i] = IsEqual(); - eq[66][i].in[0] <== in[i]; - eq[66][i].in[1] <== 42; - eq[67][i] = IsEqual(); - eq[67][i].in[0] <== in[i]; - eq[67][i].in[1] <== 43; - eq[68][i] = IsEqual(); - eq[68][i].in[0] <== in[i]; - eq[68][i].in[1] <== 45; - eq[69][i] = IsEqual(); - eq[69][i].in[0] <== in[i]; - eq[69][i].in[1] <== 46; - eq[70][i] = IsEqual(); - eq[70][i].in[0] <== in[i]; - eq[70][i].in[1] <== 47; - eq[71][i] = IsEqual(); - eq[71][i].in[0] <== in[i]; - eq[71][i].in[1] <== 48; - eq[72][i] = IsEqual(); - eq[72][i].in[0] <== in[i]; - eq[72][i].in[1] <== 49; - eq[73][i] = IsEqual(); - eq[73][i].in[0] <== in[i]; - eq[73][i].in[1] <== 50; - eq[74][i] = IsEqual(); - eq[74][i].in[0] <== in[i]; - eq[74][i].in[1] <== 51; - eq[75][i] = IsEqual(); - eq[75][i].in[0] <== in[i]; - eq[75][i].in[1] <== 52; - eq[76][i] = IsEqual(); - eq[76][i].in[0] <== in[i]; - eq[76][i].in[1] <== 53; - eq[77][i] = IsEqual(); - eq[77][i].in[0] <== in[i]; - eq[77][i].in[1] <== 54; - eq[78][i] = IsEqual(); - eq[78][i].in[0] <== in[i]; - eq[78][i].in[1] <== 55; - eq[79][i] = IsEqual(); - eq[79][i].in[0] <== in[i]; - eq[79][i].in[1] <== 56; - eq[80][i] = IsEqual(); - eq[80][i].in[0] <== in[i]; - eq[80][i].in[1] <== 57; - eq[81][i] = IsEqual(); - eq[81][i].in[0] <== in[i]; - 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].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; - and[44][i].b <== multi_or[15][i].out; - lt[22][i] = LessEqThan(8); - 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] <== 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(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[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] <== 95; - eq[85][i] = IsEqual(); - eq[85][i].in[0] <== in[i]; - eq[85][i].in[1] <== 96; - eq[86][i] = IsEqual(); - eq[86][i].in[0] <== in[i]; - eq[86][i].in[1] <== 123; - eq[87][i] = IsEqual(); - eq[87][i].in[0] <== in[i]; - eq[87][i].in[1] <== 124; - eq[88][i] = IsEqual(); - eq[88][i].in[0] <== in[i]; - 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(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]; - 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[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[90][i].out; - and[50][i] = AND(); - and[50][i].a <== states[i][11]; - and[50][i].b <== eq[90][i].out; - and[51][i] = AND(); - and[51][i].a <== states[i][12]; - 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; - 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; - and[53][i] = AND(); - and[53][i].a <== states[i][11]; - 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[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; - 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; - 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[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]); - 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[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]; - state_changed[i].in[3] <== states[i+1][4]; - state_changed[i].in[4] <== states[i+1][5]; - state_changed[i].in[5] <== states[i+1][6]; - state_changed[i].in[6] <== states[i+1][7]; - state_changed[i].in[7] <== states[i+1][8]; - state_changed[i].in[8] <== states[i+1][9]; - state_changed[i].in[9] <== states[i+1][10]; - state_changed[i].in[10] <== states[i+1][11]; - state_changed[i].in[11] <== states[i+1][12]; - state_changed[i].in[12] <== states[i+1][13]; - } - - component is_accepted = MultiOR(num_bytes+1); - for (var i = 0; i <= num_bytes; i++) { - is_accepted.in[i] <== states[i][13]; - } - 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][13] * (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][13], is_consecutive[msg_bytes-1-i][1]]); - } - // 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, 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][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]; + + signal reversed_msg[msg_bytes]; + signal reversed_reveal0[msg_bytes]; + for(var i=0; i?\r\n" - } - ] -} \ No newline at end of file diff --git a/packages/circom/circuits/common/from_addr_regex.circom b/packages/circom/circuits/common/from_addr_regex.circom index 302c8d3..105d648 100644 --- a/packages/circom/circuits/common/from_addr_regex.circom +++ b/packages/circom/circuits/common/from_addr_regex.circom @@ -1,9 +1,9 @@ pragma circom 2.1.5; -include "@zk-email/zk-regex-circom/circuits/regex_helpers.circom"; -include "@zk-email/zk-regex-circom/circuits/common/from_all_regex.circom"; -include "@zk-email/zk-regex-circom/circuits/common/email_addr_regex.circom"; -include "@zk-email/zk-regex-circom/circuits/common/email_addr_with_name_regex.circom"; +include "../regex_helpers.circom"; +include "./from_all_regex.circom"; +include "./email_addr_regex.circom"; +include "./email_addr_with_name_regex.circom"; template FromAddrRegex(msg_bytes) { diff --git a/packages/circom/circuits/common/from_all_regex.circom b/packages/circom/circuits/common/from_all_regex.circom index 0326ca7..91fbd70 100644 --- a/packages/circom/circuits/common/from_all_regex.circom +++ b/packages/circom/circuits/common/from_all_regex.circom @@ -11,6 +11,7 @@ template FromAllRegex(msg_bytes) { signal in[num_bytes]; in[0]<==255; for (var i = 0; i < msg_bytes; i++) { + _ <== LessThan(8)([msg[i], 255]); in[i+1] <== msg[i]; } diff --git a/packages/circom/circuits/common/message_id_regex.circom b/packages/circom/circuits/common/message_id_regex.circom index 418d7cc..637005a 100644 --- a/packages/circom/circuits/common/message_id_regex.circom +++ b/packages/circom/circuits/common/message_id_regex.circom @@ -11,6 +11,7 @@ template MessageIdRegex(msg_bytes) { signal in[num_bytes]; in[0]<==255; for (var i = 0; i < msg_bytes; i++) { + _ <== LessThan(8)([msg[i], 255]); in[i+1] <== msg[i]; } diff --git a/packages/circom/circuits/common/reversed_bracket.json b/packages/circom/circuits/common/reversed_bracket.json new file mode 100644 index 0000000..55ffaab --- /dev/null +++ b/packages/circom/circuits/common/reversed_bracket.json @@ -0,0 +1,16 @@ +{ + "parts": [ + { + "is_public": false, + "regex_def": ">" + }, + { + "is_public": true, + "regex_def": "[^<>]+" + }, + { + "is_public": false, + "regex_def": "<.*" + } + ] +} \ No newline at end of file diff --git a/packages/circom/circuits/common/reversed_bracket_regex.circom b/packages/circom/circuits/common/reversed_bracket_regex.circom new file mode 100644 index 0000000..3ee1258 --- /dev/null +++ b/packages/circom/circuits/common/reversed_bracket_regex.circom @@ -0,0 +1,554 @@ +pragma circom 2.1.5; + +include "@zk-email/zk-regex-circom/circuits/regex_helpers.circom"; + +// regex: >[^<>]+<.* +template ReversedBracketRegex(msg_bytes) { + signal input msg[msg_bytes]; + signal output out; + + var num_bytes = msg_bytes+1; + signal in[num_bytes]; + in[0]<==255; + for (var i = 0; i < msg_bytes; i++) { + _ <== LessThan(8)([msg[i], 255]); + in[i+1] <== msg[i]; + } + + component eq[49][num_bytes]; + component lt[16][num_bytes]; + component and[48][num_bytes]; + component multi_or[16][num_bytes]; + signal states[num_bytes+1][18]; + signal states_tmp[num_bytes+1][18]; + signal from_zero_enabled[num_bytes+1]; + from_zero_enabled[num_bytes] <== 0; + component state_changed[num_bytes]; + + for (var i = 1; i < 18; i++) { + states[0][i] <== 0; + } + + for (var i = 0; i < num_bytes; i++) { + state_changed[i] = MultiOR(17); + states[i][0] <== 1; + eq[0][i] = IsEqual(); + eq[0][i].in[0] <== in[i]; + eq[0][i].in[1] <== 62; + and[0][i] = AND(); + and[0][i].a <== states[i][0]; + and[0][i].b <== eq[0][i].out; + states_tmp[i+1][1] <== 0; + lt[0][i] = LessEqThan(8); + 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] <== 59; + and[1][i] = AND(); + and[1][i].a <== lt[0][i].out; + and[1][i].b <== lt[1][i].out; + lt[2][i] = LessEqThan(8); + lt[2][i].in[0] <== 63; + lt[2][i].in[1] <== in[i]; + lt[3][i] = LessEqThan(8); + lt[3][i].in[0] <== in[i]; + lt[3][i].in[1] <== 127; + and[2][i] = AND(); + and[2][i].a <== lt[2][i].out; + and[2][i].b <== lt[3][i].out; + eq[1][i] = IsEqual(); + eq[1][i].in[0] <== in[i]; + eq[1][i].in[1] <== 61; + and[3][i] = AND(); + and[3][i].a <== states[i][1]; + multi_or[0][i] = MultiOR(3); + multi_or[0][i].in[0] <== and[1][i].out; + multi_or[0][i].in[1] <== and[2][i].out; + multi_or[0][i].in[2] <== eq[1][i].out; + and[3][i].b <== multi_or[0][i].out; + and[4][i] = AND(); + and[4][i].a <== states[i][2]; + and[4][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[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][3]; + and[6][i].b <== and[5][i].out; + multi_or[1][i] = MultiOR(3); + 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[6][i].out; + states[i+1][2] <== multi_or[1][i].out; + lt[6][i] = LessEqThan(8); + 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] <== 223; + 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][1]; + and[8][i].b <== and[7][i].out; + and[9][i] = AND(); + and[9][i].a <== states[i][2]; + and[9][i].b <== and[7][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[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][4]; + and[11][i].b <== and[10][i].out; + and[12][i] = AND(); + and[12][i].a <== states[i][5]; + and[12][i].b <== and[5][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[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; + multi_or[2][i] = MultiOR(5); + multi_or[2][i].in[0] <== and[8][i].out; + multi_or[2][i].in[1] <== and[9][i].out; + multi_or[2][i].in[2] <== and[11][i].out; + multi_or[2][i].in[3] <== and[12][i].out; + multi_or[2][i].in[4] <== and[14][i].out; + states[i+1][3] <== multi_or[2][i].out; + eq[2][i] = IsEqual(); + eq[2][i].in[0] <== in[i]; + eq[2][i].in[1] <== 224; + and[15][i] = AND(); + and[15][i].a <== states[i][1]; + and[15][i].b <== eq[2][i].out; + and[16][i] = AND(); + and[16][i].a <== states[i][2]; + and[16][i].b <== eq[2][i].out; + multi_or[3][i] = MultiOR(2); + multi_or[3][i].in[0] <== and[15][i].out; + multi_or[3][i].in[1] <== and[16][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] <== 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; + eq[7][i] = IsEqual(); + eq[7][i].in[0] <== in[i]; + eq[7][i].in[1] <== 229; + eq[8][i] = IsEqual(); + eq[8][i].in[0] <== in[i]; + eq[8][i].in[1] <== 230; + eq[9][i] = IsEqual(); + eq[9][i].in[0] <== in[i]; + eq[9][i].in[1] <== 231; + eq[10][i] = IsEqual(); + eq[10][i].in[0] <== in[i]; + eq[10][i].in[1] <== 232; + eq[11][i] = IsEqual(); + eq[11][i].in[0] <== in[i]; + eq[11][i].in[1] <== 233; + eq[12][i] = IsEqual(); + eq[12][i].in[0] <== in[i]; + eq[12][i].in[1] <== 234; + eq[13][i] = IsEqual(); + eq[13][i].in[0] <== in[i]; + eq[13][i].in[1] <== 235; + eq[14][i] = IsEqual(); + eq[14][i].in[0] <== in[i]; + eq[14][i].in[1] <== 236; + eq[15][i] = IsEqual(); + eq[15][i].in[0] <== in[i]; + eq[15][i].in[1] <== 238; + eq[16][i] = IsEqual(); + eq[16][i].in[0] <== in[i]; + eq[16][i].in[1] <== 239; + and[17][i] = AND(); + and[17][i].a <== states[i][1]; + multi_or[4][i] = MultiOR(14); + multi_or[4][i].in[0] <== eq[3][i].out; + multi_or[4][i].in[1] <== eq[4][i].out; + multi_or[4][i].in[2] <== eq[5][i].out; + multi_or[4][i].in[3] <== eq[6][i].out; + multi_or[4][i].in[4] <== eq[7][i].out; + multi_or[4][i].in[5] <== eq[8][i].out; + multi_or[4][i].in[6] <== eq[9][i].out; + multi_or[4][i].in[7] <== eq[10][i].out; + multi_or[4][i].in[8] <== eq[11][i].out; + multi_or[4][i].in[9] <== eq[12][i].out; + multi_or[4][i].in[10] <== eq[13][i].out; + multi_or[4][i].in[11] <== eq[14][i].out; + multi_or[4][i].in[12] <== eq[15][i].out; + multi_or[4][i].in[13] <== eq[16][i].out; + and[17][i].b <== multi_or[4][i].out; + and[18][i] = AND(); + and[18][i].a <== states[i][2]; + and[18][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[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][7]; + and[20][i].b <== and[19][i].out; + and[21][i] = AND(); + and[21][i].a <== states[i][8]; + and[21][i].b <== and[5][i].out; + eq[17][i] = IsEqual(); + eq[17][i].in[0] <== in[i]; + eq[17][i].in[1] <== 128; + eq[18][i] = IsEqual(); + eq[18][i].in[0] <== in[i]; + eq[18][i].in[1] <== 129; + eq[19][i] = IsEqual(); + eq[19][i].in[0] <== in[i]; + eq[19][i].in[1] <== 130; + eq[20][i] = IsEqual(); + eq[20][i].in[0] <== in[i]; + eq[20][i].in[1] <== 131; + eq[21][i] = IsEqual(); + eq[21][i].in[0] <== in[i]; + eq[21][i].in[1] <== 132; + eq[22][i] = IsEqual(); + eq[22][i].in[0] <== in[i]; + eq[22][i].in[1] <== 133; + eq[23][i] = IsEqual(); + eq[23][i].in[0] <== in[i]; + eq[23][i].in[1] <== 134; + eq[24][i] = IsEqual(); + eq[24][i].in[0] <== in[i]; + eq[24][i].in[1] <== 135; + eq[25][i] = IsEqual(); + eq[25][i].in[0] <== in[i]; + eq[25][i].in[1] <== 136; + eq[26][i] = IsEqual(); + eq[26][i].in[0] <== in[i]; + eq[26][i].in[1] <== 137; + eq[27][i] = IsEqual(); + eq[27][i].in[0] <== in[i]; + eq[27][i].in[1] <== 138; + eq[28][i] = IsEqual(); + eq[28][i].in[0] <== in[i]; + eq[28][i].in[1] <== 139; + eq[29][i] = IsEqual(); + eq[29][i].in[0] <== in[i]; + eq[29][i].in[1] <== 140; + eq[30][i] = IsEqual(); + eq[30][i].in[0] <== in[i]; + eq[30][i].in[1] <== 141; + eq[31][i] = IsEqual(); + eq[31][i].in[0] <== in[i]; + eq[31][i].in[1] <== 142; + eq[32][i] = IsEqual(); + eq[32][i].in[0] <== in[i]; + eq[32][i].in[1] <== 143; + and[22][i] = AND(); + and[22][i].a <== states[i][9]; + multi_or[5][i] = MultiOR(16); + multi_or[5][i].in[0] <== eq[17][i].out; + multi_or[5][i].in[1] <== eq[18][i].out; + multi_or[5][i].in[2] <== eq[19][i].out; + multi_or[5][i].in[3] <== eq[20][i].out; + multi_or[5][i].in[4] <== eq[21][i].out; + multi_or[5][i].in[5] <== eq[22][i].out; + multi_or[5][i].in[6] <== eq[23][i].out; + multi_or[5][i].in[7] <== eq[24][i].out; + multi_or[5][i].in[8] <== eq[25][i].out; + multi_or[5][i].in[9] <== eq[26][i].out; + multi_or[5][i].in[10] <== eq[27][i].out; + multi_or[5][i].in[11] <== eq[28][i].out; + multi_or[5][i].in[12] <== eq[29][i].out; + multi_or[5][i].in[13] <== eq[30][i].out; + multi_or[5][i].in[14] <== eq[31][i].out; + multi_or[5][i].in[15] <== eq[32][i].out; + and[22][i].b <== multi_or[5][i].out; + multi_or[6][i] = MultiOR(5); + multi_or[6][i].in[0] <== and[17][i].out; + multi_or[6][i].in[1] <== and[18][i].out; + multi_or[6][i].in[2] <== and[20][i].out; + multi_or[6][i].in[3] <== and[21][i].out; + multi_or[6][i].in[4] <== and[22][i].out; + states[i+1][5] <== multi_or[6][i].out; + eq[33][i] = IsEqual(); + eq[33][i].in[0] <== in[i]; + eq[33][i].in[1] <== 237; + and[23][i] = AND(); + and[23][i].a <== states[i][1]; + and[23][i].b <== eq[33][i].out; + and[24][i] = AND(); + and[24][i].a <== states[i][2]; + and[24][i].b <== eq[33][i].out; + multi_or[7][i] = MultiOR(2); + multi_or[7][i].in[0] <== and[23][i].out; + multi_or[7][i].in[1] <== and[24][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] <== 240; + and[25][i] = AND(); + and[25][i].a <== states[i][1]; + and[25][i].b <== eq[34][i].out; + and[26][i] = AND(); + and[26][i].a <== states[i][2]; + and[26][i].b <== eq[34][i].out; + multi_or[8][i] = MultiOR(2); + multi_or[8][i].in[0] <== and[25][i].out; + multi_or[8][i].in[1] <== and[26][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] <== 241; + eq[36][i] = IsEqual(); + eq[36][i].in[0] <== in[i]; + eq[36][i].in[1] <== 242; + eq[37][i] = IsEqual(); + eq[37][i].in[0] <== in[i]; + eq[37][i].in[1] <== 243; + and[27][i] = AND(); + and[27][i].a <== states[i][1]; + multi_or[9][i] = MultiOR(3); + multi_or[9][i].in[0] <== eq[35][i].out; + multi_or[9][i].in[1] <== eq[36][i].out; + multi_or[9][i].in[2] <== eq[37][i].out; + and[27][i].b <== multi_or[9][i].out; + and[28][i] = AND(); + and[28][i].a <== states[i][2]; + and[28][i].b <== multi_or[9][i].out; + multi_or[10][i] = MultiOR(2); + multi_or[10][i].in[0] <== and[27][i].out; + multi_or[10][i].in[1] <== and[28][i].out; + states[i+1][8] <== multi_or[10][i].out; + eq[38][i] = IsEqual(); + eq[38][i].in[0] <== in[i]; + eq[38][i].in[1] <== 244; + and[29][i] = AND(); + and[29][i].a <== states[i][1]; + and[29][i].b <== eq[38][i].out; + and[30][i] = AND(); + and[30][i].a <== states[i][2]; + and[30][i].b <== eq[38][i].out; + multi_or[11][i] = MultiOR(2); + multi_or[11][i].in[0] <== and[29][i].out; + multi_or[11][i].in[1] <== and[30][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] <== 60; + and[31][i] = AND(); + and[31][i].a <== states[i][2]; + and[31][i].b <== eq[39][i].out; + lt[14][i] = LessEqThan(8); + lt[14][i].in[0] <== 11; + 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[32][i] = AND(); + and[32][i].a <== lt[14][i].out; + and[32][i].b <== lt[15][i].out; + eq[40][i] = IsEqual(); + eq[40][i].in[0] <== in[i]; + eq[40][i].in[1] <== 1; + eq[41][i] = IsEqual(); + eq[41][i].in[0] <== in[i]; + eq[41][i].in[1] <== 2; + eq[42][i] = IsEqual(); + eq[42][i].in[0] <== in[i]; + eq[42][i].in[1] <== 3; + eq[43][i] = IsEqual(); + eq[43][i].in[0] <== in[i]; + eq[43][i].in[1] <== 4; + eq[44][i] = IsEqual(); + eq[44][i].in[0] <== in[i]; + eq[44][i].in[1] <== 5; + eq[45][i] = IsEqual(); + eq[45][i].in[0] <== in[i]; + eq[45][i].in[1] <== 6; + eq[46][i] = IsEqual(); + eq[46][i].in[0] <== in[i]; + eq[46][i].in[1] <== 7; + eq[47][i] = IsEqual(); + eq[47][i].in[0] <== in[i]; + eq[47][i].in[1] <== 8; + eq[48][i] = IsEqual(); + eq[48][i].in[0] <== in[i]; + eq[48][i].in[1] <== 9; + and[33][i] = AND(); + and[33][i].a <== states[i][10]; + multi_or[12][i] = MultiOR(10); + multi_or[12][i].in[0] <== and[32][i].out; + multi_or[12][i].in[1] <== eq[40][i].out; + multi_or[12][i].in[2] <== eq[41][i].out; + multi_or[12][i].in[3] <== eq[42][i].out; + multi_or[12][i].in[4] <== eq[43][i].out; + multi_or[12][i].in[5] <== eq[44][i].out; + multi_or[12][i].in[6] <== eq[45][i].out; + multi_or[12][i].in[7] <== eq[46][i].out; + multi_or[12][i].in[8] <== eq[47][i].out; + multi_or[12][i].in[9] <== eq[48][i].out; + and[33][i].b <== multi_or[12][i].out; + and[34][i] = AND(); + and[34][i].a <== states[i][11]; + and[34][i].b <== and[5][i].out; + multi_or[13][i] = MultiOR(3); + multi_or[13][i].in[0] <== and[31][i].out; + multi_or[13][i].in[1] <== and[33][i].out; + multi_or[13][i].in[2] <== and[34][i].out; + states[i+1][10] <== multi_or[13][i].out; + and[35][i] = AND(); + and[35][i].a <== states[i][10]; + and[35][i].b <== and[7][i].out; + and[36][i] = AND(); + and[36][i].a <== states[i][12]; + and[36][i].b <== and[10][i].out; + and[37][i] = AND(); + and[37][i].a <== states[i][13]; + and[37][i].b <== and[5][i].out; + and[38][i] = AND(); + and[38][i].a <== states[i][14]; + and[38][i].b <== and[13][i].out; + multi_or[14][i] = MultiOR(4); + multi_or[14][i].in[0] <== and[35][i].out; + multi_or[14][i].in[1] <== and[36][i].out; + multi_or[14][i].in[2] <== and[37][i].out; + multi_or[14][i].in[3] <== and[38][i].out; + states[i+1][11] <== multi_or[14][i].out; + and[39][i] = AND(); + and[39][i].a <== states[i][10]; + and[39][i].b <== eq[2][i].out; + states[i+1][12] <== and[39][i].out; + and[40][i] = AND(); + and[40][i].a <== states[i][10]; + and[40][i].b <== multi_or[4][i].out; + and[41][i] = AND(); + and[41][i].a <== states[i][15]; + and[41][i].b <== and[19][i].out; + and[42][i] = AND(); + and[42][i].a <== states[i][16]; + and[42][i].b <== and[5][i].out; + and[43][i] = AND(); + and[43][i].a <== states[i][17]; + and[43][i].b <== multi_or[5][i].out; + multi_or[15][i] = MultiOR(4); + multi_or[15][i].in[0] <== and[40][i].out; + multi_or[15][i].in[1] <== and[41][i].out; + multi_or[15][i].in[2] <== and[42][i].out; + multi_or[15][i].in[3] <== and[43][i].out; + states[i+1][13] <== multi_or[15][i].out; + and[44][i] = AND(); + and[44][i].a <== states[i][10]; + and[44][i].b <== eq[33][i].out; + states[i+1][14] <== and[44][i].out; + and[45][i] = AND(); + and[45][i].a <== states[i][10]; + and[45][i].b <== eq[34][i].out; + states[i+1][15] <== and[45][i].out; + and[46][i] = AND(); + and[46][i].a <== states[i][10]; + and[46][i].b <== multi_or[9][i].out; + states[i+1][16] <== and[46][i].out; + and[47][i] = AND(); + and[47][i].a <== states[i][10]; + and[47][i].b <== eq[38][i].out; + states[i+1][17] <== and[47][i].out; + from_zero_enabled[i] <== MultiNOR(17)([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], states[i+1][12], states[i+1][13], states[i+1][14], states[i+1][15], states[i+1][16], states[i+1][17]]); + states[i+1][1] <== MultiOR(2)([states_tmp[i+1][1], from_zero_enabled[i] * and[0][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]; + state_changed[i].in[3] <== states[i+1][4]; + state_changed[i].in[4] <== states[i+1][5]; + state_changed[i].in[5] <== states[i+1][6]; + state_changed[i].in[6] <== states[i+1][7]; + state_changed[i].in[7] <== states[i+1][8]; + state_changed[i].in[8] <== states[i+1][9]; + state_changed[i].in[9] <== states[i+1][10]; + state_changed[i].in[10] <== states[i+1][11]; + state_changed[i].in[11] <== states[i+1][12]; + state_changed[i].in[12] <== states[i+1][13]; + state_changed[i].in[13] <== states[i+1][14]; + state_changed[i].in[14] <== states[i+1][15]; + state_changed[i].in[15] <== states[i+1][16]; + state_changed[i].in[16] <== states[i+1][17]; + } + + component is_accepted = MultiOR(num_bytes+1); + for (var i = 0; i <= num_bytes; i++) { + is_accepted.in[i] <== states[i][10]; + } + 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][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, 2), (2, 3), (2, 4), (2, 5), (2, 6), (2, 7), (2, 8), (2, 9), (3, 2), (4, 3), (5, 3), (6, 3), (7, 5), (8, 5), (9, 5)}] + 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: [(1, 2), (1, 3), (1, 4), (1, 5), (1, 6), (1, 7), (1, 8), (1, 9), (2, 2), (2, 3), (2, 4), (2, 5), (2, 6), (2, 7), (2, 8), (2, 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]; + prev_states0[3][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][1]; + prev_states0[4][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][1]; + 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][2]; + prev_states0[10][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][2]; + prev_states0[11][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][2]; + prev_states0[12][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][2]; + prev_states0[13][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][2]; + prev_states0[14][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][2]; + prev_states0[15][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][2]; + prev_states0[16][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][3]; + prev_states0[17][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][4]; + prev_states0[18][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][5]; + prev_states0[19][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][6]; + prev_states0[20][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][7]; + prev_states0[21][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][8]; + prev_states0[22][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][9]; + is_substr0[i] <== MultiOR(23)([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][4], prev_states0[11][i] * states[i+2][5], prev_states0[12][i] * states[i+2][6], prev_states0[13][i] * states[i+2][7], prev_states0[14][i] * states[i+2][8], prev_states0[15][i] * states[i+2][9], prev_states0[16][i] * states[i+2][2], prev_states0[17][i] * states[i+2][3], prev_states0[18][i] * states[i+2][3], prev_states0[19][i] * states[i+2][3], prev_states0[20][i] * states[i+2][5], prev_states0[21][i] * states[i+2][5], prev_states0[22][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]; + } +} \ No newline at end of file diff --git a/packages/circom/circuits/common/reversed_email_addr_with_name_regex.circom b/packages/circom/circuits/common/reversed_email_addr_with_name_regex.circom new file mode 100644 index 0000000..809ef2c --- /dev/null +++ b/packages/circom/circuits/common/reversed_email_addr_with_name_regex.circom @@ -0,0 +1,566 @@ +pragma circom 2.1.5; + +include "@zk-email/zk-regex-circom/circuits/regex_helpers.circom"; + +// regex: >[a-zA-Z0-9.\-]+@[A-Za-z0-9!#$%&'*+=?\-\^_`{|}~./@]+<.* +template ReversedEmailAddrWithNameRegex(msg_bytes) { + signal input msg[msg_bytes]; + signal output out; + + var num_bytes = msg_bytes+1; + signal in[num_bytes]; + in[0]<==255; + for (var i = 0; i < msg_bytes; i++) { + in[i+1] <== msg[i]; + } + + component eq[71][num_bytes]; + component lt[20][num_bytes]; + component and[32][num_bytes]; + component multi_or[11][num_bytes]; + signal states[num_bytes+1][13]; + signal states_tmp[num_bytes+1][13]; + signal from_zero_enabled[num_bytes+1]; + from_zero_enabled[num_bytes] <== 0; + component state_changed[num_bytes]; + + for (var i = 1; i < 13; i++) { + states[0][i] <== 0; + } + + for (var i = 0; i < num_bytes; i++) { + state_changed[i] = MultiOR(12); + states[i][0] <== 1; + eq[0][i] = IsEqual(); + eq[0][i].in[0] <== in[i]; + eq[0][i].in[1] <== 62; + and[0][i] = AND(); + and[0][i].a <== states[i][0]; + and[0][i].b <== eq[0][i].out; + states_tmp[i+1][1] <== 0; + lt[0][i] = LessEqThan(8); + lt[0][i].in[0] <== 65; + lt[0][i].in[1] <== in[i]; + lt[1][i] = LessEqThan(8); + lt[1][i].in[0] <== in[i]; + lt[1][i].in[1] <== 90; + and[1][i] = AND(); + and[1][i].a <== lt[0][i].out; + and[1][i].b <== lt[1][i].out; + lt[2][i] = LessEqThan(8); + lt[2][i].in[0] <== 97; + lt[2][i].in[1] <== in[i]; + lt[3][i] = LessEqThan(8); + lt[3][i].in[0] <== in[i]; + lt[3][i].in[1] <== 122; + and[2][i] = AND(); + and[2][i].a <== lt[2][i].out; + and[2][i].b <== lt[3][i].out; + eq[1][i] = IsEqual(); + eq[1][i].in[0] <== in[i]; + eq[1][i].in[1] <== 45; + eq[2][i] = IsEqual(); + eq[2][i].in[0] <== in[i]; + eq[2][i].in[1] <== 46; + eq[3][i] = IsEqual(); + eq[3][i].in[0] <== in[i]; + eq[3][i].in[1] <== 48; + eq[4][i] = IsEqual(); + eq[4][i].in[0] <== in[i]; + eq[4][i].in[1] <== 49; + eq[5][i] = IsEqual(); + eq[5][i].in[0] <== in[i]; + eq[5][i].in[1] <== 50; + eq[6][i] = IsEqual(); + eq[6][i].in[0] <== in[i]; + eq[6][i].in[1] <== 51; + eq[7][i] = IsEqual(); + eq[7][i].in[0] <== in[i]; + eq[7][i].in[1] <== 52; + eq[8][i] = IsEqual(); + eq[8][i].in[0] <== in[i]; + eq[8][i].in[1] <== 53; + eq[9][i] = IsEqual(); + eq[9][i].in[0] <== in[i]; + eq[9][i].in[1] <== 54; + eq[10][i] = IsEqual(); + eq[10][i].in[0] <== in[i]; + eq[10][i].in[1] <== 55; + eq[11][i] = IsEqual(); + eq[11][i].in[0] <== in[i]; + eq[11][i].in[1] <== 56; + eq[12][i] = IsEqual(); + eq[12][i].in[0] <== in[i]; + eq[12][i].in[1] <== 57; + and[3][i] = AND(); + and[3][i].a <== states[i][1]; + multi_or[0][i] = MultiOR(14); + multi_or[0][i].in[0] <== and[1][i].out; + multi_or[0][i].in[1] <== and[2][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; + multi_or[0][i].in[12] <== eq[11][i].out; + multi_or[0][i].in[13] <== eq[12][i].out; + and[3][i].b <== multi_or[0][i].out; + and[4][i] = AND(); + and[4][i].a <== states[i][2]; + 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][2] <== multi_or[1][i].out; + eq[13][i] = IsEqual(); + eq[13][i].in[0] <== in[i]; + eq[13][i].in[1] <== 64; + and[5][i] = AND(); + and[5][i].a <== states[i][2]; + and[5][i].b <== eq[13][i].out; + states[i+1][3] <== and[5][i].out; + lt[4][i] = LessEqThan(8); + lt[4][i].in[0] <== 63; + 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; + and[6][i] = AND(); + and[6][i].a <== lt[4][i].out; + and[6][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[7][i] = AND(); + and[7][i].a <== lt[6][i].out; + and[7][i].b <== lt[7][i].out; + eq[14][i] = IsEqual(); + eq[14][i].in[0] <== in[i]; + eq[14][i].in[1] <== 33; + eq[15][i] = IsEqual(); + eq[15][i].in[0] <== in[i]; + eq[15][i].in[1] <== 35; + eq[16][i] = IsEqual(); + eq[16][i].in[0] <== in[i]; + eq[16][i].in[1] <== 36; + eq[17][i] = IsEqual(); + eq[17][i].in[0] <== in[i]; + eq[17][i].in[1] <== 37; + eq[18][i] = IsEqual(); + eq[18][i].in[0] <== in[i]; + eq[18][i].in[1] <== 38; + eq[19][i] = IsEqual(); + eq[19][i].in[0] <== in[i]; + eq[19][i].in[1] <== 39; + eq[20][i] = IsEqual(); + eq[20][i].in[0] <== in[i]; + eq[20][i].in[1] <== 42; + eq[21][i] = IsEqual(); + eq[21][i].in[0] <== in[i]; + eq[21][i].in[1] <== 43; + eq[22][i] = IsEqual(); + eq[22][i].in[0] <== in[i]; + eq[22][i].in[1] <== 47; + eq[23][i] = IsEqual(); + eq[23][i].in[0] <== in[i]; + eq[23][i].in[1] <== 61; + and[8][i] = AND(); + and[8][i].a <== states[i][3]; + multi_or[2][i] = MultiOR(24); + 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[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[1][i].out; + multi_or[2][i].in[11] <== eq[2][i].out; + multi_or[2][i].in[12] <== eq[22][i].out; + multi_or[2][i].in[13] <== eq[3][i].out; + multi_or[2][i].in[14] <== eq[4][i].out; + multi_or[2][i].in[15] <== eq[5][i].out; + multi_or[2][i].in[16] <== eq[6][i].out; + multi_or[2][i].in[17] <== eq[7][i].out; + multi_or[2][i].in[18] <== eq[8][i].out; + multi_or[2][i].in[19] <== eq[9][i].out; + multi_or[2][i].in[20] <== eq[10][i].out; + multi_or[2][i].in[21] <== eq[11][i].out; + multi_or[2][i].in[22] <== eq[12][i].out; + multi_or[2][i].in[23] <== eq[23][i].out; + and[8][i].b <== multi_or[2][i].out; + and[9][i] = AND(); + and[9][i].a <== states[i][4]; + and[9][i].b <== multi_or[2][i].out; + multi_or[3][i] = MultiOR(2); + multi_or[3][i].in[0] <== and[8][i].out; + multi_or[3][i].in[1] <== and[9][i].out; + states[i+1][4] <== multi_or[3][i].out; + eq[24][i] = IsEqual(); + eq[24][i].in[0] <== in[i]; + eq[24][i].in[1] <== 60; + and[10][i] = AND(); + and[10][i].a <== states[i][4]; + and[10][i].b <== eq[24][i].out; + lt[8][i] = LessEqThan(8); + lt[8][i].in[0] <== 11; + lt[8][i].in[1] <== in[i]; + lt[9][i] = LessEqThan(8); + lt[9][i].in[0] <== in[i]; + lt[9][i].in[1] <== 127; + and[11][i] = AND(); + and[11][i].a <== lt[8][i].out; + and[11][i].b <== lt[9][i].out; + eq[25][i] = IsEqual(); + eq[25][i].in[0] <== in[i]; + eq[25][i].in[1] <== 1; + eq[26][i] = IsEqual(); + eq[26][i].in[0] <== in[i]; + eq[26][i].in[1] <== 2; + eq[27][i] = IsEqual(); + eq[27][i].in[0] <== in[i]; + eq[27][i].in[1] <== 3; + eq[28][i] = IsEqual(); + eq[28][i].in[0] <== in[i]; + eq[28][i].in[1] <== 4; + eq[29][i] = IsEqual(); + eq[29][i].in[0] <== in[i]; + eq[29][i].in[1] <== 5; + eq[30][i] = IsEqual(); + eq[30][i].in[0] <== in[i]; + eq[30][i].in[1] <== 6; + eq[31][i] = IsEqual(); + eq[31][i].in[0] <== in[i]; + eq[31][i].in[1] <== 7; + eq[32][i] = IsEqual(); + eq[32][i].in[0] <== in[i]; + eq[32][i].in[1] <== 8; + eq[33][i] = IsEqual(); + eq[33][i].in[0] <== in[i]; + eq[33][i].in[1] <== 9; + and[12][i] = AND(); + and[12][i].a <== states[i][5]; + multi_or[4][i] = MultiOR(10); + multi_or[4][i].in[0] <== and[11][i].out; + multi_or[4][i].in[1] <== eq[25][i].out; + multi_or[4][i].in[2] <== eq[26][i].out; + multi_or[4][i].in[3] <== eq[27][i].out; + multi_or[4][i].in[4] <== eq[28][i].out; + multi_or[4][i].in[5] <== eq[29][i].out; + multi_or[4][i].in[6] <== eq[30][i].out; + multi_or[4][i].in[7] <== eq[31][i].out; + multi_or[4][i].in[8] <== eq[32][i].out; + multi_or[4][i].in[9] <== eq[33][i].out; + and[12][i].b <== multi_or[4][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] <== 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; + multi_or[5][i] = MultiOR(3); + multi_or[5][i].in[0] <== and[10][i].out; + multi_or[5][i].in[1] <== and[12][i].out; + multi_or[5][i].in[2] <== and[14][i].out; + states[i+1][5] <== multi_or[5][i].out; + lt[12][i] = LessEqThan(8); + lt[12][i].in[0] <== 194; + lt[12][i].in[1] <== in[i]; + lt[13][i] = LessEqThan(8); + lt[13][i].in[0] <== in[i]; + lt[13][i].in[1] <== 223; + and[15][i] = AND(); + and[15][i].a <== lt[12][i].out; + and[15][i].b <== lt[13][i].out; + and[16][i] = AND(); + and[16][i].a <== states[i][5]; + and[16][i].b <== and[15][i].out; + lt[14][i] = LessEqThan(8); + lt[14][i].in[0] <== 160; + lt[14][i].in[1] <== in[i]; + lt[15][i] = LessEqThan(8); + lt[15][i].in[0] <== in[i]; + lt[15][i].in[1] <== 191; + and[17][i] = AND(); + and[17][i].a <== lt[14][i].out; + and[17][i].b <== lt[15][i].out; + and[18][i] = AND(); + and[18][i].a <== states[i][7]; + and[18][i].b <== and[17][i].out; + and[19][i] = AND(); + and[19][i].a <== states[i][8]; + and[19][i].b <== and[13][i].out; + lt[16][i] = LessEqThan(8); + lt[16][i].in[0] <== 128; + lt[16][i].in[1] <== in[i]; + lt[17][i] = LessEqThan(8); + lt[17][i].in[0] <== in[i]; + lt[17][i].in[1] <== 159; + and[20][i] = AND(); + and[20][i].a <== lt[16][i].out; + and[20][i].b <== lt[17][i].out; + and[21][i] = AND(); + and[21][i].a <== states[i][9]; + and[21][i].b <== and[20][i].out; + multi_or[6][i] = MultiOR(4); + multi_or[6][i].in[0] <== and[16][i].out; + multi_or[6][i].in[1] <== and[18][i].out; + multi_or[6][i].in[2] <== and[19][i].out; + multi_or[6][i].in[3] <== and[21][i].out; + states[i+1][6] <== multi_or[6][i].out; + eq[34][i] = IsEqual(); + eq[34][i].in[0] <== in[i]; + eq[34][i].in[1] <== 224; + and[22][i] = AND(); + and[22][i].a <== states[i][5]; + and[22][i].b <== eq[34][i].out; + states[i+1][7] <== and[22][i].out; + eq[35][i] = IsEqual(); + eq[35][i].in[0] <== in[i]; + eq[35][i].in[1] <== 225; + eq[36][i] = IsEqual(); + eq[36][i].in[0] <== in[i]; + eq[36][i].in[1] <== 226; + eq[37][i] = IsEqual(); + eq[37][i].in[0] <== in[i]; + eq[37][i].in[1] <== 227; + eq[38][i] = IsEqual(); + eq[38][i].in[0] <== in[i]; + eq[38][i].in[1] <== 228; + eq[39][i] = IsEqual(); + eq[39][i].in[0] <== in[i]; + eq[39][i].in[1] <== 229; + eq[40][i] = IsEqual(); + eq[40][i].in[0] <== in[i]; + eq[40][i].in[1] <== 230; + eq[41][i] = IsEqual(); + eq[41][i].in[0] <== in[i]; + eq[41][i].in[1] <== 231; + eq[42][i] = IsEqual(); + eq[42][i].in[0] <== in[i]; + eq[42][i].in[1] <== 232; + eq[43][i] = IsEqual(); + eq[43][i].in[0] <== in[i]; + eq[43][i].in[1] <== 233; + eq[44][i] = IsEqual(); + eq[44][i].in[0] <== in[i]; + eq[44][i].in[1] <== 234; + eq[45][i] = IsEqual(); + eq[45][i].in[0] <== in[i]; + eq[45][i].in[1] <== 235; + eq[46][i] = IsEqual(); + eq[46][i].in[0] <== in[i]; + eq[46][i].in[1] <== 236; + eq[47][i] = IsEqual(); + eq[47][i].in[0] <== in[i]; + eq[47][i].in[1] <== 238; + eq[48][i] = IsEqual(); + eq[48][i].in[0] <== in[i]; + eq[48][i].in[1] <== 239; + and[23][i] = AND(); + and[23][i].a <== states[i][5]; + multi_or[7][i] = MultiOR(14); + 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; + multi_or[7][i].in[3] <== eq[38][i].out; + multi_or[7][i].in[4] <== eq[39][i].out; + multi_or[7][i].in[5] <== eq[40][i].out; + multi_or[7][i].in[6] <== eq[41][i].out; + multi_or[7][i].in[7] <== eq[42][i].out; + multi_or[7][i].in[8] <== eq[43][i].out; + multi_or[7][i].in[9] <== eq[44][i].out; + multi_or[7][i].in[10] <== eq[45][i].out; + multi_or[7][i].in[11] <== eq[46][i].out; + multi_or[7][i].in[12] <== eq[47][i].out; + multi_or[7][i].in[13] <== eq[48][i].out; + and[23][i].b <== multi_or[7][i].out; + lt[18][i] = LessEqThan(8); + lt[18][i].in[0] <== 144; + lt[18][i].in[1] <== in[i]; + lt[19][i] = LessEqThan(8); + lt[19][i].in[0] <== in[i]; + lt[19][i].in[1] <== 191; + and[24][i] = AND(); + and[24][i].a <== lt[18][i].out; + and[24][i].b <== lt[19][i].out; + and[25][i] = AND(); + and[25][i].a <== states[i][10]; + and[25][i].b <== and[24][i].out; + and[26][i] = AND(); + and[26][i].a <== states[i][11]; + and[26][i].b <== and[13][i].out; + eq[49][i] = IsEqual(); + eq[49][i].in[0] <== in[i]; + eq[49][i].in[1] <== 128; + eq[50][i] = IsEqual(); + eq[50][i].in[0] <== in[i]; + eq[50][i].in[1] <== 129; + eq[51][i] = IsEqual(); + eq[51][i].in[0] <== in[i]; + eq[51][i].in[1] <== 130; + eq[52][i] = IsEqual(); + eq[52][i].in[0] <== in[i]; + eq[52][i].in[1] <== 131; + eq[53][i] = IsEqual(); + eq[53][i].in[0] <== in[i]; + eq[53][i].in[1] <== 132; + eq[54][i] = IsEqual(); + eq[54][i].in[0] <== in[i]; + eq[54][i].in[1] <== 133; + eq[55][i] = IsEqual(); + eq[55][i].in[0] <== in[i]; + eq[55][i].in[1] <== 134; + eq[56][i] = IsEqual(); + eq[56][i].in[0] <== in[i]; + eq[56][i].in[1] <== 135; + eq[57][i] = IsEqual(); + eq[57][i].in[0] <== in[i]; + eq[57][i].in[1] <== 136; + eq[58][i] = IsEqual(); + eq[58][i].in[0] <== in[i]; + eq[58][i].in[1] <== 137; + eq[59][i] = IsEqual(); + eq[59][i].in[0] <== in[i]; + eq[59][i].in[1] <== 138; + eq[60][i] = IsEqual(); + eq[60][i].in[0] <== in[i]; + eq[60][i].in[1] <== 139; + eq[61][i] = IsEqual(); + eq[61][i].in[0] <== in[i]; + eq[61][i].in[1] <== 140; + eq[62][i] = IsEqual(); + eq[62][i].in[0] <== in[i]; + eq[62][i].in[1] <== 141; + eq[63][i] = IsEqual(); + eq[63][i].in[0] <== in[i]; + eq[63][i].in[1] <== 142; + eq[64][i] = IsEqual(); + eq[64][i].in[0] <== in[i]; + eq[64][i].in[1] <== 143; + and[27][i] = AND(); + and[27][i].a <== states[i][12]; + multi_or[8][i] = MultiOR(16); + multi_or[8][i].in[0] <== eq[49][i].out; + multi_or[8][i].in[1] <== eq[50][i].out; + multi_or[8][i].in[2] <== eq[51][i].out; + multi_or[8][i].in[3] <== eq[52][i].out; + multi_or[8][i].in[4] <== eq[53][i].out; + multi_or[8][i].in[5] <== eq[54][i].out; + multi_or[8][i].in[6] <== eq[55][i].out; + multi_or[8][i].in[7] <== eq[56][i].out; + multi_or[8][i].in[8] <== eq[57][i].out; + multi_or[8][i].in[9] <== eq[58][i].out; + multi_or[8][i].in[10] <== eq[59][i].out; + multi_or[8][i].in[11] <== eq[60][i].out; + multi_or[8][i].in[12] <== eq[61][i].out; + multi_or[8][i].in[13] <== eq[62][i].out; + multi_or[8][i].in[14] <== eq[63][i].out; + multi_or[8][i].in[15] <== eq[64][i].out; + and[27][i].b <== multi_or[8][i].out; + multi_or[9][i] = MultiOR(4); + multi_or[9][i].in[0] <== and[23][i].out; + multi_or[9][i].in[1] <== and[25][i].out; + multi_or[9][i].in[2] <== and[26][i].out; + multi_or[9][i].in[3] <== and[27][i].out; + states[i+1][8] <== multi_or[9][i].out; + eq[65][i] = IsEqual(); + eq[65][i].in[0] <== in[i]; + eq[65][i].in[1] <== 237; + and[28][i] = AND(); + and[28][i].a <== states[i][5]; + and[28][i].b <== eq[65][i].out; + states[i+1][9] <== and[28][i].out; + eq[66][i] = IsEqual(); + eq[66][i].in[0] <== in[i]; + eq[66][i].in[1] <== 240; + and[29][i] = AND(); + and[29][i].a <== states[i][5]; + and[29][i].b <== eq[66][i].out; + states[i+1][10] <== and[29][i].out; + eq[67][i] = IsEqual(); + eq[67][i].in[0] <== in[i]; + eq[67][i].in[1] <== 241; + eq[68][i] = IsEqual(); + eq[68][i].in[0] <== in[i]; + eq[68][i].in[1] <== 242; + eq[69][i] = IsEqual(); + eq[69][i].in[0] <== in[i]; + eq[69][i].in[1] <== 243; + and[30][i] = AND(); + and[30][i].a <== states[i][5]; + multi_or[10][i] = MultiOR(3); + multi_or[10][i].in[0] <== eq[67][i].out; + multi_or[10][i].in[1] <== eq[68][i].out; + multi_or[10][i].in[2] <== eq[69][i].out; + and[30][i].b <== multi_or[10][i].out; + states[i+1][11] <== and[30][i].out; + eq[70][i] = IsEqual(); + eq[70][i].in[0] <== in[i]; + eq[70][i].in[1] <== 244; + and[31][i] = AND(); + and[31][i].a <== states[i][5]; + and[31][i].b <== eq[70][i].out; + states[i+1][12] <== and[31][i].out; + from_zero_enabled[i] <== MultiNOR(12)([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], states[i+1][12]]); + states[i+1][1] <== MultiOR(2)([states_tmp[i+1][1], from_zero_enabled[i] * and[0][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]; + state_changed[i].in[3] <== states[i+1][4]; + state_changed[i].in[4] <== states[i+1][5]; + state_changed[i].in[5] <== states[i+1][6]; + state_changed[i].in[6] <== states[i+1][7]; + state_changed[i].in[7] <== states[i+1][8]; + state_changed[i].in[8] <== states[i+1][9]; + state_changed[i].in[9] <== states[i+1][10]; + state_changed[i].in[10] <== states[i+1][11]; + state_changed[i].in[11] <== states[i+1][12]; + } + + component is_accepted = MultiOR(num_bytes+1); + for (var i = 0; i <= num_bytes; i++) { + is_accepted.in[i] <== states[i][5]; + } + 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][5] * (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][5], is_consecutive[msg_bytes-1-i][1]]); + } + // substrings calculated: [{(1, 2), (2, 2), (2, 3), (3, 4), (4, 4)}] + signal prev_states0[5][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), (2, 2), (2, 3), (3, 4), (4, 4)] + 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][2]; + prev_states0[2][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][2]; + prev_states0[3][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][3]; + prev_states0[4][i] <== (1 - from_zero_enabled[i+1]) * states[i+1][4]; + is_substr0[i] <== MultiOR(5)([prev_states0[0][i] * states[i+2][2], 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]]); + is_reveal0[i] <== MultiAND(3)([out, is_substr0[i], is_consecutive[i][2]]); + reveal0[i] <== in[i+1] * is_reveal0[i]; + } +} \ No newline at end of file diff --git a/packages/circom/circuits/common/subject_all_regex.circom b/packages/circom/circuits/common/subject_all_regex.circom index e66edcc..11c39e8 100644 --- a/packages/circom/circuits/common/subject_all_regex.circom +++ b/packages/circom/circuits/common/subject_all_regex.circom @@ -11,6 +11,7 @@ template SubjectAllRegex(msg_bytes) { signal in[num_bytes]; in[0]<==255; for (var i = 0; i < msg_bytes; i++) { + _ <== LessThan(8)([msg[i], 255]); in[i+1] <== msg[i]; } diff --git a/packages/circom/circuits/common/timestamp_regex.circom b/packages/circom/circuits/common/timestamp_regex.circom index d0f909a..31aa51d 100644 --- a/packages/circom/circuits/common/timestamp_regex.circom +++ b/packages/circom/circuits/common/timestamp_regex.circom @@ -11,6 +11,7 @@ template TimestampRegex(msg_bytes) { signal in[num_bytes]; in[0]<==255; for (var i = 0; i < msg_bytes; i++) { + _ <== LessThan(8)([msg[i], 255]); in[i+1] <== msg[i]; } diff --git a/packages/circom/circuits/common/to_addr.json b/packages/circom/circuits/common/to_addr.json deleted file mode 100644 index 9c7a4b1..0000000 --- a/packages/circom/circuits/common/to_addr.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "parts": [ - { - "is_public": false, - "regex_def": "(\r\n|^)to:" - }, - { - "is_public": false, - "regex_def": "([^\r\n]+<)?" - }, - { - "is_public": true, - "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 2dbbca8..873f00c 100644 --- a/packages/circom/circuits/common/to_all_regex.circom +++ b/packages/circom/circuits/common/to_all_regex.circom @@ -11,6 +11,7 @@ template ToAllRegex(msg_bytes) { signal in[num_bytes]; in[0]<==255; for (var i = 0; i < msg_bytes; i++) { + _ <== LessThan(8)([msg[i], 255]); in[i+1] <== msg[i]; } diff --git a/packages/circom/package.json b/packages/circom/package.json index 7ada07d..d9996b1 100644 --- a/packages/circom/package.json +++ b/packages/circom/package.json @@ -1,6 +1,6 @@ { "name": "@zk-email/zk-regex-circom", - "version": "2.1.1", + "version": "2.2.0", "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": [ @@ -23,7 +23,7 @@ "devDependencies": { "@types/jest": "^29.5.4", "chai": "^4.3.7", - "circom_tester": "^0.0.19", + "circom_tester": "^0.0.20", "circomlib": "^2.0.5", "circomlibjs": "^0.1.2", "ffjavascript": "^0.2.59", diff --git a/packages/circom/tests/circuits/asterisk1_regex.circom b/packages/circom/tests/circuits/asterisk1_regex.circom index 84cfa9d..82dffb2 100644 --- a/packages/circom/tests/circuits/asterisk1_regex.circom +++ b/packages/circom/tests/circuits/asterisk1_regex.circom @@ -11,6 +11,7 @@ template Asterisk1Regex(msg_bytes) { signal in[num_bytes]; in[0]<==255; for (var i = 0; i < msg_bytes; i++) { + _ <== LessThan(8)([msg[i], 255]); in[i+1] <== msg[i]; } diff --git a/packages/circom/tests/circuits/asterisk2_regex.circom b/packages/circom/tests/circuits/asterisk2_regex.circom index 5c82fbc..3ff752f 100644 --- a/packages/circom/tests/circuits/asterisk2_regex.circom +++ b/packages/circom/tests/circuits/asterisk2_regex.circom @@ -11,6 +11,7 @@ template Asterisk2Regex(msg_bytes) { signal in[num_bytes]; in[0]<==255; for (var i = 0; i < msg_bytes; i++) { + _ <== LessThan(8)([msg[i], 255]); in[i+1] <== msg[i]; } diff --git a/packages/circom/tests/circuits/asterisk3_regex.circom b/packages/circom/tests/circuits/asterisk3_regex.circom index 29b5ecd..e0a4b02 100644 --- a/packages/circom/tests/circuits/asterisk3_regex.circom +++ b/packages/circom/tests/circuits/asterisk3_regex.circom @@ -11,6 +11,7 @@ template Asterisk3Regex(msg_bytes) { signal in[num_bytes]; in[0]<==255; for (var i = 0; i < msg_bytes; i++) { + _ <== LessThan(8)([msg[i], 255]); in[i+1] <== msg[i]; } diff --git a/packages/circom/tests/circuits/caret1_regex.circom b/packages/circom/tests/circuits/caret1_regex.circom index c308f41..073e941 100644 --- a/packages/circom/tests/circuits/caret1_regex.circom +++ b/packages/circom/tests/circuits/caret1_regex.circom @@ -11,6 +11,7 @@ template Caret1Regex(msg_bytes) { signal in[num_bytes]; in[0]<==255; for (var i = 0; i < msg_bytes; i++) { + _ <== LessThan(8)([msg[i], 255]); in[i+1] <== msg[i]; } diff --git a/packages/circom/tests/circuits/caret2_regex.circom b/packages/circom/tests/circuits/caret2_regex.circom index 4da9f95..a3655b4 100644 --- a/packages/circom/tests/circuits/caret2_regex.circom +++ b/packages/circom/tests/circuits/caret2_regex.circom @@ -11,6 +11,7 @@ template Caret2Regex(msg_bytes) { signal in[num_bytes]; in[0]<==255; for (var i = 0; i < msg_bytes; i++) { + _ <== LessThan(8)([msg[i], 255]); in[i+1] <== msg[i]; } diff --git a/packages/circom/tests/circuits/caret3_regex.circom b/packages/circom/tests/circuits/caret3_regex.circom index 9cf377d..3fbdd37 100644 --- a/packages/circom/tests/circuits/caret3_regex.circom +++ b/packages/circom/tests/circuits/caret3_regex.circom @@ -11,6 +11,7 @@ template Caret3Regex(msg_bytes) { signal in[num_bytes]; in[0]<==255; for (var i = 0; i < msg_bytes; i++) { + _ <== LessThan(8)([msg[i], 255]); in[i+1] <== msg[i]; } diff --git a/packages/circom/tests/circuits/caret4_regex.circom b/packages/circom/tests/circuits/caret4_regex.circom index 79f53c2..f89098b 100644 --- a/packages/circom/tests/circuits/caret4_regex.circom +++ b/packages/circom/tests/circuits/caret4_regex.circom @@ -11,6 +11,7 @@ template Caret4Regex(msg_bytes) { signal in[num_bytes]; in[0]<==255; for (var i = 0; i < msg_bytes; i++) { + _ <== LessThan(8)([msg[i], 255]); in[i+1] <== msg[i]; } diff --git a/packages/circom/tests/circuits/caret5_regex.circom b/packages/circom/tests/circuits/caret5_regex.circom index 2c189b3..7a51160 100644 --- a/packages/circom/tests/circuits/caret5_regex.circom +++ b/packages/circom/tests/circuits/caret5_regex.circom @@ -11,6 +11,7 @@ template Caret5Regex(msg_bytes) { signal in[num_bytes]; in[0]<==255; for (var i = 0; i < msg_bytes; i++) { + _ <== LessThan(8)([msg[i], 255]); in[i+1] <== msg[i]; } diff --git a/packages/circom/tests/circuits/dollar1_regex.circom b/packages/circom/tests/circuits/dollar1_regex.circom index e8e8aee..a2ca8cd 100644 --- a/packages/circom/tests/circuits/dollar1_regex.circom +++ b/packages/circom/tests/circuits/dollar1_regex.circom @@ -11,6 +11,7 @@ template Dollar1Regex(msg_bytes) { signal in[num_bytes]; in[0]<==255; for (var i = 0; i < msg_bytes; i++) { + _ <== LessThan(8)([msg[i], 255]); in[i+1] <== msg[i]; } diff --git a/packages/circom/tests/circuits/dollar2_regex.circom b/packages/circom/tests/circuits/dollar2_regex.circom index 6a621a3..c0821df 100644 --- a/packages/circom/tests/circuits/dollar2_regex.circom +++ b/packages/circom/tests/circuits/dollar2_regex.circom @@ -11,6 +11,7 @@ template Dollar2Regex(msg_bytes) { signal in[num_bytes]; in[0]<==255; for (var i = 0; i < msg_bytes; i++) { + _ <== LessThan(8)([msg[i], 255]); in[i+1] <== msg[i]; } diff --git a/packages/circom/tests/circuits/dot1_regex.circom b/packages/circom/tests/circuits/dot1_regex.circom index 80f137f..af469f6 100644 --- a/packages/circom/tests/circuits/dot1_regex.circom +++ b/packages/circom/tests/circuits/dot1_regex.circom @@ -11,6 +11,7 @@ template Dot1Regex(msg_bytes) { signal in[num_bytes]; in[0]<==255; for (var i = 0; i < msg_bytes; i++) { + _ <== LessThan(8)([msg[i], 255]); in[i+1] <== msg[i]; } diff --git a/packages/circom/tests/circuits/dot2_regex.circom b/packages/circom/tests/circuits/dot2_regex.circom index 366ac40..de6e1c5 100644 --- a/packages/circom/tests/circuits/dot2_regex.circom +++ b/packages/circom/tests/circuits/dot2_regex.circom @@ -11,6 +11,7 @@ template Dot2Regex(msg_bytes) { signal in[num_bytes]; in[0]<==255; for (var i = 0; i < msg_bytes; i++) { + _ <== LessThan(8)([msg[i], 255]); in[i+1] <== msg[i]; } diff --git a/packages/circom/tests/circuits/international_chars_decomposed.circom b/packages/circom/tests/circuits/international_chars_decomposed.circom index 95e53db..aa29c52 100644 --- a/packages/circom/tests/circuits/international_chars_decomposed.circom +++ b/packages/circom/tests/circuits/international_chars_decomposed.circom @@ -11,6 +11,7 @@ template InternationalCharsDecomposed(msg_bytes) { signal in[num_bytes]; in[0]<==255; for (var i = 0; i < msg_bytes; i++) { + _ <== LessThan(8)([msg[i], 255]); in[i+1] <== msg[i]; } 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 8c31790..2b96a36 100644 --- a/packages/circom/tests/circuits/invitation_code_with_prefix_regex.circom +++ b/packages/circom/tests/circuits/invitation_code_with_prefix_regex.circom @@ -11,6 +11,7 @@ template InvitationCodeWithPrefixRegex(msg_bytes) { signal in[num_bytes]; in[0]<==255; for (var i = 0; i < msg_bytes; i++) { + _ <== LessThan(8)([msg[i], 255]); in[i+1] <== msg[i]; } diff --git a/packages/circom/tests/circuits/negate1_regex.circom b/packages/circom/tests/circuits/negate1_regex.circom index e5c7572..c0df6ea 100644 --- a/packages/circom/tests/circuits/negate1_regex.circom +++ b/packages/circom/tests/circuits/negate1_regex.circom @@ -11,6 +11,7 @@ template Negate1Regex(msg_bytes) { signal in[num_bytes]; in[0]<==255; for (var i = 0; i < msg_bytes; i++) { + _ <== LessThan(8)([msg[i], 255]); in[i+1] <== msg[i]; } diff --git a/packages/circom/tests/circuits/negate2_regex.circom b/packages/circom/tests/circuits/negate2_regex.circom index 1ed57f6..9dbf7c8 100644 --- a/packages/circom/tests/circuits/negate2_regex.circom +++ b/packages/circom/tests/circuits/negate2_regex.circom @@ -11,6 +11,7 @@ template Negate2Regex(msg_bytes) { signal in[num_bytes]; in[0]<==255; for (var i = 0; i < msg_bytes; i++) { + _ <== LessThan(8)([msg[i], 255]); in[i+1] <== msg[i]; } diff --git a/packages/circom/tests/circuits/plus1_regex.circom b/packages/circom/tests/circuits/plus1_regex.circom index 8e07bca..d8c9585 100644 --- a/packages/circom/tests/circuits/plus1_regex.circom +++ b/packages/circom/tests/circuits/plus1_regex.circom @@ -11,6 +11,7 @@ template Plus1Regex(msg_bytes) { signal in[num_bytes]; in[0]<==255; for (var i = 0; i < msg_bytes; i++) { + _ <== LessThan(8)([msg[i], 255]); in[i+1] <== msg[i]; } diff --git a/packages/circom/tests/circuits/plus2_regex.circom b/packages/circom/tests/circuits/plus2_regex.circom index 446ef9d..27663d2 100644 --- a/packages/circom/tests/circuits/plus2_regex.circom +++ b/packages/circom/tests/circuits/plus2_regex.circom @@ -11,6 +11,7 @@ template Plus2Regex(msg_bytes) { signal in[num_bytes]; in[0]<==255; for (var i = 0; i < msg_bytes; i++) { + _ <== LessThan(8)([msg[i], 255]); in[i+1] <== msg[i]; } diff --git a/packages/circom/tests/circuits/plus3_regex.circom b/packages/circom/tests/circuits/plus3_regex.circom index 6c1d829..6fb0c1a 100644 --- a/packages/circom/tests/circuits/plus3_regex.circom +++ b/packages/circom/tests/circuits/plus3_regex.circom @@ -11,6 +11,7 @@ template Plus3Regex(msg_bytes) { signal in[num_bytes]; in[0]<==255; for (var i = 0; i < msg_bytes; i++) { + _ <== LessThan(8)([msg[i], 255]); in[i+1] <== msg[i]; } diff --git a/packages/circom/tests/circuits/plus4_regex.circom b/packages/circom/tests/circuits/plus4_regex.circom index 38ee5c4..938b644 100644 --- a/packages/circom/tests/circuits/plus4_regex.circom +++ b/packages/circom/tests/circuits/plus4_regex.circom @@ -11,6 +11,7 @@ template Plus4Regex(msg_bytes) { signal in[num_bytes]; in[0]<==255; for (var i = 0; i < msg_bytes; i++) { + _ <== LessThan(8)([msg[i], 255]); in[i+1] <== msg[i]; } diff --git a/packages/circom/tests/circuits/question1_regex.circom b/packages/circom/tests/circuits/question1_regex.circom index f6cd3f0..c9be7d3 100644 --- a/packages/circom/tests/circuits/question1_regex.circom +++ b/packages/circom/tests/circuits/question1_regex.circom @@ -11,6 +11,7 @@ template Question1Regex(msg_bytes) { signal in[num_bytes]; in[0]<==255; for (var i = 0; i < msg_bytes; i++) { + _ <== LessThan(8)([msg[i], 255]); in[i+1] <== msg[i]; } diff --git a/packages/circom/tests/circuits/question2_regex.circom b/packages/circom/tests/circuits/question2_regex.circom index c717812..d954378 100644 --- a/packages/circom/tests/circuits/question2_regex.circom +++ b/packages/circom/tests/circuits/question2_regex.circom @@ -11,6 +11,7 @@ template Question2Regex(msg_bytes) { signal in[num_bytes]; in[0]<==255; for (var i = 0; i < msg_bytes; i++) { + _ <== LessThan(8)([msg[i], 255]); in[i+1] <== msg[i]; } diff --git a/packages/circom/tests/circuits/question3_regex.circom b/packages/circom/tests/circuits/question3_regex.circom index 0f62662..d713b5d 100644 --- a/packages/circom/tests/circuits/question3_regex.circom +++ b/packages/circom/tests/circuits/question3_regex.circom @@ -11,6 +11,7 @@ template Question3Regex(msg_bytes) { signal in[num_bytes]; in[0]<==255; for (var i = 0; i < msg_bytes; i++) { + _ <== LessThan(8)([msg[i], 255]); in[i+1] <== msg[i]; } diff --git a/packages/circom/tests/circuits/reveal_check1_regex.circom b/packages/circom/tests/circuits/reveal_check1_regex.circom index 998cb03..51d0da3 100644 --- a/packages/circom/tests/circuits/reveal_check1_regex.circom +++ b/packages/circom/tests/circuits/reveal_check1_regex.circom @@ -11,6 +11,7 @@ template RevealCheck1Regex(msg_bytes) { signal in[num_bytes]; in[0]<==255; for (var i = 0; i < msg_bytes; i++) { + _ <== LessThan(8)([msg[i], 255]); in[i+1] <== msg[i]; } diff --git a/packages/circom/tests/circuits/reveal_check2_regex.circom b/packages/circom/tests/circuits/reveal_check2_regex.circom index c646035..62e8f96 100644 --- a/packages/circom/tests/circuits/reveal_check2_regex.circom +++ b/packages/circom/tests/circuits/reveal_check2_regex.circom @@ -11,6 +11,7 @@ template RevealCheck2Regex(msg_bytes) { signal in[num_bytes]; in[0]<==255; for (var i = 0; i < msg_bytes; i++) { + _ <== LessThan(8)([msg[i], 255]); in[i+1] <== msg[i]; } diff --git a/packages/circom/tests/circuits/simple_regex.circom b/packages/circom/tests/circuits/simple_regex.circom index 4f8f6d4..202099d 100644 --- a/packages/circom/tests/circuits/simple_regex.circom +++ b/packages/circom/tests/circuits/simple_regex.circom @@ -11,6 +11,7 @@ template SimpleRegex(msg_bytes) { signal in[num_bytes]; in[0]<==255; for (var i = 0; i < msg_bytes; i++) { + _ <== LessThan(8)([msg[i], 255]); in[i+1] <== msg[i]; } diff --git a/packages/circom/tests/circuits/simple_regex_decomposed.circom b/packages/circom/tests/circuits/simple_regex_decomposed.circom index 2bef8e7..d26a005 100644 --- a/packages/circom/tests/circuits/simple_regex_decomposed.circom +++ b/packages/circom/tests/circuits/simple_regex_decomposed.circom @@ -11,6 +11,7 @@ template SimpleRegexDecomposed(msg_bytes) { signal in[num_bytes]; in[0]<==255; for (var i = 0; i < msg_bytes; i++) { + _ <== LessThan(8)([msg[i], 255]); in[i+1] <== msg[i]; } diff --git a/packages/circom/tests/circuits/test_asterisk1_regex.circom b/packages/circom/tests/circuits/test_asterisk1_regex.circom index dd58f8c..0a64229 100644 --- a/packages/circom/tests/circuits/test_asterisk1_regex.circom +++ b/packages/circom/tests/circuits/test_asterisk1_regex.circom @@ -1,3 +1,5 @@ +pragma circom 2.1.5; + include "./asterisk1_regex.circom"; component main = Asterisk1Regex(8); \ No newline at end of file diff --git a/packages/circom/tests/circuits/test_asterisk2_regex.circom b/packages/circom/tests/circuits/test_asterisk2_regex.circom index 271b997..3cea3c8 100644 --- a/packages/circom/tests/circuits/test_asterisk2_regex.circom +++ b/packages/circom/tests/circuits/test_asterisk2_regex.circom @@ -1,3 +1,5 @@ +pragma circom 2.1.5; + include "./asterisk2_regex.circom"; component main = Asterisk2Regex(8); \ No newline at end of file diff --git a/packages/circom/tests/circuits/test_asterisk3_regex.circom b/packages/circom/tests/circuits/test_asterisk3_regex.circom index 0744f94..04a8085 100644 --- a/packages/circom/tests/circuits/test_asterisk3_regex.circom +++ b/packages/circom/tests/circuits/test_asterisk3_regex.circom @@ -1,3 +1,5 @@ +pragma circom 2.1.5; + include "./asterisk3_regex.circom"; component main = Asterisk3Regex(8); \ No newline at end of file diff --git a/packages/circom/tests/circuits/test_body_hash_regex.circom b/packages/circom/tests/circuits/test_body_hash_regex.circom index f18b6c2..3cd4170 100644 --- a/packages/circom/tests/circuits/test_body_hash_regex.circom +++ b/packages/circom/tests/circuits/test_body_hash_regex.circom @@ -1,3 +1,5 @@ +pragma circom 2.1.5; + include "../../circuits/common/body_hash_regex.circom"; component main = BodyHashRegex(1024); \ No newline at end of file diff --git a/packages/circom/tests/circuits/test_caret1_regex.circom b/packages/circom/tests/circuits/test_caret1_regex.circom index 75c867a..c9dda7d 100644 --- a/packages/circom/tests/circuits/test_caret1_regex.circom +++ b/packages/circom/tests/circuits/test_caret1_regex.circom @@ -1,3 +1,5 @@ +pragma circom 2.1.5; + include "./caret1_regex.circom"; component main = Caret1Regex(8); \ No newline at end of file diff --git a/packages/circom/tests/circuits/test_caret2_regex.circom b/packages/circom/tests/circuits/test_caret2_regex.circom index 52d18be..c3e5eac 100644 --- a/packages/circom/tests/circuits/test_caret2_regex.circom +++ b/packages/circom/tests/circuits/test_caret2_regex.circom @@ -1,3 +1,5 @@ +pragma circom 2.1.5; + include "./caret2_regex.circom"; component main = Caret2Regex(8); \ No newline at end of file diff --git a/packages/circom/tests/circuits/test_caret3_regex.circom b/packages/circom/tests/circuits/test_caret3_regex.circom index 8f4a6de..2bfb8ab 100644 --- a/packages/circom/tests/circuits/test_caret3_regex.circom +++ b/packages/circom/tests/circuits/test_caret3_regex.circom @@ -1,3 +1,5 @@ +pragma circom 2.1.5; + include "./caret3_regex.circom"; component main = Caret3Regex(8); \ No newline at end of file diff --git a/packages/circom/tests/circuits/test_caret4_regex.circom b/packages/circom/tests/circuits/test_caret4_regex.circom index 71118e7..19e68c7 100644 --- a/packages/circom/tests/circuits/test_caret4_regex.circom +++ b/packages/circom/tests/circuits/test_caret4_regex.circom @@ -1,3 +1,5 @@ +pragma circom 2.1.5; + include "./caret4_regex.circom"; component main = Caret4Regex(8); \ No newline at end of file diff --git a/packages/circom/tests/circuits/test_caret5_regex.circom b/packages/circom/tests/circuits/test_caret5_regex.circom index 695afc4..72f3e42 100644 --- a/packages/circom/tests/circuits/test_caret5_regex.circom +++ b/packages/circom/tests/circuits/test_caret5_regex.circom @@ -1,3 +1,5 @@ +pragma circom 2.1.5; + include "./caret5_regex.circom"; component main = Caret5Regex(8); \ No newline at end of file diff --git a/packages/circom/tests/circuits/test_dollar1_regex.circom b/packages/circom/tests/circuits/test_dollar1_regex.circom index bf96b77..985cbf0 100644 --- a/packages/circom/tests/circuits/test_dollar1_regex.circom +++ b/packages/circom/tests/circuits/test_dollar1_regex.circom @@ -1,3 +1,5 @@ +pragma circom 2.1.5; + include "./dollar1_regex.circom"; component main = Dollar1Regex(8); \ No newline at end of file diff --git a/packages/circom/tests/circuits/test_dollar2_regex.circom b/packages/circom/tests/circuits/test_dollar2_regex.circom index 12f41ae..d343837 100644 --- a/packages/circom/tests/circuits/test_dollar2_regex.circom +++ b/packages/circom/tests/circuits/test_dollar2_regex.circom @@ -1,3 +1,5 @@ +pragma circom 2.1.5; + include "./dollar2_regex.circom"; component main = Dollar2Regex(8); \ No newline at end of file diff --git a/packages/circom/tests/circuits/test_dot1_regex.circom b/packages/circom/tests/circuits/test_dot1_regex.circom index d0f1663..ab0b2b3 100644 --- a/packages/circom/tests/circuits/test_dot1_regex.circom +++ b/packages/circom/tests/circuits/test_dot1_regex.circom @@ -1,3 +1,5 @@ +pragma circom 2.1.5; + include "./dot1_regex.circom"; component main = Dot1Regex(8); \ No newline at end of file diff --git a/packages/circom/tests/circuits/test_dot2_regex.circom b/packages/circom/tests/circuits/test_dot2_regex.circom index b57d5be..80e9869 100644 --- a/packages/circom/tests/circuits/test_dot2_regex.circom +++ b/packages/circom/tests/circuits/test_dot2_regex.circom @@ -1,3 +1,5 @@ +pragma circom 2.1.5; + include "./dot2_regex.circom"; component main = Dot2Regex(8); \ No newline at end of file diff --git a/packages/circom/tests/circuits/test_email_addr_regex.circom b/packages/circom/tests/circuits/test_email_addr_regex.circom index 7d3e739..d429dd0 100644 --- a/packages/circom/tests/circuits/test_email_addr_regex.circom +++ b/packages/circom/tests/circuits/test_email_addr_regex.circom @@ -1,3 +1,5 @@ +pragma circom 2.1.5; + include "../../circuits/common/email_addr_regex.circom"; component main = EmailAddrRegex(256); \ No newline at end of file diff --git a/packages/circom/tests/circuits/test_email_domain_regex.circom b/packages/circom/tests/circuits/test_email_domain_regex.circom index d008d90..6232772 100644 --- a/packages/circom/tests/circuits/test_email_domain_regex.circom +++ b/packages/circom/tests/circuits/test_email_domain_regex.circom @@ -1,3 +1,5 @@ +pragma circom 2.1.5; + include "../../circuits/common/email_domain_regex.circom"; component main = EmailDomainRegex(256); \ No newline at end of file diff --git a/packages/circom/tests/circuits/test_from_addr_regex.circom b/packages/circom/tests/circuits/test_from_addr_regex.circom index 6796acc..ea9f5f0 100644 --- a/packages/circom/tests/circuits/test_from_addr_regex.circom +++ b/packages/circom/tests/circuits/test_from_addr_regex.circom @@ -1,3 +1,5 @@ +pragma circom 2.1.5; + include "../../circuits/common/from_addr_regex.circom"; component main = FromAddrRegex(1024); \ No newline at end of file diff --git a/packages/circom/tests/circuits/test_invitation_code_with_prefix_regex.circom b/packages/circom/tests/circuits/test_invitation_code_with_prefix_regex.circom index d7db356..664f80d 100644 --- a/packages/circom/tests/circuits/test_invitation_code_with_prefix_regex.circom +++ b/packages/circom/tests/circuits/test_invitation_code_with_prefix_regex.circom @@ -1,3 +1,5 @@ +pragma circom 2.1.5; + include "./invitation_code_with_prefix_regex.circom"; component main = InvitationCodeWithPrefixRegex(256); \ No newline at end of file diff --git a/packages/circom/tests/circuits/test_message_id_regex.circom b/packages/circom/tests/circuits/test_message_id_regex.circom index 15451ee..e7215f7 100644 --- a/packages/circom/tests/circuits/test_message_id_regex.circom +++ b/packages/circom/tests/circuits/test_message_id_regex.circom @@ -1,3 +1,5 @@ +pragma circom 2.1.5; + include "../../circuits/common/message_id_regex.circom"; component main = MessageIdRegex(256); \ No newline at end of file diff --git a/packages/circom/tests/circuits/test_negate1_regex.circom b/packages/circom/tests/circuits/test_negate1_regex.circom index 79cb526..2252976 100644 --- a/packages/circom/tests/circuits/test_negate1_regex.circom +++ b/packages/circom/tests/circuits/test_negate1_regex.circom @@ -1,2 +1,4 @@ +pragma circom 2.1.5; + include "./negate1_regex.circom"; component main = Negate1Regex(64); \ No newline at end of file diff --git a/packages/circom/tests/circuits/test_negate2_regex.circom b/packages/circom/tests/circuits/test_negate2_regex.circom index 5fe46a7..e46f725 100644 --- a/packages/circom/tests/circuits/test_negate2_regex.circom +++ b/packages/circom/tests/circuits/test_negate2_regex.circom @@ -1,2 +1,4 @@ +pragma circom 2.1.5; + include "./negate2_regex.circom"; component main = Negate2Regex(64); \ No newline at end of file diff --git a/packages/circom/tests/circuits/test_plus1_regex.circom b/packages/circom/tests/circuits/test_plus1_regex.circom index b08577f..d1693d4 100644 --- a/packages/circom/tests/circuits/test_plus1_regex.circom +++ b/packages/circom/tests/circuits/test_plus1_regex.circom @@ -1,3 +1,5 @@ +pragma circom 2.1.5; + include "./plus1_regex.circom"; component main = Plus1Regex(8); \ No newline at end of file diff --git a/packages/circom/tests/circuits/test_plus2_regex.circom b/packages/circom/tests/circuits/test_plus2_regex.circom index 9f7b6dc..6913134 100644 --- a/packages/circom/tests/circuits/test_plus2_regex.circom +++ b/packages/circom/tests/circuits/test_plus2_regex.circom @@ -1,3 +1,5 @@ +pragma circom 2.1.5; + include "./plus2_regex.circom"; component main = Plus2Regex(8); \ No newline at end of file diff --git a/packages/circom/tests/circuits/test_plus3_regex.circom b/packages/circom/tests/circuits/test_plus3_regex.circom index ae2aee7..1384c8d 100644 --- a/packages/circom/tests/circuits/test_plus3_regex.circom +++ b/packages/circom/tests/circuits/test_plus3_regex.circom @@ -1,3 +1,5 @@ +pragma circom 2.1.5; + include "./plus3_regex.circom"; component main = Plus3Regex(8); \ No newline at end of file diff --git a/packages/circom/tests/circuits/test_plus4_regex.circom b/packages/circom/tests/circuits/test_plus4_regex.circom index 6e7d760..af44e91 100644 --- a/packages/circom/tests/circuits/test_plus4_regex.circom +++ b/packages/circom/tests/circuits/test_plus4_regex.circom @@ -1,3 +1,5 @@ +pragma circom 2.1.5; + include "./plus4_regex.circom"; component main = Plus4Regex(8); \ No newline at end of file diff --git a/packages/circom/tests/circuits/test_question1_regex.circom b/packages/circom/tests/circuits/test_question1_regex.circom index e9f5cbd..4947d97 100644 --- a/packages/circom/tests/circuits/test_question1_regex.circom +++ b/packages/circom/tests/circuits/test_question1_regex.circom @@ -1,3 +1,5 @@ +pragma circom 2.1.5; + include "./question1_regex.circom"; component main = Question1Regex(8); \ No newline at end of file diff --git a/packages/circom/tests/circuits/test_question2_regex.circom b/packages/circom/tests/circuits/test_question2_regex.circom index be7b302..f6a0a09 100644 --- a/packages/circom/tests/circuits/test_question2_regex.circom +++ b/packages/circom/tests/circuits/test_question2_regex.circom @@ -1,3 +1,5 @@ +pragma circom 2.1.5; + include "./question2_regex.circom"; component main = Question2Regex(8); \ No newline at end of file diff --git a/packages/circom/tests/circuits/test_question3_regex.circom b/packages/circom/tests/circuits/test_question3_regex.circom index 9648de6..97e6532 100644 --- a/packages/circom/tests/circuits/test_question3_regex.circom +++ b/packages/circom/tests/circuits/test_question3_regex.circom @@ -1,3 +1,5 @@ +pragma circom 2.1.5; + include "./question3_regex.circom"; component main = Question3Regex(8); \ No newline at end of file diff --git a/packages/circom/tests/circuits/test_reveal_check1_regex.circom b/packages/circom/tests/circuits/test_reveal_check1_regex.circom index c10af39..ee24939 100644 --- a/packages/circom/tests/circuits/test_reveal_check1_regex.circom +++ b/packages/circom/tests/circuits/test_reveal_check1_regex.circom @@ -1,3 +1,5 @@ +pragma circom 2.1.5; + include "./reveal_check1_regex.circom"; component main = RevealCheck1Regex(8); \ No newline at end of file diff --git a/packages/circom/tests/circuits/test_reveal_check2_regex.circom b/packages/circom/tests/circuits/test_reveal_check2_regex.circom index c6c9062..eacba45 100644 --- a/packages/circom/tests/circuits/test_reveal_check2_regex.circom +++ b/packages/circom/tests/circuits/test_reveal_check2_regex.circom @@ -1,3 +1,5 @@ +pragma circom 2.1.5; + include "./reveal_check2_regex.circom"; component main = RevealCheck2Regex(8); \ No newline at end of file diff --git a/packages/circom/tests/circuits/test_subject_all_regex.circom b/packages/circom/tests/circuits/test_subject_all_regex.circom index 7efce72..e544739 100644 --- a/packages/circom/tests/circuits/test_subject_all_regex.circom +++ b/packages/circom/tests/circuits/test_subject_all_regex.circom @@ -1,3 +1,5 @@ +pragma circom 2.1.5; + include "../../circuits/common/subject_all_regex.circom"; component main = SubjectAllRegex(256); \ No newline at end of file diff --git a/packages/circom/tests/circuits/test_timestamp_regex.circom b/packages/circom/tests/circuits/test_timestamp_regex.circom index c1297d4..9b063ff 100644 --- a/packages/circom/tests/circuits/test_timestamp_regex.circom +++ b/packages/circom/tests/circuits/test_timestamp_regex.circom @@ -1,3 +1,5 @@ +pragma circom 2.1.5; + include "../../circuits/common/timestamp_regex.circom"; component main = TimestampRegex(1024); \ No newline at end of file diff --git a/packages/circom/tests/circuits/test_to_addr_regex.circom b/packages/circom/tests/circuits/test_to_addr_regex.circom index 12734d2..6f6343f 100644 --- a/packages/circom/tests/circuits/test_to_addr_regex.circom +++ b/packages/circom/tests/circuits/test_to_addr_regex.circom @@ -1,3 +1,5 @@ +pragma circom 2.1.5; + include "../../circuits/common/to_addr_regex.circom"; component main = ToAddrRegex(1024); \ No newline at end of file diff --git a/packages/circom/tests/from_addr.test.js b/packages/circom/tests/from_addr.test.js index dba8b0a..bfc8baa 100644 --- a/packages/circom/tests/from_addr.test.js +++ b/packages/circom/tests/from_addr.test.js @@ -28,17 +28,17 @@ describe("From Addr Regex", () => { } { const email_addr_json = readFileSync( - path.join(__dirname, "../circuits/common/email_addr_with_name.json"), + path.join(__dirname, "../circuits/common/reversed_bracket.json"), "utf8" ); const circom = compiler.genFromDecomposed( email_addr_json, - "EmailAddrWithNameRegex" + "ReversedBracketRegex" ); writeFileSync( path.join( __dirname, - "../circuits/common/email_addr_with_name_regex.circom" + "../circuits/common/reversed_bracket_regex.circom" ), circom ); @@ -268,4 +268,90 @@ describe("From Addr Regex", () => { } }); + it("from field with double <> 1", async () => { + const fromStr = "from:\"Some name \" \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("attacker@outlook.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 with double <> 2", async () => { + const fromStr = "from:\"Some name \" < attacker@outlook.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(" attacker@outlook.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 with double <> 3", async () => { + const fromStr = "from:\"Some name \" \r\n"; + const paddedStr = apis.padString(fromStr, 1024); + const circuitInputs = { + msg: paddedStr, + }; + const witness = await circuit.calculateWitness(circuitInputs); + await circuit.checkConstraints(witness); + // console.log((witness[1])); + expect(1n).toEqual(witness[1]); + const prefixIdxes = apis.extractFromAddrIdxes(fromStr)[0]; + expect("attacker@outlook.com ").toEqual(fromStr.slice(prefixIdxes[0], prefixIdxes[1])); + for (let idx = 0; idx < 1024; ++idx) { + // if (witness[2 + idx] !== 0n) { + // console.log('idx:', idx, 'witness:', 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("from field with triple <>", async () => { + const fromStr = "from:\"Some name >\" \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("attacker@outlook.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 f6b3a62..266814a 100644 --- a/packages/circom/tests/to_addr.test.js +++ b/packages/circom/tests/to_addr.test.js @@ -28,17 +28,17 @@ describe("To Addr Regex", () => { } { const email_addr_json = readFileSync( - path.join(__dirname, "../circuits/common/email_addr_with_name.json"), + path.join(__dirname, "../circuits/common/reversed_bracket.json"), "utf8" ); const circom = compiler.genFromDecomposed( email_addr_json, - "EmailAddrWithNameRegex" + "ReversedBracketRegex" ); writeFileSync( path.join( __dirname, - "../circuits/common/email_addr_with_name_regex.circom" + "../circuits/common/reversed_bracket_regex.circom" ), circom ); @@ -266,4 +266,94 @@ describe("To Addr Regex", () => { } } }); + + it("to field with double <> 1", async () => { + const toStr = "to:\"Some name \" \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("attacker@outlook.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 with double <> 2", async () => { + const toStr = "to:\"Some name \" < attacker@outlook.com>\r\n"; + const paddedStr = apis.padString(toStr, 1024); + const circuitInputs = { + msg: paddedStr, + }; + const witness = await circuit.calculateWitness(circuitInputs); + await circuit.checkConstraints(witness); + // console.log((witness[1])); + expect(1n).toEqual(witness[1]); + const prefixIdxes = apis.extractToAddrIdxes(toStr)[0]; + expect(" attacker@outlook.com").toEqual(toStr.slice(prefixIdxes[0], prefixIdxes[1])); + for (let idx = 0; idx < 1024; ++idx) { + // if (witness[2 + idx] !== 0n) { + // console.log('idx:', idx, 'witness:', 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("to field with double <> 3", async () => { + const toStr = "to:\"Some name \" \r\n"; + const paddedStr = apis.padString(toStr, 1024); + const circuitInputs = { + msg: paddedStr, + }; + const witness = await circuit.calculateWitness(circuitInputs); + await circuit.checkConstraints(witness); + // console.log((witness[1])); + expect(1n).toEqual(witness[1]); + const prefixIdxes = apis.extractToAddrIdxes(toStr)[0]; + expect("attacker@outlook.com ").toEqual(toStr.slice(prefixIdxes[0], prefixIdxes[1])); + for (let idx = 0; idx < 1024; ++idx) { + // if (witness[2 + idx] !== 0n) { + // console.log('idx:', idx, 'witness:', 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("to field with triple <>", async () => { + const toStr = "to:\"Some name >\" \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("attacker@outlook.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]); + } + } + }); }); diff --git a/packages/compiler/Cargo.toml b/packages/compiler/Cargo.toml index 049a959..958bf0a 100644 --- a/packages/compiler/Cargo.toml +++ b/packages/compiler/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "zk-regex-compiler" -version = "2.1.1" +version = "2.2.0" authors = [ "Javier Su ", "Kata Choi ", diff --git a/packages/compiler/package.json b/packages/compiler/package.json index e9e16a6..f8cce51 100644 --- a/packages/compiler/package.json +++ b/packages/compiler/package.json @@ -1,6 +1,6 @@ { "name": "@zk-email/zk-regex-compiler", - "version": "2.1.1", + "version": "2.2.0", "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.", "contributors": [ "Javier Su ", diff --git a/packages/compiler/src/circom.rs b/packages/compiler/src/circom.rs index 67b288a..2180489 100644 --- a/packages/compiler/src/circom.rs +++ b/packages/compiler/src/circom.rs @@ -584,6 +584,7 @@ fn generate_declarations( "\tsignal in[num_bytes];".to_string(), "\tin[0]<==255;".to_string(), "\tfor (var i = 0; i < msg_bytes; i++) {".to_string(), + "\t\t_ <== LessThan(8)([msg[i], 255]);".to_string(), "\t\tin[i+1] <== msg[i];".to_string(), "\t}".to_string(), "".to_string(),