diff --git a/.gitignore b/.gitignore index 1529d3b..ee605be 100644 --- a/.gitignore +++ b/.gitignore @@ -41,12 +41,6 @@ build/Release node_modules/ jspm_packages/ -# TypeScript v1 declaration files -typings/ - -# TypeScript cache -*.tsbuildinfo - # Optional npm cache directory .npm diff --git a/Cargo.lock b/Cargo.lock deleted file mode 100644 index 5132e78..0000000 --- a/Cargo.lock +++ /dev/null @@ -1,1752 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "addr2line" -version = "0.21.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" -dependencies = [ - "gimli", -] - -[[package]] -name = "adler" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" - -[[package]] -name = "ahash" -version = "0.8.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77c3a9648d43b9cd48db467b3f87fdd6e146bcc88ab0180006cef2179fe11d01" -dependencies = [ - "cfg-if", - "getrandom", - "once_cell", - "version_check", - "zerocopy", -] - -[[package]] -name = "aho-corasick" -version = "1.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2969dcb958b36655471fc61f7e416fa76033bdd4bfed0678d8fee1e2d07a1f0" -dependencies = [ - "memchr", -] - -[[package]] -name = "anstream" -version = "0.2.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "342258dd14006105c2b75ab1bd7543a03bdf0cfc94383303ac212a04939dff6f" -dependencies = [ - "anstyle", - "anstyle-parse", - "anstyle-wincon", - "concolor-override", - "concolor-query", - "is-terminal", - "utf8parse", -] - -[[package]] -name = "anstyle" -version = "0.3.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23ea9e81bd02e310c216d080f6223c179012256e5151c41db88d12c88a1684d2" - -[[package]] -name = "anstyle-parse" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a7d1bb534e9efed14f3e5f44e7dd1a4f709384023a4165199a4241e18dff0116" -dependencies = [ - "utf8parse", -] - -[[package]] -name = "anstyle-wincon" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3127af6145b149f3287bb9a0d10ad9c5692dba8c53ad48285e5bec4063834fa" -dependencies = [ - "anstyle", - "windows-sys 0.45.0", -] - -[[package]] -name = "anyhow" -version = "1.0.79" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "080e9890a082662b09c1ad45f567faeeb47f22b5fb23895fbe1e651e718e25ca" - -[[package]] -name = "autocfg" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" - -[[package]] -name = "backtrace" -version = "0.3.69" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2089b7e3f35b9dd2d0ed921ead4f6d318c27680d4a5bd167b3ee120edb105837" -dependencies = [ - "addr2line", - "cc", - "cfg-if", - "libc", - "miniz_oxide", - "object", - "rustc-demangle", -] - -[[package]] -name = "bit-set" -version = "0.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0700ddab506f33b20a03b13996eccd309a48e5ff77d0d95926aa0210fb4e95f1" -dependencies = [ - "bit-vec", -] - -[[package]] -name = "bit-vec" -version = "0.6.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "349f9b6a179ed607305526ca489b34ad0a41aed5f7980fa90eb03160b69598fb" - -[[package]] -name = "bitflags" -version = "1.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" - -[[package]] -name = "bitflags" -version = "2.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed570934406eb16438a4e976b1b4500774099c13b8cb96eec99f620f05090ddf" - -[[package]] -name = "bytes" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2bd12c1caf447e69cd4528f47f94d203fd2582878ecb9e9465484c4148a8223" - -[[package]] -name = "cc" -version = "1.0.83" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1174fb0b6ec23863f8b971027804a42614e347eafb0a95bf0b12cdae21fc4d0" -dependencies = [ - "libc", -] - -[[package]] -name = "cfg-if" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" - -[[package]] -name = "clap" -version = "4.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "046ae530c528f252094e4a77886ee1374437744b2bff1497aa898bbddbbb29b3" -dependencies = [ - "clap_builder", - "clap_derive", - "once_cell", -] - -[[package]] -name = "clap_builder" -version = "4.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "223163f58c9a40c3b0a43e1c4b50a9ce09f007ea2cb1ec258a687945b4b7929f" -dependencies = [ - "anstream", - "anstyle", - "bitflags 1.3.2", - "clap_lex", - "strsim 0.10.0", -] - -[[package]] -name = "clap_derive" -version = "4.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f9644cd56d6b87dbe899ef8b053e331c0637664e9e21a33dfcdc36093f5c5c4" -dependencies = [ - "heck", - "proc-macro2", - "quote", - "syn 2.0.48", -] - -[[package]] -name = "clap_lex" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a2dd5a6fe8c6e3502f568a6353e5273bbb15193ad9a89e457b9970798efbea1" - -[[package]] -name = "colorchoice" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" - -[[package]] -name = "concolor-override" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "40a4925288e39d5923e024781971aab940995fa31bab3ffceebbadfc87591e90" -dependencies = [ - "colorchoice", -] - -[[package]] -name = "concolor-query" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88d11d52c3d7ca2e6d0040212be9e4dbbcd78b6447f535b6b561f449427944cf" -dependencies = [ - "windows-sys 0.45.0", -] - -[[package]] -name = "convert_case" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e" - -[[package]] -name = "darling" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0d706e75d87e35569db781a9b5e2416cff1236a47ed380831f959382ccd5f858" -dependencies = [ - "darling_core", - "darling_macro", -] - -[[package]] -name = "darling_core" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0c960ae2da4de88a91b2d920c2a7233b400bc33cb28453a2987822d8392519b" -dependencies = [ - "fnv", - "ident_case", - "proc-macro2", - "quote", - "strsim 0.9.3", - "syn 1.0.109", -] - -[[package]] -name = "darling_macro" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9b5a2f4ac4969822c62224815d069952656cadc7084fdca9751e6d959189b72" -dependencies = [ - "darling_core", - "quote", - "syn 1.0.109", -] - -[[package]] -name = "data-encoding" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e962a19be5cfc3f3bf6dd8f61eb50107f356ad6270fbb3ed41476571db78be5" - -[[package]] -name = "debugid" -version = "0.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bef552e6f588e446098f6ba40d89ac146c8c7b64aade83c051ee00bb5d2bc18d" -dependencies = [ - "serde", - "uuid", -] - -[[package]] -name = "deno-proc-macro-rules" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c65c2ffdafc1564565200967edc4851c7b55422d3913466688907efd05ea26f" -dependencies = [ - "deno-proc-macro-rules-macros", - "proc-macro2", - "syn 2.0.48", -] - -[[package]] -name = "deno-proc-macro-rules-macros" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3047b312b7451e3190865713a4dd6e1f821aed614ada219766ebc3024a690435" -dependencies = [ - "once_cell", - "proc-macro2", - "quote", - "syn 2.0.48", -] - -[[package]] -name = "deno_core" -version = "0.209.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c48ff1f83aeeda4b8ed9c101b85380fd2f25a52268130546c610c8e412911d7b" -dependencies = [ - "anyhow", - "bytes", - "deno_ops", - "deno_unsync", - "futures", - "indexmap 1.9.3", - "libc", - "log", - "once_cell", - "parking_lot", - "pin-project", - "serde", - "serde_json", - "serde_v8", - "smallvec", - "sourcemap", - "tokio", - "url", - "v8", -] - -[[package]] -name = "deno_ops" -version = "0.87.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "573a5ae66f76ce159525ab9007433e19d1a074e32c27b17a4753780d659d79fa" -dependencies = [ - "deno-proc-macro-rules", - "lazy-regex", - "once_cell", - "pmutil", - "proc-macro-crate", - "proc-macro2", - "quote", - "regex", - "strum", - "strum_macros", - "syn 2.0.48", - "thiserror", -] - -[[package]] -name = "deno_unsync" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac0984205f25e71ddd1be603d76e70255953c12ff864707359ab195d26dfc7b3" -dependencies = [ - "tokio", -] - -[[package]] -name = "derive_builder" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2658621297f2cf68762a6f7dc0bb7e1ff2cfd6583daef8ee0fed6f7ec468ec0" -dependencies = [ - "darling", - "derive_builder_core", - "proc-macro2", - "quote", - "syn 1.0.109", -] - -[[package]] -name = "derive_builder_core" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2791ea3e372c8495c0bc2033991d76b512cd799d07491fbd6890124db9458bef" -dependencies = [ - "darling", - "proc-macro2", - "quote", - "syn 1.0.109", -] - -[[package]] -name = "derive_more" -version = "0.99.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fb810d30a7c1953f91334de7244731fc3f3c10d7fe163338a35b9f640960321" -dependencies = [ - "convert_case", - "proc-macro2", - "quote", - "rustc_version 0.4.0", - "syn 1.0.109", -] - -[[package]] -name = "either" -version = "1.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "11157ac094ffbdde99aa67b23417ebdd801842852b500e395a45a9c0aac03e4a" - -[[package]] -name = "equivalent" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" - -[[package]] -name = "errno" -version = "0.3.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a258e46cdc063eb8519c00b9fc845fc47bcfca4130e2f08e88665ceda8474245" -dependencies = [ - "libc", - "windows-sys 0.52.0", -] - -[[package]] -name = "fancy-regex" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b95f7c0680e4142284cf8b22c14a476e87d61b004a3a0861872b32ef7ead40a2" -dependencies = [ - "bit-set", - "regex", -] - -[[package]] -name = "fixedbitset" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ce7134b9999ecaf8bcd65542e436736ef32ddca1b3e06094cb6ec5755203b80" - -[[package]] -name = "fnv" -version = "1.0.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" - -[[package]] -name = "form_urlencoded" -version = "1.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456" -dependencies = [ - "percent-encoding", -] - -[[package]] -name = "fslock" -version = "0.1.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "57eafdd0c16f57161105ae1b98a1238f97645f2f588438b2949c99a2af9616bf" -dependencies = [ - "libc", - "winapi", -] - -[[package]] -name = "futures" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" -dependencies = [ - "futures-channel", - "futures-core", - "futures-executor", - "futures-io", - "futures-sink", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-channel" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" -dependencies = [ - "futures-core", - "futures-sink", -] - -[[package]] -name = "futures-core" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" - -[[package]] -name = "futures-executor" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" -dependencies = [ - "futures-core", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-io" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" - -[[package]] -name = "futures-macro" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.48", -] - -[[package]] -name = "futures-sink" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" - -[[package]] -name = "futures-task" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" - -[[package]] -name = "futures-util" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" -dependencies = [ - "futures-channel", - "futures-core", - "futures-io", - "futures-macro", - "futures-sink", - "futures-task", - "memchr", - "pin-project-lite", - "pin-utils", - "slab", -] - -[[package]] -name = "getrandom" -version = "0.2.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "190092ea657667030ac6a35e305e62fc4dd69fd98ac98631e5d3a2b1575a12b5" -dependencies = [ - "cfg-if", - "libc", - "wasi", -] - -[[package]] -name = "gimli" -version = "0.28.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" - -[[package]] -name = "graph-cycles" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3a6ad932c6dd3cfaf16b66754a42f87bbeefd591530c4b6a8334270a7df3e853" -dependencies = [ - "ahash", - "petgraph", - "thiserror", -] - -[[package]] -name = "hashbrown" -version = "0.12.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" - -[[package]] -name = "hashbrown" -version = "0.14.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" - -[[package]] -name = "heck" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" - -[[package]] -name = "hermit-abi" -version = "0.3.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d0c62115964e08cb8039170eb33c1d0e2388a256930279edca206fff675f82c3" - -[[package]] -name = "home" -version = "0.5.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3d1354bf6b7235cb4a0576c2619fd4ed18183f689b12b006a0ee7329eeff9a5" -dependencies = [ - "windows-sys 0.52.0", -] - -[[package]] -name = "ident_case" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" - -[[package]] -name = "idna" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6" -dependencies = [ - "unicode-bidi", - "unicode-normalization", -] - -[[package]] -name = "if_chain" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb56e1aa765b4b4f3aadfab769793b7087bb03a4ea4920644a6d238e2df5b9ed" - -[[package]] -name = "indexmap" -version = "1.9.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99" -dependencies = [ - "autocfg", - "hashbrown 0.12.3", -] - -[[package]] -name = "indexmap" -version = "2.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "824b2ae422412366ba479e8111fd301f7b5faece8149317bb81925979a53f520" -dependencies = [ - "equivalent", - "hashbrown 0.14.3", -] - -[[package]] -name = "is-terminal" -version = "0.4.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f23ff5ef2b80d608d61efee834934d862cd92461afc0560dedf493e4c033738b" -dependencies = [ - "hermit-abi", - "libc", - "windows-sys 0.52.0", -] - -[[package]] -name = "itertools" -version = "0.10.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473" -dependencies = [ - "either", -] - -[[package]] -name = "itoa" -version = "1.0.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1a46d1a171d865aa5f83f92695765caa047a9b4cbae2cbf37dbd613a793fd4c" - -[[package]] -name = "js-sandbox" -version = "0.2.0-rc.2" -source = "git+https://github.com/Bromeon/js-sandbox.git?tag=0.2.0-rc.2#b2946540aa1d67068b659bae5b867ffc4d9739dc" -dependencies = [ - "deno_core", - "js-sandbox-macros", - "serde", - "serde_json", -] - -[[package]] -name = "js-sandbox-macros" -version = "0.2.0-rc.2" -source = "git+https://github.com/Bromeon/js-sandbox.git?tag=0.2.0-rc.2#b2946540aa1d67068b659bae5b867ffc4d9739dc" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.48", -] - -[[package]] -name = "lazy-regex" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff63c423c68ea6814b7da9e88ce585f793c87ddd9e78f646970891769c8235d4" -dependencies = [ - "lazy-regex-proc_macros", - "once_cell", - "regex", -] - -[[package]] -name = "lazy-regex-proc_macros" -version = "2.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8edfc11b8f56ce85e207e62ea21557cfa09bb24a8f6b04ae181b086ff8611c22" -dependencies = [ - "proc-macro2", - "quote", - "regex", - "syn 1.0.109", -] - -[[package]] -name = "libc" -version = "0.2.153" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" - -[[package]] -name = "libloading" -version = "0.6.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "351a32417a12d5f7e82c368a66781e307834dae04c6ce0cd4456d52989229883" -dependencies = [ - "cfg-if", - "winapi", -] - -[[package]] -name = "linux-raw-sys" -version = "0.4.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01cda141df6706de531b6c46c3a33ecca755538219bd484262fa09410c13539c" - -[[package]] -name = "lock_api" -version = "0.4.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c168f8615b12bc01f9c17e2eb0cc07dcae1940121185446edc3744920e8ef45" -dependencies = [ - "autocfg", - "scopeguard", -] - -[[package]] -name = "log" -version = "0.4.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" - -[[package]] -name = "memchr" -version = "2.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "523dc4f511e55ab87b694dc30d0f820d60906ef06413f93d4d7a1385599cc149" - -[[package]] -name = "miniz_oxide" -version = "0.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" -dependencies = [ - "adler", -] - -[[package]] -name = "mio" -version = "0.8.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f3d0b296e374a4e6f3c7b0a1f5a51d748a0d34c85e7dc48fc3fa9a87657fe09" -dependencies = [ - "libc", - "wasi", - "windows-sys 0.48.0", -] - -[[package]] -name = "neon" -version = "0.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28e15415261d880aed48122e917a45e87bb82cf0260bb6db48bbab44b7464373" -dependencies = [ - "neon-build", - "neon-macros", - "neon-runtime", - "semver 0.9.0", - "smallvec", -] - -[[package]] -name = "neon-build" -version = "0.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8bac98a702e71804af3dacfde41edde4a16076a7bbe889ae61e56e18c5b1c811" - -[[package]] -name = "neon-macros" -version = "0.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b7288eac8b54af7913c60e0eb0e2a7683020dffa342ab3fd15e28f035ba897cf" -dependencies = [ - "quote", - "syn 1.0.109", - "syn-mid", -] - -[[package]] -name = "neon-runtime" -version = "0.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4676720fa8bb32c64c3d9f49c47a47289239ec46b4bdb66d0913cc512cb0daca" -dependencies = [ - "cfg-if", - "libloading", - "smallvec", -] - -[[package]] -name = "num-bigint" -version = "0.4.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "608e7659b5c3d7cba262d894801b9ec9d00de989e8a82bd4bef91d08da45cdc0" -dependencies = [ - "autocfg", - "num-integer", - "num-traits", - "rand", -] - -[[package]] -name = "num-integer" -version = "0.1.46" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7969661fd2958a5cb096e56c8e1ad0444ac2bbcd0061bd28660485a44879858f" -dependencies = [ - "num-traits", -] - -[[package]] -name = "num-traits" -version = "0.2.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da0df0e5185db44f69b44f26786fe401b6c293d1907744beaa7fa62b2e5a517a" -dependencies = [ - "autocfg", -] - -[[package]] -name = "num_cpus" -version = "1.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" -dependencies = [ - "hermit-abi", - "libc", -] - -[[package]] -name = "object" -version = "0.32.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" -dependencies = [ - "memchr", -] - -[[package]] -name = "once_cell" -version = "1.19.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" - -[[package]] -name = "parking_lot" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" -dependencies = [ - "lock_api", - "parking_lot_core", -] - -[[package]] -name = "parking_lot_core" -version = "0.9.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c42a9226546d68acdd9c0a280d17ce19bfe27a46bf68784e4066115788d008e" -dependencies = [ - "cfg-if", - "libc", - "redox_syscall", - "smallvec", - "windows-targets 0.48.5", -] - -[[package]] -name = "percent-encoding" -version = "2.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" - -[[package]] -name = "petgraph" -version = "0.6.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e1d3afd2628e69da2be385eb6f2fd57c8ac7977ceeff6dc166ff1657b0e386a9" -dependencies = [ - "fixedbitset", - "indexmap 2.2.2", -] - -[[package]] -name = "pin-project" -version = "1.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0302c4a0442c456bd56f841aee5c3bfd17967563f6fadc9ceb9f9c23cf3807e0" -dependencies = [ - "pin-project-internal", -] - -[[package]] -name = "pin-project-internal" -version = "1.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "266c042b60c9c76b8d53061e52b2e0d1116abc57cefc8c5cd671619a56ac3690" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.48", -] - -[[package]] -name = "pin-project-lite" -version = "0.2.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8afb450f006bf6385ca15ef45d71d2288452bc3683ce2e2cacc0d18e4be60b58" - -[[package]] -name = "pin-utils" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" - -[[package]] -name = "pmutil" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "52a40bc70c2c58040d2d8b167ba9a5ff59fc9dab7ad44771cfde3dcfde7a09c6" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.48", -] - -[[package]] -name = "proc-macro-crate" -version = "1.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f4c021e1093a56626774e81216a4ce732a735e5bad4868a03f3ed65ca0c3919" -dependencies = [ - "once_cell", - "toml_edit", -] - -[[package]] -name = "proc-macro2" -version = "1.0.78" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2422ad645d89c99f8f3e6b88a9fdeca7fabeac836b1002371c4367c8f984aae" -dependencies = [ - "unicode-ident", -] - -[[package]] -name = "quote" -version = "1.0.35" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" -dependencies = [ - "proc-macro2", -] - -[[package]] -name = "rand" -version = "0.8.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" -dependencies = [ - "rand_core", -] - -[[package]] -name = "rand_core" -version = "0.6.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" - -[[package]] -name = "redox_syscall" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4722d768eff46b75989dd134e5c353f0d6296e5aaa3132e776cbdb56be7731aa" -dependencies = [ - "bitflags 1.3.2", -] - -[[package]] -name = "regex" -version = "1.10.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b62dbe01f0b06f9d8dc7d49e05a0785f153b00b2c227856282f671e0318c9b15" -dependencies = [ - "aho-corasick", - "memchr", - "regex-automata", - "regex-syntax", -] - -[[package]] -name = "regex-automata" -version = "0.4.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5bb987efffd3c6d0d8f5f89510bb458559eab11e4f869acb20bf845e016259cd" -dependencies = [ - "aho-corasick", - "memchr", - "regex-syntax", -] - -[[package]] -name = "regex-syntax" -version = "0.8.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" - -[[package]] -name = "rustc-demangle" -version = "0.1.23" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" - -[[package]] -name = "rustc_version" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" -dependencies = [ - "semver 0.9.0", -] - -[[package]] -name = "rustc_version" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" -dependencies = [ - "semver 1.0.21", -] - -[[package]] -name = "rustix" -version = "0.38.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ea3e1a662af26cd7a3ba09c0297a31af215563ecf42817c98df621387f4e949" -dependencies = [ - "bitflags 2.4.2", - "errno", - "libc", - "linux-raw-sys", - "windows-sys 0.52.0", -] - -[[package]] -name = "rustversion" -version = "1.0.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ffc183a10b4478d04cbbbfc96d0873219d962dd5accaff2ffbd4ceb7df837f4" - -[[package]] -name = "ryu" -version = "1.0.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f98d2aa92eebf49b69786be48e4477826b256916e84a57ff2a4f21923b48eb4c" - -[[package]] -name = "scopeguard" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" - -[[package]] -name = "semver" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" -dependencies = [ - "semver-parser", -] - -[[package]] -name = "semver" -version = "1.0.21" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b97ed7a9823b74f99c7742f5336af7be5ecd3eeafcb1507d1fa93347b1d589b0" - -[[package]] -name = "semver-parser" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" - -[[package]] -name = "serde" -version = "1.0.196" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "870026e60fa08c69f064aa766c10f10b1d62db9ccd4d0abb206472bee0ce3b32" -dependencies = [ - "serde_derive", -] - -[[package]] -name = "serde_bytes" -version = "0.11.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b8497c313fd43ab992087548117643f6fcd935cbf36f176ffda0aacf9591734" -dependencies = [ - "serde", -] - -[[package]] -name = "serde_derive" -version = "1.0.196" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "33c85360c95e7d137454dc81d9a4ed2b8efd8fbe19cee57357b32b9771fccb67" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.48", -] - -[[package]] -name = "serde_json" -version = "1.0.113" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "69801b70b1c3dac963ecb03a364ba0ceda9cf60c71cfe475e99864759c8b8a79" -dependencies = [ - "indexmap 2.2.2", - "itoa", - "ryu", - "serde", -] - -[[package]] -name = "serde_v8" -version = "0.120.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a5424b4b41a92222abf9ddbdd78f59164f7594422ee4a61fc3704fc8ba608dc6" -dependencies = [ - "bytes", - "derive_more", - "num-bigint", - "serde", - "serde_bytes", - "smallvec", - "thiserror", - "v8", -] - -[[package]] -name = "signal-hook-registry" -version = "1.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8229b473baa5980ac72ef434c4415e70c4b5e71b423043adb4ba059f89c99a1" -dependencies = [ - "libc", -] - -[[package]] -name = "slab" -version = "0.4.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" -dependencies = [ - "autocfg", -] - -[[package]] -name = "smallvec" -version = "1.13.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6ecd384b10a64542d77071bd64bd7b231f4ed5940fba55e98c3de13824cf3d7" - -[[package]] -name = "socket2" -version = "0.5.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b5fac59a5cb5dd637972e5fca70daf0523c9067fcdc4842f053dae04a18f8e9" -dependencies = [ - "libc", - "windows-sys 0.48.0", -] - -[[package]] -name = "sourcemap" -version = "6.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e4cbf65ca7dc576cf50e21f8d0712d96d4fcfd797389744b7b222a85cdf5bd90" -dependencies = [ - "data-encoding", - "debugid", - "if_chain", - "rustc_version 0.2.3", - "serde", - "serde_json", - "unicode-id", - "url", -] - -[[package]] -name = "strsim" -version = "0.9.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6446ced80d6c486436db5c078dde11a9f73d42b57fb273121e160b84f63d894c" - -[[package]] -name = "strsim" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" - -[[package]] -name = "strum" -version = "0.25.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "290d54ea6f91c969195bdbcd7442c8c2a2ba87da8bf60a7ee86a235d4bc1e125" -dependencies = [ - "strum_macros", -] - -[[package]] -name = "strum_macros" -version = "0.25.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23dc1fa9ac9c169a78ba62f0b841814b7abae11bdd047b9c58f893439e309ea0" -dependencies = [ - "heck", - "proc-macro2", - "quote", - "rustversion", - "syn 2.0.48", -] - -[[package]] -name = "syn" -version = "1.0.109" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "syn" -version = "2.0.48" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "syn-mid" -version = "0.5.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fea305d57546cc8cd04feb14b62ec84bf17f50e3f7b12560d7bfa9265f39d9ed" -dependencies = [ - "proc-macro2", - "quote", - "syn 1.0.109", -] - -[[package]] -name = "tabbycat" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c45590f0f859197b4545be1b17b2bc3cc7bb075f7d1cc0ea1dc6521c0bf256a3" -dependencies = [ - "anyhow", - "derive_builder", - "regex", -] - -[[package]] -name = "thiserror" -version = "1.0.56" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d54378c645627613241d077a3a79db965db602882668f9136ac42af9ecb730ad" -dependencies = [ - "thiserror-impl", -] - -[[package]] -name = "thiserror-impl" -version = "1.0.56" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa0faa943b50f3db30a20aa7e265dbc66076993efed8463e8de414e5d06d3471" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.48", -] - -[[package]] -name = "tinyvec" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50" -dependencies = [ - "tinyvec_macros", -] - -[[package]] -name = "tinyvec_macros" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" - -[[package]] -name = "tokio" -version = "1.36.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61285f6515fa018fb2d1e46eb21223fff441ee8db5d0f1435e8ab4f5cdb80931" -dependencies = [ - "backtrace", - "bytes", - "libc", - "mio", - "num_cpus", - "parking_lot", - "pin-project-lite", - "signal-hook-registry", - "socket2", - "tokio-macros", - "windows-sys 0.48.0", -] - -[[package]] -name = "tokio-macros" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.48", -] - -[[package]] -name = "toml_datetime" -version = "0.6.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3550f4e9685620ac18a50ed434eb3aec30db8ba93b0287467bca5826ea25baf1" - -[[package]] -name = "toml_edit" -version = "0.19.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b5bb770da30e5cbfde35a2d7b9b8a2c4b8ef89548a7a6aeab5c9a576e3e7421" -dependencies = [ - "indexmap 2.2.2", - "toml_datetime", - "winnow", -] - -[[package]] -name = "unicode-bidi" -version = "0.3.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08f95100a766bf4f8f28f90d77e0a5461bbdb219042e7679bebe79004fed8d75" - -[[package]] -name = "unicode-id" -version = "0.3.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1b6def86329695390197b82c1e244a54a131ceb66c996f2088a3876e2ae083f" - -[[package]] -name = "unicode-ident" -version = "1.0.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" - -[[package]] -name = "unicode-normalization" -version = "0.1.22" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c5713f0fc4b5db668a2ac63cdb7bb4469d8c9fed047b1d0292cc7b0ce2ba921" -dependencies = [ - "tinyvec", -] - -[[package]] -name = "url" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "31e6302e3bb753d46e83516cae55ae196fc0c309407cf11ab35cc51a4c2a4633" -dependencies = [ - "form_urlencoded", - "idna", - "percent-encoding", - "serde", -] - -[[package]] -name = "utf8parse" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" - -[[package]] -name = "uuid" -version = "1.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f00cc9702ca12d3c81455259621e676d0f7251cec66a21e98fe2e9a37db93b2a" - -[[package]] -name = "v8" -version = "0.75.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a0e0cb10989bf856c2fdd1b6bed1bc6f96148230aa0c954634299125c1f64230" -dependencies = [ - "bitflags 1.3.2", - "fslock", - "once_cell", - "which", -] - -[[package]] -name = "version_check" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" - -[[package]] -name = "wasi" -version = "0.11.0+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" - -[[package]] -name = "which" -version = "4.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87ba24419a2078cd2b0f2ede2691b6c66d8e47836da3b6db8265ebad47afbfc7" -dependencies = [ - "either", - "home", - "once_cell", - "rustix", -] - -[[package]] -name = "winapi" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" -dependencies = [ - "winapi-i686-pc-windows-gnu", - "winapi-x86_64-pc-windows-gnu", -] - -[[package]] -name = "winapi-i686-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" - -[[package]] -name = "winapi-x86_64-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" - -[[package]] -name = "windows-sys" -version = "0.45.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0" -dependencies = [ - "windows-targets 0.42.2", -] - -[[package]] -name = "windows-sys" -version = "0.48.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" -dependencies = [ - "windows-targets 0.48.5", -] - -[[package]] -name = "windows-sys" -version = "0.52.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" -dependencies = [ - "windows-targets 0.52.0", -] - -[[package]] -name = "windows-targets" -version = "0.42.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e5180c00cd44c9b1c88adb3693291f1cd93605ded80c250a75d472756b4d071" -dependencies = [ - "windows_aarch64_gnullvm 0.42.2", - "windows_aarch64_msvc 0.42.2", - "windows_i686_gnu 0.42.2", - "windows_i686_msvc 0.42.2", - "windows_x86_64_gnu 0.42.2", - "windows_x86_64_gnullvm 0.42.2", - "windows_x86_64_msvc 0.42.2", -] - -[[package]] -name = "windows-targets" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" -dependencies = [ - "windows_aarch64_gnullvm 0.48.5", - "windows_aarch64_msvc 0.48.5", - "windows_i686_gnu 0.48.5", - "windows_i686_msvc 0.48.5", - "windows_x86_64_gnu 0.48.5", - "windows_x86_64_gnullvm 0.48.5", - "windows_x86_64_msvc 0.48.5", -] - -[[package]] -name = "windows-targets" -version = "0.52.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a18201040b24831fbb9e4eb208f8892e1f50a37feb53cc7ff887feb8f50e7cd" -dependencies = [ - "windows_aarch64_gnullvm 0.52.0", - "windows_aarch64_msvc 0.52.0", - "windows_i686_gnu 0.52.0", - "windows_i686_msvc 0.52.0", - "windows_x86_64_gnu 0.52.0", - "windows_x86_64_gnullvm 0.52.0", - "windows_x86_64_msvc 0.52.0", -] - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.42.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "597a5118570b68bc08d8d59125332c54f1ba9d9adeedeef5b99b02ba2b0698f8" - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.52.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb7764e35d4db8a7921e09562a0304bf2f93e0a51bfccee0bd0bb0b666b015ea" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.42.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e08e8864a60f06ef0d0ff4ba04124db8b0fb3be5776a5cd47641e942e58c4d43" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.52.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbaa0368d4f1d2aaefc55b6fcfee13f41544ddf36801e793edbbfd7d7df075ef" - -[[package]] -name = "windows_i686_gnu" -version = "0.42.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c61d927d8da41da96a81f029489353e68739737d3beca43145c8afec9a31a84f" - -[[package]] -name = "windows_i686_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" - -[[package]] -name = "windows_i686_gnu" -version = "0.52.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a28637cb1fa3560a16915793afb20081aba2c92ee8af57b4d5f28e4b3e7df313" - -[[package]] -name = "windows_i686_msvc" -version = "0.42.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44d840b6ec649f480a41c8d80f9c65108b92d89345dd94027bfe06ac444d1060" - -[[package]] -name = "windows_i686_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" - -[[package]] -name = "windows_i686_msvc" -version = "0.52.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ffe5e8e31046ce6230cc7215707b816e339ff4d4d67c65dffa206fd0f7aa7b9a" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.42.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8de912b8b8feb55c064867cf047dda097f92d51efad5b491dfb98f6bbb70cb36" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.52.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d6fa32db2bc4a2f5abeacf2b69f7992cd09dca97498da74a151a3132c26befd" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.42.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26d41b46a36d453748aedef1486d5c7a85db22e56aff34643984ea85514e94a3" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.52.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a657e1e9d3f514745a572a6846d3c7aa7dbe1658c056ed9c3344c4109a6949e" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.42.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9aec5da331524158c6d1a4ac0ab1541149c0b9505fde06423b02f5ef0106b9f0" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.52.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dff9641d1cd4be8d1a070daf9e3773c5f67e78b4d9d42263020c057706765c04" - -[[package]] -name = "winnow" -version = "0.5.39" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5389a154b01683d28c77f8f68f49dea75f0a4da32557a58f68ee51ebba472d29" -dependencies = [ - "memchr", -] - -[[package]] -name = "zerocopy" -version = "0.7.32" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "74d4d3961e53fa4c9a25a8637fc2bfaf2595b3d3ae34875568a5cf64787716be" -dependencies = [ - "zerocopy-derive", -] - -[[package]] -name = "zerocopy-derive" -version = "0.7.32" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ce1b18ccd8e73a9321186f97e46f9f04b778851177567b1975109d26a08d2a6" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.48", -] - -[[package]] -name = "zk-regex-apis" -version = "1.1.7" -dependencies = [ - "fancy-regex", - "itertools", - "neon", - "serde", - "serde_json", - "thiserror", -] - -[[package]] -name = "zk-regex-compiler" -version = "1.0.9" -dependencies = [ - "ahash", - "clap", - "fancy-regex", - "graph-cycles", - "itertools", - "js-sandbox", - "neon", - "petgraph", - "serde", - "serde_json", - "tabbycat", - "thiserror", -] diff --git a/babel.config.js b/babel.config.js index df17070..4d0aa62 100644 --- a/babel.config.js +++ b/babel.config.js @@ -1,11 +1,8 @@ module.exports = { - presets: [ - ['@babel/preset-env', { targets: { node: 'current' } }], - '@babel/preset-typescript', - ['@babel/preset-react', { "runtime": "automatic" }], - ['jest'] - ], - plugins: [ - '@babel/plugin-transform-modules-commonjs', - ] -}; \ No newline at end of file + presets: [ + ["@babel/preset-env", { targets: { node: "current" } }], + ["@babel/preset-react", { runtime: "automatic" }], + ["jest"], + ], + plugins: ["@babel/plugin-transform-modules-commonjs"], +}; diff --git a/package.json b/package.json index 318c5b2..b5fb03a 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,7 @@ "install": "yarn workspaces -pt run install", "build": "yarn workspaces -pt run build", "postinstall": "cargo install --path ./packages/compiler", - "test": "npx tsc && yarn workspaces -pt run test", + "test": "yarn workspaces -pt run test", "upload-binary": "yarn workspaces -pt run upload-binary" }, "repository": { @@ -41,17 +41,14 @@ "@babel/plugin-transform-modules-commonjs": "^7.22.15", "@babel/preset-env": "^7.22.2", "@babel/preset-react": "^7.22.0", - "@babel/preset-typescript": "^7.21.5", "@types/jest": "^29.5.4", "babel-jest": "^29.5.0", "babel-preset-jest": "^29.5.0", "jest": "^29.5.0", "prettier": "^3.0.0", - "prettier-plugin-solidity": "^1.1.3", - "ts-jest": "^29.1.1", - "typescript": "^4.5.4" + "prettier-plugin-solidity": "^1.1.3" }, "engines": { "yarn": "^1.22.0" } -} \ No newline at end of file +} diff --git a/packages/apis/src/decomposed_defs/body_hash.json b/packages/apis/src/decomposed_defs/body_hash.json index 6ec2710..f53b8a5 100644 --- a/packages/apis/src/decomposed_defs/body_hash.json +++ b/packages/apis/src/decomposed_defs/body_hash.json @@ -1,20 +1,20 @@ { - "parts": [ - { - "is_public": false, - "regex_def": "((\r\n)|^)dkim-signature:" - }, - { - "is_public": false, - "regex_def": "((a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z)+=[^;]+; )+bh=" - }, - { - "is_public": true, - "regex_def": "(a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z|A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z|0|1|2|3|4|5|6|7|8|9|\\+|/|=)+" - }, - { - "is_public": false, - "regex_def": ";" - } - ] -} \ No newline at end of file + "parts": [ + { + "is_public": false, + "regex_def": "((\r\n)|^)dkim-signature:" + }, + { + "is_public": false, + "regex_def": "([a-z]+=[^;]+; )+bh=" + }, + { + "is_public": true, + "regex_def": "[a-zA-Z0-9+/=]+" + }, + { + "is_public": false, + "regex_def": ";" + } + ] +} diff --git a/packages/apis/src/decomposed_defs/email_addr.json b/packages/apis/src/decomposed_defs/email_addr.json index c590439..0842165 100644 --- a/packages/apis/src/decomposed_defs/email_addr.json +++ b/packages/apis/src/decomposed_defs/email_addr.json @@ -1,8 +1,8 @@ { - "parts": [ - { - "is_public": true, - "regex_def": "(a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z|A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z|0|1|2|3|4|5|6|7|8|9|!|#|$|%|&|'|\\*|\\+|-|/|=|\\?|^|_|`|{|\\||}|~|\\.)+@(a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z|A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z|0|1|2|3|4|5|6|7|8|9|\\.|-)+" - } - ] -} \ No newline at end of file + "parts": [ + { + "is_public": true, + "regex_def": "[A-Za-z0-9!#$%&'*+=?^_`{|}~.]+@[A-Za-z0-9.-]+" + } + ] +} diff --git a/packages/apis/src/decomposed_defs/email_addr_with_name.json b/packages/apis/src/decomposed_defs/email_addr_with_name.json index ecd2ad4..31607a3 100644 --- a/packages/apis/src/decomposed_defs/email_addr_with_name.json +++ b/packages/apis/src/decomposed_defs/email_addr_with_name.json @@ -1,16 +1,16 @@ { - "parts": [ - { - "is_public": false, - "regex_def": "[^\r\n]+<" - }, - { - "is_public": true, - "regex_def": "(a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z|A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z|0|1|2|3|4|5|6|7|8|9|!|#|$|%|&|'|\\*|\\+|-|/|=|\\?|^|_|`|{|\\||}|~|\\.)+@(a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z|A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z|0|1|2|3|4|5|6|7|8|9|_|\\.|-)+" - }, - { - "is_public": false, - "regex_def": ">" - } - ] -} \ No newline at end of file + "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": ">" + } + ] +} diff --git a/packages/apis/src/decomposed_defs/email_domain.json b/packages/apis/src/decomposed_defs/email_domain.json index fb60f82..82f0330 100644 --- a/packages/apis/src/decomposed_defs/email_domain.json +++ b/packages/apis/src/decomposed_defs/email_domain.json @@ -1,16 +1,16 @@ { - "parts": [ - { - "is_public": false, - "regex_def": "(a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z|A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z|0|1|2|3|4|5|6|7|8|9|!|#|$|%|&|'|\\*|\\+|-|/|=|\\?|^|_|`|{|\\||}|~|\\.)+" - }, - { - "is_public": false, - "regex_def": "@" - }, - { - "is_public": true, - "regex_def": "(a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z|A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z|0|1|2|3|4|5|6|7|8|9|\\.|-)+" - } - ] -} \ No newline at end of file + "parts": [ + { + "is_public": false, + "regex_def": "[A-Za-z0-9!#$%&'*+-/=?^_`{\\|}~\\.]+" + }, + { + "is_public": false, + "regex_def": "@" + }, + { + "is_public": true, + "regex_def": "[A-Za-z0-9\\.-]+" + } + ] +} diff --git a/packages/apis/src/decomposed_defs/from_addr.json b/packages/apis/src/decomposed_defs/from_addr.json index 584c66c..7fdc28e 100644 --- a/packages/apis/src/decomposed_defs/from_addr.json +++ b/packages/apis/src/decomposed_defs/from_addr.json @@ -1,20 +1,20 @@ { - "parts": [ - { - "is_public": false, - "regex_def": "((\r\n)|^)from:" - }, - { - "is_public": false, - "regex_def": "([^\r\n]+<)?" - }, - { - "is_public": true, - "regex_def": "(a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z|A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z|0|1|2|3|4|5|6|7|8|9|!|#|$|%|&|'|\\*|\\+|-|/|=|\\?|^|_|`|{|\\||}|~|\\.)+@(a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z|A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z|0|1|2|3|4|5|6|7|8|9|_|\\.|-)+" - }, - { - "is_public": false, - "regex_def": ">?\r\n" - } - ] -} \ No newline at end of file + "parts": [ + { + "is_public": false, + "regex_def": "((\r\n)|^)from:" + }, + { + "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" + } + ] +} diff --git a/packages/apis/src/decomposed_defs/from_all.json b/packages/apis/src/decomposed_defs/from_all.json index 3ec0f84..a774997 100644 --- a/packages/apis/src/decomposed_defs/from_all.json +++ b/packages/apis/src/decomposed_defs/from_all.json @@ -1,16 +1,16 @@ { - "parts": [ - { - "is_public": false, - "regex_def": "((\r\n)|^)from:" - }, - { - "is_public": true, - "regex_def": "[^\r\n]+" - }, - { - "is_public": false, - "regex_def": "\r\n" - } - ] -} \ No newline at end of file + "parts": [ + { + "is_public": false, + "regex_def": "((\r\n)|^)from:" + }, + { + "is_public": true, + "regex_def": "[^\r\n]+" + }, + { + "is_public": false, + "regex_def": "\r\n" + } + ] +} diff --git a/packages/apis/src/decomposed_defs/message_id.json b/packages/apis/src/decomposed_defs/message_id.json index c207af1..f71f0ee 100644 --- a/packages/apis/src/decomposed_defs/message_id.json +++ b/packages/apis/src/decomposed_defs/message_id.json @@ -1,16 +1,16 @@ { - "parts": [ - { - "is_public": false, - "regex_def": "((\r\n)|^)message-id:" - }, - { - "is_public": true, - "regex_def": "<(=|@|\\.|\\+|_|-|a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z|A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z|0|1|2|3|4|5|6|7|8|9)+>" - }, - { - "is_public": false, - "regex_def": "\r\n" - } - ] -} \ No newline at end of file + "parts": [ + { + "is_public": false, + "regex_def": "((\r\n)|^)message-id:" + }, + { + "is_public": true, + "regex_def": "<[A-Za-z0-9=@\\.\\+_-]+>" + }, + { + "is_public": false, + "regex_def": "\r\n" + } + ] +} diff --git a/packages/apis/src/decomposed_defs/subject_all.json b/packages/apis/src/decomposed_defs/subject_all.json index fd00df4..ed7d761 100644 --- a/packages/apis/src/decomposed_defs/subject_all.json +++ b/packages/apis/src/decomposed_defs/subject_all.json @@ -1,16 +1,16 @@ { - "parts": [ - { - "is_public": false, - "regex_def": "((\r\n)|^)subject:" - }, - { - "is_public": true, - "regex_def": "[^\r\n]+" - }, - { - "is_public": false, - "regex_def": "\r\n" - } - ] -} \ No newline at end of file + "parts": [ + { + "is_public": false, + "regex_def": "((\r\n)|^)subject:" + }, + { + "is_public": true, + "regex_def": "[^\r\n]+" + }, + { + "is_public": false, + "regex_def": "\r\n" + } + ] +} diff --git a/packages/apis/src/decomposed_defs/timestamp.json b/packages/apis/src/decomposed_defs/timestamp.json index 10e4ffb..4e2895e 100644 --- a/packages/apis/src/decomposed_defs/timestamp.json +++ b/packages/apis/src/decomposed_defs/timestamp.json @@ -1,20 +1,20 @@ { - "parts": [ - { - "is_public": false, - "regex_def": "((\r\n)|^)dkim-signature:" - }, - { - "is_public": false, - "regex_def": "((a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z)+=[^;]+; )+t=" - }, - { - "is_public": true, - "regex_def": "(0|1|2|3|4|5|6|7|8|9)+" - }, - { - "is_public": false, - "regex_def": ";" - } - ] -} \ No newline at end of file + "parts": [ + { + "is_public": false, + "regex_def": "((\r\n)|^)dkim-signature:" + }, + { + "is_public": false, + "regex_def": "([a-z]+=[^;]+; )+t=" + }, + { + "is_public": true, + "regex_def": "[0-9]+" + }, + { + "is_public": false, + "regex_def": ";" + } + ] +} diff --git a/packages/apis/src/decomposed_defs/to_addr.json b/packages/apis/src/decomposed_defs/to_addr.json index f7e9a22..43384d7 100644 --- a/packages/apis/src/decomposed_defs/to_addr.json +++ b/packages/apis/src/decomposed_defs/to_addr.json @@ -1,20 +1,20 @@ { - "parts": [ - { - "is_public": false, - "regex_def": "((\r\n)|^)to:" - }, - { - "is_public": false, - "regex_def": "([^\r\n]+<)?" - }, - { - "is_public": true, - "regex_def": "(a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z|A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z|0|1|2|3|4|5|6|7|8|9|!|#|$|%|&|'|\\*|\\+|-|/|=|\\?|^|_|`|{|\\||}|~|\\.)+@(a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z|A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z|0|1|2|3|4|5|6|7|8|9|_|\\.|-)+" - }, - { - "is_public": false, - "regex_def": ">?\r\n" - } - ] -} \ No newline at end of file + "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" + } + ] +} diff --git a/packages/apis/src/decomposed_defs/to_all.json b/packages/apis/src/decomposed_defs/to_all.json index f601fbd..eeb616f 100644 --- a/packages/apis/src/decomposed_defs/to_all.json +++ b/packages/apis/src/decomposed_defs/to_all.json @@ -1,16 +1,16 @@ { - "parts": [ - { - "is_public": false, - "regex_def": "((\r\n)|^)to:" - }, - { - "is_public": true, - "regex_def": "[^\r\n]+" - }, - { - "is_public": false, - "regex_def": "\r\n" - } - ] -} \ No newline at end of file + "parts": [ + { + "is_public": false, + "regex_def": "((\r\n)|^)to:" + }, + { + "is_public": true, + "regex_def": "[^\r\n]+" + }, + { + "is_public": false, + "regex_def": "\r\n" + } + ] +} diff --git a/packages/circom/circuits/common/body_hash.json b/packages/circom/circuits/common/body_hash.json index 6ec2710..f53b8a5 100644 --- a/packages/circom/circuits/common/body_hash.json +++ b/packages/circom/circuits/common/body_hash.json @@ -1,20 +1,20 @@ { - "parts": [ - { - "is_public": false, - "regex_def": "((\r\n)|^)dkim-signature:" - }, - { - "is_public": false, - "regex_def": "((a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z)+=[^;]+; )+bh=" - }, - { - "is_public": true, - "regex_def": "(a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z|A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z|0|1|2|3|4|5|6|7|8|9|\\+|/|=)+" - }, - { - "is_public": false, - "regex_def": ";" - } - ] -} \ No newline at end of file + "parts": [ + { + "is_public": false, + "regex_def": "((\r\n)|^)dkim-signature:" + }, + { + "is_public": false, + "regex_def": "([a-z]+=[^;]+; )+bh=" + }, + { + "is_public": true, + "regex_def": "[a-zA-Z0-9+/=]+" + }, + { + "is_public": false, + "regex_def": ";" + } + ] +} diff --git a/packages/circom/circuits/common/body_hash_regex.circom b/packages/circom/circuits/common/body_hash_regex.circom index 5cd99be..1fda907 100644 --- a/packages/circom/circuits/common/body_hash_regex.circom +++ b/packages/circom/circuits/common/body_hash_regex.circom @@ -2,7 +2,7 @@ pragma circom 2.1.5; include "@zk-email/zk-regex-circom/circuits/regex_helpers.circom"; -// regex: (( \n)|^)dkim-signature:((a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z)+=[^;]+; )+bh=(a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z|A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z|0|1|2|3|4|5|6|7|8|9|\+|/|=)+; +// regex: ((\r\n)|^)dkim-signature:([a-z]+=[^;]+; )+bh=[a-zA-Z0-9+/=]+; template BodyHashRegex(msg_bytes) { signal input msg[msg_bytes]; signal output out; @@ -14,504 +14,820 @@ template BodyHashRegex(msg_bytes) { in[i+1] <== msg[i]; } - component eq[48][num_bytes]; - component lt[16][num_bytes]; - component and[47][num_bytes]; - component multi_or[12][num_bytes]; - signal states[num_bytes+1][28]; + component eq[89][num_bytes]; + component lt[24][num_bytes]; + component and[76][num_bytes]; + component multi_or[20][num_bytes]; + signal states[num_bytes+1][35]; component state_changed[num_bytes]; states[0][0] <== 1; - for (var i = 1; i < 28; i++) { + for (var i = 1; i < 35; i++) { states[0][i] <== 0; } for (var i = 0; i < num_bytes; i++) { - state_changed[i] = MultiOR(27); - lt[0][i] = LessEqThan(8); - lt[0][i].in[0] <== 97; - lt[0][i].in[1] <== in[i]; - lt[1][i] = LessEqThan(8); - lt[1][i].in[0] <== in[i]; - lt[1][i].in[1] <== 122; - and[0][i] = AND(); - and[0][i].a <== lt[0][i].out; - and[0][i].b <== lt[1][i].out; - and[1][i] = AND(); - and[1][i].a <== states[i][1]; - and[1][i].b <== and[0][i].out; - lt[2][i] = LessEqThan(8); - lt[2][i].in[0] <== 99; - 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; + state_changed[i] = MultiOR(34); eq[0][i] = IsEqual(); eq[0][i].in[0] <== in[i]; - eq[0][i].in[1] <== 97; - and[3][i] = AND(); - and[3][i].a <== states[i][7]; + eq[0][i].in[1] <== 100; + and[0][i] = AND(); + and[0][i].a <== states[i][0]; + and[0][i].b <== eq[0][i].out; + and[1][i] = AND(); + and[1][i].a <== states[i][4]; + and[1][i].b <== eq[0][i].out; multi_or[0][i] = MultiOR(2); - multi_or[0][i].in[0] <== and[2][i].out; - multi_or[0][i].in[1] <== eq[0][i].out; - and[3][i].b <== multi_or[0][i].out; - and[4][i] = AND(); - and[4][i].a <== states[i][25]; - and[4][i].b <== and[0][i].out; - lt[4][i] = LessEqThan(8); - lt[4][i].in[0] <== 105; - lt[4][i].in[1] <== in[i]; - lt[5][i] = LessEqThan(8); - lt[5][i].in[0] <== in[i]; - lt[5][i].in[1] <== 122; - and[5][i] = AND(); - and[5][i].a <== lt[4][i].out; - and[5][i].b <== lt[5][i].out; + multi_or[0][i].in[0] <== and[0][i].out; + multi_or[0][i].in[1] <== and[1][i].out; + states[i+1][1] <== multi_or[0][i].out; + state_changed[i].in[0] <== states[i+1][1]; eq[1][i] = IsEqual(); eq[1][i].in[0] <== in[i]; - eq[1][i].in[1] <== 98; + eq[1][i].in[1] <== 13; + and[2][i] = AND(); + and[2][i].a <== states[i][0]; + and[2][i].b <== eq[1][i].out; + states[i+1][2] <== and[2][i].out; + state_changed[i].in[1] <== states[i+1][2]; eq[2][i] = IsEqual(); eq[2][i].in[0] <== in[i]; - eq[2][i].in[1] <== 99; + eq[2][i].in[1] <== 107; + and[3][i] = AND(); + and[3][i].a <== states[i][1]; + and[3][i].b <== eq[2][i].out; + states[i+1][3] <== and[3][i].out; + state_changed[i].in[2] <== states[i+1][3]; eq[3][i] = IsEqual(); eq[3][i].in[0] <== in[i]; - eq[3][i].in[1] <== 100; + eq[3][i].in[1] <== 10; + and[4][i] = AND(); + and[4][i].a <== states[i][2]; + and[4][i].b <== eq[3][i].out; + states[i+1][4] <== and[4][i].out; + state_changed[i].in[3] <== states[i+1][4]; eq[4][i] = IsEqual(); eq[4][i].in[0] <== in[i]; - eq[4][i].in[1] <== 101; + eq[4][i].in[1] <== 105; + and[5][i] = AND(); + and[5][i].a <== states[i][3]; + and[5][i].b <== eq[4][i].out; + states[i+1][5] <== and[5][i].out; + state_changed[i].in[4] <== states[i+1][5]; eq[5][i] = IsEqual(); eq[5][i].in[0] <== in[i]; - eq[5][i].in[1] <== 102; + eq[5][i].in[1] <== 109; + and[6][i] = AND(); + and[6][i].a <== states[i][5]; + and[6][i].b <== eq[5][i].out; + states[i+1][6] <== and[6][i].out; + state_changed[i].in[5] <== states[i+1][6]; eq[6][i] = IsEqual(); eq[6][i].in[0] <== in[i]; - eq[6][i].in[1] <== 103; - and[6][i] = AND(); - and[6][i].a <== states[i][26]; - multi_or[1][i] = MultiOR(8); - multi_or[1][i].in[0] <== and[5][i].out; - multi_or[1][i].in[1] <== eq[0][i].out; - multi_or[1][i].in[2] <== eq[1][i].out; - multi_or[1][i].in[3] <== eq[2][i].out; - multi_or[1][i].in[4] <== eq[3][i].out; - multi_or[1][i].in[5] <== eq[4][i].out; - multi_or[1][i].in[6] <== eq[5][i].out; - multi_or[1][i].in[7] <== eq[6][i].out; - and[6][i].b <== multi_or[1][i].out; + eq[6][i].in[1] <== 45; and[7][i] = AND(); - and[7][i].a <== states[i][27]; - and[7][i].b <== and[0][i].out; - multi_or[2][i] = MultiOR(5); - multi_or[2][i].in[0] <== and[1][i].out; - multi_or[2][i].in[1] <== and[3][i].out; - multi_or[2][i].in[2] <== and[4][i].out; - multi_or[2][i].in[3] <== and[6][i].out; - multi_or[2][i].in[4] <== and[7][i].out; - states[i+1][1] <== multi_or[2][i].out; - state_changed[i].in[0] <== states[i+1][1]; - lt[6][i] = LessEqThan(8); - lt[6][i].in[0] <== 0; - lt[6][i].in[1] <== in[i]; - lt[7][i] = LessEqThan(8); - lt[7][i].in[0] <== in[i]; - lt[7][i].in[1] <== 58; - and[8][i] = AND(); - and[8][i].a <== lt[6][i].out; - and[8][i].b <== lt[7][i].out; - lt[8][i] = LessEqThan(8); - lt[8][i].in[0] <== 60; - lt[8][i].in[1] <== in[i]; - lt[9][i] = LessEqThan(8); - lt[9][i].in[0] <== in[i]; - lt[9][i].in[1] <== 254; - and[9][i] = AND(); - and[9][i].a <== lt[8][i].out; - and[9][i].b <== lt[9][i].out; - and[10][i] = AND(); - and[10][i].a <== states[i][2]; - 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; - and[10][i].b <== multi_or[3][i].out; - lt[10][i] = LessEqThan(8); - lt[10][i].in[0] <== 0; - lt[10][i].in[1] <== in[i]; - lt[11][i] = LessEqThan(8); - lt[11][i].in[0] <== in[i]; - lt[11][i].in[1] <== 42; - and[11][i] = AND(); - and[11][i].a <== lt[10][i].out; - and[11][i].b <== lt[11][i].out; - lt[12][i] = LessEqThan(8); - lt[12][i].in[0] <== 123; - lt[12][i].in[1] <== in[i]; - lt[13][i] = LessEqThan(8); - lt[13][i].in[0] <== in[i]; - lt[13][i].in[1] <== 254; - and[12][i] = AND(); - and[12][i].a <== lt[12][i].out; - and[12][i].b <== lt[13][i].out; + and[7][i].a <== states[i][6]; + and[7][i].b <== eq[6][i].out; + states[i+1][7] <== and[7][i].out; + state_changed[i].in[6] <== states[i+1][7]; eq[7][i] = IsEqual(); eq[7][i].in[0] <== in[i]; - eq[7][i].in[1] <== 44; + eq[7][i].in[1] <== 115; + and[8][i] = AND(); + and[8][i].a <== states[i][7]; + and[8][i].b <== eq[7][i].out; + states[i+1][8] <== and[8][i].out; + state_changed[i].in[7] <== states[i+1][8]; + and[9][i] = AND(); + and[9][i].a <== states[i][8]; + and[9][i].b <== eq[4][i].out; + states[i+1][9] <== and[9][i].out; + state_changed[i].in[8] <== states[i+1][9]; eq[8][i] = IsEqual(); eq[8][i].in[0] <== in[i]; - eq[8][i].in[1] <== 45; + eq[8][i].in[1] <== 103; + and[10][i] = AND(); + and[10][i].a <== states[i][9]; + and[10][i].b <== eq[8][i].out; + states[i+1][10] <== and[10][i].out; + state_changed[i].in[9] <== states[i+1][10]; eq[9][i] = IsEqual(); eq[9][i].in[0] <== in[i]; - eq[9][i].in[1] <== 46; + eq[9][i].in[1] <== 110; + and[11][i] = AND(); + and[11][i].a <== states[i][10]; + and[11][i].b <== eq[9][i].out; + states[i+1][11] <== and[11][i].out; + state_changed[i].in[10] <== states[i+1][11]; eq[10][i] = IsEqual(); eq[10][i].in[0] <== in[i]; - eq[10][i].in[1] <== 58; + eq[10][i].in[1] <== 97; + and[12][i] = AND(); + and[12][i].a <== states[i][11]; + and[12][i].b <== eq[10][i].out; + states[i+1][12] <== and[12][i].out; + state_changed[i].in[11] <== states[i+1][12]; eq[11][i] = IsEqual(); eq[11][i].in[0] <== in[i]; - eq[11][i].in[1] <== 60; + eq[11][i].in[1] <== 116; + and[13][i] = AND(); + and[13][i].a <== states[i][12]; + and[13][i].b <== eq[11][i].out; + states[i+1][13] <== and[13][i].out; + state_changed[i].in[12] <== states[i+1][13]; eq[12][i] = IsEqual(); eq[12][i].in[0] <== in[i]; - eq[12][i].in[1] <== 62; + eq[12][i].in[1] <== 117; + and[14][i] = AND(); + and[14][i].a <== states[i][13]; + and[14][i].b <== eq[12][i].out; + states[i+1][14] <== and[14][i].out; + state_changed[i].in[13] <== states[i+1][14]; eq[13][i] = IsEqual(); eq[13][i].in[0] <== in[i]; - eq[13][i].in[1] <== 63; + eq[13][i].in[1] <== 114; + and[15][i] = AND(); + and[15][i].a <== states[i][14]; + and[15][i].b <== eq[13][i].out; + states[i+1][15] <== and[15][i].out; + state_changed[i].in[14] <== states[i+1][15]; eq[14][i] = IsEqual(); eq[14][i].in[0] <== in[i]; - eq[14][i].in[1] <== 64; + eq[14][i].in[1] <== 101; + and[16][i] = AND(); + and[16][i].a <== states[i][15]; + and[16][i].b <== eq[14][i].out; + states[i+1][16] <== and[16][i].out; + state_changed[i].in[15] <== states[i+1][16]; eq[15][i] = IsEqual(); eq[15][i].in[0] <== in[i]; - eq[15][i].in[1] <== 91; + eq[15][i].in[1] <== 58; + and[17][i] = AND(); + and[17][i].a <== states[i][16]; + and[17][i].b <== eq[15][i].out; + states[i+1][17] <== and[17][i].out; + state_changed[i].in[16] <== states[i+1][17]; + lt[0][i] = LessEqThan(8); + lt[0][i].in[0] <== 97; + lt[0][i].in[1] <== in[i]; + lt[1][i] = LessEqThan(8); + lt[1][i].in[0] <== in[i]; + lt[1][i].in[1] <== 122; + and[18][i] = AND(); + and[18][i].a <== lt[0][i].out; + and[18][i].b <== lt[1][i].out; + and[19][i] = AND(); + and[19][i].a <== states[i][17]; + and[19][i].b <== and[18][i].out; + and[20][i] = AND(); + and[20][i].a <== states[i][18]; + and[20][i].b <== and[18][i].out; + lt[2][i] = LessEqThan(8); + lt[2][i].in[0] <== 99; + 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[21][i] = AND(); + and[21][i].a <== lt[2][i].out; + and[21][i].b <== lt[3][i].out; + and[22][i] = AND(); + and[22][i].a <== states[i][29]; + multi_or[1][i] = MultiOR(2); + multi_or[1][i].in[0] <== and[21][i].out; + multi_or[1][i].in[1] <== eq[10][i].out; + and[22][i].b <== multi_or[1][i].out; + lt[4][i] = LessEqThan(8); + lt[4][i].in[0] <== 105; + lt[4][i].in[1] <== in[i]; + lt[5][i] = LessEqThan(8); + lt[5][i].in[0] <== in[i]; + lt[5][i].in[1] <== 122; + and[23][i] = AND(); + and[23][i].a <== lt[4][i].out; + and[23][i].b <== lt[5][i].out; eq[16][i] = IsEqual(); eq[16][i].in[0] <== in[i]; - eq[16][i].in[1] <== 92; + eq[16][i].in[1] <== 98; eq[17][i] = IsEqual(); eq[17][i].in[0] <== in[i]; - eq[17][i].in[1] <== 93; + eq[17][i].in[1] <== 99; eq[18][i] = IsEqual(); eq[18][i].in[0] <== in[i]; - eq[18][i].in[1] <== 94; + eq[18][i].in[1] <== 102; + and[24][i] = AND(); + and[24][i].a <== states[i][30]; + multi_or[2][i] = MultiOR(8); + multi_or[2][i].in[0] <== and[23][i].out; + multi_or[2][i].in[1] <== eq[10][i].out; + multi_or[2][i].in[2] <== eq[16][i].out; + multi_or[2][i].in[3] <== eq[17][i].out; + multi_or[2][i].in[4] <== eq[0][i].out; + multi_or[2][i].in[5] <== eq[14][i].out; + multi_or[2][i].in[6] <== eq[18][i].out; + multi_or[2][i].in[7] <== eq[8][i].out; + and[24][i].b <== multi_or[2][i].out; + and[25][i] = AND(); + and[25][i].a <== states[i][31]; + and[25][i].b <== and[18][i].out; + multi_or[3][i] = MultiOR(5); + multi_or[3][i].in[0] <== and[19][i].out; + multi_or[3][i].in[1] <== and[20][i].out; + multi_or[3][i].in[2] <== and[22][i].out; + multi_or[3][i].in[3] <== and[24][i].out; + multi_or[3][i].in[4] <== and[25][i].out; + states[i+1][18] <== multi_or[3][i].out; + state_changed[i].in[17] <== states[i+1][18]; eq[19][i] = IsEqual(); eq[19][i].in[0] <== in[i]; - eq[19][i].in[1] <== 95; + eq[19][i].in[1] <== 61; + and[26][i] = AND(); + and[26][i].a <== states[i][18]; + and[26][i].b <== eq[19][i].out; + and[27][i] = AND(); + and[27][i].a <== states[i][30]; + and[27][i].b <== eq[19][i].out; + multi_or[4][i] = MultiOR(2); + multi_or[4][i].in[0] <== and[26][i].out; + multi_or[4][i].in[1] <== and[27][i].out; + states[i+1][19] <== multi_or[4][i].out; + state_changed[i].in[18] <== states[i+1][19]; + lt[6][i] = LessEqThan(8); + lt[6][i].in[0] <== 0; + lt[6][i].in[1] <== in[i]; + lt[7][i] = LessEqThan(8); + lt[7][i].in[0] <== in[i]; + lt[7][i].in[1] <== 58; + and[28][i] = AND(); + and[28][i].a <== lt[6][i].out; + and[28][i].b <== lt[7][i].out; + lt[8][i] = LessEqThan(8); + lt[8][i].in[0] <== 60; + 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[29][i] = AND(); + and[29][i].a <== lt[8][i].out; + and[29][i].b <== lt[9][i].out; + and[30][i] = AND(); + and[30][i].a <== states[i][19]; + multi_or[5][i] = MultiOR(2); + multi_or[5][i].in[0] <== and[28][i].out; + multi_or[5][i].in[1] <== and[29][i].out; + and[30][i].b <== multi_or[5][i].out; + and[31][i] = AND(); + and[31][i].a <== states[i][20]; + and[31][i].b <== multi_or[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] <== 191; + and[32][i] = AND(); + and[32][i].a <== lt[10][i].out; + and[32][i].b <== lt[11][i].out; + and[33][i] = AND(); + and[33][i].a <== states[i][21]; + and[33][i].b <== and[32][i].out; + lt[12][i] = LessEqThan(8); + lt[12][i].in[0] <== 0; + lt[12][i].in[1] <== in[i]; + lt[13][i] = LessEqThan(8); + lt[13][i].in[0] <== in[i]; + lt[13][i].in[1] <== 42; + and[34][i] = AND(); + and[34][i].a <== lt[12][i].out; + and[34][i].b <== lt[13][i].out; eq[20][i] = IsEqual(); eq[20][i].in[0] <== in[i]; - eq[20][i].in[1] <== 96; - and[13][i] = AND(); - and[13][i].a <== states[i][3]; - multi_or[4][i] = MultiOR(16); - multi_or[4][i].in[0] <== and[11][i].out; - multi_or[4][i].in[1] <== and[12][i].out; - multi_or[4][i].in[2] <== eq[7][i].out; - multi_or[4][i].in[3] <== eq[8][i].out; - multi_or[4][i].in[4] <== eq[9][i].out; - multi_or[4][i].in[5] <== eq[10][i].out; - multi_or[4][i].in[6] <== eq[11][i].out; - multi_or[4][i].in[7] <== eq[12][i].out; - multi_or[4][i].in[8] <== eq[13][i].out; - multi_or[4][i].in[9] <== eq[14][i].out; - multi_or[4][i].in[10] <== eq[15][i].out; - multi_or[4][i].in[11] <== eq[16][i].out; - multi_or[4][i].in[12] <== eq[17][i].out; - multi_or[4][i].in[13] <== eq[18][i].out; - multi_or[4][i].in[14] <== eq[19][i].out; - multi_or[4][i].in[15] <== eq[20][i].out; - and[13][i].b <== multi_or[4][i].out; - and[14][i] = AND(); - and[14][i].a <== states[i][5]; - and[14][i].b <== multi_or[4][i].out; - and[15][i] = AND(); - and[15][i].a <== states[i][6]; - and[15][i].b <== multi_or[3][i].out; - multi_or[5][i] = MultiOR(4); - multi_or[5][i].in[0] <== and[10][i].out; - multi_or[5][i].in[1] <== and[13][i].out; - multi_or[5][i].in[2] <== and[14][i].out; - multi_or[5][i].in[3] <== and[15][i].out; - states[i+1][2] <== multi_or[5][i].out; - state_changed[i].in[1] <== states[i+1][2]; + eq[20][i].in[1] <== 44; eq[21][i] = IsEqual(); eq[21][i].in[0] <== in[i]; - eq[21][i].in[1] <== 61; - and[16][i] = AND(); - and[16][i].a <== states[i][27]; - and[16][i].b <== eq[21][i].out; - states[i+1][3] <== and[16][i].out; - state_changed[i].in[2] <== states[i+1][3]; + eq[21][i].in[1] <== 46; eq[22][i] = IsEqual(); eq[22][i].in[0] <== in[i]; - eq[22][i].in[1] <== 59; - and[17][i] = AND(); - and[17][i].a <== states[i][2]; - and[17][i].b <== eq[22][i].out; - states[i+1][4] <== and[17][i].out; - state_changed[i].in[3] <== states[i+1][4]; - lt[14][i] = LessEqThan(8); - lt[14][i].in[0] <== 65; - lt[14][i].in[1] <== in[i]; - lt[15][i] = LessEqThan(8); - lt[15][i].in[0] <== in[i]; - lt[15][i].in[1] <== 90; - and[18][i] = AND(); - and[18][i].a <== lt[14][i].out; - and[18][i].b <== lt[15][i].out; + eq[22][i].in[1] <== 60; eq[23][i] = IsEqual(); eq[23][i].in[0] <== in[i]; - eq[23][i].in[1] <== 43; + eq[23][i].in[1] <== 62; eq[24][i] = IsEqual(); eq[24][i].in[0] <== in[i]; - eq[24][i].in[1] <== 47; + eq[24][i].in[1] <== 63; eq[25][i] = IsEqual(); eq[25][i].in[0] <== in[i]; - eq[25][i].in[1] <== 48; + eq[25][i].in[1] <== 64; eq[26][i] = IsEqual(); eq[26][i].in[0] <== in[i]; - eq[26][i].in[1] <== 49; + eq[26][i].in[1] <== 91; eq[27][i] = IsEqual(); eq[27][i].in[0] <== in[i]; - eq[27][i].in[1] <== 50; + eq[27][i].in[1] <== 92; eq[28][i] = IsEqual(); eq[28][i].in[0] <== in[i]; - eq[28][i].in[1] <== 51; + eq[28][i].in[1] <== 93; eq[29][i] = IsEqual(); eq[29][i].in[0] <== in[i]; - eq[29][i].in[1] <== 52; + eq[29][i].in[1] <== 94; eq[30][i] = IsEqual(); eq[30][i].in[0] <== in[i]; - eq[30][i].in[1] <== 53; + eq[30][i].in[1] <== 95; eq[31][i] = IsEqual(); eq[31][i].in[0] <== in[i]; - eq[31][i].in[1] <== 54; + eq[31][i].in[1] <== 96; eq[32][i] = IsEqual(); eq[32][i].in[0] <== in[i]; - eq[32][i].in[1] <== 55; + eq[32][i].in[1] <== 123; eq[33][i] = IsEqual(); eq[33][i].in[0] <== in[i]; - eq[33][i].in[1] <== 56; + eq[33][i].in[1] <== 124; eq[34][i] = IsEqual(); eq[34][i].in[0] <== in[i]; - eq[34][i].in[1] <== 57; - and[19][i] = AND(); - and[19][i].a <== states[i][3]; - multi_or[6][i] = MultiOR(15); - multi_or[6][i].in[0] <== and[18][i].out; - multi_or[6][i].in[1] <== and[0][i].out; - multi_or[6][i].in[2] <== eq[23][i].out; - multi_or[6][i].in[3] <== eq[24][i].out; - multi_or[6][i].in[4] <== eq[25][i].out; - multi_or[6][i].in[5] <== eq[26][i].out; - multi_or[6][i].in[6] <== eq[27][i].out; - multi_or[6][i].in[7] <== eq[28][i].out; - multi_or[6][i].in[8] <== eq[29][i].out; - multi_or[6][i].in[9] <== eq[30][i].out; - multi_or[6][i].in[10] <== eq[31][i].out; - multi_or[6][i].in[11] <== eq[32][i].out; - multi_or[6][i].in[12] <== eq[33][i].out; - multi_or[6][i].in[13] <== eq[34][i].out; - multi_or[6][i].in[14] <== eq[21][i].out; - and[19][i].b <== multi_or[6][i].out; - and[20][i] = AND(); - and[20][i].a <== states[i][5]; - and[20][i].b <== multi_or[6][i].out; - multi_or[7][i] = MultiOR(2); - multi_or[7][i].in[0] <== and[19][i].out; - multi_or[7][i].in[1] <== and[20][i].out; - states[i+1][5] <== multi_or[7][i].out; - state_changed[i].in[4] <== states[i+1][5]; - and[21][i] = AND(); - and[21][i].a <== states[i][1]; - and[21][i].b <== eq[21][i].out; - and[22][i] = AND(); - and[22][i].a <== states[i][26]; - and[22][i].b <== eq[21][i].out; - multi_or[8][i] = MultiOR(2); - multi_or[8][i].in[0] <== and[21][i].out; - multi_or[8][i].in[1] <== and[22][i].out; - states[i+1][6] <== multi_or[8][i].out; - state_changed[i].in[5] <== states[i+1][6]; + eq[34][i].in[1] <== 125; eq[35][i] = IsEqual(); eq[35][i].in[0] <== in[i]; - eq[35][i].in[1] <== 32; - and[23][i] = AND(); - and[23][i].a <== states[i][4]; - and[23][i].b <== eq[35][i].out; - and[24][i] = AND(); - and[24][i].a <== states[i][8]; - and[24][i].b <== eq[35][i].out; - multi_or[9][i] = MultiOR(2); - multi_or[9][i].in[0] <== and[23][i].out; - multi_or[9][i].in[1] <== and[24][i].out; - states[i+1][7] <== multi_or[9][i].out; - state_changed[i].in[6] <== states[i+1][7]; - and[25][i] = AND(); - and[25][i].a <== states[i][5]; - and[25][i].b <== eq[22][i].out; - states[i+1][8] <== and[25][i].out; - state_changed[i].in[7] <== states[i+1][8]; + eq[35][i].in[1] <== 126; eq[36][i] = IsEqual(); eq[36][i].in[0] <== in[i]; - eq[36][i].in[1] <== 13; - and[26][i] = AND(); - and[26][i].a <== states[i][0]; - and[26][i].b <== eq[36][i].out; - and[27][i] = AND(); - and[27][i].a <== states[i][10]; - and[27][i].b <== eq[36][i].out; - multi_or[10][i] = MultiOR(2); - multi_or[10][i].in[0] <== and[26][i].out; - multi_or[10][i].in[1] <== and[27][i].out; - states[i+1][9] <== multi_or[10][i].out; - state_changed[i].in[8] <== states[i+1][9]; + eq[36][i].in[1] <== 127; + and[35][i] = AND(); + and[35][i].a <== states[i][32]; + multi_or[6][i] = MultiOR(20); + multi_or[6][i].in[0] <== and[34][i].out; + multi_or[6][i].in[1] <== eq[20][i].out; + multi_or[6][i].in[2] <== eq[6][i].out; + multi_or[6][i].in[3] <== eq[21][i].out; + multi_or[6][i].in[4] <== eq[15][i].out; + multi_or[6][i].in[5] <== eq[22][i].out; + multi_or[6][i].in[6] <== eq[23][i].out; + multi_or[6][i].in[7] <== eq[24][i].out; + multi_or[6][i].in[8] <== eq[25][i].out; + multi_or[6][i].in[9] <== eq[26][i].out; + multi_or[6][i].in[10] <== eq[27][i].out; + multi_or[6][i].in[11] <== eq[28][i].out; + multi_or[6][i].in[12] <== eq[29][i].out; + multi_or[6][i].in[13] <== eq[30][i].out; + multi_or[6][i].in[14] <== eq[31][i].out; + multi_or[6][i].in[15] <== eq[32][i].out; + multi_or[6][i].in[16] <== eq[33][i].out; + multi_or[6][i].in[17] <== eq[34][i].out; + multi_or[6][i].in[18] <== eq[35][i].out; + multi_or[6][i].in[19] <== eq[36][i].out; + and[35][i].b <== multi_or[6][i].out; + multi_or[7][i] = MultiOR(4); + multi_or[7][i].in[0] <== and[30][i].out; + multi_or[7][i].in[1] <== and[31][i].out; + multi_or[7][i].in[2] <== and[33][i].out; + multi_or[7][i].in[3] <== and[35][i].out; + states[i+1][20] <== multi_or[7][i].out; + state_changed[i].in[19] <== states[i+1][20]; + lt[14][i] = LessEqThan(8); + lt[14][i].in[0] <== 194; + lt[14][i].in[1] <== in[i]; + lt[15][i] = LessEqThan(8); + lt[15][i].in[0] <== in[i]; + lt[15][i].in[1] <== 223; + and[36][i] = AND(); + and[36][i].a <== lt[14][i].out; + and[36][i].b <== lt[15][i].out; + and[37][i] = AND(); + and[37][i].a <== states[i][19]; + and[37][i].b <== and[36][i].out; + and[38][i] = AND(); + and[38][i].a <== states[i][20]; + and[38][i].b <== and[36][i].out; + lt[16][i] = LessEqThan(8); + lt[16][i].in[0] <== 160; + 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[39][i] = AND(); + and[39][i].a <== lt[16][i].out; + and[39][i].b <== lt[17][i].out; + and[40][i] = AND(); + and[40][i].a <== states[i][22]; + and[40][i].b <== and[39][i].out; + and[41][i] = AND(); + and[41][i].a <== states[i][23]; + and[41][i].b <== and[32][i].out; + lt[18][i] = LessEqThan(8); + lt[18][i].in[0] <== 128; + lt[18][i].in[1] <== in[i]; + lt[19][i] = LessEqThan(8); + lt[19][i].in[0] <== in[i]; + lt[19][i].in[1] <== 159; + and[42][i] = AND(); + and[42][i].a <== lt[18][i].out; + and[42][i].b <== lt[19][i].out; + and[43][i] = AND(); + and[43][i].a <== states[i][24]; + and[43][i].b <== and[42][i].out; + and[44][i] = AND(); + and[44][i].a <== states[i][32]; + and[44][i].b <== and[36][i].out; + multi_or[8][i] = MultiOR(6); + multi_or[8][i].in[0] <== and[37][i].out; + multi_or[8][i].in[1] <== and[38][i].out; + multi_or[8][i].in[2] <== and[40][i].out; + multi_or[8][i].in[3] <== and[41][i].out; + multi_or[8][i].in[4] <== and[43][i].out; + multi_or[8][i].in[5] <== and[44][i].out; + states[i+1][21] <== multi_or[8][i].out; + state_changed[i].in[20] <== states[i+1][21]; eq[37][i] = IsEqual(); eq[37][i].in[0] <== in[i]; - eq[37][i].in[1] <== 255; - and[28][i] = AND(); - and[28][i].a <== states[i][0]; - and[28][i].b <== eq[37][i].out; + eq[37][i].in[1] <== 224; + and[45][i] = AND(); + and[45][i].a <== states[i][19]; + and[45][i].b <== eq[37][i].out; + and[46][i] = AND(); + and[46][i].a <== states[i][20]; + and[46][i].b <== eq[37][i].out; + and[47][i] = AND(); + and[47][i].a <== states[i][32]; + and[47][i].b <== eq[37][i].out; + multi_or[9][i] = MultiOR(3); + multi_or[9][i].in[0] <== and[45][i].out; + multi_or[9][i].in[1] <== and[46][i].out; + multi_or[9][i].in[2] <== and[47][i].out; + states[i+1][22] <== multi_or[9][i].out; + state_changed[i].in[21] <== states[i+1][22]; eq[38][i] = IsEqual(); eq[38][i].in[0] <== in[i]; - eq[38][i].in[1] <== 10; - and[29][i] = AND(); - and[29][i].a <== states[i][9]; - and[29][i].b <== eq[38][i].out; - multi_or[11][i] = MultiOR(2); - multi_or[11][i].in[0] <== and[28][i].out; - multi_or[11][i].in[1] <== and[29][i].out; - states[i+1][10] <== multi_or[11][i].out; - state_changed[i].in[9] <== states[i+1][10]; - and[30][i] = AND(); - and[30][i].a <== states[i][10]; - and[30][i].b <== eq[3][i].out; - states[i+1][11] <== and[30][i].out; - state_changed[i].in[10] <== states[i+1][11]; + eq[38][i].in[1] <== 225; eq[39][i] = IsEqual(); eq[39][i].in[0] <== in[i]; - eq[39][i].in[1] <== 107; - and[31][i] = AND(); - and[31][i].a <== states[i][11]; - and[31][i].b <== eq[39][i].out; - states[i+1][12] <== and[31][i].out; - state_changed[i].in[11] <== states[i+1][12]; + eq[39][i].in[1] <== 226; eq[40][i] = IsEqual(); eq[40][i].in[0] <== in[i]; - eq[40][i].in[1] <== 105; - and[32][i] = AND(); - and[32][i].a <== states[i][12]; - and[32][i].b <== eq[40][i].out; - states[i+1][13] <== and[32][i].out; - state_changed[i].in[12] <== states[i+1][13]; + eq[40][i].in[1] <== 227; eq[41][i] = IsEqual(); eq[41][i].in[0] <== in[i]; - eq[41][i].in[1] <== 109; - and[33][i] = AND(); - and[33][i].a <== states[i][13]; - and[33][i].b <== eq[41][i].out; - states[i+1][14] <== and[33][i].out; - state_changed[i].in[13] <== states[i+1][14]; - and[34][i] = AND(); - and[34][i].a <== states[i][14]; - and[34][i].b <== eq[8][i].out; - states[i+1][15] <== and[34][i].out; - state_changed[i].in[14] <== states[i+1][15]; + eq[41][i].in[1] <== 228; eq[42][i] = IsEqual(); eq[42][i].in[0] <== in[i]; - eq[42][i].in[1] <== 115; - and[35][i] = AND(); - and[35][i].a <== states[i][15]; - and[35][i].b <== eq[42][i].out; - states[i+1][16] <== and[35][i].out; - state_changed[i].in[15] <== states[i+1][16]; - and[36][i] = AND(); - and[36][i].a <== states[i][16]; - and[36][i].b <== eq[40][i].out; - states[i+1][17] <== and[36][i].out; - state_changed[i].in[16] <== states[i+1][17]; - and[37][i] = AND(); - and[37][i].a <== states[i][17]; - and[37][i].b <== eq[6][i].out; - states[i+1][18] <== and[37][i].out; - state_changed[i].in[17] <== states[i+1][18]; + eq[42][i].in[1] <== 229; eq[43][i] = IsEqual(); eq[43][i].in[0] <== in[i]; - eq[43][i].in[1] <== 110; - and[38][i] = AND(); - and[38][i].a <== states[i][18]; - and[38][i].b <== eq[43][i].out; - states[i+1][19] <== and[38][i].out; - state_changed[i].in[18] <== states[i+1][19]; - and[39][i] = AND(); - and[39][i].a <== states[i][19]; - and[39][i].b <== eq[0][i].out; - states[i+1][20] <== and[39][i].out; - state_changed[i].in[19] <== states[i+1][20]; + eq[43][i].in[1] <== 230; eq[44][i] = IsEqual(); eq[44][i].in[0] <== in[i]; - eq[44][i].in[1] <== 116; - and[40][i] = AND(); - and[40][i].a <== states[i][20]; - and[40][i].b <== eq[44][i].out; - states[i+1][21] <== and[40][i].out; - state_changed[i].in[20] <== states[i+1][21]; + eq[44][i].in[1] <== 231; eq[45][i] = IsEqual(); eq[45][i].in[0] <== in[i]; - eq[45][i].in[1] <== 117; - and[41][i] = AND(); - and[41][i].a <== states[i][21]; - and[41][i].b <== eq[45][i].out; - states[i+1][22] <== and[41][i].out; - state_changed[i].in[21] <== states[i+1][22]; + eq[45][i].in[1] <== 232; eq[46][i] = IsEqual(); eq[46][i].in[0] <== in[i]; - eq[46][i].in[1] <== 114; - and[42][i] = AND(); - and[42][i].a <== states[i][22]; - and[42][i].b <== eq[46][i].out; - states[i+1][23] <== and[42][i].out; + eq[46][i].in[1] <== 233; + eq[47][i] = IsEqual(); + eq[47][i].in[0] <== in[i]; + eq[47][i].in[1] <== 234; + eq[48][i] = IsEqual(); + eq[48][i].in[0] <== in[i]; + eq[48][i].in[1] <== 235; + eq[49][i] = IsEqual(); + eq[49][i].in[0] <== in[i]; + eq[49][i].in[1] <== 236; + eq[50][i] = IsEqual(); + eq[50][i].in[0] <== in[i]; + eq[50][i].in[1] <== 238; + eq[51][i] = IsEqual(); + eq[51][i].in[0] <== in[i]; + eq[51][i].in[1] <== 239; + and[48][i] = AND(); + and[48][i].a <== states[i][19]; + multi_or[10][i] = MultiOR(14); + multi_or[10][i].in[0] <== eq[38][i].out; + multi_or[10][i].in[1] <== eq[39][i].out; + multi_or[10][i].in[2] <== eq[40][i].out; + multi_or[10][i].in[3] <== eq[41][i].out; + multi_or[10][i].in[4] <== eq[42][i].out; + multi_or[10][i].in[5] <== eq[43][i].out; + multi_or[10][i].in[6] <== eq[44][i].out; + multi_or[10][i].in[7] <== eq[45][i].out; + multi_or[10][i].in[8] <== eq[46][i].out; + multi_or[10][i].in[9] <== eq[47][i].out; + multi_or[10][i].in[10] <== eq[48][i].out; + multi_or[10][i].in[11] <== eq[49][i].out; + multi_or[10][i].in[12] <== eq[50][i].out; + multi_or[10][i].in[13] <== eq[51][i].out; + and[48][i].b <== multi_or[10][i].out; + and[49][i] = AND(); + and[49][i].a <== states[i][20]; + and[49][i].b <== multi_or[10][i].out; + lt[20][i] = LessEqThan(8); + lt[20][i].in[0] <== 144; + lt[20][i].in[1] <== in[i]; + lt[21][i] = LessEqThan(8); + lt[21][i].in[0] <== in[i]; + lt[21][i].in[1] <== 191; + and[50][i] = AND(); + and[50][i].a <== lt[20][i].out; + and[50][i].b <== lt[21][i].out; + and[51][i] = AND(); + and[51][i].a <== states[i][25]; + and[51][i].b <== and[50][i].out; + and[52][i] = AND(); + and[52][i].a <== states[i][26]; + and[52][i].b <== and[32][i].out; + eq[52][i] = IsEqual(); + eq[52][i].in[0] <== in[i]; + eq[52][i].in[1] <== 128; + eq[53][i] = IsEqual(); + eq[53][i].in[0] <== in[i]; + eq[53][i].in[1] <== 129; + eq[54][i] = IsEqual(); + eq[54][i].in[0] <== in[i]; + eq[54][i].in[1] <== 130; + eq[55][i] = IsEqual(); + eq[55][i].in[0] <== in[i]; + eq[55][i].in[1] <== 131; + eq[56][i] = IsEqual(); + eq[56][i].in[0] <== in[i]; + eq[56][i].in[1] <== 132; + eq[57][i] = IsEqual(); + eq[57][i].in[0] <== in[i]; + eq[57][i].in[1] <== 133; + eq[58][i] = IsEqual(); + eq[58][i].in[0] <== in[i]; + eq[58][i].in[1] <== 134; + eq[59][i] = IsEqual(); + eq[59][i].in[0] <== in[i]; + eq[59][i].in[1] <== 135; + eq[60][i] = IsEqual(); + eq[60][i].in[0] <== in[i]; + eq[60][i].in[1] <== 136; + eq[61][i] = IsEqual(); + eq[61][i].in[0] <== in[i]; + eq[61][i].in[1] <== 137; + eq[62][i] = IsEqual(); + eq[62][i].in[0] <== in[i]; + eq[62][i].in[1] <== 138; + eq[63][i] = IsEqual(); + eq[63][i].in[0] <== in[i]; + eq[63][i].in[1] <== 139; + eq[64][i] = IsEqual(); + eq[64][i].in[0] <== in[i]; + eq[64][i].in[1] <== 140; + eq[65][i] = IsEqual(); + eq[65][i].in[0] <== in[i]; + eq[65][i].in[1] <== 141; + eq[66][i] = IsEqual(); + eq[66][i].in[0] <== in[i]; + eq[66][i].in[1] <== 142; + eq[67][i] = IsEqual(); + eq[67][i].in[0] <== in[i]; + eq[67][i].in[1] <== 143; + and[53][i] = AND(); + and[53][i].a <== states[i][27]; + multi_or[11][i] = MultiOR(16); + multi_or[11][i].in[0] <== eq[52][i].out; + multi_or[11][i].in[1] <== eq[53][i].out; + multi_or[11][i].in[2] <== eq[54][i].out; + multi_or[11][i].in[3] <== eq[55][i].out; + multi_or[11][i].in[4] <== eq[56][i].out; + multi_or[11][i].in[5] <== eq[57][i].out; + multi_or[11][i].in[6] <== eq[58][i].out; + multi_or[11][i].in[7] <== eq[59][i].out; + multi_or[11][i].in[8] <== eq[60][i].out; + multi_or[11][i].in[9] <== eq[61][i].out; + multi_or[11][i].in[10] <== eq[62][i].out; + multi_or[11][i].in[11] <== eq[63][i].out; + multi_or[11][i].in[12] <== eq[64][i].out; + multi_or[11][i].in[13] <== eq[65][i].out; + multi_or[11][i].in[14] <== eq[66][i].out; + multi_or[11][i].in[15] <== eq[67][i].out; + and[53][i].b <== multi_or[11][i].out; + and[54][i] = AND(); + and[54][i].a <== states[i][32]; + and[54][i].b <== multi_or[10][i].out; + multi_or[12][i] = MultiOR(6); + multi_or[12][i].in[0] <== and[48][i].out; + multi_or[12][i].in[1] <== and[49][i].out; + multi_or[12][i].in[2] <== and[51][i].out; + multi_or[12][i].in[3] <== and[52][i].out; + multi_or[12][i].in[4] <== and[53][i].out; + multi_or[12][i].in[5] <== and[54][i].out; + states[i+1][23] <== multi_or[12][i].out; state_changed[i].in[22] <== states[i+1][23]; - and[43][i] = AND(); - and[43][i].a <== states[i][23]; - and[43][i].b <== eq[4][i].out; - states[i+1][24] <== and[43][i].out; + eq[68][i] = IsEqual(); + eq[68][i].in[0] <== in[i]; + eq[68][i].in[1] <== 237; + and[55][i] = AND(); + and[55][i].a <== states[i][19]; + and[55][i].b <== eq[68][i].out; + and[56][i] = AND(); + and[56][i].a <== states[i][20]; + and[56][i].b <== eq[68][i].out; + and[57][i] = AND(); + and[57][i].a <== states[i][32]; + and[57][i].b <== eq[68][i].out; + multi_or[13][i] = MultiOR(3); + multi_or[13][i].in[0] <== and[55][i].out; + multi_or[13][i].in[1] <== and[56][i].out; + multi_or[13][i].in[2] <== and[57][i].out; + states[i+1][24] <== multi_or[13][i].out; state_changed[i].in[23] <== states[i+1][24]; - and[44][i] = AND(); - and[44][i].a <== states[i][24]; - and[44][i].b <== eq[10][i].out; - states[i+1][25] <== and[44][i].out; + eq[69][i] = IsEqual(); + eq[69][i].in[0] <== in[i]; + eq[69][i].in[1] <== 240; + and[58][i] = AND(); + and[58][i].a <== states[i][19]; + and[58][i].b <== eq[69][i].out; + and[59][i] = AND(); + and[59][i].a <== states[i][20]; + and[59][i].b <== eq[69][i].out; + and[60][i] = AND(); + and[60][i].a <== states[i][32]; + and[60][i].b <== eq[69][i].out; + multi_or[14][i] = MultiOR(3); + multi_or[14][i].in[0] <== and[58][i].out; + multi_or[14][i].in[1] <== and[59][i].out; + multi_or[14][i].in[2] <== and[60][i].out; + states[i+1][25] <== multi_or[14][i].out; state_changed[i].in[24] <== states[i+1][25]; - and[45][i] = AND(); - and[45][i].a <== states[i][7]; - and[45][i].b <== eq[1][i].out; - states[i+1][26] <== and[45][i].out; + eq[70][i] = IsEqual(); + eq[70][i].in[0] <== in[i]; + eq[70][i].in[1] <== 241; + eq[71][i] = IsEqual(); + eq[71][i].in[0] <== in[i]; + eq[71][i].in[1] <== 242; + eq[72][i] = IsEqual(); + eq[72][i].in[0] <== in[i]; + eq[72][i].in[1] <== 243; + and[61][i] = AND(); + and[61][i].a <== states[i][19]; + multi_or[15][i] = MultiOR(3); + multi_or[15][i].in[0] <== eq[70][i].out; + multi_or[15][i].in[1] <== eq[71][i].out; + multi_or[15][i].in[2] <== eq[72][i].out; + and[61][i].b <== multi_or[15][i].out; + and[62][i] = AND(); + and[62][i].a <== states[i][20]; + and[62][i].b <== multi_or[15][i].out; + and[63][i] = AND(); + and[63][i].a <== states[i][32]; + and[63][i].b <== multi_or[15][i].out; + multi_or[16][i] = MultiOR(3); + multi_or[16][i].in[0] <== and[61][i].out; + multi_or[16][i].in[1] <== and[62][i].out; + multi_or[16][i].in[2] <== and[63][i].out; + states[i+1][26] <== multi_or[16][i].out; state_changed[i].in[25] <== states[i+1][26]; - eq[47][i] = IsEqual(); - eq[47][i].in[0] <== in[i]; - eq[47][i].in[1] <== 104; - and[46][i] = AND(); - and[46][i].a <== states[i][26]; - and[46][i].b <== eq[47][i].out; - states[i+1][27] <== and[46][i].out; + eq[73][i] = IsEqual(); + eq[73][i].in[0] <== in[i]; + eq[73][i].in[1] <== 244; + and[64][i] = AND(); + and[64][i].a <== states[i][19]; + and[64][i].b <== eq[73][i].out; + and[65][i] = AND(); + and[65][i].a <== states[i][20]; + and[65][i].b <== eq[73][i].out; + and[66][i] = AND(); + and[66][i].a <== states[i][32]; + and[66][i].b <== eq[73][i].out; + multi_or[17][i] = MultiOR(3); + multi_or[17][i].in[0] <== and[64][i].out; + multi_or[17][i].in[1] <== and[65][i].out; + multi_or[17][i].in[2] <== and[66][i].out; + states[i+1][27] <== multi_or[17][i].out; state_changed[i].in[26] <== states[i+1][27]; + eq[74][i] = IsEqual(); + eq[74][i].in[0] <== in[i]; + eq[74][i].in[1] <== 59; + and[67][i] = AND(); + and[67][i].a <== states[i][20]; + and[67][i].b <== eq[74][i].out; + states[i+1][28] <== and[67][i].out; + state_changed[i].in[27] <== states[i+1][28]; + eq[75][i] = IsEqual(); + eq[75][i].in[0] <== in[i]; + eq[75][i].in[1] <== 32; + and[68][i] = AND(); + and[68][i].a <== states[i][28]; + and[68][i].b <== eq[75][i].out; + states[i+1][29] <== and[68][i].out; + state_changed[i].in[28] <== states[i+1][29]; + and[69][i] = AND(); + and[69][i].a <== states[i][29]; + and[69][i].b <== eq[16][i].out; + states[i+1][30] <== and[69][i].out; + state_changed[i].in[29] <== states[i+1][30]; + eq[76][i] = IsEqual(); + eq[76][i].in[0] <== in[i]; + eq[76][i].in[1] <== 104; + and[70][i] = AND(); + and[70][i].a <== states[i][30]; + and[70][i].b <== eq[76][i].out; + states[i+1][31] <== and[70][i].out; + state_changed[i].in[30] <== states[i+1][31]; + and[71][i] = AND(); + and[71][i].a <== states[i][31]; + and[71][i].b <== eq[19][i].out; + states[i+1][32] <== and[71][i].out; + state_changed[i].in[31] <== states[i+1][32]; + 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[72][i] = AND(); + and[72][i].a <== lt[22][i].out; + and[72][i].b <== lt[23][i].out; + eq[77][i] = IsEqual(); + eq[77][i].in[0] <== in[i]; + eq[77][i].in[1] <== 43; + eq[78][i] = IsEqual(); + eq[78][i].in[0] <== in[i]; + eq[78][i].in[1] <== 47; + eq[79][i] = IsEqual(); + eq[79][i].in[0] <== in[i]; + eq[79][i].in[1] <== 48; + eq[80][i] = IsEqual(); + eq[80][i].in[0] <== in[i]; + eq[80][i].in[1] <== 49; + eq[81][i] = IsEqual(); + eq[81][i].in[0] <== in[i]; + eq[81][i].in[1] <== 50; + eq[82][i] = IsEqual(); + eq[82][i].in[0] <== in[i]; + eq[82][i].in[1] <== 51; + eq[83][i] = IsEqual(); + eq[83][i].in[0] <== in[i]; + eq[83][i].in[1] <== 52; + eq[84][i] = IsEqual(); + eq[84][i].in[0] <== in[i]; + eq[84][i].in[1] <== 53; + eq[85][i] = IsEqual(); + eq[85][i].in[0] <== in[i]; + eq[85][i].in[1] <== 54; + eq[86][i] = IsEqual(); + eq[86][i].in[0] <== in[i]; + eq[86][i].in[1] <== 55; + eq[87][i] = IsEqual(); + eq[87][i].in[0] <== in[i]; + eq[87][i].in[1] <== 56; + eq[88][i] = IsEqual(); + eq[88][i].in[0] <== in[i]; + eq[88][i].in[1] <== 57; + and[73][i] = AND(); + and[73][i].a <== states[i][32]; + multi_or[18][i] = MultiOR(15); + multi_or[18][i].in[0] <== and[72][i].out; + multi_or[18][i].in[1] <== and[18][i].out; + multi_or[18][i].in[2] <== eq[77][i].out; + multi_or[18][i].in[3] <== eq[78][i].out; + multi_or[18][i].in[4] <== eq[79][i].out; + multi_or[18][i].in[5] <== eq[80][i].out; + multi_or[18][i].in[6] <== eq[81][i].out; + multi_or[18][i].in[7] <== eq[82][i].out; + multi_or[18][i].in[8] <== eq[83][i].out; + multi_or[18][i].in[9] <== eq[84][i].out; + multi_or[18][i].in[10] <== eq[85][i].out; + multi_or[18][i].in[11] <== eq[86][i].out; + multi_or[18][i].in[12] <== eq[87][i].out; + multi_or[18][i].in[13] <== eq[88][i].out; + multi_or[18][i].in[14] <== eq[19][i].out; + and[73][i].b <== multi_or[18][i].out; + and[74][i] = AND(); + and[74][i].a <== states[i][33]; + and[74][i].b <== multi_or[18][i].out; + multi_or[19][i] = MultiOR(2); + multi_or[19][i].in[0] <== and[73][i].out; + multi_or[19][i].in[1] <== and[74][i].out; + states[i+1][33] <== multi_or[19][i].out; + state_changed[i].in[32] <== states[i+1][33]; + and[75][i] = AND(); + and[75][i].a <== states[i][33]; + and[75][i].b <== eq[74][i].out; + states[i+1][34] <== and[75][i].out; + state_changed[i].in[33] <== states[i+1][34]; states[i+1][0] <== 1 - state_changed[i].out; } component final_state_result = MultiOR(num_bytes+1); for (var i = 0; i <= num_bytes; i++) { - final_state_result.in[i] <== states[i][8]; + final_state_result.in[i] <== states[i][34]; } out <== final_state_result.out; - signal is_consecutive[msg_bytes+1][2]; is_consecutive[msg_bytes][1] <== 1; for (var i = 0; i < msg_bytes; i++) { - is_consecutive[msg_bytes-1-i][0] <== states[num_bytes-i][8] * (1 - is_consecutive[msg_bytes-i][1]) + is_consecutive[msg_bytes-i][1]; + is_consecutive[msg_bytes-1-i][0] <== states[num_bytes-i][34] * (1 - is_consecutive[msg_bytes-i][1]) + is_consecutive[msg_bytes-i][1]; is_consecutive[msg_bytes-1-i][1] <== state_changed[msg_bytes-i].out * is_consecutive[msg_bytes-1-i][0]; } + // substrings calculated: [{(32, 33), (33, 33)}] signal is_substr0[msg_bytes][3]; signal is_reveal0[msg_bytes]; signal output reveal0[msg_bytes]; for (var i = 0; i < msg_bytes; i++) { is_substr0[i][0] <== 0; - // the 0-th substring transitions: [(3, 5), (5, 5)] - is_substr0[i][1] <== is_substr0[i][0] + states[i+1][3] * states[i+2][5]; - is_substr0[i][2] <== is_substr0[i][1] + states[i+1][5] * states[i+2][5]; + // the 0-th substring transitions: [(32, 33), (33, 33)] + is_substr0[i][1] <== is_substr0[i][0] + states[i+1][32] * states[i+2][33]; + is_substr0[i][2] <== is_substr0[i][1] + states[i+1][33] * states[i+2][33]; is_reveal0[i] <== is_substr0[i][2] * is_consecutive[i][1]; reveal0[i] <== in[i+1] * is_reveal0[i]; } diff --git a/packages/circom/circuits/common/email_addr.json b/packages/circom/circuits/common/email_addr.json index c590439..0842165 100644 --- a/packages/circom/circuits/common/email_addr.json +++ b/packages/circom/circuits/common/email_addr.json @@ -1,8 +1,8 @@ { - "parts": [ - { - "is_public": true, - "regex_def": "(a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z|A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z|0|1|2|3|4|5|6|7|8|9|!|#|$|%|&|'|\\*|\\+|-|/|=|\\?|^|_|`|{|\\||}|~|\\.)+@(a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z|A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z|0|1|2|3|4|5|6|7|8|9|\\.|-)+" - } - ] -} \ No newline at end of file + "parts": [ + { + "is_public": true, + "regex_def": "[A-Za-z0-9!#$%&'*+=?^_`{|}~.]+@[A-Za-z0-9.-]+" + } + ] +} diff --git a/packages/circom/circuits/common/email_addr_regex.circom b/packages/circom/circuits/common/email_addr_regex.circom index 39d55c9..59239cf 100644 --- a/packages/circom/circuits/common/email_addr_regex.circom +++ b/packages/circom/circuits/common/email_addr_regex.circom @@ -2,7 +2,7 @@ pragma circom 2.1.5; include "@zk-email/zk-regex-circom/circuits/regex_helpers.circom"; -// regex: (a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z|A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z|0|1|2|3|4|5|6|7|8|9|!|#|$|%|&|'|\*|\+|-|/|=|\?|^|_|`|{|\||}|~|\.)+@(a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z|A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z|0|1|2|3|4|5|6|7|8|9|\.|-)+ +// regex: [A-Za-z0-9!#$%&'*+=?^_`{|}~.]+@[A-Za-z0-9.-]+ template EmailAddrRegex(msg_bytes) { signal input msg[msg_bytes]; signal output out; @@ -14,7 +14,7 @@ template EmailAddrRegex(msg_bytes) { in[i+1] <== msg[i]; } - component eq[25][num_bytes]; + component eq[24][num_bytes]; component lt[8][num_bytes]; component and[9][num_bytes]; component multi_or[5][num_bytes]; @@ -72,55 +72,49 @@ template EmailAddrRegex(msg_bytes) { eq[7][i].in[1] <== 43; eq[8][i] = IsEqual(); eq[8][i].in[0] <== in[i]; - eq[8][i].in[1] <== 45; + eq[8][i].in[1] <== 46; eq[9][i] = IsEqual(); eq[9][i].in[0] <== in[i]; - eq[9][i].in[1] <== 46; + eq[9][i].in[1] <== 48; eq[10][i] = IsEqual(); eq[10][i].in[0] <== in[i]; - eq[10][i].in[1] <== 47; + eq[10][i].in[1] <== 49; eq[11][i] = IsEqual(); eq[11][i].in[0] <== in[i]; - eq[11][i].in[1] <== 48; + eq[11][i].in[1] <== 50; eq[12][i] = IsEqual(); eq[12][i].in[0] <== in[i]; - eq[12][i].in[1] <== 49; + eq[12][i].in[1] <== 51; eq[13][i] = IsEqual(); eq[13][i].in[0] <== in[i]; - eq[13][i].in[1] <== 50; + eq[13][i].in[1] <== 52; eq[14][i] = IsEqual(); eq[14][i].in[0] <== in[i]; - eq[14][i].in[1] <== 51; + eq[14][i].in[1] <== 53; eq[15][i] = IsEqual(); eq[15][i].in[0] <== in[i]; - eq[15][i].in[1] <== 52; + eq[15][i].in[1] <== 54; eq[16][i] = IsEqual(); eq[16][i].in[0] <== in[i]; - eq[16][i].in[1] <== 53; + eq[16][i].in[1] <== 55; eq[17][i] = IsEqual(); eq[17][i].in[0] <== in[i]; - eq[17][i].in[1] <== 54; + eq[17][i].in[1] <== 56; eq[18][i] = IsEqual(); eq[18][i].in[0] <== in[i]; - eq[18][i].in[1] <== 55; + eq[18][i].in[1] <== 57; eq[19][i] = IsEqual(); eq[19][i].in[0] <== in[i]; - eq[19][i].in[1] <== 56; + eq[19][i].in[1] <== 61; eq[20][i] = IsEqual(); eq[20][i].in[0] <== in[i]; - eq[20][i].in[1] <== 57; + eq[20][i].in[1] <== 63; eq[21][i] = IsEqual(); eq[21][i].in[0] <== in[i]; - eq[21][i].in[1] <== 61; - eq[22][i] = IsEqual(); - eq[22][i].in[0] <== in[i]; - eq[22][i].in[1] <== 63; - eq[23][i] = IsEqual(); - eq[23][i].in[0] <== in[i]; - eq[23][i].in[1] <== 255; + eq[21][i].in[1] <== 255; and[2][i] = AND(); and[2][i].a <== states[i][0]; - multi_or[0][i] = MultiOR(26); + multi_or[0][i] = MultiOR(24); multi_or[0][i].in[0] <== and[0][i].out; multi_or[0][i].in[1] <== and[1][i].out; multi_or[0][i].in[2] <== eq[0][i].out; @@ -145,8 +139,6 @@ template EmailAddrRegex(msg_bytes) { multi_or[0][i].in[21] <== eq[19][i].out; multi_or[0][i].in[22] <== eq[20][i].out; multi_or[0][i].in[23] <== eq[21][i].out; - multi_or[0][i].in[24] <== eq[22][i].out; - multi_or[0][i].in[25] <== eq[23][i].out; and[2][i].b <== multi_or[0][i].out; lt[4][i] = LessEqThan(8); lt[4][i].in[0] <== 94; @@ -159,7 +151,7 @@ template EmailAddrRegex(msg_bytes) { and[3][i].b <== lt[5][i].out; and[4][i] = AND(); and[4][i].a <== states[i][1]; - multi_or[1][i] = MultiOR(25); + multi_or[1][i] = MultiOR(23); multi_or[1][i].in[0] <== and[0][i].out; multi_or[1][i].in[1] <== and[3][i].out; multi_or[1][i].in[2] <== eq[0][i].out; @@ -183,20 +175,18 @@ template EmailAddrRegex(msg_bytes) { multi_or[1][i].in[20] <== eq[18][i].out; multi_or[1][i].in[21] <== eq[19][i].out; multi_or[1][i].in[22] <== eq[20][i].out; - multi_or[1][i].in[23] <== eq[21][i].out; - multi_or[1][i].in[24] <== eq[22][i].out; and[4][i].b <== multi_or[1][i].out; multi_or[2][i] = MultiOR(2); multi_or[2][i].in[0] <== and[2][i].out; multi_or[2][i].in[1] <== and[4][i].out; states[i+1][1] <== multi_or[2][i].out; state_changed[i].in[0] <== states[i+1][1]; - eq[24][i] = IsEqual(); - eq[24][i].in[0] <== in[i]; - eq[24][i].in[1] <== 64; + eq[22][i] = IsEqual(); + eq[22][i].in[0] <== in[i]; + eq[22][i].in[1] <== 64; and[5][i] = AND(); and[5][i].a <== states[i][1]; - and[5][i].b <== eq[24][i].out; + and[5][i].b <== eq[22][i].out; states[i+1][2] <== and[5][i].out; state_changed[i].in[1] <== states[i+1][2]; lt[6][i] = LessEqThan(8); @@ -208,23 +198,26 @@ template EmailAddrRegex(msg_bytes) { and[6][i] = AND(); and[6][i].a <== lt[6][i].out; and[6][i].b <== lt[7][i].out; + eq[23][i] = IsEqual(); + eq[23][i].in[0] <== in[i]; + eq[23][i].in[1] <== 45; and[7][i] = AND(); and[7][i].a <== states[i][2]; multi_or[3][i] = MultiOR(14); multi_or[3][i].in[0] <== and[0][i].out; multi_or[3][i].in[1] <== and[6][i].out; - multi_or[3][i].in[2] <== eq[8][i].out; - multi_or[3][i].in[3] <== eq[9][i].out; - multi_or[3][i].in[4] <== eq[11][i].out; - multi_or[3][i].in[5] <== eq[12][i].out; - multi_or[3][i].in[6] <== eq[13][i].out; - multi_or[3][i].in[7] <== eq[14][i].out; - multi_or[3][i].in[8] <== eq[15][i].out; - multi_or[3][i].in[9] <== eq[16][i].out; - multi_or[3][i].in[10] <== eq[17][i].out; - multi_or[3][i].in[11] <== eq[18][i].out; - multi_or[3][i].in[12] <== eq[19][i].out; - multi_or[3][i].in[13] <== eq[20][i].out; + multi_or[3][i].in[2] <== eq[23][i].out; + multi_or[3][i].in[3] <== eq[8][i].out; + multi_or[3][i].in[4] <== eq[9][i].out; + multi_or[3][i].in[5] <== eq[10][i].out; + multi_or[3][i].in[6] <== eq[11][i].out; + multi_or[3][i].in[7] <== eq[12][i].out; + multi_or[3][i].in[8] <== eq[13][i].out; + multi_or[3][i].in[9] <== eq[14][i].out; + multi_or[3][i].in[10] <== eq[15][i].out; + multi_or[3][i].in[11] <== eq[16][i].out; + multi_or[3][i].in[12] <== eq[17][i].out; + multi_or[3][i].in[13] <== eq[18][i].out; and[7][i].b <== multi_or[3][i].out; and[8][i] = AND(); and[8][i].a <== states[i][3]; @@ -242,13 +235,13 @@ template EmailAddrRegex(msg_bytes) { final_state_result.in[i] <== states[i][3]; } out <== final_state_result.out; - signal is_consecutive[msg_bytes+1][2]; is_consecutive[msg_bytes][1] <== 1; for (var i = 0; i < msg_bytes; i++) { is_consecutive[msg_bytes-1-i][0] <== states[num_bytes-i][3] * (1 - is_consecutive[msg_bytes-i][1]) + is_consecutive[msg_bytes-i][1]; is_consecutive[msg_bytes-1-i][1] <== state_changed[msg_bytes-i].out * is_consecutive[msg_bytes-1-i][0]; } + // substrings calculated: [{(0, 1), (1, 1), (1, 2), (2, 3), (3, 3)}] signal is_substr0[msg_bytes][6]; signal is_reveal0[msg_bytes]; signal output reveal0[msg_bytes]; diff --git a/packages/circom/circuits/common/email_addr_with_name.json b/packages/circom/circuits/common/email_addr_with_name.json index ecd2ad4..31607a3 100644 --- a/packages/circom/circuits/common/email_addr_with_name.json +++ b/packages/circom/circuits/common/email_addr_with_name.json @@ -1,16 +1,16 @@ { - "parts": [ - { - "is_public": false, - "regex_def": "[^\r\n]+<" - }, - { - "is_public": true, - "regex_def": "(a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z|A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z|0|1|2|3|4|5|6|7|8|9|!|#|$|%|&|'|\\*|\\+|-|/|=|\\?|^|_|`|{|\\||}|~|\\.)+@(a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z|A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z|0|1|2|3|4|5|6|7|8|9|_|\\.|-)+" - }, - { - "is_public": false, - "regex_def": ">" - } - ] -} \ No newline at end of file + "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": ">" + } + ] +} 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 30dd128..ddc6b85 100644 --- a/packages/circom/circuits/common/email_addr_with_name_regex.circom +++ b/packages/circom/circuits/common/email_addr_with_name_regex.circom @@ -2,7 +2,7 @@ pragma circom 2.1.5; include "@zk-email/zk-regex-circom/circuits/regex_helpers.circom"; -// regex: [^ \n]+<(a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z|A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z|0|1|2|3|4|5|6|7|8|9|!|#|$|%|&|'|\*|\+|-|/|=|\?|^|_|`|{|\||}|~|\.)+@(a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z|A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z|0|1|2|3|4|5|6|7|8|9|_|\.|-)+> +// regex: [^\r\n]+<[a-zA-Z0-9!#$%&'*+-/=?^_`{\|}~\.]+@[a-zA-Z0-9_\.-]+> template EmailAddrWithNameRegex(msg_bytes) { signal input msg[msg_bytes]; signal output out; @@ -14,589 +14,752 @@ template EmailAddrWithNameRegex(msg_bytes) { in[i+1] <== msg[i]; } - component eq[50][num_bytes]; - component lt[24][num_bytes]; - component and[31][num_bytes]; - component multi_or[13][num_bytes]; - signal states[num_bytes+1][7]; + component eq[86][num_bytes]; + component lt[26][num_bytes]; + component and[52][num_bytes]; + component multi_or[20][num_bytes]; + signal states[num_bytes+1][14]; component state_changed[num_bytes]; states[0][0] <== 1; - for (var i = 1; i < 7; i++) { + for (var i = 1; i < 14; i++) { states[0][i] <== 0; } for (var i = 0; i < num_bytes; i++) { - state_changed[i] = MultiOR(6); + state_changed[i] = MultiOR(13); lt[0][i] = LessEqThan(8); - lt[0][i].in[0] <== 14; + lt[0][i].in[0] <== 194; lt[0][i].in[1] <== in[i]; lt[1][i] = LessEqThan(8); lt[1][i].in[0] <== in[i]; - lt[1][i].in[1] <== 93; + lt[1][i].in[1] <== 223; and[0][i] = AND(); and[0][i].a <== lt[0][i].out; and[0][i].b <== lt[1][i].out; + and[1][i] = AND(); + and[1][i].a <== states[i][0]; + and[1][i].b <== and[0][i].out; lt[2][i] = LessEqThan(8); - lt[2][i].in[0] <== 95; + lt[2][i].in[0] <== 160; lt[2][i].in[1] <== in[i]; lt[3][i] = LessEqThan(8); lt[3][i].in[0] <== in[i]; - lt[3][i].in[1] <== 255; - and[1][i] = AND(); - and[1][i].a <== lt[2][i].out; - and[1][i].b <== lt[3][i].out; + lt[3][i].in[1] <== 191; + and[2][i] = AND(); + and[2][i].a <== lt[2][i].out; + and[2][i].b <== lt[3][i].out; + and[3][i] = AND(); + and[3][i].a <== states[i][2]; + and[3][i].b <== and[2][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[4][i] = AND(); + and[4][i].a <== lt[4][i].out; + and[4][i].b <== lt[5][i].out; + and[5][i] = AND(); + and[5][i].a <== states[i][3]; + and[5][i].b <== and[4][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] <== 159; + and[6][i] = AND(); + and[6][i].a <== lt[6][i].out; + and[6][i].b <== lt[7][i].out; + and[7][i] = AND(); + and[7][i].a <== states[i][4]; + and[7][i].b <== and[6][i].out; + lt[8][i] = LessEqThan(8); + lt[8][i].in[0] <== 49; + lt[8][i].in[1] <== in[i]; + lt[9][i] = LessEqThan(8); + lt[9][i].in[0] <== in[i]; + lt[9][i].in[1] <== 223; + and[8][i] = AND(); + and[8][i].a <== lt[8][i].out; + and[8][i].b <== lt[9][i].out; + and[9][i] = AND(); + and[9][i].a <== states[i][8]; + and[9][i].b <== and[8][i].out; + lt[10][i] = LessEqThan(8); + lt[10][i].in[0] <== 127; + 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[10][i] = AND(); + and[10][i].a <== lt[10][i].out; + and[10][i].b <== lt[11][i].out; eq[0][i] = IsEqual(); eq[0][i].in[0] <== in[i]; - eq[0][i].in[1] <== 0; + eq[0][i].in[1] <== 58; eq[1][i] = IsEqual(); eq[1][i].in[0] <== in[i]; - eq[1][i].in[1] <== 1; + eq[1][i].in[1] <== 59; eq[2][i] = IsEqual(); eq[2][i].in[0] <== in[i]; - eq[2][i].in[1] <== 2; + eq[2][i].in[1] <== 60; eq[3][i] = IsEqual(); eq[3][i].in[0] <== in[i]; - eq[3][i].in[1] <== 3; + eq[3][i].in[1] <== 62; eq[4][i] = IsEqual(); eq[4][i].in[0] <== in[i]; - eq[4][i].in[1] <== 4; + eq[4][i].in[1] <== 64; eq[5][i] = IsEqual(); eq[5][i].in[0] <== in[i]; - eq[5][i].in[1] <== 5; + eq[5][i].in[1] <== 91; eq[6][i] = IsEqual(); eq[6][i].in[0] <== in[i]; - eq[6][i].in[1] <== 6; + eq[6][i].in[1] <== 92; eq[7][i] = IsEqual(); eq[7][i].in[0] <== in[i]; - eq[7][i].in[1] <== 7; + eq[7][i].in[1] <== 93; + and[11][i] = AND(); + and[11][i].a <== states[i][9]; + multi_or[0][i] = MultiOR(9); + multi_or[0][i].in[0] <== and[10][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; + and[11][i].b <== multi_or[0][i].out; + multi_or[1][i] = MultiOR(6); + multi_or[1][i].in[0] <== and[1][i].out; + multi_or[1][i].in[1] <== and[3][i].out; + multi_or[1][i].in[2] <== and[5][i].out; + multi_or[1][i].in[3] <== and[7][i].out; + multi_or[1][i].in[4] <== and[9][i].out; + multi_or[1][i].in[5] <== and[11][i].out; + states[i+1][1] <== multi_or[1][i].out; + state_changed[i].in[0] <== states[i+1][1]; eq[8][i] = IsEqual(); eq[8][i].in[0] <== in[i]; - eq[8][i].in[1] <== 8; + eq[8][i].in[1] <== 224; + and[12][i] = AND(); + and[12][i].a <== states[i][0]; + and[12][i].b <== eq[8][i].out; + and[13][i] = AND(); + and[13][i].a <== states[i][8]; + and[13][i].b <== eq[8][i].out; + and[14][i] = AND(); + and[14][i].a <== states[i][9]; + and[14][i].b <== eq[8][i].out; + multi_or[2][i] = MultiOR(3); + multi_or[2][i].in[0] <== and[12][i].out; + multi_or[2][i].in[1] <== and[13][i].out; + multi_or[2][i].in[2] <== and[14][i].out; + states[i+1][2] <== multi_or[2][i].out; + state_changed[i].in[1] <== states[i+1][2]; eq[9][i] = IsEqual(); eq[9][i].in[0] <== in[i]; - eq[9][i].in[1] <== 9; + eq[9][i].in[1] <== 225; eq[10][i] = IsEqual(); eq[10][i].in[0] <== in[i]; - eq[10][i].in[1] <== 11; + eq[10][i].in[1] <== 226; eq[11][i] = IsEqual(); eq[11][i].in[0] <== in[i]; - eq[11][i].in[1] <== 12; - and[2][i] = AND(); - and[2][i].a <== states[i][0]; - multi_or[0][i] = MultiOR(14); - multi_or[0][i].in[0] <== and[0][i].out; - multi_or[0][i].in[1] <== and[1][i].out; - multi_or[0][i].in[2] <== eq[0][i].out; - multi_or[0][i].in[3] <== eq[1][i].out; - multi_or[0][i].in[4] <== eq[2][i].out; - multi_or[0][i].in[5] <== eq[3][i].out; - multi_or[0][i].in[6] <== eq[4][i].out; - multi_or[0][i].in[7] <== eq[5][i].out; - multi_or[0][i].in[8] <== eq[6][i].out; - multi_or[0][i].in[9] <== eq[7][i].out; - multi_or[0][i].in[10] <== eq[8][i].out; - multi_or[0][i].in[11] <== eq[9][i].out; - multi_or[0][i].in[12] <== eq[10][i].out; - multi_or[0][i].in[13] <== eq[11][i].out; - and[2][i].b <== multi_or[0][i].out; - lt[4][i] = LessEqThan(8); - lt[4][i].in[0] <== 14; - lt[4][i].in[1] <== in[i]; - lt[5][i] = LessEqThan(8); - lt[5][i].in[0] <== in[i]; - lt[5][i].in[1] <== 254; - 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[3][i].out; - multi_or[1][i].in[1] <== eq[0][i].out; - multi_or[1][i].in[2] <== eq[1][i].out; - multi_or[1][i].in[3] <== eq[2][i].out; - multi_or[1][i].in[4] <== eq[3][i].out; - multi_or[1][i].in[5] <== eq[4][i].out; - multi_or[1][i].in[6] <== eq[5][i].out; - multi_or[1][i].in[7] <== eq[6][i].out; - multi_or[1][i].in[8] <== eq[7][i].out; - multi_or[1][i].in[9] <== eq[8][i].out; - multi_or[1][i].in[10] <== eq[9][i].out; - multi_or[1][i].in[11] <== eq[10][i].out; - multi_or[1][i].in[12] <== eq[11][i].out; - and[4][i].b <== multi_or[1][i].out; - lt[6][i] = LessEqThan(8); - lt[6][i].in[0] <== 14; - lt[6][i].in[1] <== in[i]; - lt[7][i] = LessEqThan(8); - lt[7][i].in[0] <== in[i]; - lt[7][i].in[1] <== 44; - and[5][i] = AND(); - and[5][i].a <== lt[6][i].out; - and[5][i].b <== lt[7][i].out; - lt[8][i] = LessEqThan(8); - lt[8][i].in[0] <== 123; - lt[8][i].in[1] <== in[i]; - lt[9][i] = LessEqThan(8); - lt[9][i].in[0] <== in[i]; - lt[9][i].in[1] <== 254; - and[6][i] = AND(); - and[6][i].a <== lt[8][i].out; - and[6][i].b <== lt[9][i].out; + eq[11][i].in[1] <== 227; eq[12][i] = IsEqual(); eq[12][i].in[0] <== in[i]; - eq[12][i].in[1] <== 47; + eq[12][i].in[1] <== 228; eq[13][i] = IsEqual(); eq[13][i].in[0] <== in[i]; - eq[13][i].in[1] <== 58; + eq[13][i].in[1] <== 229; eq[14][i] = IsEqual(); eq[14][i].in[0] <== in[i]; - eq[14][i].in[1] <== 59; + eq[14][i].in[1] <== 230; eq[15][i] = IsEqual(); eq[15][i].in[0] <== in[i]; - eq[15][i].in[1] <== 61; + eq[15][i].in[1] <== 231; eq[16][i] = IsEqual(); eq[16][i].in[0] <== in[i]; - eq[16][i].in[1] <== 63; + eq[16][i].in[1] <== 232; eq[17][i] = IsEqual(); eq[17][i].in[0] <== in[i]; - eq[17][i].in[1] <== 64; + eq[17][i].in[1] <== 233; eq[18][i] = IsEqual(); eq[18][i].in[0] <== in[i]; - eq[18][i].in[1] <== 91; + eq[18][i].in[1] <== 234; eq[19][i] = IsEqual(); eq[19][i].in[0] <== in[i]; - eq[19][i].in[1] <== 92; + eq[19][i].in[1] <== 235; eq[20][i] = IsEqual(); eq[20][i].in[0] <== in[i]; - eq[20][i].in[1] <== 93; + eq[20][i].in[1] <== 236; eq[21][i] = IsEqual(); eq[21][i].in[0] <== in[i]; - eq[21][i].in[1] <== 94; + eq[21][i].in[1] <== 238; eq[22][i] = IsEqual(); eq[22][i].in[0] <== in[i]; - eq[22][i].in[1] <== 96; - and[7][i] = AND(); - and[7][i].a <== states[i][2]; - multi_or[2][i] = MultiOR(25); - multi_or[2][i].in[0] <== and[5][i].out; - multi_or[2][i].in[1] <== and[6][i].out; - multi_or[2][i].in[2] <== eq[0][i].out; - multi_or[2][i].in[3] <== eq[1][i].out; - multi_or[2][i].in[4] <== eq[2][i].out; - multi_or[2][i].in[5] <== eq[3][i].out; - multi_or[2][i].in[6] <== eq[4][i].out; - multi_or[2][i].in[7] <== eq[5][i].out; - multi_or[2][i].in[8] <== eq[6][i].out; - multi_or[2][i].in[9] <== eq[7][i].out; - multi_or[2][i].in[10] <== eq[8][i].out; - multi_or[2][i].in[11] <== eq[9][i].out; - multi_or[2][i].in[12] <== eq[10][i].out; - multi_or[2][i].in[13] <== eq[11][i].out; - multi_or[2][i].in[14] <== eq[12][i].out; - multi_or[2][i].in[15] <== eq[13][i].out; - multi_or[2][i].in[16] <== eq[14][i].out; - multi_or[2][i].in[17] <== eq[15][i].out; - multi_or[2][i].in[18] <== eq[16][i].out; - multi_or[2][i].in[19] <== eq[17][i].out; - multi_or[2][i].in[20] <== eq[18][i].out; - multi_or[2][i].in[21] <== eq[19][i].out; - multi_or[2][i].in[22] <== eq[20][i].out; - multi_or[2][i].in[23] <== eq[21][i].out; - multi_or[2][i].in[24] <== eq[22][i].out; - and[7][i].b <== multi_or[2][i].out; - lt[10][i] = LessEqThan(8); - lt[10][i].in[0] <== 14; - lt[10][i].in[1] <== in[i]; - lt[11][i] = LessEqThan(8); - lt[11][i].in[0] <== in[i]; - lt[11][i].in[1] <== 59; - and[8][i] = AND(); - and[8][i].a <== lt[10][i].out; - and[8][i].b <== lt[11][i].out; + eq[22][i].in[1] <== 239; + and[15][i] = AND(); + and[15][i].a <== states[i][0]; + multi_or[3][i] = MultiOR(14); + multi_or[3][i].in[0] <== eq[9][i].out; + multi_or[3][i].in[1] <== eq[10][i].out; + multi_or[3][i].in[2] <== eq[11][i].out; + multi_or[3][i].in[3] <== eq[12][i].out; + multi_or[3][i].in[4] <== eq[13][i].out; + multi_or[3][i].in[5] <== eq[14][i].out; + multi_or[3][i].in[6] <== eq[15][i].out; + multi_or[3][i].in[7] <== eq[16][i].out; + multi_or[3][i].in[8] <== eq[17][i].out; + multi_or[3][i].in[9] <== eq[18][i].out; + multi_or[3][i].in[10] <== eq[19][i].out; + multi_or[3][i].in[11] <== eq[20][i].out; + multi_or[3][i].in[12] <== eq[21][i].out; + multi_or[3][i].in[13] <== eq[22][i].out; + and[15][i].b <== multi_or[3][i].out; lt[12][i] = LessEqThan(8); - lt[12][i].in[0] <== 61; + 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] <== 254; - and[9][i] = AND(); - and[9][i].a <== lt[12][i].out; - and[9][i].b <== lt[13][i].out; - and[10][i] = AND(); - and[10][i].a <== states[i][3]; - multi_or[3][i] = MultiOR(14); - multi_or[3][i].in[0] <== and[8][i].out; - multi_or[3][i].in[1] <== and[9][i].out; - multi_or[3][i].in[2] <== eq[0][i].out; - multi_or[3][i].in[3] <== eq[1][i].out; - multi_or[3][i].in[4] <== eq[2][i].out; - multi_or[3][i].in[5] <== eq[3][i].out; - multi_or[3][i].in[6] <== eq[4][i].out; - multi_or[3][i].in[7] <== eq[5][i].out; - multi_or[3][i].in[8] <== eq[6][i].out; - multi_or[3][i].in[9] <== eq[7][i].out; - multi_or[3][i].in[10] <== eq[8][i].out; - multi_or[3][i].in[11] <== eq[9][i].out; - multi_or[3][i].in[12] <== eq[10][i].out; - multi_or[3][i].in[13] <== eq[11][i].out; - and[10][i].b <== multi_or[3][i].out; - lt[14][i] = LessEqThan(8); - lt[14][i].in[0] <== 14; - lt[14][i].in[1] <== in[i]; - lt[15][i] = LessEqThan(8); - lt[15][i].in[0] <== in[i]; - lt[15][i].in[1] <== 32; - and[11][i] = AND(); - and[11][i].a <== lt[14][i].out; - and[11][i].b <== lt[15][i].out; - lt[16][i] = LessEqThan(8); - lt[16][i].in[0] <== 127; - lt[16][i].in[1] <== in[i]; - lt[17][i] = LessEqThan(8); - lt[17][i].in[0] <== in[i]; - lt[17][i].in[1] <== 254; - and[12][i] = AND(); - and[12][i].a <== lt[16][i].out; - and[12][i].b <== lt[17][i].out; + lt[13][i].in[1] <== 191; + and[16][i] = AND(); + and[16][i].a <== lt[12][i].out; + and[16][i].b <== lt[13][i].out; + and[17][i] = AND(); + and[17][i].a <== states[i][5]; + and[17][i].b <== and[16][i].out; + and[18][i] = AND(); + and[18][i].a <== states[i][6]; + and[18][i].b <== and[4][i].out; eq[23][i] = IsEqual(); eq[23][i].in[0] <== in[i]; - eq[23][i].in[1] <== 34; + eq[23][i].in[1] <== 128; eq[24][i] = IsEqual(); eq[24][i].in[0] <== in[i]; - eq[24][i].in[1] <== 40; + eq[24][i].in[1] <== 129; eq[25][i] = IsEqual(); eq[25][i].in[0] <== in[i]; - eq[25][i].in[1] <== 41; + eq[25][i].in[1] <== 130; eq[26][i] = IsEqual(); eq[26][i].in[0] <== in[i]; - eq[26][i].in[1] <== 44; + eq[26][i].in[1] <== 131; eq[27][i] = IsEqual(); eq[27][i].in[0] <== in[i]; - eq[27][i].in[1] <== 62; - and[13][i] = AND(); - and[13][i].a <== states[i][4]; - multi_or[4][i] = MultiOR(25); - multi_or[4][i].in[0] <== and[11][i].out; - multi_or[4][i].in[1] <== and[12][i].out; - multi_or[4][i].in[2] <== eq[0][i].out; - multi_or[4][i].in[3] <== eq[1][i].out; - multi_or[4][i].in[4] <== eq[2][i].out; - multi_or[4][i].in[5] <== eq[3][i].out; - multi_or[4][i].in[6] <== eq[4][i].out; - multi_or[4][i].in[7] <== eq[5][i].out; - multi_or[4][i].in[8] <== eq[6][i].out; - multi_or[4][i].in[9] <== eq[7][i].out; - multi_or[4][i].in[10] <== eq[8][i].out; - multi_or[4][i].in[11] <== eq[9][i].out; - multi_or[4][i].in[12] <== eq[10][i].out; - multi_or[4][i].in[13] <== eq[11][i].out; - multi_or[4][i].in[14] <== eq[23][i].out; - multi_or[4][i].in[15] <== eq[24][i].out; - multi_or[4][i].in[16] <== eq[25][i].out; - multi_or[4][i].in[17] <== eq[26][i].out; - multi_or[4][i].in[18] <== eq[13][i].out; - multi_or[4][i].in[19] <== eq[14][i].out; - multi_or[4][i].in[20] <== eq[27][i].out; - multi_or[4][i].in[21] <== eq[17][i].out; - multi_or[4][i].in[22] <== eq[18][i].out; - multi_or[4][i].in[23] <== eq[19][i].out; - multi_or[4][i].in[24] <== eq[20][i].out; - and[13][i].b <== multi_or[4][i].out; - and[14][i] = AND(); - and[14][i].a <== states[i][5]; - multi_or[5][i] = MultiOR(24); - multi_or[5][i].in[0] <== and[11][i].out; - multi_or[5][i].in[1] <== and[12][i].out; - multi_or[5][i].in[2] <== eq[0][i].out; - multi_or[5][i].in[3] <== eq[1][i].out; - multi_or[5][i].in[4] <== eq[2][i].out; - multi_or[5][i].in[5] <== eq[3][i].out; - multi_or[5][i].in[6] <== eq[4][i].out; - multi_or[5][i].in[7] <== eq[5][i].out; - multi_or[5][i].in[8] <== eq[6][i].out; - multi_or[5][i].in[9] <== eq[7][i].out; - multi_or[5][i].in[10] <== eq[8][i].out; - multi_or[5][i].in[11] <== eq[9][i].out; - multi_or[5][i].in[12] <== eq[10][i].out; - multi_or[5][i].in[13] <== eq[11][i].out; - multi_or[5][i].in[14] <== eq[23][i].out; - multi_or[5][i].in[15] <== eq[24][i].out; - multi_or[5][i].in[16] <== eq[25][i].out; - multi_or[5][i].in[17] <== eq[26][i].out; - multi_or[5][i].in[18] <== eq[13][i].out; - multi_or[5][i].in[19] <== eq[14][i].out; - multi_or[5][i].in[20] <== eq[27][i].out; - multi_or[5][i].in[21] <== eq[18][i].out; - multi_or[5][i].in[22] <== eq[19][i].out; - multi_or[5][i].in[23] <== eq[20][i].out; - and[14][i].b <== multi_or[5][i].out; - and[15][i] = AND(); - and[15][i].a <== states[i][6]; - multi_or[6][i] = MultiOR(26); - multi_or[6][i].in[0] <== and[5][i].out; - multi_or[6][i].in[1] <== and[6][i].out; - multi_or[6][i].in[2] <== eq[0][i].out; - multi_or[6][i].in[3] <== eq[1][i].out; - multi_or[6][i].in[4] <== eq[2][i].out; - multi_or[6][i].in[5] <== eq[3][i].out; - multi_or[6][i].in[6] <== eq[4][i].out; - multi_or[6][i].in[7] <== eq[5][i].out; - multi_or[6][i].in[8] <== eq[6][i].out; - multi_or[6][i].in[9] <== eq[7][i].out; - multi_or[6][i].in[10] <== eq[8][i].out; - multi_or[6][i].in[11] <== eq[9][i].out; - multi_or[6][i].in[12] <== eq[10][i].out; - multi_or[6][i].in[13] <== eq[11][i].out; - multi_or[6][i].in[14] <== eq[12][i].out; - multi_or[6][i].in[15] <== eq[13][i].out; - multi_or[6][i].in[16] <== eq[14][i].out; - multi_or[6][i].in[17] <== eq[15][i].out; - multi_or[6][i].in[18] <== eq[27][i].out; - multi_or[6][i].in[19] <== eq[16][i].out; - multi_or[6][i].in[20] <== eq[17][i].out; - multi_or[6][i].in[21] <== eq[18][i].out; - multi_or[6][i].in[22] <== eq[19][i].out; - multi_or[6][i].in[23] <== eq[20][i].out; - multi_or[6][i].in[24] <== eq[21][i].out; - multi_or[6][i].in[25] <== eq[22][i].out; - and[15][i].b <== multi_or[6][i].out; - multi_or[7][i] = MultiOR(7); - multi_or[7][i].in[0] <== and[2][i].out; - multi_or[7][i].in[1] <== and[4][i].out; - multi_or[7][i].in[2] <== and[7][i].out; - multi_or[7][i].in[3] <== and[10][i].out; - multi_or[7][i].in[4] <== and[13][i].out; - multi_or[7][i].in[5] <== and[14][i].out; - multi_or[7][i].in[6] <== and[15][i].out; - states[i+1][1] <== multi_or[7][i].out; - state_changed[i].in[0] <== states[i+1][1]; - lt[18][i] = LessEqThan(8); - lt[18][i].in[0] <== 65; - 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[16][i] = AND(); - and[16][i].a <== lt[18][i].out; - and[16][i].b <== lt[19][i].out; - lt[20][i] = LessEqThan(8); - lt[20][i].in[0] <== 97; - lt[20][i].in[1] <== in[i]; - lt[21][i] = LessEqThan(8); - lt[21][i].in[0] <== in[i]; - lt[21][i].in[1] <== 122; - and[17][i] = AND(); - and[17][i].a <== lt[20][i].out; - and[17][i].b <== lt[21][i].out; + eq[27][i].in[1] <== 132; eq[28][i] = IsEqual(); eq[28][i].in[0] <== in[i]; - eq[28][i].in[1] <== 45; + eq[28][i].in[1] <== 133; eq[29][i] = IsEqual(); eq[29][i].in[0] <== in[i]; - eq[29][i].in[1] <== 46; + eq[29][i].in[1] <== 134; eq[30][i] = IsEqual(); eq[30][i].in[0] <== in[i]; - eq[30][i].in[1] <== 48; + eq[30][i].in[1] <== 135; eq[31][i] = IsEqual(); eq[31][i].in[0] <== in[i]; - eq[31][i].in[1] <== 49; + eq[31][i].in[1] <== 136; eq[32][i] = IsEqual(); eq[32][i].in[0] <== in[i]; - eq[32][i].in[1] <== 50; + eq[32][i].in[1] <== 137; eq[33][i] = IsEqual(); eq[33][i].in[0] <== in[i]; - eq[33][i].in[1] <== 51; + eq[33][i].in[1] <== 138; eq[34][i] = IsEqual(); eq[34][i].in[0] <== in[i]; - eq[34][i].in[1] <== 52; + eq[34][i].in[1] <== 139; eq[35][i] = IsEqual(); eq[35][i].in[0] <== in[i]; - eq[35][i].in[1] <== 53; + eq[35][i].in[1] <== 140; eq[36][i] = IsEqual(); eq[36][i].in[0] <== in[i]; - eq[36][i].in[1] <== 54; + eq[36][i].in[1] <== 141; eq[37][i] = IsEqual(); eq[37][i].in[0] <== in[i]; - eq[37][i].in[1] <== 55; + eq[37][i].in[1] <== 142; eq[38][i] = IsEqual(); eq[38][i].in[0] <== in[i]; - eq[38][i].in[1] <== 56; - eq[39][i] = IsEqual(); - eq[39][i].in[0] <== in[i]; - eq[39][i].in[1] <== 57; - eq[40][i] = IsEqual(); - eq[40][i].in[0] <== in[i]; - eq[40][i].in[1] <== 95; - and[18][i] = AND(); - and[18][i].a <== states[i][2]; - multi_or[8][i] = MultiOR(15); - multi_or[8][i].in[0] <== and[16][i].out; - multi_or[8][i].in[1] <== and[17][i].out; - multi_or[8][i].in[2] <== eq[28][i].out; - multi_or[8][i].in[3] <== eq[29][i].out; - multi_or[8][i].in[4] <== eq[30][i].out; - multi_or[8][i].in[5] <== eq[31][i].out; - multi_or[8][i].in[6] <== eq[32][i].out; - multi_or[8][i].in[7] <== eq[33][i].out; - multi_or[8][i].in[8] <== eq[34][i].out; - multi_or[8][i].in[9] <== eq[35][i].out; - multi_or[8][i].in[10] <== eq[36][i].out; - multi_or[8][i].in[11] <== eq[37][i].out; - multi_or[8][i].in[12] <== eq[38][i].out; - multi_or[8][i].in[13] <== eq[39][i].out; - multi_or[8][i].in[14] <== eq[40][i].out; - and[18][i].b <== multi_or[8][i].out; + eq[38][i].in[1] <== 143; and[19][i] = AND(); - and[19][i].a <== states[i][6]; - and[19][i].b <== multi_or[8][i].out; - multi_or[9][i] = MultiOR(2); - multi_or[9][i].in[0] <== and[18][i].out; - multi_or[9][i].in[1] <== and[19][i].out; - states[i+1][2] <== multi_or[9][i].out; - state_changed[i].in[1] <== states[i+1][2]; + and[19][i].a <== states[i][7]; + multi_or[4][i] = MultiOR(16); + multi_or[4][i].in[0] <== eq[23][i].out; + multi_or[4][i].in[1] <== eq[24][i].out; + multi_or[4][i].in[2] <== eq[25][i].out; + multi_or[4][i].in[3] <== eq[26][i].out; + multi_or[4][i].in[4] <== eq[27][i].out; + multi_or[4][i].in[5] <== eq[28][i].out; + multi_or[4][i].in[6] <== eq[29][i].out; + multi_or[4][i].in[7] <== eq[30][i].out; + multi_or[4][i].in[8] <== eq[31][i].out; + multi_or[4][i].in[9] <== eq[32][i].out; + multi_or[4][i].in[10] <== eq[33][i].out; + multi_or[4][i].in[11] <== eq[34][i].out; + multi_or[4][i].in[12] <== eq[35][i].out; + multi_or[4][i].in[13] <== eq[36][i].out; + multi_or[4][i].in[14] <== eq[37][i].out; + multi_or[4][i].in[15] <== eq[38][i].out; + and[19][i].b <== multi_or[4][i].out; and[20][i] = AND(); - and[20][i].a <== states[i][2]; - and[20][i].b <== eq[27][i].out; - states[i+1][3] <== and[20][i].out; - state_changed[i].in[2] <== states[i+1][3]; - eq[41][i] = IsEqual(); - eq[41][i].in[0] <== in[i]; - eq[41][i].in[1] <== 60; + and[20][i].a <== states[i][8]; + and[20][i].b <== multi_or[3][i].out; and[21][i] = AND(); - and[21][i].a <== states[i][1]; - and[21][i].b <== eq[41][i].out; + and[21][i].a <== states[i][9]; + and[21][i].b <== multi_or[3][i].out; + multi_or[5][i] = MultiOR(6); + multi_or[5][i].in[0] <== and[15][i].out; + multi_or[5][i].in[1] <== and[17][i].out; + multi_or[5][i].in[2] <== and[18][i].out; + multi_or[5][i].in[3] <== and[19][i].out; + multi_or[5][i].in[4] <== and[20][i].out; + multi_or[5][i].in[5] <== and[21][i].out; + states[i+1][3] <== multi_or[5][i].out; + state_changed[i].in[2] <== states[i+1][3]; + eq[39][i] = IsEqual(); + eq[39][i].in[0] <== in[i]; + eq[39][i].in[1] <== 237; and[22][i] = AND(); - and[22][i].a <== states[i][2]; - and[22][i].b <== eq[41][i].out; + and[22][i].a <== states[i][0]; + and[22][i].b <== eq[39][i].out; and[23][i] = AND(); - and[23][i].a <== states[i][3]; - and[23][i].b <== eq[41][i].out; + and[23][i].a <== states[i][8]; + and[23][i].b <== eq[39][i].out; and[24][i] = AND(); - and[24][i].a <== states[i][4]; - and[24][i].b <== eq[41][i].out; + and[24][i].a <== states[i][9]; + and[24][i].b <== eq[39][i].out; + multi_or[6][i] = MultiOR(3); + multi_or[6][i].in[0] <== and[22][i].out; + multi_or[6][i].in[1] <== and[23][i].out; + multi_or[6][i].in[2] <== and[24][i].out; + states[i+1][4] <== multi_or[6][i].out; + state_changed[i].in[3] <== states[i+1][4]; + eq[40][i] = IsEqual(); + eq[40][i].in[0] <== in[i]; + eq[40][i].in[1] <== 240; and[25][i] = AND(); - and[25][i].a <== states[i][5]; - and[25][i].b <== eq[41][i].out; + and[25][i].a <== states[i][0]; + and[25][i].b <== eq[40][i].out; and[26][i] = AND(); - and[26][i].a <== states[i][6]; - and[26][i].b <== eq[41][i].out; - multi_or[10][i] = MultiOR(6); - multi_or[10][i].in[0] <== and[21][i].out; - multi_or[10][i].in[1] <== and[22][i].out; - multi_or[10][i].in[2] <== and[23][i].out; - multi_or[10][i].in[3] <== and[24][i].out; - multi_or[10][i].in[4] <== and[25][i].out; - multi_or[10][i].in[5] <== and[26][i].out; - states[i+1][4] <== multi_or[10][i].out; - state_changed[i].in[3] <== states[i+1][4]; - lt[22][i] = LessEqThan(8); - lt[22][i].in[0] <== 94; - lt[22][i].in[1] <== in[i]; - lt[23][i] = LessEqThan(8); - lt[23][i].in[0] <== in[i]; - lt[23][i].in[1] <== 126; + and[26][i].a <== states[i][8]; + and[26][i].b <== eq[40][i].out; and[27][i] = AND(); - and[27][i].a <== lt[22][i].out; - and[27][i].b <== lt[23][i].out; + and[27][i].a <== states[i][9]; + and[27][i].b <== eq[40][i].out; + multi_or[7][i] = MultiOR(3); + multi_or[7][i].in[0] <== and[25][i].out; + multi_or[7][i].in[1] <== and[26][i].out; + multi_or[7][i].in[2] <== and[27][i].out; + states[i+1][5] <== multi_or[7][i].out; + state_changed[i].in[4] <== states[i+1][5]; + eq[41][i] = IsEqual(); + eq[41][i].in[0] <== in[i]; + eq[41][i].in[1] <== 241; eq[42][i] = IsEqual(); eq[42][i].in[0] <== in[i]; - eq[42][i].in[1] <== 33; + eq[42][i].in[1] <== 242; eq[43][i] = IsEqual(); eq[43][i].in[0] <== in[i]; - eq[43][i].in[1] <== 35; + eq[43][i].in[1] <== 243; + and[28][i] = AND(); + and[28][i].a <== states[i][0]; + multi_or[8][i] = MultiOR(3); + multi_or[8][i].in[0] <== eq[41][i].out; + multi_or[8][i].in[1] <== eq[42][i].out; + multi_or[8][i].in[2] <== eq[43][i].out; + and[28][i].b <== multi_or[8][i].out; + and[29][i] = AND(); + and[29][i].a <== states[i][8]; + and[29][i].b <== multi_or[8][i].out; + and[30][i] = AND(); + and[30][i].a <== states[i][9]; + and[30][i].b <== multi_or[8][i].out; + multi_or[9][i] = MultiOR(3); + multi_or[9][i].in[0] <== and[28][i].out; + multi_or[9][i].in[1] <== and[29][i].out; + multi_or[9][i].in[2] <== and[30][i].out; + states[i+1][6] <== multi_or[9][i].out; + state_changed[i].in[5] <== states[i+1][6]; eq[44][i] = IsEqual(); eq[44][i].in[0] <== in[i]; - eq[44][i].in[1] <== 36; + eq[44][i].in[1] <== 244; + and[31][i] = AND(); + and[31][i].a <== states[i][0]; + and[31][i].b <== eq[44][i].out; + and[32][i] = AND(); + and[32][i].a <== states[i][8]; + and[32][i].b <== eq[44][i].out; + and[33][i] = AND(); + and[33][i].a <== states[i][9]; + and[33][i].b <== eq[44][i].out; + multi_or[10][i] = MultiOR(3); + multi_or[10][i].in[0] <== and[31][i].out; + multi_or[10][i].in[1] <== and[32][i].out; + multi_or[10][i].in[2] <== and[33][i].out; + states[i+1][7] <== multi_or[10][i].out; + state_changed[i].in[6] <== states[i+1][7]; + lt[14][i] = LessEqThan(8); + lt[14][i].in[0] <== 14; + lt[14][i].in[1] <== in[i]; + lt[15][i] = LessEqThan(8); + lt[15][i].in[0] <== in[i]; + lt[15][i].in[1] <== 93; + and[34][i] = AND(); + and[34][i].a <== lt[14][i].out; + and[34][i].b <== lt[15][i].out; + lt[16][i] = LessEqThan(8); + lt[16][i].in[0] <== 95; + lt[16][i].in[1] <== in[i]; + lt[17][i] = LessEqThan(8); + lt[17][i].in[0] <== in[i]; + lt[17][i].in[1] <== 127; + and[35][i] = AND(); + and[35][i].a <== lt[16][i].out; + and[35][i].b <== lt[17][i].out; eq[45][i] = IsEqual(); eq[45][i].in[0] <== in[i]; - eq[45][i].in[1] <== 37; + eq[45][i].in[1] <== 0; eq[46][i] = IsEqual(); eq[46][i].in[0] <== in[i]; - eq[46][i].in[1] <== 38; + eq[46][i].in[1] <== 1; eq[47][i] = IsEqual(); eq[47][i].in[0] <== in[i]; - eq[47][i].in[1] <== 39; + eq[47][i].in[1] <== 2; eq[48][i] = IsEqual(); eq[48][i].in[0] <== in[i]; - eq[48][i].in[1] <== 42; + eq[48][i].in[1] <== 3; eq[49][i] = IsEqual(); eq[49][i].in[0] <== in[i]; - eq[49][i].in[1] <== 43; - and[28][i] = AND(); - and[28][i].a <== states[i][4]; - multi_or[11][i] = MultiOR(25); - multi_or[11][i].in[0] <== and[16][i].out; - multi_or[11][i].in[1] <== and[27][i].out; - multi_or[11][i].in[2] <== eq[42][i].out; - multi_or[11][i].in[3] <== eq[43][i].out; - multi_or[11][i].in[4] <== eq[44][i].out; - multi_or[11][i].in[5] <== eq[45][i].out; - multi_or[11][i].in[6] <== eq[46][i].out; - multi_or[11][i].in[7] <== eq[47][i].out; - multi_or[11][i].in[8] <== eq[48][i].out; - multi_or[11][i].in[9] <== eq[49][i].out; - multi_or[11][i].in[10] <== eq[28][i].out; - multi_or[11][i].in[11] <== eq[29][i].out; - multi_or[11][i].in[12] <== eq[12][i].out; - multi_or[11][i].in[13] <== eq[30][i].out; - multi_or[11][i].in[14] <== eq[31][i].out; - multi_or[11][i].in[15] <== eq[32][i].out; - multi_or[11][i].in[16] <== eq[33][i].out; - multi_or[11][i].in[17] <== eq[34][i].out; - multi_or[11][i].in[18] <== eq[35][i].out; - multi_or[11][i].in[19] <== eq[36][i].out; - multi_or[11][i].in[20] <== eq[37][i].out; - multi_or[11][i].in[21] <== eq[38][i].out; - multi_or[11][i].in[22] <== eq[39][i].out; - multi_or[11][i].in[23] <== eq[15][i].out; - multi_or[11][i].in[24] <== eq[16][i].out; - and[28][i].b <== multi_or[11][i].out; - and[29][i] = AND(); - and[29][i].a <== states[i][5]; - and[29][i].b <== multi_or[11][i].out; - multi_or[12][i] = MultiOR(2); - multi_or[12][i].in[0] <== and[28][i].out; - multi_or[12][i].in[1] <== and[29][i].out; - states[i+1][5] <== multi_or[12][i].out; - state_changed[i].in[4] <== states[i+1][5]; - and[30][i] = AND(); - and[30][i].a <== states[i][5]; - and[30][i].b <== eq[17][i].out; - states[i+1][6] <== and[30][i].out; - state_changed[i].in[5] <== states[i+1][6]; + eq[49][i].in[1] <== 4; + eq[50][i] = IsEqual(); + eq[50][i].in[0] <== in[i]; + eq[50][i].in[1] <== 5; + eq[51][i] = IsEqual(); + eq[51][i].in[0] <== in[i]; + eq[51][i].in[1] <== 6; + eq[52][i] = IsEqual(); + eq[52][i].in[0] <== in[i]; + eq[52][i].in[1] <== 7; + eq[53][i] = IsEqual(); + eq[53][i].in[0] <== in[i]; + eq[53][i].in[1] <== 8; + eq[54][i] = IsEqual(); + eq[54][i].in[0] <== in[i]; + eq[54][i].in[1] <== 9; + eq[55][i] = IsEqual(); + eq[55][i].in[0] <== in[i]; + eq[55][i].in[1] <== 11; + eq[56][i] = IsEqual(); + eq[56][i].in[0] <== in[i]; + eq[56][i].in[1] <== 12; + eq[57][i] = IsEqual(); + eq[57][i].in[0] <== in[i]; + eq[57][i].in[1] <== 255; + and[36][i] = AND(); + and[36][i].a <== states[i][0]; + multi_or[11][i] = MultiOR(15); + multi_or[11][i].in[0] <== and[34][i].out; + multi_or[11][i].in[1] <== and[35][i].out; + multi_or[11][i].in[2] <== eq[45][i].out; + multi_or[11][i].in[3] <== eq[46][i].out; + multi_or[11][i].in[4] <== eq[47][i].out; + multi_or[11][i].in[5] <== eq[48][i].out; + multi_or[11][i].in[6] <== eq[49][i].out; + multi_or[11][i].in[7] <== eq[50][i].out; + multi_or[11][i].in[8] <== eq[51][i].out; + multi_or[11][i].in[9] <== eq[52][i].out; + multi_or[11][i].in[10] <== eq[53][i].out; + multi_or[11][i].in[11] <== eq[54][i].out; + multi_or[11][i].in[12] <== eq[55][i].out; + multi_or[11][i].in[13] <== eq[56][i].out; + multi_or[11][i].in[14] <== eq[57][i].out; + and[36][i].b <== multi_or[11][i].out; + and[37][i] = AND(); + and[37][i].a <== states[i][1]; + and[37][i].b <== and[4][i].out; + and[38][i] = AND(); + and[38][i].a <== states[i][8]; + multi_or[12][i] = MultiOR(14); + multi_or[12][i].in[0] <== and[34][i].out; + multi_or[12][i].in[1] <== and[35][i].out; + multi_or[12][i].in[2] <== eq[45][i].out; + multi_or[12][i].in[3] <== eq[46][i].out; + multi_or[12][i].in[4] <== eq[47][i].out; + multi_or[12][i].in[5] <== eq[48][i].out; + multi_or[12][i].in[6] <== eq[49][i].out; + multi_or[12][i].in[7] <== eq[50][i].out; + multi_or[12][i].in[8] <== eq[51][i].out; + multi_or[12][i].in[9] <== eq[52][i].out; + multi_or[12][i].in[10] <== eq[53][i].out; + multi_or[12][i].in[11] <== eq[54][i].out; + multi_or[12][i].in[12] <== eq[55][i].out; + multi_or[12][i].in[13] <== eq[56][i].out; + and[38][i].b <== multi_or[12][i].out; + lt[18][i] = LessEqThan(8); + lt[18][i].in[0] <== 14; + lt[18][i].in[1] <== in[i]; + lt[19][i] = LessEqThan(8); + lt[19][i].in[0] <== in[i]; + lt[19][i].in[1] <== 32; + and[39][i] = AND(); + and[39][i].a <== lt[18][i].out; + and[39][i].b <== lt[19][i].out; + eq[58][i] = IsEqual(); + eq[58][i].in[0] <== in[i]; + eq[58][i].in[1] <== 34; + eq[59][i] = IsEqual(); + eq[59][i].in[0] <== in[i]; + eq[59][i].in[1] <== 40; + eq[60][i] = IsEqual(); + eq[60][i].in[0] <== in[i]; + eq[60][i].in[1] <== 41; + and[40][i] = AND(); + and[40][i].a <== states[i][9]; + multi_or[13][i] = MultiOR(18); + multi_or[13][i].in[0] <== and[39][i].out; + multi_or[13][i].in[1] <== eq[45][i].out; + multi_or[13][i].in[2] <== eq[46][i].out; + multi_or[13][i].in[3] <== eq[47][i].out; + multi_or[13][i].in[4] <== eq[48][i].out; + multi_or[13][i].in[5] <== eq[49][i].out; + multi_or[13][i].in[6] <== eq[50][i].out; + multi_or[13][i].in[7] <== eq[51][i].out; + multi_or[13][i].in[8] <== eq[52][i].out; + multi_or[13][i].in[9] <== eq[53][i].out; + multi_or[13][i].in[10] <== eq[54][i].out; + multi_or[13][i].in[11] <== eq[55][i].out; + multi_or[13][i].in[12] <== eq[56][i].out; + multi_or[13][i].in[13] <== eq[58][i].out; + multi_or[13][i].in[14] <== eq[59][i].out; + multi_or[13][i].in[15] <== eq[60][i].out; + multi_or[13][i].in[16] <== eq[0][i].out; + multi_or[13][i].in[17] <== eq[1][i].out; + and[40][i].b <== multi_or[13][i].out; + multi_or[14][i] = MultiOR(4); + multi_or[14][i].in[0] <== and[36][i].out; + multi_or[14][i].in[1] <== and[37][i].out; + multi_or[14][i].in[2] <== and[38][i].out; + multi_or[14][i].in[3] <== and[40][i].out; + states[i+1][8] <== multi_or[14][i].out; + state_changed[i].in[7] <== states[i+1][8]; + and[41][i] = AND(); + and[41][i].a <== states[i][8]; + and[41][i].b <== eq[2][i].out; + and[42][i] = AND(); + and[42][i].a <== states[i][9]; + and[42][i].b <== eq[2][i].out; + multi_or[15][i] = MultiOR(2); + multi_or[15][i].in[0] <== and[41][i].out; + multi_or[15][i].in[1] <== and[42][i].out; + states[i+1][9] <== multi_or[15][i].out; + state_changed[i].in[8] <== states[i+1][9]; + lt[20][i] = LessEqThan(8); + lt[20][i].in[0] <== 65; + lt[20][i].in[1] <== in[i]; + lt[21][i] = LessEqThan(8); + lt[21][i].in[0] <== in[i]; + lt[21][i].in[1] <== 90; + and[43][i] = AND(); + and[43][i].a <== lt[20][i].out; + and[43][i].b <== lt[21][i].out; + lt[22][i] = LessEqThan(8); + lt[22][i].in[0] <== 94; + lt[22][i].in[1] <== in[i]; + lt[23][i] = LessEqThan(8); + lt[23][i].in[0] <== in[i]; + lt[23][i].in[1] <== 126; + and[44][i] = AND(); + and[44][i].a <== lt[22][i].out; + and[44][i].b <== lt[23][i].out; + eq[61][i] = IsEqual(); + eq[61][i].in[0] <== in[i]; + eq[61][i].in[1] <== 33; + eq[62][i] = IsEqual(); + eq[62][i].in[0] <== in[i]; + eq[62][i].in[1] <== 35; + eq[63][i] = IsEqual(); + eq[63][i].in[0] <== in[i]; + eq[63][i].in[1] <== 36; + eq[64][i] = IsEqual(); + eq[64][i].in[0] <== in[i]; + eq[64][i].in[1] <== 37; + eq[65][i] = IsEqual(); + eq[65][i].in[0] <== in[i]; + eq[65][i].in[1] <== 38; + eq[66][i] = IsEqual(); + eq[66][i].in[0] <== in[i]; + eq[66][i].in[1] <== 39; + eq[67][i] = IsEqual(); + eq[67][i].in[0] <== in[i]; + eq[67][i].in[1] <== 42; + eq[68][i] = IsEqual(); + eq[68][i].in[0] <== in[i]; + eq[68][i].in[1] <== 43; + eq[69][i] = IsEqual(); + eq[69][i].in[0] <== in[i]; + eq[69][i].in[1] <== 44; + eq[70][i] = IsEqual(); + eq[70][i].in[0] <== in[i]; + eq[70][i].in[1] <== 45; + eq[71][i] = IsEqual(); + eq[71][i].in[0] <== in[i]; + eq[71][i].in[1] <== 46; + eq[72][i] = IsEqual(); + eq[72][i].in[0] <== in[i]; + eq[72][i].in[1] <== 47; + eq[73][i] = IsEqual(); + eq[73][i].in[0] <== in[i]; + eq[73][i].in[1] <== 48; + eq[74][i] = IsEqual(); + eq[74][i].in[0] <== in[i]; + eq[74][i].in[1] <== 49; + eq[75][i] = IsEqual(); + eq[75][i].in[0] <== in[i]; + eq[75][i].in[1] <== 50; + eq[76][i] = IsEqual(); + eq[76][i].in[0] <== in[i]; + eq[76][i].in[1] <== 51; + eq[77][i] = IsEqual(); + eq[77][i].in[0] <== in[i]; + eq[77][i].in[1] <== 52; + eq[78][i] = IsEqual(); + eq[78][i].in[0] <== in[i]; + eq[78][i].in[1] <== 53; + eq[79][i] = IsEqual(); + eq[79][i].in[0] <== in[i]; + eq[79][i].in[1] <== 54; + eq[80][i] = IsEqual(); + eq[80][i].in[0] <== in[i]; + eq[80][i].in[1] <== 55; + eq[81][i] = IsEqual(); + eq[81][i].in[0] <== in[i]; + eq[81][i].in[1] <== 56; + eq[82][i] = IsEqual(); + eq[82][i].in[0] <== in[i]; + eq[82][i].in[1] <== 57; + eq[83][i] = IsEqual(); + eq[83][i].in[0] <== in[i]; + eq[83][i].in[1] <== 61; + eq[84][i] = IsEqual(); + eq[84][i].in[0] <== in[i]; + eq[84][i].in[1] <== 63; + and[45][i] = AND(); + and[45][i].a <== states[i][9]; + multi_or[16][i] = MultiOR(26); + multi_or[16][i].in[0] <== and[43][i].out; + multi_or[16][i].in[1] <== and[44][i].out; + multi_or[16][i].in[2] <== eq[61][i].out; + multi_or[16][i].in[3] <== eq[62][i].out; + multi_or[16][i].in[4] <== eq[63][i].out; + multi_or[16][i].in[5] <== eq[64][i].out; + multi_or[16][i].in[6] <== eq[65][i].out; + multi_or[16][i].in[7] <== eq[66][i].out; + multi_or[16][i].in[8] <== eq[67][i].out; + multi_or[16][i].in[9] <== eq[68][i].out; + multi_or[16][i].in[10] <== eq[69][i].out; + multi_or[16][i].in[11] <== eq[70][i].out; + multi_or[16][i].in[12] <== eq[71][i].out; + multi_or[16][i].in[13] <== eq[72][i].out; + multi_or[16][i].in[14] <== eq[73][i].out; + multi_or[16][i].in[15] <== eq[74][i].out; + multi_or[16][i].in[16] <== eq[75][i].out; + multi_or[16][i].in[17] <== eq[76][i].out; + multi_or[16][i].in[18] <== eq[77][i].out; + multi_or[16][i].in[19] <== eq[78][i].out; + multi_or[16][i].in[20] <== eq[79][i].out; + multi_or[16][i].in[21] <== eq[80][i].out; + multi_or[16][i].in[22] <== eq[81][i].out; + multi_or[16][i].in[23] <== eq[82][i].out; + multi_or[16][i].in[24] <== eq[83][i].out; + multi_or[16][i].in[25] <== eq[84][i].out; + and[45][i].b <== multi_or[16][i].out; + and[46][i] = AND(); + and[46][i].a <== states[i][10]; + and[46][i].b <== multi_or[16][i].out; + multi_or[17][i] = MultiOR(2); + multi_or[17][i].in[0] <== and[45][i].out; + multi_or[17][i].in[1] <== and[46][i].out; + states[i+1][10] <== multi_or[17][i].out; + state_changed[i].in[9] <== states[i+1][10]; + and[47][i] = AND(); + and[47][i].a <== states[i][10]; + and[47][i].b <== eq[4][i].out; + states[i+1][11] <== and[47][i].out; + state_changed[i].in[10] <== states[i+1][11]; + 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[48][i] = AND(); + and[48][i].a <== lt[24][i].out; + and[48][i].b <== lt[25][i].out; + eq[85][i] = IsEqual(); + eq[85][i].in[0] <== in[i]; + eq[85][i].in[1] <== 95; + and[49][i] = AND(); + and[49][i].a <== states[i][11]; + multi_or[18][i] = MultiOR(15); + multi_or[18][i].in[0] <== and[43][i].out; + multi_or[18][i].in[1] <== and[48][i].out; + multi_or[18][i].in[2] <== eq[70][i].out; + multi_or[18][i].in[3] <== eq[71][i].out; + multi_or[18][i].in[4] <== eq[73][i].out; + multi_or[18][i].in[5] <== eq[74][i].out; + multi_or[18][i].in[6] <== eq[75][i].out; + multi_or[18][i].in[7] <== eq[76][i].out; + multi_or[18][i].in[8] <== eq[77][i].out; + multi_or[18][i].in[9] <== eq[78][i].out; + multi_or[18][i].in[10] <== eq[79][i].out; + multi_or[18][i].in[11] <== eq[80][i].out; + multi_or[18][i].in[12] <== eq[81][i].out; + multi_or[18][i].in[13] <== eq[82][i].out; + multi_or[18][i].in[14] <== eq[85][i].out; + and[49][i].b <== multi_or[18][i].out; + and[50][i] = AND(); + and[50][i].a <== states[i][12]; + and[50][i].b <== multi_or[18][i].out; + multi_or[19][i] = MultiOR(2); + multi_or[19][i].in[0] <== and[49][i].out; + multi_or[19][i].in[1] <== and[50][i].out; + states[i+1][12] <== multi_or[19][i].out; + state_changed[i].in[11] <== states[i+1][12]; + and[51][i] = AND(); + and[51][i].a <== states[i][12]; + and[51][i].b <== eq[3][i].out; + states[i+1][13] <== and[51][i].out; + state_changed[i].in[12] <== states[i+1][13]; states[i+1][0] <== 1 - state_changed[i].out; } component final_state_result = MultiOR(num_bytes+1); for (var i = 0; i <= num_bytes; i++) { - final_state_result.in[i] <== states[i][3]; + final_state_result.in[i] <== states[i][13]; } out <== final_state_result.out; - signal is_consecutive[msg_bytes+1][2]; is_consecutive[msg_bytes][1] <== 1; for (var i = 0; i < msg_bytes; i++) { - is_consecutive[msg_bytes-1-i][0] <== states[num_bytes-i][3] * (1 - is_consecutive[msg_bytes-i][1]) + is_consecutive[msg_bytes-i][1]; + is_consecutive[msg_bytes-1-i][0] <== states[num_bytes-i][13] * (1 - is_consecutive[msg_bytes-i][1]) + is_consecutive[msg_bytes-i][1]; is_consecutive[msg_bytes-1-i][1] <== state_changed[msg_bytes-i].out * is_consecutive[msg_bytes-1-i][0]; } - signal is_substr0[msg_bytes][10]; + // substrings calculated: [{(9, 10), (10, 10), (10, 11), (11, 12), (12, 12)}] + signal is_substr0[msg_bytes][6]; signal is_reveal0[msg_bytes]; signal output reveal0[msg_bytes]; for (var i = 0; i < msg_bytes; i++) { is_substr0[i][0] <== 0; - // the 0-th substring transitions: [(2, 2), (2, 4), (4, 4), (4, 5), (5, 4), (5, 5), (5, 6), (6, 2), (6, 4)] - is_substr0[i][1] <== is_substr0[i][0] + states[i+1][2] * states[i+2][2]; - is_substr0[i][2] <== is_substr0[i][1] + states[i+1][2] * states[i+2][4]; - is_substr0[i][3] <== is_substr0[i][2] + states[i+1][4] * states[i+2][4]; - is_substr0[i][4] <== is_substr0[i][3] + states[i+1][4] * states[i+2][5]; - is_substr0[i][5] <== is_substr0[i][4] + states[i+1][5] * states[i+2][4]; - is_substr0[i][6] <== is_substr0[i][5] + states[i+1][5] * states[i+2][5]; - is_substr0[i][7] <== is_substr0[i][6] + states[i+1][5] * states[i+2][6]; - is_substr0[i][8] <== is_substr0[i][7] + states[i+1][6] * states[i+2][2]; - is_substr0[i][9] <== is_substr0[i][8] + states[i+1][6] * states[i+2][4]; - is_reveal0[i] <== is_substr0[i][9] * is_consecutive[i][1]; + // the 0-th substring transitions: [(9, 10), (10, 10), (10, 11), (11, 12), (12, 12)] + is_substr0[i][1] <== is_substr0[i][0] + states[i+1][9] * states[i+2][10]; + is_substr0[i][2] <== is_substr0[i][1] + states[i+1][10] * states[i+2][10]; + is_substr0[i][3] <== is_substr0[i][2] + states[i+1][10] * states[i+2][11]; + is_substr0[i][4] <== is_substr0[i][3] + states[i+1][11] * states[i+2][12]; + is_substr0[i][5] <== is_substr0[i][4] + states[i+1][12] * states[i+2][12]; + is_reveal0[i] <== is_substr0[i][5] * is_consecutive[i][1]; reveal0[i] <== in[i+1] * is_reveal0[i]; } } \ No newline at end of file diff --git a/packages/circom/circuits/common/email_domain.json b/packages/circom/circuits/common/email_domain.json index fb60f82..82f0330 100644 --- a/packages/circom/circuits/common/email_domain.json +++ b/packages/circom/circuits/common/email_domain.json @@ -1,16 +1,16 @@ { - "parts": [ - { - "is_public": false, - "regex_def": "(a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z|A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z|0|1|2|3|4|5|6|7|8|9|!|#|$|%|&|'|\\*|\\+|-|/|=|\\?|^|_|`|{|\\||}|~|\\.)+" - }, - { - "is_public": false, - "regex_def": "@" - }, - { - "is_public": true, - "regex_def": "(a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z|A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z|0|1|2|3|4|5|6|7|8|9|\\.|-)+" - } - ] -} \ No newline at end of file + "parts": [ + { + "is_public": false, + "regex_def": "[A-Za-z0-9!#$%&'*+-/=?^_`{\\|}~\\.]+" + }, + { + "is_public": false, + "regex_def": "@" + }, + { + "is_public": true, + "regex_def": "[A-Za-z0-9\\.-]+" + } + ] +} diff --git a/packages/circom/circuits/common/email_domain_regex.circom b/packages/circom/circuits/common/email_domain_regex.circom index 620116a..cb582f2 100644 --- a/packages/circom/circuits/common/email_domain_regex.circom +++ b/packages/circom/circuits/common/email_domain_regex.circom @@ -2,7 +2,7 @@ pragma circom 2.1.5; include "@zk-email/zk-regex-circom/circuits/regex_helpers.circom"; -// regex: (a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z|A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z|0|1|2|3|4|5|6|7|8|9|!|#|$|%|&|'|\*|\+|-|/|=|\?|^|_|`|{|\||}|~|\.)+@(a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z|A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z|0|1|2|3|4|5|6|7|8|9|\.|-)+ +// regex: [A-Za-z0-9!#$%&'*+-/=?^_`{\|}~\.]+@[A-Za-z0-9\.-]+ template EmailDomainRegex(msg_bytes) { signal input msg[msg_bytes]; signal output out; @@ -14,7 +14,7 @@ template EmailDomainRegex(msg_bytes) { in[i+1] <== msg[i]; } - component eq[25][num_bytes]; + component eq[26][num_bytes]; component lt[8][num_bytes]; component and[9][num_bytes]; component multi_or[5][num_bytes]; @@ -72,55 +72,58 @@ template EmailDomainRegex(msg_bytes) { eq[7][i].in[1] <== 43; eq[8][i] = IsEqual(); eq[8][i].in[0] <== in[i]; - eq[8][i].in[1] <== 45; + eq[8][i].in[1] <== 44; eq[9][i] = IsEqual(); eq[9][i].in[0] <== in[i]; - eq[9][i].in[1] <== 46; + eq[9][i].in[1] <== 45; eq[10][i] = IsEqual(); eq[10][i].in[0] <== in[i]; - eq[10][i].in[1] <== 47; + eq[10][i].in[1] <== 46; eq[11][i] = IsEqual(); eq[11][i].in[0] <== in[i]; - eq[11][i].in[1] <== 48; + eq[11][i].in[1] <== 47; eq[12][i] = IsEqual(); eq[12][i].in[0] <== in[i]; - eq[12][i].in[1] <== 49; + eq[12][i].in[1] <== 48; eq[13][i] = IsEqual(); eq[13][i].in[0] <== in[i]; - eq[13][i].in[1] <== 50; + eq[13][i].in[1] <== 49; eq[14][i] = IsEqual(); eq[14][i].in[0] <== in[i]; - eq[14][i].in[1] <== 51; + eq[14][i].in[1] <== 50; eq[15][i] = IsEqual(); eq[15][i].in[0] <== in[i]; - eq[15][i].in[1] <== 52; + eq[15][i].in[1] <== 51; eq[16][i] = IsEqual(); eq[16][i].in[0] <== in[i]; - eq[16][i].in[1] <== 53; + eq[16][i].in[1] <== 52; eq[17][i] = IsEqual(); eq[17][i].in[0] <== in[i]; - eq[17][i].in[1] <== 54; + eq[17][i].in[1] <== 53; eq[18][i] = IsEqual(); eq[18][i].in[0] <== in[i]; - eq[18][i].in[1] <== 55; + eq[18][i].in[1] <== 54; eq[19][i] = IsEqual(); eq[19][i].in[0] <== in[i]; - eq[19][i].in[1] <== 56; + eq[19][i].in[1] <== 55; eq[20][i] = IsEqual(); eq[20][i].in[0] <== in[i]; - eq[20][i].in[1] <== 57; + eq[20][i].in[1] <== 56; eq[21][i] = IsEqual(); eq[21][i].in[0] <== in[i]; - eq[21][i].in[1] <== 61; + eq[21][i].in[1] <== 57; eq[22][i] = IsEqual(); eq[22][i].in[0] <== in[i]; - eq[22][i].in[1] <== 63; + eq[22][i].in[1] <== 61; eq[23][i] = IsEqual(); eq[23][i].in[0] <== in[i]; - eq[23][i].in[1] <== 255; + eq[23][i].in[1] <== 63; + eq[24][i] = IsEqual(); + eq[24][i].in[0] <== in[i]; + eq[24][i].in[1] <== 255; and[2][i] = AND(); and[2][i].a <== states[i][0]; - multi_or[0][i] = MultiOR(26); + multi_or[0][i] = MultiOR(27); multi_or[0][i].in[0] <== and[0][i].out; multi_or[0][i].in[1] <== and[1][i].out; multi_or[0][i].in[2] <== eq[0][i].out; @@ -147,6 +150,7 @@ template EmailDomainRegex(msg_bytes) { multi_or[0][i].in[23] <== eq[21][i].out; multi_or[0][i].in[24] <== eq[22][i].out; multi_or[0][i].in[25] <== eq[23][i].out; + multi_or[0][i].in[26] <== eq[24][i].out; and[2][i].b <== multi_or[0][i].out; lt[4][i] = LessEqThan(8); lt[4][i].in[0] <== 94; @@ -159,7 +163,7 @@ template EmailDomainRegex(msg_bytes) { and[3][i].b <== lt[5][i].out; and[4][i] = AND(); and[4][i].a <== states[i][1]; - multi_or[1][i] = MultiOR(25); + multi_or[1][i] = MultiOR(26); multi_or[1][i].in[0] <== and[0][i].out; multi_or[1][i].in[1] <== and[3][i].out; multi_or[1][i].in[2] <== eq[0][i].out; @@ -185,18 +189,19 @@ template EmailDomainRegex(msg_bytes) { multi_or[1][i].in[22] <== eq[20][i].out; multi_or[1][i].in[23] <== eq[21][i].out; multi_or[1][i].in[24] <== eq[22][i].out; + multi_or[1][i].in[25] <== eq[23][i].out; and[4][i].b <== multi_or[1][i].out; multi_or[2][i] = MultiOR(2); multi_or[2][i].in[0] <== and[2][i].out; multi_or[2][i].in[1] <== and[4][i].out; states[i+1][1] <== multi_or[2][i].out; state_changed[i].in[0] <== states[i+1][1]; - eq[24][i] = IsEqual(); - eq[24][i].in[0] <== in[i]; - eq[24][i].in[1] <== 64; + eq[25][i] = IsEqual(); + eq[25][i].in[0] <== in[i]; + eq[25][i].in[1] <== 64; and[5][i] = AND(); and[5][i].a <== states[i][1]; - and[5][i].b <== eq[24][i].out; + and[5][i].b <== eq[25][i].out; states[i+1][2] <== and[5][i].out; state_changed[i].in[1] <== states[i+1][2]; lt[6][i] = LessEqThan(8); @@ -213,18 +218,18 @@ template EmailDomainRegex(msg_bytes) { multi_or[3][i] = MultiOR(14); multi_or[3][i].in[0] <== and[0][i].out; multi_or[3][i].in[1] <== and[6][i].out; - multi_or[3][i].in[2] <== eq[8][i].out; - multi_or[3][i].in[3] <== eq[9][i].out; - multi_or[3][i].in[4] <== eq[11][i].out; - multi_or[3][i].in[5] <== eq[12][i].out; - multi_or[3][i].in[6] <== eq[13][i].out; - multi_or[3][i].in[7] <== eq[14][i].out; - multi_or[3][i].in[8] <== eq[15][i].out; - multi_or[3][i].in[9] <== eq[16][i].out; - multi_or[3][i].in[10] <== eq[17][i].out; - multi_or[3][i].in[11] <== eq[18][i].out; - multi_or[3][i].in[12] <== eq[19][i].out; - multi_or[3][i].in[13] <== eq[20][i].out; + multi_or[3][i].in[2] <== eq[9][i].out; + multi_or[3][i].in[3] <== eq[10][i].out; + multi_or[3][i].in[4] <== eq[12][i].out; + multi_or[3][i].in[5] <== eq[13][i].out; + multi_or[3][i].in[6] <== eq[14][i].out; + multi_or[3][i].in[7] <== eq[15][i].out; + multi_or[3][i].in[8] <== eq[16][i].out; + multi_or[3][i].in[9] <== eq[17][i].out; + multi_or[3][i].in[10] <== eq[18][i].out; + multi_or[3][i].in[11] <== eq[19][i].out; + multi_or[3][i].in[12] <== eq[20][i].out; + multi_or[3][i].in[13] <== eq[21][i].out; and[7][i].b <== multi_or[3][i].out; and[8][i] = AND(); and[8][i].a <== states[i][3]; @@ -242,13 +247,13 @@ template EmailDomainRegex(msg_bytes) { final_state_result.in[i] <== states[i][3]; } out <== final_state_result.out; - signal is_consecutive[msg_bytes+1][2]; is_consecutive[msg_bytes][1] <== 1; for (var i = 0; i < msg_bytes; i++) { is_consecutive[msg_bytes-1-i][0] <== states[num_bytes-i][3] * (1 - is_consecutive[msg_bytes-i][1]) + is_consecutive[msg_bytes-i][1]; is_consecutive[msg_bytes-1-i][1] <== state_changed[msg_bytes-i].out * is_consecutive[msg_bytes-1-i][0]; } + // substrings calculated: [{(2, 3), (3, 3)}] signal is_substr0[msg_bytes][3]; signal is_reveal0[msg_bytes]; signal output reveal0[msg_bytes]; diff --git a/packages/circom/circuits/common/from_addr.json b/packages/circom/circuits/common/from_addr.json index 584c66c..7fdc28e 100644 --- a/packages/circom/circuits/common/from_addr.json +++ b/packages/circom/circuits/common/from_addr.json @@ -1,20 +1,20 @@ { - "parts": [ - { - "is_public": false, - "regex_def": "((\r\n)|^)from:" - }, - { - "is_public": false, - "regex_def": "([^\r\n]+<)?" - }, - { - "is_public": true, - "regex_def": "(a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z|A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z|0|1|2|3|4|5|6|7|8|9|!|#|$|%|&|'|\\*|\\+|-|/|=|\\?|^|_|`|{|\\||}|~|\\.)+@(a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z|A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z|0|1|2|3|4|5|6|7|8|9|_|\\.|-)+" - }, - { - "is_public": false, - "regex_def": ">?\r\n" - } - ] -} \ No newline at end of file + "parts": [ + { + "is_public": false, + "regex_def": "((\r\n)|^)from:" + }, + { + "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" + } + ] +} diff --git a/packages/circom/circuits/common/from_all_regex.circom b/packages/circom/circuits/common/from_all_regex.circom index 291815b..e343006 100644 --- a/packages/circom/circuits/common/from_all_regex.circom +++ b/packages/circom/circuits/common/from_all_regex.circom @@ -2,7 +2,7 @@ pragma circom 2.1.5; include "@zk-email/zk-regex-circom/circuits/regex_helpers.circom"; -// regex: (( \n)|^)from:[^ \n]+ \n +// regex: ((\r\n)|^)from:[^\r\n]+\r\n template FromAllRegex(msg_bytes) { signal input msg[msg_bytes]; signal output out; @@ -14,195 +14,504 @@ template FromAllRegex(msg_bytes) { in[i+1] <== msg[i]; } - component eq[20][num_bytes]; - component lt[2][num_bytes]; - component and[14][num_bytes]; - component multi_or[4][num_bytes]; - signal states[num_bytes+1][11]; + component eq[56][num_bytes]; + component lt[12][num_bytes]; + component and[39][num_bytes]; + component multi_or[13][num_bytes]; + signal states[num_bytes+1][18]; component state_changed[num_bytes]; states[0][0] <== 1; - for (var i = 1; i < 11; i++) { + for (var i = 1; i < 18; i++) { states[0][i] <== 0; } for (var i = 0; i < num_bytes; i++) { - state_changed[i] = MultiOR(10); - 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] <== 254; - and[0][i] = AND(); - and[0][i].a <== lt[0][i].out; - and[0][i].b <== lt[1][i].out; + state_changed[i] = MultiOR(17); eq[0][i] = IsEqual(); eq[0][i].in[0] <== in[i]; - eq[0][i].in[1] <== 0; + eq[0][i].in[1] <== 102; + and[0][i] = AND(); + and[0][i].a <== states[i][0]; + and[0][i].b <== eq[0][i].out; + and[1][i] = AND(); + and[1][i].a <== states[i][4]; + and[1][i].b <== eq[0][i].out; + multi_or[0][i] = MultiOR(2); + multi_or[0][i].in[0] <== and[0][i].out; + multi_or[0][i].in[1] <== and[1][i].out; + states[i+1][1] <== multi_or[0][i].out; + state_changed[i].in[0] <== states[i+1][1]; eq[1][i] = IsEqual(); eq[1][i].in[0] <== in[i]; - eq[1][i].in[1] <== 1; + eq[1][i].in[1] <== 13; + and[2][i] = AND(); + and[2][i].a <== states[i][0]; + and[2][i].b <== eq[1][i].out; + states[i+1][2] <== and[2][i].out; + state_changed[i].in[1] <== states[i+1][2]; eq[2][i] = IsEqual(); eq[2][i].in[0] <== in[i]; - eq[2][i].in[1] <== 2; + eq[2][i].in[1] <== 114; + and[3][i] = AND(); + and[3][i].a <== states[i][1]; + and[3][i].b <== eq[2][i].out; + states[i+1][3] <== and[3][i].out; + state_changed[i].in[2] <== states[i+1][3]; eq[3][i] = IsEqual(); eq[3][i].in[0] <== in[i]; - eq[3][i].in[1] <== 3; + eq[3][i].in[1] <== 10; + and[4][i] = AND(); + and[4][i].a <== states[i][2]; + and[4][i].b <== eq[3][i].out; + states[i+1][4] <== and[4][i].out; + state_changed[i].in[3] <== states[i+1][4]; eq[4][i] = IsEqual(); eq[4][i].in[0] <== in[i]; - eq[4][i].in[1] <== 4; + eq[4][i].in[1] <== 111; + and[5][i] = AND(); + and[5][i].a <== states[i][3]; + and[5][i].b <== eq[4][i].out; + states[i+1][5] <== and[5][i].out; + state_changed[i].in[4] <== states[i+1][5]; eq[5][i] = IsEqual(); eq[5][i].in[0] <== in[i]; - eq[5][i].in[1] <== 5; + eq[5][i].in[1] <== 109; + and[6][i] = AND(); + and[6][i].a <== states[i][5]; + and[6][i].b <== eq[5][i].out; + states[i+1][6] <== and[6][i].out; + state_changed[i].in[5] <== states[i+1][6]; eq[6][i] = IsEqual(); eq[6][i].in[0] <== in[i]; - eq[6][i].in[1] <== 6; + eq[6][i].in[1] <== 58; + and[7][i] = AND(); + and[7][i].a <== states[i][6]; + and[7][i].b <== eq[6][i].out; + states[i+1][7] <== and[7][i].out; + state_changed[i].in[6] <== states[i+1][7]; + lt[0][i] = LessEqThan(8); + lt[0][i].in[0] <== 194; + lt[0][i].in[1] <== in[i]; + lt[1][i] = LessEqThan(8); + lt[1][i].in[0] <== in[i]; + lt[1][i].in[1] <== 223; + and[8][i] = AND(); + and[8][i].a <== lt[0][i].out; + and[8][i].b <== lt[1][i].out; + and[9][i] = AND(); + and[9][i].a <== states[i][7]; + and[9][i].b <== and[8][i].out; + lt[2][i] = LessEqThan(8); + lt[2][i].in[0] <== 160; + lt[2][i].in[1] <== in[i]; + lt[3][i] = LessEqThan(8); + lt[3][i].in[0] <== in[i]; + lt[3][i].in[1] <== 191; + and[10][i] = AND(); + and[10][i].a <== lt[2][i].out; + and[10][i].b <== lt[3][i].out; + and[11][i] = AND(); + and[11][i].a <== states[i][9]; + and[11][i].b <== and[10][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[12][i] = AND(); + and[12][i].a <== lt[4][i].out; + and[12][i].b <== lt[5][i].out; + and[13][i] = AND(); + and[13][i].a <== states[i][10]; + and[13][i].b <== and[12][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] <== 159; + and[14][i] = AND(); + and[14][i].a <== lt[6][i].out; + and[14][i].b <== lt[7][i].out; + and[15][i] = AND(); + and[15][i].a <== states[i][11]; + and[15][i].b <== and[14][i].out; + and[16][i] = AND(); + and[16][i].a <== states[i][15]; + and[16][i].b <== and[8][i].out; + multi_or[1][i] = MultiOR(5); + multi_or[1][i].in[0] <== and[9][i].out; + multi_or[1][i].in[1] <== and[11][i].out; + multi_or[1][i].in[2] <== and[13][i].out; + multi_or[1][i].in[3] <== and[15][i].out; + multi_or[1][i].in[4] <== and[16][i].out; + states[i+1][8] <== multi_or[1][i].out; + state_changed[i].in[7] <== states[i+1][8]; eq[7][i] = IsEqual(); eq[7][i].in[0] <== in[i]; - eq[7][i].in[1] <== 7; + eq[7][i].in[1] <== 224; + and[17][i] = AND(); + and[17][i].a <== states[i][7]; + and[17][i].b <== eq[7][i].out; + and[18][i] = AND(); + and[18][i].a <== states[i][15]; + and[18][i].b <== eq[7][i].out; + multi_or[2][i] = MultiOR(2); + multi_or[2][i].in[0] <== and[17][i].out; + multi_or[2][i].in[1] <== and[18][i].out; + states[i+1][9] <== multi_or[2][i].out; + state_changed[i].in[8] <== states[i+1][9]; eq[8][i] = IsEqual(); eq[8][i].in[0] <== in[i]; - eq[8][i].in[1] <== 8; + eq[8][i].in[1] <== 225; eq[9][i] = IsEqual(); eq[9][i].in[0] <== in[i]; - eq[9][i].in[1] <== 9; + eq[9][i].in[1] <== 226; eq[10][i] = IsEqual(); eq[10][i].in[0] <== in[i]; - eq[10][i].in[1] <== 11; + eq[10][i].in[1] <== 227; eq[11][i] = IsEqual(); eq[11][i].in[0] <== in[i]; - eq[11][i].in[1] <== 12; - and[1][i] = AND(); - and[1][i].a <== states[i][1]; - multi_or[0][i] = MultiOR(13); - 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; - multi_or[0][i].in[12] <== eq[11][i].out; - and[1][i].b <== multi_or[0][i].out; - and[2][i] = AND(); - and[2][i].a <== states[i][8]; - and[2][i].b <== multi_or[0][i].out; - multi_or[1][i] = MultiOR(2); - multi_or[1][i].in[0] <== and[1][i].out; - multi_or[1][i].in[1] <== and[2][i].out; - states[i+1][1] <== multi_or[1][i].out; - state_changed[i].in[0] <== states[i+1][1]; + eq[11][i].in[1] <== 228; eq[12][i] = IsEqual(); eq[12][i].in[0] <== in[i]; - eq[12][i].in[1] <== 13; - and[3][i] = AND(); - and[3][i].a <== states[i][0]; - and[3][i].b <== eq[12][i].out; - and[4][i] = AND(); - and[4][i].a <== states[i][3]; - and[4][i].b <== eq[12][i].out; - multi_or[2][i] = MultiOR(2); - multi_or[2][i].in[0] <== and[3][i].out; - multi_or[2][i].in[1] <== and[4][i].out; - states[i+1][2] <== multi_or[2][i].out; - state_changed[i].in[1] <== states[i+1][2]; + eq[12][i].in[1] <== 229; eq[13][i] = IsEqual(); eq[13][i].in[0] <== in[i]; - eq[13][i].in[1] <== 255; - and[5][i] = AND(); - and[5][i].a <== states[i][0]; - and[5][i].b <== eq[13][i].out; + eq[13][i].in[1] <== 230; eq[14][i] = IsEqual(); eq[14][i].in[0] <== in[i]; - eq[14][i].in[1] <== 10; - and[6][i] = AND(); - and[6][i].a <== states[i][2]; - and[6][i].b <== eq[14][i].out; - multi_or[3][i] = MultiOR(2); - multi_or[3][i].in[0] <== and[5][i].out; - multi_or[3][i].in[1] <== and[6][i].out; - states[i+1][3] <== multi_or[3][i].out; - state_changed[i].in[2] <== states[i+1][3]; + eq[14][i].in[1] <== 231; eq[15][i] = IsEqual(); eq[15][i].in[0] <== in[i]; - eq[15][i].in[1] <== 102; - and[7][i] = AND(); - and[7][i].a <== states[i][3]; - and[7][i].b <== eq[15][i].out; - states[i+1][4] <== and[7][i].out; - state_changed[i].in[3] <== states[i+1][4]; + eq[15][i].in[1] <== 232; eq[16][i] = IsEqual(); eq[16][i].in[0] <== in[i]; - eq[16][i].in[1] <== 114; - and[8][i] = AND(); - and[8][i].a <== states[i][4]; - and[8][i].b <== eq[16][i].out; - states[i+1][5] <== and[8][i].out; - state_changed[i].in[4] <== states[i+1][5]; + eq[16][i].in[1] <== 233; eq[17][i] = IsEqual(); eq[17][i].in[0] <== in[i]; - eq[17][i].in[1] <== 111; - and[9][i] = AND(); - and[9][i].a <== states[i][5]; - and[9][i].b <== eq[17][i].out; - states[i+1][6] <== and[9][i].out; - state_changed[i].in[5] <== states[i+1][6]; + eq[17][i].in[1] <== 234; eq[18][i] = IsEqual(); eq[18][i].in[0] <== in[i]; - eq[18][i].in[1] <== 109; - and[10][i] = AND(); - and[10][i].a <== states[i][6]; - and[10][i].b <== eq[18][i].out; - states[i+1][7] <== and[10][i].out; - state_changed[i].in[6] <== states[i+1][7]; + eq[18][i].in[1] <== 235; eq[19][i] = IsEqual(); eq[19][i].in[0] <== in[i]; - eq[19][i].in[1] <== 58; - and[11][i] = AND(); - and[11][i].a <== states[i][7]; - and[11][i].b <== eq[19][i].out; - states[i+1][8] <== and[11][i].out; - state_changed[i].in[7] <== states[i+1][8]; - and[12][i] = AND(); - and[12][i].a <== states[i][1]; - and[12][i].b <== eq[12][i].out; - states[i+1][9] <== and[12][i].out; - state_changed[i].in[8] <== states[i+1][9]; - and[13][i] = AND(); - and[13][i].a <== states[i][9]; - and[13][i].b <== eq[14][i].out; - states[i+1][10] <== and[13][i].out; + eq[19][i].in[1] <== 236; + eq[20][i] = IsEqual(); + eq[20][i].in[0] <== in[i]; + eq[20][i].in[1] <== 238; + eq[21][i] = IsEqual(); + eq[21][i].in[0] <== in[i]; + eq[21][i].in[1] <== 239; + and[19][i] = AND(); + and[19][i].a <== states[i][7]; + multi_or[3][i] = MultiOR(14); + multi_or[3][i].in[0] <== eq[8][i].out; + multi_or[3][i].in[1] <== eq[9][i].out; + multi_or[3][i].in[2] <== eq[10][i].out; + multi_or[3][i].in[3] <== eq[11][i].out; + multi_or[3][i].in[4] <== eq[12][i].out; + multi_or[3][i].in[5] <== eq[13][i].out; + multi_or[3][i].in[6] <== eq[14][i].out; + multi_or[3][i].in[7] <== eq[15][i].out; + multi_or[3][i].in[8] <== eq[16][i].out; + multi_or[3][i].in[9] <== eq[17][i].out; + multi_or[3][i].in[10] <== eq[18][i].out; + multi_or[3][i].in[11] <== eq[19][i].out; + multi_or[3][i].in[12] <== eq[20][i].out; + multi_or[3][i].in[13] <== eq[21][i].out; + and[19][i].b <== multi_or[3][i].out; + lt[8][i] = LessEqThan(8); + lt[8][i].in[0] <== 144; + 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[20][i] = AND(); + and[20][i].a <== lt[8][i].out; + and[20][i].b <== lt[9][i].out; + and[21][i] = AND(); + and[21][i].a <== states[i][12]; + and[21][i].b <== and[20][i].out; + and[22][i] = AND(); + and[22][i].a <== states[i][13]; + and[22][i].b <== and[12][i].out; + eq[22][i] = IsEqual(); + eq[22][i].in[0] <== in[i]; + eq[22][i].in[1] <== 128; + eq[23][i] = IsEqual(); + eq[23][i].in[0] <== in[i]; + eq[23][i].in[1] <== 129; + eq[24][i] = IsEqual(); + eq[24][i].in[0] <== in[i]; + eq[24][i].in[1] <== 130; + eq[25][i] = IsEqual(); + eq[25][i].in[0] <== in[i]; + eq[25][i].in[1] <== 131; + eq[26][i] = IsEqual(); + eq[26][i].in[0] <== in[i]; + eq[26][i].in[1] <== 132; + eq[27][i] = IsEqual(); + eq[27][i].in[0] <== in[i]; + eq[27][i].in[1] <== 133; + eq[28][i] = IsEqual(); + eq[28][i].in[0] <== in[i]; + eq[28][i].in[1] <== 134; + eq[29][i] = IsEqual(); + eq[29][i].in[0] <== in[i]; + eq[29][i].in[1] <== 135; + eq[30][i] = IsEqual(); + eq[30][i].in[0] <== in[i]; + eq[30][i].in[1] <== 136; + eq[31][i] = IsEqual(); + eq[31][i].in[0] <== in[i]; + eq[31][i].in[1] <== 137; + eq[32][i] = IsEqual(); + eq[32][i].in[0] <== in[i]; + eq[32][i].in[1] <== 138; + eq[33][i] = IsEqual(); + eq[33][i].in[0] <== in[i]; + eq[33][i].in[1] <== 139; + eq[34][i] = IsEqual(); + eq[34][i].in[0] <== in[i]; + eq[34][i].in[1] <== 140; + eq[35][i] = IsEqual(); + eq[35][i].in[0] <== in[i]; + eq[35][i].in[1] <== 141; + eq[36][i] = IsEqual(); + eq[36][i].in[0] <== in[i]; + eq[36][i].in[1] <== 142; + eq[37][i] = IsEqual(); + eq[37][i].in[0] <== in[i]; + eq[37][i].in[1] <== 143; + and[23][i] = AND(); + and[23][i].a <== states[i][14]; + multi_or[4][i] = MultiOR(16); + multi_or[4][i].in[0] <== eq[22][i].out; + multi_or[4][i].in[1] <== eq[23][i].out; + multi_or[4][i].in[2] <== eq[24][i].out; + multi_or[4][i].in[3] <== eq[25][i].out; + multi_or[4][i].in[4] <== eq[26][i].out; + multi_or[4][i].in[5] <== eq[27][i].out; + multi_or[4][i].in[6] <== eq[28][i].out; + multi_or[4][i].in[7] <== eq[29][i].out; + multi_or[4][i].in[8] <== eq[30][i].out; + multi_or[4][i].in[9] <== eq[31][i].out; + multi_or[4][i].in[10] <== eq[32][i].out; + multi_or[4][i].in[11] <== eq[33][i].out; + multi_or[4][i].in[12] <== eq[34][i].out; + multi_or[4][i].in[13] <== eq[35][i].out; + multi_or[4][i].in[14] <== eq[36][i].out; + multi_or[4][i].in[15] <== eq[37][i].out; + and[23][i].b <== multi_or[4][i].out; + and[24][i] = AND(); + and[24][i].a <== states[i][15]; + and[24][i].b <== multi_or[3][i].out; + multi_or[5][i] = MultiOR(5); + multi_or[5][i].in[0] <== and[19][i].out; + multi_or[5][i].in[1] <== and[21][i].out; + multi_or[5][i].in[2] <== and[22][i].out; + multi_or[5][i].in[3] <== and[23][i].out; + multi_or[5][i].in[4] <== and[24][i].out; + states[i+1][10] <== multi_or[5][i].out; state_changed[i].in[9] <== states[i+1][10]; + eq[38][i] = IsEqual(); + eq[38][i].in[0] <== in[i]; + eq[38][i].in[1] <== 237; + and[25][i] = AND(); + and[25][i].a <== states[i][7]; + and[25][i].b <== eq[38][i].out; + and[26][i] = AND(); + and[26][i].a <== states[i][15]; + and[26][i].b <== eq[38][i].out; + multi_or[6][i] = MultiOR(2); + multi_or[6][i].in[0] <== and[25][i].out; + multi_or[6][i].in[1] <== and[26][i].out; + states[i+1][11] <== multi_or[6][i].out; + state_changed[i].in[10] <== states[i+1][11]; + eq[39][i] = IsEqual(); + eq[39][i].in[0] <== in[i]; + eq[39][i].in[1] <== 240; + and[27][i] = AND(); + and[27][i].a <== states[i][7]; + and[27][i].b <== eq[39][i].out; + and[28][i] = AND(); + and[28][i].a <== states[i][15]; + and[28][i].b <== eq[39][i].out; + multi_or[7][i] = MultiOR(2); + multi_or[7][i].in[0] <== and[27][i].out; + multi_or[7][i].in[1] <== and[28][i].out; + states[i+1][12] <== multi_or[7][i].out; + state_changed[i].in[11] <== states[i+1][12]; + eq[40][i] = IsEqual(); + eq[40][i].in[0] <== in[i]; + eq[40][i].in[1] <== 241; + eq[41][i] = IsEqual(); + eq[41][i].in[0] <== in[i]; + eq[41][i].in[1] <== 242; + eq[42][i] = IsEqual(); + eq[42][i].in[0] <== in[i]; + eq[42][i].in[1] <== 243; + and[29][i] = AND(); + and[29][i].a <== states[i][7]; + multi_or[8][i] = MultiOR(3); + multi_or[8][i].in[0] <== eq[40][i].out; + multi_or[8][i].in[1] <== eq[41][i].out; + multi_or[8][i].in[2] <== eq[42][i].out; + and[29][i].b <== multi_or[8][i].out; + and[30][i] = AND(); + and[30][i].a <== states[i][15]; + and[30][i].b <== multi_or[8][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[i+1][13] <== multi_or[9][i].out; + state_changed[i].in[12] <== states[i+1][13]; + eq[43][i] = IsEqual(); + eq[43][i].in[0] <== in[i]; + eq[43][i].in[1] <== 244; + and[31][i] = AND(); + and[31][i].a <== states[i][7]; + and[31][i].b <== eq[43][i].out; + and[32][i] = AND(); + and[32][i].a <== states[i][15]; + and[32][i].b <== eq[43][i].out; + multi_or[10][i] = MultiOR(2); + multi_or[10][i].in[0] <== and[31][i].out; + multi_or[10][i].in[1] <== and[32][i].out; + states[i+1][14] <== multi_or[10][i].out; + state_changed[i].in[13] <== states[i+1][14]; + lt[10][i] = LessEqThan(8); + lt[10][i].in[0] <== 14; + lt[10][i].in[1] <== in[i]; + lt[11][i] = LessEqThan(8); + lt[11][i].in[0] <== in[i]; + lt[11][i].in[1] <== 127; + and[33][i] = AND(); + and[33][i].a <== lt[10][i].out; + and[33][i].b <== lt[11][i].out; + eq[44][i] = IsEqual(); + eq[44][i].in[0] <== in[i]; + eq[44][i].in[1] <== 0; + eq[45][i] = IsEqual(); + eq[45][i].in[0] <== in[i]; + eq[45][i].in[1] <== 1; + eq[46][i] = IsEqual(); + eq[46][i].in[0] <== in[i]; + eq[46][i].in[1] <== 2; + eq[47][i] = IsEqual(); + eq[47][i].in[0] <== in[i]; + eq[47][i].in[1] <== 3; + eq[48][i] = IsEqual(); + eq[48][i].in[0] <== in[i]; + eq[48][i].in[1] <== 4; + eq[49][i] = IsEqual(); + eq[49][i].in[0] <== in[i]; + eq[49][i].in[1] <== 5; + eq[50][i] = IsEqual(); + eq[50][i].in[0] <== in[i]; + eq[50][i].in[1] <== 6; + eq[51][i] = IsEqual(); + eq[51][i].in[0] <== in[i]; + eq[51][i].in[1] <== 7; + eq[52][i] = IsEqual(); + eq[52][i].in[0] <== in[i]; + eq[52][i].in[1] <== 8; + eq[53][i] = IsEqual(); + eq[53][i].in[0] <== in[i]; + eq[53][i].in[1] <== 9; + eq[54][i] = IsEqual(); + eq[54][i].in[0] <== in[i]; + eq[54][i].in[1] <== 11; + eq[55][i] = IsEqual(); + eq[55][i].in[0] <== in[i]; + eq[55][i].in[1] <== 12; + and[34][i] = AND(); + and[34][i].a <== states[i][7]; + multi_or[11][i] = MultiOR(13); + multi_or[11][i].in[0] <== and[33][i].out; + multi_or[11][i].in[1] <== eq[44][i].out; + multi_or[11][i].in[2] <== eq[45][i].out; + multi_or[11][i].in[3] <== eq[46][i].out; + multi_or[11][i].in[4] <== eq[47][i].out; + multi_or[11][i].in[5] <== eq[48][i].out; + multi_or[11][i].in[6] <== eq[49][i].out; + multi_or[11][i].in[7] <== eq[50][i].out; + multi_or[11][i].in[8] <== eq[51][i].out; + multi_or[11][i].in[9] <== eq[52][i].out; + multi_or[11][i].in[10] <== eq[53][i].out; + multi_or[11][i].in[11] <== eq[54][i].out; + multi_or[11][i].in[12] <== eq[55][i].out; + and[34][i].b <== multi_or[11][i].out; + and[35][i] = AND(); + and[35][i].a <== states[i][8]; + and[35][i].b <== and[12][i].out; + and[36][i] = AND(); + and[36][i].a <== states[i][15]; + and[36][i].b <== multi_or[11][i].out; + multi_or[12][i] = MultiOR(3); + multi_or[12][i].in[0] <== and[34][i].out; + multi_or[12][i].in[1] <== and[35][i].out; + multi_or[12][i].in[2] <== and[36][i].out; + states[i+1][15] <== multi_or[12][i].out; + state_changed[i].in[14] <== states[i+1][15]; + and[37][i] = AND(); + and[37][i].a <== states[i][15]; + and[37][i].b <== eq[1][i].out; + states[i+1][16] <== and[37][i].out; + state_changed[i].in[15] <== states[i+1][16]; + and[38][i] = AND(); + and[38][i].a <== states[i][16]; + and[38][i].b <== eq[3][i].out; + states[i+1][17] <== and[38][i].out; + state_changed[i].in[16] <== states[i+1][17]; states[i+1][0] <== 1 - state_changed[i].out; } component final_state_result = MultiOR(num_bytes+1); for (var i = 0; i <= num_bytes; i++) { - final_state_result.in[i] <== states[i][10]; + final_state_result.in[i] <== states[i][17]; } out <== final_state_result.out; - signal is_consecutive[msg_bytes+1][2]; is_consecutive[msg_bytes][1] <== 1; 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][1]) + is_consecutive[msg_bytes-i][1]; + is_consecutive[msg_bytes-1-i][0] <== states[num_bytes-i][17] * (1 - is_consecutive[msg_bytes-i][1]) + is_consecutive[msg_bytes-i][1]; is_consecutive[msg_bytes-1-i][1] <== state_changed[msg_bytes-i].out * is_consecutive[msg_bytes-1-i][0]; } - signal is_substr0[msg_bytes][3]; + // substrings calculated: [{(7, 8), (7, 9), (7, 10), (7, 11), (7, 12), (7, 13), (7, 14), (7, 15), (8, 15), (9, 8), (10, 8), (11, 8), (12, 10), (13, 10), (14, 10), (15, 8), (15, 9), (15, 10), (15, 11), (15, 12), (15, 13), (15, 14), (15, 15)}] + signal is_substr0[msg_bytes][24]; signal is_reveal0[msg_bytes]; signal output reveal0[msg_bytes]; for (var i = 0; i < msg_bytes; i++) { is_substr0[i][0] <== 0; - // the 0-th substring transitions: [(1, 1), (8, 1)] - is_substr0[i][1] <== is_substr0[i][0] + states[i+1][1] * states[i+2][1]; - is_substr0[i][2] <== is_substr0[i][1] + states[i+1][8] * states[i+2][1]; - is_reveal0[i] <== is_substr0[i][2] * is_consecutive[i][1]; + // the 0-th substring transitions: [(7, 8), (7, 9), (7, 10), (7, 11), (7, 12), (7, 13), (7, 14), (7, 15), (8, 15), (9, 8), (10, 8), (11, 8), (12, 10), (13, 10), (14, 10), (15, 8), (15, 9), (15, 10), (15, 11), (15, 12), (15, 13), (15, 14), (15, 15)] + is_substr0[i][1] <== is_substr0[i][0] + states[i+1][7] * states[i+2][8]; + is_substr0[i][2] <== is_substr0[i][1] + states[i+1][7] * states[i+2][9]; + is_substr0[i][3] <== is_substr0[i][2] + states[i+1][7] * states[i+2][10]; + is_substr0[i][4] <== is_substr0[i][3] + states[i+1][7] * states[i+2][11]; + is_substr0[i][5] <== is_substr0[i][4] + states[i+1][7] * states[i+2][12]; + is_substr0[i][6] <== is_substr0[i][5] + states[i+1][7] * states[i+2][13]; + is_substr0[i][7] <== is_substr0[i][6] + states[i+1][7] * states[i+2][14]; + is_substr0[i][8] <== is_substr0[i][7] + states[i+1][7] * states[i+2][15]; + is_substr0[i][9] <== is_substr0[i][8] + states[i+1][8] * states[i+2][15]; + is_substr0[i][10] <== is_substr0[i][9] + states[i+1][9] * states[i+2][8]; + is_substr0[i][11] <== is_substr0[i][10] + states[i+1][10] * states[i+2][8]; + is_substr0[i][12] <== is_substr0[i][11] + states[i+1][11] * states[i+2][8]; + is_substr0[i][13] <== is_substr0[i][12] + states[i+1][12] * states[i+2][10]; + is_substr0[i][14] <== is_substr0[i][13] + states[i+1][13] * states[i+2][10]; + is_substr0[i][15] <== is_substr0[i][14] + states[i+1][14] * states[i+2][10]; + is_substr0[i][16] <== is_substr0[i][15] + states[i+1][15] * states[i+2][8]; + is_substr0[i][17] <== is_substr0[i][16] + states[i+1][15] * states[i+2][9]; + is_substr0[i][18] <== is_substr0[i][17] + states[i+1][15] * states[i+2][10]; + is_substr0[i][19] <== is_substr0[i][18] + states[i+1][15] * states[i+2][11]; + is_substr0[i][20] <== is_substr0[i][19] + states[i+1][15] * states[i+2][12]; + is_substr0[i][21] <== is_substr0[i][20] + states[i+1][15] * states[i+2][13]; + is_substr0[i][22] <== is_substr0[i][21] + states[i+1][15] * states[i+2][14]; + is_substr0[i][23] <== is_substr0[i][22] + states[i+1][15] * states[i+2][15]; + is_reveal0[i] <== is_substr0[i][23] * is_consecutive[i][1]; reveal0[i] <== in[i+1] * is_reveal0[i]; } } \ No newline at end of file diff --git a/packages/circom/circuits/common/message_id.json b/packages/circom/circuits/common/message_id.json index c207af1..f71f0ee 100644 --- a/packages/circom/circuits/common/message_id.json +++ b/packages/circom/circuits/common/message_id.json @@ -1,16 +1,16 @@ { - "parts": [ - { - "is_public": false, - "regex_def": "((\r\n)|^)message-id:" - }, - { - "is_public": true, - "regex_def": "<(=|@|\\.|\\+|_|-|a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z|A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z|0|1|2|3|4|5|6|7|8|9)+>" - }, - { - "is_public": false, - "regex_def": "\r\n" - } - ] -} \ No newline at end of file + "parts": [ + { + "is_public": false, + "regex_def": "((\r\n)|^)message-id:" + }, + { + "is_public": true, + "regex_def": "<[A-Za-z0-9=@\\.\\+_-]+>" + }, + { + "is_public": false, + "regex_def": "\r\n" + } + ] +} diff --git a/packages/circom/circuits/common/message_id_regex.circom b/packages/circom/circuits/common/message_id_regex.circom index 4f8131b..f0005a8 100644 --- a/packages/circom/circuits/common/message_id_regex.circom +++ b/packages/circom/circuits/common/message_id_regex.circom @@ -2,7 +2,7 @@ pragma circom 2.1.5; include "@zk-email/zk-regex-circom/circuits/regex_helpers.circom"; -// regex: (( \n)|^)message-id:<(=|@|\.|\+|_|-|a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z|A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z|0|1|2|3|4|5|6|7|8|9)+> \n +// regex: ((\r\n)|^)message-id:<[A-Za-z0-9=@\.\+_-]+>\r\n template MessageIdRegex(msg_bytes) { signal input msg[msg_bytes]; signal output out; @@ -14,10 +14,10 @@ template MessageIdRegex(msg_bytes) { in[i+1] <== msg[i]; } - component eq[28][num_bytes]; + component eq[27][num_bytes]; component lt[4][num_bytes]; - component and[23][num_bytes]; - component multi_or[4][num_bytes]; + component and[22][num_bytes]; + component multi_or[3][num_bytes]; signal states[num_bytes+1][19]; component state_changed[num_bytes]; @@ -28,259 +28,250 @@ template MessageIdRegex(msg_bytes) { for (var i = 0; i < num_bytes; i++) { state_changed[i] = MultiOR(18); - lt[0][i] = LessEqThan(8); - lt[0][i].in[0] <== 64; - 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[0][i] = AND(); - and[0][i].a <== lt[0][i].out; - and[0][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[1][i] = AND(); - and[1][i].a <== lt[2][i].out; - and[1][i].b <== lt[3][i].out; eq[0][i] = IsEqual(); eq[0][i].in[0] <== in[i]; - eq[0][i].in[1] <== 43; + eq[0][i].in[1] <== 109; + and[0][i] = AND(); + and[0][i].a <== states[i][0]; + and[0][i].b <== eq[0][i].out; + and[1][i] = AND(); + and[1][i].a <== states[i][4]; + and[1][i].b <== eq[0][i].out; + multi_or[0][i] = MultiOR(2); + multi_or[0][i].in[0] <== and[0][i].out; + multi_or[0][i].in[1] <== and[1][i].out; + states[i+1][1] <== multi_or[0][i].out; + state_changed[i].in[0] <== states[i+1][1]; eq[1][i] = IsEqual(); eq[1][i].in[0] <== in[i]; - eq[1][i].in[1] <== 45; + eq[1][i].in[1] <== 13; + and[2][i] = AND(); + and[2][i].a <== states[i][0]; + and[2][i].b <== eq[1][i].out; + states[i+1][2] <== and[2][i].out; + state_changed[i].in[1] <== states[i+1][2]; eq[2][i] = IsEqual(); eq[2][i].in[0] <== in[i]; - eq[2][i].in[1] <== 46; + eq[2][i].in[1] <== 101; + and[3][i] = AND(); + and[3][i].a <== states[i][1]; + and[3][i].b <== eq[2][i].out; + states[i+1][3] <== and[3][i].out; + state_changed[i].in[2] <== states[i+1][3]; eq[3][i] = IsEqual(); eq[3][i].in[0] <== in[i]; - eq[3][i].in[1] <== 48; + eq[3][i].in[1] <== 10; + and[4][i] = AND(); + and[4][i].a <== states[i][2]; + and[4][i].b <== eq[3][i].out; + states[i+1][4] <== and[4][i].out; + state_changed[i].in[3] <== states[i+1][4]; eq[4][i] = IsEqual(); eq[4][i].in[0] <== in[i]; - eq[4][i].in[1] <== 49; + eq[4][i].in[1] <== 115; + and[5][i] = AND(); + and[5][i].a <== states[i][3]; + and[5][i].b <== eq[4][i].out; + states[i+1][5] <== and[5][i].out; + state_changed[i].in[4] <== states[i+1][5]; + and[6][i] = AND(); + and[6][i].a <== states[i][5]; + and[6][i].b <== eq[4][i].out; + states[i+1][6] <== and[6][i].out; + state_changed[i].in[5] <== states[i+1][6]; eq[5][i] = IsEqual(); eq[5][i].in[0] <== in[i]; - eq[5][i].in[1] <== 50; + eq[5][i].in[1] <== 97; + and[7][i] = AND(); + and[7][i].a <== states[i][6]; + and[7][i].b <== eq[5][i].out; + states[i+1][7] <== and[7][i].out; + state_changed[i].in[6] <== states[i+1][7]; eq[6][i] = IsEqual(); eq[6][i].in[0] <== in[i]; - eq[6][i].in[1] <== 51; + eq[6][i].in[1] <== 103; + and[8][i] = AND(); + and[8][i].a <== states[i][7]; + and[8][i].b <== eq[6][i].out; + states[i+1][8] <== and[8][i].out; + state_changed[i].in[7] <== states[i+1][8]; + and[9][i] = AND(); + and[9][i].a <== states[i][8]; + and[9][i].b <== eq[2][i].out; + states[i+1][9] <== and[9][i].out; + state_changed[i].in[8] <== states[i+1][9]; eq[7][i] = IsEqual(); eq[7][i].in[0] <== in[i]; - eq[7][i].in[1] <== 52; + eq[7][i].in[1] <== 45; + and[10][i] = AND(); + and[10][i].a <== states[i][9]; + and[10][i].b <== eq[7][i].out; + states[i+1][10] <== and[10][i].out; + state_changed[i].in[9] <== states[i+1][10]; eq[8][i] = IsEqual(); eq[8][i].in[0] <== in[i]; - eq[8][i].in[1] <== 53; + eq[8][i].in[1] <== 105; + and[11][i] = AND(); + and[11][i].a <== states[i][10]; + and[11][i].b <== eq[8][i].out; + states[i+1][11] <== and[11][i].out; + state_changed[i].in[10] <== states[i+1][11]; eq[9][i] = IsEqual(); eq[9][i].in[0] <== in[i]; - eq[9][i].in[1] <== 54; + eq[9][i].in[1] <== 100; + and[12][i] = AND(); + and[12][i].a <== states[i][11]; + and[12][i].b <== eq[9][i].out; + states[i+1][12] <== and[12][i].out; + state_changed[i].in[11] <== states[i+1][12]; eq[10][i] = IsEqual(); eq[10][i].in[0] <== in[i]; - eq[10][i].in[1] <== 55; + eq[10][i].in[1] <== 58; + and[13][i] = AND(); + and[13][i].a <== states[i][12]; + and[13][i].b <== eq[10][i].out; + states[i+1][13] <== and[13][i].out; + state_changed[i].in[12] <== states[i+1][13]; eq[11][i] = IsEqual(); eq[11][i].in[0] <== in[i]; - eq[11][i].in[1] <== 56; + eq[11][i].in[1] <== 60; + and[14][i] = AND(); + and[14][i].a <== states[i][13]; + and[14][i].b <== eq[11][i].out; + states[i+1][14] <== and[14][i].out; + state_changed[i].in[13] <== states[i+1][14]; + lt[0][i] = LessEqThan(8); + lt[0][i].in[0] <== 64; + 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[15][i] = AND(); + and[15][i].a <== lt[0][i].out; + and[15][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[16][i] = AND(); + and[16][i].a <== lt[2][i].out; + and[16][i].b <== lt[3][i].out; eq[12][i] = IsEqual(); eq[12][i].in[0] <== in[i]; - eq[12][i].in[1] <== 57; + eq[12][i].in[1] <== 43; eq[13][i] = IsEqual(); eq[13][i].in[0] <== in[i]; - eq[13][i].in[1] <== 61; + eq[13][i].in[1] <== 46; eq[14][i] = IsEqual(); eq[14][i].in[0] <== in[i]; - eq[14][i].in[1] <== 95; - and[2][i] = AND(); - and[2][i].a <== states[i][1]; - multi_or[0][i] = MultiOR(17); - multi_or[0][i].in[0] <== and[0][i].out; - multi_or[0][i].in[1] <== and[1][i].out; - multi_or[0][i].in[2] <== eq[0][i].out; - multi_or[0][i].in[3] <== eq[1][i].out; - multi_or[0][i].in[4] <== eq[2][i].out; - multi_or[0][i].in[5] <== eq[3][i].out; - multi_or[0][i].in[6] <== eq[4][i].out; - multi_or[0][i].in[7] <== eq[5][i].out; - multi_or[0][i].in[8] <== eq[6][i].out; - multi_or[0][i].in[9] <== eq[7][i].out; - multi_or[0][i].in[10] <== eq[8][i].out; - multi_or[0][i].in[11] <== eq[9][i].out; - multi_or[0][i].in[12] <== eq[10][i].out; - multi_or[0][i].in[13] <== eq[11][i].out; - multi_or[0][i].in[14] <== eq[12][i].out; - multi_or[0][i].in[15] <== eq[13][i].out; - multi_or[0][i].in[16] <== eq[14][i].out; - and[2][i].b <== multi_or[0][i].out; - and[3][i] = AND(); - and[3][i].a <== states[i][18]; - and[3][i].b <== multi_or[0][i].out; - multi_or[1][i] = MultiOR(2); - multi_or[1][i].in[0] <== and[2][i].out; - multi_or[1][i].in[1] <== and[3][i].out; - states[i+1][1] <== multi_or[1][i].out; - state_changed[i].in[0] <== states[i+1][1]; + eq[14][i].in[1] <== 48; eq[15][i] = IsEqual(); eq[15][i].in[0] <== in[i]; - eq[15][i].in[1] <== 13; - and[4][i] = AND(); - and[4][i].a <== states[i][0]; - and[4][i].b <== eq[15][i].out; - and[5][i] = AND(); - and[5][i].a <== states[i][3]; - and[5][i].b <== eq[15][i].out; - multi_or[2][i] = MultiOR(2); - multi_or[2][i].in[0] <== and[4][i].out; - multi_or[2][i].in[1] <== and[5][i].out; - states[i+1][2] <== multi_or[2][i].out; - state_changed[i].in[1] <== states[i+1][2]; + eq[15][i].in[1] <== 49; eq[16][i] = IsEqual(); eq[16][i].in[0] <== in[i]; - eq[16][i].in[1] <== 255; - and[6][i] = AND(); - and[6][i].a <== states[i][0]; - and[6][i].b <== eq[16][i].out; + eq[16][i].in[1] <== 50; eq[17][i] = IsEqual(); eq[17][i].in[0] <== in[i]; - eq[17][i].in[1] <== 10; - and[7][i] = AND(); - and[7][i].a <== states[i][2]; - and[7][i].b <== eq[17][i].out; - multi_or[3][i] = MultiOR(2); - multi_or[3][i].in[0] <== and[6][i].out; - multi_or[3][i].in[1] <== and[7][i].out; - states[i+1][3] <== multi_or[3][i].out; - state_changed[i].in[2] <== states[i+1][3]; + eq[17][i].in[1] <== 51; eq[18][i] = IsEqual(); eq[18][i].in[0] <== in[i]; - eq[18][i].in[1] <== 62; - and[8][i] = AND(); - and[8][i].a <== states[i][1]; - and[8][i].b <== eq[18][i].out; - states[i+1][4] <== and[8][i].out; - state_changed[i].in[3] <== states[i+1][4]; + eq[18][i].in[1] <== 52; eq[19][i] = IsEqual(); eq[19][i].in[0] <== in[i]; - eq[19][i].in[1] <== 109; - and[9][i] = AND(); - and[9][i].a <== states[i][3]; - and[9][i].b <== eq[19][i].out; - states[i+1][5] <== and[9][i].out; - state_changed[i].in[4] <== states[i+1][5]; - and[10][i] = AND(); - and[10][i].a <== states[i][4]; - and[10][i].b <== eq[15][i].out; - states[i+1][6] <== and[10][i].out; - state_changed[i].in[5] <== states[i+1][6]; - and[11][i] = AND(); - and[11][i].a <== states[i][6]; - and[11][i].b <== eq[17][i].out; - states[i+1][7] <== and[11][i].out; - state_changed[i].in[6] <== states[i+1][7]; + eq[19][i].in[1] <== 53; eq[20][i] = IsEqual(); eq[20][i].in[0] <== in[i]; - eq[20][i].in[1] <== 101; - and[12][i] = AND(); - and[12][i].a <== states[i][5]; - and[12][i].b <== eq[20][i].out; - states[i+1][8] <== and[12][i].out; - state_changed[i].in[7] <== states[i+1][8]; + eq[20][i].in[1] <== 54; eq[21][i] = IsEqual(); eq[21][i].in[0] <== in[i]; - eq[21][i].in[1] <== 115; - and[13][i] = AND(); - and[13][i].a <== states[i][8]; - and[13][i].b <== eq[21][i].out; - states[i+1][9] <== and[13][i].out; - state_changed[i].in[8] <== states[i+1][9]; - and[14][i] = AND(); - and[14][i].a <== states[i][9]; - and[14][i].b <== eq[21][i].out; - states[i+1][10] <== and[14][i].out; - state_changed[i].in[9] <== states[i+1][10]; + eq[21][i].in[1] <== 55; eq[22][i] = IsEqual(); eq[22][i].in[0] <== in[i]; - eq[22][i].in[1] <== 97; - and[15][i] = AND(); - and[15][i].a <== states[i][10]; - and[15][i].b <== eq[22][i].out; - states[i+1][11] <== and[15][i].out; - state_changed[i].in[10] <== states[i+1][11]; + eq[22][i].in[1] <== 56; eq[23][i] = IsEqual(); eq[23][i].in[0] <== in[i]; - eq[23][i].in[1] <== 103; - and[16][i] = AND(); - and[16][i].a <== states[i][11]; - and[16][i].b <== eq[23][i].out; - states[i+1][12] <== and[16][i].out; - state_changed[i].in[11] <== states[i+1][12]; - and[17][i] = AND(); - and[17][i].a <== states[i][12]; - and[17][i].b <== eq[20][i].out; - states[i+1][13] <== and[17][i].out; - state_changed[i].in[12] <== states[i+1][13]; - and[18][i] = AND(); - and[18][i].a <== states[i][13]; - and[18][i].b <== eq[1][i].out; - states[i+1][14] <== and[18][i].out; - state_changed[i].in[13] <== states[i+1][14]; + eq[23][i].in[1] <== 57; eq[24][i] = IsEqual(); eq[24][i].in[0] <== in[i]; - eq[24][i].in[1] <== 105; - and[19][i] = AND(); - and[19][i].a <== states[i][14]; - and[19][i].b <== eq[24][i].out; - states[i+1][15] <== and[19][i].out; - state_changed[i].in[14] <== states[i+1][15]; + eq[24][i].in[1] <== 61; eq[25][i] = IsEqual(); eq[25][i].in[0] <== in[i]; - eq[25][i].in[1] <== 100; - and[20][i] = AND(); - and[20][i].a <== states[i][15]; - and[20][i].b <== eq[25][i].out; - states[i+1][16] <== and[20][i].out; - state_changed[i].in[15] <== states[i+1][16]; + eq[25][i].in[1] <== 95; + and[17][i] = AND(); + and[17][i].a <== states[i][14]; + multi_or[1][i] = MultiOR(17); + multi_or[1][i].in[0] <== and[15][i].out; + multi_or[1][i].in[1] <== and[16][i].out; + multi_or[1][i].in[2] <== eq[12][i].out; + multi_or[1][i].in[3] <== eq[7][i].out; + multi_or[1][i].in[4] <== eq[13][i].out; + multi_or[1][i].in[5] <== eq[14][i].out; + multi_or[1][i].in[6] <== eq[15][i].out; + multi_or[1][i].in[7] <== eq[16][i].out; + multi_or[1][i].in[8] <== eq[17][i].out; + multi_or[1][i].in[9] <== eq[18][i].out; + multi_or[1][i].in[10] <== eq[19][i].out; + multi_or[1][i].in[11] <== eq[20][i].out; + multi_or[1][i].in[12] <== eq[21][i].out; + multi_or[1][i].in[13] <== eq[22][i].out; + multi_or[1][i].in[14] <== eq[23][i].out; + multi_or[1][i].in[15] <== eq[24][i].out; + multi_or[1][i].in[16] <== eq[25][i].out; + and[17][i].b <== multi_or[1][i].out; + and[18][i] = AND(); + and[18][i].a <== states[i][15]; + and[18][i].b <== multi_or[1][i].out; + multi_or[2][i] = MultiOR(2); + multi_or[2][i].in[0] <== and[17][i].out; + multi_or[2][i].in[1] <== and[18][i].out; + states[i+1][15] <== multi_or[2][i].out; + state_changed[i].in[14] <== states[i+1][15]; eq[26][i] = IsEqual(); eq[26][i].in[0] <== in[i]; - eq[26][i].in[1] <== 58; - and[21][i] = AND(); - and[21][i].a <== states[i][16]; - and[21][i].b <== eq[26][i].out; - states[i+1][17] <== and[21][i].out; + eq[26][i].in[1] <== 62; + and[19][i] = AND(); + and[19][i].a <== states[i][15]; + and[19][i].b <== eq[26][i].out; + states[i+1][16] <== and[19][i].out; + state_changed[i].in[15] <== states[i+1][16]; + and[20][i] = AND(); + and[20][i].a <== states[i][16]; + and[20][i].b <== eq[1][i].out; + states[i+1][17] <== and[20][i].out; state_changed[i].in[16] <== states[i+1][17]; - eq[27][i] = IsEqual(); - eq[27][i].in[0] <== in[i]; - eq[27][i].in[1] <== 60; - and[22][i] = AND(); - and[22][i].a <== states[i][17]; - and[22][i].b <== eq[27][i].out; - states[i+1][18] <== and[22][i].out; + and[21][i] = AND(); + and[21][i].a <== states[i][17]; + and[21][i].b <== eq[3][i].out; + states[i+1][18] <== and[21][i].out; state_changed[i].in[17] <== states[i+1][18]; states[i+1][0] <== 1 - state_changed[i].out; } component final_state_result = MultiOR(num_bytes+1); for (var i = 0; i <= num_bytes; i++) { - final_state_result.in[i] <== states[i][7]; + final_state_result.in[i] <== states[i][18]; } out <== final_state_result.out; - signal is_consecutive[msg_bytes+1][2]; is_consecutive[msg_bytes][1] <== 1; for (var i = 0; i < msg_bytes; i++) { - is_consecutive[msg_bytes-1-i][0] <== states[num_bytes-i][7] * (1 - is_consecutive[msg_bytes-i][1]) + is_consecutive[msg_bytes-i][1]; + is_consecutive[msg_bytes-1-i][0] <== states[num_bytes-i][18] * (1 - is_consecutive[msg_bytes-i][1]) + is_consecutive[msg_bytes-i][1]; is_consecutive[msg_bytes-1-i][1] <== state_changed[msg_bytes-i].out * is_consecutive[msg_bytes-1-i][0]; } + // substrings calculated: [{(13, 14), (14, 15), (15, 15), (15, 16)}] signal is_substr0[msg_bytes][5]; signal is_reveal0[msg_bytes]; signal output reveal0[msg_bytes]; for (var i = 0; i < msg_bytes; i++) { is_substr0[i][0] <== 0; - // the 0-th substring transitions: [(1, 1), (1, 4), (17, 18), (18, 1)] - is_substr0[i][1] <== is_substr0[i][0] + states[i+1][1] * states[i+2][1]; - is_substr0[i][2] <== is_substr0[i][1] + states[i+1][1] * states[i+2][4]; - is_substr0[i][3] <== is_substr0[i][2] + states[i+1][17] * states[i+2][18]; - is_substr0[i][4] <== is_substr0[i][3] + states[i+1][18] * states[i+2][1]; + // the 0-th substring transitions: [(13, 14), (14, 15), (15, 15), (15, 16)] + is_substr0[i][1] <== is_substr0[i][0] + states[i+1][13] * states[i+2][14]; + is_substr0[i][2] <== is_substr0[i][1] + states[i+1][14] * states[i+2][15]; + is_substr0[i][3] <== is_substr0[i][2] + states[i+1][15] * states[i+2][15]; + is_substr0[i][4] <== is_substr0[i][3] + states[i+1][15] * states[i+2][16]; is_reveal0[i] <== is_substr0[i][4] * is_consecutive[i][1]; reveal0[i] <== in[i+1] * is_reveal0[i]; } diff --git a/packages/circom/circuits/common/subject_all.json b/packages/circom/circuits/common/subject_all.json index fd00df4..ed7d761 100644 --- a/packages/circom/circuits/common/subject_all.json +++ b/packages/circom/circuits/common/subject_all.json @@ -1,16 +1,16 @@ { - "parts": [ - { - "is_public": false, - "regex_def": "((\r\n)|^)subject:" - }, - { - "is_public": true, - "regex_def": "[^\r\n]+" - }, - { - "is_public": false, - "regex_def": "\r\n" - } - ] -} \ No newline at end of file + "parts": [ + { + "is_public": false, + "regex_def": "((\r\n)|^)subject:" + }, + { + "is_public": true, + "regex_def": "[^\r\n]+" + }, + { + "is_public": false, + "regex_def": "\r\n" + } + ] +} diff --git a/packages/circom/circuits/common/subject_all_regex.circom b/packages/circom/circuits/common/subject_all_regex.circom index ab6392b..6a2ad14 100644 --- a/packages/circom/circuits/common/subject_all_regex.circom +++ b/packages/circom/circuits/common/subject_all_regex.circom @@ -2,7 +2,7 @@ pragma circom 2.1.5; include "@zk-email/zk-regex-circom/circuits/regex_helpers.circom"; -// regex: (( \n)|^)subject:[^ \n]+ \n +// regex: ((\r\n)|^)subject:[^\r\n]+\r\n template SubjectAllRegex(msg_bytes) { signal input msg[msg_bytes]; signal output out; @@ -14,219 +14,528 @@ template SubjectAllRegex(msg_bytes) { in[i+1] <== msg[i]; } - component eq[23][num_bytes]; - component lt[2][num_bytes]; - component and[17][num_bytes]; - component multi_or[4][num_bytes]; - signal states[num_bytes+1][14]; + component eq[59][num_bytes]; + component lt[12][num_bytes]; + component and[42][num_bytes]; + component multi_or[13][num_bytes]; + signal states[num_bytes+1][21]; component state_changed[num_bytes]; states[0][0] <== 1; - for (var i = 1; i < 14; i++) { + for (var i = 1; i < 21; i++) { states[0][i] <== 0; } for (var i = 0; i < num_bytes; i++) { - state_changed[i] = MultiOR(13); - 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] <== 254; - and[0][i] = AND(); - and[0][i].a <== lt[0][i].out; - and[0][i].b <== lt[1][i].out; + state_changed[i] = MultiOR(20); eq[0][i] = IsEqual(); eq[0][i].in[0] <== in[i]; - eq[0][i].in[1] <== 0; + eq[0][i].in[1] <== 115; + and[0][i] = AND(); + and[0][i].a <== states[i][0]; + and[0][i].b <== eq[0][i].out; + and[1][i] = AND(); + and[1][i].a <== states[i][4]; + and[1][i].b <== eq[0][i].out; + multi_or[0][i] = MultiOR(2); + multi_or[0][i].in[0] <== and[0][i].out; + multi_or[0][i].in[1] <== and[1][i].out; + states[i+1][1] <== multi_or[0][i].out; + state_changed[i].in[0] <== states[i+1][1]; eq[1][i] = IsEqual(); eq[1][i].in[0] <== in[i]; - eq[1][i].in[1] <== 1; + eq[1][i].in[1] <== 13; + and[2][i] = AND(); + and[2][i].a <== states[i][0]; + and[2][i].b <== eq[1][i].out; + states[i+1][2] <== and[2][i].out; + state_changed[i].in[1] <== states[i+1][2]; eq[2][i] = IsEqual(); eq[2][i].in[0] <== in[i]; - eq[2][i].in[1] <== 2; + eq[2][i].in[1] <== 117; + and[3][i] = AND(); + and[3][i].a <== states[i][1]; + and[3][i].b <== eq[2][i].out; + states[i+1][3] <== and[3][i].out; + state_changed[i].in[2] <== states[i+1][3]; eq[3][i] = IsEqual(); eq[3][i].in[0] <== in[i]; - eq[3][i].in[1] <== 3; + eq[3][i].in[1] <== 10; + and[4][i] = AND(); + and[4][i].a <== states[i][2]; + and[4][i].b <== eq[3][i].out; + states[i+1][4] <== and[4][i].out; + state_changed[i].in[3] <== states[i+1][4]; eq[4][i] = IsEqual(); eq[4][i].in[0] <== in[i]; - eq[4][i].in[1] <== 4; + eq[4][i].in[1] <== 98; + and[5][i] = AND(); + and[5][i].a <== states[i][3]; + and[5][i].b <== eq[4][i].out; + states[i+1][5] <== and[5][i].out; + state_changed[i].in[4] <== states[i+1][5]; eq[5][i] = IsEqual(); eq[5][i].in[0] <== in[i]; - eq[5][i].in[1] <== 5; + eq[5][i].in[1] <== 106; + and[6][i] = AND(); + and[6][i].a <== states[i][5]; + and[6][i].b <== eq[5][i].out; + states[i+1][6] <== and[6][i].out; + state_changed[i].in[5] <== states[i+1][6]; eq[6][i] = IsEqual(); eq[6][i].in[0] <== in[i]; - eq[6][i].in[1] <== 6; + eq[6][i].in[1] <== 101; + and[7][i] = AND(); + and[7][i].a <== states[i][6]; + and[7][i].b <== eq[6][i].out; + states[i+1][7] <== and[7][i].out; + state_changed[i].in[6] <== states[i+1][7]; eq[7][i] = IsEqual(); eq[7][i].in[0] <== in[i]; - eq[7][i].in[1] <== 7; + eq[7][i].in[1] <== 99; + and[8][i] = AND(); + and[8][i].a <== states[i][7]; + and[8][i].b <== eq[7][i].out; + states[i+1][8] <== and[8][i].out; + state_changed[i].in[7] <== states[i+1][8]; eq[8][i] = IsEqual(); eq[8][i].in[0] <== in[i]; - eq[8][i].in[1] <== 8; + eq[8][i].in[1] <== 116; + and[9][i] = AND(); + and[9][i].a <== states[i][8]; + and[9][i].b <== eq[8][i].out; + states[i+1][9] <== and[9][i].out; + state_changed[i].in[8] <== states[i+1][9]; eq[9][i] = IsEqual(); eq[9][i].in[0] <== in[i]; - eq[9][i].in[1] <== 9; + eq[9][i].in[1] <== 58; + and[10][i] = AND(); + and[10][i].a <== states[i][9]; + and[10][i].b <== eq[9][i].out; + states[i+1][10] <== and[10][i].out; + state_changed[i].in[9] <== states[i+1][10]; + lt[0][i] = LessEqThan(8); + lt[0][i].in[0] <== 194; + lt[0][i].in[1] <== in[i]; + lt[1][i] = LessEqThan(8); + lt[1][i].in[0] <== in[i]; + lt[1][i].in[1] <== 223; + and[11][i] = AND(); + and[11][i].a <== lt[0][i].out; + and[11][i].b <== lt[1][i].out; + and[12][i] = AND(); + and[12][i].a <== states[i][10]; + and[12][i].b <== and[11][i].out; + lt[2][i] = LessEqThan(8); + lt[2][i].in[0] <== 160; + lt[2][i].in[1] <== in[i]; + lt[3][i] = LessEqThan(8); + lt[3][i].in[0] <== in[i]; + lt[3][i].in[1] <== 191; + and[13][i] = AND(); + and[13][i].a <== lt[2][i].out; + and[13][i].b <== lt[3][i].out; + and[14][i] = AND(); + and[14][i].a <== states[i][12]; + and[14][i].b <== and[13][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[15][i] = AND(); + and[15][i].a <== lt[4][i].out; + and[15][i].b <== lt[5][i].out; + and[16][i] = AND(); + and[16][i].a <== states[i][13]; + and[16][i].b <== and[15][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] <== 159; + and[17][i] = AND(); + and[17][i].a <== lt[6][i].out; + and[17][i].b <== lt[7][i].out; + and[18][i] = AND(); + and[18][i].a <== states[i][14]; + and[18][i].b <== and[17][i].out; + and[19][i] = AND(); + and[19][i].a <== states[i][18]; + and[19][i].b <== and[11][i].out; + multi_or[1][i] = MultiOR(5); + multi_or[1][i].in[0] <== and[12][i].out; + multi_or[1][i].in[1] <== and[14][i].out; + multi_or[1][i].in[2] <== and[16][i].out; + multi_or[1][i].in[3] <== and[18][i].out; + multi_or[1][i].in[4] <== and[19][i].out; + states[i+1][11] <== multi_or[1][i].out; + state_changed[i].in[10] <== states[i+1][11]; eq[10][i] = IsEqual(); eq[10][i].in[0] <== in[i]; - eq[10][i].in[1] <== 11; + eq[10][i].in[1] <== 224; + and[20][i] = AND(); + and[20][i].a <== states[i][10]; + and[20][i].b <== eq[10][i].out; + and[21][i] = AND(); + and[21][i].a <== states[i][18]; + and[21][i].b <== eq[10][i].out; + multi_or[2][i] = MultiOR(2); + multi_or[2][i].in[0] <== and[20][i].out; + multi_or[2][i].in[1] <== and[21][i].out; + states[i+1][12] <== multi_or[2][i].out; + state_changed[i].in[11] <== states[i+1][12]; eq[11][i] = IsEqual(); eq[11][i].in[0] <== in[i]; - eq[11][i].in[1] <== 12; - and[1][i] = AND(); - and[1][i].a <== states[i][1]; - multi_or[0][i] = MultiOR(13); - 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; - multi_or[0][i].in[12] <== eq[11][i].out; - and[1][i].b <== multi_or[0][i].out; - and[2][i] = AND(); - and[2][i].a <== states[i][12]; - and[2][i].b <== multi_or[0][i].out; - multi_or[1][i] = MultiOR(2); - multi_or[1][i].in[0] <== and[1][i].out; - multi_or[1][i].in[1] <== and[2][i].out; - states[i+1][1] <== multi_or[1][i].out; - state_changed[i].in[0] <== states[i+1][1]; + eq[11][i].in[1] <== 225; eq[12][i] = IsEqual(); eq[12][i].in[0] <== in[i]; - eq[12][i].in[1] <== 13; - and[3][i] = AND(); - and[3][i].a <== states[i][0]; - and[3][i].b <== eq[12][i].out; - and[4][i] = AND(); - and[4][i].a <== states[i][3]; - and[4][i].b <== eq[12][i].out; - multi_or[2][i] = MultiOR(2); - multi_or[2][i].in[0] <== and[3][i].out; - multi_or[2][i].in[1] <== and[4][i].out; - states[i+1][2] <== multi_or[2][i].out; - state_changed[i].in[1] <== states[i+1][2]; + eq[12][i].in[1] <== 226; eq[13][i] = IsEqual(); eq[13][i].in[0] <== in[i]; - eq[13][i].in[1] <== 255; - and[5][i] = AND(); - and[5][i].a <== states[i][0]; - and[5][i].b <== eq[13][i].out; + eq[13][i].in[1] <== 227; eq[14][i] = IsEqual(); eq[14][i].in[0] <== in[i]; - eq[14][i].in[1] <== 10; - and[6][i] = AND(); - and[6][i].a <== states[i][2]; - and[6][i].b <== eq[14][i].out; - multi_or[3][i] = MultiOR(2); - multi_or[3][i].in[0] <== and[5][i].out; - multi_or[3][i].in[1] <== and[6][i].out; - states[i+1][3] <== multi_or[3][i].out; - state_changed[i].in[2] <== states[i+1][3]; + eq[14][i].in[1] <== 228; eq[15][i] = IsEqual(); eq[15][i].in[0] <== in[i]; - eq[15][i].in[1] <== 115; - and[7][i] = AND(); - and[7][i].a <== states[i][3]; - and[7][i].b <== eq[15][i].out; - states[i+1][4] <== and[7][i].out; - state_changed[i].in[3] <== states[i+1][4]; + eq[15][i].in[1] <== 229; eq[16][i] = IsEqual(); eq[16][i].in[0] <== in[i]; - eq[16][i].in[1] <== 117; - and[8][i] = AND(); - and[8][i].a <== states[i][4]; - and[8][i].b <== eq[16][i].out; - states[i+1][5] <== and[8][i].out; - state_changed[i].in[4] <== states[i+1][5]; + eq[16][i].in[1] <== 230; eq[17][i] = IsEqual(); eq[17][i].in[0] <== in[i]; - eq[17][i].in[1] <== 98; - and[9][i] = AND(); - and[9][i].a <== states[i][5]; - and[9][i].b <== eq[17][i].out; - states[i+1][6] <== and[9][i].out; - state_changed[i].in[5] <== states[i+1][6]; + eq[17][i].in[1] <== 231; eq[18][i] = IsEqual(); eq[18][i].in[0] <== in[i]; - eq[18][i].in[1] <== 106; - and[10][i] = AND(); - and[10][i].a <== states[i][6]; - and[10][i].b <== eq[18][i].out; - states[i+1][7] <== and[10][i].out; - state_changed[i].in[6] <== states[i+1][7]; + eq[18][i].in[1] <== 232; eq[19][i] = IsEqual(); eq[19][i].in[0] <== in[i]; - eq[19][i].in[1] <== 101; - and[11][i] = AND(); - and[11][i].a <== states[i][7]; - and[11][i].b <== eq[19][i].out; - states[i+1][8] <== and[11][i].out; - state_changed[i].in[7] <== states[i+1][8]; + eq[19][i].in[1] <== 233; eq[20][i] = IsEqual(); eq[20][i].in[0] <== in[i]; - eq[20][i].in[1] <== 99; - and[12][i] = AND(); - and[12][i].a <== states[i][8]; - and[12][i].b <== eq[20][i].out; - states[i+1][9] <== and[12][i].out; - state_changed[i].in[8] <== states[i+1][9]; - and[13][i] = AND(); - and[13][i].a <== states[i][1]; - and[13][i].b <== eq[12][i].out; - states[i+1][10] <== and[13][i].out; - state_changed[i].in[9] <== states[i+1][10]; + eq[20][i].in[1] <== 234; eq[21][i] = IsEqual(); eq[21][i].in[0] <== in[i]; - eq[21][i].in[1] <== 116; - and[14][i] = AND(); - and[14][i].a <== states[i][9]; - and[14][i].b <== eq[21][i].out; - states[i+1][11] <== and[14][i].out; - state_changed[i].in[10] <== states[i+1][11]; + eq[21][i].in[1] <== 235; eq[22][i] = IsEqual(); eq[22][i].in[0] <== in[i]; - eq[22][i].in[1] <== 58; - and[15][i] = AND(); - and[15][i].a <== states[i][11]; - and[15][i].b <== eq[22][i].out; - states[i+1][12] <== and[15][i].out; - state_changed[i].in[11] <== states[i+1][12]; - and[16][i] = AND(); - and[16][i].a <== states[i][10]; - and[16][i].b <== eq[14][i].out; - states[i+1][13] <== and[16][i].out; + eq[22][i].in[1] <== 236; + eq[23][i] = IsEqual(); + eq[23][i].in[0] <== in[i]; + eq[23][i].in[1] <== 238; + eq[24][i] = IsEqual(); + eq[24][i].in[0] <== in[i]; + eq[24][i].in[1] <== 239; + and[22][i] = AND(); + and[22][i].a <== states[i][10]; + multi_or[3][i] = MultiOR(14); + multi_or[3][i].in[0] <== eq[11][i].out; + multi_or[3][i].in[1] <== eq[12][i].out; + multi_or[3][i].in[2] <== eq[13][i].out; + multi_or[3][i].in[3] <== eq[14][i].out; + multi_or[3][i].in[4] <== eq[15][i].out; + multi_or[3][i].in[5] <== eq[16][i].out; + multi_or[3][i].in[6] <== eq[17][i].out; + multi_or[3][i].in[7] <== eq[18][i].out; + multi_or[3][i].in[8] <== eq[19][i].out; + multi_or[3][i].in[9] <== eq[20][i].out; + multi_or[3][i].in[10] <== eq[21][i].out; + multi_or[3][i].in[11] <== eq[22][i].out; + multi_or[3][i].in[12] <== eq[23][i].out; + multi_or[3][i].in[13] <== eq[24][i].out; + and[22][i].b <== multi_or[3][i].out; + lt[8][i] = LessEqThan(8); + lt[8][i].in[0] <== 144; + 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[23][i] = AND(); + and[23][i].a <== lt[8][i].out; + and[23][i].b <== lt[9][i].out; + and[24][i] = AND(); + and[24][i].a <== states[i][15]; + and[24][i].b <== and[23][i].out; + and[25][i] = AND(); + and[25][i].a <== states[i][16]; + and[25][i].b <== and[15][i].out; + eq[25][i] = IsEqual(); + eq[25][i].in[0] <== in[i]; + eq[25][i].in[1] <== 128; + eq[26][i] = IsEqual(); + eq[26][i].in[0] <== in[i]; + eq[26][i].in[1] <== 129; + eq[27][i] = IsEqual(); + eq[27][i].in[0] <== in[i]; + eq[27][i].in[1] <== 130; + eq[28][i] = IsEqual(); + eq[28][i].in[0] <== in[i]; + eq[28][i].in[1] <== 131; + eq[29][i] = IsEqual(); + eq[29][i].in[0] <== in[i]; + eq[29][i].in[1] <== 132; + eq[30][i] = IsEqual(); + eq[30][i].in[0] <== in[i]; + eq[30][i].in[1] <== 133; + eq[31][i] = IsEqual(); + eq[31][i].in[0] <== in[i]; + eq[31][i].in[1] <== 134; + eq[32][i] = IsEqual(); + eq[32][i].in[0] <== in[i]; + eq[32][i].in[1] <== 135; + eq[33][i] = IsEqual(); + eq[33][i].in[0] <== in[i]; + eq[33][i].in[1] <== 136; + eq[34][i] = IsEqual(); + eq[34][i].in[0] <== in[i]; + eq[34][i].in[1] <== 137; + eq[35][i] = IsEqual(); + eq[35][i].in[0] <== in[i]; + eq[35][i].in[1] <== 138; + eq[36][i] = IsEqual(); + eq[36][i].in[0] <== in[i]; + eq[36][i].in[1] <== 139; + eq[37][i] = IsEqual(); + eq[37][i].in[0] <== in[i]; + eq[37][i].in[1] <== 140; + eq[38][i] = IsEqual(); + eq[38][i].in[0] <== in[i]; + eq[38][i].in[1] <== 141; + eq[39][i] = IsEqual(); + eq[39][i].in[0] <== in[i]; + eq[39][i].in[1] <== 142; + eq[40][i] = IsEqual(); + eq[40][i].in[0] <== in[i]; + eq[40][i].in[1] <== 143; + and[26][i] = AND(); + and[26][i].a <== states[i][17]; + multi_or[4][i] = MultiOR(16); + multi_or[4][i].in[0] <== eq[25][i].out; + multi_or[4][i].in[1] <== eq[26][i].out; + multi_or[4][i].in[2] <== eq[27][i].out; + multi_or[4][i].in[3] <== eq[28][i].out; + multi_or[4][i].in[4] <== eq[29][i].out; + multi_or[4][i].in[5] <== eq[30][i].out; + multi_or[4][i].in[6] <== eq[31][i].out; + multi_or[4][i].in[7] <== eq[32][i].out; + multi_or[4][i].in[8] <== eq[33][i].out; + multi_or[4][i].in[9] <== eq[34][i].out; + multi_or[4][i].in[10] <== eq[35][i].out; + multi_or[4][i].in[11] <== eq[36][i].out; + multi_or[4][i].in[12] <== eq[37][i].out; + multi_or[4][i].in[13] <== eq[38][i].out; + multi_or[4][i].in[14] <== eq[39][i].out; + multi_or[4][i].in[15] <== eq[40][i].out; + and[26][i].b <== multi_or[4][i].out; + and[27][i] = AND(); + and[27][i].a <== states[i][18]; + and[27][i].b <== multi_or[3][i].out; + multi_or[5][i] = MultiOR(5); + multi_or[5][i].in[0] <== and[22][i].out; + multi_or[5][i].in[1] <== and[24][i].out; + multi_or[5][i].in[2] <== and[25][i].out; + multi_or[5][i].in[3] <== and[26][i].out; + multi_or[5][i].in[4] <== and[27][i].out; + states[i+1][13] <== multi_or[5][i].out; state_changed[i].in[12] <== states[i+1][13]; + eq[41][i] = IsEqual(); + eq[41][i].in[0] <== in[i]; + eq[41][i].in[1] <== 237; + and[28][i] = AND(); + and[28][i].a <== states[i][10]; + and[28][i].b <== eq[41][i].out; + and[29][i] = AND(); + and[29][i].a <== states[i][18]; + and[29][i].b <== eq[41][i].out; + multi_or[6][i] = MultiOR(2); + multi_or[6][i].in[0] <== and[28][i].out; + multi_or[6][i].in[1] <== and[29][i].out; + states[i+1][14] <== multi_or[6][i].out; + state_changed[i].in[13] <== states[i+1][14]; + eq[42][i] = IsEqual(); + eq[42][i].in[0] <== in[i]; + eq[42][i].in[1] <== 240; + and[30][i] = AND(); + and[30][i].a <== states[i][10]; + and[30][i].b <== eq[42][i].out; + and[31][i] = AND(); + and[31][i].a <== states[i][18]; + and[31][i].b <== eq[42][i].out; + multi_or[7][i] = MultiOR(2); + multi_or[7][i].in[0] <== and[30][i].out; + multi_or[7][i].in[1] <== and[31][i].out; + states[i+1][15] <== multi_or[7][i].out; + state_changed[i].in[14] <== states[i+1][15]; + eq[43][i] = IsEqual(); + eq[43][i].in[0] <== in[i]; + eq[43][i].in[1] <== 241; + eq[44][i] = IsEqual(); + eq[44][i].in[0] <== in[i]; + eq[44][i].in[1] <== 242; + eq[45][i] = IsEqual(); + eq[45][i].in[0] <== in[i]; + eq[45][i].in[1] <== 243; + and[32][i] = AND(); + and[32][i].a <== states[i][10]; + multi_or[8][i] = MultiOR(3); + multi_or[8][i].in[0] <== eq[43][i].out; + multi_or[8][i].in[1] <== eq[44][i].out; + multi_or[8][i].in[2] <== eq[45][i].out; + and[32][i].b <== multi_or[8][i].out; + and[33][i] = AND(); + and[33][i].a <== states[i][18]; + and[33][i].b <== multi_or[8][i].out; + multi_or[9][i] = MultiOR(2); + multi_or[9][i].in[0] <== and[32][i].out; + multi_or[9][i].in[1] <== and[33][i].out; + states[i+1][16] <== multi_or[9][i].out; + state_changed[i].in[15] <== states[i+1][16]; + eq[46][i] = IsEqual(); + eq[46][i].in[0] <== in[i]; + eq[46][i].in[1] <== 244; + and[34][i] = AND(); + and[34][i].a <== states[i][10]; + and[34][i].b <== eq[46][i].out; + and[35][i] = AND(); + and[35][i].a <== states[i][18]; + and[35][i].b <== eq[46][i].out; + multi_or[10][i] = MultiOR(2); + multi_or[10][i].in[0] <== and[34][i].out; + multi_or[10][i].in[1] <== and[35][i].out; + states[i+1][17] <== multi_or[10][i].out; + state_changed[i].in[16] <== states[i+1][17]; + lt[10][i] = LessEqThan(8); + lt[10][i].in[0] <== 14; + lt[10][i].in[1] <== in[i]; + lt[11][i] = LessEqThan(8); + lt[11][i].in[0] <== in[i]; + lt[11][i].in[1] <== 127; + and[36][i] = AND(); + and[36][i].a <== lt[10][i].out; + and[36][i].b <== lt[11][i].out; + eq[47][i] = IsEqual(); + eq[47][i].in[0] <== in[i]; + eq[47][i].in[1] <== 0; + eq[48][i] = IsEqual(); + eq[48][i].in[0] <== in[i]; + eq[48][i].in[1] <== 1; + eq[49][i] = IsEqual(); + eq[49][i].in[0] <== in[i]; + eq[49][i].in[1] <== 2; + eq[50][i] = IsEqual(); + eq[50][i].in[0] <== in[i]; + eq[50][i].in[1] <== 3; + eq[51][i] = IsEqual(); + eq[51][i].in[0] <== in[i]; + eq[51][i].in[1] <== 4; + eq[52][i] = IsEqual(); + eq[52][i].in[0] <== in[i]; + eq[52][i].in[1] <== 5; + eq[53][i] = IsEqual(); + eq[53][i].in[0] <== in[i]; + eq[53][i].in[1] <== 6; + eq[54][i] = IsEqual(); + eq[54][i].in[0] <== in[i]; + eq[54][i].in[1] <== 7; + eq[55][i] = IsEqual(); + eq[55][i].in[0] <== in[i]; + eq[55][i].in[1] <== 8; + eq[56][i] = IsEqual(); + eq[56][i].in[0] <== in[i]; + eq[56][i].in[1] <== 9; + eq[57][i] = IsEqual(); + eq[57][i].in[0] <== in[i]; + eq[57][i].in[1] <== 11; + eq[58][i] = IsEqual(); + eq[58][i].in[0] <== in[i]; + eq[58][i].in[1] <== 12; + and[37][i] = AND(); + and[37][i].a <== states[i][10]; + multi_or[11][i] = MultiOR(13); + multi_or[11][i].in[0] <== and[36][i].out; + multi_or[11][i].in[1] <== eq[47][i].out; + multi_or[11][i].in[2] <== eq[48][i].out; + multi_or[11][i].in[3] <== eq[49][i].out; + multi_or[11][i].in[4] <== eq[50][i].out; + multi_or[11][i].in[5] <== eq[51][i].out; + multi_or[11][i].in[6] <== eq[52][i].out; + multi_or[11][i].in[7] <== eq[53][i].out; + multi_or[11][i].in[8] <== eq[54][i].out; + multi_or[11][i].in[9] <== eq[55][i].out; + multi_or[11][i].in[10] <== eq[56][i].out; + multi_or[11][i].in[11] <== eq[57][i].out; + multi_or[11][i].in[12] <== eq[58][i].out; + and[37][i].b <== multi_or[11][i].out; + and[38][i] = AND(); + and[38][i].a <== states[i][11]; + and[38][i].b <== and[15][i].out; + and[39][i] = AND(); + and[39][i].a <== states[i][18]; + and[39][i].b <== multi_or[11][i].out; + multi_or[12][i] = MultiOR(3); + multi_or[12][i].in[0] <== and[37][i].out; + multi_or[12][i].in[1] <== and[38][i].out; + multi_or[12][i].in[2] <== and[39][i].out; + states[i+1][18] <== multi_or[12][i].out; + state_changed[i].in[17] <== states[i+1][18]; + and[40][i] = AND(); + and[40][i].a <== states[i][18]; + and[40][i].b <== eq[1][i].out; + states[i+1][19] <== and[40][i].out; + state_changed[i].in[18] <== states[i+1][19]; + and[41][i] = AND(); + and[41][i].a <== states[i][19]; + and[41][i].b <== eq[3][i].out; + states[i+1][20] <== and[41][i].out; + state_changed[i].in[19] <== states[i+1][20]; states[i+1][0] <== 1 - state_changed[i].out; } component final_state_result = MultiOR(num_bytes+1); for (var i = 0; i <= num_bytes; i++) { - final_state_result.in[i] <== states[i][13]; + final_state_result.in[i] <== states[i][20]; } out <== final_state_result.out; - signal is_consecutive[msg_bytes+1][2]; is_consecutive[msg_bytes][1] <== 1; 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][1]) + is_consecutive[msg_bytes-i][1]; + is_consecutive[msg_bytes-1-i][0] <== states[num_bytes-i][20] * (1 - is_consecutive[msg_bytes-i][1]) + is_consecutive[msg_bytes-i][1]; is_consecutive[msg_bytes-1-i][1] <== state_changed[msg_bytes-i].out * is_consecutive[msg_bytes-1-i][0]; } - signal is_substr0[msg_bytes][3]; + // substrings calculated: [{(10, 11), (10, 12), (10, 13), (10, 14), (10, 15), (10, 16), (10, 17), (10, 18), (11, 18), (12, 11), (13, 11), (14, 11), (15, 13), (16, 13), (17, 13), (18, 11), (18, 12), (18, 13), (18, 14), (18, 15), (18, 16), (18, 17), (18, 18)}] + signal is_substr0[msg_bytes][24]; signal is_reveal0[msg_bytes]; signal output reveal0[msg_bytes]; for (var i = 0; i < msg_bytes; i++) { is_substr0[i][0] <== 0; - // the 0-th substring transitions: [(1, 1), (12, 1)] - is_substr0[i][1] <== is_substr0[i][0] + states[i+1][1] * states[i+2][1]; - is_substr0[i][2] <== is_substr0[i][1] + states[i+1][12] * states[i+2][1]; - is_reveal0[i] <== is_substr0[i][2] * is_consecutive[i][1]; + // the 0-th substring transitions: [(10, 11), (10, 12), (10, 13), (10, 14), (10, 15), (10, 16), (10, 17), (10, 18), (11, 18), (12, 11), (13, 11), (14, 11), (15, 13), (16, 13), (17, 13), (18, 11), (18, 12), (18, 13), (18, 14), (18, 15), (18, 16), (18, 17), (18, 18)] + is_substr0[i][1] <== is_substr0[i][0] + states[i+1][10] * states[i+2][11]; + is_substr0[i][2] <== is_substr0[i][1] + states[i+1][10] * states[i+2][12]; + is_substr0[i][3] <== is_substr0[i][2] + states[i+1][10] * states[i+2][13]; + is_substr0[i][4] <== is_substr0[i][3] + states[i+1][10] * states[i+2][14]; + is_substr0[i][5] <== is_substr0[i][4] + states[i+1][10] * states[i+2][15]; + is_substr0[i][6] <== is_substr0[i][5] + states[i+1][10] * states[i+2][16]; + is_substr0[i][7] <== is_substr0[i][6] + states[i+1][10] * states[i+2][17]; + is_substr0[i][8] <== is_substr0[i][7] + states[i+1][10] * states[i+2][18]; + is_substr0[i][9] <== is_substr0[i][8] + states[i+1][11] * states[i+2][18]; + is_substr0[i][10] <== is_substr0[i][9] + states[i+1][12] * states[i+2][11]; + is_substr0[i][11] <== is_substr0[i][10] + states[i+1][13] * states[i+2][11]; + is_substr0[i][12] <== is_substr0[i][11] + states[i+1][14] * states[i+2][11]; + is_substr0[i][13] <== is_substr0[i][12] + states[i+1][15] * states[i+2][13]; + is_substr0[i][14] <== is_substr0[i][13] + states[i+1][16] * states[i+2][13]; + is_substr0[i][15] <== is_substr0[i][14] + states[i+1][17] * states[i+2][13]; + is_substr0[i][16] <== is_substr0[i][15] + states[i+1][18] * states[i+2][11]; + is_substr0[i][17] <== is_substr0[i][16] + states[i+1][18] * states[i+2][12]; + is_substr0[i][18] <== is_substr0[i][17] + states[i+1][18] * states[i+2][13]; + is_substr0[i][19] <== is_substr0[i][18] + states[i+1][18] * states[i+2][14]; + is_substr0[i][20] <== is_substr0[i][19] + states[i+1][18] * states[i+2][15]; + is_substr0[i][21] <== is_substr0[i][20] + states[i+1][18] * states[i+2][16]; + is_substr0[i][22] <== is_substr0[i][21] + states[i+1][18] * states[i+2][17]; + is_substr0[i][23] <== is_substr0[i][22] + states[i+1][18] * states[i+2][18]; + is_reveal0[i] <== is_substr0[i][23] * is_consecutive[i][1]; reveal0[i] <== in[i+1] * is_reveal0[i]; } } \ No newline at end of file diff --git a/packages/circom/circuits/common/timestamp.json b/packages/circom/circuits/common/timestamp.json index 10e4ffb..4e2895e 100644 --- a/packages/circom/circuits/common/timestamp.json +++ b/packages/circom/circuits/common/timestamp.json @@ -1,20 +1,20 @@ { - "parts": [ - { - "is_public": false, - "regex_def": "((\r\n)|^)dkim-signature:" - }, - { - "is_public": false, - "regex_def": "((a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z)+=[^;]+; )+t=" - }, - { - "is_public": true, - "regex_def": "(0|1|2|3|4|5|6|7|8|9)+" - }, - { - "is_public": false, - "regex_def": ";" - } - ] -} \ No newline at end of file + "parts": [ + { + "is_public": false, + "regex_def": "((\r\n)|^)dkim-signature:" + }, + { + "is_public": false, + "regex_def": "([a-z]+=[^;]+; )+t=" + }, + { + "is_public": true, + "regex_def": "[0-9]+" + }, + { + "is_public": false, + "regex_def": ";" + } + ] +} diff --git a/packages/circom/circuits/common/timestamp_regex.circom b/packages/circom/circuits/common/timestamp_regex.circom index 13910b2..2ff8518 100644 --- a/packages/circom/circuits/common/timestamp_regex.circom +++ b/packages/circom/circuits/common/timestamp_regex.circom @@ -2,7 +2,7 @@ pragma circom 2.1.5; include "@zk-email/zk-regex-circom/circuits/regex_helpers.circom"; -// regex: (( \n)|^)dkim-signature:((a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z)+=[^;]+; )+t=(0|1|2|3|4|5|6|7|8|9)+; +// regex: ((\r\n)|^)dkim-signature:([a-z]+=[^;]+; )+t=[0-9]+; template TimestampRegex(msg_bytes) { signal input msg[msg_bytes]; signal output out; @@ -14,401 +14,707 @@ template TimestampRegex(msg_bytes) { in[i+1] <== msg[i]; } - component eq[35][num_bytes]; - component lt[10][num_bytes]; - component and[41][num_bytes]; - component multi_or[10][num_bytes]; - signal states[num_bytes+1][27]; + component eq[71][num_bytes]; + component lt[20][num_bytes]; + component and[71][num_bytes]; + component multi_or[18][num_bytes]; + signal states[num_bytes+1][34]; component state_changed[num_bytes]; states[0][0] <== 1; - for (var i = 1; i < 27; i++) { + for (var i = 1; i < 34; i++) { states[0][i] <== 0; } for (var i = 0; i < num_bytes; i++) { - state_changed[i] = MultiOR(26); - lt[0][i] = LessEqThan(8); - lt[0][i].in[0] <== 97; - lt[0][i].in[1] <== in[i]; - lt[1][i] = LessEqThan(8); - lt[1][i].in[0] <== in[i]; - lt[1][i].in[1] <== 122; - and[0][i] = AND(); - and[0][i].a <== lt[0][i].out; - and[0][i].b <== lt[1][i].out; - and[1][i] = AND(); - and[1][i].a <== states[i][1]; - and[1][i].b <== and[0][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] <== 115; - and[2][i] = AND(); - and[2][i].a <== lt[2][i].out; - and[2][i].b <== lt[3][i].out; + state_changed[i] = MultiOR(33); eq[0][i] = IsEqual(); eq[0][i].in[0] <== in[i]; - eq[0][i].in[1] <== 117; + eq[0][i].in[1] <== 100; + and[0][i] = AND(); + and[0][i].a <== states[i][0]; + and[0][i].b <== eq[0][i].out; + and[1][i] = AND(); + and[1][i].a <== states[i][4]; + and[1][i].b <== eq[0][i].out; + multi_or[0][i] = MultiOR(2); + multi_or[0][i].in[0] <== and[0][i].out; + multi_or[0][i].in[1] <== and[1][i].out; + states[i+1][1] <== multi_or[0][i].out; + state_changed[i].in[0] <== states[i+1][1]; eq[1][i] = IsEqual(); eq[1][i].in[0] <== in[i]; - eq[1][i].in[1] <== 118; + eq[1][i].in[1] <== 13; + and[2][i] = AND(); + and[2][i].a <== states[i][0]; + and[2][i].b <== eq[1][i].out; + states[i+1][2] <== and[2][i].out; + state_changed[i].in[1] <== states[i+1][2]; eq[2][i] = IsEqual(); eq[2][i].in[0] <== in[i]; - eq[2][i].in[1] <== 119; + eq[2][i].in[1] <== 107; + and[3][i] = AND(); + and[3][i].a <== states[i][1]; + and[3][i].b <== eq[2][i].out; + states[i+1][3] <== and[3][i].out; + state_changed[i].in[2] <== states[i+1][3]; eq[3][i] = IsEqual(); eq[3][i].in[0] <== in[i]; - eq[3][i].in[1] <== 120; + eq[3][i].in[1] <== 10; + and[4][i] = AND(); + and[4][i].a <== states[i][2]; + and[4][i].b <== eq[3][i].out; + states[i+1][4] <== and[4][i].out; + state_changed[i].in[3] <== states[i+1][4]; eq[4][i] = IsEqual(); eq[4][i].in[0] <== in[i]; - eq[4][i].in[1] <== 121; + eq[4][i].in[1] <== 105; + and[5][i] = AND(); + and[5][i].a <== states[i][3]; + and[5][i].b <== eq[4][i].out; + states[i+1][5] <== and[5][i].out; + state_changed[i].in[4] <== states[i+1][5]; eq[5][i] = IsEqual(); eq[5][i].in[0] <== in[i]; - eq[5][i].in[1] <== 122; - and[3][i] = AND(); - and[3][i].a <== states[i][6]; - multi_or[0][i] = MultiOR(7); - multi_or[0][i].in[0] <== and[2][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; - and[3][i].b <== multi_or[0][i].out; - and[4][i] = AND(); - and[4][i].a <== states[i][24]; - and[4][i].b <== and[0][i].out; - and[5][i] = AND(); - and[5][i].a <== states[i][25]; - and[5][i].b <== and[0][i].out; - multi_or[1][i] = MultiOR(4); - multi_or[1][i].in[0] <== and[1][i].out; - multi_or[1][i].in[1] <== and[3][i].out; - multi_or[1][i].in[2] <== and[4][i].out; - multi_or[1][i].in[3] <== and[5][i].out; - states[i+1][1] <== multi_or[1][i].out; - state_changed[i].in[0] <== states[i+1][1]; - lt[4][i] = LessEqThan(8); - lt[4][i].in[0] <== 0; - lt[4][i].in[1] <== in[i]; - lt[5][i] = LessEqThan(8); - lt[5][i].in[0] <== in[i]; - lt[5][i].in[1] <== 58; + eq[5][i].in[1] <== 109; 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] <== 60; - lt[6][i].in[1] <== in[i]; - lt[7][i] = LessEqThan(8); - lt[7][i].in[0] <== in[i]; - lt[7][i].in[1] <== 254; - 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][2]; - multi_or[2][i] = MultiOR(2); - multi_or[2][i].in[0] <== and[6][i].out; - multi_or[2][i].in[1] <== and[7][i].out; - and[8][i].b <== multi_or[2][i].out; - lt[8][i] = LessEqThan(8); - lt[8][i].in[0] <== 0; - lt[8][i].in[1] <== in[i]; - lt[9][i] = LessEqThan(8); - lt[9][i].in[0] <== in[i]; - lt[9][i].in[1] <== 47; - and[9][i] = AND(); - and[9][i].a <== lt[8][i].out; - and[9][i].b <== lt[9][i].out; + and[6][i].a <== states[i][5]; + and[6][i].b <== eq[5][i].out; + states[i+1][6] <== and[6][i].out; + state_changed[i].in[5] <== states[i+1][6]; eq[6][i] = IsEqual(); eq[6][i].in[0] <== in[i]; - eq[6][i].in[1] <== 58; - and[10][i] = AND(); - and[10][i].a <== states[i][3]; - multi_or[3][i] = MultiOR(3); - multi_or[3][i].in[0] <== and[9][i].out; - multi_or[3][i].in[1] <== and[7][i].out; - multi_or[3][i].in[2] <== eq[6][i].out; - and[10][i].b <== multi_or[3][i].out; - and[11][i] = AND(); - and[11][i].a <== states[i][7]; - and[11][i].b <== multi_or[2][i].out; - and[12][i] = AND(); - and[12][i].a <== states[i][26]; - and[12][i].b <== multi_or[3][i].out; - multi_or[4][i] = MultiOR(4); - multi_or[4][i].in[0] <== and[8][i].out; - multi_or[4][i].in[1] <== and[10][i].out; - multi_or[4][i].in[2] <== and[11][i].out; - multi_or[4][i].in[3] <== and[12][i].out; - states[i+1][2] <== multi_or[4][i].out; - state_changed[i].in[1] <== states[i+1][2]; + eq[6][i].in[1] <== 45; + and[7][i] = AND(); + and[7][i].a <== states[i][6]; + and[7][i].b <== eq[6][i].out; + states[i+1][7] <== and[7][i].out; + state_changed[i].in[6] <== states[i+1][7]; eq[7][i] = IsEqual(); eq[7][i].in[0] <== in[i]; - eq[7][i].in[1] <== 48; + eq[7][i].in[1] <== 115; + and[8][i] = AND(); + and[8][i].a <== states[i][7]; + and[8][i].b <== eq[7][i].out; + states[i+1][8] <== and[8][i].out; + state_changed[i].in[7] <== states[i+1][8]; + and[9][i] = AND(); + and[9][i].a <== states[i][8]; + and[9][i].b <== eq[4][i].out; + states[i+1][9] <== and[9][i].out; + state_changed[i].in[8] <== states[i+1][9]; eq[8][i] = IsEqual(); eq[8][i].in[0] <== in[i]; - eq[8][i].in[1] <== 49; + eq[8][i].in[1] <== 103; + and[10][i] = AND(); + and[10][i].a <== states[i][9]; + and[10][i].b <== eq[8][i].out; + states[i+1][10] <== and[10][i].out; + state_changed[i].in[9] <== states[i+1][10]; eq[9][i] = IsEqual(); eq[9][i].in[0] <== in[i]; - eq[9][i].in[1] <== 50; + eq[9][i].in[1] <== 110; + and[11][i] = AND(); + and[11][i].a <== states[i][10]; + and[11][i].b <== eq[9][i].out; + states[i+1][11] <== and[11][i].out; + state_changed[i].in[10] <== states[i+1][11]; eq[10][i] = IsEqual(); eq[10][i].in[0] <== in[i]; - eq[10][i].in[1] <== 51; + eq[10][i].in[1] <== 97; + and[12][i] = AND(); + and[12][i].a <== states[i][11]; + and[12][i].b <== eq[10][i].out; + states[i+1][12] <== and[12][i].out; + state_changed[i].in[11] <== states[i+1][12]; eq[11][i] = IsEqual(); eq[11][i].in[0] <== in[i]; - eq[11][i].in[1] <== 52; + eq[11][i].in[1] <== 116; + and[13][i] = AND(); + and[13][i].a <== states[i][12]; + and[13][i].b <== eq[11][i].out; + states[i+1][13] <== and[13][i].out; + state_changed[i].in[12] <== states[i+1][13]; eq[12][i] = IsEqual(); eq[12][i].in[0] <== in[i]; - eq[12][i].in[1] <== 53; + eq[12][i].in[1] <== 117; + and[14][i] = AND(); + and[14][i].a <== states[i][13]; + and[14][i].b <== eq[12][i].out; + states[i+1][14] <== and[14][i].out; + state_changed[i].in[13] <== states[i+1][14]; eq[13][i] = IsEqual(); eq[13][i].in[0] <== in[i]; - eq[13][i].in[1] <== 54; + eq[13][i].in[1] <== 114; + and[15][i] = AND(); + and[15][i].a <== states[i][14]; + and[15][i].b <== eq[13][i].out; + states[i+1][15] <== and[15][i].out; + state_changed[i].in[14] <== states[i+1][15]; eq[14][i] = IsEqual(); eq[14][i].in[0] <== in[i]; - eq[14][i].in[1] <== 55; + eq[14][i].in[1] <== 101; + and[16][i] = AND(); + and[16][i].a <== states[i][15]; + and[16][i].b <== eq[14][i].out; + states[i+1][16] <== and[16][i].out; + state_changed[i].in[15] <== states[i+1][16]; eq[15][i] = IsEqual(); eq[15][i].in[0] <== in[i]; - eq[15][i].in[1] <== 56; + eq[15][i].in[1] <== 58; + and[17][i] = AND(); + and[17][i].a <== states[i][16]; + and[17][i].b <== eq[15][i].out; + states[i+1][17] <== and[17][i].out; + state_changed[i].in[16] <== states[i+1][17]; + lt[0][i] = LessEqThan(8); + lt[0][i].in[0] <== 97; + lt[0][i].in[1] <== in[i]; + lt[1][i] = LessEqThan(8); + lt[1][i].in[0] <== in[i]; + lt[1][i].in[1] <== 122; + and[18][i] = AND(); + and[18][i].a <== lt[0][i].out; + and[18][i].b <== lt[1][i].out; + and[19][i] = AND(); + and[19][i].a <== states[i][17]; + and[19][i].b <== and[18][i].out; + and[20][i] = AND(); + and[20][i].a <== states[i][18]; + and[20][i].b <== and[18][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] <== 115; + and[21][i] = AND(); + and[21][i].a <== lt[2][i].out; + and[21][i].b <== lt[3][i].out; eq[16][i] = IsEqual(); eq[16][i].in[0] <== in[i]; - eq[16][i].in[1] <== 57; - and[13][i] = AND(); - and[13][i].a <== states[i][3]; - multi_or[5][i] = MultiOR(10); - multi_or[5][i].in[0] <== eq[7][i].out; - multi_or[5][i].in[1] <== eq[8][i].out; - multi_or[5][i].in[2] <== eq[9][i].out; - multi_or[5][i].in[3] <== eq[10][i].out; - multi_or[5][i].in[4] <== eq[11][i].out; - multi_or[5][i].in[5] <== eq[12][i].out; - multi_or[5][i].in[6] <== eq[13][i].out; - multi_or[5][i].in[7] <== eq[14][i].out; - multi_or[5][i].in[8] <== eq[15][i].out; - multi_or[5][i].in[9] <== eq[16][i].out; - and[13][i].b <== multi_or[5][i].out; - and[14][i] = AND(); - and[14][i].a <== states[i][26]; - and[14][i].b <== multi_or[5][i].out; - multi_or[6][i] = MultiOR(2); - multi_or[6][i].in[0] <== and[13][i].out; - multi_or[6][i].in[1] <== and[14][i].out; - states[i+1][3] <== multi_or[6][i].out; - state_changed[i].in[2] <== states[i+1][3]; + eq[16][i].in[1] <== 118; eq[17][i] = IsEqual(); eq[17][i].in[0] <== in[i]; - eq[17][i].in[1] <== 59; - and[15][i] = AND(); - and[15][i].a <== states[i][2]; - and[15][i].b <== eq[17][i].out; - states[i+1][4] <== and[15][i].out; - state_changed[i].in[3] <== states[i+1][4]; - and[16][i] = AND(); - and[16][i].a <== states[i][3]; - and[16][i].b <== eq[17][i].out; - states[i+1][5] <== and[16][i].out; - state_changed[i].in[4] <== states[i+1][5]; + eq[17][i].in[1] <== 119; eq[18][i] = IsEqual(); eq[18][i].in[0] <== in[i]; - eq[18][i].in[1] <== 32; - and[17][i] = AND(); - and[17][i].a <== states[i][4]; - and[17][i].b <== eq[18][i].out; - and[18][i] = AND(); - and[18][i].a <== states[i][5]; - and[18][i].b <== eq[18][i].out; - multi_or[7][i] = MultiOR(2); - multi_or[7][i].in[0] <== and[17][i].out; - multi_or[7][i].in[1] <== and[18][i].out; - states[i+1][6] <== multi_or[7][i].out; - state_changed[i].in[5] <== states[i+1][6]; + eq[18][i].in[1] <== 120; eq[19][i] = IsEqual(); eq[19][i].in[0] <== in[i]; - eq[19][i].in[1] <== 61; - and[19][i] = AND(); - and[19][i].a <== states[i][1]; - and[19][i].b <== eq[19][i].out; - states[i+1][7] <== and[19][i].out; - state_changed[i].in[6] <== states[i+1][7]; + eq[19][i].in[1] <== 121; eq[20][i] = IsEqual(); eq[20][i].in[0] <== in[i]; - eq[20][i].in[1] <== 13; - and[20][i] = AND(); - and[20][i].a <== states[i][0]; - and[20][i].b <== eq[20][i].out; - and[21][i] = AND(); - and[21][i].a <== states[i][9]; - and[21][i].b <== eq[20][i].out; - multi_or[8][i] = MultiOR(2); - multi_or[8][i].in[0] <== and[20][i].out; - multi_or[8][i].in[1] <== and[21][i].out; - states[i+1][8] <== multi_or[8][i].out; - state_changed[i].in[7] <== states[i+1][8]; + eq[20][i].in[1] <== 122; + and[22][i] = AND(); + and[22][i].a <== states[i][29]; + multi_or[1][i] = MultiOR(7); + multi_or[1][i].in[0] <== and[21][i].out; + multi_or[1][i].in[1] <== eq[12][i].out; + multi_or[1][i].in[2] <== eq[16][i].out; + multi_or[1][i].in[3] <== eq[17][i].out; + multi_or[1][i].in[4] <== eq[18][i].out; + multi_or[1][i].in[5] <== eq[19][i].out; + multi_or[1][i].in[6] <== eq[20][i].out; + and[22][i].b <== multi_or[1][i].out; + and[23][i] = AND(); + and[23][i].a <== states[i][30]; + and[23][i].b <== and[18][i].out; + multi_or[2][i] = MultiOR(4); + multi_or[2][i].in[0] <== and[19][i].out; + multi_or[2][i].in[1] <== and[20][i].out; + multi_or[2][i].in[2] <== and[22][i].out; + multi_or[2][i].in[3] <== and[23][i].out; + states[i+1][18] <== multi_or[2][i].out; + state_changed[i].in[17] <== states[i+1][18]; eq[21][i] = IsEqual(); eq[21][i].in[0] <== in[i]; - eq[21][i].in[1] <== 255; - and[22][i] = AND(); - and[22][i].a <== states[i][0]; - and[22][i].b <== eq[21][i].out; + eq[21][i].in[1] <== 61; + and[24][i] = AND(); + and[24][i].a <== states[i][18]; + and[24][i].b <== eq[21][i].out; + states[i+1][19] <== and[24][i].out; + state_changed[i].in[18] <== states[i+1][19]; + lt[4][i] = LessEqThan(8); + lt[4][i].in[0] <== 0; + lt[4][i].in[1] <== in[i]; + lt[5][i] = LessEqThan(8); + lt[5][i].in[0] <== in[i]; + lt[5][i].in[1] <== 58; + and[25][i] = AND(); + and[25][i].a <== lt[4][i].out; + and[25][i].b <== lt[5][i].out; + lt[6][i] = LessEqThan(8); + lt[6][i].in[0] <== 60; + lt[6][i].in[1] <== in[i]; + lt[7][i] = LessEqThan(8); + lt[7][i].in[0] <== in[i]; + lt[7][i].in[1] <== 127; + and[26][i] = AND(); + and[26][i].a <== lt[6][i].out; + and[26][i].b <== lt[7][i].out; + and[27][i] = AND(); + and[27][i].a <== states[i][19]; + multi_or[3][i] = MultiOR(2); + multi_or[3][i].in[0] <== and[25][i].out; + multi_or[3][i].in[1] <== and[26][i].out; + and[27][i].b <== multi_or[3][i].out; + and[28][i] = AND(); + and[28][i].a <== states[i][20]; + and[28][i].b <== multi_or[3][i].out; + lt[8][i] = LessEqThan(8); + lt[8][i].in[0] <== 128; + 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[29][i] = AND(); + and[29][i].a <== lt[8][i].out; + and[29][i].b <== lt[9][i].out; + and[30][i] = AND(); + and[30][i].a <== states[i][21]; + and[30][i].b <== and[29][i].out; + lt[10][i] = LessEqThan(8); + lt[10][i].in[0] <== 0; + lt[10][i].in[1] <== in[i]; + lt[11][i] = LessEqThan(8); + lt[11][i].in[0] <== in[i]; + lt[11][i].in[1] <== 47; + and[31][i] = AND(); + and[31][i].a <== lt[10][i].out; + and[31][i].b <== lt[11][i].out; + and[32][i] = AND(); + and[32][i].a <== states[i][31]; + multi_or[4][i] = MultiOR(3); + multi_or[4][i].in[0] <== and[31][i].out; + multi_or[4][i].in[1] <== and[26][i].out; + multi_or[4][i].in[2] <== eq[15][i].out; + and[32][i].b <== multi_or[4][i].out; + multi_or[5][i] = MultiOR(4); + multi_or[5][i].in[0] <== and[27][i].out; + multi_or[5][i].in[1] <== and[28][i].out; + multi_or[5][i].in[2] <== and[30][i].out; + multi_or[5][i].in[3] <== and[32][i].out; + states[i+1][20] <== multi_or[5][i].out; + state_changed[i].in[19] <== states[i+1][20]; + 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[33][i] = AND(); + and[33][i].a <== lt[12][i].out; + and[33][i].b <== lt[13][i].out; + and[34][i] = AND(); + and[34][i].a <== states[i][19]; + and[34][i].b <== and[33][i].out; + and[35][i] = AND(); + and[35][i].a <== states[i][20]; + and[35][i].b <== and[33][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[36][i] = AND(); + and[36][i].a <== lt[14][i].out; + and[36][i].b <== lt[15][i].out; + and[37][i] = AND(); + and[37][i].a <== states[i][22]; + and[37][i].b <== and[36][i].out; + and[38][i] = AND(); + and[38][i].a <== states[i][23]; + and[38][i].b <== and[29][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[39][i] = AND(); + and[39][i].a <== lt[16][i].out; + and[39][i].b <== lt[17][i].out; + and[40][i] = AND(); + and[40][i].a <== states[i][24]; + and[40][i].b <== and[39][i].out; + and[41][i] = AND(); + and[41][i].a <== states[i][31]; + and[41][i].b <== and[33][i].out; + multi_or[6][i] = MultiOR(6); + multi_or[6][i].in[0] <== and[34][i].out; + multi_or[6][i].in[1] <== and[35][i].out; + multi_or[6][i].in[2] <== and[37][i].out; + multi_or[6][i].in[3] <== and[38][i].out; + multi_or[6][i].in[4] <== and[40][i].out; + multi_or[6][i].in[5] <== and[41][i].out; + states[i+1][21] <== multi_or[6][i].out; + state_changed[i].in[20] <== states[i+1][21]; eq[22][i] = IsEqual(); eq[22][i].in[0] <== in[i]; - eq[22][i].in[1] <== 10; - and[23][i] = AND(); - and[23][i].a <== states[i][8]; - and[23][i].b <== eq[22][i].out; - multi_or[9][i] = MultiOR(2); - multi_or[9][i].in[0] <== and[22][i].out; - multi_or[9][i].in[1] <== and[23][i].out; - states[i+1][9] <== multi_or[9][i].out; - state_changed[i].in[8] <== states[i+1][9]; + eq[22][i].in[1] <== 224; + and[42][i] = AND(); + and[42][i].a <== states[i][19]; + and[42][i].b <== eq[22][i].out; + and[43][i] = AND(); + and[43][i].a <== states[i][20]; + and[43][i].b <== eq[22][i].out; + and[44][i] = AND(); + and[44][i].a <== states[i][31]; + and[44][i].b <== eq[22][i].out; + multi_or[7][i] = MultiOR(3); + multi_or[7][i].in[0] <== and[42][i].out; + multi_or[7][i].in[1] <== and[43][i].out; + multi_or[7][i].in[2] <== and[44][i].out; + states[i+1][22] <== multi_or[7][i].out; + state_changed[i].in[21] <== states[i+1][22]; eq[23][i] = IsEqual(); eq[23][i].in[0] <== in[i]; - eq[23][i].in[1] <== 100; - and[24][i] = AND(); - and[24][i].a <== states[i][9]; - and[24][i].b <== eq[23][i].out; - states[i+1][10] <== and[24][i].out; - state_changed[i].in[9] <== states[i+1][10]; + eq[23][i].in[1] <== 225; eq[24][i] = IsEqual(); eq[24][i].in[0] <== in[i]; - eq[24][i].in[1] <== 107; - and[25][i] = AND(); - and[25][i].a <== states[i][10]; - and[25][i].b <== eq[24][i].out; - states[i+1][11] <== and[25][i].out; - state_changed[i].in[10] <== states[i+1][11]; + eq[24][i].in[1] <== 226; eq[25][i] = IsEqual(); eq[25][i].in[0] <== in[i]; - eq[25][i].in[1] <== 105; - and[26][i] = AND(); - and[26][i].a <== states[i][11]; - and[26][i].b <== eq[25][i].out; - states[i+1][12] <== and[26][i].out; - state_changed[i].in[11] <== states[i+1][12]; + eq[25][i].in[1] <== 227; eq[26][i] = IsEqual(); eq[26][i].in[0] <== in[i]; - eq[26][i].in[1] <== 109; - and[27][i] = AND(); - and[27][i].a <== states[i][12]; - and[27][i].b <== eq[26][i].out; - states[i+1][13] <== and[27][i].out; - state_changed[i].in[12] <== states[i+1][13]; + eq[26][i].in[1] <== 228; eq[27][i] = IsEqual(); eq[27][i].in[0] <== in[i]; - eq[27][i].in[1] <== 45; - and[28][i] = AND(); - and[28][i].a <== states[i][13]; - and[28][i].b <== eq[27][i].out; - states[i+1][14] <== and[28][i].out; - state_changed[i].in[13] <== states[i+1][14]; + eq[27][i].in[1] <== 229; eq[28][i] = IsEqual(); eq[28][i].in[0] <== in[i]; - eq[28][i].in[1] <== 115; - and[29][i] = AND(); - and[29][i].a <== states[i][14]; - and[29][i].b <== eq[28][i].out; - states[i+1][15] <== and[29][i].out; - state_changed[i].in[14] <== states[i+1][15]; - and[30][i] = AND(); - and[30][i].a <== states[i][15]; - and[30][i].b <== eq[25][i].out; - states[i+1][16] <== and[30][i].out; - state_changed[i].in[15] <== states[i+1][16]; + eq[28][i].in[1] <== 230; eq[29][i] = IsEqual(); eq[29][i].in[0] <== in[i]; - eq[29][i].in[1] <== 103; - and[31][i] = AND(); - and[31][i].a <== states[i][16]; - and[31][i].b <== eq[29][i].out; - states[i+1][17] <== and[31][i].out; - state_changed[i].in[16] <== states[i+1][17]; + eq[29][i].in[1] <== 231; eq[30][i] = IsEqual(); eq[30][i].in[0] <== in[i]; - eq[30][i].in[1] <== 110; - and[32][i] = AND(); - and[32][i].a <== states[i][17]; - and[32][i].b <== eq[30][i].out; - states[i+1][18] <== and[32][i].out; - state_changed[i].in[17] <== states[i+1][18]; + eq[30][i].in[1] <== 232; eq[31][i] = IsEqual(); eq[31][i].in[0] <== in[i]; - eq[31][i].in[1] <== 97; - and[33][i] = AND(); - and[33][i].a <== states[i][18]; - and[33][i].b <== eq[31][i].out; - states[i+1][19] <== and[33][i].out; - state_changed[i].in[18] <== states[i+1][19]; + eq[31][i].in[1] <== 233; eq[32][i] = IsEqual(); eq[32][i].in[0] <== in[i]; - eq[32][i].in[1] <== 116; - and[34][i] = AND(); - and[34][i].a <== states[i][19]; - and[34][i].b <== eq[32][i].out; - states[i+1][20] <== and[34][i].out; - state_changed[i].in[19] <== states[i+1][20]; - and[35][i] = AND(); - and[35][i].a <== states[i][20]; - and[35][i].b <== eq[0][i].out; - states[i+1][21] <== and[35][i].out; - state_changed[i].in[20] <== states[i+1][21]; + eq[32][i].in[1] <== 234; eq[33][i] = IsEqual(); eq[33][i].in[0] <== in[i]; - eq[33][i].in[1] <== 114; - and[36][i] = AND(); - and[36][i].a <== states[i][21]; - and[36][i].b <== eq[33][i].out; - states[i+1][22] <== and[36][i].out; - state_changed[i].in[21] <== states[i+1][22]; + eq[33][i].in[1] <== 235; eq[34][i] = IsEqual(); eq[34][i].in[0] <== in[i]; - eq[34][i].in[1] <== 101; - and[37][i] = AND(); - and[37][i].a <== states[i][22]; - and[37][i].b <== eq[34][i].out; - states[i+1][23] <== and[37][i].out; + 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[45][i] = AND(); + and[45][i].a <== states[i][19]; + multi_or[8][i] = MultiOR(14); + multi_or[8][i].in[0] <== eq[23][i].out; + multi_or[8][i].in[1] <== eq[24][i].out; + multi_or[8][i].in[2] <== eq[25][i].out; + multi_or[8][i].in[3] <== eq[26][i].out; + multi_or[8][i].in[4] <== eq[27][i].out; + multi_or[8][i].in[5] <== eq[28][i].out; + multi_or[8][i].in[6] <== eq[29][i].out; + multi_or[8][i].in[7] <== eq[30][i].out; + multi_or[8][i].in[8] <== eq[31][i].out; + multi_or[8][i].in[9] <== eq[32][i].out; + multi_or[8][i].in[10] <== eq[33][i].out; + multi_or[8][i].in[11] <== eq[34][i].out; + multi_or[8][i].in[12] <== eq[35][i].out; + multi_or[8][i].in[13] <== eq[36][i].out; + and[45][i].b <== multi_or[8][i].out; + and[46][i] = AND(); + and[46][i].a <== states[i][20]; + and[46][i].b <== multi_or[8][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[47][i] = AND(); + and[47][i].a <== lt[18][i].out; + and[47][i].b <== lt[19][i].out; + and[48][i] = AND(); + and[48][i].a <== states[i][25]; + and[48][i].b <== and[47][i].out; + and[49][i] = AND(); + and[49][i].a <== states[i][26]; + and[49][i].b <== and[29][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[50][i] = AND(); + and[50][i].a <== states[i][27]; + multi_or[9][i] = MultiOR(16); + multi_or[9][i].in[0] <== eq[37][i].out; + multi_or[9][i].in[1] <== eq[38][i].out; + multi_or[9][i].in[2] <== eq[39][i].out; + multi_or[9][i].in[3] <== eq[40][i].out; + multi_or[9][i].in[4] <== eq[41][i].out; + multi_or[9][i].in[5] <== eq[42][i].out; + multi_or[9][i].in[6] <== eq[43][i].out; + multi_or[9][i].in[7] <== eq[44][i].out; + multi_or[9][i].in[8] <== eq[45][i].out; + multi_or[9][i].in[9] <== eq[46][i].out; + multi_or[9][i].in[10] <== eq[47][i].out; + multi_or[9][i].in[11] <== eq[48][i].out; + multi_or[9][i].in[12] <== eq[49][i].out; + multi_or[9][i].in[13] <== eq[50][i].out; + multi_or[9][i].in[14] <== eq[51][i].out; + multi_or[9][i].in[15] <== eq[52][i].out; + and[50][i].b <== multi_or[9][i].out; + and[51][i] = AND(); + and[51][i].a <== states[i][31]; + and[51][i].b <== multi_or[8][i].out; + multi_or[10][i] = MultiOR(6); + multi_or[10][i].in[0] <== and[45][i].out; + multi_or[10][i].in[1] <== and[46][i].out; + multi_or[10][i].in[2] <== and[48][i].out; + multi_or[10][i].in[3] <== and[49][i].out; + multi_or[10][i].in[4] <== and[50][i].out; + multi_or[10][i].in[5] <== and[51][i].out; + states[i+1][23] <== multi_or[10][i].out; state_changed[i].in[22] <== states[i+1][23]; - and[38][i] = AND(); - and[38][i].a <== states[i][23]; - and[38][i].b <== eq[6][i].out; - states[i+1][24] <== and[38][i].out; + eq[53][i] = IsEqual(); + eq[53][i].in[0] <== in[i]; + eq[53][i].in[1] <== 237; + and[52][i] = AND(); + and[52][i].a <== states[i][19]; + and[52][i].b <== eq[53][i].out; + and[53][i] = AND(); + and[53][i].a <== states[i][20]; + and[53][i].b <== eq[53][i].out; + and[54][i] = AND(); + and[54][i].a <== states[i][31]; + and[54][i].b <== eq[53][i].out; + multi_or[11][i] = MultiOR(3); + multi_or[11][i].in[0] <== and[52][i].out; + multi_or[11][i].in[1] <== and[53][i].out; + multi_or[11][i].in[2] <== and[54][i].out; + states[i+1][24] <== multi_or[11][i].out; state_changed[i].in[23] <== states[i+1][24]; - and[39][i] = AND(); - and[39][i].a <== states[i][6]; - and[39][i].b <== eq[32][i].out; - states[i+1][25] <== and[39][i].out; + eq[54][i] = IsEqual(); + eq[54][i].in[0] <== in[i]; + eq[54][i].in[1] <== 240; + and[55][i] = AND(); + and[55][i].a <== states[i][19]; + and[55][i].b <== eq[54][i].out; + and[56][i] = AND(); + and[56][i].a <== states[i][20]; + and[56][i].b <== eq[54][i].out; + and[57][i] = AND(); + and[57][i].a <== states[i][31]; + and[57][i].b <== eq[54][i].out; + multi_or[12][i] = MultiOR(3); + multi_or[12][i].in[0] <== and[55][i].out; + multi_or[12][i].in[1] <== and[56][i].out; + multi_or[12][i].in[2] <== and[57][i].out; + states[i+1][25] <== multi_or[12][i].out; state_changed[i].in[24] <== states[i+1][25]; - and[40][i] = AND(); - and[40][i].a <== states[i][25]; - and[40][i].b <== eq[19][i].out; - states[i+1][26] <== and[40][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[58][i] = AND(); + and[58][i].a <== states[i][19]; + multi_or[13][i] = MultiOR(3); + multi_or[13][i].in[0] <== eq[55][i].out; + multi_or[13][i].in[1] <== eq[56][i].out; + multi_or[13][i].in[2] <== eq[57][i].out; + and[58][i].b <== multi_or[13][i].out; + and[59][i] = AND(); + and[59][i].a <== states[i][20]; + and[59][i].b <== multi_or[13][i].out; + and[60][i] = AND(); + and[60][i].a <== states[i][31]; + and[60][i].b <== multi_or[13][i].out; + multi_or[14][i] = MultiOR(3); + multi_or[14][i].in[0] <== and[58][i].out; + multi_or[14][i].in[1] <== and[59][i].out; + multi_or[14][i].in[2] <== and[60][i].out; + states[i+1][26] <== multi_or[14][i].out; state_changed[i].in[25] <== states[i+1][26]; + eq[58][i] = IsEqual(); + eq[58][i].in[0] <== in[i]; + eq[58][i].in[1] <== 244; + and[61][i] = AND(); + and[61][i].a <== states[i][19]; + and[61][i].b <== eq[58][i].out; + and[62][i] = AND(); + and[62][i].a <== states[i][20]; + and[62][i].b <== eq[58][i].out; + and[63][i] = AND(); + and[63][i].a <== states[i][31]; + and[63][i].b <== eq[58][i].out; + multi_or[15][i] = MultiOR(3); + multi_or[15][i].in[0] <== and[61][i].out; + multi_or[15][i].in[1] <== and[62][i].out; + multi_or[15][i].in[2] <== and[63][i].out; + states[i+1][27] <== multi_or[15][i].out; + state_changed[i].in[26] <== states[i+1][27]; + eq[59][i] = IsEqual(); + eq[59][i].in[0] <== in[i]; + eq[59][i].in[1] <== 59; + and[64][i] = AND(); + and[64][i].a <== states[i][20]; + and[64][i].b <== eq[59][i].out; + states[i+1][28] <== and[64][i].out; + state_changed[i].in[27] <== states[i+1][28]; + eq[60][i] = IsEqual(); + eq[60][i].in[0] <== in[i]; + eq[60][i].in[1] <== 32; + and[65][i] = AND(); + and[65][i].a <== states[i][28]; + and[65][i].b <== eq[60][i].out; + states[i+1][29] <== and[65][i].out; + state_changed[i].in[28] <== states[i+1][29]; + and[66][i] = AND(); + and[66][i].a <== states[i][29]; + and[66][i].b <== eq[11][i].out; + states[i+1][30] <== and[66][i].out; + state_changed[i].in[29] <== states[i+1][30]; + and[67][i] = AND(); + and[67][i].a <== states[i][30]; + and[67][i].b <== eq[21][i].out; + states[i+1][31] <== and[67][i].out; + state_changed[i].in[30] <== states[i+1][31]; + eq[61][i] = IsEqual(); + eq[61][i].in[0] <== in[i]; + eq[61][i].in[1] <== 48; + eq[62][i] = IsEqual(); + eq[62][i].in[0] <== in[i]; + eq[62][i].in[1] <== 49; + eq[63][i] = IsEqual(); + eq[63][i].in[0] <== in[i]; + eq[63][i].in[1] <== 50; + eq[64][i] = IsEqual(); + eq[64][i].in[0] <== in[i]; + eq[64][i].in[1] <== 51; + eq[65][i] = IsEqual(); + eq[65][i].in[0] <== in[i]; + eq[65][i].in[1] <== 52; + eq[66][i] = IsEqual(); + eq[66][i].in[0] <== in[i]; + eq[66][i].in[1] <== 53; + eq[67][i] = IsEqual(); + eq[67][i].in[0] <== in[i]; + eq[67][i].in[1] <== 54; + eq[68][i] = IsEqual(); + eq[68][i].in[0] <== in[i]; + eq[68][i].in[1] <== 55; + eq[69][i] = IsEqual(); + eq[69][i].in[0] <== in[i]; + eq[69][i].in[1] <== 56; + eq[70][i] = IsEqual(); + eq[70][i].in[0] <== in[i]; + eq[70][i].in[1] <== 57; + and[68][i] = AND(); + and[68][i].a <== states[i][31]; + multi_or[16][i] = MultiOR(10); + multi_or[16][i].in[0] <== eq[61][i].out; + multi_or[16][i].in[1] <== eq[62][i].out; + multi_or[16][i].in[2] <== eq[63][i].out; + multi_or[16][i].in[3] <== eq[64][i].out; + multi_or[16][i].in[4] <== eq[65][i].out; + multi_or[16][i].in[5] <== eq[66][i].out; + multi_or[16][i].in[6] <== eq[67][i].out; + multi_or[16][i].in[7] <== eq[68][i].out; + multi_or[16][i].in[8] <== eq[69][i].out; + multi_or[16][i].in[9] <== eq[70][i].out; + and[68][i].b <== multi_or[16][i].out; + and[69][i] = AND(); + and[69][i].a <== states[i][32]; + and[69][i].b <== multi_or[16][i].out; + multi_or[17][i] = MultiOR(2); + multi_or[17][i].in[0] <== and[68][i].out; + multi_or[17][i].in[1] <== and[69][i].out; + states[i+1][32] <== multi_or[17][i].out; + state_changed[i].in[31] <== states[i+1][32]; + and[70][i] = AND(); + and[70][i].a <== states[i][32]; + and[70][i].b <== eq[59][i].out; + states[i+1][33] <== and[70][i].out; + state_changed[i].in[32] <== states[i+1][33]; states[i+1][0] <== 1 - state_changed[i].out; } component final_state_result = MultiOR(num_bytes+1); for (var i = 0; i <= num_bytes; i++) { - final_state_result.in[i] <== states[i][5]; + final_state_result.in[i] <== states[i][33]; } out <== final_state_result.out; - signal is_consecutive[msg_bytes+1][2]; is_consecutive[msg_bytes][1] <== 1; 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][1]) + is_consecutive[msg_bytes-i][1]; + is_consecutive[msg_bytes-1-i][0] <== states[num_bytes-i][33] * (1 - is_consecutive[msg_bytes-i][1]) + is_consecutive[msg_bytes-i][1]; is_consecutive[msg_bytes-1-i][1] <== state_changed[msg_bytes-i].out * is_consecutive[msg_bytes-1-i][0]; } + // substrings calculated: [{(31, 32), (32, 32)}] signal is_substr0[msg_bytes][3]; signal is_reveal0[msg_bytes]; signal output reveal0[msg_bytes]; for (var i = 0; i < msg_bytes; i++) { is_substr0[i][0] <== 0; - // the 0-th substring transitions: [(3, 3), (26, 3)] - is_substr0[i][1] <== is_substr0[i][0] + states[i+1][3] * states[i+2][3]; - is_substr0[i][2] <== is_substr0[i][1] + states[i+1][26] * states[i+2][3]; + // the 0-th substring transitions: [(31, 32), (32, 32)] + is_substr0[i][1] <== is_substr0[i][0] + states[i+1][31] * states[i+2][32]; + is_substr0[i][2] <== is_substr0[i][1] + states[i+1][32] * states[i+2][32]; is_reveal0[i] <== is_substr0[i][2] * is_consecutive[i][1]; reveal0[i] <== in[i+1] * is_reveal0[i]; } diff --git a/packages/circom/circuits/common/to_addr.json b/packages/circom/circuits/common/to_addr.json index f7e9a22..43384d7 100644 --- a/packages/circom/circuits/common/to_addr.json +++ b/packages/circom/circuits/common/to_addr.json @@ -1,20 +1,20 @@ { - "parts": [ - { - "is_public": false, - "regex_def": "((\r\n)|^)to:" - }, - { - "is_public": false, - "regex_def": "([^\r\n]+<)?" - }, - { - "is_public": true, - "regex_def": "(a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z|A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z|0|1|2|3|4|5|6|7|8|9|!|#|$|%|&|'|\\*|\\+|-|/|=|\\?|^|_|`|{|\\||}|~|\\.)+@(a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z|A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z|0|1|2|3|4|5|6|7|8|9|_|\\.|-)+" - }, - { - "is_public": false, - "regex_def": ">?\r\n" - } - ] -} \ No newline at end of file + "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" + } + ] +} diff --git a/packages/circom/circuits/common/to_all_regex.circom b/packages/circom/circuits/common/to_all_regex.circom index 1ba5d4f..bbd8e69 100644 --- a/packages/circom/circuits/common/to_all_regex.circom +++ b/packages/circom/circuits/common/to_all_regex.circom @@ -2,7 +2,7 @@ pragma circom 2.1.5; include "@zk-email/zk-regex-circom/circuits/regex_helpers.circom"; -// regex: (( \n)|^)to:[^ \n]+ \n +// regex: ((\r\n)|^)to:[^\r\n]+\r\n template ToAllRegex(msg_bytes) { signal input msg[msg_bytes]; signal output out; @@ -14,179 +14,488 @@ template ToAllRegex(msg_bytes) { in[i+1] <== msg[i]; } - component eq[18][num_bytes]; - component lt[2][num_bytes]; - component and[12][num_bytes]; - component multi_or[4][num_bytes]; - signal states[num_bytes+1][9]; + component eq[54][num_bytes]; + component lt[12][num_bytes]; + component and[37][num_bytes]; + component multi_or[13][num_bytes]; + signal states[num_bytes+1][16]; component state_changed[num_bytes]; states[0][0] <== 1; - for (var i = 1; i < 9; i++) { + for (var i = 1; i < 16; i++) { states[0][i] <== 0; } for (var i = 0; i < num_bytes; i++) { - state_changed[i] = MultiOR(8); - 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] <== 254; - and[0][i] = AND(); - and[0][i].a <== lt[0][i].out; - and[0][i].b <== lt[1][i].out; + state_changed[i] = MultiOR(15); eq[0][i] = IsEqual(); eq[0][i].in[0] <== in[i]; - eq[0][i].in[1] <== 0; + eq[0][i].in[1] <== 116; + and[0][i] = AND(); + and[0][i].a <== states[i][0]; + and[0][i].b <== eq[0][i].out; + and[1][i] = AND(); + and[1][i].a <== states[i][4]; + and[1][i].b <== eq[0][i].out; + multi_or[0][i] = MultiOR(2); + multi_or[0][i].in[0] <== and[0][i].out; + multi_or[0][i].in[1] <== and[1][i].out; + states[i+1][1] <== multi_or[0][i].out; + state_changed[i].in[0] <== states[i+1][1]; eq[1][i] = IsEqual(); eq[1][i].in[0] <== in[i]; - eq[1][i].in[1] <== 1; + eq[1][i].in[1] <== 13; + and[2][i] = AND(); + and[2][i].a <== states[i][0]; + and[2][i].b <== eq[1][i].out; + states[i+1][2] <== and[2][i].out; + state_changed[i].in[1] <== states[i+1][2]; eq[2][i] = IsEqual(); eq[2][i].in[0] <== in[i]; - eq[2][i].in[1] <== 2; + eq[2][i].in[1] <== 111; + and[3][i] = AND(); + and[3][i].a <== states[i][1]; + and[3][i].b <== eq[2][i].out; + states[i+1][3] <== and[3][i].out; + state_changed[i].in[2] <== states[i+1][3]; eq[3][i] = IsEqual(); eq[3][i].in[0] <== in[i]; - eq[3][i].in[1] <== 3; + eq[3][i].in[1] <== 10; + and[4][i] = AND(); + and[4][i].a <== states[i][2]; + and[4][i].b <== eq[3][i].out; + states[i+1][4] <== and[4][i].out; + state_changed[i].in[3] <== states[i+1][4]; eq[4][i] = IsEqual(); eq[4][i].in[0] <== in[i]; - eq[4][i].in[1] <== 4; + eq[4][i].in[1] <== 58; + and[5][i] = AND(); + and[5][i].a <== states[i][3]; + and[5][i].b <== eq[4][i].out; + states[i+1][5] <== and[5][i].out; + state_changed[i].in[4] <== states[i+1][5]; + lt[0][i] = LessEqThan(8); + lt[0][i].in[0] <== 194; + lt[0][i].in[1] <== in[i]; + lt[1][i] = LessEqThan(8); + lt[1][i].in[0] <== in[i]; + lt[1][i].in[1] <== 223; + and[6][i] = AND(); + and[6][i].a <== lt[0][i].out; + and[6][i].b <== lt[1][i].out; + and[7][i] = AND(); + and[7][i].a <== states[i][5]; + and[7][i].b <== and[6][i].out; + lt[2][i] = LessEqThan(8); + lt[2][i].in[0] <== 160; + lt[2][i].in[1] <== in[i]; + lt[3][i] = LessEqThan(8); + lt[3][i].in[0] <== in[i]; + lt[3][i].in[1] <== 191; + and[8][i] = AND(); + and[8][i].a <== lt[2][i].out; + and[8][i].b <== lt[3][i].out; + and[9][i] = AND(); + and[9][i].a <== states[i][7]; + and[9][i].b <== and[8][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[10][i] = AND(); + and[10][i].a <== lt[4][i].out; + and[10][i].b <== lt[5][i].out; + and[11][i] = AND(); + and[11][i].a <== states[i][8]; + and[11][i].b <== and[10][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] <== 159; + and[12][i] = AND(); + and[12][i].a <== lt[6][i].out; + and[12][i].b <== lt[7][i].out; + and[13][i] = AND(); + and[13][i].a <== states[i][9]; + and[13][i].b <== and[12][i].out; + and[14][i] = AND(); + and[14][i].a <== states[i][13]; + and[14][i].b <== and[6][i].out; + multi_or[1][i] = MultiOR(5); + multi_or[1][i].in[0] <== and[7][i].out; + multi_or[1][i].in[1] <== and[9][i].out; + multi_or[1][i].in[2] <== and[11][i].out; + multi_or[1][i].in[3] <== and[13][i].out; + multi_or[1][i].in[4] <== and[14][i].out; + states[i+1][6] <== multi_or[1][i].out; + state_changed[i].in[5] <== states[i+1][6]; eq[5][i] = IsEqual(); eq[5][i].in[0] <== in[i]; - eq[5][i].in[1] <== 5; + eq[5][i].in[1] <== 224; + and[15][i] = AND(); + and[15][i].a <== states[i][5]; + and[15][i].b <== eq[5][i].out; + and[16][i] = AND(); + and[16][i].a <== states[i][13]; + and[16][i].b <== eq[5][i].out; + multi_or[2][i] = MultiOR(2); + multi_or[2][i].in[0] <== and[15][i].out; + multi_or[2][i].in[1] <== and[16][i].out; + states[i+1][7] <== multi_or[2][i].out; + state_changed[i].in[6] <== states[i+1][7]; eq[6][i] = IsEqual(); eq[6][i].in[0] <== in[i]; - eq[6][i].in[1] <== 6; + eq[6][i].in[1] <== 225; eq[7][i] = IsEqual(); eq[7][i].in[0] <== in[i]; - eq[7][i].in[1] <== 7; + eq[7][i].in[1] <== 226; eq[8][i] = IsEqual(); eq[8][i].in[0] <== in[i]; - eq[8][i].in[1] <== 8; + eq[8][i].in[1] <== 227; eq[9][i] = IsEqual(); eq[9][i].in[0] <== in[i]; - eq[9][i].in[1] <== 9; + eq[9][i].in[1] <== 228; eq[10][i] = IsEqual(); eq[10][i].in[0] <== in[i]; - eq[10][i].in[1] <== 11; + eq[10][i].in[1] <== 229; eq[11][i] = IsEqual(); eq[11][i].in[0] <== in[i]; - eq[11][i].in[1] <== 12; - and[1][i] = AND(); - and[1][i].a <== states[i][1]; - multi_or[0][i] = MultiOR(13); - 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; - multi_or[0][i].in[12] <== eq[11][i].out; - and[1][i].b <== multi_or[0][i].out; - and[2][i] = AND(); - and[2][i].a <== states[i][6]; - and[2][i].b <== multi_or[0][i].out; - multi_or[1][i] = MultiOR(2); - multi_or[1][i].in[0] <== and[1][i].out; - multi_or[1][i].in[1] <== and[2][i].out; - states[i+1][1] <== multi_or[1][i].out; - state_changed[i].in[0] <== states[i+1][1]; + eq[11][i].in[1] <== 230; eq[12][i] = IsEqual(); eq[12][i].in[0] <== in[i]; - eq[12][i].in[1] <== 13; - and[3][i] = AND(); - and[3][i].a <== states[i][0]; - and[3][i].b <== eq[12][i].out; - and[4][i] = AND(); - and[4][i].a <== states[i][3]; - and[4][i].b <== eq[12][i].out; - multi_or[2][i] = MultiOR(2); - multi_or[2][i].in[0] <== and[3][i].out; - multi_or[2][i].in[1] <== and[4][i].out; - states[i+1][2] <== multi_or[2][i].out; - state_changed[i].in[1] <== states[i+1][2]; + eq[12][i].in[1] <== 231; eq[13][i] = IsEqual(); eq[13][i].in[0] <== in[i]; - eq[13][i].in[1] <== 255; - and[5][i] = AND(); - and[5][i].a <== states[i][0]; - and[5][i].b <== eq[13][i].out; + eq[13][i].in[1] <== 232; eq[14][i] = IsEqual(); eq[14][i].in[0] <== in[i]; - eq[14][i].in[1] <== 10; - and[6][i] = AND(); - and[6][i].a <== states[i][2]; - and[6][i].b <== eq[14][i].out; - multi_or[3][i] = MultiOR(2); - multi_or[3][i].in[0] <== and[5][i].out; - multi_or[3][i].in[1] <== and[6][i].out; - states[i+1][3] <== multi_or[3][i].out; - state_changed[i].in[2] <== states[i+1][3]; + eq[14][i].in[1] <== 233; eq[15][i] = IsEqual(); eq[15][i].in[0] <== in[i]; - eq[15][i].in[1] <== 116; - and[7][i] = AND(); - and[7][i].a <== states[i][3]; - and[7][i].b <== eq[15][i].out; - states[i+1][4] <== and[7][i].out; - state_changed[i].in[3] <== states[i+1][4]; + eq[15][i].in[1] <== 234; eq[16][i] = IsEqual(); eq[16][i].in[0] <== in[i]; - eq[16][i].in[1] <== 111; - and[8][i] = AND(); - and[8][i].a <== states[i][4]; - and[8][i].b <== eq[16][i].out; - states[i+1][5] <== and[8][i].out; - state_changed[i].in[4] <== states[i+1][5]; + eq[16][i].in[1] <== 235; eq[17][i] = IsEqual(); eq[17][i].in[0] <== in[i]; - eq[17][i].in[1] <== 58; - and[9][i] = AND(); - and[9][i].a <== states[i][5]; - and[9][i].b <== eq[17][i].out; - states[i+1][6] <== and[9][i].out; - state_changed[i].in[5] <== states[i+1][6]; - and[10][i] = AND(); - and[10][i].a <== states[i][1]; - and[10][i].b <== eq[12][i].out; - states[i+1][7] <== and[10][i].out; - state_changed[i].in[6] <== states[i+1][7]; - and[11][i] = AND(); - and[11][i].a <== states[i][7]; - and[11][i].b <== eq[14][i].out; - states[i+1][8] <== and[11][i].out; + eq[17][i].in[1] <== 236; + eq[18][i] = IsEqual(); + eq[18][i].in[0] <== in[i]; + eq[18][i].in[1] <== 238; + eq[19][i] = IsEqual(); + eq[19][i].in[0] <== in[i]; + eq[19][i].in[1] <== 239; + and[17][i] = AND(); + and[17][i].a <== states[i][5]; + multi_or[3][i] = MultiOR(14); + multi_or[3][i].in[0] <== eq[6][i].out; + multi_or[3][i].in[1] <== eq[7][i].out; + multi_or[3][i].in[2] <== eq[8][i].out; + multi_or[3][i].in[3] <== eq[9][i].out; + multi_or[3][i].in[4] <== eq[10][i].out; + multi_or[3][i].in[5] <== eq[11][i].out; + multi_or[3][i].in[6] <== eq[12][i].out; + multi_or[3][i].in[7] <== eq[13][i].out; + multi_or[3][i].in[8] <== eq[14][i].out; + multi_or[3][i].in[9] <== eq[15][i].out; + multi_or[3][i].in[10] <== eq[16][i].out; + multi_or[3][i].in[11] <== eq[17][i].out; + multi_or[3][i].in[12] <== eq[18][i].out; + multi_or[3][i].in[13] <== eq[19][i].out; + and[17][i].b <== multi_or[3][i].out; + lt[8][i] = LessEqThan(8); + lt[8][i].in[0] <== 144; + 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[18][i] = AND(); + and[18][i].a <== lt[8][i].out; + and[18][i].b <== lt[9][i].out; + and[19][i] = AND(); + and[19][i].a <== states[i][10]; + and[19][i].b <== and[18][i].out; + and[20][i] = AND(); + and[20][i].a <== states[i][11]; + and[20][i].b <== and[10][i].out; + eq[20][i] = IsEqual(); + eq[20][i].in[0] <== in[i]; + eq[20][i].in[1] <== 128; + eq[21][i] = IsEqual(); + eq[21][i].in[0] <== in[i]; + eq[21][i].in[1] <== 129; + eq[22][i] = IsEqual(); + eq[22][i].in[0] <== in[i]; + eq[22][i].in[1] <== 130; + eq[23][i] = IsEqual(); + eq[23][i].in[0] <== in[i]; + eq[23][i].in[1] <== 131; + eq[24][i] = IsEqual(); + eq[24][i].in[0] <== in[i]; + eq[24][i].in[1] <== 132; + eq[25][i] = IsEqual(); + eq[25][i].in[0] <== in[i]; + eq[25][i].in[1] <== 133; + eq[26][i] = IsEqual(); + eq[26][i].in[0] <== in[i]; + eq[26][i].in[1] <== 134; + eq[27][i] = IsEqual(); + eq[27][i].in[0] <== in[i]; + eq[27][i].in[1] <== 135; + eq[28][i] = IsEqual(); + eq[28][i].in[0] <== in[i]; + eq[28][i].in[1] <== 136; + eq[29][i] = IsEqual(); + eq[29][i].in[0] <== in[i]; + eq[29][i].in[1] <== 137; + eq[30][i] = IsEqual(); + eq[30][i].in[0] <== in[i]; + eq[30][i].in[1] <== 138; + eq[31][i] = IsEqual(); + eq[31][i].in[0] <== in[i]; + eq[31][i].in[1] <== 139; + eq[32][i] = IsEqual(); + eq[32][i].in[0] <== in[i]; + eq[32][i].in[1] <== 140; + eq[33][i] = IsEqual(); + eq[33][i].in[0] <== in[i]; + eq[33][i].in[1] <== 141; + eq[34][i] = IsEqual(); + eq[34][i].in[0] <== in[i]; + eq[34][i].in[1] <== 142; + eq[35][i] = IsEqual(); + eq[35][i].in[0] <== in[i]; + eq[35][i].in[1] <== 143; + and[21][i] = AND(); + and[21][i].a <== states[i][12]; + multi_or[4][i] = MultiOR(16); + multi_or[4][i].in[0] <== eq[20][i].out; + multi_or[4][i].in[1] <== eq[21][i].out; + multi_or[4][i].in[2] <== eq[22][i].out; + multi_or[4][i].in[3] <== eq[23][i].out; + multi_or[4][i].in[4] <== eq[24][i].out; + multi_or[4][i].in[5] <== eq[25][i].out; + multi_or[4][i].in[6] <== eq[26][i].out; + multi_or[4][i].in[7] <== eq[27][i].out; + multi_or[4][i].in[8] <== eq[28][i].out; + multi_or[4][i].in[9] <== eq[29][i].out; + multi_or[4][i].in[10] <== eq[30][i].out; + multi_or[4][i].in[11] <== eq[31][i].out; + multi_or[4][i].in[12] <== eq[32][i].out; + multi_or[4][i].in[13] <== eq[33][i].out; + multi_or[4][i].in[14] <== eq[34][i].out; + multi_or[4][i].in[15] <== eq[35][i].out; + and[21][i].b <== multi_or[4][i].out; + and[22][i] = AND(); + and[22][i].a <== states[i][13]; + and[22][i].b <== multi_or[3][i].out; + multi_or[5][i] = MultiOR(5); + multi_or[5][i].in[0] <== and[17][i].out; + multi_or[5][i].in[1] <== and[19][i].out; + multi_or[5][i].in[2] <== and[20][i].out; + multi_or[5][i].in[3] <== and[21][i].out; + multi_or[5][i].in[4] <== and[22][i].out; + states[i+1][8] <== multi_or[5][i].out; state_changed[i].in[7] <== states[i+1][8]; + eq[36][i] = IsEqual(); + eq[36][i].in[0] <== in[i]; + eq[36][i].in[1] <== 237; + and[23][i] = AND(); + and[23][i].a <== states[i][5]; + and[23][i].b <== eq[36][i].out; + and[24][i] = AND(); + and[24][i].a <== states[i][13]; + and[24][i].b <== eq[36][i].out; + multi_or[6][i] = MultiOR(2); + multi_or[6][i].in[0] <== and[23][i].out; + multi_or[6][i].in[1] <== and[24][i].out; + states[i+1][9] <== multi_or[6][i].out; + state_changed[i].in[8] <== states[i+1][9]; + eq[37][i] = IsEqual(); + eq[37][i].in[0] <== in[i]; + eq[37][i].in[1] <== 240; + and[25][i] = AND(); + and[25][i].a <== states[i][5]; + and[25][i].b <== eq[37][i].out; + and[26][i] = AND(); + and[26][i].a <== states[i][13]; + and[26][i].b <== eq[37][i].out; + multi_or[7][i] = MultiOR(2); + multi_or[7][i].in[0] <== and[25][i].out; + multi_or[7][i].in[1] <== and[26][i].out; + states[i+1][10] <== multi_or[7][i].out; + state_changed[i].in[9] <== states[i+1][10]; + eq[38][i] = IsEqual(); + eq[38][i].in[0] <== in[i]; + eq[38][i].in[1] <== 241; + eq[39][i] = IsEqual(); + eq[39][i].in[0] <== in[i]; + eq[39][i].in[1] <== 242; + eq[40][i] = IsEqual(); + eq[40][i].in[0] <== in[i]; + eq[40][i].in[1] <== 243; + and[27][i] = AND(); + and[27][i].a <== states[i][5]; + multi_or[8][i] = MultiOR(3); + multi_or[8][i].in[0] <== eq[38][i].out; + multi_or[8][i].in[1] <== eq[39][i].out; + multi_or[8][i].in[2] <== eq[40][i].out; + and[27][i].b <== multi_or[8][i].out; + and[28][i] = AND(); + and[28][i].a <== states[i][13]; + and[28][i].b <== multi_or[8][i].out; + multi_or[9][i] = MultiOR(2); + multi_or[9][i].in[0] <== and[27][i].out; + multi_or[9][i].in[1] <== and[28][i].out; + states[i+1][11] <== multi_or[9][i].out; + state_changed[i].in[10] <== states[i+1][11]; + eq[41][i] = IsEqual(); + eq[41][i].in[0] <== in[i]; + eq[41][i].in[1] <== 244; + and[29][i] = AND(); + and[29][i].a <== states[i][5]; + and[29][i].b <== eq[41][i].out; + and[30][i] = AND(); + and[30][i].a <== states[i][13]; + and[30][i].b <== eq[41][i].out; + multi_or[10][i] = MultiOR(2); + multi_or[10][i].in[0] <== and[29][i].out; + multi_or[10][i].in[1] <== and[30][i].out; + states[i+1][12] <== multi_or[10][i].out; + state_changed[i].in[11] <== states[i+1][12]; + lt[10][i] = LessEqThan(8); + lt[10][i].in[0] <== 14; + lt[10][i].in[1] <== in[i]; + lt[11][i] = LessEqThan(8); + lt[11][i].in[0] <== in[i]; + lt[11][i].in[1] <== 127; + and[31][i] = AND(); + and[31][i].a <== lt[10][i].out; + and[31][i].b <== lt[11][i].out; + eq[42][i] = IsEqual(); + eq[42][i].in[0] <== in[i]; + eq[42][i].in[1] <== 0; + eq[43][i] = IsEqual(); + eq[43][i].in[0] <== in[i]; + eq[43][i].in[1] <== 1; + eq[44][i] = IsEqual(); + eq[44][i].in[0] <== in[i]; + eq[44][i].in[1] <== 2; + eq[45][i] = IsEqual(); + eq[45][i].in[0] <== in[i]; + eq[45][i].in[1] <== 3; + eq[46][i] = IsEqual(); + eq[46][i].in[0] <== in[i]; + eq[46][i].in[1] <== 4; + eq[47][i] = IsEqual(); + eq[47][i].in[0] <== in[i]; + eq[47][i].in[1] <== 5; + eq[48][i] = IsEqual(); + eq[48][i].in[0] <== in[i]; + eq[48][i].in[1] <== 6; + eq[49][i] = IsEqual(); + eq[49][i].in[0] <== in[i]; + eq[49][i].in[1] <== 7; + eq[50][i] = IsEqual(); + eq[50][i].in[0] <== in[i]; + eq[50][i].in[1] <== 8; + eq[51][i] = IsEqual(); + eq[51][i].in[0] <== in[i]; + eq[51][i].in[1] <== 9; + eq[52][i] = IsEqual(); + eq[52][i].in[0] <== in[i]; + eq[52][i].in[1] <== 11; + eq[53][i] = IsEqual(); + eq[53][i].in[0] <== in[i]; + eq[53][i].in[1] <== 12; + and[32][i] = AND(); + and[32][i].a <== states[i][5]; + multi_or[11][i] = MultiOR(13); + multi_or[11][i].in[0] <== and[31][i].out; + multi_or[11][i].in[1] <== eq[42][i].out; + multi_or[11][i].in[2] <== eq[43][i].out; + multi_or[11][i].in[3] <== eq[44][i].out; + multi_or[11][i].in[4] <== eq[45][i].out; + multi_or[11][i].in[5] <== eq[46][i].out; + multi_or[11][i].in[6] <== eq[47][i].out; + multi_or[11][i].in[7] <== eq[48][i].out; + multi_or[11][i].in[8] <== eq[49][i].out; + multi_or[11][i].in[9] <== eq[50][i].out; + multi_or[11][i].in[10] <== eq[51][i].out; + multi_or[11][i].in[11] <== eq[52][i].out; + multi_or[11][i].in[12] <== eq[53][i].out; + and[32][i].b <== multi_or[11][i].out; + and[33][i] = AND(); + and[33][i].a <== states[i][6]; + and[33][i].b <== and[10][i].out; + and[34][i] = AND(); + and[34][i].a <== states[i][13]; + and[34][i].b <== multi_or[11][i].out; + multi_or[12][i] = MultiOR(3); + multi_or[12][i].in[0] <== and[32][i].out; + multi_or[12][i].in[1] <== and[33][i].out; + multi_or[12][i].in[2] <== and[34][i].out; + states[i+1][13] <== multi_or[12][i].out; + state_changed[i].in[12] <== states[i+1][13]; + and[35][i] = AND(); + and[35][i].a <== states[i][13]; + and[35][i].b <== eq[1][i].out; + states[i+1][14] <== and[35][i].out; + state_changed[i].in[13] <== states[i+1][14]; + and[36][i] = AND(); + and[36][i].a <== states[i][14]; + and[36][i].b <== eq[3][i].out; + states[i+1][15] <== and[36][i].out; + state_changed[i].in[14] <== states[i+1][15]; states[i+1][0] <== 1 - state_changed[i].out; } component final_state_result = MultiOR(num_bytes+1); for (var i = 0; i <= num_bytes; i++) { - final_state_result.in[i] <== states[i][8]; + final_state_result.in[i] <== states[i][15]; } out <== final_state_result.out; - signal is_consecutive[msg_bytes+1][2]; is_consecutive[msg_bytes][1] <== 1; for (var i = 0; i < msg_bytes; i++) { - is_consecutive[msg_bytes-1-i][0] <== states[num_bytes-i][8] * (1 - is_consecutive[msg_bytes-i][1]) + is_consecutive[msg_bytes-i][1]; + is_consecutive[msg_bytes-1-i][0] <== states[num_bytes-i][15] * (1 - is_consecutive[msg_bytes-i][1]) + is_consecutive[msg_bytes-i][1]; is_consecutive[msg_bytes-1-i][1] <== state_changed[msg_bytes-i].out * is_consecutive[msg_bytes-1-i][0]; } - signal is_substr0[msg_bytes][3]; + // substrings calculated: [{(5, 6), (5, 7), (5, 8), (5, 9), (5, 10), (5, 11), (5, 12), (5, 13), (6, 13), (7, 6), (8, 6), (9, 6), (10, 8), (11, 8), (12, 8), (13, 6), (13, 7), (13, 8), (13, 9), (13, 10), (13, 11), (13, 12), (13, 13)}] + signal is_substr0[msg_bytes][24]; signal is_reveal0[msg_bytes]; signal output reveal0[msg_bytes]; for (var i = 0; i < msg_bytes; i++) { is_substr0[i][0] <== 0; - // the 0-th substring transitions: [(1, 1), (6, 1)] - is_substr0[i][1] <== is_substr0[i][0] + states[i+1][1] * states[i+2][1]; - is_substr0[i][2] <== is_substr0[i][1] + states[i+1][6] * states[i+2][1]; - is_reveal0[i] <== is_substr0[i][2] * is_consecutive[i][1]; + // the 0-th substring transitions: [(5, 6), (5, 7), (5, 8), (5, 9), (5, 10), (5, 11), (5, 12), (5, 13), (6, 13), (7, 6), (8, 6), (9, 6), (10, 8), (11, 8), (12, 8), (13, 6), (13, 7), (13, 8), (13, 9), (13, 10), (13, 11), (13, 12), (13, 13)] + is_substr0[i][1] <== is_substr0[i][0] + states[i+1][5] * states[i+2][6]; + is_substr0[i][2] <== is_substr0[i][1] + states[i+1][5] * states[i+2][7]; + is_substr0[i][3] <== is_substr0[i][2] + states[i+1][5] * states[i+2][8]; + is_substr0[i][4] <== is_substr0[i][3] + states[i+1][5] * states[i+2][9]; + is_substr0[i][5] <== is_substr0[i][4] + states[i+1][5] * states[i+2][10]; + is_substr0[i][6] <== is_substr0[i][5] + states[i+1][5] * states[i+2][11]; + is_substr0[i][7] <== is_substr0[i][6] + states[i+1][5] * states[i+2][12]; + is_substr0[i][8] <== is_substr0[i][7] + states[i+1][5] * states[i+2][13]; + is_substr0[i][9] <== is_substr0[i][8] + states[i+1][6] * states[i+2][13]; + is_substr0[i][10] <== is_substr0[i][9] + states[i+1][7] * states[i+2][6]; + is_substr0[i][11] <== is_substr0[i][10] + states[i+1][8] * states[i+2][6]; + is_substr0[i][12] <== is_substr0[i][11] + states[i+1][9] * states[i+2][6]; + is_substr0[i][13] <== is_substr0[i][12] + states[i+1][10] * states[i+2][8]; + is_substr0[i][14] <== is_substr0[i][13] + states[i+1][11] * states[i+2][8]; + is_substr0[i][15] <== is_substr0[i][14] + states[i+1][12] * states[i+2][8]; + is_substr0[i][16] <== is_substr0[i][15] + states[i+1][13] * states[i+2][6]; + is_substr0[i][17] <== is_substr0[i][16] + states[i+1][13] * states[i+2][7]; + is_substr0[i][18] <== is_substr0[i][17] + states[i+1][13] * states[i+2][8]; + is_substr0[i][19] <== is_substr0[i][18] + states[i+1][13] * states[i+2][9]; + is_substr0[i][20] <== is_substr0[i][19] + states[i+1][13] * states[i+2][10]; + is_substr0[i][21] <== is_substr0[i][20] + states[i+1][13] * states[i+2][11]; + is_substr0[i][22] <== is_substr0[i][21] + states[i+1][13] * states[i+2][12]; + is_substr0[i][23] <== is_substr0[i][22] + states[i+1][13] * states[i+2][13]; + is_reveal0[i] <== is_substr0[i][23] * is_consecutive[i][1]; reveal0[i] <== in[i+1] * is_reveal0[i]; } } \ No newline at end of file diff --git a/packages/circom/package.json b/packages/circom/package.json index d373afd..055666e 100644 --- a/packages/circom/package.json +++ b/packages/circom/package.json @@ -27,19 +27,13 @@ "circomlibjs": "^0.1.2", "ffjavascript": "^0.2.59", "jest": "^29.5.0", - "mocha": "^10.2.0", - "ts-jest": "^29.1.1", - "typescript": "^4.8.3" + "mocha": "^10.2.0" }, "babel": { "presets": [ [ "@babel/preset-env" - ], - "@babel/preset-typescript", - [ - "jest" ] ] } -} \ No newline at end of file +} diff --git a/packages/circom/tests/body_hash_regex.test.js b/packages/circom/tests/body_hash_regex.test.js new file mode 100644 index 0000000..81e3991 --- /dev/null +++ b/packages/circom/tests/body_hash_regex.test.js @@ -0,0 +1,81 @@ +const circom_tester = require("circom_tester"); +const wasm_tester = circom_tester.wasm; +import * as path from "path"; +import { readFileSync } from "fs"; +const apis = require("../../apis"); +const option = { + include: path.join(__dirname, "../../../node_modules"), +}; +const compiler = require("../../compiler"); + +jest.setTimeout(600000); +describe("Bodyhash Regex", () => { + let circuit; + beforeAll(async () => { + compiler.genFromDecomposed( + path.join(__dirname, "../circuits/common/body_hash.json"), + { + circomFilePath: path.join( + __dirname, + "../circuits/common/body_hash_regex.circom" + ), + templateName: "BodyHashRegex", + genSubstrs: true, + } + ); + circuit = await wasm_tester( + path.join(__dirname, "./circuits/test_body_hash_regex.circom"), + option + ); + }); + + it("bodyhash in the header", async () => { + const signatureField = `dkim-signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1694989812; x=1695594612; dara=google.com; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=BWETwQ9JDReS4GyR2v2TTR8Bpzj9ayumsWQJ3q7vehs=; b=`; + const paddedStr = apis.padString(signatureField, 1024); + const circuitInputs = { + msg: paddedStr, + }; + const witness = await circuit.calculateWitness(circuitInputs); + await circuit.checkConstraints(witness); + expect(1n).toEqual(witness[1]); + const prefixIdxes = apis.extractSubstrIdxes( + signatureField, + readFileSync( + path.join(__dirname, "../circuits/common/body_hash.json"), + "utf8" + ) + )[0]; + 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("timestamp after new line", async () => { + const signatureField = `\r\ndkim-signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1694989812; x=1695594612; dara=google.com; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=BWETwQ9JDReS4GyR2v2TTR8Bpzj9ayumsWQJ3q7vehs=; b=`; + const paddedStr = apis.padString(signatureField, 1024); + const circuitInputs = { + msg: paddedStr, + }; + const witness = await circuit.calculateWitness(circuitInputs); + await circuit.checkConstraints(witness); + expect(1n).toEqual(witness[1]); + const prefixIdxes = apis.extractSubstrIdxes( + signatureField, + readFileSync( + path.join(__dirname, "../circuits/common/body_hash.json"), + "utf8" + ) + )[0]; + 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/body_hash_regex.test.ts b/packages/circom/tests/body_hash_regex.test.ts deleted file mode 100644 index ee59450..0000000 --- a/packages/circom/tests/body_hash_regex.test.ts +++ /dev/null @@ -1,69 +0,0 @@ -const ff = require('ffjavascript'); -const stringifyBigInts = ff.utils.stringifyBigInts; -const circom_tester = require("circom_tester"); -const wasm_tester = circom_tester.wasm; -import * as path from "path"; -import { readFileSync } from "fs"; -const p = "21888242871839275222246405745257275088548364400416034343698204186575808495617"; -const field = new ff.F1Field(p); -const apis = require("../../apis"); -const option = { - include: path.join(__dirname, "../../../node_modules") -}; -const compiler = require("../../compiler"); - - -jest.setTimeout(120000); -describe("Bodyhash Regex", () => { - let circuit; - beforeAll(async () => { - compiler.genFromDecomposed(path.join(__dirname, "../circuits/common/body_hash.json"), { - circomFilePath: path.join(__dirname, "../circuits/common/body_hash_regex.circom"), - templateName: "BodyHashRegex", - genSubstrs: true - }); - circuit = await wasm_tester(path.join(__dirname, "./circuits/test_body_hash_regex.circom"), option); - }); - - it("bodyhash in the header", async () => { - const signatureField = `dkim-signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1694989812; x=1695594612; dara=google.com; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=BWETwQ9JDReS4GyR2v2TTR8Bpzj9ayumsWQJ3q7vehs=; b=`; - // const revealed = "1694989812"; - const paddedStr = apis.padString(signatureField, 1024); - const circuitInputs = { - msg: paddedStr, - }; - // const circuit = await wasm_tester(path.join(__dirname, "./circuits/test_timestamp_regex.circom"), option); - const witness = await circuit.calculateWitness(circuitInputs); - await circuit.checkConstraints(witness); - expect(1n).toEqual(witness[1]); - const prefixIdxes = apis.extractSubstrIdxes(signatureField, readFileSync(path.join(__dirname, "../circuits/common/body_hash.json"), "utf8"))[0]; - 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("timestamp after new line", async () => { - const signatureField = `\r\ndkim-signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1694989812; x=1695594612; dara=google.com; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=BWETwQ9JDReS4GyR2v2TTR8Bpzj9ayumsWQJ3q7vehs=; b=`; - // const revealed = "1694989812"; - const paddedStr = apis.padString(signatureField, 1024); - const circuitInputs = { - msg: paddedStr, - }; - // const circuit = await wasm_tester(path.join(__dirname, "./circuits/test_bodyhash_regex.circom"), option); - const witness = await circuit.calculateWitness(circuitInputs); - await circuit.checkConstraints(witness); - expect(1n).toEqual(witness[1]); - const prefixIdxes = apis.extractSubstrIdxes(signatureField, readFileSync(path.join(__dirname, "../circuits/common/body_hash.json"), "utf8"))[0]; - 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]); - } - } - }); -}); \ No newline at end of file diff --git a/packages/circom/tests/circuits/international_chars_decomposed.circom b/packages/circom/tests/circuits/international_chars_decomposed.circom new file mode 100644 index 0000000..b26cfe7 --- /dev/null +++ b/packages/circom/tests/circuits/international_chars_decomposed.circom @@ -0,0 +1,908 @@ +pragma circom 2.1.5; + +include "@zk-email/zk-regex-circom/circuits/regex_helpers.circom"; + +// regex: Latin-Extension=[¡-ƿ]+ Greek=[Ͱ-Ͽ]+ Cyrillic=[Ѐ-ӿ]+ Arabic=[؀-ۿ]+ Devanagari=[ऀ-ॿ]+ Hiragana&Katakana=[ぁ-ヿ]+ +template InternationalCharsDecomposed(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[67][num_bytes]; + component lt[6][num_bytes]; + component and[103][num_bytes]; + component multi_or[18][num_bytes]; + signal states[num_bytes+1][90]; + component state_changed[num_bytes]; + + states[0][0] <== 1; + for (var i = 1; i < 90; i++) { + states[0][i] <== 0; + } + + for (var i = 0; i < num_bytes; i++) { + state_changed[i] = MultiOR(89); + eq[0][i] = IsEqual(); + eq[0][i].in[0] <== in[i]; + eq[0][i].in[1] <== 76; + and[0][i] = AND(); + and[0][i].a <== states[i][0]; + and[0][i].b <== eq[0][i].out; + states[i+1][1] <== and[0][i].out; + state_changed[i].in[0] <== states[i+1][1]; + eq[1][i] = IsEqual(); + eq[1][i].in[0] <== in[i]; + eq[1][i].in[1] <== 97; + and[1][i] = AND(); + and[1][i].a <== states[i][1]; + and[1][i].b <== eq[1][i].out; + states[i+1][2] <== and[1][i].out; + state_changed[i].in[1] <== states[i+1][2]; + eq[2][i] = IsEqual(); + eq[2][i].in[0] <== in[i]; + eq[2][i].in[1] <== 116; + and[2][i] = AND(); + and[2][i].a <== states[i][2]; + and[2][i].b <== eq[2][i].out; + states[i+1][3] <== and[2][i].out; + state_changed[i].in[2] <== states[i+1][3]; + eq[3][i] = IsEqual(); + eq[3][i].in[0] <== in[i]; + eq[3][i].in[1] <== 105; + and[3][i] = AND(); + and[3][i].a <== states[i][3]; + and[3][i].b <== eq[3][i].out; + states[i+1][4] <== and[3][i].out; + state_changed[i].in[3] <== states[i+1][4]; + eq[4][i] = IsEqual(); + eq[4][i].in[0] <== in[i]; + eq[4][i].in[1] <== 110; + and[4][i] = AND(); + and[4][i].a <== states[i][4]; + and[4][i].b <== eq[4][i].out; + states[i+1][5] <== and[4][i].out; + state_changed[i].in[4] <== states[i+1][5]; + eq[5][i] = IsEqual(); + eq[5][i].in[0] <== in[i]; + eq[5][i].in[1] <== 45; + and[5][i] = AND(); + and[5][i].a <== states[i][5]; + and[5][i].b <== eq[5][i].out; + states[i+1][6] <== and[5][i].out; + state_changed[i].in[5] <== states[i+1][6]; + eq[6][i] = IsEqual(); + eq[6][i].in[0] <== in[i]; + eq[6][i].in[1] <== 69; + and[6][i] = AND(); + and[6][i].a <== states[i][6]; + and[6][i].b <== eq[6][i].out; + states[i+1][7] <== and[6][i].out; + state_changed[i].in[6] <== states[i+1][7]; + eq[7][i] = IsEqual(); + eq[7][i].in[0] <== in[i]; + eq[7][i].in[1] <== 120; + and[7][i] = AND(); + and[7][i].a <== states[i][7]; + and[7][i].b <== eq[7][i].out; + states[i+1][8] <== and[7][i].out; + state_changed[i].in[7] <== states[i+1][8]; + and[8][i] = AND(); + and[8][i].a <== states[i][8]; + and[8][i].b <== eq[2][i].out; + states[i+1][9] <== and[8][i].out; + state_changed[i].in[8] <== states[i+1][9]; + eq[8][i] = IsEqual(); + eq[8][i].in[0] <== in[i]; + eq[8][i].in[1] <== 101; + and[9][i] = AND(); + and[9][i].a <== states[i][9]; + and[9][i].b <== eq[8][i].out; + states[i+1][10] <== and[9][i].out; + state_changed[i].in[9] <== states[i+1][10]; + and[10][i] = AND(); + and[10][i].a <== states[i][10]; + and[10][i].b <== eq[4][i].out; + states[i+1][11] <== and[10][i].out; + state_changed[i].in[10] <== states[i+1][11]; + eq[9][i] = IsEqual(); + eq[9][i].in[0] <== in[i]; + eq[9][i].in[1] <== 115; + and[11][i] = AND(); + and[11][i].a <== states[i][11]; + and[11][i].b <== eq[9][i].out; + states[i+1][12] <== and[11][i].out; + state_changed[i].in[11] <== states[i+1][12]; + and[12][i] = AND(); + and[12][i].a <== states[i][12]; + and[12][i].b <== eq[3][i].out; + states[i+1][13] <== and[12][i].out; + state_changed[i].in[12] <== states[i+1][13]; + eq[10][i] = IsEqual(); + eq[10][i].in[0] <== in[i]; + eq[10][i].in[1] <== 111; + and[13][i] = AND(); + and[13][i].a <== states[i][13]; + and[13][i].b <== eq[10][i].out; + states[i+1][14] <== and[13][i].out; + state_changed[i].in[13] <== states[i+1][14]; + and[14][i] = AND(); + and[14][i].a <== states[i][14]; + and[14][i].b <== eq[4][i].out; + states[i+1][15] <== and[14][i].out; + state_changed[i].in[14] <== states[i+1][15]; + eq[11][i] = IsEqual(); + eq[11][i].in[0] <== in[i]; + eq[11][i].in[1] <== 61; + and[15][i] = AND(); + and[15][i].a <== states[i][15]; + and[15][i].b <== eq[11][i].out; + states[i+1][16] <== and[15][i].out; + state_changed[i].in[15] <== states[i+1][16]; + eq[12][i] = IsEqual(); + eq[12][i].in[0] <== in[i]; + eq[12][i].in[1] <== 195; + eq[13][i] = IsEqual(); + eq[13][i].in[0] <== in[i]; + eq[13][i].in[1] <== 196; + eq[14][i] = IsEqual(); + eq[14][i].in[0] <== in[i]; + eq[14][i].in[1] <== 197; + eq[15][i] = IsEqual(); + eq[15][i].in[0] <== in[i]; + eq[15][i].in[1] <== 198; + and[16][i] = AND(); + and[16][i].a <== states[i][16]; + multi_or[0][i] = MultiOR(4); + multi_or[0][i].in[0] <== eq[12][i].out; + multi_or[0][i].in[1] <== eq[13][i].out; + multi_or[0][i].in[2] <== eq[14][i].out; + multi_or[0][i].in[3] <== eq[15][i].out; + and[16][i].b <== multi_or[0][i].out; + and[17][i] = AND(); + and[17][i].a <== states[i][19]; + and[17][i].b <== multi_or[0][i].out; + multi_or[1][i] = MultiOR(2); + multi_or[1][i].in[0] <== and[16][i].out; + multi_or[1][i].in[1] <== and[17][i].out; + states[i+1][17] <== multi_or[1][i].out; + state_changed[i].in[16] <== states[i+1][17]; + eq[16][i] = IsEqual(); + eq[16][i].in[0] <== in[i]; + eq[16][i].in[1] <== 194; + and[18][i] = AND(); + and[18][i].a <== states[i][16]; + and[18][i].b <== eq[16][i].out; + and[19][i] = AND(); + and[19][i].a <== states[i][19]; + and[19][i].b <== eq[16][i].out; + multi_or[2][i] = MultiOR(2); + multi_or[2][i].in[0] <== and[18][i].out; + multi_or[2][i].in[1] <== and[19][i].out; + states[i+1][18] <== multi_or[2][i].out; + state_changed[i].in[17] <== states[i+1][18]; + lt[0][i] = LessEqThan(8); + lt[0][i].in[0] <== 128; + lt[0][i].in[1] <== in[i]; + lt[1][i] = LessEqThan(8); + lt[1][i].in[0] <== in[i]; + lt[1][i].in[1] <== 191; + and[20][i] = AND(); + and[20][i].a <== lt[0][i].out; + and[20][i].b <== lt[1][i].out; + and[21][i] = AND(); + and[21][i].a <== states[i][17]; + and[21][i].b <== and[20][i].out; + lt[2][i] = LessEqThan(8); + lt[2][i].in[0] <== 161; + lt[2][i].in[1] <== in[i]; + lt[3][i] = LessEqThan(8); + lt[3][i].in[0] <== in[i]; + lt[3][i].in[1] <== 191; + and[22][i] = AND(); + and[22][i].a <== lt[2][i].out; + and[22][i].b <== lt[3][i].out; + and[23][i] = AND(); + and[23][i].a <== states[i][18]; + and[23][i].b <== and[22][i].out; + multi_or[3][i] = MultiOR(2); + multi_or[3][i].in[0] <== and[21][i].out; + multi_or[3][i].in[1] <== and[23][i].out; + states[i+1][19] <== multi_or[3][i].out; + state_changed[i].in[18] <== states[i+1][19]; + eq[17][i] = IsEqual(); + eq[17][i].in[0] <== in[i]; + eq[17][i].in[1] <== 32; + and[24][i] = AND(); + and[24][i].a <== states[i][19]; + and[24][i].b <== eq[17][i].out; + states[i+1][20] <== and[24][i].out; + state_changed[i].in[19] <== states[i+1][20]; + eq[18][i] = IsEqual(); + eq[18][i].in[0] <== in[i]; + eq[18][i].in[1] <== 71; + and[25][i] = AND(); + and[25][i].a <== states[i][20]; + and[25][i].b <== eq[18][i].out; + states[i+1][21] <== and[25][i].out; + state_changed[i].in[20] <== states[i+1][21]; + eq[19][i] = IsEqual(); + eq[19][i].in[0] <== in[i]; + eq[19][i].in[1] <== 114; + and[26][i] = AND(); + and[26][i].a <== states[i][21]; + and[26][i].b <== eq[19][i].out; + states[i+1][22] <== and[26][i].out; + state_changed[i].in[21] <== states[i+1][22]; + and[27][i] = AND(); + and[27][i].a <== states[i][22]; + and[27][i].b <== eq[8][i].out; + states[i+1][23] <== and[27][i].out; + state_changed[i].in[22] <== states[i+1][23]; + and[28][i] = AND(); + and[28][i].a <== states[i][23]; + and[28][i].b <== eq[8][i].out; + states[i+1][24] <== and[28][i].out; + state_changed[i].in[23] <== states[i+1][24]; + eq[20][i] = IsEqual(); + eq[20][i].in[0] <== in[i]; + eq[20][i].in[1] <== 107; + and[29][i] = AND(); + and[29][i].a <== states[i][24]; + and[29][i].b <== eq[20][i].out; + states[i+1][25] <== and[29][i].out; + state_changed[i].in[24] <== states[i+1][25]; + and[30][i] = AND(); + and[30][i].a <== states[i][25]; + and[30][i].b <== eq[11][i].out; + states[i+1][26] <== and[30][i].out; + state_changed[i].in[25] <== states[i+1][26]; + eq[21][i] = IsEqual(); + eq[21][i].in[0] <== in[i]; + eq[21][i].in[1] <== 206; + eq[22][i] = IsEqual(); + eq[22][i].in[0] <== in[i]; + eq[22][i].in[1] <== 207; + and[31][i] = AND(); + and[31][i].a <== states[i][26]; + multi_or[4][i] = MultiOR(2); + multi_or[4][i].in[0] <== eq[21][i].out; + multi_or[4][i].in[1] <== eq[22][i].out; + and[31][i].b <== multi_or[4][i].out; + and[32][i] = AND(); + and[32][i].a <== states[i][29]; + and[32][i].b <== multi_or[4][i].out; + multi_or[5][i] = MultiOR(2); + multi_or[5][i].in[0] <== and[31][i].out; + multi_or[5][i].in[1] <== and[32][i].out; + states[i+1][27] <== multi_or[5][i].out; + state_changed[i].in[26] <== states[i+1][27]; + eq[23][i] = IsEqual(); + eq[23][i].in[0] <== in[i]; + eq[23][i].in[1] <== 205; + and[33][i] = AND(); + and[33][i].a <== states[i][26]; + and[33][i].b <== eq[23][i].out; + and[34][i] = AND(); + and[34][i].a <== states[i][29]; + and[34][i].b <== eq[23][i].out; + multi_or[6][i] = MultiOR(2); + multi_or[6][i].in[0] <== and[33][i].out; + multi_or[6][i].in[1] <== and[34][i].out; + states[i+1][28] <== multi_or[6][i].out; + state_changed[i].in[27] <== states[i+1][28]; + and[35][i] = AND(); + and[35][i].a <== states[i][27]; + and[35][i].b <== and[20][i].out; + eq[24][i] = IsEqual(); + eq[24][i].in[0] <== in[i]; + eq[24][i].in[1] <== 176; + eq[25][i] = IsEqual(); + eq[25][i].in[0] <== in[i]; + eq[25][i].in[1] <== 177; + eq[26][i] = IsEqual(); + eq[26][i].in[0] <== in[i]; + eq[26][i].in[1] <== 178; + eq[27][i] = IsEqual(); + eq[27][i].in[0] <== in[i]; + eq[27][i].in[1] <== 179; + eq[28][i] = IsEqual(); + eq[28][i].in[0] <== in[i]; + eq[28][i].in[1] <== 180; + eq[29][i] = IsEqual(); + eq[29][i].in[0] <== in[i]; + eq[29][i].in[1] <== 181; + eq[30][i] = IsEqual(); + eq[30][i].in[0] <== in[i]; + eq[30][i].in[1] <== 182; + eq[31][i] = IsEqual(); + eq[31][i].in[0] <== in[i]; + eq[31][i].in[1] <== 183; + eq[32][i] = IsEqual(); + eq[32][i].in[0] <== in[i]; + eq[32][i].in[1] <== 184; + eq[33][i] = IsEqual(); + eq[33][i].in[0] <== in[i]; + eq[33][i].in[1] <== 185; + eq[34][i] = IsEqual(); + eq[34][i].in[0] <== in[i]; + eq[34][i].in[1] <== 186; + eq[35][i] = IsEqual(); + eq[35][i].in[0] <== in[i]; + eq[35][i].in[1] <== 187; + eq[36][i] = IsEqual(); + eq[36][i].in[0] <== in[i]; + eq[36][i].in[1] <== 188; + eq[37][i] = IsEqual(); + eq[37][i].in[0] <== in[i]; + eq[37][i].in[1] <== 189; + eq[38][i] = IsEqual(); + eq[38][i].in[0] <== in[i]; + eq[38][i].in[1] <== 190; + eq[39][i] = IsEqual(); + eq[39][i].in[0] <== in[i]; + eq[39][i].in[1] <== 191; + and[36][i] = AND(); + and[36][i].a <== states[i][28]; + multi_or[7][i] = MultiOR(16); + multi_or[7][i].in[0] <== eq[24][i].out; + multi_or[7][i].in[1] <== eq[25][i].out; + multi_or[7][i].in[2] <== eq[26][i].out; + multi_or[7][i].in[3] <== eq[27][i].out; + multi_or[7][i].in[4] <== eq[28][i].out; + multi_or[7][i].in[5] <== eq[29][i].out; + multi_or[7][i].in[6] <== eq[30][i].out; + multi_or[7][i].in[7] <== eq[31][i].out; + multi_or[7][i].in[8] <== eq[32][i].out; + multi_or[7][i].in[9] <== eq[33][i].out; + multi_or[7][i].in[10] <== eq[34][i].out; + multi_or[7][i].in[11] <== eq[35][i].out; + multi_or[7][i].in[12] <== eq[36][i].out; + multi_or[7][i].in[13] <== eq[37][i].out; + multi_or[7][i].in[14] <== eq[38][i].out; + multi_or[7][i].in[15] <== eq[39][i].out; + and[36][i].b <== multi_or[7][i].out; + multi_or[8][i] = MultiOR(2); + multi_or[8][i].in[0] <== and[35][i].out; + multi_or[8][i].in[1] <== and[36][i].out; + states[i+1][29] <== multi_or[8][i].out; + state_changed[i].in[28] <== states[i+1][29]; + and[37][i] = AND(); + and[37][i].a <== states[i][29]; + and[37][i].b <== eq[17][i].out; + states[i+1][30] <== and[37][i].out; + state_changed[i].in[29] <== states[i+1][30]; + eq[40][i] = IsEqual(); + eq[40][i].in[0] <== in[i]; + eq[40][i].in[1] <== 67; + and[38][i] = AND(); + and[38][i].a <== states[i][30]; + and[38][i].b <== eq[40][i].out; + states[i+1][31] <== and[38][i].out; + state_changed[i].in[30] <== states[i+1][31]; + eq[41][i] = IsEqual(); + eq[41][i].in[0] <== in[i]; + eq[41][i].in[1] <== 121; + and[39][i] = AND(); + and[39][i].a <== states[i][31]; + and[39][i].b <== eq[41][i].out; + states[i+1][32] <== and[39][i].out; + state_changed[i].in[31] <== states[i+1][32]; + and[40][i] = AND(); + and[40][i].a <== states[i][32]; + and[40][i].b <== eq[19][i].out; + states[i+1][33] <== and[40][i].out; + state_changed[i].in[32] <== states[i+1][33]; + and[41][i] = AND(); + and[41][i].a <== states[i][33]; + and[41][i].b <== eq[3][i].out; + states[i+1][34] <== and[41][i].out; + state_changed[i].in[33] <== states[i+1][34]; + eq[42][i] = IsEqual(); + eq[42][i].in[0] <== in[i]; + eq[42][i].in[1] <== 108; + and[42][i] = AND(); + and[42][i].a <== states[i][34]; + and[42][i].b <== eq[42][i].out; + states[i+1][35] <== and[42][i].out; + state_changed[i].in[34] <== states[i+1][35]; + and[43][i] = AND(); + and[43][i].a <== states[i][35]; + and[43][i].b <== eq[42][i].out; + states[i+1][36] <== and[43][i].out; + state_changed[i].in[35] <== states[i+1][36]; + and[44][i] = AND(); + and[44][i].a <== states[i][36]; + and[44][i].b <== eq[3][i].out; + states[i+1][37] <== and[44][i].out; + state_changed[i].in[36] <== states[i+1][37]; + eq[43][i] = IsEqual(); + eq[43][i].in[0] <== in[i]; + eq[43][i].in[1] <== 99; + and[45][i] = AND(); + and[45][i].a <== states[i][37]; + and[45][i].b <== eq[43][i].out; + states[i+1][38] <== and[45][i].out; + state_changed[i].in[37] <== states[i+1][38]; + and[46][i] = AND(); + and[46][i].a <== states[i][38]; + and[46][i].b <== eq[11][i].out; + states[i+1][39] <== and[46][i].out; + state_changed[i].in[38] <== states[i+1][39]; + eq[44][i] = IsEqual(); + eq[44][i].in[0] <== in[i]; + eq[44][i].in[1] <== 208; + eq[45][i] = IsEqual(); + eq[45][i].in[0] <== in[i]; + eq[45][i].in[1] <== 209; + eq[46][i] = IsEqual(); + eq[46][i].in[0] <== in[i]; + eq[46][i].in[1] <== 210; + eq[47][i] = IsEqual(); + eq[47][i].in[0] <== in[i]; + eq[47][i].in[1] <== 211; + and[47][i] = AND(); + and[47][i].a <== states[i][39]; + multi_or[9][i] = MultiOR(4); + multi_or[9][i].in[0] <== eq[44][i].out; + multi_or[9][i].in[1] <== eq[45][i].out; + multi_or[9][i].in[2] <== eq[46][i].out; + multi_or[9][i].in[3] <== eq[47][i].out; + and[47][i].b <== multi_or[9][i].out; + and[48][i] = AND(); + and[48][i].a <== states[i][41]; + and[48][i].b <== multi_or[9][i].out; + multi_or[10][i] = MultiOR(2); + multi_or[10][i].in[0] <== and[47][i].out; + multi_or[10][i].in[1] <== and[48][i].out; + states[i+1][40] <== multi_or[10][i].out; + state_changed[i].in[39] <== states[i+1][40]; + and[49][i] = AND(); + and[49][i].a <== states[i][40]; + and[49][i].b <== and[20][i].out; + states[i+1][41] <== and[49][i].out; + state_changed[i].in[40] <== states[i+1][41]; + and[50][i] = AND(); + and[50][i].a <== states[i][41]; + and[50][i].b <== eq[17][i].out; + states[i+1][42] <== and[50][i].out; + state_changed[i].in[41] <== states[i+1][42]; + eq[48][i] = IsEqual(); + eq[48][i].in[0] <== in[i]; + eq[48][i].in[1] <== 65; + and[51][i] = AND(); + and[51][i].a <== states[i][42]; + and[51][i].b <== eq[48][i].out; + states[i+1][43] <== and[51][i].out; + state_changed[i].in[42] <== states[i+1][43]; + and[52][i] = AND(); + and[52][i].a <== states[i][43]; + and[52][i].b <== eq[19][i].out; + states[i+1][44] <== and[52][i].out; + state_changed[i].in[43] <== states[i+1][44]; + and[53][i] = AND(); + and[53][i].a <== states[i][44]; + and[53][i].b <== eq[1][i].out; + states[i+1][45] <== and[53][i].out; + state_changed[i].in[44] <== states[i+1][45]; + eq[49][i] = IsEqual(); + eq[49][i].in[0] <== in[i]; + eq[49][i].in[1] <== 98; + and[54][i] = AND(); + and[54][i].a <== states[i][45]; + and[54][i].b <== eq[49][i].out; + states[i+1][46] <== and[54][i].out; + state_changed[i].in[45] <== states[i+1][46]; + and[55][i] = AND(); + and[55][i].a <== states[i][46]; + and[55][i].b <== eq[3][i].out; + states[i+1][47] <== and[55][i].out; + state_changed[i].in[46] <== states[i+1][47]; + and[56][i] = AND(); + and[56][i].a <== states[i][47]; + and[56][i].b <== eq[43][i].out; + states[i+1][48] <== and[56][i].out; + state_changed[i].in[47] <== states[i+1][48]; + and[57][i] = AND(); + and[57][i].a <== states[i][48]; + and[57][i].b <== eq[11][i].out; + states[i+1][49] <== and[57][i].out; + state_changed[i].in[48] <== states[i+1][49]; + eq[50][i] = IsEqual(); + eq[50][i].in[0] <== in[i]; + eq[50][i].in[1] <== 216; + eq[51][i] = IsEqual(); + eq[51][i].in[0] <== in[i]; + eq[51][i].in[1] <== 217; + eq[52][i] = IsEqual(); + eq[52][i].in[0] <== in[i]; + eq[52][i].in[1] <== 218; + eq[53][i] = IsEqual(); + eq[53][i].in[0] <== in[i]; + eq[53][i].in[1] <== 219; + and[58][i] = AND(); + and[58][i].a <== states[i][49]; + multi_or[11][i] = MultiOR(4); + multi_or[11][i].in[0] <== eq[50][i].out; + multi_or[11][i].in[1] <== eq[51][i].out; + multi_or[11][i].in[2] <== eq[52][i].out; + multi_or[11][i].in[3] <== eq[53][i].out; + and[58][i].b <== multi_or[11][i].out; + and[59][i] = AND(); + and[59][i].a <== states[i][51]; + and[59][i].b <== multi_or[11][i].out; + multi_or[12][i] = MultiOR(2); + multi_or[12][i].in[0] <== and[58][i].out; + multi_or[12][i].in[1] <== and[59][i].out; + states[i+1][50] <== multi_or[12][i].out; + state_changed[i].in[49] <== states[i+1][50]; + and[60][i] = AND(); + and[60][i].a <== states[i][50]; + and[60][i].b <== and[20][i].out; + states[i+1][51] <== and[60][i].out; + state_changed[i].in[50] <== states[i+1][51]; + and[61][i] = AND(); + and[61][i].a <== states[i][51]; + and[61][i].b <== eq[17][i].out; + states[i+1][52] <== and[61][i].out; + state_changed[i].in[51] <== states[i+1][52]; + eq[54][i] = IsEqual(); + eq[54][i].in[0] <== in[i]; + eq[54][i].in[1] <== 68; + and[62][i] = AND(); + and[62][i].a <== states[i][52]; + and[62][i].b <== eq[54][i].out; + states[i+1][53] <== and[62][i].out; + state_changed[i].in[52] <== states[i+1][53]; + and[63][i] = AND(); + and[63][i].a <== states[i][53]; + and[63][i].b <== eq[8][i].out; + states[i+1][54] <== and[63][i].out; + state_changed[i].in[53] <== states[i+1][54]; + eq[55][i] = IsEqual(); + eq[55][i].in[0] <== in[i]; + eq[55][i].in[1] <== 118; + and[64][i] = AND(); + and[64][i].a <== states[i][54]; + and[64][i].b <== eq[55][i].out; + states[i+1][55] <== and[64][i].out; + state_changed[i].in[54] <== states[i+1][55]; + and[65][i] = AND(); + and[65][i].a <== states[i][55]; + and[65][i].b <== eq[1][i].out; + states[i+1][56] <== and[65][i].out; + state_changed[i].in[55] <== states[i+1][56]; + and[66][i] = AND(); + and[66][i].a <== states[i][56]; + and[66][i].b <== eq[4][i].out; + states[i+1][57] <== and[66][i].out; + state_changed[i].in[56] <== states[i+1][57]; + and[67][i] = AND(); + and[67][i].a <== states[i][57]; + and[67][i].b <== eq[1][i].out; + states[i+1][58] <== and[67][i].out; + state_changed[i].in[57] <== states[i+1][58]; + eq[56][i] = IsEqual(); + eq[56][i].in[0] <== in[i]; + eq[56][i].in[1] <== 103; + and[68][i] = AND(); + and[68][i].a <== states[i][58]; + and[68][i].b <== eq[56][i].out; + states[i+1][59] <== and[68][i].out; + state_changed[i].in[58] <== states[i+1][59]; + and[69][i] = AND(); + and[69][i].a <== states[i][59]; + and[69][i].b <== eq[1][i].out; + states[i+1][60] <== and[69][i].out; + state_changed[i].in[59] <== states[i+1][60]; + and[70][i] = AND(); + and[70][i].a <== states[i][60]; + and[70][i].b <== eq[19][i].out; + states[i+1][61] <== and[70][i].out; + state_changed[i].in[60] <== states[i+1][61]; + and[71][i] = AND(); + and[71][i].a <== states[i][61]; + and[71][i].b <== eq[3][i].out; + states[i+1][62] <== and[71][i].out; + state_changed[i].in[61] <== states[i+1][62]; + and[72][i] = AND(); + and[72][i].a <== states[i][62]; + and[72][i].b <== eq[11][i].out; + states[i+1][63] <== and[72][i].out; + state_changed[i].in[62] <== states[i+1][63]; + eq[57][i] = IsEqual(); + eq[57][i].in[0] <== in[i]; + eq[57][i].in[1] <== 224; + and[73][i] = AND(); + and[73][i].a <== states[i][63]; + and[73][i].b <== eq[57][i].out; + and[74][i] = AND(); + and[74][i].a <== states[i][66]; + and[74][i].b <== eq[57][i].out; + multi_or[13][i] = MultiOR(2); + multi_or[13][i].in[0] <== and[73][i].out; + multi_or[13][i].in[1] <== and[74][i].out; + states[i+1][64] <== multi_or[13][i].out; + state_changed[i].in[63] <== states[i+1][64]; + eq[58][i] = IsEqual(); + eq[58][i].in[0] <== in[i]; + eq[58][i].in[1] <== 164; + eq[59][i] = IsEqual(); + eq[59][i].in[0] <== in[i]; + eq[59][i].in[1] <== 165; + and[75][i] = AND(); + and[75][i].a <== states[i][64]; + multi_or[14][i] = MultiOR(2); + multi_or[14][i].in[0] <== eq[58][i].out; + multi_or[14][i].in[1] <== eq[59][i].out; + and[75][i].b <== multi_or[14][i].out; + states[i+1][65] <== and[75][i].out; + state_changed[i].in[64] <== states[i+1][65]; + and[76][i] = AND(); + and[76][i].a <== states[i][65]; + and[76][i].b <== and[20][i].out; + states[i+1][66] <== and[76][i].out; + state_changed[i].in[65] <== states[i+1][66]; + and[77][i] = AND(); + and[77][i].a <== states[i][66]; + and[77][i].b <== eq[17][i].out; + states[i+1][67] <== and[77][i].out; + state_changed[i].in[66] <== states[i+1][67]; + eq[60][i] = IsEqual(); + eq[60][i].in[0] <== in[i]; + eq[60][i].in[1] <== 72; + and[78][i] = AND(); + and[78][i].a <== states[i][67]; + and[78][i].b <== eq[60][i].out; + states[i+1][68] <== and[78][i].out; + state_changed[i].in[67] <== states[i+1][68]; + and[79][i] = AND(); + and[79][i].a <== states[i][68]; + and[79][i].b <== eq[3][i].out; + states[i+1][69] <== and[79][i].out; + state_changed[i].in[68] <== states[i+1][69]; + and[80][i] = AND(); + and[80][i].a <== states[i][69]; + and[80][i].b <== eq[19][i].out; + states[i+1][70] <== and[80][i].out; + state_changed[i].in[69] <== states[i+1][70]; + and[81][i] = AND(); + and[81][i].a <== states[i][70]; + and[81][i].b <== eq[1][i].out; + states[i+1][71] <== and[81][i].out; + state_changed[i].in[70] <== states[i+1][71]; + and[82][i] = AND(); + and[82][i].a <== states[i][71]; + and[82][i].b <== eq[56][i].out; + states[i+1][72] <== and[82][i].out; + state_changed[i].in[71] <== states[i+1][72]; + and[83][i] = AND(); + and[83][i].a <== states[i][72]; + and[83][i].b <== eq[1][i].out; + states[i+1][73] <== and[83][i].out; + state_changed[i].in[72] <== states[i+1][73]; + and[84][i] = AND(); + and[84][i].a <== states[i][73]; + and[84][i].b <== eq[4][i].out; + states[i+1][74] <== and[84][i].out; + state_changed[i].in[73] <== states[i+1][74]; + and[85][i] = AND(); + and[85][i].a <== states[i][74]; + and[85][i].b <== eq[1][i].out; + states[i+1][75] <== and[85][i].out; + state_changed[i].in[74] <== states[i+1][75]; + eq[61][i] = IsEqual(); + eq[61][i].in[0] <== in[i]; + eq[61][i].in[1] <== 38; + and[86][i] = AND(); + and[86][i].a <== states[i][75]; + and[86][i].b <== eq[61][i].out; + states[i+1][76] <== and[86][i].out; + state_changed[i].in[75] <== states[i+1][76]; + eq[62][i] = IsEqual(); + eq[62][i].in[0] <== in[i]; + eq[62][i].in[1] <== 75; + and[87][i] = AND(); + and[87][i].a <== states[i][76]; + and[87][i].b <== eq[62][i].out; + states[i+1][77] <== and[87][i].out; + state_changed[i].in[76] <== states[i+1][77]; + and[88][i] = AND(); + and[88][i].a <== states[i][77]; + and[88][i].b <== eq[1][i].out; + states[i+1][78] <== and[88][i].out; + state_changed[i].in[77] <== states[i+1][78]; + and[89][i] = AND(); + and[89][i].a <== states[i][78]; + and[89][i].b <== eq[2][i].out; + states[i+1][79] <== and[89][i].out; + state_changed[i].in[78] <== states[i+1][79]; + and[90][i] = AND(); + and[90][i].a <== states[i][79]; + and[90][i].b <== eq[1][i].out; + states[i+1][80] <== and[90][i].out; + state_changed[i].in[79] <== states[i+1][80]; + and[91][i] = AND(); + and[91][i].a <== states[i][80]; + and[91][i].b <== eq[20][i].out; + states[i+1][81] <== and[91][i].out; + state_changed[i].in[80] <== states[i+1][81]; + and[92][i] = AND(); + and[92][i].a <== states[i][81]; + and[92][i].b <== eq[1][i].out; + states[i+1][82] <== and[92][i].out; + state_changed[i].in[81] <== states[i+1][82]; + and[93][i] = AND(); + and[93][i].a <== states[i][82]; + and[93][i].b <== eq[4][i].out; + states[i+1][83] <== and[93][i].out; + state_changed[i].in[82] <== states[i+1][83]; + and[94][i] = AND(); + and[94][i].a <== states[i][83]; + and[94][i].b <== eq[1][i].out; + states[i+1][84] <== and[94][i].out; + state_changed[i].in[83] <== states[i+1][84]; + and[95][i] = AND(); + and[95][i].a <== states[i][84]; + and[95][i].b <== eq[11][i].out; + states[i+1][85] <== and[95][i].out; + state_changed[i].in[84] <== states[i+1][85]; + eq[63][i] = IsEqual(); + eq[63][i].in[0] <== in[i]; + eq[63][i].in[1] <== 227; + and[96][i] = AND(); + and[96][i].a <== states[i][85]; + and[96][i].b <== eq[63][i].out; + and[97][i] = AND(); + and[97][i].a <== states[i][89]; + and[97][i].b <== eq[63][i].out; + multi_or[15][i] = MultiOR(2); + multi_or[15][i].in[0] <== and[96][i].out; + multi_or[15][i].in[1] <== and[97][i].out; + states[i+1][86] <== multi_or[15][i].out; + state_changed[i].in[85] <== states[i+1][86]; + eq[64][i] = IsEqual(); + eq[64][i].in[0] <== in[i]; + eq[64][i].in[1] <== 129; + and[98][i] = AND(); + and[98][i].a <== states[i][86]; + and[98][i].b <== eq[64][i].out; + states[i+1][87] <== and[98][i].out; + state_changed[i].in[86] <== states[i+1][87]; + eq[65][i] = IsEqual(); + eq[65][i].in[0] <== in[i]; + eq[65][i].in[1] <== 130; + eq[66][i] = IsEqual(); + eq[66][i].in[0] <== in[i]; + eq[66][i].in[1] <== 131; + and[99][i] = AND(); + and[99][i].a <== states[i][86]; + multi_or[16][i] = MultiOR(2); + multi_or[16][i].in[0] <== eq[65][i].out; + multi_or[16][i].in[1] <== eq[66][i].out; + and[99][i].b <== multi_or[16][i].out; + states[i+1][88] <== and[99][i].out; + state_changed[i].in[87] <== states[i+1][88]; + lt[4][i] = LessEqThan(8); + lt[4][i].in[0] <== 129; + 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[100][i] = AND(); + and[100][i].a <== lt[4][i].out; + and[100][i].b <== lt[5][i].out; + and[101][i] = AND(); + and[101][i].a <== states[i][87]; + and[101][i].b <== and[100][i].out; + and[102][i] = AND(); + and[102][i].a <== states[i][88]; + and[102][i].b <== and[20][i].out; + multi_or[17][i] = MultiOR(2); + multi_or[17][i].in[0] <== and[101][i].out; + multi_or[17][i].in[1] <== and[102][i].out; + states[i+1][89] <== multi_or[17][i].out; + state_changed[i].in[88] <== states[i+1][89]; + states[i+1][0] <== 1 - state_changed[i].out; + } + + component final_state_result = MultiOR(num_bytes+1); + for (var i = 0; i <= num_bytes; i++) { + final_state_result.in[i] <== states[i][89]; + } + out <== final_state_result.out; + signal is_consecutive[msg_bytes+1][2]; + is_consecutive[msg_bytes][1] <== 1; + for (var i = 0; i < msg_bytes; i++) { + is_consecutive[msg_bytes-1-i][0] <== states[num_bytes-i][89] * (1 - is_consecutive[msg_bytes-i][1]) + is_consecutive[msg_bytes-i][1]; + is_consecutive[msg_bytes-1-i][1] <== state_changed[msg_bytes-i].out * is_consecutive[msg_bytes-1-i][0]; + } + // substrings calculated: [{(16, 17), (16, 18), (17, 19), (18, 19), (19, 17), (19, 18)}, {(26, 27), (26, 28), (27, 29), (28, 29), (29, 27), (29, 28)}, {(39, 40), (40, 41), (41, 40)}, {(49, 50), (50, 51), (51, 50)}, {(63, 64), (64, 65), (65, 66), (66, 64)}, {(85, 86), (86, 87), (86, 88), (87, 89), (88, 89), (89, 86)}] + signal is_substr0[msg_bytes][7]; + signal is_reveal0[msg_bytes]; + signal output reveal0[msg_bytes]; + for (var i = 0; i < msg_bytes; i++) { + is_substr0[i][0] <== 0; + // the 0-th substring transitions: [(16, 17), (16, 18), (17, 19), (18, 19), (19, 17), (19, 18)] + is_substr0[i][1] <== is_substr0[i][0] + states[i+1][16] * states[i+2][17]; + is_substr0[i][2] <== is_substr0[i][1] + states[i+1][16] * states[i+2][18]; + is_substr0[i][3] <== is_substr0[i][2] + states[i+1][17] * states[i+2][19]; + is_substr0[i][4] <== is_substr0[i][3] + states[i+1][18] * states[i+2][19]; + is_substr0[i][5] <== is_substr0[i][4] + states[i+1][19] * states[i+2][17]; + is_substr0[i][6] <== is_substr0[i][5] + states[i+1][19] * states[i+2][18]; + is_reveal0[i] <== is_substr0[i][6] * is_consecutive[i][1]; + reveal0[i] <== in[i+1] * is_reveal0[i]; + } + signal is_substr1[msg_bytes][7]; + signal is_reveal1[msg_bytes]; + signal output reveal1[msg_bytes]; + for (var i = 0; i < msg_bytes; i++) { + is_substr1[i][0] <== 0; + // the 1-th substring transitions: [(26, 27), (26, 28), (27, 29), (28, 29), (29, 27), (29, 28)] + is_substr1[i][1] <== is_substr1[i][0] + states[i+1][26] * states[i+2][27]; + is_substr1[i][2] <== is_substr1[i][1] + states[i+1][26] * states[i+2][28]; + is_substr1[i][3] <== is_substr1[i][2] + states[i+1][27] * states[i+2][29]; + is_substr1[i][4] <== is_substr1[i][3] + states[i+1][28] * states[i+2][29]; + is_substr1[i][5] <== is_substr1[i][4] + states[i+1][29] * states[i+2][27]; + is_substr1[i][6] <== is_substr1[i][5] + states[i+1][29] * states[i+2][28]; + is_reveal1[i] <== is_substr1[i][6] * is_consecutive[i][1]; + reveal1[i] <== in[i+1] * is_reveal1[i]; + } + signal is_substr2[msg_bytes][4]; + signal is_reveal2[msg_bytes]; + signal output reveal2[msg_bytes]; + for (var i = 0; i < msg_bytes; i++) { + is_substr2[i][0] <== 0; + // the 2-th substring transitions: [(39, 40), (40, 41), (41, 40)] + is_substr2[i][1] <== is_substr2[i][0] + states[i+1][39] * states[i+2][40]; + is_substr2[i][2] <== is_substr2[i][1] + states[i+1][40] * states[i+2][41]; + is_substr2[i][3] <== is_substr2[i][2] + states[i+1][41] * states[i+2][40]; + is_reveal2[i] <== is_substr2[i][3] * is_consecutive[i][1]; + reveal2[i] <== in[i+1] * is_reveal2[i]; + } + signal is_substr3[msg_bytes][4]; + signal is_reveal3[msg_bytes]; + signal output reveal3[msg_bytes]; + for (var i = 0; i < msg_bytes; i++) { + is_substr3[i][0] <== 0; + // the 3-th substring transitions: [(49, 50), (50, 51), (51, 50)] + is_substr3[i][1] <== is_substr3[i][0] + states[i+1][49] * states[i+2][50]; + is_substr3[i][2] <== is_substr3[i][1] + states[i+1][50] * states[i+2][51]; + is_substr3[i][3] <== is_substr3[i][2] + states[i+1][51] * states[i+2][50]; + is_reveal3[i] <== is_substr3[i][3] * is_consecutive[i][1]; + reveal3[i] <== in[i+1] * is_reveal3[i]; + } + signal is_substr4[msg_bytes][5]; + signal is_reveal4[msg_bytes]; + signal output reveal4[msg_bytes]; + for (var i = 0; i < msg_bytes; i++) { + is_substr4[i][0] <== 0; + // the 4-th substring transitions: [(63, 64), (64, 65), (65, 66), (66, 64)] + is_substr4[i][1] <== is_substr4[i][0] + states[i+1][63] * states[i+2][64]; + is_substr4[i][2] <== is_substr4[i][1] + states[i+1][64] * states[i+2][65]; + is_substr4[i][3] <== is_substr4[i][2] + states[i+1][65] * states[i+2][66]; + is_substr4[i][4] <== is_substr4[i][3] + states[i+1][66] * states[i+2][64]; + is_reveal4[i] <== is_substr4[i][4] * is_consecutive[i][1]; + reveal4[i] <== in[i+1] * is_reveal4[i]; + } + signal is_substr5[msg_bytes][7]; + signal is_reveal5[msg_bytes]; + signal output reveal5[msg_bytes]; + for (var i = 0; i < msg_bytes; i++) { + is_substr5[i][0] <== 0; + // the 5-th substring transitions: [(85, 86), (86, 87), (86, 88), (87, 89), (88, 89), (89, 86)] + is_substr5[i][1] <== is_substr5[i][0] + states[i+1][85] * states[i+2][86]; + is_substr5[i][2] <== is_substr5[i][1] + states[i+1][86] * states[i+2][87]; + is_substr5[i][3] <== is_substr5[i][2] + states[i+1][86] * states[i+2][88]; + is_substr5[i][4] <== is_substr5[i][3] + states[i+1][87] * states[i+2][89]; + is_substr5[i][5] <== is_substr5[i][4] + states[i+1][88] * states[i+2][89]; + is_substr5[i][6] <== is_substr5[i][5] + states[i+1][89] * states[i+2][86]; + is_reveal5[i] <== is_substr5[i][6] * is_consecutive[i][1]; + reveal5[i] <== in[i+1] * is_reveal5[i]; + } +} \ No newline at end of file diff --git a/packages/circom/tests/circuits/international_chars_decomposed.json b/packages/circom/tests/circuits/international_chars_decomposed.json new file mode 100644 index 0000000..45590e6 --- /dev/null +++ b/packages/circom/tests/circuits/international_chars_decomposed.json @@ -0,0 +1,52 @@ +{ + "parts": [ + { + "is_public": false, + "regex_def": "Latin-Extension=" + }, + { + "is_public": true, + "regex_def": "[¡-ƿ]+" + }, + { + "is_public": false, + "regex_def": " Greek=" + }, + { + "is_public": true, + "regex_def": "[Ͱ-Ͽ]+" + }, + { + "is_public": false, + "regex_def": " Cyrillic=" + }, + { + "is_public": true, + "regex_def": "[Ѐ-ӿ]+" + }, + { + "is_public": false, + "regex_def": " Arabic=" + }, + { + "is_public": true, + "regex_def": "[؀-ۿ]+" + }, + { + "is_public": false, + "regex_def": " Devanagari=" + }, + { + "is_public": true, + "regex_def": "[ऀ-ॿ]+" + }, + { + "is_public": false, + "regex_def": " Hiragana&Katakana=" + }, + { + "is_public": true, + "regex_def": "[ぁ-ヿ]+" + } + ] +} diff --git a/packages/circom/tests/circuits/negate1_regex.circom b/packages/circom/tests/circuits/negate1_regex.circom index 2b77730..28b7fac 100644 --- a/packages/circom/tests/circuits/negate1_regex.circom +++ b/packages/circom/tests/circuits/negate1_regex.circom @@ -14,110 +14,438 @@ template Negate1Regex(msg_bytes) { in[i+1] <== msg[i]; } - component eq[3][num_bytes]; - component lt[6][num_bytes]; - component and[8][num_bytes]; - component multi_or[2][num_bytes]; - signal states[num_bytes+1][5]; + component eq[45][num_bytes]; + component lt[14][num_bytes]; + component and[33][num_bytes]; + component multi_or[12][num_bytes]; + signal states[num_bytes+1][12]; component state_changed[num_bytes]; states[0][0] <== 1; - for (var i = 1; i < 5; i++) { + for (var i = 1; i < 12; i++) { states[0][i] <== 0; } for (var i = 0; i < num_bytes; i++) { - state_changed[i] = MultiOR(4); + state_changed[i] = MultiOR(11); + eq[0][i] = IsEqual(); + eq[0][i].in[0] <== in[i]; + eq[0][i].in[1] <== 97; + and[0][i] = AND(); + and[0][i].a <== states[i][0]; + and[0][i].b <== eq[0][i].out; + states[i+1][1] <== and[0][i].out; + state_changed[i].in[0] <== states[i+1][1]; + eq[1][i] = IsEqual(); + eq[1][i].in[0] <== in[i]; + eq[1][i].in[1] <== 58; + and[1][i] = AND(); + and[1][i].a <== states[i][1]; + and[1][i].b <== eq[1][i].out; + states[i+1][2] <== and[1][i].out; + state_changed[i].in[1] <== states[i+1][2]; lt[0][i] = LessEqThan(8); - lt[0][i].in[0] <== 0; + lt[0][i].in[0] <== 194; lt[0][i].in[1] <== in[i]; lt[1][i] = LessEqThan(8); lt[1][i].in[0] <== in[i]; - lt[1][i].in[1] <== 45; - and[0][i] = AND(); - and[0][i].a <== lt[0][i].out; - and[0][i].b <== lt[1][i].out; + lt[1][i].in[1] <== 223; + and[2][i] = AND(); + and[2][i].a <== lt[0][i].out; + and[2][i].b <== lt[1][i].out; + and[3][i] = AND(); + and[3][i].a <== states[i][2]; + and[3][i].b <== and[2][i].out; lt[2][i] = LessEqThan(8); - lt[2][i].in[0] <== 47; + lt[2][i].in[0] <== 160; lt[2][i].in[1] <== in[i]; lt[3][i] = LessEqThan(8); lt[3][i].in[0] <== in[i]; - lt[3][i].in[1] <== 96; - and[1][i] = AND(); - and[1][i].a <== lt[2][i].out; - and[1][i].b <== lt[3][i].out; + lt[3][i].in[1] <== 191; + and[4][i] = AND(); + and[4][i].a <== lt[2][i].out; + and[4][i].b <== lt[3][i].out; + and[5][i] = AND(); + and[5][i].a <== states[i][4]; + and[5][i].b <== and[4][i].out; lt[4][i] = LessEqThan(8); - lt[4][i].in[0] <== 123; + 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] <== 254; - and[2][i] = AND(); - and[2][i].a <== lt[4][i].out; - and[2][i].b <== lt[5][i].out; - and[3][i] = AND(); - and[3][i].a <== states[i][1]; - multi_or[0][i] = MultiOR(3); - multi_or[0][i].in[0] <== and[0][i].out; - multi_or[0][i].in[1] <== and[1][i].out; - multi_or[0][i].in[2] <== and[2][i].out; - and[3][i].b <== multi_or[0][i].out; - and[4][i] = AND(); - and[4][i].a <== states[i][3]; - and[4][i].b <== multi_or[0][i].out; - multi_or[1][i] = MultiOR(2); - multi_or[1][i].in[0] <== and[3][i].out; - multi_or[1][i].in[1] <== and[4][i].out; - states[i+1][1] <== multi_or[1][i].out; - state_changed[i].in[0] <== states[i+1][1]; - eq[0][i] = IsEqual(); - eq[0][i].in[0] <== in[i]; - eq[0][i].in[1] <== 97; - and[5][i] = AND(); - and[5][i].a <== states[i][0]; - and[5][i].b <== eq[0][i].out; - states[i+1][2] <== and[5][i].out; - state_changed[i].in[1] <== states[i+1][2]; - eq[1][i] = IsEqual(); - eq[1][i].in[0] <== in[i]; - eq[1][i].in[1] <== 58; + lt[5][i].in[1] <== 191; and[6][i] = AND(); - and[6][i].a <== states[i][2]; - and[6][i].b <== eq[1][i].out; - states[i+1][3] <== and[6][i].out; + and[6][i].a <== lt[4][i].out; + and[6][i].b <== lt[5][i].out; + and[7][i] = AND(); + and[7][i].a <== states[i][5]; + and[7][i].b <== and[6][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] <== 159; + and[8][i] = AND(); + and[8][i].a <== lt[6][i].out; + and[8][i].b <== lt[7][i].out; + and[9][i] = AND(); + and[9][i].a <== states[i][6]; + and[9][i].b <== and[8][i].out; + and[10][i] = AND(); + and[10][i].a <== states[i][10]; + and[10][i].b <== and[2][i].out; + multi_or[0][i] = MultiOR(5); + multi_or[0][i].in[0] <== and[3][i].out; + multi_or[0][i].in[1] <== and[5][i].out; + multi_or[0][i].in[2] <== and[7][i].out; + multi_or[0][i].in[3] <== and[9][i].out; + multi_or[0][i].in[4] <== and[10][i].out; + states[i+1][3] <== multi_or[0][i].out; state_changed[i].in[2] <== states[i+1][3]; eq[2][i] = IsEqual(); eq[2][i].in[0] <== in[i]; - eq[2][i].in[1] <== 46; - and[7][i] = AND(); - and[7][i].a <== states[i][1]; - and[7][i].b <== eq[2][i].out; - states[i+1][4] <== and[7][i].out; + eq[2][i].in[1] <== 224; + and[11][i] = AND(); + and[11][i].a <== states[i][2]; + and[11][i].b <== eq[2][i].out; + and[12][i] = AND(); + and[12][i].a <== states[i][10]; + and[12][i].b <== eq[2][i].out; + multi_or[1][i] = MultiOR(2); + multi_or[1][i].in[0] <== and[11][i].out; + multi_or[1][i].in[1] <== and[12][i].out; + states[i+1][4] <== multi_or[1][i].out; state_changed[i].in[3] <== states[i+1][4]; + 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[13][i] = AND(); + and[13][i].a <== states[i][2]; + multi_or[2][i] = MultiOR(14); + multi_or[2][i].in[0] <== eq[3][i].out; + multi_or[2][i].in[1] <== eq[4][i].out; + multi_or[2][i].in[2] <== eq[5][i].out; + multi_or[2][i].in[3] <== eq[6][i].out; + multi_or[2][i].in[4] <== eq[7][i].out; + multi_or[2][i].in[5] <== eq[8][i].out; + multi_or[2][i].in[6] <== eq[9][i].out; + multi_or[2][i].in[7] <== eq[10][i].out; + multi_or[2][i].in[8] <== eq[11][i].out; + multi_or[2][i].in[9] <== eq[12][i].out; + multi_or[2][i].in[10] <== eq[13][i].out; + multi_or[2][i].in[11] <== eq[14][i].out; + multi_or[2][i].in[12] <== eq[15][i].out; + multi_or[2][i].in[13] <== eq[16][i].out; + and[13][i].b <== multi_or[2][i].out; + lt[8][i] = LessEqThan(8); + lt[8][i].in[0] <== 144; + 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[14][i] = AND(); + and[14][i].a <== lt[8][i].out; + and[14][i].b <== lt[9][i].out; + and[15][i] = AND(); + and[15][i].a <== states[i][7]; + and[15][i].b <== and[14][i].out; + and[16][i] = AND(); + and[16][i].a <== states[i][8]; + and[16][i].b <== and[6][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[17][i] = AND(); + and[17][i].a <== states[i][9]; + multi_or[3][i] = MultiOR(16); + multi_or[3][i].in[0] <== eq[17][i].out; + multi_or[3][i].in[1] <== eq[18][i].out; + multi_or[3][i].in[2] <== eq[19][i].out; + multi_or[3][i].in[3] <== eq[20][i].out; + multi_or[3][i].in[4] <== eq[21][i].out; + multi_or[3][i].in[5] <== eq[22][i].out; + multi_or[3][i].in[6] <== eq[23][i].out; + multi_or[3][i].in[7] <== eq[24][i].out; + multi_or[3][i].in[8] <== eq[25][i].out; + multi_or[3][i].in[9] <== eq[26][i].out; + multi_or[3][i].in[10] <== eq[27][i].out; + multi_or[3][i].in[11] <== eq[28][i].out; + multi_or[3][i].in[12] <== eq[29][i].out; + multi_or[3][i].in[13] <== eq[30][i].out; + multi_or[3][i].in[14] <== eq[31][i].out; + multi_or[3][i].in[15] <== eq[32][i].out; + and[17][i].b <== multi_or[3][i].out; + and[18][i] = AND(); + and[18][i].a <== states[i][10]; + and[18][i].b <== multi_or[2][i].out; + multi_or[4][i] = MultiOR(5); + multi_or[4][i].in[0] <== and[13][i].out; + multi_or[4][i].in[1] <== and[15][i].out; + multi_or[4][i].in[2] <== and[16][i].out; + multi_or[4][i].in[3] <== and[17][i].out; + multi_or[4][i].in[4] <== and[18][i].out; + states[i+1][5] <== multi_or[4][i].out; + state_changed[i].in[4] <== states[i+1][5]; + eq[33][i] = IsEqual(); + eq[33][i].in[0] <== in[i]; + eq[33][i].in[1] <== 237; + and[19][i] = AND(); + and[19][i].a <== states[i][2]; + and[19][i].b <== eq[33][i].out; + and[20][i] = AND(); + and[20][i].a <== states[i][10]; + and[20][i].b <== eq[33][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[i+1][6] <== multi_or[5][i].out; + state_changed[i].in[5] <== states[i+1][6]; + eq[34][i] = IsEqual(); + eq[34][i].in[0] <== in[i]; + eq[34][i].in[1] <== 240; + and[21][i] = AND(); + and[21][i].a <== states[i][2]; + and[21][i].b <== eq[34][i].out; + and[22][i] = AND(); + and[22][i].a <== states[i][10]; + and[22][i].b <== eq[34][i].out; + multi_or[6][i] = MultiOR(2); + multi_or[6][i].in[0] <== and[21][i].out; + multi_or[6][i].in[1] <== and[22][i].out; + states[i+1][7] <== multi_or[6][i].out; + state_changed[i].in[6] <== states[i+1][7]; + 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[23][i] = AND(); + and[23][i].a <== states[i][2]; + multi_or[7][i] = MultiOR(3); + 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; + and[23][i].b <== multi_or[7][i].out; + and[24][i] = AND(); + and[24][i].a <== states[i][10]; + and[24][i].b <== multi_or[7][i].out; + multi_or[8][i] = MultiOR(2); + multi_or[8][i].in[0] <== and[23][i].out; + multi_or[8][i].in[1] <== and[24][i].out; + states[i+1][8] <== multi_or[8][i].out; + state_changed[i].in[7] <== states[i+1][8]; + eq[38][i] = IsEqual(); + eq[38][i].in[0] <== in[i]; + eq[38][i].in[1] <== 244; + and[25][i] = AND(); + and[25][i].a <== states[i][2]; + and[25][i].b <== eq[38][i].out; + and[26][i] = AND(); + and[26][i].a <== states[i][10]; + and[26][i].b <== eq[38][i].out; + multi_or[9][i] = MultiOR(2); + multi_or[9][i].in[0] <== and[25][i].out; + multi_or[9][i].in[1] <== and[26][i].out; + states[i+1][9] <== multi_or[9][i].out; + state_changed[i].in[8] <== states[i+1][9]; + lt[10][i] = LessEqThan(8); + lt[10][i].in[0] <== 0; + lt[10][i].in[1] <== in[i]; + lt[11][i] = LessEqThan(8); + lt[11][i].in[0] <== in[i]; + lt[11][i].in[1] <== 45; + and[27][i] = AND(); + and[27][i].a <== lt[10][i].out; + and[27][i].b <== lt[11][i].out; + lt[12][i] = LessEqThan(8); + lt[12][i].in[0] <== 47; + lt[12][i].in[1] <== in[i]; + lt[13][i] = LessEqThan(8); + lt[13][i].in[0] <== in[i]; + lt[13][i].in[1] <== 96; + and[28][i] = AND(); + and[28][i].a <== lt[12][i].out; + and[28][i].b <== lt[13][i].out; + eq[39][i] = IsEqual(); + eq[39][i].in[0] <== in[i]; + eq[39][i].in[1] <== 123; + eq[40][i] = IsEqual(); + eq[40][i].in[0] <== in[i]; + eq[40][i].in[1] <== 124; + eq[41][i] = IsEqual(); + eq[41][i].in[0] <== in[i]; + eq[41][i].in[1] <== 125; + eq[42][i] = IsEqual(); + eq[42][i].in[0] <== in[i]; + eq[42][i].in[1] <== 126; + eq[43][i] = IsEqual(); + eq[43][i].in[0] <== in[i]; + eq[43][i].in[1] <== 127; + and[29][i] = AND(); + and[29][i].a <== states[i][2]; + multi_or[10][i] = MultiOR(7); + multi_or[10][i].in[0] <== and[27][i].out; + multi_or[10][i].in[1] <== and[28][i].out; + multi_or[10][i].in[2] <== eq[39][i].out; + multi_or[10][i].in[3] <== eq[40][i].out; + multi_or[10][i].in[4] <== eq[41][i].out; + multi_or[10][i].in[5] <== eq[42][i].out; + multi_or[10][i].in[6] <== eq[43][i].out; + and[29][i].b <== multi_or[10][i].out; + and[30][i] = AND(); + and[30][i].a <== states[i][3]; + and[30][i].b <== and[6][i].out; + and[31][i] = AND(); + and[31][i].a <== states[i][10]; + and[31][i].b <== multi_or[10][i].out; + multi_or[11][i] = MultiOR(3); + multi_or[11][i].in[0] <== and[29][i].out; + multi_or[11][i].in[1] <== and[30][i].out; + multi_or[11][i].in[2] <== and[31][i].out; + states[i+1][10] <== multi_or[11][i].out; + state_changed[i].in[9] <== states[i+1][10]; + eq[44][i] = IsEqual(); + eq[44][i].in[0] <== in[i]; + eq[44][i].in[1] <== 46; + and[32][i] = AND(); + and[32][i].a <== states[i][10]; + and[32][i].b <== eq[44][i].out; + states[i+1][11] <== and[32][i].out; + state_changed[i].in[10] <== states[i+1][11]; states[i+1][0] <== 1 - state_changed[i].out; } component final_state_result = MultiOR(num_bytes+1); for (var i = 0; i <= num_bytes; i++) { - final_state_result.in[i] <== states[i][4]; + final_state_result.in[i] <== states[i][11]; } out <== final_state_result.out; - signal is_consecutive[msg_bytes+1][2]; is_consecutive[msg_bytes][1] <== 1; for (var i = 0; i < msg_bytes; i++) { - is_consecutive[msg_bytes-1-i][0] <== states[num_bytes-i][4] * (1 - is_consecutive[msg_bytes-i][1]) + is_consecutive[msg_bytes-i][1]; + is_consecutive[msg_bytes-1-i][0] <== states[num_bytes-i][11] * (1 - is_consecutive[msg_bytes-i][1]) + is_consecutive[msg_bytes-i][1]; is_consecutive[msg_bytes-1-i][1] <== state_changed[msg_bytes-i].out * is_consecutive[msg_bytes-1-i][0]; } - signal is_substr0[msg_bytes][3]; + // substrings calculated: [{(2, 3), (2, 4), (2, 5), (2, 6), (2, 7), (2, 8), (2, 9), (2, 10), (3, 10), (4, 3), (5, 3), (6, 3), (7, 5), (8, 5), (9, 5), (10, 3), (10, 4), (10, 5), (10, 6), (10, 7), (10, 8), (10, 9), (10, 10)}] + signal is_substr0[msg_bytes][24]; signal is_reveal0[msg_bytes]; signal output reveal0[msg_bytes]; for (var i = 0; i < msg_bytes; i++) { is_substr0[i][0] <== 0; - // the 0-th substring transitions: [(1, 1), (3, 1)] - is_substr0[i][1] <== is_substr0[i][0] + states[i+1][1] * states[i+2][1]; - is_substr0[i][2] <== is_substr0[i][1] + states[i+1][3] * states[i+2][1]; - is_reveal0[i] <== is_substr0[i][2] * is_consecutive[i][1]; + // the 0-th substring transitions: [(2, 3), (2, 4), (2, 5), (2, 6), (2, 7), (2, 8), (2, 9), (2, 10), (3, 10), (4, 3), (5, 3), (6, 3), (7, 5), (8, 5), (9, 5), (10, 3), (10, 4), (10, 5), (10, 6), (10, 7), (10, 8), (10, 9), (10, 10)] + is_substr0[i][1] <== is_substr0[i][0] + states[i+1][2] * states[i+2][3]; + is_substr0[i][2] <== is_substr0[i][1] + states[i+1][2] * states[i+2][4]; + is_substr0[i][3] <== is_substr0[i][2] + states[i+1][2] * states[i+2][5]; + is_substr0[i][4] <== is_substr0[i][3] + states[i+1][2] * states[i+2][6]; + is_substr0[i][5] <== is_substr0[i][4] + states[i+1][2] * states[i+2][7]; + is_substr0[i][6] <== is_substr0[i][5] + states[i+1][2] * states[i+2][8]; + is_substr0[i][7] <== is_substr0[i][6] + states[i+1][2] * states[i+2][9]; + is_substr0[i][8] <== is_substr0[i][7] + states[i+1][2] * states[i+2][10]; + is_substr0[i][9] <== is_substr0[i][8] + states[i+1][3] * states[i+2][10]; + is_substr0[i][10] <== is_substr0[i][9] + states[i+1][4] * states[i+2][3]; + is_substr0[i][11] <== is_substr0[i][10] + states[i+1][5] * states[i+2][3]; + is_substr0[i][12] <== is_substr0[i][11] + states[i+1][6] * states[i+2][3]; + is_substr0[i][13] <== is_substr0[i][12] + states[i+1][7] * states[i+2][5]; + is_substr0[i][14] <== is_substr0[i][13] + states[i+1][8] * states[i+2][5]; + is_substr0[i][15] <== is_substr0[i][14] + states[i+1][9] * states[i+2][5]; + is_substr0[i][16] <== is_substr0[i][15] + states[i+1][10] * states[i+2][3]; + is_substr0[i][17] <== is_substr0[i][16] + states[i+1][10] * states[i+2][4]; + is_substr0[i][18] <== is_substr0[i][17] + states[i+1][10] * states[i+2][5]; + is_substr0[i][19] <== is_substr0[i][18] + states[i+1][10] * states[i+2][6]; + is_substr0[i][20] <== is_substr0[i][19] + states[i+1][10] * states[i+2][7]; + is_substr0[i][21] <== is_substr0[i][20] + states[i+1][10] * states[i+2][8]; + is_substr0[i][22] <== is_substr0[i][21] + states[i+1][10] * states[i+2][9]; + is_substr0[i][23] <== is_substr0[i][22] + states[i+1][10] * states[i+2][10]; + is_reveal0[i] <== is_substr0[i][23] * is_consecutive[i][1]; reveal0[i] <== in[i+1] * is_reveal0[i]; } } \ No newline at end of file diff --git a/packages/circom/tests/circuits/simple_regex.circom b/packages/circom/tests/circuits/simple_regex.circom index a862e51..24fef27 100644 --- a/packages/circom/tests/circuits/simple_regex.circom +++ b/packages/circom/tests/circuits/simple_regex.circom @@ -122,13 +122,13 @@ template SimpleRegex(msg_bytes) { final_state_result.in[i] <== states[i][9]; } out <== final_state_result.out; - signal is_consecutive[msg_bytes+1][2]; is_consecutive[msg_bytes][1] <== 1; for (var i = 0; i < msg_bytes; i++) { is_consecutive[msg_bytes-1-i][0] <== states[num_bytes-i][9] * (1 - is_consecutive[msg_bytes-i][1]) + is_consecutive[msg_bytes-i][1]; is_consecutive[msg_bytes-1-i][1] <== state_changed[msg_bytes-i].out * is_consecutive[msg_bytes-1-i][0]; } + // substrings calculated: [{(2, 3)}, {(6, 7), (7, 7)}, {(8, 9)}] signal is_substr0[msg_bytes][2]; signal is_reveal0[msg_bytes]; signal output reveal0[msg_bytes]; diff --git a/packages/circom/tests/circuits/simple_regex_decomposed.circom b/packages/circom/tests/circuits/simple_regex_decomposed.circom index 4eef307..65cba6d 100644 --- a/packages/circom/tests/circuits/simple_regex_decomposed.circom +++ b/packages/circom/tests/circuits/simple_regex_decomposed.circom @@ -2,7 +2,7 @@ pragma circom 2.1.5; include "@zk-email/zk-regex-circom/circuits/regex_helpers.circom"; -// regex: email was meant for @(a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z|A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z|0|1|2|3|4|5|6|7|8|9|_)+. +// regex: email was meant for @[a-zA-Z0-9_]+\. template SimpleRegexDecomposed(msg_bytes) { signal input msg[msg_bytes]; signal output out; @@ -28,232 +28,232 @@ template SimpleRegexDecomposed(msg_bytes) { for (var i = 0; i < num_bytes; i++) { state_changed[i] = MultiOR(23); - 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[0][i] = AND(); - and[0][i].a <== lt[0][i].out; - and[0][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[1][i] = AND(); - and[1][i].a <== lt[2][i].out; - and[1][i].b <== lt[3][i].out; eq[0][i] = IsEqual(); eq[0][i].in[0] <== in[i]; - eq[0][i].in[1] <== 48; + eq[0][i].in[1] <== 101; + and[0][i] = AND(); + and[0][i].a <== states[i][0]; + and[0][i].b <== eq[0][i].out; + states[i+1][1] <== and[0][i].out; + state_changed[i].in[0] <== states[i+1][1]; eq[1][i] = IsEqual(); eq[1][i].in[0] <== in[i]; - eq[1][i].in[1] <== 49; + eq[1][i].in[1] <== 109; + and[1][i] = AND(); + and[1][i].a <== states[i][1]; + and[1][i].b <== eq[1][i].out; + states[i+1][2] <== and[1][i].out; + state_changed[i].in[1] <== states[i+1][2]; eq[2][i] = IsEqual(); eq[2][i].in[0] <== in[i]; - eq[2][i].in[1] <== 50; + eq[2][i].in[1] <== 97; + and[2][i] = AND(); + and[2][i].a <== states[i][2]; + and[2][i].b <== eq[2][i].out; + states[i+1][3] <== and[2][i].out; + state_changed[i].in[2] <== states[i+1][3]; eq[3][i] = IsEqual(); eq[3][i].in[0] <== in[i]; - eq[3][i].in[1] <== 51; + eq[3][i].in[1] <== 105; + and[3][i] = AND(); + and[3][i].a <== states[i][3]; + and[3][i].b <== eq[3][i].out; + states[i+1][4] <== and[3][i].out; + state_changed[i].in[3] <== states[i+1][4]; eq[4][i] = IsEqual(); eq[4][i].in[0] <== in[i]; - eq[4][i].in[1] <== 52; + eq[4][i].in[1] <== 108; + and[4][i] = AND(); + and[4][i].a <== states[i][4]; + and[4][i].b <== eq[4][i].out; + states[i+1][5] <== and[4][i].out; + state_changed[i].in[4] <== states[i+1][5]; eq[5][i] = IsEqual(); eq[5][i].in[0] <== in[i]; - eq[5][i].in[1] <== 53; + eq[5][i].in[1] <== 32; + and[5][i] = AND(); + and[5][i].a <== states[i][5]; + and[5][i].b <== eq[5][i].out; + states[i+1][6] <== and[5][i].out; + state_changed[i].in[5] <== states[i+1][6]; eq[6][i] = IsEqual(); eq[6][i].in[0] <== in[i]; - eq[6][i].in[1] <== 54; + eq[6][i].in[1] <== 119; + and[6][i] = AND(); + and[6][i].a <== states[i][6]; + and[6][i].b <== eq[6][i].out; + states[i+1][7] <== and[6][i].out; + state_changed[i].in[6] <== states[i+1][7]; + and[7][i] = AND(); + and[7][i].a <== states[i][7]; + and[7][i].b <== eq[2][i].out; + states[i+1][8] <== and[7][i].out; + state_changed[i].in[7] <== states[i+1][8]; eq[7][i] = IsEqual(); eq[7][i].in[0] <== in[i]; - eq[7][i].in[1] <== 55; + eq[7][i].in[1] <== 115; + and[8][i] = AND(); + and[8][i].a <== states[i][8]; + and[8][i].b <== eq[7][i].out; + states[i+1][9] <== and[8][i].out; + state_changed[i].in[8] <== states[i+1][9]; + and[9][i] = AND(); + and[9][i].a <== states[i][9]; + and[9][i].b <== eq[5][i].out; + states[i+1][10] <== and[9][i].out; + state_changed[i].in[9] <== states[i+1][10]; + and[10][i] = AND(); + and[10][i].a <== states[i][10]; + and[10][i].b <== eq[1][i].out; + states[i+1][11] <== and[10][i].out; + state_changed[i].in[10] <== states[i+1][11]; + and[11][i] = AND(); + and[11][i].a <== states[i][11]; + and[11][i].b <== eq[0][i].out; + states[i+1][12] <== and[11][i].out; + state_changed[i].in[11] <== states[i+1][12]; + and[12][i] = AND(); + and[12][i].a <== states[i][12]; + and[12][i].b <== eq[2][i].out; + states[i+1][13] <== and[12][i].out; + state_changed[i].in[12] <== states[i+1][13]; eq[8][i] = IsEqual(); eq[8][i].in[0] <== in[i]; - eq[8][i].in[1] <== 56; + eq[8][i].in[1] <== 110; + and[13][i] = AND(); + and[13][i].a <== states[i][13]; + and[13][i].b <== eq[8][i].out; + states[i+1][14] <== and[13][i].out; + state_changed[i].in[13] <== states[i+1][14]; eq[9][i] = IsEqual(); eq[9][i].in[0] <== in[i]; - eq[9][i].in[1] <== 57; + eq[9][i].in[1] <== 116; + and[14][i] = AND(); + and[14][i].a <== states[i][14]; + and[14][i].b <== eq[9][i].out; + states[i+1][15] <== and[14][i].out; + state_changed[i].in[14] <== states[i+1][15]; + and[15][i] = AND(); + and[15][i].a <== states[i][15]; + and[15][i].b <== eq[5][i].out; + states[i+1][16] <== and[15][i].out; + state_changed[i].in[15] <== states[i+1][16]; eq[10][i] = IsEqual(); eq[10][i].in[0] <== in[i]; - eq[10][i].in[1] <== 95; - and[2][i] = AND(); - and[2][i].a <== states[i][1]; - multi_or[0][i] = MultiOR(13); - multi_or[0][i].in[0] <== and[0][i].out; - multi_or[0][i].in[1] <== and[1][i].out; - multi_or[0][i].in[2] <== eq[0][i].out; - multi_or[0][i].in[3] <== eq[1][i].out; - multi_or[0][i].in[4] <== eq[2][i].out; - multi_or[0][i].in[5] <== eq[3][i].out; - multi_or[0][i].in[6] <== eq[4][i].out; - multi_or[0][i].in[7] <== eq[5][i].out; - multi_or[0][i].in[8] <== eq[6][i].out; - multi_or[0][i].in[9] <== eq[7][i].out; - multi_or[0][i].in[10] <== eq[8][i].out; - multi_or[0][i].in[11] <== eq[9][i].out; - multi_or[0][i].in[12] <== eq[10][i].out; - and[2][i].b <== multi_or[0][i].out; - and[3][i] = AND(); - and[3][i].a <== states[i][23]; - and[3][i].b <== multi_or[0][i].out; - multi_or[1][i] = MultiOR(2); - multi_or[1][i].in[0] <== and[2][i].out; - multi_or[1][i].in[1] <== and[3][i].out; - states[i+1][1] <== multi_or[1][i].out; - state_changed[i].in[0] <== states[i+1][1]; + eq[10][i].in[1] <== 102; + and[16][i] = AND(); + and[16][i].a <== states[i][16]; + and[16][i].b <== eq[10][i].out; + states[i+1][17] <== and[16][i].out; + state_changed[i].in[16] <== states[i+1][17]; eq[11][i] = IsEqual(); eq[11][i].in[0] <== in[i]; - eq[11][i].in[1] <== 101; - and[4][i] = AND(); - and[4][i].a <== states[i][0]; - and[4][i].b <== eq[11][i].out; - states[i+1][2] <== and[4][i].out; - state_changed[i].in[1] <== states[i+1][2]; + eq[11][i].in[1] <== 111; + and[17][i] = AND(); + and[17][i].a <== states[i][17]; + and[17][i].b <== eq[11][i].out; + states[i+1][18] <== and[17][i].out; + state_changed[i].in[17] <== states[i+1][18]; eq[12][i] = IsEqual(); eq[12][i].in[0] <== in[i]; - eq[12][i].in[1] <== 109; - and[5][i] = AND(); - and[5][i].a <== states[i][2]; - and[5][i].b <== eq[12][i].out; - states[i+1][3] <== and[5][i].out; - state_changed[i].in[2] <== states[i+1][3]; + eq[12][i].in[1] <== 114; + and[18][i] = AND(); + and[18][i].a <== states[i][18]; + and[18][i].b <== eq[12][i].out; + states[i+1][19] <== and[18][i].out; + state_changed[i].in[18] <== states[i+1][19]; + and[19][i] = AND(); + and[19][i].a <== states[i][19]; + and[19][i].b <== eq[5][i].out; + states[i+1][20] <== and[19][i].out; + state_changed[i].in[19] <== states[i+1][20]; eq[13][i] = IsEqual(); eq[13][i].in[0] <== in[i]; - eq[13][i].in[1] <== 46; - and[6][i] = AND(); - and[6][i].a <== states[i][1]; - and[6][i].b <== eq[13][i].out; - states[i+1][4] <== and[6][i].out; - state_changed[i].in[3] <== states[i+1][4]; + eq[13][i].in[1] <== 64; + and[20][i] = AND(); + and[20][i].a <== states[i][20]; + and[20][i].b <== eq[13][i].out; + states[i+1][21] <== and[20][i].out; + state_changed[i].in[20] <== states[i+1][21]; + 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[21][i] = AND(); + and[21][i].a <== lt[0][i].out; + and[21][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[22][i] = AND(); + and[22][i].a <== lt[2][i].out; + and[22][i].b <== lt[3][i].out; eq[14][i] = IsEqual(); eq[14][i].in[0] <== in[i]; - eq[14][i].in[1] <== 97; - and[7][i] = AND(); - and[7][i].a <== states[i][3]; - and[7][i].b <== eq[14][i].out; - states[i+1][5] <== and[7][i].out; - state_changed[i].in[4] <== states[i+1][5]; + eq[14][i].in[1] <== 48; eq[15][i] = IsEqual(); eq[15][i].in[0] <== in[i]; - eq[15][i].in[1] <== 105; - and[8][i] = AND(); - and[8][i].a <== states[i][5]; - and[8][i].b <== eq[15][i].out; - states[i+1][6] <== and[8][i].out; - state_changed[i].in[5] <== states[i+1][6]; + eq[15][i].in[1] <== 49; eq[16][i] = IsEqual(); eq[16][i].in[0] <== in[i]; - eq[16][i].in[1] <== 108; - and[9][i] = AND(); - and[9][i].a <== states[i][6]; - and[9][i].b <== eq[16][i].out; - states[i+1][7] <== and[9][i].out; - state_changed[i].in[6] <== states[i+1][7]; + eq[16][i].in[1] <== 50; eq[17][i] = IsEqual(); eq[17][i].in[0] <== in[i]; - eq[17][i].in[1] <== 32; - and[10][i] = AND(); - and[10][i].a <== states[i][7]; - and[10][i].b <== eq[17][i].out; - states[i+1][8] <== and[10][i].out; - state_changed[i].in[7] <== states[i+1][8]; + eq[17][i].in[1] <== 51; eq[18][i] = IsEqual(); eq[18][i].in[0] <== in[i]; - eq[18][i].in[1] <== 119; - and[11][i] = AND(); - and[11][i].a <== states[i][8]; - and[11][i].b <== eq[18][i].out; - states[i+1][9] <== and[11][i].out; - state_changed[i].in[8] <== states[i+1][9]; - and[12][i] = AND(); - and[12][i].a <== states[i][9]; - and[12][i].b <== eq[14][i].out; - states[i+1][10] <== and[12][i].out; - state_changed[i].in[9] <== states[i+1][10]; + eq[18][i].in[1] <== 52; eq[19][i] = IsEqual(); eq[19][i].in[0] <== in[i]; - eq[19][i].in[1] <== 115; - and[13][i] = AND(); - and[13][i].a <== states[i][10]; - and[13][i].b <== eq[19][i].out; - states[i+1][11] <== and[13][i].out; - state_changed[i].in[10] <== states[i+1][11]; - and[14][i] = AND(); - and[14][i].a <== states[i][11]; - and[14][i].b <== eq[17][i].out; - states[i+1][12] <== and[14][i].out; - state_changed[i].in[11] <== states[i+1][12]; - and[15][i] = AND(); - and[15][i].a <== states[i][12]; - and[15][i].b <== eq[12][i].out; - states[i+1][13] <== and[15][i].out; - state_changed[i].in[12] <== states[i+1][13]; - and[16][i] = AND(); - and[16][i].a <== states[i][13]; - and[16][i].b <== eq[11][i].out; - states[i+1][14] <== and[16][i].out; - state_changed[i].in[13] <== states[i+1][14]; - and[17][i] = AND(); - and[17][i].a <== states[i][14]; - and[17][i].b <== eq[14][i].out; - states[i+1][15] <== and[17][i].out; - state_changed[i].in[14] <== states[i+1][15]; + eq[19][i].in[1] <== 53; eq[20][i] = IsEqual(); eq[20][i].in[0] <== in[i]; - eq[20][i].in[1] <== 110; - and[18][i] = AND(); - and[18][i].a <== states[i][15]; - and[18][i].b <== eq[20][i].out; - states[i+1][16] <== and[18][i].out; - state_changed[i].in[15] <== states[i+1][16]; + eq[20][i].in[1] <== 54; eq[21][i] = IsEqual(); eq[21][i].in[0] <== in[i]; - eq[21][i].in[1] <== 116; - and[19][i] = AND(); - and[19][i].a <== states[i][16]; - and[19][i].b <== eq[21][i].out; - states[i+1][17] <== and[19][i].out; - state_changed[i].in[16] <== states[i+1][17]; - and[20][i] = AND(); - and[20][i].a <== states[i][17]; - and[20][i].b <== eq[17][i].out; - states[i+1][18] <== and[20][i].out; - state_changed[i].in[17] <== states[i+1][18]; + eq[21][i].in[1] <== 55; eq[22][i] = IsEqual(); eq[22][i].in[0] <== in[i]; - eq[22][i].in[1] <== 102; - and[21][i] = AND(); - and[21][i].a <== states[i][18]; - and[21][i].b <== eq[22][i].out; - states[i+1][19] <== and[21][i].out; - state_changed[i].in[18] <== states[i+1][19]; + eq[22][i].in[1] <== 56; eq[23][i] = IsEqual(); eq[23][i].in[0] <== in[i]; - eq[23][i].in[1] <== 111; - and[22][i] = AND(); - and[22][i].a <== states[i][19]; - and[22][i].b <== eq[23][i].out; - states[i+1][20] <== and[22][i].out; - state_changed[i].in[19] <== states[i+1][20]; + eq[23][i].in[1] <== 57; eq[24][i] = IsEqual(); eq[24][i].in[0] <== in[i]; - eq[24][i].in[1] <== 114; + eq[24][i].in[1] <== 95; and[23][i] = AND(); - and[23][i].a <== states[i][20]; - and[23][i].b <== eq[24][i].out; - states[i+1][21] <== and[23][i].out; - state_changed[i].in[20] <== states[i+1][21]; + and[23][i].a <== states[i][21]; + multi_or[0][i] = MultiOR(13); + multi_or[0][i].in[0] <== and[21][i].out; + multi_or[0][i].in[1] <== and[22][i].out; + multi_or[0][i].in[2] <== eq[14][i].out; + multi_or[0][i].in[3] <== eq[15][i].out; + multi_or[0][i].in[4] <== eq[16][i].out; + multi_or[0][i].in[5] <== eq[17][i].out; + multi_or[0][i].in[6] <== eq[18][i].out; + multi_or[0][i].in[7] <== eq[19][i].out; + multi_or[0][i].in[8] <== eq[20][i].out; + multi_or[0][i].in[9] <== eq[21][i].out; + multi_or[0][i].in[10] <== eq[22][i].out; + multi_or[0][i].in[11] <== eq[23][i].out; + multi_or[0][i].in[12] <== eq[24][i].out; + and[23][i].b <== multi_or[0][i].out; and[24][i] = AND(); - and[24][i].a <== states[i][21]; - and[24][i].b <== eq[17][i].out; - states[i+1][22] <== and[24][i].out; + and[24][i].a <== states[i][22]; + and[24][i].b <== multi_or[0][i].out; + multi_or[1][i] = MultiOR(2); + multi_or[1][i].in[0] <== and[23][i].out; + multi_or[1][i].in[1] <== and[24][i].out; + states[i+1][22] <== multi_or[1][i].out; state_changed[i].in[21] <== states[i+1][22]; eq[25][i] = IsEqual(); eq[25][i].in[0] <== in[i]; - eq[25][i].in[1] <== 64; + eq[25][i].in[1] <== 46; and[25][i] = AND(); and[25][i].a <== states[i][22]; and[25][i].b <== eq[25][i].out; @@ -264,24 +264,24 @@ template SimpleRegexDecomposed(msg_bytes) { component final_state_result = MultiOR(num_bytes+1); for (var i = 0; i <= num_bytes; i++) { - final_state_result.in[i] <== states[i][4]; + final_state_result.in[i] <== states[i][23]; } out <== final_state_result.out; - signal is_consecutive[msg_bytes+1][2]; is_consecutive[msg_bytes][1] <== 1; for (var i = 0; i < msg_bytes; i++) { - is_consecutive[msg_bytes-1-i][0] <== states[num_bytes-i][4] * (1 - is_consecutive[msg_bytes-i][1]) + is_consecutive[msg_bytes-i][1]; + is_consecutive[msg_bytes-1-i][0] <== states[num_bytes-i][23] * (1 - is_consecutive[msg_bytes-i][1]) + is_consecutive[msg_bytes-i][1]; is_consecutive[msg_bytes-1-i][1] <== state_changed[msg_bytes-i].out * is_consecutive[msg_bytes-1-i][0]; } + // substrings calculated: [{(21, 22), (22, 22)}] signal is_substr0[msg_bytes][3]; signal is_reveal0[msg_bytes]; signal output reveal0[msg_bytes]; for (var i = 0; i < msg_bytes; i++) { is_substr0[i][0] <== 0; - // the 0-th substring transitions: [(1, 1), (23, 1)] - is_substr0[i][1] <== is_substr0[i][0] + states[i+1][1] * states[i+2][1]; - is_substr0[i][2] <== is_substr0[i][1] + states[i+1][23] * states[i+2][1]; + // the 0-th substring transitions: [(21, 22), (22, 22)] + is_substr0[i][1] <== is_substr0[i][0] + states[i+1][21] * states[i+2][22]; + is_substr0[i][2] <== is_substr0[i][1] + states[i+1][22] * states[i+2][22]; is_reveal0[i] <== is_substr0[i][2] * is_consecutive[i][1]; reveal0[i] <== in[i+1] * is_reveal0[i]; } diff --git a/packages/circom/tests/circuits/simple_regex_decomposed.json b/packages/circom/tests/circuits/simple_regex_decomposed.json index 7447ee4..25def2e 100644 --- a/packages/circom/tests/circuits/simple_regex_decomposed.json +++ b/packages/circom/tests/circuits/simple_regex_decomposed.json @@ -1,16 +1,16 @@ { - "parts":[ + "parts": [ { "is_public": false, "regex_def": "email was meant for @" }, { "is_public": true, - "regex_def": "(a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z|A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z|0|1|2|3|4|5|6|7|8|9|_)+" + "regex_def": "[a-zA-Z0-9_]+" }, { "is_public": false, - "regex_def": "." + "regex_def": "\\." } ] -} \ No newline at end of file +} diff --git a/packages/circom/tests/circuits/simple_regex_substrs.json b/packages/circom/tests/circuits/simple_regex_substrs.json index 85274f4..980669b 100644 --- a/packages/circom/tests/circuits/simple_regex_substrs.json +++ b/packages/circom/tests/circuits/simple_regex_substrs.json @@ -1,26 +1,10 @@ { - "transitions": [ - [ - [ - 2, - 3 - ] - ], - [ - [ - 6, - 7 - ], - [ - 7, - 7 - ] - ], - [ - [ - 8, - 9 - ] - ] - ] -} \ No newline at end of file + "transitions": [ + [[2, 3]], + [ + [6, 7], + [7, 7] + ], + [[8, 9]] + ] +} diff --git a/packages/circom/tests/circuits/test_international_chars_decomposed.circom b/packages/circom/tests/circuits/test_international_chars_decomposed.circom new file mode 100644 index 0000000..f20725c --- /dev/null +++ b/packages/circom/tests/circuits/test_international_chars_decomposed.circom @@ -0,0 +1,5 @@ +pragma circom 2.1.5; + +include "./international_chars_decomposed.circom"; +// Latin-Extension=[¡-ƿ]+ Greek=[Ͱ-Ͽ]+ Cyrillic=[Ѐ-ӿ]+ Arabic=[؀-ۿ]+ Devanagari=[ऀ-ॿ]+ Hiragana&Katakana=[ぁ-ヿ]+ +component main = InternationalCharsDecomposed(128); \ No newline at end of file diff --git a/packages/circom/tests/email_addr.test.js b/packages/circom/tests/email_addr.test.js new file mode 100644 index 0000000..fcffe84 --- /dev/null +++ b/packages/circom/tests/email_addr.test.js @@ -0,0 +1,70 @@ +const circom_tester = require("circom_tester"); +const wasm_tester = circom_tester.wasm; +import * as path from "path"; +const apis = require("../../apis"); +const option = { + include: path.join(__dirname, "../../../node_modules"), +}; +const compiler = require("../../compiler"); + +jest.setTimeout(120000); +describe("Email Address Regex", () => { + let circuit; + beforeAll(async () => { + compiler.genFromDecomposed( + path.join(__dirname, "../circuits/common/email_addr.json"), + { + circomFilePath: path.join( + __dirname, + "../circuits/common/email_addr_regex.circom" + ), + templateName: "EmailAddrRegex", + genSubstrs: true, + } + ); + circuit = await wasm_tester( + path.join(__dirname, "./circuits/test_email_addr_regex.circom"), + option + ); + }); + + it("only an email address", async () => { + const emailAddr = "suegamisora@gmail.com"; + const paddedStr = apis.padString(emailAddr, 256); + const circuitInputs = { + msg: paddedStr, + }; + const witness = await circuit.calculateWitness(circuitInputs); + await circuit.checkConstraints(witness); + expect(1n).toEqual(witness[1]); + const prefixIdxes = apis.extractEmailAddrIdxes(emailAddr)[0]; + for (let idx = 0; idx < 256; ++idx) { + if (idx >= prefixIdxes[0] && idx < prefixIdxes[1]) { + expect(BigInt(paddedStr[idx])).toEqual(witness[2 + idx]); + } else { + expect(0n).toEqual(witness[2 + idx]); + } + } + }); + + it("with a prefix", async () => { + const prefix = "subject:"; + const emailAddr = "suegamisora@gmail.com"; + const string = prefix + emailAddr; + const paddedStr = apis.padString(string, 256); + const circuitInputs = { + msg: paddedStr, + }; + const witness = await circuit.calculateWitness(circuitInputs); + await circuit.checkConstraints(witness); + expect(1n).toEqual(witness[1]); + const prefixIdxes = apis.extractEmailAddrIdxes(string)[0]; + for (let idx = 0; idx < 256; ++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/email_addr.test.ts b/packages/circom/tests/email_addr.test.ts deleted file mode 100644 index 7bec5df..0000000 --- a/packages/circom/tests/email_addr.test.ts +++ /dev/null @@ -1,69 +0,0 @@ -const ff = require('ffjavascript'); -const stringifyBigInts = ff.utils.stringifyBigInts; -const circom_tester = require("circom_tester"); -const wasm_tester = circom_tester.wasm; -import * as path from "path"; -const p = "21888242871839275222246405745257275088548364400416034343698204186575808495617"; -const field = new ff.F1Field(p); -const apis = require("../../apis"); -const option = { - include: path.join(__dirname, "../../../node_modules") -}; -import { readFileSync } from "fs"; -const compiler = require("../../compiler"); - -jest.setTimeout(120000); -describe("Email Address Regex", () => { - let circuit; - beforeAll(async () => { - compiler.genFromDecomposed(path.join(__dirname, "../circuits/common/email_addr.json"), { - circomFilePath: path.join(__dirname, "../circuits/common/email_addr_regex.circom"), - templateName: "EmailAddrRegex", - genSubstrs: true - }); - circuit = await wasm_tester(path.join(__dirname, "./circuits/test_email_addr_regex.circom"), option); - }); - - it("only an email address", async () => { - const emailAddr = "suegamisora@gmail.com"; - const paddedStr = apis.padString(emailAddr, 256); - const circuitInputs = { - msg: paddedStr, - }; - // const circuit = await wasm_tester(path.join(__dirname, "./circuits/test_email_addr_regex.circom"), option); - const witness = await circuit.calculateWitness(circuitInputs); - await circuit.checkConstraints(witness); - expect(1n).toEqual(witness[1]); - const prefixIdxes = apis.extractEmailAddrIdxes(emailAddr)[0]; - for (let idx = 0; idx < 256; ++idx) { - if (idx >= prefixIdxes[0] && idx < prefixIdxes[1]) { - expect(BigInt(paddedStr[idx])).toEqual(witness[2 + idx]); - } else { - expect(0n).toEqual(witness[2 + idx]); - } - } - }); - - it("with a prefix", async () => { - const prefix = "subject:"; - const emailAddr = "suegamisora@gmail.com"; - const string = prefix + emailAddr; - // console.log(string); - const paddedStr = apis.padString(string, 256); - const circuitInputs = { - msg: paddedStr, - }; - // const circuit = await wasm_tester(path.join(__dirname, "./circuits/test_email_addr_regex.circom"), option); - const witness = await circuit.calculateWitness(circuitInputs); - await circuit.checkConstraints(witness); - expect(1n).toEqual(witness[1]); - const prefixIdxes = apis.extractEmailAddrIdxes(string)[0]; - for (let idx = 0; idx < 256; ++idx) { - if (idx >= prefixIdxes[0] && idx < prefixIdxes[1]) { - expect(BigInt(paddedStr[idx])).toEqual(witness[2 + idx]); - } else { - expect(0n).toEqual(witness[2 + idx]); - } - } - }); -}); \ No newline at end of file diff --git a/packages/circom/tests/email_domain.test.js b/packages/circom/tests/email_domain.test.js new file mode 100644 index 0000000..812a0c3 --- /dev/null +++ b/packages/circom/tests/email_domain.test.js @@ -0,0 +1,52 @@ +const circom_tester = require("circom_tester"); +const wasm_tester = circom_tester.wasm; +import * as path from "path"; +const apis = require("../../apis"); +const option = { + include: path.join(__dirname, "../../../node_modules"), +}; +const compiler = require("../../compiler"); + +jest.setTimeout(120000); +describe("Email Domain Regex", () => { + let circuit; + beforeAll(async () => { + compiler.genFromDecomposed( + path.join(__dirname, "../circuits/common/email_domain.json"), + { + circomFilePath: path.join( + __dirname, + "../circuits/common/email_domain_regex.circom" + ), + templateName: "EmailDomainRegex", + genSubstrs: true, + } + ); + circuit = await wasm_tester( + path.join(__dirname, "./circuits/test_email_domain_regex.circom"), + option + ); + }); + + it("test a regex of an email domain", async () => { + const emailAddr = "suegamisora@gmail.com"; + const paddedStr = apis.padString(emailAddr, 256); + const circuitInputs = { + msg: paddedStr, + }; + const witness = await circuit.calculateWitness(circuitInputs); + await circuit.checkConstraints(witness); + expect(1n).toEqual(witness[1]); + for (let idx = 0; idx < 12; ++idx) { + expect(0n).toEqual(witness[2 + idx]); + } + const prefixIdxes = apis.extractEmailDomainIdxes(emailAddr)[0]; + for (let idx = 0; idx < 256; ++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/email_domain.test.ts b/packages/circom/tests/email_domain.test.ts deleted file mode 100644 index 9de2d69..0000000 --- a/packages/circom/tests/email_domain.test.ts +++ /dev/null @@ -1,50 +0,0 @@ -const ff = require('ffjavascript'); -const stringifyBigInts = ff.utils.stringifyBigInts; -const circom_tester = require("circom_tester"); -const wasm_tester = circom_tester.wasm; -import * as path from "path"; -const p = "21888242871839275222246405745257275088548364400416034343698204186575808495617"; -const field = new ff.F1Field(p); -const apis = require("../../apis"); -const option = { - include: path.join(__dirname, "../../../node_modules") -}; -import { readFileSync } from "fs"; -const compiler = require("../../compiler"); - -jest.setTimeout(120000); -describe("Email Domain Regex", () => { - let circuit; - beforeAll(async () => { - compiler.genFromDecomposed(path.join(__dirname, "../circuits/common/email_domain.json"), { - circomFilePath: path.join(__dirname, "../circuits/common/email_domain_regex.circom"), - templateName: "EmailDomainRegex", - genSubstrs: true - }); - circuit = await wasm_tester(path.join(__dirname, "./circuits/test_email_domain_regex.circom"), option); - }); - - it("test a regex of an email domain", async () => { - const emailAddr = "suegamisora@gmail.com"; - const paddedStr = apis.padString(emailAddr, 256); - // const revealed = "gmail.com"; - const circuitInputs = { - msg: paddedStr, - }; - // const circuit = await wasm_tester(path.join(__dirname, "./circuits/test_email_domain_regex.circom"), option); - const witness = await circuit.calculateWitness(circuitInputs); - await circuit.checkConstraints(witness); - expect(1n).toEqual(witness[1]); - for (let idx = 0; idx < 12; ++idx) { - expect(0n).toEqual(witness[2 + idx]); - } - const prefixIdxes = apis.extractEmailDomainIdxes(emailAddr)[0]; - for (let idx = 0; idx < 256; ++idx) { - if (idx >= prefixIdxes[0] && idx < prefixIdxes[1]) { - expect(BigInt(paddedStr[idx])).toEqual(witness[2 + idx]); - } else { - expect(0n).toEqual(witness[2 + idx]); - } - } - }); -}); \ No newline at end of file diff --git a/packages/circom/tests/from_addr.test.js b/packages/circom/tests/from_addr.test.js new file mode 100644 index 0000000..f4f240f --- /dev/null +++ b/packages/circom/tests/from_addr.test.js @@ -0,0 +1,205 @@ +const circom_tester = require("circom_tester"); +const wasm_tester = circom_tester.wasm; +import * as path from "path"; +const apis = require("../../apis"); +const option = { + include: path.join(__dirname, "../../../node_modules"), +}; +const compiler = require("../../compiler"); + +jest.setTimeout(600000); +describe("From Addr Regex", () => { + let circuit; + beforeAll(async () => { + compiler.genFromDecomposed( + path.join(__dirname, "../circuits/common/from_all.json"), + { + circomFilePath: path.join( + __dirname, + "../circuits/common/from_all_regex.circom" + ), + templateName: "FromAllRegex", + genSubstrs: true, + } + ); + compiler.genFromDecomposed( + path.join(__dirname, "../circuits/common/email_addr_with_name.json"), + { + circomFilePath: path.join( + __dirname, + "../circuits/common/email_addr_with_name_regex.circom" + ), + templateName: "EmailAddrWithNameRegex", + genSubstrs: true, + } + ); + compiler.genFromDecomposed( + path.join(__dirname, "../circuits/common/email_addr.json"), + { + circomFilePath: path.join( + __dirname, + "../circuits/common/email_addr_regex.circom" + ), + templateName: "EmailAddrRegex", + genSubstrs: true, + } + ); + circuit = await wasm_tester( + path.join(__dirname, "./circuits/test_from_addr_regex.circom"), + option + ); + }); + + it("from field from beginning case 1", async () => { + const fromStr = "from:suegamisora@gmail.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]; + 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 from beginning case 2", async () => { + const fromStr = "from:Sora Suegami \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]; + 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 from beginning case 3 (email address as a name)", async () => { + const fromStr = "from:dummy@example.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]; + 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 from beginning case 4 (non-English string is used as a name)", async () => { + const fromStr = 'from: "末神奏宙" \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]; + 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 after new line case 1", async () => { + const fromStr = "dummy\r\nfrom:suegamisora@gmail.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]; + 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 after new line case 2", async () => { + const fromStr = "dummy\r\nfrom:Sora Suegami \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]; + 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 after new line case 3 (email address as a name)", async () => { + const fromStr = + "dummy\r\nfrom:dummy@example.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]; + 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 after new line case 4 (non-English string is used as a name)", async () => { + const fromStr = 'dummy\r\nfrom: "末神奏宙" \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]; + 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/from_addr.test.ts b/packages/circom/tests/from_addr.test.ts deleted file mode 100644 index 4f3187c..0000000 --- a/packages/circom/tests/from_addr.test.ts +++ /dev/null @@ -1,246 +0,0 @@ -const ff = require('ffjavascript'); -const stringifyBigInts = ff.utils.stringifyBigInts; -const circom_tester = require("circom_tester"); -const wasm_tester = circom_tester.wasm; -import * as path from "path"; -const p = "21888242871839275222246405745257275088548364400416034343698204186575808495617"; -const field = new ff.F1Field(p); -const apis = require("../../apis"); -const option = { - include: path.join(__dirname, "../../../node_modules") -}; -import { readFileSync } from "fs"; -const compiler = require("../../compiler"); - -jest.setTimeout(240000); -describe("From Addr Regex", () => { - let circuit; - beforeAll(async () => { - compiler.genFromDecomposed(path.join(__dirname, "../circuits/common/from_all.json"), { - circomFilePath: path.join(__dirname, "../circuits/common/from_all_regex.circom"), - templateName: "FromAllRegex", - genSubstrs: true - }); - compiler.genFromDecomposed(path.join(__dirname, "../circuits/common/email_addr_with_name.json"), { - circomFilePath: path.join(__dirname, "../circuits/common/email_addr_with_name_regex.circom"), - templateName: "EmailAddrWithNameRegex", - genSubstrs: true - }); - compiler.genFromDecomposed(path.join(__dirname, "../circuits/common/email_addr.json"), { - circomFilePath: path.join(__dirname, "../circuits/common/email_addr_regex.circom"), - templateName: "EmailAddrRegex", - genSubstrs: true - }); - circuit = await wasm_tester(path.join(__dirname, "./circuits/test_from_addr_regex.circom"), option); - }); - - it("from field from beginning case 1", async () => { - const fromStr = "from:suegamisora@gmail.com\r\n"; - // const revealed = "suegamisora@gmail.com"; - const paddedStr = apis.padString(fromStr, 1024); - const circuitInputs = { - msg: paddedStr, - }; - // const circuit = await wasm_tester(path.join(__dirname, "./circuits/test_from_addr_regex.circom"), option); - const witness = await circuit.calculateWitness(circuitInputs); - await circuit.checkConstraints(witness); - expect(1n).toEqual(witness[1]); - const prefixIdxes = apis.extractFromAddrIdxes(fromStr)[0]; - 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 from beginning case 2", async () => { - const fromStr = "from:Sora Suegami \r\n"; - // const revealed = "suegamisora@gmail.com"; - // const prefixLen = "from:Sora Suegami <".length; - const paddedStr = apis.padString(fromStr, 1024); - const circuitInputs = { - msg: paddedStr, - }; - // const circuit = await wasm_tester(path.join(__dirname, "./circuits/test_from_addr_regex.circom"), option); - const witness = await circuit.calculateWitness(circuitInputs); - await circuit.checkConstraints(witness); - // console.log(witness); - // console.log(paddedStr); - expect(1n).toEqual(witness[1]); - const prefixIdxes = apis.extractFromAddrIdxes(fromStr)[0]; - // for (let idx = 0; idx < revealed.length; ++idx) { - // expect(BigInt(paddedStr[prefixIdx + idx])).toEqual(witness[2 + prefixIdx + idx]); - // } - 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 from beginning case 3 (email address as a name)", async () => { - const fromStr = "from:dummy@example.com\r\n"; - // const revealed = "suegamisora@gmail.com"; - // const prefixLen = "from:Sora Suegami <".length; - const paddedStr = apis.padString(fromStr, 1024); - const circuitInputs = { - msg: paddedStr, - }; - // const circuit = await wasm_tester(path.join(__dirname, "./circuits/test_from_addr_regex.circom"), option); - const witness = await circuit.calculateWitness(circuitInputs); - await circuit.checkConstraints(witness); - // console.log(witness); - // console.log(paddedStr); - expect(1n).toEqual(witness[1]); - const prefixIdxes = apis.extractFromAddrIdxes(fromStr)[0]; - // for (let idx = 0; idx < revealed.length; ++idx) { - // expect(BigInt(paddedStr[prefixIdx + idx])).toEqual(witness[2 + prefixIdx + idx]); - // } - 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 from beginning case 4 (non-English string is used as a name)", async () => { - const fromStr = "from: \"末神奏宙\" \r\n"; - // const revealed = "suegamisora@gmail.com"; - // const prefixLen = "from:Sora Suegami <".length; - const paddedStr = apis.padString(fromStr, 1024); - const circuitInputs = { - msg: paddedStr, - }; - // const circuit = await wasm_tester(path.join(__dirname, "./circuits/test_from_addr_regex.circom"), option); - const witness = await circuit.calculateWitness(circuitInputs); - await circuit.checkConstraints(witness); - // console.log(witness); - // console.log(paddedStr); - expect(1n).toEqual(witness[1]); - const prefixIdxes = apis.extractFromAddrIdxes(fromStr)[0]; - // for (let idx = 0; idx < revealed.length; ++idx) { - // expect(BigInt(paddedStr[prefixIdx + idx])).toEqual(witness[2 + prefixIdx + idx]); - // } - 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 after new line case 1", async () => { - const fromStr = "dummy\r\nfrom:suegamisora@gmail.com\r\n"; - const revealed = "suegamisora@gmail.com"; - // const prefixLen = "dummy\r\nfrom:".length; - const paddedStr = apis.padString(fromStr, 1024); - const circuitInputs = { - msg: paddedStr, - }; - // const circuit = await wasm_tester(path.join(__dirname, "./circuits/test_from_addr_regex.circom"), option); - const witness = await circuit.calculateWitness(circuitInputs); - await circuit.checkConstraints(witness); - // console.log(witness); - expect(1n).toEqual(witness[1]); - const prefixIdxes = apis.extractFromAddrIdxes(fromStr)[0]; - // for (let idx = 0; idx < revealed.length; ++idx) { - // expect(BigInt(paddedStr[prefixIdx + idx])).toEqual(witness[2 + prefixIdx + idx]); - // } - 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 after new line case 2", async () => { - const fromStr = "dummy\r\nfrom:Sora Suegami \r\n"; - const revealed = "suegamisora@gmail.com"; - // const prefixLen = "dummy\r\nfrom:Sora Suegami <".length; - const paddedStr = apis.padString(fromStr, 1024); - const circuitInputs = { - msg: paddedStr, - }; - // const circuit = await wasm_tester(path.join(__dirname, "./circuits/test_from_addr_regex.circom"), option); - const witness = await circuit.calculateWitness(circuitInputs); - await circuit.checkConstraints(witness); - // console.log(witness); - expect(1n).toEqual(witness[1]); - const prefixIdxes = apis.extractFromAddrIdxes(fromStr)[0]; - // for (let idx = 0; idx < revealed.length; ++idx) { - // expect(BigInt(paddedStr[prefixIdx + idx])).toEqual(witness[2 + prefixIdx + idx]); - // } - 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 after new line case 3 (email address as a name)", async () => { - const fromStr = "dummy\r\nfrom:dummy@example.com\r\n"; - // const revealed = "suegamisora@gmail.com"; - // const prefixLen = "from:Sora Suegami <".length; - const paddedStr = apis.padString(fromStr, 1024); - const circuitInputs = { - msg: paddedStr, - }; - // const circuit = await wasm_tester(path.join(__dirname, "./circuits/test_from_addr_regex.circom"), option); - const witness = await circuit.calculateWitness(circuitInputs); - await circuit.checkConstraints(witness); - // console.log(witness); - // console.log(paddedStr); - expect(1n).toEqual(witness[1]); - const prefixIdxes = apis.extractFromAddrIdxes(fromStr)[0]; - // for (let idx = 0; idx < revealed.length; ++idx) { - // expect(BigInt(paddedStr[prefixIdx + idx])).toEqual(witness[2 + prefixIdx + idx]); - // } - 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 after new line case 4 (non-English string is used as a name)", async () => { - const fromStr = "dummy\r\nfrom: \"末神奏宙\" \r\n"; - // const revealed = "suegamisora@gmail.com"; - // const prefixLen = "from:Sora Suegami <".length; - const paddedStr = apis.padString(fromStr, 1024); - const circuitInputs = { - msg: paddedStr, - }; - // const circuit = await wasm_tester(path.join(__dirname, "./circuits/test_from_addr_regex.circom"), option); - const witness = await circuit.calculateWitness(circuitInputs); - await circuit.checkConstraints(witness); - // console.log(witness); - // console.log(paddedStr); - expect(1n).toEqual(witness[1]); - const prefixIdxes = apis.extractFromAddrIdxes(fromStr)[0]; - // for (let idx = 0; idx < revealed.length; ++idx) { - // expect(BigInt(paddedStr[prefixIdx + idx])).toEqual(witness[2 + prefixIdx + idx]); - // } - 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]); - } - } - }); - -}); \ No newline at end of file diff --git a/packages/circom/tests/international_chars.test.js b/packages/circom/tests/international_chars.test.js new file mode 100644 index 0000000..f0bb5ba --- /dev/null +++ b/packages/circom/tests/international_chars.test.js @@ -0,0 +1,64 @@ +const circom_tester = require("circom_tester"); +const wasm_tester = circom_tester.wasm; +import * as path from "path"; +const apis = require("../../apis"); +const option = { + include: path.join(__dirname, "../../../node_modules"), +}; +const compiler = require("../../compiler"); + +jest.setTimeout(300000); +describe("Simple Regex Decomposed", () => { + let circuit; + beforeAll(async () => { + compiler.genFromDecomposed( + path.join(__dirname, "./circuits/international_chars_decomposed.json"), + { + circomFilePath: path.join( + __dirname, + "./circuits/international_chars_decomposed.circom" + ), + templateName: "InternationalCharsDecomposed", + genSubstrs: true, + } + ); + circuit = await wasm_tester( + path.join( + __dirname, + "./circuits/test_international_chars_decomposed.circom" + ), + option + ); + }); + + it("case 1", async () => { + const input = + "Latin-Extension=Ʃƣƙ Greek=ϕω Cyrillic=иЩ Arabic=أبت Devanagari=आदित्य Hiragana&Katakana=なツ"; + const paddedStr = apis.padString(input, 128); + const circuitInputs = { + msg: paddedStr, + }; + const witness = await circuit.calculateWitness(circuitInputs); + await circuit.checkConstraints(witness); + expect(1n).toEqual(witness[1]); + const revealedIdx = [ + [16, 17, 18, 19, 20, 21], + [29, 30, 31, 32], + [43, 44, 45, 46], + [55, 56, 57, 58, 59, 60, 61, 62], + [75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92], + [112, 113, 114, 115, 116, 117], + ]; + for (let substr_idx = 0; substr_idx < 6; ++substr_idx) { + for (let idx = 0; idx < 128; ++idx) { + if (revealedIdx[substr_idx].includes(idx)) { + expect(BigInt(paddedStr[idx])).toEqual( + witness[2 + 128 * substr_idx + idx] + ); + } else { + expect(0n).toEqual(witness[2 + 128 * substr_idx + idx]); + } + } + } + }); +}); diff --git a/packages/circom/tests/message_id_regex.test.js b/packages/circom/tests/message_id_regex.test.js new file mode 100644 index 0000000..57bbff4 --- /dev/null +++ b/packages/circom/tests/message_id_regex.test.js @@ -0,0 +1,69 @@ +const circom_tester = require("circom_tester"); +const wasm_tester = circom_tester.wasm; +import * as path from "path"; +const apis = require("../../apis"); +const option = { + include: path.join(__dirname, "../../../node_modules"), +}; +const compiler = require("../../compiler"); + +jest.setTimeout(120000); +describe("Message Id Regex", () => { + let circuit; + beforeAll(async () => { + compiler.genFromDecomposed( + path.join(__dirname, "../circuits/common/message_id.json"), + { + circomFilePath: path.join( + __dirname, + "../circuits/common/message_id_regex.circom" + ), + templateName: "MessageIdRegex", + genSubstrs: true, + } + ); + circuit = await wasm_tester( + path.join(__dirname, "./circuits/test_message_id_regex.circom"), + option + ); + }); + + it("message id from beginning", async () => { + const messageIdStr = `message-id:\r\n`; + const paddedStr = apis.padString(messageIdStr, 256); + const circuitInputs = { + msg: paddedStr, + }; + const witness = await circuit.calculateWitness(circuitInputs); + await circuit.checkConstraints(witness); + expect(1n).toEqual(witness[1]); + const prefixIdxes = apis.extractMessageIdIdxes(messageIdStr)[0]; + for (let idx = 0; idx < 256; ++idx) { + if (idx >= prefixIdxes[0] && idx < prefixIdxes[1]) { + expect(BigInt(paddedStr[idx])).toEqual(witness[2 + idx]); + } else { + expect(0n).toEqual(witness[2 + idx]); + } + } + }); + + it("subject after new line", async () => { + const messageIdStr = + "dummy\r\nmessage-id:\r\n"; + const paddedStr = apis.padString(messageIdStr, 256); + const circuitInputs = { + msg: paddedStr, + }; + const witness = await circuit.calculateWitness(circuitInputs); + await circuit.checkConstraints(witness); + expect(1n).toEqual(witness[1]); + const prefixIdxes = apis.extractMessageIdIdxes(messageIdStr)[0]; + for (let idx = 0; idx < 256; ++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/message_id_regex.test.ts b/packages/circom/tests/message_id_regex.test.ts deleted file mode 100644 index 992913c..0000000 --- a/packages/circom/tests/message_id_regex.test.ts +++ /dev/null @@ -1,73 +0,0 @@ -const ff = require('ffjavascript'); -const stringifyBigInts = ff.utils.stringifyBigInts; -const circom_tester = require("circom_tester"); -const wasm_tester = circom_tester.wasm; -import * as path from "path"; -const p = "21888242871839275222246405745257275088548364400416034343698204186575808495617"; -const field = new ff.F1Field(p); -const apis = require("../../apis"); -const option = { - include: path.join(__dirname, "../../../node_modules") -}; -import { readFileSync } from "fs"; -const compiler = require("../../compiler"); - - -jest.setTimeout(120000); -describe("Message Id Regex", () => { - let circuit; - beforeAll(async () => { - compiler.genFromDecomposed(path.join(__dirname, "../circuits/common/message_id.json"), { - circomFilePath: path.join(__dirname, "../circuits/common/message_id_regex.circom"), - templateName: "MessageIdRegex", - genSubstrs: true - }); - circuit = await wasm_tester(path.join(__dirname, "./circuits/test_message_id_regex.circom"), option); - }); - - it("message id from beginning", async () => { - const messageIdStr = "message-id:\r\n"; - // const revealed = "This is a test."; - // const prefixLen = "subject:".length; - const paddedStr = apis.padString(messageIdStr, 256); - const circuitInputs = { - msg: paddedStr, - }; - // const circuit = await wasm_tester(path.join(__dirname, "./circuits/test_subject_all_regex.circom"), option); - const witness = await circuit.calculateWitness(circuitInputs); - await circuit.checkConstraints(witness); - // console.log(witness); - expect(1n).toEqual(witness[1]); - const prefixIdxes = apis.extractMessageIdIdxes(messageIdStr)[0]; - for (let idx = 0; idx < 256; ++idx) { - if (idx >= prefixIdxes[0] && idx < prefixIdxes[1]) { - expect(BigInt(paddedStr[idx])).toEqual(witness[2 + idx]); - } else { - expect(0n).toEqual(witness[2 + idx]); - } - } - }); - - it("subject after new line", async () => { - const messageIdStr = "dummy\r\nmessage-id:\r\n"; - // const revealed = "This is a test."; - // const prefixLen = "dummy\r\nsubject:".length; - const paddedStr = apis.padString(messageIdStr, 256); - const circuitInputs = { - msg: paddedStr, - }; - // const circuit = await wasm_tester(path.join(__dirname, "./circuits/test_subject_all_regex.circom"), option); - const witness = await circuit.calculateWitness(circuitInputs); - await circuit.checkConstraints(witness); - // console.log(witness); - expect(1n).toEqual(witness[1]); - const prefixIdxes = apis.extractMessageIdIdxes(messageIdStr)[0]; - for (let idx = 0; idx < 256; ++idx) { - if (idx >= prefixIdxes[0] && idx < prefixIdxes[1]) { - expect(BigInt(paddedStr[idx])).toEqual(witness[2 + idx]); - } else { - expect(0n).toEqual(witness[2 + idx]); - } - } - }); -}); \ No newline at end of file diff --git a/packages/circom/tests/negate_regex.test.js b/packages/circom/tests/negate_regex.test.js new file mode 100644 index 0000000..b88789f --- /dev/null +++ b/packages/circom/tests/negate_regex.test.js @@ -0,0 +1,119 @@ +const circom_tester = require("circom_tester"); +const wasm_tester = circom_tester.wasm; +import * as path from "path"; +const apis = require("../../apis"); +const option = { + include: path.join(__dirname, "../../../node_modules"), +}; +const compiler = require("../../compiler"); + +jest.setTimeout(120000); +describe("Negate Regex", () => { + let circuit; + beforeAll(async () => { + compiler.genFromDecomposed( + path.join(__dirname, "./circuits/negate1.json"), + { + circomFilePath: path.join(__dirname, "./circuits/negate1_regex.circom"), + templateName: "Negate1Regex", + genSubstrs: true, + } + ); + circuit = await wasm_tester( + path.join(__dirname, "./circuits/test_negate1_regex.circom"), + option + ); + }); + + it("case 1 with regex 1", async () => { + const input = "a: ABCDEFG XYZ."; + const paddedStr = apis.padString(input, 64); + const circuitInputs = { + msg: paddedStr, + }; + const witness = await circuit.calculateWitness(circuitInputs); + await circuit.checkConstraints(witness); + expect(1n).toEqual(witness[1]); + const revealedIdx = [[2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]]; + for (let substr_idx = 0; substr_idx < 1; ++substr_idx) { + for (let idx = 0; idx < 64; ++idx) { + if (revealedIdx[substr_idx].includes(idx)) { + expect(BigInt(paddedStr[idx])).toEqual( + witness[2 + 64 * substr_idx + idx] + ); + } else { + expect(0n).toEqual(witness[2 + 64 * substr_idx + idx]); + } + } + } + }); + + it("case 2 with regex 1", async () => { + const input = "a: CRIPTOGRAFíA."; + const paddedStr = apis.padString(input, 64); + const circuitInputs = { + msg: paddedStr, + }; + const witness = await circuit.calculateWitness(circuitInputs); + await circuit.checkConstraints(witness); + expect(1n).toEqual(witness[1]); + const revealedIdx = [[2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]]; + for (let substr_idx = 0; substr_idx < 1; ++substr_idx) { + for (let idx = 0; idx < 64; ++idx) { + if (revealedIdx[substr_idx].includes(idx)) { + expect(BigInt(paddedStr[idx])).toEqual( + witness[2 + 64 * substr_idx + idx] + ); + } else { + expect(0n).toEqual(witness[2 + 64 * substr_idx + idx]); + } + } + } + }); + + it("case 3 with regex 1", async () => { + const input = "a: あいう."; + const paddedStr = apis.padString(input, 64); + const circuitInputs = { + msg: paddedStr, + }; + const witness = await circuit.calculateWitness(circuitInputs); + await circuit.checkConstraints(witness); + expect(1n).toEqual(witness[1]); + const revealedIdx = [[2, 3, 4, 5, 6, 7, 8, 9, 10, 11]]; + for (let substr_idx = 0; substr_idx < 1; ++substr_idx) { + for (let idx = 0; idx < 64; ++idx) { + if (revealedIdx[substr_idx].includes(idx)) { + expect(BigInt(paddedStr[idx])).toEqual( + witness[2 + 64 * substr_idx + idx] + ); + } else { + expect(0n).toEqual(witness[2 + 64 * substr_idx + idx]); + } + } + } + }); + + it("case 4 with regex 1", async () => { + const input = "a: التشفير."; + const paddedStr = apis.padString(input, 64); + const circuitInputs = { + msg: paddedStr, + }; + const witness = await circuit.calculateWitness(circuitInputs); + await circuit.checkConstraints(witness); + expect(1n).toEqual(witness[1]); + const revealedIdx = [[2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]]; + for (let substr_idx = 0; substr_idx < 1; ++substr_idx) { + for (let idx = 0; idx < 64; ++idx) { + if (revealedIdx[substr_idx].includes(idx)) { + expect(BigInt(paddedStr[idx])).toEqual( + witness[2 + 64 * substr_idx + idx] + ); + } else { + expect(0n).toEqual(witness[2 + 64 * substr_idx + idx]); + } + } + } + }); +}); diff --git a/packages/circom/tests/negate_regex.test.ts b/packages/circom/tests/negate_regex.test.ts deleted file mode 100644 index 6735fb5..0000000 --- a/packages/circom/tests/negate_regex.test.ts +++ /dev/null @@ -1,121 +0,0 @@ -const ff = require('ffjavascript'); -const stringifyBigInts = ff.utils.stringifyBigInts; -const circom_tester = require("circom_tester"); -const wasm_tester = circom_tester.wasm; -import * as path from "path"; -const p = "21888242871839275222246405745257275088548364400416034343698204186575808495617"; -const field = new ff.F1Field(p); -const apis = require("../../apis"); -const option = { - include: path.join(__dirname, "../../../node_modules") -}; -const compiler = require("../../compiler"); - -jest.setTimeout(120000); -describe("Negate Regex", () => { - let circuit; - beforeAll(async () => { - compiler.genFromDecomposed(path.join(__dirname, "./circuits/negate1.json"), { - circomFilePath: path.join(__dirname, "./circuits/negate1_regex.circom"), - templateName: "Negate1Regex", - genSubstrs: true - }); - circuit = await wasm_tester(path.join(__dirname, "./circuits/test_negate1_regex.circom"), option); - }); - - it("case 1 with regex 1", async () => { - const input = "a: ABCDEFG XYZ."; - const paddedStr = apis.padString(input, 64); - const circuitInputs = { - msg: paddedStr, - }; - // const circuit = await wasm_tester(path.join(__dirname, "./circuits/test_negate1_regex.circom"), option); - const witness = await circuit.calculateWitness(circuitInputs); - await circuit.checkConstraints(witness); - // console.log(witness); - expect(1n).toEqual(witness[1]); - const revealedIdx = [[2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]]; - for (let substr_idx = 0; substr_idx < 1; ++substr_idx) { - for (let idx = 0; idx < 64; ++idx) { - if (revealedIdx[substr_idx].includes(idx)) { - expect(BigInt(paddedStr[idx])).toEqual(witness[2 + 64 * substr_idx + idx]); - } else { - expect(0n).toEqual(witness[2 + 64 * substr_idx + idx]); - } - } - } - }); - - it("case 2 with regex 1", async () => { - // Spanish character "í" has 2 bytes. - const input = "a: CRIPTOGRAFíA."; - const paddedStr = apis.padString(input, 64); - const circuitInputs = { - msg: paddedStr, - }; - // const circuit = await wasm_tester(path.join(__dirname, "./circuits/test_negate1_regex.circom"), option); - const witness = await circuit.calculateWitness(circuitInputs); - await circuit.checkConstraints(witness); - // console.log(witness); - expect(1n).toEqual(witness[1]); - const revealedIdx = [[2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]]; - for (let substr_idx = 0; substr_idx < 1; ++substr_idx) { - for (let idx = 0; idx < 64; ++idx) { - if (revealedIdx[substr_idx].includes(idx)) { - expect(BigInt(paddedStr[idx])).toEqual(witness[2 + 64 * substr_idx + idx]); - } else { - expect(0n).toEqual(witness[2 + 64 * substr_idx + idx]); - } - } - } - }); - - it("case 3 with regex 1", async () => { - /// Each Japanese character has 3 bytes. - const input = "a: あいう."; - const paddedStr = apis.padString(input, 64); - const circuitInputs = { - msg: paddedStr, - }; - // const circuit = await wasm_tester(path.join(__dirname, "./circuits/test_negate1_regex.circom"), option); - const witness = await circuit.calculateWitness(circuitInputs); - await circuit.checkConstraints(witness); - // console.log(witness); - expect(1n).toEqual(witness[1]); - const revealedIdx = [[2, 3, 4, 5, 6, 7, 8, 9, 10, 11]]; - for (let substr_idx = 0; substr_idx < 1; ++substr_idx) { - for (let idx = 0; idx < 64; ++idx) { - if (revealedIdx[substr_idx].includes(idx)) { - expect(BigInt(paddedStr[idx])).toEqual(witness[2 + 64 * substr_idx + idx]); - } else { - expect(0n).toEqual(witness[2 + 64 * substr_idx + idx]); - } - } - } - }); - - it("case 4 with regex 1", async () => { - /// Arabian character "التشفير" has 14 bytes. - const input = "a: التشفير."; - const paddedStr = apis.padString(input, 64); - const circuitInputs = { - msg: paddedStr, - }; - // const circuit = await wasm_tester(path.join(__dirname, "./circuits/test_negate1_regex.circom"), option); - const witness = await circuit.calculateWitness(circuitInputs); - await circuit.checkConstraints(witness); - // console.log(witness); - // console.log(paddedStr); - expect(1n).toEqual(witness[1]); - const revealedIdx = [[2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]]; - for (let substr_idx = 0; substr_idx < 1; ++substr_idx) { - for (let idx = 0; idx < 64; ++idx) { - if (revealedIdx[substr_idx].includes(idx)) { - expect(BigInt(paddedStr[idx])).toEqual(witness[2 + 64 * substr_idx + idx]); - } else { - expect(0n).toEqual(witness[2 + 64 * substr_idx + idx]); - } - } - } - }); -}); \ No newline at end of file diff --git a/packages/circom/tests/simple_regex.test.js b/packages/circom/tests/simple_regex.test.js new file mode 100644 index 0000000..924096f --- /dev/null +++ b/packages/circom/tests/simple_regex.test.js @@ -0,0 +1,102 @@ +const circom_tester = require("circom_tester"); +const wasm_tester = circom_tester.wasm; +import * as path from "path"; +const apis = require("../../apis"); +const option = { + include: path.join(__dirname, "../../../node_modules"), +}; +const compiler = require("../../compiler"); + +jest.setTimeout(120000); +describe("Simple Regex", () => { + let circuit; + beforeAll(async () => { + compiler.genFromRaw("1=(a|b) (2=(b|c)+ )+d", { + substrsJsonPath: path.join( + __dirname, + "./circuits/simple_regex_substrs.json" + ), + circomFilePath: path.join(__dirname, "./circuits/simple_regex.circom"), + templateName: "SimpleRegex", + genSubstrs: true, + }); + circuit = await wasm_tester( + path.join(__dirname, "./circuits/test_simple_regex.circom"), + option + ); + }); + + it("case 1", async () => { + const input = "1=a 2=b d"; + const paddedStr = apis.padString(input, 64); + const circuitInputs = { + msg: paddedStr, + }; + const witness = await circuit.calculateWitness(circuitInputs); + await circuit.checkConstraints(witness); + expect(1n).toEqual(witness[1]); + const revealedIdx = [[2], [6], [8]]; + for (let substr_idx = 0; substr_idx < 3; ++substr_idx) { + for (let idx = 0; idx < 64; ++idx) { + if (revealedIdx[substr_idx].includes(idx)) { + expect(BigInt(paddedStr[idx])).toEqual( + witness[2 + 64 * substr_idx + idx] + ); + } else { + expect(0n).toEqual(witness[2 + 64 * substr_idx + idx]); + } + } + } + }); + + it("case 2", async () => { + const input = "1=a 2=b 2=bc 2=c d"; + const paddedStr = apis.padString(input, 64); + const circuitInputs = { + msg: paddedStr, + }; + const witness = await circuit.calculateWitness(circuitInputs); + await circuit.checkConstraints(witness); + expect(1n).toEqual(witness[1]); + const revealedIdx = [[2], [6, 10, 11, 15], [17]]; + for (let substr_idx = 0; substr_idx < 3; ++substr_idx) { + for (let idx = 0; idx < 64; ++idx) { + if (revealedIdx[substr_idx].includes(idx)) { + expect(BigInt(paddedStr[idx])).toEqual( + witness[2 + 64 * substr_idx + idx] + ); + } else { + expect(0n).toEqual(witness[2 + 64 * substr_idx + idx]); + } + } + } + }); + + it("case 3", async () => { + const input = "1=a 2=b 2=bc 2=c da 1=a 2=cb 2=c 2=b dd"; + const paddedStr = apis.padString(input, 64); + const circuitInputs = { + msg: paddedStr, + }; + + const witness = await circuit.calculateWitness(circuitInputs); + await circuit.checkConstraints(witness); + expect(1n).toEqual(witness[1]); + const revealedIdx = [ + [2, 22], + [6, 10, 11, 15, 26, 27, 31, 35], + [17, 37], + ]; + for (let substr_idx = 0; substr_idx < 3; ++substr_idx) { + for (let idx = 0; idx < 64; ++idx) { + if (revealedIdx[substr_idx].includes(idx)) { + expect(BigInt(paddedStr[idx])).toEqual( + witness[2 + 64 * substr_idx + idx] + ); + } else { + expect(0n).toEqual(witness[2 + 64 * substr_idx + idx]); + } + } + } + }); +}); diff --git a/packages/circom/tests/simple_regex.test.ts b/packages/circom/tests/simple_regex.test.ts deleted file mode 100644 index e86d6f4..0000000 --- a/packages/circom/tests/simple_regex.test.ts +++ /dev/null @@ -1,98 +0,0 @@ -const ff = require('ffjavascript'); -const stringifyBigInts = ff.utils.stringifyBigInts; -const circom_tester = require("circom_tester"); -const wasm_tester = circom_tester.wasm; -import * as path from "path"; -const p = "21888242871839275222246405745257275088548364400416034343698204186575808495617"; -const field = new ff.F1Field(p); -const apis = require("../../apis"); -const option = { - include: path.join(__dirname, "../../../node_modules") -}; -const compiler = require("../../compiler"); - -jest.setTimeout(120000); -describe("Simple Regex", () => { - let circuit; - beforeAll(async () => { - compiler.genFromRaw( - "1=(a|b) (2=(b|c)+ )+d", - { - substrsJsonPath: path.join(__dirname, "./circuits/simple_regex_substrs.json"), - circomFilePath: path.join(__dirname, "./circuits/simple_regex.circom"), - templateName: "SimpleRegex", - genSubstrs: true - } - ); - circuit = await wasm_tester(path.join(__dirname, "./circuits/test_simple_regex.circom"), option); - }); - - it("case 1", async () => { - const input = "1=a 2=b d"; - const paddedStr = apis.padString(input, 64); - const circuitInputs = { - msg: paddedStr, - }; - // const circuit = await wasm_tester(path.join(__dirname, "./circuits/test_simple_regex.circom"), option); - const witness = await circuit.calculateWitness(circuitInputs); - await circuit.checkConstraints(witness); - // console.log(witness); - expect(1n).toEqual(witness[1]); - const revealedIdx = [[2], [6], [8]]; - for (let substr_idx = 0; substr_idx < 3; ++substr_idx) { - for (let idx = 0; idx < 64; ++idx) { - if (revealedIdx[substr_idx].includes(idx)) { - expect(BigInt(paddedStr[idx])).toEqual(witness[2 + 64 * substr_idx + idx]); - } else { - expect(0n).toEqual(witness[2 + 64 * substr_idx + idx]); - } - } - } - }); - - it("case 2", async () => { - const input = "1=a 2=b 2=bc 2=c d"; - const paddedStr = apis.padString(input, 64); - const circuitInputs = { - msg: paddedStr, - }; - // const circuit = await wasm_tester(path.join(__dirname, "./circuits/test_simple_regex.circom"), option); - const witness = await circuit.calculateWitness(circuitInputs); - await circuit.checkConstraints(witness); - // console.log(witness); - expect(1n).toEqual(witness[1]); - const revealedIdx = [[2], [6, 10, 11, 15], [17]]; - for (let substr_idx = 0; substr_idx < 3; ++substr_idx) { - for (let idx = 0; idx < 64; ++idx) { - if (revealedIdx[substr_idx].includes(idx)) { - expect(BigInt(paddedStr[idx])).toEqual(witness[2 + 64 * substr_idx + idx]); - } else { - expect(0n).toEqual(witness[2 + 64 * substr_idx + idx]); - } - } - } - }); - - it("case 3", async () => { - const input = "1=a 2=b 2=bc 2=c da 1=a 2=cb 2=c 2=b dd"; - const paddedStr = apis.padString(input, 64); - const circuitInputs = { - msg: paddedStr, - }; - - // const circuit = await wasm_tester(path.join(__dirname, "./circuits/test_simple_regex.circom"), option); - const witness = await circuit.calculateWitness(circuitInputs); - await circuit.checkConstraints(witness); - expect(1n).toEqual(witness[1]); - const revealedIdx = [[2, 22], [6, 10, 11, 15, 26, 27, 31, 35], [17, 37]]; - for (let substr_idx = 0; substr_idx < 3; ++substr_idx) { - for (let idx = 0; idx < 64; ++idx) { - if (revealedIdx[substr_idx].includes(idx)) { - expect(BigInt(paddedStr[idx])).toEqual(witness[2 + 64 * substr_idx + idx]); - } else { - expect(0n).toEqual(witness[2 + 64 * substr_idx + idx]); - } - } - } - }); -}); diff --git a/packages/circom/tests/simple_regex_decomposed.test.js b/packages/circom/tests/simple_regex_decomposed.test.js new file mode 100644 index 0000000..39c2171 --- /dev/null +++ b/packages/circom/tests/simple_regex_decomposed.test.js @@ -0,0 +1,53 @@ +const circom_tester = require("circom_tester"); +const wasm_tester = circom_tester.wasm; +import * as path from "path"; +const apis = require("../../apis"); +const option = { + include: path.join(__dirname, "../../../node_modules"), +}; +const compiler = require("../../compiler"); + +jest.setTimeout(120000); +describe("Simple Regex Decomposed", () => { + let circuit; + beforeAll(async () => { + compiler.genFromDecomposed( + path.join(__dirname, "./circuits/simple_regex_decomposed.json"), + { + circomFilePath: path.join( + __dirname, + "./circuits/simple_regex_decomposed.circom" + ), + templateName: "SimpleRegexDecomposed", + genSubstrs: true, + } + ); + circuit = await wasm_tester( + path.join(__dirname, "./circuits/test_simple_regex_decomposed.circom"), + option + ); + }); + + it("case 1", async () => { + const input = "email was meant for @zkRegex."; + const paddedStr = apis.padString(input, 64); + const circuitInputs = { + msg: paddedStr, + }; + const witness = await circuit.calculateWitness(circuitInputs); + await circuit.checkConstraints(witness); + expect(1n).toEqual(witness[1]); + const revealedIdx = [[21, 22, 23, 24, 25, 26, 27]]; + for (let substr_idx = 0; substr_idx < 1; ++substr_idx) { + for (let idx = 0; idx < 64; ++idx) { + if (revealedIdx[substr_idx].includes(idx)) { + expect(BigInt(paddedStr[idx])).toEqual( + witness[2 + 64 * substr_idx + idx] + ); + } else { + expect(0n).toEqual(witness[2 + 64 * substr_idx + idx]); + } + } + } + }); +}); diff --git a/packages/circom/tests/simple_regex_decomposed.test.ts b/packages/circom/tests/simple_regex_decomposed.test.ts deleted file mode 100644 index cec6f1f..0000000 --- a/packages/circom/tests/simple_regex_decomposed.test.ts +++ /dev/null @@ -1,48 +0,0 @@ -const ff = require('ffjavascript'); -const stringifyBigInts = ff.utils.stringifyBigInts; -const circom_tester = require("circom_tester"); -const wasm_tester = circom_tester.wasm; -import * as path from "path"; -const p = "21888242871839275222246405745257275088548364400416034343698204186575808495617"; -const field = new ff.F1Field(p); -const apis = require("../../apis"); -const option = { - include: path.join(__dirname, "../../../node_modules") -}; -const compiler = require("../../compiler"); - -jest.setTimeout(120000); -describe("Simple Regex Decomposed", () => { - let circuit; - beforeAll(async () => { - compiler.genFromDecomposed(path.join(__dirname, "./circuits/simple_regex_decomposed.json"), { - circomFilePath: path.join(__dirname, "./circuits/simple_regex_decomposed.circom"), - templateName: "SimpleRegexDecomposed", - genSubstrs: true - }); - circuit = await wasm_tester(path.join(__dirname, "./circuits/test_simple_regex_decomposed.circom"), option); - }); - - it("case 1", async () => { - const input = "email was meant for @zkRegex."; - const paddedStr = apis.padString(input, 64); - const circuitInputs = { - msg: paddedStr, - }; - const witness = await circuit.calculateWitness(circuitInputs); - await circuit.checkConstraints(witness); - // console.log(witness); - expect(1n).toEqual(witness[1]); - const revealedIdx = [[21,22,23,24,25,26,27]]; - for (let substr_idx = 0; substr_idx < 1; ++substr_idx) { - for (let idx = 0; idx < 64; ++idx) { - if (revealedIdx[substr_idx].includes(idx)) { - expect(BigInt(paddedStr[idx])).toEqual(witness[2 + 64 * substr_idx + idx]); - } else { - expect(0n).toEqual(witness[2 + 64 * substr_idx + idx]); - } - } - } - }); - -}); \ No newline at end of file diff --git a/packages/circom/tests/subject_all.test.js b/packages/circom/tests/subject_all.test.js new file mode 100644 index 0000000..55dae0d --- /dev/null +++ b/packages/circom/tests/subject_all.test.js @@ -0,0 +1,87 @@ +const circom_tester = require("circom_tester"); +const wasm_tester = circom_tester.wasm; +import * as path from "path"; +const apis = require("../../apis"); +const option = { + include: path.join(__dirname, "../../../node_modules"), +}; +const compiler = require("../../compiler"); + +jest.setTimeout(120000); +describe("Subject All Regex", () => { + let circuit; + beforeAll(async () => { + compiler.genFromDecomposed( + path.join(__dirname, "../circuits/common/subject_all.json"), + { + circomFilePath: path.join( + __dirname, + "../circuits/common/subject_all_regex.circom" + ), + templateName: "SubjectAllRegex", + genSubstrs: true, + } + ); + circuit = await wasm_tester( + path.join(__dirname, "./circuits/test_subject_all_regex.circom"), + option + ); + }); + + it("subject from beginning", async () => { + const subjectStr = "subject:This is a test.\r\n"; + const paddedStr = apis.padString(subjectStr, 256); + const circuitInputs = { + msg: paddedStr, + }; + const witness = await circuit.calculateWitness(circuitInputs); + await circuit.checkConstraints(witness); + expect(1n).toEqual(witness[1]); + const prefixIdxes = apis.extractSubjectAllIdxes(subjectStr)[0]; + for (let idx = 0; idx < 256; ++idx) { + if (idx >= prefixIdxes[0] && idx < prefixIdxes[1]) { + expect(BigInt(paddedStr[idx])).toEqual(witness[2 + idx]); + } else { + expect(0n).toEqual(witness[2 + idx]); + } + } + }); + + it("subject after new line", async () => { + const subjectStr = "dummy\r\nsubject:This is a test.\r\n"; + const paddedStr = apis.padString(subjectStr, 256); + const circuitInputs = { + msg: paddedStr, + }; + const witness = await circuit.calculateWitness(circuitInputs); + await circuit.checkConstraints(witness); + expect(1n).toEqual(witness[1]); + const prefixIdxes = apis.extractSubjectAllIdxes(subjectStr)[0]; + for (let idx = 0; idx < 256; ++idx) { + if (idx >= prefixIdxes[0] && idx < prefixIdxes[1]) { + expect(BigInt(paddedStr[idx])).toEqual(witness[2 + idx]); + } else { + expect(0n).toEqual(witness[2 + idx]); + } + } + }); + + it("subject from beginning and non-English case", async () => { + const subjectStr = "subject:これはテストです。\r\n"; + const paddedStr = apis.padString(subjectStr, 256); + const circuitInputs = { + msg: paddedStr, + }; + const witness = await circuit.calculateWitness(circuitInputs); + await circuit.checkConstraints(witness); + expect(1n).toEqual(witness[1]); + const prefixIdxes = apis.extractSubjectAllIdxes(subjectStr)[0]; + for (let idx = 0; idx < 256; ++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/subject_all.test.ts b/packages/circom/tests/subject_all.test.ts deleted file mode 100644 index cbfac0b..0000000 --- a/packages/circom/tests/subject_all.test.ts +++ /dev/null @@ -1,96 +0,0 @@ -const ff = require('ffjavascript'); -const stringifyBigInts = ff.utils.stringifyBigInts; -const circom_tester = require("circom_tester"); -const wasm_tester = circom_tester.wasm; -import * as path from "path"; -const p = "21888242871839275222246405745257275088548364400416034343698204186575808495617"; -const field = new ff.F1Field(p); -const apis = require("../../apis"); -const option = { - include: path.join(__dirname, "../../../node_modules") -}; -import { readFileSync } from "fs"; -const compiler = require("../../compiler"); - - -jest.setTimeout(120000); -describe("Subject All Regex", () => { - let circuit; - beforeAll(async () => { - compiler.genFromDecomposed(path.join(__dirname, "../circuits/common/subject_all.json"), { - circomFilePath: path.join(__dirname, "../circuits/common/subject_all_regex.circom"), - templateName: "SubjectAllRegex", - genSubstrs: true - }); - circuit = await wasm_tester(path.join(__dirname, "./circuits/test_subject_all_regex.circom"), option); - }); - - it("subject from beginning", async () => { - const subjectStr = "subject:This is a test.\r\n"; - // const revealed = "This is a test."; - // const prefixLen = "subject:".length; - const paddedStr = apis.padString(subjectStr, 256); - const circuitInputs = { - msg: paddedStr, - }; - // const circuit = await wasm_tester(path.join(__dirname, "./circuits/test_subject_all_regex.circom"), option); - const witness = await circuit.calculateWitness(circuitInputs); - await circuit.checkConstraints(witness); - // console.log(witness); - expect(1n).toEqual(witness[1]); - const prefixIdxes = apis.extractSubjectAllIdxes(subjectStr)[0]; - for (let idx = 0; idx < 256; ++idx) { - if (idx >= prefixIdxes[0] && idx < prefixIdxes[1]) { - expect(BigInt(paddedStr[idx])).toEqual(witness[2 + idx]); - } else { - expect(0n).toEqual(witness[2 + idx]); - } - } - }); - - it("subject after new line", async () => { - const subjectStr = "dummy\r\nsubject:This is a test.\r\n"; - // const revealed = "This is a test."; - // const prefixLen = "dummy\r\nsubject:".length; - const paddedStr = apis.padString(subjectStr, 256); - const circuitInputs = { - msg: paddedStr, - }; - // const circuit = await wasm_tester(path.join(__dirname, "./circuits/test_subject_all_regex.circom"), option); - const witness = await circuit.calculateWitness(circuitInputs); - await circuit.checkConstraints(witness); - // console.log(witness); - expect(1n).toEqual(witness[1]); - const prefixIdxes = apis.extractSubjectAllIdxes(subjectStr)[0]; - for (let idx = 0; idx < 256; ++idx) { - if (idx >= prefixIdxes[0] && idx < prefixIdxes[1]) { - expect(BigInt(paddedStr[idx])).toEqual(witness[2 + idx]); - } else { - expect(0n).toEqual(witness[2 + idx]); - } - } - }); - - it("subject from beginning and non-English case", async () => { - const subjectStr = "subject:これはテストです。\r\n"; - // const revealed = "This is a test."; - // const prefixLen = "subject:".length; - const paddedStr = apis.padString(subjectStr, 256); - const circuitInputs = { - msg: paddedStr, - }; - // const circuit = await wasm_tester(path.join(__dirname, "./circuits/test_subject_all_regex.circom"), option); - const witness = await circuit.calculateWitness(circuitInputs); - await circuit.checkConstraints(witness); - // console.log(witness); - expect(1n).toEqual(witness[1]); - const prefixIdxes = apis.extractSubjectAllIdxes(subjectStr)[0]; - for (let idx = 0; idx < 256; ++idx) { - if (idx >= prefixIdxes[0] && idx < prefixIdxes[1]) { - expect(BigInt(paddedStr[idx])).toEqual(witness[2 + idx]); - } else { - expect(0n).toEqual(witness[2 + idx]); - } - } - }); -}); \ No newline at end of file diff --git a/packages/circom/tests/timestamp.test.js b/packages/circom/tests/timestamp.test.js new file mode 100644 index 0000000..59c0e96 --- /dev/null +++ b/packages/circom/tests/timestamp.test.js @@ -0,0 +1,68 @@ +const circom_tester = require("circom_tester"); +const wasm_tester = circom_tester.wasm; +import * as path from "path"; +const apis = require("../../apis"); +const option = { + include: path.join(__dirname, "../../../node_modules"), +}; +const compiler = require("../../compiler"); + +jest.setTimeout(600000); +describe("Timestamp Regex", () => { + let circuit; + beforeAll(async () => { + compiler.genFromDecomposed( + path.join(__dirname, "../circuits/common/timestamp.json"), + { + circomFilePath: path.join( + __dirname, + "../circuits/common/timestamp_regex.circom" + ), + templateName: "TimestampRegex", + genSubstrs: true, + } + ); + circuit = await wasm_tester( + path.join(__dirname, "./circuits/test_timestamp_regex.circom"), + option + ); + }); + + it("timestamp in the header", async () => { + const signatureField = `dkim-signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1694989812; x=1695594612; dara=google.com; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=BWETwQ9JDReS4GyR2v2TTR8Bpzj9ayumsWQJ3q7vehs=; b=`; + const paddedStr = apis.padString(signatureField, 1024); + const circuitInputs = { + msg: paddedStr, + }; + const witness = await circuit.calculateWitness(circuitInputs); + await circuit.checkConstraints(witness); + expect(1n).toEqual(witness[1]); + const prefixIdxes = apis.extractTimestampIdxes(signatureField)[0]; + 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("timestamp after new line", async () => { + const signatureField = `\r\ndkim-signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1694989812; x=1695594612; dara=google.com; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=BWETwQ9JDReS4GyR2v2TTR8Bpzj9ayumsWQJ3q7vehs=; b=`; + const paddedStr = apis.padString(signatureField, 1024); + const circuitInputs = { + msg: paddedStr, + }; + const witness = await circuit.calculateWitness(circuitInputs); + await circuit.checkConstraints(witness); + expect(1n).toEqual(witness[1]); + const prefixIdxes = apis.extractTimestampIdxes(signatureField)[0]; + 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/timestamp.test.ts b/packages/circom/tests/timestamp.test.ts deleted file mode 100644 index ec2dda6..0000000 --- a/packages/circom/tests/timestamp.test.ts +++ /dev/null @@ -1,69 +0,0 @@ -const ff = require('ffjavascript'); -const stringifyBigInts = ff.utils.stringifyBigInts; -const circom_tester = require("circom_tester"); -const wasm_tester = circom_tester.wasm; -import * as path from "path"; -import { readFileSync } from "fs"; -const p = "21888242871839275222246405745257275088548364400416034343698204186575808495617"; -const field = new ff.F1Field(p); -const apis = require("../../apis"); -const option = { - include: path.join(__dirname, "../../../node_modules") -}; -const compiler = require("../../compiler"); - - -jest.setTimeout(120000); -describe("Timestamp Regex", () => { - let circuit; - beforeAll(async () => { - compiler.genFromDecomposed(path.join(__dirname, "../circuits/common/timestamp.json"), { - circomFilePath: path.join(__dirname, "../circuits/common/timestamp_regex.circom"), - templateName: "TimestampRegex", - genSubstrs: true - }); - circuit = await wasm_tester(path.join(__dirname, "./circuits/test_timestamp_regex.circom"), option); - }); - - it("timestamp in the header", async () => { - const signatureField = `dkim-signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1694989812; x=1695594612; dara=google.com; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=BWETwQ9JDReS4GyR2v2TTR8Bpzj9ayumsWQJ3q7vehs=; b=`; - // const revealed = "1694989812"; - const paddedStr = apis.padString(signatureField, 1024); - const circuitInputs = { - msg: paddedStr, - }; - // const circuit = await wasm_tester(path.join(__dirname, "./circuits/test_timestamp_regex.circom"), option); - const witness = await circuit.calculateWitness(circuitInputs); - await circuit.checkConstraints(witness); - expect(1n).toEqual(witness[1]); - const prefixIdxes = apis.extractTimestampIdxes(signatureField)[0]; - 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("timestamp after new line", async () => { - const signatureField = `\r\ndkim-signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1694989812; x=1695594612; dara=google.com; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=BWETwQ9JDReS4GyR2v2TTR8Bpzj9ayumsWQJ3q7vehs=; b=`; - // const revealed = "1694989812"; - const paddedStr = apis.padString(signatureField, 1024); - const circuitInputs = { - msg: paddedStr, - }; - // const circuit = await wasm_tester(path.join(__dirname, "./circuits/test_timestamp_regex.circom"), option); - const witness = await circuit.calculateWitness(circuitInputs); - await circuit.checkConstraints(witness); - expect(1n).toEqual(witness[1]); - const prefixIdxes = apis.extractTimestampIdxes(signatureField)[0]; - 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]); - } - } - }); -}); \ No newline at end of file diff --git a/packages/circom/tests/to_addr.test.js b/packages/circom/tests/to_addr.test.js new file mode 100644 index 0000000..79c01f9 --- /dev/null +++ b/packages/circom/tests/to_addr.test.js @@ -0,0 +1,204 @@ +const circom_tester = require("circom_tester"); +const wasm_tester = circom_tester.wasm; +import * as path from "path"; +const apis = require("../../apis"); +const option = { + include: path.join(__dirname, "../../../node_modules"), +}; +const compiler = require("../../compiler"); + +jest.setTimeout(600000); +describe("To Addr Regex", () => { + let circuit; + beforeAll(async () => { + compiler.genFromDecomposed( + path.join(__dirname, "../circuits/common/to_all.json"), + { + circomFilePath: path.join( + __dirname, + "../circuits/common/to_all_regex.circom" + ), + templateName: "ToAllRegex", + genSubstrs: true, + } + ); + compiler.genFromDecomposed( + path.join(__dirname, "../circuits/common/email_addr_with_name.json"), + { + circomFilePath: path.join( + __dirname, + "../circuits/common/email_addr_with_name_regex.circom" + ), + templateName: "EmailAddrWithNameRegex", + genSubstrs: true, + } + ); + compiler.genFromDecomposed( + path.join(__dirname, "../circuits/common/email_addr.json"), + { + circomFilePath: path.join( + __dirname, + "../circuits/common/email_addr_regex.circom" + ), + templateName: "EmailAddrRegex", + genSubstrs: true, + } + ); + circuit = await wasm_tester( + path.join(__dirname, "./circuits/test_to_addr_regex.circom"), + option + ); + }); + + it("to field from beginning case 1", async () => { + const toStr = "to:adityabisht@gmail.com\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]; + 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 from beginning case 2", async () => { + const toStr = "to:Aditya Bisht \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]; + 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 from beginning case 3 (email address as a name)", async () => { + const toStr = "to:dummy@example.com\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]; + 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 from beginning case 4 (non-English string is used as a name)", async () => { + const toStr = 'to: "末神奏宙" \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]; + 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 after new line case 1", async () => { + const toStr = "dummy\r\nto:adityabisht@gmail.com\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]; + 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 after new line case 2", async () => { + const toStr = "dummy\r\nto:Sora Suegami \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]; + 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 after new line case 3 (email address as a name)", async () => { + const toStr = "dummy\r\nto:dummy@example.com\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]; + 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 after new line case 4 (non-English string is used as a name)", async () => { + const toStr = 'dummy\r\nto: "末神奏宙" \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]; + 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.ts b/packages/circom/tests/to_addr.test.ts deleted file mode 100644 index 6ecb6fa..0000000 --- a/packages/circom/tests/to_addr.test.ts +++ /dev/null @@ -1,184 +0,0 @@ -const circom_tester = require("circom_tester"); -const wasm_tester = circom_tester.wasm; -import * as path from "path"; -const apis = require("../../apis"); -const option = { - include: path.join(__dirname, "../../../node_modules") -}; -const compiler = require("../../compiler"); - -jest.setTimeout(240000); -describe("To Addr Regex", () => { - let circuit; - beforeAll(async () => { - compiler.genFromDecomposed(path.join(__dirname, "../circuits/common/to_all.json"), { - circomFilePath: path.join(__dirname, "../circuits/common/to_all_regex.circom"), - templateName: "ToAllRegex", - genSubstrs: true - }); - compiler.genFromDecomposed(path.join(__dirname, "../circuits/common/email_addr_with_name.json"), { - circomFilePath: path.join(__dirname, "../circuits/common/email_addr_with_name_regex.circom"), - templateName: "EmailAddrWithNameRegex", - genSubstrs: true - }); - compiler.genFromDecomposed(path.join(__dirname, "../circuits/common/email_addr.json"), { - circomFilePath: path.join(__dirname, "../circuits/common/email_addr_regex.circom"), - templateName: "EmailAddrRegex", - genSubstrs: true - }); - circuit = await wasm_tester(path.join(__dirname, "./circuits/test_to_addr_regex.circom"), option); - }); - - it("to field from beginning case 1", async () => { - const toStr = "to:adityabisht@gmail.com\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]; - 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 from beginning case 2", async () => { - const toStr = "to:Aditya Bisht \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]; - 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 from beginning case 3 (email address as a name)", async () => { - const toStr = "to:dummy@example.com\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]; - 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 from beginning case 4 (non-English string is used as a name)", async () => { - const toStr = "to: \"末神奏宙\" \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]; - 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 after new line case 1", async () => { - const toStr = "dummy\r\nto:adityabisht@gmail.com\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]; - 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 after new line case 2", async () => { - const toStr = "dummy\r\nto:Sora Suegami \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]; - 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 after new line case 3 (email address as a name)", async () => { - const toStr = "dummy\r\nto:dummy@example.com\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]; - 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 after new line case 4 (non-English string is used as a name)", async () => { - const toStr = "dummy\r\nto: \"末神奏宙\" \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]; - 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]); - } - } - }); -}); \ No newline at end of file diff --git a/packages/compiler/Cargo.toml b/packages/compiler/Cargo.toml index 94d9c34..f1b51e3 100644 --- a/packages/compiler/Cargo.toml +++ b/packages/compiler/Cargo.toml @@ -28,10 +28,11 @@ graph-cycles = "0.1.0" thiserror = "1.0.40" serde_json = "1.0.95" serde = { version = "1.0.159", features = ["derive"] } -js-sandbox = { version = "0.2.0-rc.2", git = "https://github.com/Bromeon/js-sandbox.git", tag = "0.2.0-rc.2" } itertools = "0.10.3" clap = { version = "=4.2.1", features = ["derive"] } ahash = "=0.8.7" +regex-automata = "0.4.5" +regex = "1.10.3" [dependencies.neon] version = "0.10" diff --git a/packages/compiler/package.json b/packages/compiler/package.json index 247333b..12d7c8b 100644 --- a/packages/compiler/package.json +++ b/packages/compiler/package.json @@ -14,21 +14,20 @@ "url": "git+https://github.com/zkemail/zk-regex.git" }, "scripts": { - "build": "npx tsc && cargo-cp-artifact -nc index.node -- cargo build --message-format=json-render-diagnostics", - "build-debug": "npx tsc && npm run build --", - "build-release": "npx tsc && npm run build -- --release", + "build": "cargo-cp-artifact -nc index.node -- cargo build --message-format=json-render-diagnostics", + "build-debug": "npm run build --", + "build-release": "npm run build -- --release", "install": "npm run build-debug", "install-release": "node-pre-gyp install --update-binary --fallback-to-build=false || npm run build-release", - "test": "npx tsc && cargo test", - "package": "npx tsc && node-pre-gyp package", - "upload-binary": "npx tsc && npm run package && node-pre-gyp-github publish" + "test": "cargo test", + "package": "node-pre-gyp package", + "upload-binary": "npm run package && node-pre-gyp-github publish" }, "license": "MIT", "dependencies": { "@mapbox/node-pre-gyp": "^1.0", "cargo-cp-artifact": "^0.1", - "node-pre-gyp-github": "https://github.com/ultamatt/node-pre-gyp-github.git", - "typescript": "^5.2.2" + "node-pre-gyp-github": "https://github.com/ultamatt/node-pre-gyp-github.git" }, "binary": { "module_name": "index", diff --git a/packages/compiler/src/bin/compiler.rs b/packages/compiler/src/bin/compiler.rs index 7420b8f..18b95e8 100644 --- a/packages/compiler/src/bin/compiler.rs +++ b/packages/compiler/src/bin/compiler.rs @@ -1,5 +1,3 @@ - - use clap::{Parser, Subcommand}; use zk_regex_compiler::*; @@ -80,43 +78,43 @@ fn main() { gen_substrs, ); } // Commands::GenHalo2Texts { - // decomposed_regex_path, - // allstr_file_path, - // substrs_dir_path, - // } => { - // let regex_decomposed: DecomposedRegexConfig = - // serde_json::from_reader(File::open(decomposed_regex_path).unwrap()).unwrap(); - // let num_public_part = regex_decomposed - // .parts - // .iter() - // .filter(|part| part.is_public) - // .collect_vec() - // .len(); - // let substr_file_pathes = (0..num_public_part) - // .map(|idx| { - // PathBuf::new() - // .join(&substrs_dir_path) - // .join(&format!("substr{}.txt", idx)) - // }) - // .collect_vec(); - // regex_decomposed - // .gen_regex_files( - // &Path::new(&allstr_file_path).to_path_buf(), - // &substr_file_pathes, - // ) - // .unwrap(); - // } - // Commands::GenCircom { - // decomposed_regex_path, - // circom_file_path, - // template_name, - // } => { - // let regex_decomposed: DecomposedRegexConfig = - // serde_json::from_reader(File::open(decomposed_regex_path).unwrap()).unwrap(); - // let circom_path = PathBuf::from(circom_file_path); - // regex_decomposed - // .gen_circom(&circom_path, &template_name) - // .unwrap(); - // } + // decomposed_regex_path, + // allstr_file_path, + // substrs_dir_path, + // } => { + // let regex_decomposed: DecomposedRegexConfig = + // serde_json::from_reader(File::open(decomposed_regex_path).unwrap()).unwrap(); + // let num_public_part = regex_decomposed + // .parts + // .iter() + // .filter(|part| part.is_public) + // .collect_vec() + // .len(); + // let substr_file_pathes = (0..num_public_part) + // .map(|idx| { + // PathBuf::new() + // .join(&substrs_dir_path) + // .join(&format!("substr{}.txt", idx)) + // }) + // .collect_vec(); + // regex_decomposed + // .gen_regex_files( + // &Path::new(&allstr_file_path).to_path_buf(), + // &substr_file_pathes, + // ) + // .unwrap(); + // } + // Commands::GenCircom { + // decomposed_regex_path, + // circom_file_path, + // template_name, + // } => { + // let regex_decomposed: DecomposedRegexConfig = + // serde_json::from_reader(File::open(decomposed_regex_path).unwrap()).unwrap(); + // let circom_path = PathBuf::from(circom_file_path); + // regex_decomposed + // .gen_circom(&circom_path, &template_name) + // .unwrap(); + // } } } diff --git a/packages/compiler/src/circom.rs b/packages/compiler/src/circom.rs index 790c4f7..dfb9ac6 100644 --- a/packages/compiler/src/circom.rs +++ b/packages/compiler/src/circom.rs @@ -1,13 +1,354 @@ use super::CompilerError; use crate::get_accepted_state; -use crate::js_caller::*; +use crate::DFAGraph; use crate::RegexAndDFA; -// use crate::{AllstrRegexDef, SubstrRegexDef}; +use std::collections::{BTreeMap, BTreeSet}; use std::fs::File; use std::io::Write; use std::path::PathBuf; +fn gen_circom_allstr(dfa_graph: &DFAGraph, template_name: &str, regex_str: &str) -> String { + let n = dfa_graph.states.len(); + let mut rev_graph = BTreeMap::>>::new(); + let mut to_init_graph = vec![]; + let mut init_going_state: Option = None; + + for i in 0..n { + rev_graph.insert(i, BTreeMap::new()); + to_init_graph.push(vec![]); + } + + let mut accept_nodes = BTreeSet::::new(); + + for i in 0..n { + let node = &dfa_graph.states[i]; + for (k, v) in &node.edges { + let chars: Vec = v.iter().cloned().collect(); + rev_graph.get_mut(k).unwrap().insert(i, chars.clone()); + + if i == 0 { + if let Some(index) = chars.iter().position(|&x| x == 94) { + init_going_state = Some(*k); + rev_graph.get_mut(&k).unwrap().get_mut(&i).unwrap()[index] = 255; + } + + for j in rev_graph.get(&k).unwrap().get(&i).unwrap() { + if *j == 255 { + continue; + } + to_init_graph[*k].push(*j); + } + } + } + + if node.r#type == "accept" { + accept_nodes.insert(i); + } + } + + if let Some(init_going_state) = init_going_state { + for (going_state, chars) in to_init_graph.iter().enumerate() { + if chars.is_empty() { + continue; + } + + if rev_graph + .get_mut(&(going_state as usize)) + .unwrap() + .get_mut(&init_going_state) + .is_none() + { + rev_graph + .get_mut(&(going_state as usize)) + .unwrap() + .insert(init_going_state, vec![]); + } + + rev_graph + .get_mut(&(going_state as usize)) + .unwrap() + .get_mut(&init_going_state) + .unwrap() + .extend_from_slice(chars); + } + } + + if accept_nodes.is_empty() { + panic!("Accept node must exist"); + } + + let accept_nodes_array: Vec = accept_nodes.into_iter().collect(); + + if accept_nodes_array.len() != 1 { + panic!("The size of accept nodes must be one"); + } + + let mut eq_i = 0; + let mut lt_i = 0; + let mut and_i = 0; + let mut multi_or_i = 0; + + let mut range_checks = vec![vec![None; 256]; 256]; + let mut eq_checks = vec![None; 256]; + let mut multi_or_checks1 = BTreeMap::::new(); + let mut multi_or_checks2 = BTreeMap::::new(); + + let mut lines = vec![]; + + lines.push("\tfor (var i = 0; i < num_bytes; i++) {".to_string()); + lines.push(format!("\t\tstate_changed[i] = MultiOR({});", n - 1)); + + for i in 1..n { + let mut outputs = vec![]; + + for (prev_i, k) in rev_graph.get(&(i as usize)).unwrap().iter() { + let prev_i_num = *prev_i; + let mut k = k.clone(); + k.sort(); + + let mut eq_outputs = vec![]; + let mut vals = k.clone().into_iter().collect::>(); + + if vals.is_empty() { + continue; + } + + let mut min_maxes = vec![]; + let mut cur_min = k[0]; + let mut cur_max = k[0]; + + for idx in 1..k.len() { + if cur_max == k[idx] { + continue; + } else if cur_max + 1 == k[idx] { + cur_max += 1; + } else { + if cur_max - cur_min >= 16 { + min_maxes.push((cur_min, cur_max)); + } + cur_min = k[idx]; + cur_max = k[idx]; + } + } + + if cur_max - cur_min >= 16 { + min_maxes.push((cur_min, cur_max)); + } + + for min_max in &min_maxes { + for code in min_max.0..=min_max.1 { + vals.remove(&code); + } + } + + for min_max in &min_maxes { + let min = min_max.0; + let max = min_max.1; + + if range_checks[min as usize][max as usize].is_none() { + lines.push(format!("\t\tlt[{}][i] = LessEqThan(8);", lt_i)); + lines.push(format!("\t\tlt[{}][i].in[0] <== {};", lt_i, min)); + lines.push(format!("\t\tlt[{}][i].in[1] <== in[i];", lt_i)); + lines.push(format!("\t\tlt[{}][i] = LessEqThan(8);", lt_i + 1)); + lines.push(format!("\t\tlt[{}][i].in[0] <== in[i];", lt_i + 1)); + lines.push(format!("\t\tlt[{}][i].in[1] <== {};", lt_i + 1, max)); + lines.push(format!("\t\tand[{}][i] = AND();", and_i)); + lines.push(format!("\t\tand[{}][i].a <== lt[{}][i].out;", and_i, lt_i)); + lines.push(format!( + "\t\tand[{}][i].b <== lt[{}][i].out;", + and_i, + lt_i + 1 + )); + eq_outputs.push(("and", and_i)); + range_checks[min as usize][max as usize] = Some((lt_i, and_i)); + lt_i += 2; + and_i += 1; + } else { + if let Some((_, and_i)) = range_checks[min as usize][max as usize] { + eq_outputs.push(("and", and_i)); + } + } + } + + for code in &vals { + if eq_checks[*code as usize].is_none() { + lines.push(format!("\t\teq[{}][i] = IsEqual();", eq_i)); + lines.push(format!("\t\teq[{}][i].in[0] <== in[i];", eq_i)); + lines.push(format!("\t\teq[{}][i].in[1] <== {};", eq_i, code)); + eq_outputs.push(("eq", eq_i)); + eq_checks[*code as usize] = Some(eq_i); + eq_i += 1; + } else { + if let Some(eq_i) = eq_checks[*code as usize] { + eq_outputs.push(("eq", eq_i)); + } + } + } + + lines.push(format!("\t\tand[{}][i] = AND();", and_i)); + lines.push(format!( + "\t\tand[{}][i].a <== states[i][{}];", + and_i, prev_i_num + )); + + if eq_outputs.len() == 1 { + lines.push(format!( + "\t\tand[{}][i].b <== {}[{}][i].out;", + and_i, eq_outputs[0].0, eq_outputs[0].1 + )); + } else if eq_outputs.len() > 1 { + let eq_outputs_key = serde_json::to_string(&eq_outputs).unwrap(); + + if multi_or_checks1.get(&eq_outputs_key).is_none() { + lines.push(format!( + "\t\tmulti_or[{}][i] = MultiOR({});", + multi_or_i, + eq_outputs.len() + )); + + for (output_i, (eq_type, eq_i)) in eq_outputs.iter().enumerate() { + lines.push(format!( + "\t\tmulti_or[{}][i].in[{}] <== {}[{}][i].out;", + multi_or_i, output_i, eq_type, eq_i + )); + } + + lines.push(format!( + "\t\tand[{}][i].b <== multi_or[{}][i].out;", + and_i, multi_or_i + )); + multi_or_checks1.insert(eq_outputs_key, multi_or_i); + multi_or_i += 1; + } else { + if let Some(multi_or_i) = multi_or_checks1.get(&eq_outputs_key) { + lines.push(format!( + "\t\tand[{}][i].b <== multi_or[{}][i].out;", + and_i, multi_or_i + )); + } + } + } + + outputs.push(and_i); + and_i += 1; + } + + if outputs.len() == 1 { + lines.push(format!( + "\t\tstates[i+1][{}] <== and[{}][i].out;", + i, outputs[0] + )); + } else if outputs.len() > 1 { + let outputs_key = serde_json::to_string(&outputs).unwrap(); + + if multi_or_checks2.get(&outputs_key).is_none() { + lines.push(format!( + "\t\tmulti_or[{}][i] = MultiOR({});", + multi_or_i, + outputs.len() + )); + + for (output_i, and_i) in outputs.iter().enumerate() { + lines.push(format!( + "\t\tmulti_or[{}][i].in[{}] <== and[{}][i].out;", + multi_or_i, output_i, and_i + )); + } + + lines.push(format!( + "\t\tstates[i+1][{}] <== multi_or[{}][i].out;", + i, multi_or_i + )); + multi_or_checks2.insert(outputs_key, multi_or_i); + multi_or_i += 1; + } else { + if let Some(multi_or_i_) = multi_or_checks2.get(&outputs_key) { + lines.push(format!( + "\t\tstates[i+1][{}] <== multi_or[{}][i].out;", + i, multi_or_i_ + )); + } + } + } + + lines.push(format!( + "\t\tstate_changed[i].in[{}] <== states[i+1][{}];", + i - 1, + i + )); + } + + lines.push("\t\tstates[i+1][0] <== 1 - state_changed[i].out;".to_string()); + + let mut declarations = vec![]; + declarations.push("pragma circom 2.1.5;\n".to_string()); + declarations + .push("include \"@zk-email/zk-regex-circom/circuits/regex_helpers.circom\";\n".to_string()); + declarations.push(format!( + "// regex: {}", + regex_str.replace("\n", "\\n").replace("\r", "\\r"), + )); + declarations.push(format!("template {}(msg_bytes) {{", template_name)); + declarations.push("\tsignal input msg[msg_bytes];".to_string()); + declarations.push("\tsignal output out;\n".to_string()); + declarations.push("\tvar num_bytes = msg_bytes+1;".to_string()); + declarations.push("\tsignal in[num_bytes];".to_string()); + declarations.push("\tin[0]<==255;".to_string()); + declarations.push("\tfor (var i = 0; i < msg_bytes; i++) {".to_string()); + declarations.push("\t\tin[i+1] <== msg[i];".to_string()); + declarations.push("\t}\n".to_string()); + + if eq_i > 0 { + declarations.push(format!("\tcomponent eq[{}][num_bytes];", eq_i)); + } + + if lt_i > 0 { + declarations.push(format!("\tcomponent lt[{}][num_bytes];", lt_i)); + } + + if and_i > 0 { + declarations.push(format!("\tcomponent and[{}][num_bytes];", and_i)); + } + + if multi_or_i > 0 { + declarations.push(format!("\tcomponent multi_or[{}][num_bytes];", multi_or_i)); + } + + declarations.push(format!("\tsignal states[num_bytes+1][{}];", n)); + declarations.push("\tcomponent state_changed[num_bytes];\n".to_string()); + + let mut init_code = vec![]; + init_code.push("\tstates[0][0] <== 1;".to_string()); + init_code.push(format!("\tfor (var i = 1; i < {}; i++) {{", n)); + init_code.push("\t\tstates[0][i] <== 0;".to_string()); + init_code.push("\t}\n".to_string()); + + let mut final_code = declarations + .into_iter() + .chain(init_code) + .chain(lines) + .collect::>(); + final_code.push("\t}".to_string()); + + let accept_node = accept_nodes_array[0]; + let mut accept_lines = vec![]; + + accept_lines.push("".to_string()); + accept_lines.push("\tcomponent final_state_result = MultiOR(num_bytes+1);".to_string()); + accept_lines.push("\tfor (var i = 0; i <= num_bytes; i++) {".to_string()); + accept_lines.push(format!( + "\t\tfinal_state_result.in[i] <== states[i][{}];", + accept_node + )); + accept_lines.push("\t}".to_string()); + accept_lines.push("\tout <== final_state_result.out;".to_string()); + + final_code.extend(accept_lines); + + final_code.join("\n") +} + impl RegexAndDFA { pub fn gen_circom( &self, @@ -15,7 +356,7 @@ impl RegexAndDFA { template_name: &str, gen_substrs: bool, ) -> Result<(), CompilerError> { - let circom = gen_circom_allstr(&self.dfa_val, template_name, &self.regex_str)?; + let circom = gen_circom_allstr(&self.dfa_val, template_name, &self.regex_str); if gen_substrs { self.add_substrs_constraints(circom_path, circom)?; } else { @@ -31,22 +372,20 @@ impl RegexAndDFA { circom_path: &PathBuf, mut circom: String, ) -> Result<(), CompilerError> { - let accepted_state = - get_accepted_state(&self.dfa_val).ok_or(JsCallerError::NoAcceptedState)?; + let accepted_state = get_accepted_state(&self.dfa_val).unwrap(); circom += "\n"; circom += "\tsignal is_consecutive[msg_bytes+1][2];\n"; circom += "\tis_consecutive[msg_bytes][1] <== 1;\n"; circom += "\tfor (var i = 0; i < msg_bytes; i++) {\n"; - circom += &format!("\t\tis_consecutive[msg_bytes-1-i][0] <== states[num_bytes-i][{}] * (1 - is_consecutive[msg_bytes-i][1]) + is_consecutive[msg_bytes-i][1];\n",accepted_state); + circom += &format!("\t\tis_consecutive[msg_bytes-1-i][0] <== states[num_bytes-i][{}] * (1 - is_consecutive[msg_bytes-i][1]) + is_consecutive[msg_bytes-i][1];\n", accepted_state); circom += "\t\tis_consecutive[msg_bytes-1-i][1] <== state_changed[msg_bytes-i].out * is_consecutive[msg_bytes-1-i][0];\n"; circom += "\t}\n"; let substr_defs_array = &self.substrs_defs.substr_defs_array; - // circom += &format!( - // "\t// substrings calculated: {:?}\n", - // &self.substrs_defs.substr_defs_array - // ); - + circom += &format!( + "\t// substrings calculated: {:?}\n", + &self.substrs_defs.substr_defs_array + ); for (idx, defs) in substr_defs_array.into_iter().enumerate() { let num_defs = defs.len(); circom += &format!("\tsignal is_substr{}[msg_bytes][{}];\n", idx, num_defs + 1); diff --git a/packages/compiler/src/gen_circom.js b/packages/compiler/src/gen_circom.js deleted file mode 100644 index 00de96e..0000000 --- a/packages/compiler/src/gen_circom.js +++ /dev/null @@ -1,322 +0,0 @@ -"use strict"; -function genCircomAllstr(graph_json, template_name, regex_str = "") { - /** - * This function generates a Circom circuit from a given graph_json, template_name, and regex_str. - * @param {Object} graph_json - The graph in JSON format. - * @param {string} template_name - The name to be used for the Circom template. - * @param {string} regex_str - The regular expression string, used only to print in a comment at the top. - */ - const N = graph_json.length; - // console.log(JSON.stringify(graph_json, null, 2)); - // const graph = Array(N).fill({}); - const rev_graph = {}; - const to_init_graph = []; - let init_going_state = null; - for (let i = 0; i < N; i++) { - rev_graph[i] = {}; - to_init_graph.push([]); - } - const accept_nodes = new Set(); - for (let i = 0; i < N; i++) { - const node = graph_json[i]; - for (let k in node.edges) { - const v = node.edges[k]; - rev_graph[v][i] = Array.from(JSON.parse(k)).map((c) => c.charCodeAt(0)); - if (i === 0) { - const index = rev_graph[v][i].indexOf(94); - if (index !== -1) { - init_going_state = v; - rev_graph[v][i][index] = 255; - } - for (let j = 0; j < rev_graph[v][i].length; j++) { - if (rev_graph[v][i][j] == 255) { - continue; - } - to_init_graph[v].push(rev_graph[v][i][j]); - } - } - } - if (node.type == "accept") { - accept_nodes.add(i); - } - } - if (init_going_state !== null) { - for (const [going_state, chars] of Object.entries(to_init_graph)) { - const going_state_num = Number(going_state); - if (chars.length === 0) { - continue; - } - if (rev_graph[going_state_num][init_going_state] == null) { - rev_graph[going_state_num][init_going_state] = []; - } - rev_graph[going_state_num][init_going_state] = - rev_graph[going_state_num][init_going_state].concat(chars); - } - } - if (accept_nodes.size === 0) { - throw new Error("accept node must exist"); - } - const accept_nodes_array = [...accept_nodes]; - if (accept_nodes_array.length !== 1) { - throw new Error("the size of accept nodes must be one"); - } - let eq_i = 0; - let lt_i = 0; - let and_i = 0; - let multi_or_i = 0; - const range_checks = new Array(256); - for (let i = 0; i < 256; i++) { - range_checks[i] = new Array(256); - } - const eq_checks = new Array(256); - const multi_or_checks1 = {}; - const multi_or_checks2 = {}; - let lines = []; - lines.push(`\tfor (var i = 0; i < num_bytes; i++) {`); - // const uppercase = new Set(Array.from("ABCDEFGHIJKLMNOPQRSTUVWXYZ").map(c => c.charCodeAt())); - // const lowercase = new Set(Array.from("abcdefghijklmnopqrstuvwxyz").map(c => c.charCodeAt())); - // const digits = new Set(Array.from("0123456789").map(c => c.charCodeAt())); - // const symbols1 = new Set([":", ";", "<", "=", ">", "?", "@"].map(c => c.charCodeAt())); - // const symbols2 = new Set(["[", "\\", "]", "^", "_", "`"].map(c => c.charCodeAt())); - // const symbols3 = new Set(["{", "|", "}", "~"].map(c => c.charCodeAt())); - lines.push(`\t\tstate_changed[i] = MultiOR(${N - 1});`); - for (let i = 1; i < N; i++) { - const outputs = []; - // let is_negates = []; - for (const prev_i of Object.keys(rev_graph[i])) { - const prev_i_num = Number(prev_i); - const k = rev_graph[i][prev_i_num]; - k.sort((a, b) => Number(a) - Number(b)); - const eq_outputs = []; - let vals = new Set(k); - // let is_negate = false; - // if (vals.has(0xff)) { - // vals.delete(0xff); - // is_negate = true; - // } - if (vals.size === 0) { - continue; - } - // if (is_negate === true) { - // for (let another_i = 1; another_i < N; another_i++) { - // if (i === another_i) { - // continue; - // } - // if (rev_graph[another_i][prev_i] === null) { - // continue; - // } - // const another_vals = new Set(rev_graph[another_i][prev_i]); - // if (another_vals.size === 0) { - // continue; - // } - // for (let another_val of another_vals) { - // vals.add(another_val); - // } - // } - // } - const min_maxes = []; - let cur_min = k[0]; - let cur_max = k[0]; - for (let idx = 1; idx < k.length; ++idx) { - if (cur_max === k[idx]) { - continue; - } - else if (cur_max + 1 === k[idx]) { - cur_max += 1; - } - else { - if (cur_max - cur_min >= 16) { - min_maxes.push([cur_min, cur_max]); - } - cur_min = k[idx]; - cur_max = k[idx]; - } - } - if (cur_max - cur_min >= 16) { - min_maxes.push([cur_min, cur_max]); - } - for (const min_max of min_maxes) { - for (let code = min_max[0]; code <= min_max[1]; ++code) { - vals.delete(code); - } - } - // for (let subsets of [ - // [digits, 47, 58], - // [symbols1, 57, 65], - // [uppercase, 64, 91], - // [symbols2, 90, 97], - // [lowercase, 96, 123], - // [symbols3, 122, 127] - // ]) { - // const subset = subsets[0]; - // const min = subsets[1]; - // const max = subsets[2]; - // if (vals.isSuperset(subset)) { - // vals.difference(subset); - // if (min_maxs.length == 0) { - // min_maxs.push([min, max]); - // } else { - // const last = min_maxs[min_maxs.length - 1]; - // if (last[1] - 1 == min) { - // min_maxs[min_maxs.length - 1][1] = max; - // } else { - // min_maxs.push([min, max]); - // } - // } - // } - // } - for (let min_max of min_maxes) { - const min = min_max[0]; - const max = min_max[1]; - if (range_checks[min][max] === undefined) { - lines.push(`\t\tlt[${lt_i}][i] = LessEqThan(8);`); - lines.push(`\t\tlt[${lt_i}][i].in[0] <== ${min};`); - lines.push(`\t\tlt[${lt_i}][i].in[1] <== in[i];`); - lines.push(`\t\tlt[${lt_i + 1}][i] = LessEqThan(8);`); - lines.push(`\t\tlt[${lt_i + 1}][i].in[0] <== in[i];`); - lines.push(`\t\tlt[${lt_i + 1}][i].in[1] <== ${max};`); - lines.push(`\t\tand[${and_i}][i] = AND();`); - lines.push(`\t\tand[${and_i}][i].a <== lt[${lt_i}][i].out;`); - lines.push(`\t\tand[${and_i}][i].b <== lt[${lt_i + 1}][i].out;`); - eq_outputs.push(["and", and_i]); - range_checks[min][max] = [lt_i, and_i]; - lt_i += 2; - and_i += 1; - } - else { - let [_, and_i] = range_checks[min][max]; - eq_outputs.push(["and", and_i]); - } - } - for (let code of vals) { - if (eq_checks[code] === undefined) { - lines.push(`\t\teq[${eq_i}][i] = IsEqual();`); - lines.push(`\t\teq[${eq_i}][i].in[0] <== in[i];`); - lines.push(`\t\teq[${eq_i}][i].in[1] <== ${code};`); - eq_outputs.push(["eq", eq_i]); - eq_checks[code] = eq_i; - eq_i += 1; - } - else { - eq_outputs.push(["eq", eq_checks[code]]); - } - } - lines.push(`\t\tand[${and_i}][i] = AND();`); - lines.push(`\t\tand[${and_i}][i].a <== states[i][${prev_i}];`); - if (eq_outputs.length === 1) { - // if (is_negate) { - // lines.push(`\t\tand[${and_i}][i].b <== 1 - ${eq_outputs[0][0]}[${eq_outputs[0][1]}][i].out;`); - // } else { - // lines.push(`\t\tand[${and_i}][i].b <== ${eq_outputs[0][0]}[${eq_outputs[0][1]}][i].out;`); - // } - lines.push(`\t\tand[${and_i}][i].b <== ${eq_outputs[0][0]}[${eq_outputs[0][1]}][i].out;`); - } - else if (eq_outputs.length > 1) { - const eq_outputs_key = JSON.stringify(eq_outputs); - if (multi_or_checks1[eq_outputs_key] === undefined) { - lines.push(`\t\tmulti_or[${multi_or_i}][i] = MultiOR(${eq_outputs.length});`); - for (let output_i = 0; output_i < eq_outputs.length; output_i++) { - lines.push(`\t\tmulti_or[${multi_or_i}][i].in[${output_i}] <== ${eq_outputs[output_i][0]}[${eq_outputs[output_i][1]}][i].out;`); - } - // if (is_negate) { - // lines.push(`\t\tand[${and_i}][i].b <== 1 - multi_or[${multi_or_i}][i].out;`); - // } else { - // lines.push(`\t\tand[${and_i}][i].b <== multi_or[${multi_or_i}][i].out;`); - // } - lines.push(`\t\tand[${and_i}][i].b <== multi_or[${multi_or_i}][i].out;`); - multi_or_checks1[eq_outputs_key] = multi_or_i; - multi_or_i += 1; - } - else { - lines.push(`\t\tand[${and_i}][i].b <== multi_or[${multi_or_checks1[eq_outputs_key]}][i].out;`); - } - } - outputs.push(and_i); - and_i += 1; - } - if (outputs.length === 1) { - lines.push(`\t\tstates[i+1][${i}] <== and[${outputs[0]}][i].out;`); - } - else if (outputs.length > 1) { - const outputs_key = JSON.stringify(outputs); - if (multi_or_checks2[outputs_key] === undefined) { - lines.push(`\t\tmulti_or[${multi_or_i}][i] = MultiOR(${outputs.length});`); - for (let output_i = 0; output_i < outputs.length; output_i++) { - lines.push(`\t\tmulti_or[${multi_or_i}][i].in[${output_i}] <== and[${outputs[output_i]}][i].out;`); - } - lines.push(`\t\tstates[i+1][${i}] <== multi_or[${multi_or_i}][i].out;`); - multi_or_checks2[outputs_key] = multi_or_i; - multi_or_i += 1; - } - else { - lines.push(`\t\tstates[i+1][${i}] <== multi_or[${multi_or_checks2[outputs_key]}][i].out;`); - } - } - lines.push(`\t\tstate_changed[i].in[${i - 1}] <== states[i+1][${i}];`); - } - lines.push(`\t\tstates[i+1][0] <== 1 - state_changed[i].out;`); - lines.push("\t}"); - const declarations = []; - declarations.push(`pragma circom 2.1.5;\n`); - declarations.push(`include "@zk-email/zk-regex-circom/circuits/regex_helpers.circom";\n`); - // declarations.push(`pragma circom 2.1.5;\ninclude "@zk-email/circuits/regexes/regex_helpers.circom";\n`); - declarations.push(`// regex: ${regex_str.replace(/\n/g, "\\n")}`); - declarations.push(`template ${template_name}(msg_bytes) {`); - declarations.push(`\tsignal input msg[msg_bytes];`); - declarations.push(`\tsignal output out;\n`); - declarations.push(`\tvar num_bytes = msg_bytes+1;`); - declarations.push(`\tsignal in[num_bytes];`); - declarations.push(`\tin[0]<==255;`); - declarations.push(`\tfor (var i = 0; i < msg_bytes; i++) {`); - declarations.push(`\t\tin[i+1] <== msg[i];`); - declarations.push(`\t}\n`); - if (eq_i > 0) { - declarations.push(`\tcomponent eq[${eq_i}][num_bytes];`); - } - if (lt_i > 0) { - declarations.push(`\tcomponent lt[${lt_i}][num_bytes];`); - } - if (and_i > 0) { - declarations.push(`\tcomponent and[${and_i}][num_bytes];`); - } - if (multi_or_i > 0) { - declarations.push(`\tcomponent multi_or[${multi_or_i}][num_bytes];`); - } - declarations.push(`\tsignal states[num_bytes+1][${N}];`); - declarations.push(`\tcomponent state_changed[num_bytes];`); - declarations.push(""); - const init_code = []; - init_code.push(`\tstates[0][0] <== 1;`); - init_code.push(`\tfor (var i = 1; i < ${N}; i++) {`); - init_code.push(`\t\tstates[0][i] <== 0;`); - init_code.push("\t}"); - init_code.push(""); - lines = declarations.concat(init_code).concat(lines); - const accept_node = accept_nodes_array[0]; - const accept_lines = [""]; - accept_lines.push("\tcomponent final_state_result = MultiOR(num_bytes+1);"); - accept_lines.push("\tfor (var i = 0; i <= num_bytes; i++) {"); - accept_lines.push(`\t\tfinal_state_result.in[i] <== states[i][${accept_node}];`); - accept_lines.push("\t}"); - accept_lines.push("\tout <== final_state_result.out;"); - lines = lines.concat(accept_lines); - let string = lines.reduce((res, line) => res + line + "\n", ""); - return string; -} -// Commented these two out as they're only used by the code that's also commented out -// Set.prototype.isSuperset = function (subset) { -// if (this.size === 0) { -// return false; -// } -// for (var elem of subset) { -// if (!this.has(elem)) { -// return false; -// } -// } -// return true; -// } -// Set.prototype.difference = function (setB) { -// for (let elem of setB) { -// this.delete(elem) -// } -// } diff --git a/packages/compiler/src/gen_circom.ts b/packages/compiler/src/gen_circom.ts deleted file mode 100644 index 164a693..0000000 --- a/packages/compiler/src/gen_circom.ts +++ /dev/null @@ -1,374 +0,0 @@ -type Graph = { - type: string; - edges: Record; -}[]; - -function genCircomAllstr( - graph_json: Graph, - template_name: string, - regex_str = "" -): string { - /** - * This function generates a Circom circuit from a given graph_json, template_name, and regex_str. - * @param {Object} graph_json - The graph in JSON format. - * @param {string} template_name - The name to be used for the Circom template. - * @param {string} regex_str - The regular expression string, used only to print in a comment at the top. - */ - - const N = graph_json.length; - // console.log(JSON.stringify(graph_json, null, 2)); - // const graph = Array(N).fill({}); - const rev_graph: Record> = {}; - const to_init_graph: number[][] = []; - let init_going_state: number | null = null; - - for (let i = 0; i < N; i++) { - rev_graph[i] = {}; - to_init_graph.push([]); - } - - const accept_nodes: Set = new Set(); - for (let i = 0; i < N; i++) { - const node = graph_json[i]; - for (let k in node.edges) { - const v: number = node.edges[k]; - rev_graph[v][i] = Array.from(JSON.parse(k)).map((c) => - (c as string).charCodeAt(0) - ); - if (i === 0) { - const index = rev_graph[v][i].indexOf(94); - if (index !== -1) { - init_going_state = v; - rev_graph[v][i][index] = 255; - } - for (let j = 0; j < rev_graph[v][i].length; j++) { - if (rev_graph[v][i][j] == 255) { - continue; - } - to_init_graph[v].push(rev_graph[v][i][j]); - } - } - } - if (node.type == "accept") { - accept_nodes.add(i); - } - } - - if (init_going_state !== null) { - for (const [going_state, chars] of Object.entries(to_init_graph)) { - const going_state_num = Number(going_state); - if (chars.length === 0) { - continue; - } - if (rev_graph[going_state_num][init_going_state] == null) { - rev_graph[going_state_num][init_going_state] = []; - } - rev_graph[going_state_num][init_going_state] = - rev_graph[going_state_num][init_going_state].concat(chars); - } - } - - if (accept_nodes.size === 0) { - throw new Error("accept node must exist"); - } - const accept_nodes_array = [...accept_nodes]; - if (accept_nodes_array.length !== 1) { - throw new Error("the size of accept nodes must be one"); - } - - let eq_i: number = 0; - let lt_i: number = 0; - let and_i: number = 0; - let multi_or_i: number = 0; - - const range_checks: number[][][] = new Array(256); - for (let i = 0; i < 256; i++) { - range_checks[i] = new Array(256); - } - const eq_checks: number[] = new Array(256); - const multi_or_checks1: Record = {}; - const multi_or_checks2: Record = {}; - - let lines: string[] = []; - lines.push(`\tfor (var i = 0; i < num_bytes; i++) {`); - - // const uppercase = new Set(Array.from("ABCDEFGHIJKLMNOPQRSTUVWXYZ").map(c => c.charCodeAt())); - // const lowercase = new Set(Array.from("abcdefghijklmnopqrstuvwxyz").map(c => c.charCodeAt())); - // const digits = new Set(Array.from("0123456789").map(c => c.charCodeAt())); - // const symbols1 = new Set([":", ";", "<", "=", ">", "?", "@"].map(c => c.charCodeAt())); - // const symbols2 = new Set(["[", "\\", "]", "^", "_", "`"].map(c => c.charCodeAt())); - // const symbols3 = new Set(["{", "|", "}", "~"].map(c => c.charCodeAt())); - lines.push(`\t\tstate_changed[i] = MultiOR(${N - 1});`); - - for (let i = 1; i < N; i++) { - const outputs: number[] = []; - // let is_negates = []; - for (const prev_i of Object.keys(rev_graph[i])) { - const prev_i_num = Number(prev_i); - const k = rev_graph[i][prev_i_num]; - k.sort((a, b) => Number(a) - Number(b)); - const eq_outputs: [string, number][] = []; - let vals: Set = new Set(k); - // let is_negate = false; - // if (vals.has(0xff)) { - // vals.delete(0xff); - // is_negate = true; - // } - if (vals.size === 0) { - continue; - } - // if (is_negate === true) { - // for (let another_i = 1; another_i < N; another_i++) { - // if (i === another_i) { - // continue; - // } - // if (rev_graph[another_i][prev_i] === null) { - // continue; - // } - // const another_vals = new Set(rev_graph[another_i][prev_i]); - // if (another_vals.size === 0) { - // continue; - // } - // for (let another_val of another_vals) { - // vals.add(another_val); - // } - // } - // } - const min_maxes: [number, number][] = []; - let cur_min: number = k[0]; - let cur_max: number = k[0]; - - for (let idx = 1; idx < k.length; ++idx) { - if (cur_max === k[idx]) { - continue; - } else if (cur_max + 1 === k[idx]) { - cur_max += 1; - } else { - if (cur_max - cur_min >= 16) { - min_maxes.push([cur_min, cur_max]); - } - cur_min = k[idx]; - cur_max = k[idx]; - } - } - - if (cur_max - cur_min >= 16) { - min_maxes.push([cur_min, cur_max]); - } - for (const min_max of min_maxes) { - for (let code = min_max[0]; code <= min_max[1]; ++code) { - vals.delete(code); - } - } - - // for (let subsets of [ - // [digits, 47, 58], - // [symbols1, 57, 65], - // [uppercase, 64, 91], - // [symbols2, 90, 97], - // [lowercase, 96, 123], - // [symbols3, 122, 127] - // ]) { - // const subset = subsets[0]; - // const min = subsets[1]; - // const max = subsets[2]; - // if (vals.isSuperset(subset)) { - // vals.difference(subset); - // if (min_maxs.length == 0) { - // min_maxs.push([min, max]); - // } else { - // const last = min_maxs[min_maxs.length - 1]; - // if (last[1] - 1 == min) { - // min_maxs[min_maxs.length - 1][1] = max; - // } else { - // min_maxs.push([min, max]); - // } - // } - // } - // } - - for (let min_max of min_maxes) { - const min: number = min_max[0]; - const max: number = min_max[1]; - if (range_checks[min][max] === undefined) { - lines.push(`\t\tlt[${lt_i}][i] = LessEqThan(8);`); - lines.push(`\t\tlt[${lt_i}][i].in[0] <== ${min};`); - lines.push(`\t\tlt[${lt_i}][i].in[1] <== in[i];`); - - lines.push(`\t\tlt[${lt_i + 1}][i] = LessEqThan(8);`); - lines.push(`\t\tlt[${lt_i + 1}][i].in[0] <== in[i];`); - lines.push(`\t\tlt[${lt_i + 1}][i].in[1] <== ${max};`); - - lines.push(`\t\tand[${and_i}][i] = AND();`); - lines.push(`\t\tand[${and_i}][i].a <== lt[${lt_i}][i].out;`); - lines.push(`\t\tand[${and_i}][i].b <== lt[${lt_i + 1}][i].out;`); - - eq_outputs.push(["and", and_i]); - range_checks[min][max] = [lt_i, and_i]; - lt_i += 2; - and_i += 1; - } else { - let [_, and_i] = range_checks[min][max]; - eq_outputs.push(["and", and_i]); - } - } - for (let code of vals) { - if (eq_checks[code] === undefined) { - lines.push(`\t\teq[${eq_i}][i] = IsEqual();`); - lines.push(`\t\teq[${eq_i}][i].in[0] <== in[i];`); - lines.push(`\t\teq[${eq_i}][i].in[1] <== ${code};`); - eq_outputs.push(["eq", eq_i]); - eq_checks[code] = eq_i; - eq_i += 1; - } else { - eq_outputs.push(["eq", eq_checks[code]]); - } - } - - lines.push(`\t\tand[${and_i}][i] = AND();`); - lines.push(`\t\tand[${and_i}][i].a <== states[i][${prev_i}];`); - if (eq_outputs.length === 1) { - // if (is_negate) { - // lines.push(`\t\tand[${and_i}][i].b <== 1 - ${eq_outputs[0][0]}[${eq_outputs[0][1]}][i].out;`); - // } else { - // lines.push(`\t\tand[${and_i}][i].b <== ${eq_outputs[0][0]}[${eq_outputs[0][1]}][i].out;`); - // } - lines.push( - `\t\tand[${and_i}][i].b <== ${eq_outputs[0][0]}[${eq_outputs[0][1]}][i].out;` - ); - } else if (eq_outputs.length > 1) { - const eq_outputs_key: string = JSON.stringify(eq_outputs); - if (multi_or_checks1[eq_outputs_key] === undefined) { - lines.push( - `\t\tmulti_or[${multi_or_i}][i] = MultiOR(${eq_outputs.length});` - ); - for (let output_i = 0; output_i < eq_outputs.length; output_i++) { - lines.push( - `\t\tmulti_or[${multi_or_i}][i].in[${output_i}] <== ${eq_outputs[output_i][0]}[${eq_outputs[output_i][1]}][i].out;` - ); - } - // if (is_negate) { - // lines.push(`\t\tand[${and_i}][i].b <== 1 - multi_or[${multi_or_i}][i].out;`); - // } else { - // lines.push(`\t\tand[${and_i}][i].b <== multi_or[${multi_or_i}][i].out;`); - // } - lines.push( - `\t\tand[${and_i}][i].b <== multi_or[${multi_or_i}][i].out;` - ); - multi_or_checks1[eq_outputs_key] = multi_or_i; - multi_or_i += 1; - } else { - lines.push( - `\t\tand[${and_i}][i].b <== multi_or[${multi_or_checks1[eq_outputs_key]}][i].out;` - ); - } - } - - outputs.push(and_i); - and_i += 1; - } - - if (outputs.length === 1) { - lines.push(`\t\tstates[i+1][${i}] <== and[${outputs[0]}][i].out;`); - } else if (outputs.length > 1) { - const outputs_key: string = JSON.stringify(outputs); - if (multi_or_checks2[outputs_key] === undefined) { - lines.push( - `\t\tmulti_or[${multi_or_i}][i] = MultiOR(${outputs.length});` - ); - for (let output_i = 0; output_i < outputs.length; output_i++) { - lines.push( - `\t\tmulti_or[${multi_or_i}][i].in[${output_i}] <== and[${outputs[output_i]}][i].out;` - ); - } - lines.push(`\t\tstates[i+1][${i}] <== multi_or[${multi_or_i}][i].out;`); - multi_or_checks2[outputs_key] = multi_or_i; - multi_or_i += 1; - } else { - lines.push( - `\t\tstates[i+1][${i}] <== multi_or[${multi_or_checks2[outputs_key]}][i].out;` - ); - } - } - - lines.push(`\t\tstate_changed[i].in[${i - 1}] <== states[i+1][${i}];`); - } - - lines.push(`\t\tstates[i+1][0] <== 1 - state_changed[i].out;`); - lines.push("\t}"); - - const declarations: string[] = []; - declarations.push(`pragma circom 2.1.5;\n`); - declarations.push( - `include "@zk-email/zk-regex-circom/circuits/regex_helpers.circom";\n` - ); - // declarations.push(`pragma circom 2.1.5;\ninclude "@zk-email/circuits/regexes/regex_helpers.circom";\n`); - declarations.push(`// regex: ${regex_str.replace(/\n/g, "\\n")}`); - declarations.push(`template ${template_name}(msg_bytes) {`); - declarations.push(`\tsignal input msg[msg_bytes];`); - declarations.push(`\tsignal output out;\n`); - declarations.push(`\tvar num_bytes = msg_bytes+1;`); - declarations.push(`\tsignal in[num_bytes];`); - declarations.push(`\tin[0]<==255;`); - declarations.push(`\tfor (var i = 0; i < msg_bytes; i++) {`); - declarations.push(`\t\tin[i+1] <== msg[i];`); - declarations.push(`\t}\n`); - if (eq_i > 0) { - declarations.push(`\tcomponent eq[${eq_i}][num_bytes];`); - } - if (lt_i > 0) { - declarations.push(`\tcomponent lt[${lt_i}][num_bytes];`); - } - if (and_i > 0) { - declarations.push(`\tcomponent and[${and_i}][num_bytes];`); - } - if (multi_or_i > 0) { - declarations.push(`\tcomponent multi_or[${multi_or_i}][num_bytes];`); - } - declarations.push(`\tsignal states[num_bytes+1][${N}];`); - declarations.push(`\tcomponent state_changed[num_bytes];`); - declarations.push(""); - - const init_code: string[] = []; - init_code.push(`\tstates[0][0] <== 1;`); - init_code.push(`\tfor (var i = 1; i < ${N}; i++) {`); - init_code.push(`\t\tstates[0][i] <== 0;`); - init_code.push("\t}"); - init_code.push(""); - - lines = declarations.concat(init_code).concat(lines); - - const accept_node: number = accept_nodes_array[0]; - const accept_lines = [""]; - accept_lines.push("\tcomponent final_state_result = MultiOR(num_bytes+1);"); - accept_lines.push("\tfor (var i = 0; i <= num_bytes; i++) {"); - accept_lines.push( - `\t\tfinal_state_result.in[i] <== states[i][${accept_node}];` - ); - accept_lines.push("\t}"); - accept_lines.push("\tout <== final_state_result.out;"); - - lines = lines.concat(accept_lines); - let string: string = lines.reduce((res, line) => res + line + "\n", ""); - return string; -} - -// Commented these two out as they're only used by the code that's also commented out - -// Set.prototype.isSuperset = function (subset) { -// if (this.size === 0) { -// return false; -// } -// for (var elem of subset) { -// if (!this.has(elem)) { -// return false; -// } -// } -// return true; -// } - -// Set.prototype.difference = function (setB) { -// for (let elem of setB) { -// this.delete(elem) -// } -// } \ No newline at end of file diff --git a/packages/compiler/src/halo2.rs b/packages/compiler/src/halo2.rs index ec0ee23..568657e 100644 --- a/packages/compiler/src/halo2.rs +++ b/packages/compiler/src/halo2.rs @@ -1,104 +1,100 @@ -use crate::js_caller::*; -use crate::*; +// use crate::js_caller::*; +// use crate::*; -use itertools::Itertools; +// use itertools::Itertools; +// use std::io::BufWriter; +// use std::io::Write; +// use std::path::PathBuf; +// use std::{fs::File}; +// impl RegexAndDFA { +// pub fn gen_halo2_tables( +// &self, +// allstr_file_path: &PathBuf, +// substr_file_pathes: &[PathBuf], +// gen_substrs: bool, +// ) -> Result<(), CompilerError> { +// let regex_text = self.dfa_to_regex_def_text()?; +// let mut regex_file = File::create(allstr_file_path)?; +// write!(regex_file, "{}", regex_text)?; +// regex_file.flush()?; +// if !gen_substrs { +// return Ok(()); +// } +// let substr_endpoints_array = self.substrs_defs.substr_endpoints_array.as_ref().unwrap(); +// // let max_bytes = self.substrs_defs.max_bytes.as_ref().unwrap(); +// for (idx, defs) in self.substrs_defs.substr_defs_array.iter().enumerate() { +// let mut writer = BufWriter::new(File::create(&substr_file_pathes[idx])?); +// // let max_size = max_bytes[idx]; +// // writer.write_fmt(format_args!("{}\n", &max_size))?; +// // writer.write_fmt(format_args!("0\n{}\n", self.max_byte_size - 1))?; +// let mut starts_str = "".to_string(); +// let starts = substr_endpoints_array[idx] +// .0 +// .iter() +// .sorted_by(|a, b| a.cmp(b)); +// for start in starts { +// starts_str += &format!("{} ", start); +// } +// writer.write_fmt(format_args!("{}\n", starts_str))?; +// let mut ends_str = "".to_string(); +// let ends = substr_endpoints_array[idx] +// .1 +// .iter() +// .sorted_by(|a, b| a.cmp(b)); +// for end in ends { +// ends_str += &format!("{} ", end); +// } +// writer.write_fmt(format_args!("{}\n", ends_str))?; +// let mut defs = defs.iter().collect::>(); +// defs.sort_by(|a, b| { +// let start_cmp = a.0.cmp(&b.0); +// let end_cmp = a.1.cmp(&b.1); +// if start_cmp == std::cmp::Ordering::Equal { +// end_cmp +// } else { +// start_cmp +// } +// }); +// for (cur, next) in defs.iter() { +// writer.write_fmt(format_args!("{} {}\n", cur, next))?; +// } +// } +// Ok(()) +// } -use std::io::BufWriter; -use std::io::Write; - -use std::path::PathBuf; -use std::{fs::File}; - - -impl RegexAndDFA { - pub fn gen_halo2_tables( - &self, - allstr_file_path: &PathBuf, - substr_file_pathes: &[PathBuf], - gen_substrs: bool, - ) -> Result<(), CompilerError> { - let regex_text = self.dfa_to_regex_def_text()?; - let mut regex_file = File::create(allstr_file_path)?; - write!(regex_file, "{}", regex_text)?; - regex_file.flush()?; - if !gen_substrs { - return Ok(()); - } - let substr_endpoints_array = self.substrs_defs.substr_endpoints_array.as_ref().unwrap(); - // let max_bytes = self.substrs_defs.max_bytes.as_ref().unwrap(); - for (idx, defs) in self.substrs_defs.substr_defs_array.iter().enumerate() { - let mut writer = BufWriter::new(File::create(&substr_file_pathes[idx])?); - // let max_size = max_bytes[idx]; - // writer.write_fmt(format_args!("{}\n", &max_size))?; - // writer.write_fmt(format_args!("0\n{}\n", self.max_byte_size - 1))?; - let mut starts_str = "".to_string(); - let starts = substr_endpoints_array[idx] - .0 - .iter() - .sorted_by(|a, b| a.cmp(b)); - for start in starts { - starts_str += &format!("{} ", start); - } - writer.write_fmt(format_args!("{}\n", starts_str))?; - let mut ends_str = "".to_string(); - let ends = substr_endpoints_array[idx] - .1 - .iter() - .sorted_by(|a, b| a.cmp(b)); - for end in ends { - ends_str += &format!("{} ", end); - } - writer.write_fmt(format_args!("{}\n", ends_str))?; - let mut defs = defs.iter().collect::>(); - defs.sort_by(|a, b| { - let start_cmp = a.0.cmp(&b.0); - let end_cmp = a.1.cmp(&b.1); - if start_cmp == std::cmp::Ordering::Equal { - end_cmp - } else { - start_cmp - } - }); - for (cur, next) in defs.iter() { - writer.write_fmt(format_args!("{} {}\n", cur, next))?; - } - } - Ok(()) - } - - pub fn dfa_to_regex_def_text(&self) -> Result { - let accepted_state = - get_accepted_state(&self.dfa_val).ok_or(JsCallerError::NoAcceptedState)?; - let max_state = get_max_state(&self.dfa_val)?; - let mut text = "0\n".to_string(); - text += &format!("{}\n", accepted_state.to_string()); - text += &format!("{}\n", max_state.to_string()); - for (i, val) in self.dfa_val.iter().enumerate() { - for (key, next_node_val) in val["edges"] - .as_object() - .ok_or(JsCallerError::InvalidEdges(val["edges"].clone()))? - .iter() - { - let key_list: Vec = serde_json::from_str(&key)?; - for key_char in key_list.iter() { - let key_char: char = key_char.chars().collect::>()[0]; - let next_node = next_node_val - .as_u64() - .ok_or(JsCallerError::InvalidNodeValue(next_node_val.clone()))? - as usize; - // println!("i {} next {} char {}", i, next_node, key_char as u8); - text += &format!( - "{} {} {}\n", - i.to_string(), - next_node.to_string(), - (key_char as u8).to_string() - ); - } - } - } - Ok(text) - } -} +// pub fn dfa_to_regex_def_text(&self) -> Result { +// let accepted_state = +// get_accepted_state(&self.dfa_val).ok_or(JsCallerError::NoAcceptedState)?; +// let max_state = get_max_state(&self.dfa_val)?; +// let mut text = "0\n".to_string(); +// text += &format!("{}\n", accepted_state.to_string()); +// text += &format!("{}\n", max_state.to_string()); +// for (i, val) in self.dfa_val.iter().enumerate() { +// for (key, next_node_val) in val["edges"] +// .as_object() +// .ok_or(JsCallerError::InvalidEdges(val["edges"].clone()))? +// .iter() +// { +// let key_list: Vec = serde_json::from_str(&key)?; +// for key_char in key_list.iter() { +// let key_char: char = key_char.chars().collect::>()[0]; +// let next_node = next_node_val +// .as_u64() +// .ok_or(JsCallerError::InvalidNodeValue(next_node_val.clone()))? +// as usize; +// // println!("i {} next {} char {}", i, next_node, key_char as u8); +// text += &format!( +// "{} {} {}\n", +// i.to_string(), +// next_node.to_string(), +// (key_char as u8).to_string() +// ); +// } +// } +// } +// Ok(text) +// } +// } diff --git a/packages/compiler/src/js_caller.rs b/packages/compiler/src/js_caller.rs deleted file mode 100644 index 5938a56..0000000 --- a/packages/compiler/src/js_caller.rs +++ /dev/null @@ -1,55 +0,0 @@ - - -use js_sandbox::{JsError, Script}; - -use serde_json::Value; -use thiserror::Error; - -#[derive(Error, Debug)] -pub enum JsCallerError { - #[error("Edges {0} are not object")] - InvalidEdges(Value), - #[error("node value {0} is not u64")] - InvalidNodeValue(Value), - #[error("No accepted state")] - NoAcceptedState, - #[error(transparent)] - JsError(#[from] JsError), - #[error(transparent)] - JsonError(#[from] serde_json::Error), -} - -// pub fn catch_all_regex_str() -> Result { -// let code: &'static str = include_str!("regex.js"); -// let mut script = Script::from_string(code)?; -// let result: String = script.call("catchAllRegexStr", ())?; -// Ok(result) -// } - -pub fn text_context_prefix() -> Result { - let code: &'static str = include_str!("regex.js"); - let mut script = Script::from_string(code)?; - let result: String = script.call("textContextPrefix", ())?; - Ok(result) -} - -// pub fn format_regex_printable(regex: &str) -> Result { -// let code: &'static str = include_str!("regex.js"); -// let mut script = Script::from_string(code)?; -// let result: String = script.call("formatRegexPrintable", (regex,))?; -// Ok(result) -// } - -pub fn regex_to_dfa(regex: &str) -> Result, JsCallerError> { - let code: &'static str = include_str!("regex.js"); - let mut script = Script::from_string(code)?; - let result: String = script.call("regexToDfa", (regex,))?; - Ok(serde_json::from_str(&result)?) -} - -pub fn gen_circom_allstr(graph: &[Value], template_name: &str, regex_str: &str) -> Result { - let code: &'static str = include_str!("gen_circom.js"); - let mut script = Script::from_string(code)?; - let result: String = script.call("genCircomAllstr", (graph, template_name, regex_str))?; - Ok(result) -} diff --git a/packages/compiler/src/lib.rs b/packages/compiler/src/lib.rs index 7f46f6e..14f6f33 100644 --- a/packages/compiler/src/lib.rs +++ b/packages/compiler/src/lib.rs @@ -1,24 +1,21 @@ +use std::fs::File; use std::iter::FromIterator; -use std::{collections::HashMap, fs::File}; pub mod circom; pub mod halo2; -pub mod js_caller; - pub mod node; +pub mod regex; // #[cfg(test)] // mod tests; use crate::node::*; +use crate::regex::*; use neon; -use crate::js_caller::*; -use fancy_regex::Regex; use itertools::Itertools; use petgraph::prelude::*; use serde::{Deserialize, Serialize}; -use serde_json::Value; -use std::collections::HashSet; +use std::collections::{BTreeMap, BTreeSet}; use std::path::PathBuf; use thiserror::Error; @@ -28,8 +25,6 @@ pub enum CompilerError { #[error("No edge from {:?} to {:?} in the graph",.0,.1)] NoEdge(NodeIndex, NodeIndex), #[error(transparent)] - JsCallerError(#[from] JsCallerError), - #[error(transparent)] IoError(#[from] std::io::Error), #[error(transparent)] RegexError(#[from] fancy_regex::Error), @@ -62,19 +57,31 @@ pub enum SoldityType { Decimal, } +#[derive(Debug, Clone)] +pub struct DFAState { + r#type: String, + state: usize, + edges: BTreeMap>, +} + +#[derive(Debug, Clone)] +pub struct DFAGraph { + states: Vec, +} + #[derive(Debug, Clone)] pub struct RegexAndDFA { // pub max_byte_size: usize, // Original regex string, only here to be printed in generated file to make it more reproducible pub regex_str: String, - pub dfa_val: Vec, + pub dfa_val: DFAGraph, pub substrs_defs: SubstrsDefs, } #[derive(Debug, Clone)] pub struct SubstrsDefs { - pub substr_defs_array: Vec>, - pub substr_endpoints_array: Option, HashSet)>>, + pub substr_defs_array: Vec>, + pub substr_endpoints_array: Option, BTreeSet)>>, // pub max_bytes: Option>, } @@ -85,239 +92,7 @@ pub struct SubstrsDefsJson { impl DecomposedRegexConfig { pub fn to_regex_and_dfa(&self) -> Result { - let mut all_regex = String::new(); - let part_configs = &self.parts; - for config in part_configs.iter() { - all_regex += &config.regex_def; - } - let dfa_val = regex_to_dfa(&all_regex)?; - // println!("dfa_val {:?}", dfa_val); - let substrs_defs = self.extract_substr_ids(&dfa_val)?; - Ok(RegexAndDFA { - // max_byte_size: self.max_byte_size, - regex_str: all_regex, - dfa_val, - substrs_defs, - }) - } - - pub fn extract_substr_ids(&self, dfa_val: &[Value]) -> Result { - let part_configs = &self.parts; - let mut graph = Graph::::with_capacity(0, 0); - let max_state = get_max_state(dfa_val)?; - add_graph_nodes(dfa_val, &mut graph, None, max_state)?; - let accepted_state = get_accepted_state(dfa_val).ok_or(JsCallerError::NoAcceptedState)?; - let accepted_state_index = NodeIndex::from(accepted_state); - let mut pathes = Vec::>>::new(); - let mut stack = Vec::<(NodeIndex, Vec>)>::new(); - stack.push((accepted_state_index, vec![accepted_state_index])); - let mut self_nodes = HashSet::new(); - let mut self_nodes_char = HashMap::new(); - for state in 0..=max_state { - let node = NodeIndex::from(state); - if let Some(edge) = graph.find_edge(node, node) { - let str = graph.edge_weight(edge).unwrap().to_string(); - let bytes = str.as_bytes(); - self_nodes_char.insert(node.index(), bytes[0]); - } - } - - while stack.len() != 0 { - let (node, path) = stack.pop().unwrap(); - let mut parents = graph.neighbors(node).detach(); - while let Some((edge, parent)) = parents.next(&graph) { - if parent.index() == node.index() { - self_nodes.insert(node.index()); - graph.remove_edge(edge).unwrap(); - continue; - } - if !path.contains(&parent) { - if parent.index() == 0 { - pathes.push(path.to_vec()); - continue; - } - stack.push((parent, vec![path.clone(), vec![parent]].concat())); - } - } - } - - let mut public_config_indexes: Vec = vec![]; - let mut part_regexes = vec![]; - for (idx, config) in part_configs.iter().enumerate() { - if config.is_public { - public_config_indexes.push(idx); - } - let mut this_regex = config.regex_def.to_string(); - if let Some(mut idx) = this_regex.find("[^") { - let mut new_regex = this_regex[0..idx].to_string(); - new_regex += "["; - idx += 2; - let end = this_regex.find("]").unwrap(); - let mut chars_in_brancket = vec![]; - while idx < end { - let char = this_regex.chars().nth(idx).unwrap(); - if char == '\\' { - chars_in_brancket - .push(format!("\\{}", this_regex.chars().nth(idx + 1).unwrap())); - idx += 2; - } else { - chars_in_brancket.push(char.to_string()); - idx += 1; - } - } - for code in 0..255 { - let code_char = char::from_u32(code).unwrap(); - let mut code_str = code_char.to_string(); - if [ - '(', ')', '*', '+', '.', '?', '[', '\\', ']', '^', '`', '|', '-', - ] - .contains(&code_char) - { - code_str = format!("\\{}", code_char); - } - if chars_in_brancket.contains(&code_str) { - continue; - } - new_regex += &code_str; - } - new_regex += &this_regex[end..].to_string(); - this_regex = new_regex; - } - this_regex = this_regex.replace("^", "\\^"); - if idx == 0 { - part_regexes.push(Regex::new(&this_regex)?); - } else { - let pre_regex = part_regexes[idx - 1].to_string(); - part_regexes.push(Regex::new(&(pre_regex + &this_regex))?); - } - } - let num_public_parts = public_config_indexes.len(); - let mut substr_defs_array = (0..num_public_parts) - .map(|_| HashSet::<(usize, usize)>::new()) - .collect_vec(); - let mut substr_endpoints_array = (0..num_public_parts) - .map(|_| (HashSet::::new(), HashSet::::new())) - .collect_vec(); - for path in pathes.iter_mut() { - let n = path.len(); - path.append(&mut vec![NodeIndex::from(0)]); - let edges = (0..n) - .map(|idx| { - graph - .find_edge(path[idx], path[idx + 1]) - .ok_or(CompilerError::NoEdge(path[idx], path[idx + 1])) - }) - .collect::>, CompilerError>>()?; - let string_vec = edges - .iter() - .map(|edge| graph.edge_weight(*edge).unwrap().to_string()) - .collect::>(); - let path_states = path - .into_iter() - .rev() - .map(|node| node.index()) - .collect::>(); - let path_strs = string_vec - .iter() - .rev() - .map(|s| s.to_string()) - .collect::>(); - let substr_states = self.get_substr_defs_from_path( - &path_states, - &path_strs, - &part_regexes, - &public_config_indexes, - )?; - for (substr_idx, (path_states, substr)) in substr_states.into_iter().enumerate() { - let defs = &mut substr_defs_array[substr_idx]; - substr_endpoints_array[substr_idx].0.insert(path_states[0]); - substr_endpoints_array[substr_idx] - .1 - .insert(path_states[path_states.len() - 1]); - for path_idx in 0..(path_states.len() - 1) { - defs.insert((path_states[path_idx], path_states[path_idx + 1])); - if self_nodes.contains(&path_states[path_idx]) { - defs.insert((path_states[path_idx], path_states[path_idx])); - } - for pre_path_idx in 0..=path_idx { - if graph - .find_edge( - NodeIndex::from(path_states[pre_path_idx]), - NodeIndex::from(path_states[path_idx + 1]), - ) - .is_some() - { - defs.insert((path_states[path_idx + 1], path_states[pre_path_idx])); - } - } - } - if self_nodes.contains(&path_states[path_states.len() - 1]) { - let part_index = public_config_indexes[substr_idx]; - let part_regex = &part_regexes[part_index]; - let byte = self_nodes_char[&path_states[path_states.len() - 1]]; - let substr = substr + &(byte as char).to_string(); - if part_regex.is_match(&substr).unwrap() { - defs.insert(( - path_states[path_states.len() - 1], - path_states[path_states.len() - 1], - )); - } - } - } - } - // let max_bytes = public_config_indexes - // .iter() - // .map(|idx| self.parts[*idx].max_size) - // .collect_vec(); - let substrs_defs = SubstrsDefs { - substr_defs_array, - substr_endpoints_array: Some(substr_endpoints_array), - // max_bytes: Some(max_bytes), - }; - Ok(substrs_defs) - } - - fn get_substr_defs_from_path( - &self, - path_states: &[usize], - path_strs: &[String], - part_regexes: &[Regex], - public_config_indexes: &[usize], - ) -> Result, String)>, CompilerError> { - debug_assert_eq!(path_states.len(), path_strs.len() + 1); - let mut concat_str = String::new(); - for str in path_strs.into_iter() { - let first_chars = str.as_bytes(); - concat_str += &(first_chars[0] as char).to_string(); - } - let index_ends = part_regexes - .iter() - .map(|regex| { - // println!("regex {}", regex); - // println!("concat_str {}", concat_str); - let found = regex.find(&concat_str).unwrap().unwrap(); - // println!("found {:?}", found); - if found.start() == found.end() { - found.end() + 1 - } else { - found.end() - } - }) - .collect_vec(); - let mut substr_results = vec![]; - for index in public_config_indexes.iter() { - let start = if *index == 0 { - 0 - } else { - index_ends[index - 1] - }; - let end = index_ends[*index]; - substr_results.push(( - path_states[(start)..=end].to_vec(), - concat_str[0..=(end - 1)].to_string(), - )); - } - Ok(substr_results) + Ok(regex_and_dfa(self)) } } @@ -327,11 +102,11 @@ impl RegexAndDFA { regex_str: &str, substrs_defs_json: SubstrsDefsJson, ) -> Result { - let dfa_val = regex_to_dfa(regex_str)?; + let dfa_val = dfa_from_regex_str(regex_str); let substr_defs_array = substrs_defs_json .transitions .into_iter() - .map(|transitions_array| HashSet::<(usize, usize)>::from_iter(transitions_array)) + .map(|transitions_array| BTreeSet::<(usize, usize)>::from_iter(transitions_array)) .collect_vec(); let substrs_defs = SubstrsDefs { substr_defs_array, @@ -370,11 +145,11 @@ pub fn gen_from_decomposed( // num_public_parts += 1; // } // } - // let substr_file_pathes = (0..num_public_parts) + // let substr_file_paths = (0..num_public_parts) // .map(|idx| halo2_dir_path.join(format!("substr_{}.txt", idx))) // .collect_vec(); // regex_and_dfa - // .gen_halo2_tables(&allstr_file_path, &substr_file_pathes, gen_substrs) + // .gen_halo2_tables(&allstr_file_path, &substr_file_paths, gen_substrs) // .expect("failed to generate halo2 tables"); // } if let Some(circom_file_path) = circom_file_path { @@ -413,11 +188,11 @@ pub fn gen_from_raw( // if let Some(halo2_dir_path) = halo2_dir_path { // let halo2_dir_path = PathBuf::from(halo2_dir_path); // let allstr_file_path = halo2_dir_path.join("allstr.txt"); - // let substr_file_pathes = (0..num_public_parts) + // let substr_file_paths = (0..num_public_parts) // .map(|idx| halo2_dir_path.join(format!("substr_{}.txt", idx))) // .collect_vec(); // regex_and_dfa - // .gen_halo2_tables(&allstr_file_path, &substr_file_pathes, gen_substrs) + // .gen_halo2_tables(&allstr_file_path, &substr_file_paths, gen_substrs) // .expect("failed to generate halo2 tables"); // } if let Some(circom_file_path) = circom_file_path { @@ -430,99 +205,24 @@ pub fn gen_from_raw( } } -pub(crate) fn get_accepted_state(dfa_val: &[Value]) -> Option { - for i in 0..dfa_val.len() { - if dfa_val[i]["type"] == "accept" { +pub(crate) fn get_accepted_state(dfa_val: &DFAGraph) -> Option { + for i in 0..dfa_val.states.len() { + if dfa_val.states[i].r#type == "accept" { return Some(i as usize); } } None } -pub(crate) fn get_max_state(dfa_val: &[Value]) -> Result { - let mut max_state = 0; - for (_i, val) in dfa_val.iter().enumerate() { - for (_, next_node_val) in val["edges"] - .as_object() - .ok_or(JsCallerError::InvalidEdges(val["edges"].clone()))? - .iter() - { - let next_node = next_node_val - .as_u64() - .ok_or(JsCallerError::InvalidNodeValue(next_node_val.clone()))? - as usize; - if next_node > max_state { - max_state = next_node; - } - } - } - Ok(max_state) -} - -pub(crate) fn add_graph_nodes( - dfa_val: &[Value], - graph: &mut Graph, - last_max_state: Option, - next_max_state: usize, -) -> Result<(), JsCallerError> { - let first_new_state = match last_max_state { - Some(v) => v + 1, - None => 0, - }; - for idx in first_new_state..=next_max_state { - graph.add_node(idx == next_max_state); - } - - for (i, val) in dfa_val.iter().enumerate() { - for (key, next_node_val) in val["edges"] - .as_object() - .ok_or(JsCallerError::InvalidEdges(val["edges"].clone()))? - .iter() - { - let next_node = next_node_val - .as_u64() - .ok_or(JsCallerError::InvalidNodeValue(next_node_val.clone()))? - as usize; - if let Some(max) = last_max_state { - if i <= max && next_node <= max { - continue; - } - } - let key_list: Vec = serde_json::from_str::>(&key)? - .iter() - .filter(|s| s.as_str() != "\u{ff}") - .cloned() - .collect_vec(); - // let mut key_str = String::new(); - // for key_char in key_list.iter() { - // // println!("key_char {}", key_char); - // assert!(key_char.len() == 1); - // // key_str += key_char; - // } - if key_list.len() == 0 { - continue; - } - let mut key = None; - for key_idx in 0..key_list.len() { - let char = key_list[key_idx].chars().nth(0).unwrap(); - if (char as u8) < 10 || (char as u8) > 127 { - continue; - } - if key_list[key_idx].as_bytes().len() == 1 { - key = Some(char); - break; - } - } - // assert_eq!(key_list[key_idx].as_bytes().len(), 1); - graph.add_edge( - NodeIndex::from(next_node), - NodeIndex::from(i), - key.expect("there is no representative character."), - ); - } - } - Ok(()) -} +// pub(crate) fn get_max_state(dfa_val: &DFAGraph) -> usize { +// let mut max_state = 0; +// for (_i, val) in dfa_val.states.iter().enumerate() { +// if val.state > max_state { +// max_state = val.state; +// } +// } +// max_state +// } #[cfg(feature = "export_neon_main")] #[neon::main] @@ -535,7 +235,6 @@ fn main(mut cx: neon::prelude::ModuleContext) -> neon::prelude::NeonResult<()> { #[cfg(test)] mod tests { use super::*; - use std::path::Path; #[test] fn test_gen_from_decomposed() { @@ -546,13 +245,11 @@ mod tests { let circom_template_name = Some("SubjectAllRegex"); let gen_substrs = Some(true); - let result = gen_from_decomposed( + let _result = gen_from_decomposed( decomposed_regex_path.to_str().unwrap(), Some(circom_file_path.to_str().unwrap()), circom_template_name.map(|s| s), gen_substrs, ); - - // assert!(result.is_ok()); } } diff --git a/packages/compiler/src/node.rs b/packages/compiler/src/node.rs index 0932771..eefc713 100644 --- a/packages/compiler/src/node.rs +++ b/packages/compiler/src/node.rs @@ -7,12 +7,12 @@ pub(crate) fn gen_from_decomposed_node(mut cx: FunctionContext) -> JsResult(0)?.value(&mut cx); println!("Decomposed regex path: {}", decomposed_regex_path); let obj = cx.argument::(1)?; - println!("Object: {:?}", obj); let circom_file_path = obj .get_opt::(&mut cx, "circomFilePath")? .map(|v| { - let path = v.to_string(&mut cx) + let path = v + .to_string(&mut cx) .expect("circomFilePath must be null or string") .value(&mut cx); println!("Circom file path: {}", path); @@ -21,7 +21,8 @@ pub(crate) fn gen_from_decomposed_node(mut cx: FunctionContext) -> JsResult(&mut cx, "templateName")? .map(|v| { - let name = v.to_string(&mut cx) + let name = v + .to_string(&mut cx) .expect("templateName must be null or string") .value(&mut cx); println!("Circom template name: {}", name); @@ -30,7 +31,8 @@ pub(crate) fn gen_from_decomposed_node(mut cx: FunctionContext) -> JsResult(&mut cx, "genSubstrs")? .map(|v| { - let gen = v.as_value(&mut cx) + let gen = v + .as_value(&mut cx) .downcast::(&mut cx) .expect("genSubstrs must be null or boolean") .value(&mut cx); diff --git a/packages/compiler/src/regex.js b/packages/compiler/src/regex.js deleted file mode 100644 index 8ce6818..0000000 --- a/packages/compiler/src/regex.js +++ /dev/null @@ -1,807 +0,0 @@ -"use strict"; -/* eslint-disable no-prototype-builtins */ -/*jslint browser: true*/ -const a2z_nosep = "abcdefghijklmnopqrstuvwxyz"; -const A2Z_nosep = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; -const a2f_nosep = "abcdef"; -const A2F_nosep = "ABCDEF"; -const r0to9_nosep = "0123456789"; -const escapeMap = { n: "\n", r: "\r", t: "\t", v: "\v", f: "\f" }; -const whitespace = Object.values(escapeMap); -const slash_s = whitespace.join("|"); -/** - * Parse regex to a min DFA spec - * to support some shorthands that make regex easier to write e.g. [A-Z] - */ -function regexToMinDFASpec(str) { - // Replace all A-Z with A2Z etc - let combined_nosep = str - .replaceAll("A-Z", A2Z_nosep) - .replaceAll("a-z", a2z_nosep) - .replaceAll("A-F", A2F_nosep) - .replaceAll("a-f", a2f_nosep) - .replaceAll("0-9", r0to9_nosep) - .replaceAll("\\w", A2Z_nosep + r0to9_nosep + a2z_nosep + "_") - .replaceAll("\\d", r0to9_nosep) - .replaceAll("\\s", slash_s); - // .replaceAll("\\w", A2Z_nosep + r0to9_nosep + a2z_nosep); // I think that there's also an underscore here - // function addPipeInsideBrackets(str: string): string { - // let result: string = ""; - // let insideBrackets: boolean = false; - // for (let i = 0; i < str.length; i++) { - // if (str[i] === "[") { - // result += str[i]; - // insideBrackets = true; - // continue; - // } else if (str[i] === "]") { - // insideBrackets = false; - // } - // let str_to_add = str[i]; - // if (str[i] === "\\") { - // i++; - // str_to_add += str[i]; - // } - // result += insideBrackets ? "|" + str_to_add : str_to_add; - // } - // return result.replaceAll("[|", "[").replaceAll("[", "(").replaceAll("]", ")"); - // } - // function makeCurlyBracesFallback(str) { - // let result = ""; - // let insideBrackets = false; - // for (let i = 0; i < str.length; i++) { - // if (str[i] === "{") { - // result += str[i]; - // insideBrackets = true; - // continue; - // } else if (str[i] === "}") { - // insideBrackets = false; - // } - // result += insideBrackets ? "|" + str[i] : str[i]; - // } - // return result.replaceAll("[|", "[").replaceAll("[", "(").replaceAll("]", ")"); - // } - // function checkIfBracketsHavePipes(str: string): boolean { - // let result: boolean = true; - // let insideBrackets: boolean = false; - // let insideParens: number = 0; - // let indexAt: number = 0; - // for (let i = 0; i < str.length; i++) { - // if (indexAt >= str.length) break; - // if (str[indexAt] === "[") { - // insideBrackets = true; - // indexAt++; - // continue; - // } else if (str[indexAt] === "]") { - // insideBrackets = false; - // } - // if (str[indexAt] === "(") { - // insideParens++; - // } else if (str[indexAt] === ")") { - // insideParens--; - // } - // if (insideBrackets) { - // if (str[indexAt] === "|") { - // indexAt++; - // } else { - // result = false; - // return result; - // } - // } - // if (!insideParens && str[indexAt] === "|") { - // console.log("Error: | outside of parens!"); - // } - // if (str[indexAt] === "\\") { - // indexAt++; - // } - // indexAt++; - // } - // return result; - // } - // let combined; - // if (!checkIfBracketsHavePipes(combined_nosep)) { - // // console.log("Adding pipes within brackets between everything!"); - // combined = addPipeInsideBrackets(combined_nosep); - // if (!checkIfBracketsHavePipes(combined)) { - // console.log("Did not add brackets correctly!"); - // } - // } else { - // combined = combined_nosep; - // } - return combined_nosep; -} -/** - * Try parsing simple regular expression to syntax tree. - * - * Basic grammars: - * Empty: S -> ϵ - * Cat: S -> S S - * Or: S -> S | S - * Star: S -> S * - * Text: S -> [0-9a-zA-Z] - * S -> ( S ) - * - * Extension: - * Plus: S -> S + -> S S * - * Ques: S -> S ? -> (S | ϵ) - * - * @param {string} text The input regular expression - * @return {string|object} Returns a string that is an error message if failed to parse the expression, - * otherwise returns an object which is the syntax tree. - */ -function parseRegex(text) { - text = regexToMinDFASpec(text); - 'use strict'; - function parseSub(text, begin, end, first) { - var i, sub, last = 0, node = { - begin: begin, - end: end, - }, virNode, tempNode, stack = 0, parts = []; - if (text.length === 0) { - return 'Error: empty input at ' + begin + '.'; - } - if (first) { - for (i = 0; i <= text.length; i += 1) { - if (i === text.length || (text[i] === '|' && stack === 0)) { - if (last === 0 && i === text.length) { - return parseSub(text, begin + last, begin + i, false); - } - sub = parseSub(text.slice(last, i), begin + last, begin + i, true); - if (typeof sub === 'string') { - return sub; - } - parts.push(sub); - last = i + 1; - } - else if (text[i] === '(') { - stack += 1; - } - else if (text[i] === ')') { - stack -= 1; - } - } - if (parts.length === 1) { - return parts[0]; - } - node.type = 'or'; - node.parts = parts; - } - else { - for (i = 0; i < text.length; i += 1) { - if (text[i] === '(') { - last = i + 1; - i += 1; - stack = 1; - while (i < text.length && stack !== 0) { - if (text[i] === '(') { - stack += 1; - } - else if (text[i] === ')') { - stack -= 1; - } - i += 1; - } - if (stack !== 0) { - return `Error: missing right parentheses for ${begin + last}.`; - } - i -= 1; - sub = parseSub(text.slice(last, i), begin + last, begin + i, true); - if (typeof sub === 'string') { - return sub; - } - sub.begin -= 1; - sub.end += 1; - parts.push(sub); - // } else if (text[i] === '[') { - // last = i + 1; - // i += 1; - // if (text[i] === '^') { - // text[i] = '\u{ff}'; - // } - // stack = 1; - // while (i < text.length && stack !== 0) { - // if (text[i] === ']') { - // stack -= 1; - // } - // i += 1; - // } - // if (stack !== 0) { - // return 'Error: missing right brakets for ' + (begin + last) + '.'; - // } - // i -= 1; - // sub = parseSub(text.slice(last, i), begin + last, begin + i, true); - // if (typeof sub === 'string') { - // return sub; - // } - // sub.begin -= 1; - // sub.end += 1; - // parts.push(sub); - } - else if (text[i] === '*') { - if (parts.length === 0) { - return `Error: unexpected * at ${begin + i}.`; - } - tempNode = { begin: parts[parts.length - 1].begin, end: parts[parts.length - 1].end + 1 }; - tempNode.type = 'star'; - tempNode.sub = parts[parts.length - 1]; - parts[parts.length - 1] = tempNode; - } - else if (text[i] === '+') { - if (parts.length === 0) { - return `Error: unexpected + at ${begin + i}.`; - } - virNode = { begin: parts[parts.length - 1].begin, end: parts[parts.length - 1].end + 1 }; - virNode.type = 'star'; - virNode.sub = parts[parts.length - 1]; - tempNode = { begin: parts[parts.length - 1].begin, end: parts[parts.length - 1].end + 1 }; - tempNode.type = 'cat'; - tempNode.parts = [parts[parts.length - 1], virNode]; - parts[parts.length - 1] = tempNode; - } - else if (text[i] === '?') { - if (parts.length === 0) { - return `Error: unexpected ? at ${begin + i}.`; - } - virNode = { begin: parts[parts.length - 1].begin, end: parts[parts.length - 1].end + 1 }; - virNode.type = 'empty'; - virNode.sub = parts[parts.length - 1]; - tempNode = { begin: parts[parts.length - 1].begin, end: parts[parts.length - 1].end + 1 }; - tempNode.type = 'or'; - tempNode.parts = [parts[parts.length - 1], virNode]; - parts[parts.length - 1] = tempNode; - } - else if (text[i] === 'ϵ') { - tempNode = { begin: begin + i, end: begin + i + 1 }; - tempNode.type = 'empty'; - parts.push(tempNode); - } - else if (Array.isArray(text[i])) { - tempNode = { begin: begin + i, end: begin + i + 1 }; - tempNode.type = 'text'; - tempNode.text = text[i][0]; - parts.push(tempNode); - } - else { - tempNode = { begin: begin + i, end: begin + i + 1 }; - tempNode.type = 'text'; - tempNode.text = text[i]; - parts.push(tempNode); - } - } - // console.log(`parts ${JSON.stringify(parts)}`); - if (parts.length === 1) { - return parts[0]; - } - node.type = 'cat'; - node.parts = parts; - } - return node; - } - let char; - let new_text = []; - let i = 0; - let is_in_brancket = false; - let brancket_text = []; - while (i < text.length) { - char = text[i]; - if (text[i] == '\\') { - char = [text[i + 1]]; - // new_text.push([text[i + 1]]); - i += 1; - } - if (char === '[') { - if (is_in_brancket) { - return `Error: unexpected [ at ${i}.`; - } - is_in_brancket = true; - brancket_text = []; - // new_text.push(char); - i += 1; - } - else if (char === ']') { - if (!is_in_brancket) { - return `Error: unexpected ] at ${i}.`; - } - is_in_brancket = false; - if (brancket_text[0] === '^') { - brancket_text.shift(); - let rev_text = []; - let code_char = ''; - const brancket_text_jsons = brancket_text.map(val => JSON.stringify(val)); - for (let idx = 0; idx < 255; idx++) { - code_char = String.fromCodePoint(idx); - if ([ - '(', - ')', - '*', - '+', - '.', - '?', - '[', - '\\', - ']', - '^', - '`', - '|', - '-' - ].indexOf(code_char) != -1) { - code_char = [code_char]; - } - if (brancket_text_jsons.indexOf(JSON.stringify(code_char)) === -1) { - rev_text.push(code_char); - } - } - brancket_text = rev_text; - } - new_text.push('('); - for (const c of brancket_text) { - new_text.push(c); - new_text.push('|'); - } - new_text = new_text.slice(0, -1); - new_text.push(')'); - i += 1; - } - else if (is_in_brancket) { - if (!Array.isArray(char) && ['(', ')', '[', '*', '+', '?', 'ϵ'].includes(char)) { - return `Error: unexpected ${char} at ${i}.`; - } - if (char === '^' && text[i - 1] !== '[') { - return `Error: unexpected ^ at ${i}.`; - } - // new_text.push(char); - // new_text.push('|'); - brancket_text.push(char); - i += 1; - } - else { - new_text.push(char); - i += 1; - } - } - if (is_in_brancket) { - return `Error: missing right brackets.`; - } - return parseSub(new_text, 0, new_text.length, true); -} -/** -* Convert regular expression to nondeterministic finite automaton. -* -* @param {string} text @see parseRegex() -* @return {object|string} -*/ -function regexToNfa(text) { - 'use strict'; - function generateGraph(node, start, end, count) { - var i, last, temp, tempStart, tempEnd; - if (!start.hasOwnProperty('id')) { - start.id = count; - count += 1; - } - switch (node.type) { - case 'empty': - start.edges.push(['ϵ', end]); - break; - case 'text': - start.edges.push([node.text, end]); - break; - case 'cat': - last = start; - for (i = 0; i < node.parts.length - 1; i += 1) { - temp = { 'type': '', 'edges': [] }; - count = generateGraph(node.parts[i], last, temp, count); - last = temp; - } - count = generateGraph(node.parts[node.parts.length - 1], last, end, count); - break; - case 'or': - for (i = 0; i < node.parts.length; i += 1) { - tempStart = { 'type': '', 'edges': [] }; - tempEnd = { 'type': '', 'edges': [['ϵ', end]] }; - start.edges.push(['ϵ', tempStart]); - count = generateGraph(node.parts[i], tempStart, tempEnd, count); - } - break; - case 'star': - tempStart = { 'type': '', 'edges': [] }; - tempEnd = { 'type': '', 'edges': [['ϵ', tempStart], ['ϵ', end]] }; - start.edges.push(['ϵ', tempStart]); - start.edges.push(['ϵ', end]); - count = generateGraph(node.sub, tempStart, tempEnd, count); - break; - } - if (!end.hasOwnProperty('id')) { - end.id = count; - count += 1; - } - return count; - } - var ast = parseRegex(text), start = { 'type': 'start', 'edges': [] }, accept = { 'type': 'accept', 'edges': [] }; - if (typeof ast === 'string') { - return ast; - } - generateGraph(ast, start, accept, 0); - return start; -} -/** -* Convert nondeterministic finite automaton to deterministic finite automaton. -* -* @param {object} nfa @see regexToNfa(), the function assumes that the given NFA is valid. -* @return {object} dfa Returns the first element of the DFA. -*/ -function nfaToDfa(nfa) { - 'use strict'; - function getClosure(nodes) { - var i, closure = [], stack = [], symbols = [], type = '', top; - for (i = 0; i < nodes.length; i += 1) { - stack.push(nodes[i]); - closure.push(nodes[i]); - if (nodes[i].type === 'accept') { - type = 'accept'; - } - } - while (stack.length > 0) { - top = stack.pop(); - // If top is of type string and starts with "Error" then return error - if (typeof top === 'string' && top[0] === 'E' && !top) { - continue; - } - for (i = 0; i < top.edges.length; i += 1) { - if (top.edges[i][0] === 'ϵ') { - if (closure.indexOf(top.edges[i][1]) < 0) { - stack.push(top.edges[i][1]); - closure.push(top.edges[i][1]); - if (top.edges[i][1].type === 'accept') { - type = 'accept'; - } - } - } - else { - if (symbols.indexOf(top.edges[i][0]) < 0) { - symbols.push(top.edges[i][0]); - } - } - } - } - closure.sort((a, b) => { - if (a.id && b.id) { - return a.id > b.id ? 1 : -1; - } - return 0; - }); - symbols.sort(); - return { - id: '', - 'key': closure.map(function (x) { - return x.id; - }).join(','), - 'items': closure, - 'symbols': symbols, - 'type': type, - 'edges': [], - 'trans': {}, - 'nature': 0, - }; - } - function getClosedMove(closure, symbol) { - var i, j, node, nexts = []; - for (i = 0; i < closure.items.length; i += 1) { - node = closure.items[i]; - for (j = 0; j < node.edges.length; j += 1) { - if (symbol === node.edges[j][0]) { - if (nexts.indexOf(node.edges[j][1]) < 0) { - nexts.push(node.edges[j][1]); - } - } - } - } - return getClosure(nexts); - } - function toAlphaCount(n) { - var a = 'A'.charCodeAt(0), z = 'Z'.charCodeAt(0), len = z - a + 1, s = ''; - while (n >= 0) { - s = String.fromCharCode(n % len + a) + s; - n = Math.floor(n / len) - 1; - } - return s; - } - var i, first = getClosure([nfa]), states = {}, front = 0, top, closure, queue = [first], count = 0; - first.id = toAlphaCount(count); - states[first.key] = first; - while (front < queue.length) { - top = queue[front]; - front += 1; - for (i = 0; i < top.symbols.length; i += 1) { - closure = getClosedMove(top, top.symbols[i]); - if (!states.hasOwnProperty(closure.key)) { - count += 1; - closure.id = toAlphaCount(count); - states[closure.key] = closure; - queue.push(closure); - } - top.trans[top.symbols[i]] = states[closure.key]; - top.edges.push([top.symbols[i], states[closure.key]]); - } - } - return first; -} -/** -* Convert the DFA to its minimum form using Hopcroft's algorithm. -* -* @param {object} dfa @see nfaToDfa(), the function assumes that the given DFA is valid. -* @return {object} dfa Returns the first element of the minimum DFA. -*/ -function minDfa(dfa) { - 'use strict'; - function getReverseEdges(start) { - var i, top, symbol, next, front = 0, queue = [start], visited = {}, symbols = {}, // The input alphabet - idMap = {}, // Map id to states - revEdges = {}; // Map id to the ids which connects to the id with an alphabet - visited[start.id] = true; - while (front < queue.length) { - top = queue[front]; - front += 1; - idMap[top.id] = top; - for (i = 0; i < top.symbols.length; i += 1) { - symbol = top.symbols[i]; - if (!symbols.hasOwnProperty(symbol)) { - symbols[symbol] = true; - } - next = top.trans[symbol]; - if (!revEdges.hasOwnProperty(next.id)) { - revEdges[next.id] = {}; - } - if (!revEdges[next.id].hasOwnProperty(symbol)) { - revEdges[next.id][symbol] = []; - } - revEdges[next.id][symbol].push(top.id); - if (!visited.hasOwnProperty(next.id)) { - visited[next.id] = true; - queue.push(next); - } - } - } - return [Object.keys(symbols), idMap, revEdges]; - } - function hopcroft(symbols, idMap, revEdges) { - const ids = Object.keys(idMap).sort(); - const partitions = {}; - const queue = []; - const visited = {}; - let front = 0; - let top; - let i; - let j; - let k; - let keys; - let key; - let key1; - let key2; - let group1; - let group2; - let symbol; - let revGroup; - group1 = []; - group2 = []; - for (i = 0; i < ids.length; i += 1) { - if (idMap[ids[i]].type === 'accept') { - group1.push(ids[i]); - } - else { - group2.push(ids[i]); - } - } - key = group1.join(','); - partitions[key] = group1; - queue.push(key); - visited[key] = 0; - if (group2.length !== 0) { - key = group2.join(','); - partitions[key] = group2; - queue.push(key); - } - while (front < queue.length) { - top = queue[front]; - front += 1; - if (top) { - top = top.split(','); - for (i = 0; i < symbols.length; i += 1) { - symbol = symbols[i]; - revGroup = {}; - for (j = 0; j < top.length; j += 1) { - if (revEdges.hasOwnProperty(top[j]) && revEdges[top[j]].hasOwnProperty(symbol)) { - for (k = 0; k < revEdges[top[j]][symbol].length; k += 1) { - revGroup[revEdges[top[j]][symbol][k]] = true; - } - } - } - keys = Object.keys(partitions); - for (j = 0; j < keys.length; j += 1) { - key = keys[j]; - group1 = []; - group2 = []; - for (k = 0; k < partitions[key].length; k += 1) { - if (revGroup.hasOwnProperty(partitions[key][k])) { - group1.push(partitions[key][k]); - } - else { - group2.push(partitions[key][k]); - } - } - if (group1.length !== 0 && group2.length !== 0) { - delete partitions[key]; - key1 = group1.join(','); - key2 = group2.join(','); - partitions[key1] = group1; - partitions[key2] = group2; - if (visited.hasOwnProperty(key1)) { - queue[visited[key1]] = null; - visited[key1] = queue.length; - queue.push(key1); - visited[key2] = queue.length; - queue.push(key2); - } - else if (group1.length <= group2.length) { - visited[key1] = queue.length; - queue.push(key1); - } - else { - visited[key2] = queue.length; - queue.push(key2); - } - } - } - } - } - } - return Object.values(partitions); - } - function buildMinNfa(start, partitions, idMap, revEdges) { - var i, j, temp, node, symbol; - const nodes = []; - const group = {}; - const edges = {}; - partitions.sort(function (a, b) { - var ka = a.join(','), kb = b.join(','); - if (ka < kb) { - return -1; - } - if (ka > kb) { - return 1; - } - return 0; - }); - for (i = 0; i < partitions.length; i += 1) { - if (partitions[i].indexOf(start.id.toString()) >= 0) { - if (i > 0) { - temp = partitions[i]; - partitions[i] = partitions[0]; - partitions[0] = temp; - } - break; - } - } - for (i = 0; i < partitions.length; i += 1) { - const node = { - id: (i + 1).toString(), - key: partitions[i].join(','), - items: [], - symbols: [], - type: idMap[partitions[i][0]].type, - edges: [], - trans: {}, - nature: 0, - }; - for (j = 0; j < partitions[i].length; j += 1) { - node.items.push(idMap[partitions[i][j]]); - group[partitions[i][j]] = i; - } - edges[i] = {}; - nodes.push(node); - } - Object.keys(revEdges).forEach(function (to) { - Object.keys(revEdges[to]).forEach(function (symbol) { - revEdges[to][symbol].forEach(function (from) { - if (!edges[group[from]].hasOwnProperty(group[to])) { - edges[group[from]][group[to]] = {}; - } - edges[group[from]][group[to]][symbol] = true; - }); - }); - }); - Object.keys(edges).forEach((from) => { - Object.keys(edges[Number(from)]).forEach((to) => { - const symbol = JSON.stringify(Object.keys(edges[Number(from)][Number(to)]).sort()); - nodes[parseInt(from)].symbols.push(symbol); - nodes[parseInt(from)].edges.push([symbol, nodes[parseInt(to)]]); - nodes[parseInt(from)].trans[symbol] = nodes[parseInt(to)]; - }); - }); - return nodes[0]; - } - var edgesTuple = getReverseEdges(dfa), symbols = edgesTuple[0], idMap = edgesTuple[1], revEdges = edgesTuple[2], partitions = hopcroft(symbols, idMap, revEdges); - return buildMinNfa(dfa, partitions, idMap, revEdges); -} -function toNature(col) { - var i, j, base = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', result = 0; - if ('1' <= col[0] && col[0] <= '9') { - result = parseInt(col, 10); - } - else { - for (i = 0, j = col.length - 1; i < col.length; i += 1, j -= 1) { - result += Math.pow(base.length, j) * (base.indexOf(col[i]) + 1); - } - } - return result; -} -// '(\r\n|\x80)(to|from):([A-Za-z0-9 _."@-]+<)?[a-zA-Z0-9_.-]+@[a-zA-Z0-9_.]+>?\r\n'; -// let regex = '(\r\n|\x80)(to|from):((a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z|A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z|0|1|2|3|4|5|6|7|8|9| |_|.|"|@|-)+<)?(a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z|A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z|0|1|2|3|4|5|6|7|8|9|_|.|-)+@(a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z|A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z|0|1|2|3|4|5|6|7|8|9|_|.|-)+>?\r\n'; -// const key_chars = '(a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z)'; -// const catch_all = '(0|1|2|3|4|5|6|7|8|9|a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z|A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z|!|"|#|$|%|&|\'|\\(|\\)|\\*|\\+|,|-|.|/|:|;|<|=|>|\\?|@|[|\\\\|]|^|_|`|{|\\||}|~| |\t|\n|\r|\x0b|\x0c)'; -// const catch_all_without_semicolon = '(0|1|2|3|4|5|6|7|8|9|a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z|A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z|!|"|#|$|%|&|\'|\\(|\\)|\\*|\\+|,|-|.|/|:|<|=|>|\\?|@|[|\\\\|]|^|_|`|{|\\||}|~| |\t|\n|\r|\x0b|\x0c)'; -// const base_64 = '(a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z|A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z|0|1|2|3|4|5|6|7|8|9|\\+|/|=)'; -// const word_char = '(a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z|A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z|0|1|2|3|4|5|6|7|8|9|_)'; -function regexToDfa(regex) { - let nfa = regexToNfa(regex); - let dfa = minDfa(nfaToDfa(nfa)); - var i, states = {}, nodes = [], stack = [dfa], symbols = []; - while (stack.length > 0) { - const top = stack.pop(); - if (!states.hasOwnProperty(top.id.toString())) { - states[top.id] = top; - top.nature = toNature(top.id.toString()); - nodes.push(top); - for (i = 0; i < top.edges.length; i += 1) { - if (top.edges[i][0] !== 'ϵ' && symbols.indexOf(top.edges[i][0]) < 0) { - symbols.push(top.edges[i][0]); - } - stack.push(top.edges[i][1]); - } - } - } - nodes.sort(function (a, b) { - return a.nature - b.nature; - }); - symbols.sort(); - const graph = []; - for (let i = 0; i < nodes.length; i += 1) { - const curr = {}; - curr.type = nodes[i].type; - curr.edges = {}; - for (let j = 0; j < symbols.length; j += 1) { - if (nodes[i].trans.hasOwnProperty(symbols[j])) { - curr.edges[symbols[j]] = nodes[i].trans[symbols[j]].nature - 1; - } - } - graph[nodes[i].nature - 1] = curr; - } - // console.log(`graph: ${JSON.stringify(graph, null, 2)}`); - return JSON.stringify(graph); -} -// function catchAllRegexStr() { -// return "(0|1|2|3|4|5|6|7|8|9|a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z|A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z|!|\"|#|$|%|&|'|\\(|\\)|\\*|\\+|,|-|.|/|:|;|<|=|>|\\?|@|\\[|\\\\|\\]|\\^|_|`|{|\\||}|~| |\t|\n|\r|\x0b|\x0c)"; -// } -// function catchAllWithoutRNRegexStr() { -// return "(0|1|2|3|4|5|6|7|8|9|a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z|A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z|!|\"|#|$|%|&|'|\\(|\\)|\\*|\\+|,|-|.|/|:|;|<|=|>|\\?|@|[|\\\\|]|^|_|`|{|\\||}|~| |\t|\x0b|\x0c)"; -// } -// function textContextPrefix() { -// return `Content-Type: text/plain; charset="UTF-8"\r\n\r\n`; -// } -// function formatRegexPrintable(s) { -// const escaped_string_json = JSON.stringify(s); -// const escaped_string = escaped_string_json.slice(1, escaped_string_json.length - 1); -// return escaped_string -// .replaceAll("\\\\\\\\", "\\") -// .replaceAll("\\\\", "\\") -// .replaceAll("/", "\\/") -// .replaceAll("\u000b", "\\♥") -// .replaceAll("^", "\\^") -// .replaceAll("$", "\\$") -// .replaceAll("|[|", "|\\[|") -// .replaceAll("|]|", "|\\]|") -// .replaceAll("|.|", "|\\.|") -// .replaceAll("|$|", "|\\$|") -// .replaceAll("|^|", "|\\^|"); -// } -// module.exports = { -// regexToDfa -// }; diff --git a/packages/compiler/src/regex.rs b/packages/compiler/src/regex.rs new file mode 100644 index 0000000..02ae9d3 --- /dev/null +++ b/packages/compiler/src/regex.rs @@ -0,0 +1,350 @@ +use crate::{DFAGraph, DFAState, DecomposedRegexConfig, RegexAndDFA, SubstrsDefs}; +use regex::Regex; +use regex_automata::dfa::{dense::DFA, StartKind}; +use std::collections::{BTreeMap, BTreeSet}; + +#[derive(Debug, Clone)] +struct DFAInfoState { + typ: String, + source: usize, + edges: BTreeMap, +} + +#[derive(Debug)] +struct DFAGraphInfo { + states: Vec, +} + +fn parse_dfa_output(output: &str) -> DFAGraphInfo { + let mut dfa_info = DFAGraphInfo { states: Vec::new() }; + + let re = Regex::new(r"\*?(\d+): ((.+?) => (\d+),?)+").unwrap(); + for captures in re.captures_iter(output) { + let src = captures[1].parse::().unwrap(); + let mut state = DFAInfoState { + source: src, + typ: String::new(), + edges: BTreeMap::new(), + }; + if &captures[0][0..1] == "*" { + state.typ = String::from("accept"); + } + for transition in Regex::new(r"\s+[^=]+\s*=>\s*(\d+)+\s*|\s+=+\s*=>\s*(\d+)+") + .unwrap() + .captures_iter(&captures[0].to_string()) + { + let trimmed_transition = transition[0].trim(); + let transition_vec = trimmed_transition.split("=>").collect::>(); + let mut transition_vec_iter = transition_vec.iter(); + let mut src = transition_vec_iter.next().unwrap().trim().to_string(); + if src.len() > 2 + && src.chars().nth(2).unwrap() == '\\' + && !(src.chars().nth(3).unwrap() == 'x') + { + src = format!("{}{}", &src[0..2], &src[3..]); + } + let dst = transition_vec_iter.next().unwrap().trim(); + state.edges.insert(src, dst.parse::().unwrap()); + } + dfa_info.states.push(state); + } + + let mut eoi_pointing_states = BTreeSet::new(); + + for state in &mut dfa_info.states { + if let Some(eoi_target) = state.edges.get("EOI").cloned() { + eoi_pointing_states.insert(eoi_target); + state.typ = String::from("accept"); + state.edges.remove("EOI"); + } + } + + let start_state_re = Regex::new(r"START-GROUP\(anchored\)[\s*\w*\=>]*Text => (\d+)").unwrap(); + let start_state = start_state_re.captures_iter(output).next().unwrap()[1] + .parse::() + .unwrap(); + + // Sort states by order of appearance and rename the sources + let mut sorted_states = DFAGraphInfo { states: Vec::new() }; + let mut sorted_states_set = BTreeSet::new(); + let mut new_states = BTreeSet::new(); + new_states.insert(start_state); + while !new_states.is_empty() { + let mut next_states = BTreeSet::new(); + for state in &new_states { + if let Some(state) = dfa_info.states.iter().find(|s| s.source == *state) { + sorted_states.states.push((*state).clone()); + sorted_states_set.insert(state.source); + for (_, dst) in &state.edges { + if !sorted_states_set.contains(dst) { + next_states.insert(*dst); + } + } + } + } + // Check if the next_states are already in the sorted_states_set + new_states.clear(); + for state in &next_states { + if !sorted_states_set.contains(state) { + new_states.insert(*state); + } + } + } + + // Rename the sources + let mut switch_states = BTreeMap::new(); + for (i, state) in sorted_states.states.iter_mut().enumerate() { + let temp = state.source; + state.source = i as usize; + switch_states.insert(temp, state.source); + } + + // Iterate over all edges of all states + for state in &mut sorted_states.states { + for (_, dst) in &mut state.edges { + *dst = switch_states.get(dst).unwrap().clone(); + } + } + + sorted_states +} + +fn dfa_to_graph(dfa_info: &DFAGraphInfo) -> DFAGraph { + let mut graph = DFAGraph { states: Vec::new() }; + for state in &dfa_info.states { + let mut edges = BTreeMap::new(); + let key_mappings: BTreeMap<&str, u8> = [ + ("\\n", 10), + ("\\r", 13), + ("\\t", 9), + ("\\v", 11), + ("\\f", 12), + ("\\0", 0), + ] + .into(); + for (key, value) in &state.edges { + let mut key: &str = key; + if key == "' '" { + key = " "; + } + let re = Regex::new(r"(.+)-(.+)").unwrap(); + if re.is_match(key) { + let capture = re.captures_iter(key).next().unwrap(); + let mut start = &capture[1]; + let start_index; + if start.starts_with("\\x") { + start = &start[2..]; + start_index = u8::from_str_radix(start, 16).unwrap(); + } else { + if key_mappings.contains_key(start) { + start_index = *key_mappings.get(start).unwrap(); + } else { + start_index = start.as_bytes()[0]; + } + } + let mut end = &capture[2]; + let end_index; + if end.starts_with("\\x") { + end = &end[2..]; + end_index = u8::from_str_radix(end, 16).unwrap(); + } else { + if key_mappings.contains_key(end) { + end_index = *key_mappings.get(end).unwrap(); + } else { + end_index = end.as_bytes()[0]; + } + } + let char_range: Vec = (start_index..=end_index).collect(); + if edges.contains_key(value) { + let edge: &mut BTreeSet = edges.get_mut(value).unwrap(); + for c in char_range { + edge.insert(c); + } + } else { + edges.insert(*value, char_range.into_iter().collect()); + } + } else { + let index; + if key.starts_with("\\x") { + key = &key[2..]; + index = u8::from_str_radix(key, 16).unwrap(); + } else { + if key_mappings.contains_key(key) { + index = *key_mappings.get(key).unwrap(); + } else { + index = key.as_bytes()[0]; + } + } + if edges.contains_key(value) { + let edge: &mut BTreeSet = edges.get_mut(value).unwrap(); + edge.insert(index); + } else { + edges.insert(*value, vec![index].into_iter().collect()); + } + } + } + + graph.states.push(DFAState { + r#type: state.typ.clone(), + edges: edges, + state: state.source, + }); + } + + graph +} + +fn rename_states(dfa_info: &DFAGraph, base: usize) -> DFAGraph { + let mut dfa_info = dfa_info.clone(); + // Rename the sources + let mut switch_states = BTreeMap::new(); + for (i, state) in dfa_info.states.iter_mut().enumerate() { + let temp = state.state; + state.state = i + base; + switch_states.insert(temp, state.state); + } + + // Iterate over all edges of all states and rename the states + for state in &mut dfa_info.states { + let mut new_edges = BTreeMap::new(); + for (key, value) in &state.edges { + new_edges.insert(*switch_states.get(key).unwrap(), value.clone()); + } + state.edges = new_edges; + } + + dfa_info +} + +fn add_dfa(net_dfa: &DFAGraph, graph: &DFAGraph) -> DFAGraph { + if net_dfa.states.is_empty() { + return graph.clone(); + } + let mut net_dfa = net_dfa.clone(); + + let start_state = graph.states.iter().next().unwrap(); + + for state in &mut net_dfa.states { + if state.r#type == "accept" { + for (k, v) in &start_state.edges { + for edge_value in v { + for (_, v) in &mut state.edges { + if v.contains(edge_value) { + v.retain(|val| val != edge_value); + } + } + } + state.edges.insert(*k, v.clone()); + } + state.r#type = "".to_string(); + } + } + + for state in &graph.states { + if state.state != start_state.state { + net_dfa.states.push(state.clone()); + } + } + + net_dfa +} + +pub fn regex_and_dfa(decomposed_regex: &DecomposedRegexConfig) -> RegexAndDFA { + let mut config = DFA::config().minimize(true); + config = config.start_kind(StartKind::Anchored); + config = config.byte_classes(false); + config = config.accelerate(true); + + let mut net_dfa = DFAGraph { states: Vec::new() }; + let mut substr_defs_array = Vec::new(); + + for regex in decomposed_regex.parts.iter() { + let re = DFA::builder() + .configure(config.clone()) + .build(&format!(r"^{}$", regex.regex_def)) + .unwrap(); + let re_str = format!("{:?}", re); + let mut graph = dfa_to_graph(&parse_dfa_output(&re_str)); + + // Find max state in net_dfa + let mut max_state_index = 0; + for state in net_dfa.states.iter() { + if state.state > max_state_index { + max_state_index = state.state; + } + } + + graph = rename_states(&graph, max_state_index); + + if regex.is_public { + let mut accepting_states = Vec::new(); + for state in &net_dfa.states { + if state.r#type == "accept" { + accepting_states.push(state); + } + } + + let mut public_edges = BTreeSet::new(); + for state in &graph.states { + for (key, _) in &state.edges { + public_edges.insert((state.state, *key)); + } + } + + if max_state_index != 0 { + for public_edge in &public_edges.clone() { + if public_edge.0 == max_state_index && public_edge.1 == max_state_index { + public_edges.remove(&(public_edge.0, public_edge.1)); + for accept_state in &accepting_states { + for accept_state_ in &accepting_states { + public_edges.insert((accept_state.state, accept_state_.state)); + } + } + } else if public_edge.0 == max_state_index { + public_edges.remove(&(public_edge.0, public_edge.1)); + for accept_state in &accepting_states { + public_edges.insert((accept_state.state, public_edge.1)); + } + } else if public_edge.1 == max_state_index { + public_edges.remove(&(public_edge.0, public_edge.1)); + for accept_state in &accepting_states { + public_edges.insert((public_edge.0, accept_state.state)); + } + } + } + } + + substr_defs_array.push(public_edges); + } + + net_dfa = add_dfa(&net_dfa, &graph); + } + + let mut regex_str = String::new(); + for regex in decomposed_regex.parts.iter() { + regex_str += ®ex.regex_def; + } + + RegexAndDFA { + regex_str: regex_str, + dfa_val: net_dfa, + substrs_defs: SubstrsDefs { + substr_defs_array: substr_defs_array, + substr_endpoints_array: None, + }, + } +} + +pub fn dfa_from_regex_str(regex: &str) -> DFAGraph { + let mut config = DFA::config().minimize(true); + config = config.start_kind(StartKind::Anchored); + config = config.byte_classes(false); + config = config.accelerate(true); + let re = DFA::builder() + .configure(config) + .build(&format!(r"^{}$", regex)) + .unwrap(); + let re_str = format!("{:?}", re); + let graph = dfa_to_graph(&parse_dfa_output(&re_str)); + graph +} diff --git a/packages/compiler/src/regex.ts b/packages/compiler/src/regex.ts deleted file mode 100644 index b25a631..0000000 --- a/packages/compiler/src/regex.ts +++ /dev/null @@ -1,900 +0,0 @@ -/* eslint-disable no-prototype-builtins */ -/*jslint browser: true*/ - -const a2z_nosep = "abcdefghijklmnopqrstuvwxyz"; -const A2Z_nosep = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; -const a2f_nosep = "abcdef"; -const A2F_nosep = "ABCDEF"; -const r0to9_nosep = "0123456789"; -const escapeMap = { n: "\n", r: "\r", t: "\t", v: "\v", f: "\f" }; -const whitespace = Object.values(escapeMap); -const slash_s = whitespace.join("|"); - -/** - * Parse regex to a min DFA spec - * to support some shorthands that make regex easier to write e.g. [A-Z] - */ -function regexToMinDFASpec(str: string): string { - // Replace all A-Z with A2Z etc - let combined_nosep = str - .replaceAll("A-Z", A2Z_nosep) - .replaceAll("a-z", a2z_nosep) - .replaceAll("A-F", A2F_nosep) - .replaceAll("a-f", a2f_nosep) - .replaceAll("0-9", r0to9_nosep) - .replaceAll("\\w", A2Z_nosep + r0to9_nosep + a2z_nosep + "_") - .replaceAll("\\d", r0to9_nosep) - .replaceAll("\\s", slash_s); - // .replaceAll("\\w", A2Z_nosep + r0to9_nosep + a2z_nosep); // I think that there's also an underscore here - - // function addPipeInsideBrackets(str: string): string { - // let result: string = ""; - // let insideBrackets: boolean = false; - // for (let i = 0; i < str.length; i++) { - // if (str[i] === "[") { - // result += str[i]; - // insideBrackets = true; - // continue; - // } else if (str[i] === "]") { - // insideBrackets = false; - // } - // let str_to_add = str[i]; - // if (str[i] === "\\") { - // i++; - // str_to_add += str[i]; - // } - // result += insideBrackets ? "|" + str_to_add : str_to_add; - // } - // return result.replaceAll("[|", "[").replaceAll("[", "(").replaceAll("]", ")"); - // } - - // function makeCurlyBracesFallback(str) { - // let result = ""; - // let insideBrackets = false; - // for (let i = 0; i < str.length; i++) { - // if (str[i] === "{") { - // result += str[i]; - // insideBrackets = true; - // continue; - // } else if (str[i] === "}") { - // insideBrackets = false; - // } - // result += insideBrackets ? "|" + str[i] : str[i]; - // } - // return result.replaceAll("[|", "[").replaceAll("[", "(").replaceAll("]", ")"); - // } - - // function checkIfBracketsHavePipes(str: string): boolean { - // let result: boolean = true; - // let insideBrackets: boolean = false; - // let insideParens: number = 0; - // let indexAt: number = 0; - // for (let i = 0; i < str.length; i++) { - // if (indexAt >= str.length) break; - // if (str[indexAt] === "[") { - // insideBrackets = true; - // indexAt++; - // continue; - // } else if (str[indexAt] === "]") { - // insideBrackets = false; - // } - // if (str[indexAt] === "(") { - // insideParens++; - // } else if (str[indexAt] === ")") { - // insideParens--; - // } - // if (insideBrackets) { - // if (str[indexAt] === "|") { - // indexAt++; - // } else { - // result = false; - // return result; - // } - // } - // if (!insideParens && str[indexAt] === "|") { - // console.log("Error: | outside of parens!"); - // } - // if (str[indexAt] === "\\") { - // indexAt++; - // } - // indexAt++; - // } - // return result; - // } - - // let combined; - // if (!checkIfBracketsHavePipes(combined_nosep)) { - // // console.log("Adding pipes within brackets between everything!"); - // combined = addPipeInsideBrackets(combined_nosep); - // if (!checkIfBracketsHavePipes(combined)) { - // console.log("Did not add brackets correctly!"); - // } - // } else { - // combined = combined_nosep; - // } - - return combined_nosep; -} - -type CusNode = { - type?: string; - sub?: CusNode; - parts?: CusNode[]; - text?: string | [string]; - begin: number; - end: number; -} - -type NfaEdge = [string | [string], NfaNode]; - -type NfaNode = { - type: string; - edges: NfaEdge[]; - id?: string | number; -}; - -type DfaEdge = [string | [string], DfaNode]; - -type DfaNode = { - id: string | number; - key: string, - items: NfaNode[], - symbols: (string | [string])[], - type: string, - edges: DfaEdge[], - trans: Record; - nature: number; -}; - - -/** - * Try parsing simple regular expression to syntax tree. - * - * Basic grammars: - * Empty: S -> ϵ - * Cat: S -> S S - * Or: S -> S | S - * Star: S -> S * - * Text: S -> [0-9a-zA-Z] - * S -> ( S ) - * - * Extension: - * Plus: S -> S + -> S S * - * Ques: S -> S ? -> (S | ϵ) - * - * @param {string} text The input regular expression - * @return {string|object} Returns a string that is an error message if failed to parse the expression, - * otherwise returns an object which is the syntax tree. - */ -function parseRegex(text: string): CusNode | string { - text = regexToMinDFASpec(text); - 'use strict'; - function parseSub(text: (string | [string])[], begin: number, end: number, first: boolean): CusNode | string { - var i: number, - sub: CusNode | string, - last: number = 0, - node: CusNode = { - begin: begin, - end: end, - }, - virNode: CusNode, - tempNode: CusNode, - stack: number = 0, - parts: CusNode[] = []; - if (text.length === 0) { - return 'Error: empty input at ' + begin + '.'; - } - if (first) { - for (i = 0; i <= text.length; i += 1) { - if (i === text.length || (text[i] === '|' && stack === 0)) { - if (last === 0 && i === text.length) { - return parseSub(text, begin + last, begin + i, false); - } - sub = parseSub(text.slice(last, i), begin + last, begin + i, true); - if (typeof sub === 'string') { - return sub; - } - parts.push(sub); - last = i + 1; - } else if (text[i] === '(') { - stack += 1; - } else if (text[i] === ')') { - stack -= 1; - } - } - - if (parts.length === 1) { - return parts[0]; - } - node.type = 'or'; - node.parts = parts; - } else { - for (i = 0; i < text.length; i += 1) { - if (text[i] === '(') { - last = i + 1; - i += 1; - stack = 1; - while (i < text.length && stack !== 0) { - if (text[i] === '(') { - stack += 1; - } else if (text[i] === ')') { - stack -= 1; - } - i += 1; - } - if (stack !== 0) { - return `Error: missing right parentheses for ${begin + last}.`; - } - i -= 1; - sub = parseSub(text.slice(last, i), begin + last, begin + i, true); - if (typeof sub === 'string') { - return sub; - } - sub.begin -= 1; - sub.end += 1; - parts.push(sub); - // } else if (text[i] === '[') { - // last = i + 1; - // i += 1; - // if (text[i] === '^') { - // text[i] = '\u{ff}'; - // } - // stack = 1; - // while (i < text.length && stack !== 0) { - // if (text[i] === ']') { - // stack -= 1; - // } - // i += 1; - // } - // if (stack !== 0) { - // return 'Error: missing right brakets for ' + (begin + last) + '.'; - // } - // i -= 1; - // sub = parseSub(text.slice(last, i), begin + last, begin + i, true); - // if (typeof sub === 'string') { - // return sub; - // } - // sub.begin -= 1; - // sub.end += 1; - // parts.push(sub); - } else if (text[i] === '*') { - if (parts.length === 0) { - return `Error: unexpected * at ${begin + i}.`; - } - tempNode = { begin: parts[parts.length - 1].begin, end: parts[parts.length - 1].end + 1 }; - tempNode.type = 'star'; - tempNode.sub = parts[parts.length - 1]; - parts[parts.length - 1] = tempNode; - } else if (text[i] === '+') { - if (parts.length === 0) { - return `Error: unexpected + at ${begin + i}.`; - } - virNode = { begin: parts[parts.length - 1].begin, end: parts[parts.length - 1].end + 1 }; - virNode.type = 'star'; - virNode.sub = parts[parts.length - 1]; - tempNode = { begin: parts[parts.length - 1].begin, end: parts[parts.length - 1].end + 1 }; - tempNode.type = 'cat'; - tempNode.parts = [parts[parts.length - 1], virNode]; - parts[parts.length - 1] = tempNode; - } else if (text[i] === '?') { - if (parts.length === 0) { - return `Error: unexpected ? at ${begin + i}.`; - } - virNode = { begin: parts[parts.length - 1].begin, end: parts[parts.length - 1].end + 1 }; - virNode.type = 'empty'; - virNode.sub = parts[parts.length - 1]; - tempNode = { begin: parts[parts.length - 1].begin, end: parts[parts.length - 1].end + 1 }; - tempNode.type = 'or'; - tempNode.parts = [parts[parts.length - 1], virNode]; - parts[parts.length - 1] = tempNode; - } else if (text[i] === 'ϵ') { - tempNode = { begin: begin + i, end: begin + i + 1 }; - tempNode.type = 'empty'; - parts.push(tempNode); - } else if (Array.isArray(text[i])) { - tempNode = { begin: begin + i, end: begin + i + 1 }; - tempNode.type = 'text'; - tempNode.text = text[i][0]; - parts.push(tempNode); - } else { - tempNode = { begin: begin + i, end: begin + i + 1 }; - tempNode.type = 'text'; - tempNode.text = text[i]; - parts.push(tempNode); - } - } - // console.log(`parts ${JSON.stringify(parts)}`); - if (parts.length === 1) { - return parts[0]; - } - node.type = 'cat'; - node.parts = parts; - } - return node; - } - - let char: string | [string]; - let new_text: (string | [string])[] = []; - let i: number = 0; - let is_in_brancket: boolean = false; - let brancket_text: (string | [string])[] = []; - while (i < text.length) { - char = text[i]; - - if (text[i] == '\\') { - char = [text[i + 1]]; - // new_text.push([text[i + 1]]); - i += 1; - } - - if (char === '[') { - if (is_in_brancket) { - return `Error: unexpected [ at ${i}.`; - } - is_in_brancket = true; - brancket_text = []; - // new_text.push(char); - i += 1; - } else if (char === ']') { - if (!is_in_brancket) { - return `Error: unexpected ] at ${i}.`; - } - is_in_brancket = false; - - if (brancket_text[0] === '^') { - brancket_text.shift(); - let rev_text: (string | [string])[] = []; - let code_char: string | [string] = ''; - const brancket_text_jsons = brancket_text.map(val => JSON.stringify(val)); - for (let idx = 0; idx < 255; idx++) { - code_char = String.fromCodePoint(idx); - - if ([ - '(', - ')', - '*', - '+', - '.', - '?', - '[', - '\\', - ']', - '^', - '`', - '|', - '-' - ].indexOf(code_char) != -1) { - code_char = [code_char]; - } - - if (brancket_text_jsons.indexOf(JSON.stringify(code_char)) === -1) { - rev_text.push(code_char); - } - } - - brancket_text = rev_text; - } - - new_text.push('('); - - for (const c of brancket_text) { - new_text.push(c); - new_text.push('|'); - } - - new_text = new_text.slice(0, -1); - new_text.push(')'); - i += 1; - } else if (is_in_brancket) { - if (!Array.isArray(char) && ['(', ')', '[', '*', '+', '?', 'ϵ'].includes(char)) { - return `Error: unexpected ${char} at ${i}.`; - } - - if (char === '^' && text[i - 1] !== '[') { - return `Error: unexpected ^ at ${i}.`; - } - // new_text.push(char); - // new_text.push('|'); - brancket_text.push(char); - i += 1; - } else { - new_text.push(char); - i += 1; - } - } - - if (is_in_brancket) { - return `Error: missing right brackets.`; - } - - return parseSub(new_text, 0, new_text.length, true); -} - - -/** -* Convert regular expression to nondeterministic finite automaton. -* -* @param {string} text @see parseRegex() -* @return {object|string} -*/ -function regexToNfa(text: string): NfaNode | string { - 'use strict'; - function generateGraph(node: CusNode, start: NfaNode, end: NfaNode, count: number): number { - var i: number, last: NfaNode, temp: NfaNode, tempStart: NfaNode, tempEnd: NfaNode; - if (!start.hasOwnProperty('id')) { - start.id = count; - count += 1; - } - switch (node.type) { - case 'empty': - start.edges.push(['ϵ', end]); - break; - case 'text': - start.edges.push([node.text!, end]); - break; - case 'cat': - last = start; - for (i = 0; i < node.parts!.length - 1; i += 1) { - temp = { 'type': '', 'edges': [] }; - count = generateGraph(node.parts![i], last, temp, count); - last = temp; - } - count = generateGraph(node.parts![node.parts!.length - 1], last, end, count); - break; - case 'or': - for (i = 0; i < node.parts!.length; i += 1) { - tempStart = { 'type': '', 'edges': [] }; - tempEnd = { 'type': '', 'edges': [['ϵ', end]] }; - start.edges.push(['ϵ', tempStart]); - count = generateGraph(node.parts![i], tempStart, tempEnd, count); - } - break; - case 'star': - tempStart = { 'type': '', 'edges': [] }; - tempEnd = { 'type': '', 'edges': [['ϵ', tempStart], ['ϵ', end]] }; - start.edges.push(['ϵ', tempStart]); - start.edges.push(['ϵ', end]); - count = generateGraph(node.sub!, tempStart, tempEnd, count); - break; - } - if (!end.hasOwnProperty('id')) { - end.id = count; - count += 1; - } - return count; - } - var ast = parseRegex(text), - start = { 'type': 'start', 'edges': [] }, - accept = { 'type': 'accept', 'edges': [] }; - if (typeof ast === 'string') { - return ast; - } - generateGraph(ast, start, accept, 0); - return start; -} - -/** -* Convert nondeterministic finite automaton to deterministic finite automaton. -* -* @param {object} nfa @see regexToNfa(), the function assumes that the given NFA is valid. -* @return {object} dfa Returns the first element of the DFA. -*/ -function nfaToDfa(nfa: NfaNode): DfaNode { - 'use strict'; - function getClosure(nodes: NfaNode[]): DfaNode { - var i: number, - closure: NfaNode[] = [], - stack: NfaNode[] = [], - symbols: (string | [string])[] = [], - type: string = '', - top: NfaNode; - for (i = 0; i < nodes.length; i += 1) { - stack.push(nodes[i]); - closure.push(nodes[i]); - if (nodes[i].type === 'accept') { - type = 'accept'; - } - } - while (stack.length > 0) { - top = stack.pop()!; - // If top is of type string and starts with "Error" then return error - if (typeof top === 'string' && top[0] === 'E' && !top) { - continue; - } - for (i = 0; i < top.edges.length; i += 1) { - if (top.edges[i][0] === 'ϵ') { - if (closure.indexOf(top.edges[i][1]) < 0) { - stack.push(top.edges[i][1]); - closure.push(top.edges[i][1]); - if (top.edges[i][1].type === 'accept') { - type = 'accept'; - } - } - } else { - if (symbols.indexOf(top.edges[i][0]) < 0) { - symbols.push(top.edges[i][0]); - } - } - } - } - closure.sort((a, b) => { - if (a.id && b.id) { - return a.id > b.id ? 1 : -1; - } - return 0; - }); - symbols.sort(); - return { - id: '', - 'key': closure.map(function (x) { - return x.id; - }).join(','), - 'items': closure, - 'symbols': symbols, - 'type': type, - 'edges': [], - 'trans': {}, - 'nature': 0, - }; - } - function getClosedMove(closure: DfaNode, symbol: string | [string]): DfaNode { - var i, - j, - node, - nexts = []; - for (i = 0; i < closure.items.length; i += 1) { - node = closure.items[i]; - for (j = 0; j < node.edges.length; j += 1) { - if (symbol === node.edges[j][0]) { - if (nexts.indexOf(node.edges[j][1]) < 0) { - nexts.push(node.edges[j][1]); - } - } - } - } - return getClosure(nexts); - } - function toAlphaCount(n: number): string { - var a = 'A'.charCodeAt(0), - z = 'Z'.charCodeAt(0), - len = z - a + 1, - s = ''; - while (n >= 0) { - s = String.fromCharCode(n % len + a) + s; - n = Math.floor(n / len) - 1; - } - return s; - } - var i: number, - first: DfaNode = getClosure([nfa]), - states: Record = {}, - front: number = 0, - top: DfaNode, - closure: DfaNode, - queue: DfaNode[] = [first], - count: number = 0; - first.id = toAlphaCount(count); - states[first.key] = first; - while (front < queue.length) { - top = queue[front]; - front += 1; - for (i = 0; i < top.symbols.length; i += 1) { - closure = getClosedMove(top, top.symbols[i]); - if (!states.hasOwnProperty(closure.key)) { - count += 1; - closure.id = toAlphaCount(count); - states[closure.key] = closure; - queue.push(closure); - } - top.trans[top.symbols[i] as string] = states[closure.key]; - top.edges.push([top.symbols[i], states[closure.key]]); - } - } - return first; -} - -/** -* Convert the DFA to its minimum form using Hopcroft's algorithm. -* -* @param {object} dfa @see nfaToDfa(), the function assumes that the given DFA is valid. -* @return {object} dfa Returns the first element of the minimum DFA. -*/ -function minDfa(dfa: DfaNode) { - 'use strict'; - function getReverseEdges(start: DfaNode): [string[], Record, Record>] { - var i: number, top: DfaNode, symbol: string | [string], next: DfaNode, - front: number = 0, - queue: DfaNode[] = [start], - visited: Record = {}, - symbols: Record = {}, // The input alphabet - idMap: Record = {}, // Map id to states - revEdges: Record> = {}; // Map id to the ids which connects to the id with an alphabet - visited[start.id] = true; - while (front < queue.length) { - top = queue[front]; - front += 1; - idMap[top.id] = top; - for (i = 0; i < top.symbols.length; i += 1) { - symbol = top.symbols[i]; - if (!symbols.hasOwnProperty(symbol as string)) { - symbols[symbol as string] = true; - } - next = top.trans[symbol as string]; - if (!revEdges.hasOwnProperty(next.id)) { - revEdges[next.id] = {}; - } - if (!revEdges[next.id].hasOwnProperty(symbol as string)) { - revEdges[next.id][symbol as string] = []; - } - revEdges[next.id][symbol as string].push(top.id); - if (!visited.hasOwnProperty(next.id)) { - visited[next.id] = true; - queue.push(next); - } - } - } - return [Object.keys(symbols), idMap, revEdges]; - } - function hopcroft(symbols: string[], idMap: Record, revEdges: Record>): string[][] { - const ids = Object.keys(idMap).sort(); - const partitions: Record = {}; - const queue: (string | null)[] = []; - const visited: Record = {}; - - let front = 0; - let top: string[] | string | null; - let i: number; - let j: number; - let k: number; - let keys: string[]; - let key: string; - let key1: string; - let key2: string; - let group1: string[]; - let group2: string[]; - let symbol: string; - let revGroup: Record; - - group1 = []; - group2 = []; - for (i = 0; i < ids.length; i += 1) { - if (idMap[ids[i]].type === 'accept') { - group1.push(ids[i]); - } else { - group2.push(ids[i]); - } - } - key = group1.join(','); - partitions[key] = group1; - queue.push(key); - visited[key] = 0; - if (group2.length !== 0) { - key = group2.join(','); - partitions[key] = group2; - queue.push(key); - } - while (front < queue.length) { - top = queue[front]; - front += 1; - if (top) { - top = top.split(','); - for (i = 0; i < symbols.length; i += 1) { - symbol = symbols[i]; - revGroup = {}; - for (j = 0; j < top.length; j += 1) { - if (revEdges.hasOwnProperty(top[j]) && revEdges[top[j]].hasOwnProperty(symbol)) { - for (k = 0; k < revEdges[top[j]][symbol].length; k += 1) { - revGroup[revEdges[top[j]][symbol][k]] = true; - } - } - } - keys = Object.keys(partitions); - for (j = 0; j < keys.length; j += 1) { - key = keys[j]; - group1 = []; - group2 = []; - for (k = 0; k < partitions[key].length; k += 1) { - if (revGroup.hasOwnProperty(partitions[key][k])) { - group1.push(partitions[key][k]); - } else { - group2.push(partitions[key][k]); - } - } - if (group1.length !== 0 && group2.length !== 0) { - delete partitions[key]; - key1 = group1.join(','); - key2 = group2.join(','); - partitions[key1] = group1; - partitions[key2] = group2; - if (visited.hasOwnProperty(key1)) { - queue[visited[key1]] = null; - visited[key1] = queue.length; - queue.push(key1); - visited[key2] = queue.length; - queue.push(key2); - } else if (group1.length <= group2.length) { - visited[key1] = queue.length; - queue.push(key1); - } else { - visited[key2] = queue.length; - queue.push(key2); - } - } - } - } - } - } - return Object.values(partitions); - } - function buildMinNfa(start: DfaNode, partitions: string[][], idMap: Record, revEdges: Record>): DfaNode { - var i: number, j: number, temp: string[], node, symbol; - const nodes: DfaNode[] = []; - const group: Record = {}; - const edges: Record>> = {}; - partitions.sort(function (a, b) { - var ka = a.join(','), kb = b.join(','); - if (ka < kb) { - return -1; - } - if (ka > kb) { - return 1; - } - return 0; - }); - for (i = 0; i < partitions.length; i += 1) { - if (partitions[i].indexOf(start.id.toString()) >= 0) { - if (i > 0) { - temp = partitions[i]; - partitions[i] = partitions[0]; - partitions[0] = temp; - } - break; - } - } - for (i = 0; i < partitions.length; i += 1) { - const node: DfaNode = { - id: (i + 1).toString(), - key: partitions[i].join(','), - items: [], - symbols: [], - type: idMap[partitions[i][0]].type, - edges: [], - trans: {}, - nature: 0, - }; - for (j = 0; j < partitions[i].length; j += 1) { - node.items.push(idMap[partitions[i][j]]); - group[partitions[i][j]] = i; - } - edges[i] = {}; - nodes.push(node); - } - Object.keys(revEdges).forEach(function (to) { - Object.keys(revEdges[to]).forEach(function (symbol) { - revEdges[to][symbol].forEach(function (from) { - if (!edges[group[from]].hasOwnProperty(group[to])) { - edges[group[from]][group[to]] = {}; - } - edges[group[from]][group[to]][symbol] = true; - }); - }); - }); - Object.keys(edges).forEach((from) => { - Object.keys(edges[Number(from)]).forEach((to) => { - const symbol = JSON.stringify(Object.keys(edges[Number(from)][Number(to)]).sort()); - nodes[parseInt(from)].symbols.push(symbol); - nodes[parseInt(from)].edges.push([symbol, nodes[parseInt(to)]]); - nodes[parseInt(from)].trans[symbol] = nodes[parseInt(to)]; - }); - }); - return nodes[0]; - } - var edgesTuple = getReverseEdges(dfa), - symbols = edgesTuple[0], - idMap = edgesTuple[1], - revEdges = edgesTuple[2], - partitions = hopcroft(symbols, idMap, revEdges); - return buildMinNfa(dfa, partitions, idMap, revEdges); -} - -function toNature(col: string): number { - var i, - j, - base = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', - result = 0; - if ('1' <= col[0] && col[0] <= '9') { - result = parseInt(col, 10); - } else { - for (i = 0, j = col.length - 1; i < col.length; i += 1, j -= 1) { - result += Math.pow(base.length, j) * (base.indexOf(col[i]) + 1); - } - } - return result; -} - -// '(\r\n|\x80)(to|from):([A-Za-z0-9 _."@-]+<)?[a-zA-Z0-9_.-]+@[a-zA-Z0-9_.]+>?\r\n'; -// let regex = '(\r\n|\x80)(to|from):((a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z|A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z|0|1|2|3|4|5|6|7|8|9| |_|.|"|@|-)+<)?(a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z|A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z|0|1|2|3|4|5|6|7|8|9|_|.|-)+@(a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z|A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z|0|1|2|3|4|5|6|7|8|9|_|.|-)+>?\r\n'; - -// const key_chars = '(a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z)'; -// const catch_all = '(0|1|2|3|4|5|6|7|8|9|a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z|A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z|!|"|#|$|%|&|\'|\\(|\\)|\\*|\\+|,|-|.|/|:|;|<|=|>|\\?|@|[|\\\\|]|^|_|`|{|\\||}|~| |\t|\n|\r|\x0b|\x0c)'; -// const catch_all_without_semicolon = '(0|1|2|3|4|5|6|7|8|9|a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z|A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z|!|"|#|$|%|&|\'|\\(|\\)|\\*|\\+|,|-|.|/|:|<|=|>|\\?|@|[|\\\\|]|^|_|`|{|\\||}|~| |\t|\n|\r|\x0b|\x0c)'; -// const base_64 = '(a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z|A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z|0|1|2|3|4|5|6|7|8|9|\\+|/|=)'; -// const word_char = '(a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z|A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z|0|1|2|3|4|5|6|7|8|9|_)'; - - -function regexToDfa(regex: string): string { - let nfa = regexToNfa(regex); - let dfa = minDfa(nfaToDfa(nfa as NfaNode)); - var i: number, - states: Record = {}, - nodes: DfaNode[] = [], - stack = [dfa], - symbols: string[] = []; - - while (stack.length > 0) { - const top = stack.pop()!; - if (!states.hasOwnProperty(top.id.toString())) { - states[top.id] = top; - top.nature = toNature(top.id.toString()); - nodes.push(top); - for (i = 0; i < top.edges.length; i += 1) { - if (top.edges[i][0] !== 'ϵ' && symbols.indexOf(top.edges[i][0] as string) < 0) { - symbols.push(top.edges[i][0] as string); - } - stack.push(top.edges[i][1]); - } - } - } - nodes.sort(function (a, b) { - return a.nature - b.nature; - }); - symbols.sort(); - const graph: Record[] = []; - for (let i = 0; i < nodes.length; i += 1) { - const curr: Record = {}; - curr.type = nodes[i].type; - curr.edges = {}; - for (let j = 0; j < symbols.length; j += 1) { - if (nodes[i].trans.hasOwnProperty(symbols[j])) { - curr.edges[symbols[j]] = nodes[i].trans[symbols[j]].nature - 1; - } - } - graph[nodes[i].nature - 1] = curr; - } - // console.log(`graph: ${JSON.stringify(graph, null, 2)}`); - - return JSON.stringify(graph); -} - -// function catchAllRegexStr() { -// return "(0|1|2|3|4|5|6|7|8|9|a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z|A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z|!|\"|#|$|%|&|'|\\(|\\)|\\*|\\+|,|-|.|/|:|;|<|=|>|\\?|@|\\[|\\\\|\\]|\\^|_|`|{|\\||}|~| |\t|\n|\r|\x0b|\x0c)"; -// } - -// function catchAllWithoutRNRegexStr() { -// return "(0|1|2|3|4|5|6|7|8|9|a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z|A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z|!|\"|#|$|%|&|'|\\(|\\)|\\*|\\+|,|-|.|/|:|;|<|=|>|\\?|@|[|\\\\|]|^|_|`|{|\\||}|~| |\t|\x0b|\x0c)"; -// } - -// function textContextPrefix() { -// return `Content-Type: text/plain; charset="UTF-8"\r\n\r\n`; -// } - -// function formatRegexPrintable(s) { -// const escaped_string_json = JSON.stringify(s); -// const escaped_string = escaped_string_json.slice(1, escaped_string_json.length - 1); -// return escaped_string -// .replaceAll("\\\\\\\\", "\\") -// .replaceAll("\\\\", "\\") -// .replaceAll("/", "\\/") -// .replaceAll("\u000b", "\\♥") -// .replaceAll("^", "\\^") -// .replaceAll("$", "\\$") -// .replaceAll("|[|", "|\\[|") -// .replaceAll("|]|", "|\\]|") -// .replaceAll("|.|", "|\\.|") -// .replaceAll("|$|", "|\\$|") -// .replaceAll("|^|", "|\\^|"); -// } - -// module.exports = { -// regexToDfa -// }; diff --git a/packages/compiler/src/tests/regex_to_dfa.rs b/packages/compiler/src/tests/regex_to_dfa.rs index 95ddf8b..b2b55ac 100644 --- a/packages/compiler/src/tests/regex_to_dfa.rs +++ b/packages/compiler/src/tests/regex_to_dfa.rs @@ -1,86 +1,94 @@ -use crate::js_caller::{JsCallerError, regex_to_dfa}; +// use crate::js_caller::{regex_to_dfa, JsCallerError}; -#[test] -fn test_regex_to_dfa_case_1() { - let regex = "[a-z]+"; - let dfa = regex_to_dfa(regex).unwrap(); - assert_eq!(serde_json::to_string_pretty(&dfa).unwrap(), r#"[ - { - "type": "", - "edges": { - "[\"a\",\"b\",\"c\",\"d\",\"e\",\"f\",\"g\",\"h\",\"i\",\"j\",\"k\",\"l\",\"m\",\"n\",\"o\",\"p\",\"q\",\"r\",\"s\",\"t\",\"u\",\"v\",\"w\",\"x\",\"y\",\"z\"]": 1 - } - }, - { - "type": "accept", - "edges": { - "[\"a\",\"b\",\"c\",\"d\",\"e\",\"f\",\"g\",\"h\",\"i\",\"j\",\"k\",\"l\",\"m\",\"n\",\"o\",\"p\",\"q\",\"r\",\"s\",\"t\",\"u\",\"v\",\"w\",\"x\",\"y\",\"z\"]": 1 - } - } -]"#); -} +// #[cfg(test)] +// fn test_regex_to_dfa_case_1() { +// let regex = "[a-z]+"; +// let dfa = regex_to_dfa(regex).unwrap(); +// assert_eq!( +// serde_json::to_string_pretty(&dfa).unwrap(), +// r#"[ +// { +// "type": "", +// "edges": { +// "[\"a\",\"b\",\"c\",\"d\",\"e\",\"f\",\"g\",\"h\",\"i\",\"j\",\"k\",\"l\",\"m\",\"n\",\"o\",\"p\",\"q\",\"r\",\"s\",\"t\",\"u\",\"v\",\"w\",\"x\",\"y\",\"z\"]": 1 +// } +// }, +// { +// "type": "accept", +// "edges": { +// "[\"a\",\"b\",\"c\",\"d\",\"e\",\"f\",\"g\",\"h\",\"i\",\"j\",\"k\",\"l\",\"m\",\"n\",\"o\",\"p\",\"q\",\"r\",\"s\",\"t\",\"u\",\"v\",\"w\",\"x\",\"y\",\"z\"]": 1 +// } +// } +// ]"# +// ); +// } -#[test] -fn test_regex_to_dfa_case_2() { - let regex = "[a-z0-9]+"; - let dfa = regex_to_dfa(regex).unwrap(); - assert_eq!(serde_json::to_string_pretty(&dfa).unwrap(), r#"[ - { - "type": "", - "edges": { - "[\"0\",\"1\",\"2\",\"3\",\"4\",\"5\",\"6\",\"7\",\"8\",\"9\",\"a\",\"b\",\"c\",\"d\",\"e\",\"f\",\"g\",\"h\",\"i\",\"j\",\"k\",\"l\",\"m\",\"n\",\"o\",\"p\",\"q\",\"r\",\"s\",\"t\",\"u\",\"v\",\"w\",\"x\",\"y\",\"z\"]": 1 - } - }, - { - "type": "accept", - "edges": { - "[\"0\",\"1\",\"2\",\"3\",\"4\",\"5\",\"6\",\"7\",\"8\",\"9\",\"a\",\"b\",\"c\",\"d\",\"e\",\"f\",\"g\",\"h\",\"i\",\"j\",\"k\",\"l\",\"m\",\"n\",\"o\",\"p\",\"q\",\"r\",\"s\",\"t\",\"u\",\"v\",\"w\",\"x\",\"y\",\"z\"]": 1 - } - } -]"#); -} +// #[test] +// fn test_regex_to_dfa_case_2() { +// let regex = "[a-z0-9]+"; +// let dfa = regex_to_dfa(regex).unwrap(); +// assert_eq!( +// serde_json::to_string_pretty(&dfa).unwrap(), +// r#"[ +// { +// "type": "", +// "edges": { +// "[\"0\",\"1\",\"2\",\"3\",\"4\",\"5\",\"6\",\"7\",\"8\",\"9\",\"a\",\"b\",\"c\",\"d\",\"e\",\"f\",\"g\",\"h\",\"i\",\"j\",\"k\",\"l\",\"m\",\"n\",\"o\",\"p\",\"q\",\"r\",\"s\",\"t\",\"u\",\"v\",\"w\",\"x\",\"y\",\"z\"]": 1 +// } +// }, +// { +// "type": "accept", +// "edges": { +// "[\"0\",\"1\",\"2\",\"3\",\"4\",\"5\",\"6\",\"7\",\"8\",\"9\",\"a\",\"b\",\"c\",\"d\",\"e\",\"f\",\"g\",\"h\",\"i\",\"j\",\"k\",\"l\",\"m\",\"n\",\"o\",\"p\",\"q\",\"r\",\"s\",\"t\",\"u\",\"v\",\"w\",\"x\",\"y\",\"z\"]": 1 +// } +// } +// ]"# +// ); +// } -#[test] -fn test_regex_to_dfa_case_3() { - - let regex = "[a-z0-9]+@[a-z0-9]+\r\n"; - let dfa = regex_to_dfa(regex).unwrap(); - assert_eq!(serde_json::to_string_pretty(&dfa).unwrap(), r#"[ - { - "type": "", - "edges": { - "[\"0\",\"1\",\"2\",\"3\",\"4\",\"5\",\"6\",\"7\",\"8\",\"9\",\"a\",\"b\",\"c\",\"d\",\"e\",\"f\",\"g\",\"h\",\"i\",\"j\",\"k\",\"l\",\"m\",\"n\",\"o\",\"p\",\"q\",\"r\",\"s\",\"t\",\"u\",\"v\",\"w\",\"x\",\"y\",\"z\"]": 1 - } - }, - { - "type": "", - "edges": { - "[\"0\",\"1\",\"2\",\"3\",\"4\",\"5\",\"6\",\"7\",\"8\",\"9\",\"a\",\"b\",\"c\",\"d\",\"e\",\"f\",\"g\",\"h\",\"i\",\"j\",\"k\",\"l\",\"m\",\"n\",\"o\",\"p\",\"q\",\"r\",\"s\",\"t\",\"u\",\"v\",\"w\",\"x\",\"y\",\"z\"]": 1, - "[\"@\"]": 2 - } - }, - { - "type": "", - "edges": { - "[\"0\",\"1\",\"2\",\"3\",\"4\",\"5\",\"6\",\"7\",\"8\",\"9\",\"a\",\"b\",\"c\",\"d\",\"e\",\"f\",\"g\",\"h\",\"i\",\"j\",\"k\",\"l\",\"m\",\"n\",\"o\",\"p\",\"q\",\"r\",\"s\",\"t\",\"u\",\"v\",\"w\",\"x\",\"y\",\"z\"]": 3 - } - }, - { - "type": "", - "edges": { - "[\"0\",\"1\",\"2\",\"3\",\"4\",\"5\",\"6\",\"7\",\"8\",\"9\",\"a\",\"b\",\"c\",\"d\",\"e\",\"f\",\"g\",\"h\",\"i\",\"j\",\"k\",\"l\",\"m\",\"n\",\"o\",\"p\",\"q\",\"r\",\"s\",\"t\",\"u\",\"v\",\"w\",\"x\",\"y\",\"z\"]": 3, - "[\"\\r\"]": 4 - } - }, - { - "type": "", - "edges": { - "[\"\\n\"]": 5 - } - }, - { - "type": "accept", - "edges": {} - } -]"#); -} \ No newline at end of file +// #[test] +// fn test_regex_to_dfa_case_3() { +// let regex = "[a-z0-9]+@[a-z0-9]+\r\n"; +// let dfa = regex_to_dfa(regex).unwrap(); +// assert_eq!( +// serde_json::to_string_pretty(&dfa).unwrap(), +// r#"[ +// { +// "type": "", +// "edges": { +// "[\"0\",\"1\",\"2\",\"3\",\"4\",\"5\",\"6\",\"7\",\"8\",\"9\",\"a\",\"b\",\"c\",\"d\",\"e\",\"f\",\"g\",\"h\",\"i\",\"j\",\"k\",\"l\",\"m\",\"n\",\"o\",\"p\",\"q\",\"r\",\"s\",\"t\",\"u\",\"v\",\"w\",\"x\",\"y\",\"z\"]": 1 +// } +// }, +// { +// "type": "", +// "edges": { +// "[\"0\",\"1\",\"2\",\"3\",\"4\",\"5\",\"6\",\"7\",\"8\",\"9\",\"a\",\"b\",\"c\",\"d\",\"e\",\"f\",\"g\",\"h\",\"i\",\"j\",\"k\",\"l\",\"m\",\"n\",\"o\",\"p\",\"q\",\"r\",\"s\",\"t\",\"u\",\"v\",\"w\",\"x\",\"y\",\"z\"]": 1, +// "[\"@\"]": 2 +// } +// }, +// { +// "type": "", +// "edges": { +// "[\"0\",\"1\",\"2\",\"3\",\"4\",\"5\",\"6\",\"7\",\"8\",\"9\",\"a\",\"b\",\"c\",\"d\",\"e\",\"f\",\"g\",\"h\",\"i\",\"j\",\"k\",\"l\",\"m\",\"n\",\"o\",\"p\",\"q\",\"r\",\"s\",\"t\",\"u\",\"v\",\"w\",\"x\",\"y\",\"z\"]": 3 +// } +// }, +// { +// "type": "", +// "edges": { +// "[\"0\",\"1\",\"2\",\"3\",\"4\",\"5\",\"6\",\"7\",\"8\",\"9\",\"a\",\"b\",\"c\",\"d\",\"e\",\"f\",\"g\",\"h\",\"i\",\"j\",\"k\",\"l\",\"m\",\"n\",\"o\",\"p\",\"q\",\"r\",\"s\",\"t\",\"u\",\"v\",\"w\",\"x\",\"y\",\"z\"]": 3, +// "[\"\\r\"]": 4 +// } +// }, +// { +// "type": "", +// "edges": { +// "[\"\\n\"]": 5 +// } +// }, +// { +// "type": "accept", +// "edges": {} +// } +// ]"# +// ); +// } diff --git a/packages/compiler/tsconfig.json b/packages/compiler/tsconfig.json deleted file mode 100644 index 515784b..0000000 --- a/packages/compiler/tsconfig.json +++ /dev/null @@ -1,104 +0,0 @@ -{ - "compilerOptions": { - /* Visit https://aka.ms/tsconfig to read more about this file */ - /* Projects */ - // "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */ - // "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */ - // "tsBuildInfoFile": "./.tsbuildinfo", /* Specify the path to .tsbuildinfo incremental compilation file. */ - // "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects. */ - // "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */ - // "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */ - /* Language and Environment */ - "target": "ES2021", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */ - // "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */ - // "jsx": "preserve", /* Specify what JSX code is generated. */ - // "experimentalDecorators": true, /* Enable experimental support for legacy experimental decorators. */ - // "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */ - // "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */ - // "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */ - // "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */ - // "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */ - // "noLib": true, /* Disable including any library files, including the default lib.d.ts. */ - // "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */ - // "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */ - /* Modules */ - "module": "commonjs", /* Specify what module code is generated. */ - // "rootDir": "./", /* Specify the root folder within your source files. */ - // "moduleResolution": "node10", /* Specify how TypeScript looks up a file from a given module specifier. */ - // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */ - // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */ - // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */ - // "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */ - // "types": [], /* Specify type package names to be included without being referenced in a source file. */ - // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ - // "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */ - // "allowImportingTsExtensions": true, /* Allow imports to include TypeScript file extensions. Requires '--moduleResolution bundler' and either '--noEmit' or '--emitDeclarationOnly' to be set. */ - // "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */ - // "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */ - // "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */ - // "resolveJsonModule": true, /* Enable importing .json files. */ - // "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */ - // "noResolve": true, /* Disallow 'import's, 'require's or ''s from expanding the number of files TypeScript should add to a project. */ - /* JavaScript Support */ - // "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */ - // "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */ - // "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */ - /* Emit */ - // "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */ - // "declarationMap": true, /* Create sourcemaps for d.ts files. */ - // "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */ - // "sourceMap": true, /* Create source map files for emitted JavaScript files. */ - // "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */ - // "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */ - // "outDir": "./", /* Specify an output folder for all emitted files. */ - // "removeComments": true, /* Disable emitting comments. */ - // "noEmit": true, /* Disable emitting files from a compilation. */ - // "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */ - // "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types. */ - // "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */ - // "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */ - // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */ - // "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */ - // "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */ - // "newLine": "crlf", /* Set the newline character for emitting files. */ - // "stripInternal": true, /* Disable emitting declarations that have '@internal' in their JSDoc comments. */ - // "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */ - // "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */ - // "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */ - // "declarationDir": "./", /* Specify the output directory for generated declaration files. */ - // "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */ - /* Interop Constraints */ - // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */ - // "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */ - // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */ - "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */ - // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */ - "forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */ - /* Type Checking */ - "strict": true, /* Enable all strict type-checking options. */ - // "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */ - // "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */ - // "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */ - // "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */ - // "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */ - // "noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */ - // "useUnknownInCatchVariables": true, /* Default catch clause variables as 'unknown' instead of 'any'. */ - // "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */ - // "noUnusedLocals": true, /* Enable error reporting when local variables aren't read. */ - // "noUnusedParameters": true, /* Raise an error when a function parameter isn't read. */ - // "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */ - // "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */ - // "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */ - // "noUncheckedIndexedAccess": true, /* Add 'undefined' to a type when accessed using an index. */ - // "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */ - // "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type. */ - // "allowUnusedLabels": true, /* Disable error reporting for unused labels. */ - // "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */ - /* Completeness */ - // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */ - "skipLibCheck": true /* Skip type checking all .d.ts files. */ - }, - "include": [ - "src/**/*" - ], -} \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json deleted file mode 100644 index 2955be6..0000000 --- a/tsconfig.json +++ /dev/null @@ -1,17 +0,0 @@ -// Visit https://aka.ms/tsconfig.json for all config options -{ - "compilerOptions": { - "target": "ES2021", - "module": "commonjs", - "strict": true, - "resolveJsonModule": true, - "esModuleInterop": true, - "skipLibCheck": true, - "forceConsistentCasingInFileNames": true - }, - "include": [ - "./scripts", - "./test", - "./packages/compiler/src" - ] -} \ No newline at end of file