From 3562cafcd2b6aa5e15593d8ae75fe9d283cb9ed3 Mon Sep 17 00:00:00 2001 From: Aditya Bisht Date: Thu, 7 Nov 2024 02:58:04 +0700 Subject: [PATCH] feat: add circuit input fn for sdk --- Cargo.lock | 421 ++++++++++++++++++++++++++++++++++++++-------- Cargo.toml | 2 +- src/circuit.rs | 188 ++++++++++++++++++++- src/converters.rs | 35 ++++ 4 files changed, 568 insertions(+), 78 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7922daa..3944b28 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -64,9 +64,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.90" +version = "1.0.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37bf3594c4c988a53154954629820791dde498571819ae4ca50ca811e060cc95" +checksum = "4c95c10ba0b00a02636238b814946408b1322d5ac4760326e6fb8ec956d85775" [[package]] name = "arrayref" @@ -97,7 +97,7 @@ checksum = "721cae7de5c34fbb2acd27e21e6d2cf7b886dce0c27388d46c4e6c47ea4318dd" dependencies = [ "proc-macro2", "quote", - "syn 2.0.82", + "syn 2.0.87", ] [[package]] @@ -119,7 +119,7 @@ checksum = "3c87f3f15e7794432337fc718554eaa4dc8f04c9677a950ffe366f20a162ae42" dependencies = [ "proc-macro2", "quote", - "syn 2.0.82", + "syn 2.0.87", ] [[package]] @@ -339,9 +339,9 @@ dependencies = [ [[package]] name = "cc" -version = "1.1.31" +version = "1.1.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2e7962b54006dcfcc61cb72735f4d89bb97061dd6a7ed882ec6b8ee53714c6f" +checksum = "baee610e9452a8f6f0a1b6194ec09ff9e2d85dea54432acdae41aa0761c95d70" dependencies = [ "jobserver", "libc", @@ -634,7 +634,7 @@ checksum = "f46882e17999c6cc590af592290432be3bce0428cb0d5f8b6715e4dc7b383eb3" dependencies = [ "proc-macro2", "quote", - "syn 2.0.82", + "syn 2.0.87", ] [[package]] @@ -665,13 +665,22 @@ dependencies = [ [[package]] name = "derive_more" -version = "0.99.18" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f33878137e4dafd7fa914ad4e259e18a4e8e532b9617a2d0150262bf53abfce" +checksum = "4a9b99b9cbbe49445b21764dc0625032a89b145a2642e67603e1c936f5458d05" +dependencies = [ + "derive_more-impl", +] + +[[package]] +name = "derive_more-impl" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb7330aeadfbe296029522e6c40f315320aba36fc43a5b3632f3795348f3bd22" dependencies = [ "proc-macro2", "quote", - "syn 2.0.82", + "syn 2.0.87", ] [[package]] @@ -728,6 +737,17 @@ dependencies = [ "winapi", ] +[[package]] +name = "displaydoc" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.87", +] + [[package]] name = "dunce" version = "1.0.5" @@ -808,9 +828,9 @@ dependencies = [ [[package]] name = "encoding_rs" -version = "0.8.34" +version = "0.8.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b45de904aa0b010bce2ab45264d0631681847fa7b6f2eaa7dab7619943bc4f59" +checksum = "75030f3c4f45dafd7586dd6780965a8c7e8e285a5ecb86713e63a79c5b2766f3" dependencies = [ "cfg-if", ] @@ -997,7 +1017,7 @@ dependencies = [ "reqwest", "serde", "serde_json", - "syn 2.0.82", + "syn 2.0.87", "toml", "walkdir", ] @@ -1015,7 +1035,7 @@ dependencies = [ "proc-macro2", "quote", "serde_json", - "syn 2.0.82", + "syn 2.0.87", ] [[package]] @@ -1041,7 +1061,7 @@ dependencies = [ "serde", "serde_json", "strum", - "syn 2.0.82", + "syn 2.0.87", "tempfile", "thiserror", "tiny-keccak", @@ -1373,7 +1393,7 @@ checksum = "162ee34ebcb7c64a8abebc059ce0fee27c2262618d7b60ed8faf72fef13c3650" dependencies = [ "proc-macro2", "quote", - "syn 2.0.82", + "syn 2.0.87", ] [[package]] @@ -1550,9 +1570,9 @@ checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" [[package]] name = "hashbrown" -version = "0.15.0" +version = "0.15.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb" +checksum = "3a9bfc1af68b1726ea47d3d5109de126281def866b33970e10fbab11b5dafab3" [[package]] name = "hashers" @@ -1735,6 +1755,124 @@ dependencies = [ "cc", ] +[[package]] +name = "icu_collections" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db2fa452206ebee18c4b5c2274dbf1de17008e874b4dc4f0aea9d01ca79e4526" +dependencies = [ + "displaydoc", + "yoke", + "zerofrom", + "zerovec", +] + +[[package]] +name = "icu_locid" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13acbb8371917fc971be86fc8057c41a64b521c184808a698c02acc242dbf637" +dependencies = [ + "displaydoc", + "litemap", + "tinystr", + "writeable", + "zerovec", +] + +[[package]] +name = "icu_locid_transform" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "01d11ac35de8e40fdeda00d9e1e9d92525f3f9d887cdd7aa81d727596788b54e" +dependencies = [ + "displaydoc", + "icu_locid", + "icu_locid_transform_data", + "icu_provider", + "tinystr", + "zerovec", +] + +[[package]] +name = "icu_locid_transform_data" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fdc8ff3388f852bede6b579ad4e978ab004f139284d7b28715f773507b946f6e" + +[[package]] +name = "icu_normalizer" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19ce3e0da2ec68599d193c93d088142efd7f9c5d6fc9b803774855747dc6a84f" +dependencies = [ + "displaydoc", + "icu_collections", + "icu_normalizer_data", + "icu_properties", + "icu_provider", + "smallvec", + "utf16_iter", + "utf8_iter", + "write16", + "zerovec", +] + +[[package]] +name = "icu_normalizer_data" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8cafbf7aa791e9b22bec55a167906f9e1215fd475cd22adfcf660e03e989516" + +[[package]] +name = "icu_properties" +version = "1.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93d6020766cfc6302c15dbbc9c8778c37e62c14427cb7f6e601d849e092aeef5" +dependencies = [ + "displaydoc", + "icu_collections", + "icu_locid_transform", + "icu_properties_data", + "icu_provider", + "tinystr", + "zerovec", +] + +[[package]] +name = "icu_properties_data" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67a8effbc3dd3e4ba1afa8ad918d5684b8868b3b26500753effea8d2eed19569" + +[[package]] +name = "icu_provider" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ed421c8a8ef78d3e2dbc98a973be2f3770cb42b606e3ab18d6237c4dfde68d9" +dependencies = [ + "displaydoc", + "icu_locid", + "icu_provider_macros", + "stable_deref_trait", + "tinystr", + "writeable", + "yoke", + "zerofrom", + "zerovec", +] + +[[package]] +name = "icu_provider_macros" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ec89e9337638ecdc08744df490b221a7399bf8d164eb52a665454e60e075ad6" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.87", +] + [[package]] name = "idna" version = "0.2.3" @@ -1748,12 +1886,23 @@ dependencies = [ [[package]] name = "idna" -version = "0.5.0" +version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6" +checksum = "686f825264d630750a544639377bae737628043f20d38bbc029e8f29ea968a7e" dependencies = [ - "unicode-bidi", - "unicode-normalization", + "idna_adapter", + "smallvec", + "utf8_iter", +] + +[[package]] +name = "idna_adapter" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "daca1df1c957320b2cf139ac61e7bd64fed304c5040df000a745aa1de3b4ef71" +dependencies = [ + "icu_normalizer", + "icu_properties", ] [[package]] @@ -1817,7 +1966,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da" dependencies = [ "equivalent", - "hashbrown 0.15.0", + "hashbrown 0.15.1", ] [[package]] @@ -2002,9 +2151,9 @@ checksum = "8e9489c2807c139ffd9c1794f4af0ebe86a828db53ecdc7fea2111d0fed085d1" [[package]] name = "libm" -version = "0.2.8" +version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058" +checksum = "8355be11b20d696c8f18f6cc018c4e372165b1fa8126cef092399c9951984ffa" [[package]] name = "libredox" @@ -2028,6 +2177,12 @@ version = "0.4.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" +[[package]] +name = "litemap" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "643cb0b8d4fcc284004d5fd0d67ccf61dfffadb7f75e1e71bc420f4688a3a704" + [[package]] name = "lock_api" version = "0.4.12" @@ -2100,9 +2255,9 @@ checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" [[package]] name = "minicov" -version = "0.3.5" +version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c71e683cd655513b99affab7d317deb690528255a0d5f717f1024093c12b169" +checksum = "f27fe9f1cc3c22e1687f9446c2083c4c5fc7f0bcf1c7a86bdbded14985895b4b" dependencies = [ "cc", "walkdir", @@ -2260,7 +2415,7 @@ dependencies = [ "proc-macro-crate", "proc-macro2", "quote", - "syn 2.0.82", + "syn 2.0.87", ] [[package]] @@ -2326,7 +2481,7 @@ checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.82", + "syn 2.0.87", ] [[package]] @@ -2545,7 +2700,7 @@ dependencies = [ "phf_shared 0.11.2", "proc-macro2", "quote", - "syn 2.0.82", + "syn 2.0.87", ] [[package]] @@ -2568,29 +2723,29 @@ dependencies = [ [[package]] name = "pin-project" -version = "1.1.6" +version = "1.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf123a161dde1e524adf36f90bc5d8d3462824a9c43553ad07a8183161189ec" +checksum = "be57f64e946e500c8ee36ef6331845d40a93055567ec57e8fae13efd33759b95" dependencies = [ "pin-project-internal", ] [[package]] name = "pin-project-internal" -version = "1.1.6" +version = "1.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4502d8515ca9f32f1fb543d987f63d95a14934883db45bdb48060b6b69257f8" +checksum = "3c0f5fad0874fc7abcd4d750e76917eaebbecaa2c20bde22e1dbeeba8beb758c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.82", + "syn 2.0.87", ] [[package]] name = "pin-project-lite" -version = "0.2.14" +version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" +checksum = "915a1e146535de9163f3987b8944ed8cf49a18bb0056bcebcdcece385cece4ff" [[package]] name = "pin-utils" @@ -2660,12 +2815,12 @@ checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c" [[package]] name = "prettyplease" -version = "0.2.24" +version = "0.2.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "910d41a655dac3b764f1ade94821093d3610248694320cd072303a8eedcf221d" +checksum = "64d1ec885c64d0457d564db4ec299b2dae3f9c02808b8ad9c3a089c591b18033" dependencies = [ "proc-macro2", - "syn 2.0.82", + "syn 2.0.87", ] [[package]] @@ -2693,9 +2848,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.88" +version = "1.0.89" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7c3a7fc5db1e57d5a779a352c8cdb57b29aa4c40cc69c3a68a7fedc815fbf2f9" +checksum = "f139b0662de085916d1fb67d2b4169d1addddda1919e696f3252b740b629986e" dependencies = [ "unicode-ident", ] @@ -2830,9 +2985,9 @@ dependencies = [ [[package]] name = "regex" -version = "1.11.0" +version = "1.10.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38200e5ee88914975b69f657f0801b6f6dccafd44fd9326302a4aaeecfacb1d8" +checksum = "4219d74c6b67a3654a9fbebc4b419e22126d13d2f3c4a07ee0cb61ff79a79619" dependencies = [ "aho-corasick", "memchr", @@ -3062,9 +3217,9 @@ dependencies = [ [[package]] name = "rustix" -version = "0.38.37" +version = "0.38.39" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8acb788b847c24f28525660c4d7758620a7210875711f79e7f663cc152726811" +checksum = "375116bee2be9ed569afe2154ea6a99dfdffd257f533f187498c2a8f5feaf4ee" dependencies = [ "bitflags 2.6.0", "errno", @@ -3136,9 +3291,9 @@ dependencies = [ [[package]] name = "scale-info" -version = "2.11.3" +version = "2.11.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eca070c12893629e2cc820a9761bedf6ce1dcddc9852984d1dc734b8bd9bd024" +checksum = "1aa7ffc1c0ef49b0452c6e2986abf2b07743320641ffd5fc63d552458e3b779b" dependencies = [ "cfg-if", "derive_more", @@ -3148,14 +3303,14 @@ dependencies = [ [[package]] name = "scale-info-derive" -version = "2.11.3" +version = "2.11.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2d35494501194174bda522a32605929eefc9ecf7e0a326c26db1fdd85881eb62" +checksum = "46385cc24172cf615450267463f937c10072516359b3ff1cb24228a4a08bf951" dependencies = [ "proc-macro-crate", "proc-macro2", "quote", - "syn 1.0.109", + "syn 2.0.87", ] [[package]] @@ -3261,9 +3416,9 @@ checksum = "cd0b0ec5f1c1ca621c432a25813d8d60c88abe6d3e08a3eb9cf37d97a0fe3d73" [[package]] name = "serde" -version = "1.0.211" +version = "1.0.214" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ac55e59090389fb9f0dd9e0f3c09615afed1d19094284d0b200441f13550793" +checksum = "f55c3193aca71c12ad7890f1785d2b73e1b9f63a0bbc353c08ef26fe03fc56b5" dependencies = [ "serde_derive", ] @@ -3281,13 +3436,13 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.211" +version = "1.0.214" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "54be4f245ce16bc58d57ef2716271d0d4519e0f6defa147f6e081005bcb278ff" +checksum = "de523f781f095e28fa605cdce0f8307e451cc0fd14e2eb4cd2e98a355b147766" dependencies = [ "proc-macro2", "quote", - "syn 2.0.82", + "syn 2.0.87", ] [[package]] @@ -3504,6 +3659,12 @@ dependencies = [ "der", ] +[[package]] +name = "stable_deref_trait" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" + [[package]] name = "static_assertions" version = "1.1.0" @@ -3542,7 +3703,7 @@ dependencies = [ "proc-macro2", "quote", "rustversion", - "syn 2.0.82", + "syn 2.0.87", ] [[package]] @@ -3584,9 +3745,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.82" +version = "2.0.87" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "83540f837a8afc019423a8edb95b52a8effe46957ee402287f4292fae35be021" +checksum = "25aa4ce346d03a6dcd68dd8b4010bcb74e54e62c90c573f394c46eae99aba32d" dependencies = [ "proc-macro2", "quote", @@ -3599,6 +3760,17 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2047c6ded9c721764247e62cd3b03c09ffc529b2ba5b10ec482ae507a4a70160" +[[package]] +name = "synstructure" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8af7666ab7b6390ab78131fb5b0fce11d6b7a6951602017c35fa82800708971" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.87", +] + [[package]] name = "system-configuration" version = "0.5.1" @@ -3658,22 +3830,22 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.64" +version = "1.0.68" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d50af8abc119fb8bb6dbabcfa89656f46f84aa0ac7688088608076ad2b459a84" +checksum = "02dd99dc800bbb97186339685293e1cc5d9df1f8fae2d0aecd9ff1c77efea892" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.64" +version = "1.0.68" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08904e7672f5eb876eaaf87e0ce17857500934f4981c4a0ab2b4aa98baac7fc3" +checksum = "a7c61ec9a6f64d2793d8a45faba21efbe3ced62a886d44c36a009b2b519b4c7e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.82", + "syn 2.0.87", ] [[package]] @@ -3726,6 +3898,16 @@ dependencies = [ "crunchy", ] +[[package]] +name = "tinystr" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9117f5d4db391c1cf6927e7bea3db74b9a1c1add8f7eda9ffd5364f40f57b82f" +dependencies = [ + "displaydoc", + "zerovec", +] + [[package]] name = "tinyvec" version = "1.8.0" @@ -3863,7 +4045,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.82", + "syn 2.0.87", ] [[package]] @@ -4031,12 +4213,12 @@ checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" [[package]] name = "url" -version = "2.5.2" +version = "2.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22784dbdf76fdde8af1aeda5622b546b422b6fc585325248a2bf9f5e41e94d6c" +checksum = "8d157f1b96d14500ffdc1f10ba712e780825526c03d9a49b4d0324b0d9113ada" dependencies = [ "form_urlencoded", - "idna 0.5.0", + "idna 1.0.3", "percent-encoding", ] @@ -4046,6 +4228,18 @@ version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" +[[package]] +name = "utf16_iter" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8232dd3cdaed5356e0f716d285e4b40b932ac434100fe9b7e0e8e935b9e6246" + +[[package]] +name = "utf8_iter" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be" + [[package]] name = "uuid" version = "0.8.2" @@ -4117,7 +4311,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.82", + "syn 2.0.87", "wasm-bindgen-shared", ] @@ -4151,7 +4345,7 @@ checksum = "26c6ab57572f7a24a4985830b120de1594465e5d500f24afe89e16b4e833ef68" dependencies = [ "proc-macro2", "quote", - "syn 2.0.82", + "syn 2.0.87", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -4185,7 +4379,7 @@ checksum = "c97b2ef2c8d627381e51c071c2ab328eac606d3f69dd82bcbca20a9e389d95f0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.82", + "syn 2.0.87", ] [[package]] @@ -4417,6 +4611,18 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "write16" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d1890f4022759daae28ed4fe62859b1236caebfc61ede2f63ed4e695f3f6d936" + +[[package]] +name = "writeable" +version = "0.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e9df38ee2d2c3c5948ea468a8406ff0db0b29ae1ffde1bcf20ef305bcc95c51" + [[package]] name = "ws_stream_wasm" version = "0.7.4" @@ -4451,6 +4657,30 @@ version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09041cd90cf85f7f8b2df60c646f853b7f535ce68f85244eb6731cf89fa498ec" +[[package]] +name = "yoke" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c5b1314b079b0930c31e3af543d8ee1757b1951ae1e1565ec704403a7240ca5" +dependencies = [ + "serde", + "stable_deref_trait", + "yoke-derive", + "zerofrom", +] + +[[package]] +name = "yoke-derive" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "28cc31741b18cb6f1d5ff12f5b7523e3d6eb0852bbbad19d73905511d9849b95" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.87", + "synstructure", +] + [[package]] name = "zerocopy" version = "0.7.35" @@ -4469,7 +4699,28 @@ checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.82", + "syn 2.0.87", +] + +[[package]] +name = "zerofrom" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91ec111ce797d0e0784a1116d0ddcdbea84322cd79e5d5ad173daeba4f93ab55" +dependencies = [ + "zerofrom-derive", +] + +[[package]] +name = "zerofrom-derive" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ea7b4a3637ea8669cedf0f1fd5c286a17f3de97b8dd5a70a6c167a1730e63a5" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.87", + "synstructure", ] [[package]] @@ -4478,6 +4729,28 @@ version = "1.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" +[[package]] +name = "zerovec" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa2b893d79df23bfb12d5461018d408ea19dfafe76c2c7ef6d4eba614f8ff079" +dependencies = [ + "yoke", + "zerofrom", + "zerovec-derive", +] + +[[package]] +name = "zerovec-derive" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6eafa6dfb17584ea3e2bd6e76e0cc15ad7af12b09abdd1ca55961bed9b1063c6" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.87", +] + [[package]] name = "zip" version = "0.6.6" @@ -4500,8 +4773,8 @@ dependencies = [ [[package]] name = "zk-regex-apis" -version = "2.2.0" -source = "git+https://github.com/zkemail/zk-regex.git#3319327ef3599989071ab2ea3cb9340a2c48b354" +version = "2.3.0" +source = "git+https://github.com/zkemail/zk-regex.git#f5f70b96c215659ebf38d4ed0ae9082b085842a5" dependencies = [ "fancy-regex", "itertools 0.13.0", diff --git a/Cargo.toml b/Cargo.toml index 0b7ffaf..faffc45 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -34,7 +34,7 @@ slog-term = "2.9.0" slog-json = "2.6.1" lazy_static = "1.4" file-rotate = "0.7.5" -regex = "1.10.6" +regex = "=1.10.6" mailparse = "0.15.0" wasm-bindgen = "0.2.95" wasm-bindgen-futures = "0.4.45" diff --git a/src/circuit.rs b/src/circuit.rs index 4662e96..99ac69f 100644 --- a/src/circuit.rs +++ b/src/circuit.rs @@ -1,12 +1,16 @@ use anyhow::Result; use num_bigint::BigInt; use serde::{Deserialize, Serialize}; -use std::cmp; +use serde_json::{json, Value}; +use std::{cmp, collections::VecDeque}; +use zk_regex_apis::extract_substrs::{ + extract_substr_idxes, DecomposedRegexConfig, RegexPartConfig, +}; use crate::{ field_to_hex, find_index_in_body, generate_partial_sha, remove_quoted_printable_soft_breaks, - sha256_pad, to_circom_bigint_bytes, vec_u8_to_bigint, AccountCode, PaddedEmailAddr, - ParsedEmail, MAX_BODY_PADDED_BYTES, MAX_HEADER_PADDED_BYTES, + sha256_pad, string_to_circom_bigint_bytes, to_circom_bigint_bytes, vec_u8_to_bigint, + AccountCode, PaddedEmailAddr, ParsedEmail, MAX_BODY_PADDED_BYTES, MAX_HEADER_PADDED_BYTES, }; #[derive(Serialize, Deserialize)] @@ -84,6 +88,33 @@ pub struct CircuitOptions { pub ignore_body_hash_check: Option, // Flag to ignore the body hash check } +#[derive(Serialize, Deserialize, Debug, Clone)] +#[serde(rename_all = "camelCase")] +pub struct ExternalInput { + pub name: String, // The name of the external input + pub value: Option, // The optional value of the external input + pub max_length: usize, // The maximum length of the input value +} + +#[derive(Serialize, Deserialize, Debug, Clone)] +#[serde(rename_all = "camelCase")] +pub struct DecomposedRegex { + pub parts: Vec, // The parts of the regex configuration + pub name: String, // The name of the decomposed regex + pub max_length: usize, // The maximum length of the regex match + pub location: String, // The location where the regex is applied (e.g., header or body) +} + +#[derive(Serialize, Deserialize, Debug, Clone)] +#[serde(rename_all = "camelCase")] +pub struct CircuitInputWithDecomposedRegexesAndExternalInputsParams { + pub max_header_length: usize, // The maximum length of the email header + pub max_body_length: usize, // The maximum length of the email body + pub ignore_body_hash_check: bool, // Flag to ignore the body hash check + pub remove_soft_lines_breaks: bool, // Flag to remove soft line breaks from the body + pub sha_precompute_selector: Option, // Optional regex selector for SHA-256 precomputation +} + impl CircuitInputParams { /// Creates a new `CircuitInputParams` instance with provided parameters and options. /// @@ -350,3 +381,154 @@ pub async fn generate_claim_input( // Serialize the claim circuit input to JSON and return Ok(serde_json::to_string(&claim_input)?) } + +/// Asynchronously generates circuit inputs with decomposed regexes and external inputs. +/// +/// This function processes an email, applies decomposed regexes, and incorporates external inputs +/// to produce a JSON object representing the inputs for a zero-knowledge proof circuit. +/// +/// # Arguments +/// +/// * `email` - A string slice containing the raw email data. +/// * `decomposed_regexes` - A vector of `DecomposedRegex` structs for regex processing. +/// * `external_inputs` - A vector of `ExternalInput` structs for additional inputs. +/// * `params` - Parameters for circuit input generation encapsulated in `CircuitInputWithDecomposedRegexesAndExternalInputsParams`. +/// +/// # Returns +/// +/// A `Result` which is either a JSON object of the circuit inputs on success or an error on failure. +pub async fn generate_circuit_inputs_with_decomposed_regexes_and_external_inputs( + email: &str, + decomposed_regexes: Vec, + external_inputs: Vec, + params: CircuitInputWithDecomposedRegexesAndExternalInputsParams, +) -> Result { + // Parse the raw email to extract canonicalized body and header, and other components + let parsed_email = ParsedEmail::new_from_raw_email(email).await?; + + // Clone the fields that are used by value before the move occurs + let public_key = parsed_email.public_key.clone(); + let signature = parsed_email.signature.clone(); + + // Create a CircuitParams struct from the parsed email + let circuit_params = CircuitParams { + body: parsed_email.canonicalized_body.as_bytes().to_vec(), + header: parsed_email.canonicalized_header.as_bytes().to_vec(), + body_hash_idx: parsed_email.get_body_hash_idxes()?.0, + rsa_signature: vec_u8_to_bigint(signature), + rsa_public_key: vec_u8_to_bigint(public_key), + }; + + // Create a CircuitOptions struct from the optional parameters + let circuit_options = CircuitOptions { + sha_precompute_selector: params.sha_precompute_selector, + max_header_length: Some(params.max_header_length), + max_body_length: Some(params.max_body_length), + ignore_body_hash_check: Some(params.ignore_body_hash_check), + }; + + // Create circuit input parameters from the CircuitParams and CircuitOptions structs + let circuit_input_params = CircuitInputParams::new(circuit_params, circuit_options); + + // Generate the circuit inputs from the parameters + let email_circuit_inputs = generate_circuit_inputs(circuit_input_params.clone())?; + + // Create a JSON object to hold the circuit inputs + let mut circuit_inputs = json!({ + "emailHeader": email_circuit_inputs.header_padded, + "emailHeaderLength": email_circuit_inputs.header_len_padded_bytes, + "pubkey": email_circuit_inputs.pubkey, + "signature": email_circuit_inputs.signature, + }); + + // Include body-related inputs if the body hash check is not ignored + if !params.ignore_body_hash_check { + circuit_inputs["bodyHashIndex"] = email_circuit_inputs.body_hash_idx.into(); + circuit_inputs["precomputedSHA"] = email_circuit_inputs.precomputed_sha.into(); + circuit_inputs["emailBody"] = email_circuit_inputs.body_padded.clone().into(); + circuit_inputs["emailBodyLength"] = email_circuit_inputs.body_len_padded_bytes.into(); + } + + // Clean the body by removing quoted-printable soft breaks if necessary + let cleaned_body = email_circuit_inputs + .body_padded + .clone() + .map(remove_quoted_printable_soft_breaks); + + // Add the cleaned body to the circuit inputs if soft line breaks are to be removed + if params.remove_soft_lines_breaks { + circuit_inputs["decodedEmailBodyIn"] = cleaned_body.clone().into(); + } + + // Process each decomposed regex and add the resulting indices to the circuit inputs + for decomposed_regex in decomposed_regexes { + let mut decomposed_regex_config = DecomposedRegexConfig { + parts: VecDeque::new().into(), + }; + for part in decomposed_regex.parts { + decomposed_regex_config.parts.push(part); + } + + // Determine the input string based on the regex location + let input = if decomposed_regex.location == "header" { + &String::from_utf8(email_circuit_inputs.header_padded.clone())? + } else if decomposed_regex.location == "body" && params.remove_soft_lines_breaks { + &cleaned_body + .as_ref() + .map(|v| String::from_utf8_lossy(v).into_owned()) + .unwrap_or_else(|| String::new()) + } else { + &email_circuit_inputs + .body_padded + .as_ref() + .map(|v| String::from_utf8_lossy(v).into_owned()) + .unwrap_or_else(|| String::new()) + }; + + // Extract substring indices using the decomposed regex configuration + let idxes: Vec<(usize, usize)> = + extract_substr_idxes(input, &decomposed_regex_config, true)?; + + // Add the first index to the circuit inputs + circuit_inputs[format!("{}RegexIdx", decomposed_regex.name)] = idxes[0].0.into(); + } + + // Process each external input and add it to the circuit inputs + for external_input in external_inputs { + let mut value = + string_to_circom_bigint_bytes(&external_input.value.as_deref().unwrap_or(""))?; + let signal_length = compute_signal_length(external_input.max_length); + + // Pad the value to the signal length + if value.len() < signal_length { + value.extend( + vec![0; signal_length - value.len()] + .into_iter() + .map(|num| num.to_string()), + ); + } + + // Add the external input to the circuit inputs + circuit_inputs[external_input.name] = value.into(); + } + + // Return the circuit inputs as a JSON object + Ok(circuit_inputs) +} + +/// Computes the signal length required for a given maximum length. +/// +/// This function calculates the number of 31-byte segments needed to accommodate +/// the given `max_length`. If there is a remainder when dividing by 31, an additional +/// segment is added to ensure the entire length is covered. +/// +/// # Arguments +/// +/// * `max_length` - The maximum length of the input for which the signal length is computed. +/// +/// # Returns +/// +/// The computed signal length as a `usize`. +pub fn compute_signal_length(max_length: usize) -> usize { + (max_length / 31) + if max_length % 31 != 0 { 1 } else { 0 } +} diff --git a/src/converters.rs b/src/converters.rs index cc2a30b..ca30d4c 100644 --- a/src/converters.rs +++ b/src/converters.rs @@ -445,3 +445,38 @@ pub fn uint_to_decimal_string(uint: u128, decimal: usize) -> String { compact_result } + +/// Converts a string to a vector of strings representing Circom-compatible big integers. +/// +/// This function takes an input string, converts it to UTF-8 bytes, and then processes +/// these bytes into field elements. Each field element is then converted into a big integer +/// string representation suitable for use in Circom circuits. +/// +/// # Arguments +/// +/// * `input` - A string slice to be converted. +/// +/// # Returns +/// +/// A `Result` containing a vector of strings, each representing a big integer, or an error on failure. +pub fn string_to_circom_bigint_bytes(input: &str) -> Result> { + // Convert the input string to UTF-8 bytes + let utf8_bytes = input.as_bytes(); + + // Convert the bytes to field elements + let frs = bytes_to_fields(utf8_bytes); + + // Convert each field element to a big integer string + let num_strings: Vec = frs + .iter() + .map(|fr| { + // Convert the field element to a 32-byte array + let bytes = fr_to_bytes32(fr).expect("Failed to convert Fr to bytes"); + // Convert the byte array to a big integer and then to a string + BigInt::from_bytes_be(num_bigint::Sign::Plus, &bytes).to_string() + }) + .collect(); + + // Return the vector of big integer strings + Ok(num_strings) +}