diff --git a/.gitignore b/.gitignore index 1480ec778..5f38836d9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ -/target *.json -output/ +.idea/ +/target +/output crates/playground/wasm crates/playground/target diff --git a/Cargo.lock b/Cargo.lock index 0c63a687c..3319b08c8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -17,6 +17,28 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" +[[package]] +name = "ahash" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fcb51a0695d8f838b1ee009b3fbf66bda078cd64590202a864a8f3e8c4315c47" +dependencies = [ + "getrandom", + "once_cell", + "version_check", +] + +[[package]] +name = "ahash" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c99f64d1e06488f620f932677e24bc6e2897582980441ae90a671415bd7ec2f" +dependencies = [ + "cfg-if 1.0.0", + "once_cell", + "version_check", +] + [[package]] name = "aho-corasick" version = "1.0.2" @@ -26,6 +48,12 @@ dependencies = [ "memchr", ] +[[package]] +name = "allocator-api2" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0942ffc6dcaadf03badf6e6a2d0228460359d5e34b57ccdc720b7382dfbd5ec5" + [[package]] name = "android-tzdata" version = "0.1.1" @@ -73,6 +101,17 @@ version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" +[[package]] +name = "async-trait" +version = "0.1.73" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc00ceb34980c03614e35a3a4e218276a0a824e911d07651cd0d858a51e8c0f0" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.28", +] + [[package]] name = "atty" version = "0.2.14" @@ -105,6 +144,18 @@ dependencies = [ "rustc-demangle", ] +[[package]] +name = "base64" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" + +[[package]] +name = "base64" +version = "0.21.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "604178f6c5c21f02dc555784810edfb88d34ac2c73b2eae109655649ee73ce3d" + [[package]] name = "bitflags" version = "1.3.2" @@ -161,6 +212,27 @@ dependencies = [ "subtle", ] +[[package]] +name = "bson" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9aeb8bae494e49dbc330dd23cf78f6f7accee22f640ce3ab17841badaa4ce232" +dependencies = [ + "ahash 0.7.6", + "base64 0.13.1", + "bitvec", + "hex", + "indexmap 1.9.3", + "js-sys", + "lazy_static", + "rand", + "serde", + "serde_bytes", + "serde_json", + "time", + "uuid", +] + [[package]] name = "bstr" version = "1.6.0" @@ -177,6 +249,12 @@ version = "3.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f1e260c3a9040a7c19a12468758f4c16f31a81a1fe087482be9570ec864bb6c" +[[package]] +name = "bytes" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "89b2fd2a0dcf38d7971e2194b6b6eebab45ae01067456a7fd93d5547a61b70be" + [[package]] name = "cc" version = "1.0.80" @@ -232,6 +310,43 @@ dependencies = [ "phf_codegen", ] +[[package]] +name = "circuits-batcher" +version = "0.1.0" +source = "git+https://github.com/DelphinusLab/continuation-batcher.git#7eccb6358a3b68d13be901791bd0661f0545ea06" +dependencies = [ + "anyhow", + "ark-std", + "bitvec", + "clap", + "downcast-rs", + "env_logger", + "ff", + "halo2_proofs", + "halo2aggregator-s", + "halo2ecc-s", + "hex", + "lazy_static", + "log", + "md5", + "num", + "num-bigint", + "num-derive", + "num-integer", + "num-traits", + "poseidon", + "quote", + "rand", + "serde", + "serde_json", + "sha2", + "strum", + "strum_macros", + "uuid", + "wabt", + "wast", +] + [[package]] name = "clap" version = "3.2.25" @@ -242,7 +357,7 @@ dependencies = [ "bitflags 1.3.2", "clap_derive", "clap_lex", - "indexmap", + "indexmap 1.9.3", "once_cell", "strsim", "termcolor", @@ -297,6 +412,12 @@ version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "21a53c0a4d288377e7415b53dcfc3c04da5cdc2cc95c8d5ac178b58f0b861ad6" +[[package]] +name = "convert_case" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e" + [[package]] name = "core-foundation-sys" version = "0.8.4" @@ -395,13 +516,56 @@ dependencies = [ "cuda-config", ] +[[package]] +name = "darling" +version = "0.13.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a01d95850c592940db9b8194bc39f4bc0e89dee5c4265e4b1807c34a9aba453c" +dependencies = [ + "darling_core", + "darling_macro", +] + +[[package]] +name = "darling_core" +version = "0.13.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "859d65a907b6852c9361e3185c862aae7fafd2887876799fa55f5f99dc40d610" +dependencies = [ + "fnv", + "ident_case", + "proc-macro2", + "quote", + "strsim", + "syn 1.0.109", +] + +[[package]] +name = "darling_macro" +version = "0.13.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c972679f83bdf9c42bd905396b6c3588a843a17f0f16dfcfa3e2c5d57441835" +dependencies = [ + "darling_core", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "data-encoding" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2e66c9d817f1720209181c316d28635c050fa304f9c79e47a520882661b7308" + [[package]] name = "delphinus-cli" version = "0.1.0" dependencies = [ "anyhow", "ark-std", + "circuits-batcher", "clap", + "delphinus-host", "delphinus-zkwasm", "env_logger", "halo2_proofs", @@ -417,6 +581,39 @@ dependencies = [ "wasmi", ] +[[package]] +name = "delphinus-host" +version = "0.1.0" +dependencies = [ + "anyhow", + "ark-std", + "bitvec", + "delphinus-zkwasm", + "downcast-rs", + "ff", + "halo2_proofs", + "halo2aggregator-s", + "hex", + "lazy_static", + "log", + "num-bigint", + "num-integer", + "num-traits", + "parity-wasm", + "poseidon", + "rand", + "rusty-fork", + "serde", + "serde_json", + "sha2", + "specs", + "strum", + "strum_macros", + "wabt", + "wasmi", + "zkwasm-host-circuits", +] + [[package]] name = "delphinus-zkwasm" version = "0.1.0" @@ -425,6 +622,7 @@ dependencies = [ "ark-std", "bitvec", "downcast-rs", + "ff", "halo2_proofs", "halo2aggregator-s", "hex", @@ -434,15 +632,48 @@ dependencies = [ "num-integer", "num-traits", "parity-wasm", + "poseidon", "rand", "rusty-fork", "serde", "serde_json", + "sha2", "specs", "strum", "strum_macros", "wabt", "wasmi", + "zkwasm-host-circuits", +] + +[[package]] +name = "deranged" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7684a49fb1af197853ef7b2ee694bc1f5b4179556f1e5710e1760c5db6f5e929" + +[[package]] +name = "derivative" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fcc3dd5e9e9c0b295d6e1e4d811fb6f157d5ffd784b8d202fc62eac8035a770b" +dependencies = [ + "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]] @@ -459,6 +690,7 @@ checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" dependencies = [ "block-buffer", "crypto-common", + "subtle", ] [[package]] @@ -521,6 +753,18 @@ version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07" +[[package]] +name = "enum-as-inner" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "21cdad81446a7f7dc43f6a77409efeb9733d2fa65553efef6018ef257c959b73" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "syn 1.0.109", +] + [[package]] name = "env_logger" version = "0.9.3" @@ -534,6 +778,12 @@ dependencies = [ "termcolor", ] +[[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.2" @@ -639,7 +889,7 @@ version = "0.10.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1657b4441c3403d9f7b3409e47575237dac27b1b5726df654a6ecbf92f0f7577" dependencies = [ - "spin", + "spin 0.9.8", ] [[package]] @@ -648,6 +898,15 @@ version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" +[[package]] +name = "form_urlencoded" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a62bc1cf6f830c2ec14a513a9fb124d0a213a629668a4186f329db21fe045652" +dependencies = [ + "percent-encoding", +] + [[package]] name = "fsevent-sys" version = "4.1.0" @@ -663,6 +922,77 @@ version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" +[[package]] +name = "futures-channel" +version = "0.3.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "955518d47e09b25bbebc7a18df10b81f0c766eaf4c4f1cccef2fca5f2a4fb5f2" +dependencies = [ + "futures-core", +] + +[[package]] +name = "futures-core" +version = "0.3.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4bca583b7e26f571124fe5b7561d49cb2868d79116cfa0eefce955557c6fee8c" + +[[package]] +name = "futures-executor" +version = "0.3.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ccecee823288125bd88b4d7f565c9e58e41858e47ab72e8ea2d64e93624386e0" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fff74096e71ed47f8e023204cfd0aa1289cd54ae5430a9523be060cdb849964" + +[[package]] +name = "futures-macro" +version = "0.3.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "89ca545a94061b6365f2c7355b4b32bd20df3ff95f02da9329b34ccc3bd6ee72" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.28", +] + +[[package]] +name = "futures-sink" +version = "0.3.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f43be4fe21a13b9781a69afa4985b0f6ee0e1afab2c6f454a8cf30e2b2237b6e" + +[[package]] +name = "futures-task" +version = "0.3.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76d3d132be6c0e6aa1534069c705a74a5997a356c0dc2f86a47765e5617c5b65" + +[[package]] +name = "futures-util" +version = "0.3.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26b01e40b772d54cf6c6d721c1d1abd0647a0106a12ecaa1c186273392a69533" +dependencies = [ + "futures-core", + "futures-io", + "futures-macro", + "futures-task", + "memchr", + "pin-project-lite", + "pin-utils", + "slab", +] + [[package]] name = "generic-array" version = "0.14.7" @@ -799,6 +1129,16 @@ version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" +[[package]] +name = "hashbrown" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c6201b9ff9fd90a5a3bac2e56a830d0caa509576f0e503818ee82c181b3437a" +dependencies = [ + "ahash 0.8.3", + "allocator-api2", +] + [[package]] name = "heck" version = "0.4.1" @@ -826,6 +1166,26 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" +[[package]] +name = "hmac" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" +dependencies = [ + "digest", +] + +[[package]] +name = "hostname" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c731c3e10504cc8ed35cfe2f1db4c9274c3d35fa486e3b31df46f068ef3e867" +dependencies = [ + "libc", + "match_cfg", + "winapi 0.3.9", +] + [[package]] name = "humansize" version = "2.1.3" @@ -865,14 +1225,41 @@ dependencies = [ ] [[package]] -name = "ignore" -version = "0.4.20" +name = "ident_case" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dbe7873dab538a9a44ad79ede1faf5f30d49f9a5c883ddbab48bce81b64b7492" +checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" + +[[package]] +name = "idna" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "418a0a6fab821475f634efe3ccc45c013f742efe03d853e8d3355d5cb850ecf8" dependencies = [ - "globset", - "lazy_static", - "log", + "matches", + "unicode-bidi", + "unicode-normalization", +] + +[[package]] +name = "idna" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d20d6b07bfbc108882d88ed8e37d39636dcc260e15e30c45e6ba089610b917c" +dependencies = [ + "unicode-bidi", + "unicode-normalization", +] + +[[package]] +name = "ignore" +version = "0.4.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dbe7873dab538a9a44ad79ede1faf5f30d49f9a5c883ddbab48bce81b64b7492" +dependencies = [ + "globset", + "lazy_static", + "log", "memchr", "regex", "same-file", @@ -888,7 +1275,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99" dependencies = [ "autocfg", - "hashbrown", + "hashbrown 0.12.3", +] + +[[package]] +name = "indexmap" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d5477fe2230a79769d8dc68e0eabf5437907c0457a5614a9e8dddb67f65eb65d" +dependencies = [ + "equivalent", + "hashbrown 0.14.0", ] [[package]] @@ -911,6 +1308,24 @@ dependencies = [ "libc", ] +[[package]] +name = "ipconfig" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b58db92f96b720de98181bbbe63c831e87005ab460c1bf306eb2622b4707997f" +dependencies = [ + "socket2 0.5.3", + "widestring", + "windows-sys 0.48.0", + "winreg", +] + +[[package]] +name = "ipnet" +version = "2.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "28b29a3cd74f0f4598934efe3aeba42bae0eb4680554128851ebbecb02af14e6" + [[package]] name = "is-terminal" version = "0.4.9" @@ -973,6 +1388,12 @@ version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" +[[package]] +name = "leb128" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "884e2677b40cc8c339eaefcb701c32ef1fd2493d71118dc0ca4b6a736c93bd67" + [[package]] name = "libc" version = "0.2.147" @@ -985,6 +1406,12 @@ version = "0.2.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f7012b1bbb0719e1097c47611d3898568c546d597c2e74d66f6087edd5233ff4" +[[package]] +name = "linked-hash-map" +version = "0.5.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0717cef1bc8b636c6e1c1bbdefc09e6322da8a9321966e8928ef80d20f7f770f" + [[package]] name = "linux-raw-sys" version = "0.4.5" @@ -1007,6 +1434,45 @@ version = "0.4.19" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b06a4cde4c0f271a446782e3eff8de789548ce57dbc8eca9292c27f4a42004b4" +[[package]] +name = "lru" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eedb2bdbad7e0634f83989bf596f497b070130daaa398ab22d84c39e266deec5" +dependencies = [ + "hashbrown 0.14.0", +] + +[[package]] +name = "lru-cache" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "31e24f1ad8321ca0e8a1e0ac13f23cb668e6f5466c2c57319f6a5cf1cc8e3b1c" +dependencies = [ + "linked-hash-map", +] + +[[package]] +name = "match_cfg" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ffbee8634e0d45d258acb448e7eaab3fce7a0a467395d4d9f228e3c1f01fb2e4" + +[[package]] +name = "matches" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2532096657941c2fea9c289d370a250971c689d4f143798ff67113ec042024a5" + +[[package]] +name = "md-5" +version = "0.10.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6365506850d44bff6e2fbcb5176cf63650e48bd45ef2fe2665ae1570e0f4b9ca" +dependencies = [ + "digest", +] + [[package]] name = "md5" version = "0.7.0" @@ -1065,6 +1531,53 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "mongodb" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebcd85ec209a5b84fd9f54b9e381f6fa17462bc74160d018fc94fd8b9f61faa8" +dependencies = [ + "async-trait", + "base64 0.13.1", + "bitflags 1.3.2", + "bson", + "chrono", + "derivative", + "derive_more", + "futures-core", + "futures-executor", + "futures-io", + "futures-util", + "hex", + "hmac", + "lazy_static", + "md-5", + "pbkdf2", + "percent-encoding", + "rand", + "rustc_version_runtime", + "rustls", + "rustls-pemfile", + "serde", + "serde_bytes", + "serde_with", + "sha-1", + "sha2", + "socket2 0.4.9", + "stringprep", + "strsim", + "take_mut", + "thiserror", + "tokio", + "tokio-rustls", + "tokio-util", + "trust-dns-proto", + "trust-dns-resolver", + "typed-builder", + "uuid", + "webpki-roots", +] + [[package]] name = "notify" version = "6.0.1" @@ -1232,6 +1745,29 @@ version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "be5e13c266502aadf83426d87d81a0f5d1ef45b8027f5a471c360abfe4bfae92" +[[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.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93f00c865fe7cabf650081affecd3871070f26767e7b2070a3ffae14c654b447" +dependencies = [ + "cfg-if 1.0.0", + "libc", + "redox_syscall 0.3.5", + "smallvec", + "windows-targets 0.48.1", +] + [[package]] name = "parse-zoneinfo" version = "0.3.0" @@ -1241,6 +1777,15 @@ dependencies = [ "regex", ] +[[package]] +name = "pbkdf2" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "83a0692ec44e4cf1ef28ca317f14f8f07da2d95ec3fa01f86e4467b725e60917" +dependencies = [ + "digest", +] + [[package]] name = "percent-encoding" version = "2.3.0" @@ -1330,6 +1875,18 @@ dependencies = [ "uncased", ] +[[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 = "poseidon" version = "0.2.0" @@ -1509,6 +2066,40 @@ version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e5ea92a5b6195c6ef2a0295ea818b312502c6fc94dde986c5553242e18fd4ce2" +[[package]] +name = "resolv-conf" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "52e44394d2086d010551b14b53b1f24e31647570cd1deb0379e2c21b329aba00" +dependencies = [ + "hostname", + "quick-error", +] + +[[package]] +name = "ring" +version = "0.16.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3053cf52e236a3ed746dfc745aa9cacf1b791d846bdaf412f60a8d7d6e17c8fc" +dependencies = [ + "cc", + "libc", + "once_cell", + "spin 0.5.2", + "untrusted", + "web-sys", + "winapi 0.3.9", +] + +[[package]] +name = "ripemd" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd124222d17ad93a644ed9d011a40f4fb64aa54275c08cc216524a9ea82fb09f" +dependencies = [ + "digest", +] + [[package]] name = "rust-gpu-tools" version = "0.6.2" @@ -1549,6 +2140,34 @@ 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.18", +] + +[[package]] +name = "rustc_version_runtime" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d31b7153270ebf48bf91c65ae5b0c00e749c4cfad505f66530ac74950249582f" +dependencies = [ + "rustc_version 0.2.3", + "semver 0.9.0", +] + [[package]] name = "rustix" version = "0.38.4" @@ -1562,6 +2181,27 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "rustls" +version = "0.20.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fff78fc74d175294f4e83b28343315ffcfb114b156f0185e9741cb5570f50e2f" +dependencies = [ + "log", + "ring", + "sct", + "webpki", +] + +[[package]] +name = "rustls-pemfile" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2d3987094b1d07b653b7dfdc3f70ce9a1da9c51ac18c1b06b662e4f9a0e9f4b2" +dependencies = [ + "base64 0.21.2", +] + [[package]] name = "rustversion" version = "1.0.14" @@ -1601,6 +2241,37 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" +[[package]] +name = "sct" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d53dcdb7c9f8158937a7981b48accfd39a43af418591a5d008c7b22b5e1b7ca4" +dependencies = [ + "ring", + "untrusted", +] + +[[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.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b0293b4b29daaf487284529cc2f5675b8e57c61f70167ba415a463651fd6a918" + +[[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.180" @@ -1610,6 +2281,15 @@ dependencies = [ "serde_derive", ] +[[package]] +name = "serde_bytes" +version = "0.11.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab33ec92f677585af6d88c65593ae2375adde54efdbf16d597f2cbc7a6d368ff" +dependencies = [ + "serde", +] + [[package]] name = "serde_derive" version = "1.0.180" @@ -1627,11 +2307,45 @@ version = "1.0.104" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "076066c5f1078eac5b722a31827a8832fe108bed65dfa75e233c89f8206e976c" dependencies = [ + "indexmap 2.0.0", "itoa", "ryu", "serde", ] +[[package]] +name = "serde_with" +version = "1.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "678b5a069e50bf00ecd22d0cd8ddf7c236f68581b03db652061ed5eb13a312ff" +dependencies = [ + "serde", + "serde_with_macros", +] + +[[package]] +name = "serde_with_macros" +version = "1.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e182d6ec6f05393cc0e5ed1bf81ad6db3a8feedf8ee515ecdd369809bcce8082" +dependencies = [ + "darling", + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "sha-1" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f5058ada175748e33390e40e872bd0fe59a19f265d0158daa551c5a88a76009c" +dependencies = [ + "cfg-if 1.0.0", + "cpufeatures", + "digest", +] + [[package]] name = "sha2" version = "0.10.7" @@ -1643,12 +2357,30 @@ dependencies = [ "digest", ] +[[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 = "siphasher" version = "0.3.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7bd3e3206899af3f8b12af284fafc038cc1dc2b41d1b89dd17297221c5d225de" +[[package]] +name = "slab" +version = "0.4.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6528351c9bc8ab22353f9d776db39a20288e8d6c37ef8cfe3317cf875eecfc2d" +dependencies = [ + "autocfg", +] + [[package]] name = "slug" version = "0.1.4" @@ -1658,11 +2390,38 @@ dependencies = [ "deunicode", ] +[[package]] +name = "smallvec" +version = "1.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62bb4feee49fdd9f707ef802e22365a35de4b7b299de4763d44bfea899442ff9" + +[[package]] +name = "socket2" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64a4a911eed85daf18834cfaa86a79b7d266ff93ff5ba14005426219480ed662" +dependencies = [ + "libc", + "winapi 0.3.9", +] + +[[package]] +name = "socket2" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2538b18701741680e0322a2302176d3253a35388e2e62f172f64f4f16605f877" +dependencies = [ + "libc", + "windows-sys 0.48.0", +] + [[package]] name = "specs" version = "0.1.0" dependencies = [ "halo2_proofs", + "hex", "lazy_static", "num-bigint", "parity-wasm", @@ -1672,6 +2431,12 @@ dependencies = [ "strum_macros", ] +[[package]] +name = "spin" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" + [[package]] name = "spin" version = "0.9.8" @@ -1687,6 +2452,16 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" +[[package]] +name = "stringprep" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db3737bde7edce97102e0e2b15365bf7a20bfdb5f60f4f9e8d7004258a51a8da" +dependencies = [ + "unicode-bidi", + "unicode-normalization", +] + [[package]] name = "strsim" version = "0.10.0" @@ -1740,6 +2515,12 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "take_mut" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f764005d11ee5f36500a149ace24e00e3da98b0158b3e2d53a7495660d3f4d60" + [[package]] name = "tap" version = "1.0.1" @@ -1835,6 +2616,159 @@ dependencies = [ "once_cell", ] +[[package]] +name = "time" +version = "0.3.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b0fdd63d58b18d663fbdf70e049f00a22c8e42be082203be7f26589213cd75ea" +dependencies = [ + "deranged", + "itoa", + "serde", + "time-core", + "time-macros", +] + +[[package]] +name = "time-core" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7300fbefb4dadc1af235a9cef3737cea692a9d97e1b9cbcd4ebdae6f8868e6fb" + +[[package]] +name = "time-macros" +version = "0.2.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eb71511c991639bb078fd5bf97757e03914361c48100d52878b8e52b46fb92cd" +dependencies = [ + "time-core", +] + +[[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.31.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "40de3a2ba249dcb097e01be5e67a5ff53cf250397715a071a81543e8a832a920" +dependencies = [ + "backtrace", + "bytes", + "libc", + "mio", + "num_cpus", + "pin-project-lite", + "signal-hook-registry", + "socket2 0.5.3", + "tokio-macros", + "windows-sys 0.48.0", +] + +[[package]] +name = "tokio-macros" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "630bdcf245f78637c13ec01ffae6187cca34625e8c63150d424b59e55af2675e" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.28", +] + +[[package]] +name = "tokio-rustls" +version = "0.23.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c43ee83903113e03984cb9e5cebe6c04a5116269e900e3ddba8f068a62adda59" +dependencies = [ + "rustls", + "tokio", + "webpki", +] + +[[package]] +name = "tokio-util" +version = "0.7.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "806fe8c2c87eccc8b3267cbae29ed3ab2d0bd37fca70ab622e46aaa9375ddb7d" +dependencies = [ + "bytes", + "futures-core", + "futures-io", + "futures-sink", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "trust-dns-proto" +version = "0.21.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c31f240f59877c3d4bb3b3ea0ec5a6a0cff07323580ff8c7a605cd7d08b255d" +dependencies = [ + "async-trait", + "cfg-if 1.0.0", + "data-encoding", + "enum-as-inner", + "futures-channel", + "futures-io", + "futures-util", + "idna 0.2.3", + "ipnet", + "lazy_static", + "log", + "rand", + "smallvec", + "thiserror", + "tinyvec", + "tokio", + "url", +] + +[[package]] +name = "trust-dns-resolver" +version = "0.21.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e4ba72c2ea84515690c9fcef4c6c660bb9df3036ed1051686de84605b74fd558" +dependencies = [ + "cfg-if 1.0.0", + "futures-util", + "ipconfig", + "lazy_static", + "log", + "lru-cache", + "parking_lot", + "resolv-conf", + "smallvec", + "thiserror", + "tokio", + "trust-dns-proto", +] + +[[package]] +name = "typed-builder" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "89851716b67b937e393b3daa8423e67ddfc4bbbf1654bcf05488e95e0828db0c" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + [[package]] name = "typenum" version = "1.16.0" @@ -1906,12 +2840,60 @@ dependencies = [ "unic-common", ] +[[package]] +name = "unicode-bidi" +version = "0.3.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92888ba5573ff080736b3648696b70cafad7d250551175acbaa4e0385b3e1460" + [[package]] name = "unicode-ident" version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "301abaae475aa91687eb82514b328ab47a211a533026cb25fc3e519b86adfc3c" +[[package]] +name = "unicode-normalization" +version = "0.1.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c5713f0fc4b5db668a2ac63cdb7bb4469d8c9fed047b1d0292cc7b0ce2ba921" +dependencies = [ + "tinyvec", +] + +[[package]] +name = "unicode-width" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b" + +[[package]] +name = "untrusted" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a" + +[[package]] +name = "url" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50bff7831e19200a85b17131d085c25d7811bc4e186efdaf54bbd132994a88cb" +dependencies = [ + "form_urlencoded", + "idna 0.4.0", + "percent-encoding", +] + +[[package]] +name = "uuid" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79daa5ed5740825c40b389c5e50312b9c86df53fccd33f281df655642b43869d" +dependencies = [ + "getrandom", + "serde", +] + [[package]] name = "version_check" version = "0.9.4" @@ -2020,6 +3002,15 @@ version = "0.2.87" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ca6ad05a4870b2bf5fe995117d3728437bd27d7cd5f06f13c17443ef369775a1" +[[package]] +name = "wasm-encoder" +version = "0.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c64ac98d5d61192cc45c701b7e4bd0b9aff91e2edfc7a088406cfe2288581e2c" +dependencies = [ + "leb128", +] + [[package]] name = "wasmi" version = "0.11.0" @@ -2049,6 +3040,53 @@ dependencies = [ "parity-wasm", ] +[[package]] +name = "wast" +version = "47.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02b98502f3978adea49551e801a6687678e6015317d7d9470a67fe813393f2a8" +dependencies = [ + "leb128", + "memchr", + "unicode-width", + "wasm-encoder", +] + +[[package]] +name = "web-sys" +version = "0.3.64" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b85cbef8c220a6abc02aefd892dfc0fc23afb1c6a426316ec33253a3877249b" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "webpki" +version = "0.22.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f095d78192e208183081cc07bc5515ef55216397af48b873e5edcd72637fa1bd" +dependencies = [ + "ring", + "untrusted", +] + +[[package]] +name = "webpki-roots" +version = "0.22.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6c71e40d7d2c34a5106301fb632274ca37242cd0c9d3e64dbece371a40a2d87" +dependencies = [ + "webpki", +] + +[[package]] +name = "widestring" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "653f141f39ec16bba3c5abe400a0c60da7468261cc2cbf36805022876bc721a8" + [[package]] name = "winapi" version = "0.2.8" @@ -2233,6 +3271,16 @@ version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a" +[[package]] +name = "winreg" +version = "0.50.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "524e57b2c537c0f9b1e69f1965311ec12182b4122e45035b1508cd24d2adadb1" +dependencies = [ + "cfg-if 1.0.0", + "windows-sys 0.48.0", +] + [[package]] name = "wyz" version = "0.5.1" @@ -2251,3 +3299,29 @@ dependencies = [ "flume", "scopeguard", ] + +[[package]] +name = "zkwasm-host-circuits" +version = "0.1.0" +source = "git+https://github.com/DelphinusLab/zkWasm-host-circuits.git?branch=main#e4dbc533b04963c0e3eb2db5101c0b096a0eea8b" +dependencies = [ + "ark-std", + "circuits-batcher", + "clap", + "ff", + "halo2_proofs", + "halo2ecc-s", + "hex", + "lazy_static", + "lru", + "mongodb", + "num-bigint", + "poseidon", + "rand", + "ripemd", + "serde", + "serde_json", + "strum", + "strum_macros", + "subtle", +] diff --git a/Cargo.toml b/Cargo.toml index 4b8cfc0a4..463a20284 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,5 @@ [workspace] -members = ["crates/specs", "crates/zkwasm", "crates/cli"] +members = ["crates/specs", "crates/zkwasm", "crates/cli", "crates/host"] exclude = ["third-party/wasmi", "crates/playground"] [workspace.dependencies] diff --git a/README.md b/README.md index e61a00ce3..145124582 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,7 @@ git clone --recurse-submodules wasm code ## Runtime input: -input of wasm function and the top level function must be main. +input of wasm function and the top level function must be zkmain ## Proving target: simulation of wasm execution of target wasm bytecode with particular inputs are correct. @@ -53,9 +53,13 @@ cargo run --release -- --function --wasm single-ve ``` with OPTIONS: ``` + --param [...] + Path of the setup related files (circuit info, vkey, params, etc). -o, --output [...] Path of the output files. The md5 of the wasm binary file is the default path if not supplied. + -p, --param [...] + Path of the parameter files. (trusted setup, etc) --private [...] Private arguments of your wasm program arguments of format value:type where @@ -66,15 +70,7 @@ with OPTIONS: type=i64|bytes|bytes-packed, multiple values should be separated with ' ' (space) ``` ## Batch prove and verify: -``` -cargo run --release -- --function --wasm aggregate-prove [OPTIONS] -cargo run --release -- --function --wasm aggregate-verify --proof --instances -``` - -## Generate verify contract: -``` -cargo run --release --function --wasm solidity-aggregate-verifier --proof --instances -``` +Please see zkWASM continuation batcher at https://github.com/DelphinusLab/continuation-batcher for batching proof with host circuits and verifier generation in smart contracts. # Operations Spec [WIP] We uses z3 (https://github.com/Z3Prover/z3) to check that all operation are compiled to zkp circuits correctly. diff --git a/crates/cli/Cargo.toml b/crates/cli/Cargo.toml index 474274cbe..fe1eca45e 100644 --- a/crates/cli/Cargo.toml +++ b/crates/cli/Cargo.toml @@ -18,11 +18,13 @@ hex = "0.4.3" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" delphinus-zkwasm = { path = "../zkwasm" } +delphinus-host = { path = "../host" } anyhow.workspace = true halo2aggregator-s.workspace = true halo2_proofs.workspace = true wasmi.workspace = true +circuits-batcher = { git = "https://github.com/DelphinusLab/continuation-batcher.git" } [features] default = [] -cuda = ["delphinus-zkwasm/cuda"] \ No newline at end of file +cuda = ["delphinus-zkwasm/cuda"] diff --git a/crates/cli/src/app_builder.rs b/crates/cli/src/app_builder.rs index ba042935e..e1d45a6c2 100644 --- a/crates/cli/src/app_builder.rs +++ b/crates/cli/src/app_builder.rs @@ -2,6 +2,8 @@ use anyhow::Result; use clap::App; use clap::AppSettings; use delphinus_zkwasm::circuits::config::MIN_K; +use delphinus_zkwasm::runtime::host::default_env::DefaultHostEnvBuilder; +use delphinus_zkwasm::runtime::host::default_env::ExecutionArg; use log::info; use log::warn; use std::fs; @@ -13,13 +15,10 @@ use std::sync::Mutex; use crate::exec::exec_dry_run; use super::command::CommandBuilder; -use super::exec::exec_aggregate_create_proof; use super::exec::exec_create_proof; use super::exec::exec_dry_run_service; use super::exec::exec_image_checksum; use super::exec::exec_setup; -use super::exec::exec_solidity_aggregate_proof; -use super::exec::exec_verify_aggregate_proof; use super::exec::exec_verify_proof; fn load_or_generate_output_path(wasm_md5: &String, path: Option<&PathBuf>) -> PathBuf { @@ -65,6 +64,7 @@ pub trait AppBuilder: CommandBuilder { .setting(AppSettings::SubcommandRequired) .arg(Self::zkwasm_k_arg()) .arg(Self::output_path_arg()) + .arg(Self::param_path_arg()) .arg(Self::function_name_arg()) .arg(Self::phantom_functions_arg()) .arg(Self::zkwasm_file_arg()); @@ -73,9 +73,6 @@ pub trait AppBuilder: CommandBuilder { let app = Self::append_dry_run_subcommand(app); let app = Self::append_create_single_proof_subcommand(app); let app = Self::append_verify_single_proof_subcommand(app); - let app = Self::append_create_aggregate_proof_subcommand(app); - let app = Self::append_verify_aggregate_verify_subcommand(app); - let app = Self::append_generate_solidity_verifier(app); let app = Self::append_image_checksum_subcommand(app); app @@ -97,22 +94,29 @@ pub trait AppBuilder: CommandBuilder { let md5 = format!("{:X}", md5::compute(&wasm_binary)); let phantom_functions = Self::parse_phantom_functions(&top_matches); + let param_dir = load_or_generate_output_path(&md5, top_matches.get_one::("param")); + let output_dir = load_or_generate_output_path(&md5, top_matches.get_one::("output")); fs::create_dir_all(&output_dir)?; + fs::create_dir_all(¶m_dir)?; match top_matches.subcommand() { - Some(("setup", _)) => exec_setup( + Some(("setup", _)) => exec_setup::( zkwasm_k, Self::AGGREGATE_K, Self::NAME, wasm_binary, phantom_functions, &output_dir, + ¶m_dir, + ), + Some(("checksum", _)) => exec_image_checksum::( + zkwasm_k, + wasm_binary, + phantom_functions, + &output_dir, ), - Some(("checksum", _)) => { - exec_image_checksum(zkwasm_k, wasm_binary, phantom_functions, &output_dir) - } Some(("dry-run", sub_matches)) => { let public_inputs: Vec = Self::parse_single_public_arg(&sub_matches); let private_inputs: Vec = Self::parse_single_private_arg(&sub_matches); @@ -130,20 +134,27 @@ pub trait AppBuilder: CommandBuilder { warn!("All context paths are ignored when dry-run is running in service mode."); } - exec_dry_run_service(zkwasm_k, wasm_binary, phantom_functions, &listen) + exec_dry_run_service::( + zkwasm_k, + wasm_binary, + phantom_functions, + &listen, + ) } else { assert!(public_inputs.len() <= Self::MAX_PUBLIC_INPUT_SIZE); let context_output = Arc::new(Mutex::new(vec![])); - exec_dry_run( + exec_dry_run::( zkwasm_k, wasm_binary, phantom_functions, - public_inputs, - private_inputs, - context_in, - context_output.clone(), + ExecutionArg { + public_inputs, + private_inputs, + context_inputs: context_in, + context_outputs: Arc::new(Mutex::new(vec![])), + }, )?; write_context_output(&context_output.lock().unwrap(), context_out_path)?; @@ -162,99 +173,26 @@ pub trait AppBuilder: CommandBuilder { assert!(public_inputs.len() <= Self::MAX_PUBLIC_INPUT_SIZE); - exec_create_proof( + exec_create_proof::( Self::NAME, zkwasm_k, wasm_binary, phantom_functions, &output_dir, - public_inputs, - private_inputs, - context_in, - context_out.clone(), + ¶m_dir, + ExecutionArg { + public_inputs, + private_inputs, + context_inputs: context_in, + context_outputs: context_out.clone(), + }, )?; write_context_output(&context_out.lock().unwrap(), context_out_path)?; Ok(()) } - Some(("single-verify", sub_matches)) => { - let proof_path: PathBuf = Self::parse_proof_path_arg(&sub_matches); - let instance_path: PathBuf = Self::parse_single_instance_arg(&sub_matches); - - exec_verify_proof( - Self::NAME, - zkwasm_k, - wasm_binary, - phantom_functions, - &output_dir, - &proof_path, - &instance_path, - ) - } - Some(("aggregate-prove", sub_matches)) => { - let public_inputs: Vec> = Self::parse_aggregate_public_args(&sub_matches); - let private_inputs: Vec> = - Self::parse_aggregate_private_args(&sub_matches); - let context_inputs = public_inputs.iter().map(|_| vec![]).collect(); - let context_outputs = public_inputs - .iter() - .map(|_| Arc::new(Mutex::new(vec![]))) - .collect(); - - for instances in &public_inputs { - assert!(instances.len() <= Self::MAX_PUBLIC_INPUT_SIZE); - } - - assert_eq!(public_inputs.len(), Self::N_PROOFS); - assert_eq!(private_inputs.len(), Self::N_PROOFS); - - exec_aggregate_create_proof( - zkwasm_k, - Self::AGGREGATE_K, - Self::NAME, - wasm_binary, - phantom_functions, - &output_dir, - public_inputs, - private_inputs, - context_inputs, - context_outputs, - ) - } - - Some(("aggregate-verify", sub_matches)) => { - let proof_path: PathBuf = Self::parse_proof_path_arg(&sub_matches); - let instances_path: PathBuf = Self::parse_aggregate_instance(&sub_matches); - - exec_verify_aggregate_proof( - Self::AGGREGATE_K as u32, - &output_dir, - &proof_path, - &instances_path, - Self::N_PROOFS, - ) - } - - Some(("solidity-aggregate-verifier", sub_matches)) => { - let proof_path: PathBuf = Self::parse_proof_path_arg(&sub_matches); - let instances_path: PathBuf = Self::parse_aggregate_instance(&sub_matches); - let aux_only: bool = Self::parse_auxonly(&sub_matches); - let sol_path: PathBuf = Self::parse_sol_dir_arg(&sub_matches); - - exec_solidity_aggregate_proof( - zkwasm_k, - Self::AGGREGATE_K, - Self::MAX_PUBLIC_INPUT_SIZE, - &output_dir, - &proof_path, - &sol_path, - &instances_path, - Self::N_PROOFS, - aux_only, - ) - } - + Some(("single-verify", _)) => exec_verify_proof(Self::NAME, &output_dir, ¶m_dir), Some((_, _)) => todo!(), None => todo!(), } diff --git a/crates/cli/src/args.rs b/crates/cli/src/args.rs index fc11b7eb3..df881e8f9 100644 --- a/crates/cli/src/args.rs +++ b/crates/cli/src/args.rs @@ -1,62 +1,10 @@ -use std::path::PathBuf; - use clap::arg; use clap::value_parser; use clap::Arg; use clap::ArgAction; use clap::ArgMatches; - -pub fn parse_args(values: Vec<&str>) -> Vec { - values - .into_iter() - .map(|v| { - let [v, t] = v.split(":").collect::>()[..] else { todo!() }; - match t { - "i64" => { - if v.starts_with("0x") { - vec![ - u64::from_str_radix(String::from(v).trim_start_matches("0x"), 16) - .unwrap(), - ] - } else { - vec![v.parse::().unwrap()] - } - } - "bytes" => { - if !v.starts_with("0x") { - panic!("bytes input need start with 0x"); - } - let bytes = hex::decode(String::from(v).trim_start_matches("0x")).unwrap(); - bytes - .into_iter() - .map(|x| u64::from(x)) - .collect::>() - } - "bytes-packed" => { - if !v.starts_with("0x") { - panic!("bytes input need start with 0x"); - } - let bytes = hex::decode(String::from(v).trim_start_matches("0x")).unwrap(); - let bytes = bytes.chunks(8); - bytes - .into_iter() - .map(|x| { - let mut data = [0u8; 8]; - data[..x.len()].copy_from_slice(x); - - u64::from_le_bytes(data) - }) - .collect::>() - } - - _ => { - panic!("Unsupported input data type: {}", t) - } - } - }) - .flatten() - .collect() -} +use specs::args::parse_args; +use std::path::PathBuf; pub trait ArgBuilder { fn zkwasm_k_arg<'a>() -> Arg<'a> { @@ -117,6 +65,12 @@ pub trait ArgBuilder { ).value_parser(value_parser!(PathBuf)) } + fn param_path_arg<'a>() -> Arg<'a> { + arg!( + -p --param [PARAM_PATH] "Path of the params files.\nThe md5 of the wasm binary file is the default path if not supplied." + ).value_parser(value_parser!(PathBuf)) + } + fn proof_path_arg<'a>() -> Arg<'a> { arg!( -p --proof "Path of proof." diff --git a/crates/cli/src/command.rs b/crates/cli/src/command.rs index 92d7466b4..5c68e7587 100644 --- a/crates/cli/src/command.rs +++ b/crates/cli/src/command.rs @@ -38,10 +38,7 @@ pub trait CommandBuilder: ArgBuilder { } fn append_verify_single_proof_subcommand(app: App) -> App { - let command = Command::new("single-verify") - .arg(Self::proof_path_arg()) - .arg(Self::single_instance_path_arg()); - + let command = Command::new("single-verify"); app.subcommand(command) } diff --git a/crates/cli/src/exec.rs b/crates/cli/src/exec.rs index 9014faaf5..8a34fcba7 100644 --- a/crates/cli/src/exec.rs +++ b/crates/cli/src/exec.rs @@ -1,59 +1,48 @@ +use crate::app_builder::write_context_output; use anyhow::Result; +use circuits_batcher::proof::CircuitInfo; +use circuits_batcher::proof::ProofInfo; +use circuits_batcher::proof::ProofLoadInfo; use delphinus_zkwasm::circuits::TestCircuit; -use delphinus_zkwasm::loader::ExecutionArg; use delphinus_zkwasm::loader::ZkWasmLoader; -use halo2_proofs::arithmetic::BaseExt; +use delphinus_zkwasm::runtime::host::ContextOutput; +use delphinus_zkwasm::runtime::host::HostEnvBuilder; +use delphinus_zkwasm::runtime::host::Sequence; use halo2_proofs::pairing::bn256::Bn256; use halo2_proofs::pairing::bn256::Fr; -use halo2_proofs::pairing::bn256::G1Affine; -use halo2_proofs::plonk::verify_proof; -use halo2_proofs::plonk::SingleVerifier; use halo2_proofs::poly::commitment::ParamsVerifier; -use halo2aggregator_s::circuit_verifier::circuit::AggregatorCircuit; -use halo2aggregator_s::circuits::utils::load_instance; use halo2aggregator_s::circuits::utils::load_or_build_unsafe_params; -use halo2aggregator_s::circuits::utils::load_proof; -use halo2aggregator_s::circuits::utils::load_vkey; -use halo2aggregator_s::circuits::utils::run_circuit_unsafe_full_pass; -use halo2aggregator_s::circuits::utils::store_instance; use halo2aggregator_s::circuits::utils::TranscriptHash; -use halo2aggregator_s::solidity_verifier::codegen::solidity_aux_gen; -use halo2aggregator_s::solidity_verifier::solidity_render; -use halo2aggregator_s::transcript::sha256::ShaRead; +use halo2aggregator_s::native_verifier; use log::debug; use log::error; use log::info; use notify::event::AccessMode; use notify::RecursiveMode; use notify::Watcher; -use serde::Deserialize; -use serde::Serialize; use std::fs; use std::io::Write; use std::path::Path; use std::path::PathBuf; -use std::sync::Arc; -use std::sync::Mutex; use wasmi::RuntimeValue; -use crate::app_builder::write_context_output; -use crate::args::parse_args; - -const AGGREGATE_PREFIX: &'static str = "aggregate-circuit"; - -pub fn exec_setup( +pub fn exec_setup( zkwasm_k: u32, aggregate_k: u32, - prefix: &'static str, + prefix: &str, wasm_binary: Vec, phantom_functions: Vec, - output_dir: &PathBuf, -) -> Result<()> { + _output_dir: &PathBuf, + param_dir: &PathBuf, +) -> Result<()> +where + Builder: HostEnvBuilder, +{ info!("Setup Params and VerifyingKey"); macro_rules! prepare_params { ($k: expr) => {{ - let params_path = &output_dir.join(format!("K{}.params", $k)); + let params_path = ¶m_dir.join(format!("K{}.params", $k)); if params_path.exists() { info!("Found Params with K = {} at {:?}", $k, params_path); @@ -70,13 +59,14 @@ pub fn exec_setup( // Setup ZkWasm Vkey { - let vk_path = &output_dir.join(format!("{}.{}.vkey.data", prefix, 0)); + let vk_path = ¶m_dir.join(format!("{}.vkey.data", prefix)); if vk_path.exists() { info!("Found Verifying at {:?}", vk_path); } else { info!("Create Verifying to {:?}", vk_path); - let loader = ZkWasmLoader::::new(zkwasm_k, wasm_binary, phantom_functions)?; + let loader = + ZkWasmLoader::::new(zkwasm_k, wasm_binary, phantom_functions)?; let vkey = loader.create_vkey(¶ms)?; @@ -88,13 +78,17 @@ pub fn exec_setup( Ok(()) } -pub fn exec_image_checksum( +pub fn exec_image_checksum( zkwasm_k: u32, wasm_binary: Vec, phantom_functions: Vec, output_dir: &PathBuf, -) -> Result<()> { - let loader = ZkWasmLoader::::new(zkwasm_k, wasm_binary, phantom_functions)?; +) -> Result<()> +where + Builder: HostEnvBuilder, +{ + let loader = + ZkWasmLoader::::new(zkwasm_k, wasm_binary, phantom_functions)?; let params = load_or_build_unsafe_params::( zkwasm_k, @@ -115,26 +109,22 @@ pub fn exec_image_checksum( Ok(()) } -pub fn exec_dry_run_service( +pub fn exec_dry_run_service( zkwasm_k: u32, wasm_binary: Vec, phantom_functions: Vec, listen: &PathBuf, -) -> Result<()> { +) -> Result<()> +where + Arg: ContextOutput + From, + Builder: HostEnvBuilder, +{ use notify::event::AccessKind; use notify::event::EventKind; use notify::event::ModifyKind; use notify::event::RenameMode; use notify::Event; - #[derive(Serialize, Deserialize, Debug)] - struct Sequence { - private_inputs: Vec, - public_inputs: Vec, - context_input: Vec, - context_output: Option, - } - info!("Dry-run service is running."); info!("{:?} is watched", listen); @@ -159,38 +149,20 @@ pub fn exec_dry_run_service( let json = fs::read_to_string(path).unwrap(); if let Ok(sequence) = serde_json::from_str::(&json) { - debug!("{:?}", sequence); - - let private_inputs = parse_args( - sequence.private_inputs.iter().map(|s| s.as_str()).collect(), - ); - let public_inputs = parse_args( - sequence.public_inputs.iter().map(|s| s.as_str()).collect(), - ); - let context_inputs = parse_args( - sequence.context_input.iter().map(|s| s.as_str()).collect(), - ); - let context_outputs = Arc::new(Mutex::new(vec![])); - - let loader = ZkWasmLoader::::new( + let arg: Arg = sequence.clone().into(); + let context_output_data = arg.get_context_outputs(); + + let loader = ZkWasmLoader::::new( zkwasm_k, wasm_binary.clone(), phantom_functions.clone(), ) .unwrap(); - - let r = loader - .dry_run(ExecutionArg { - public_inputs, - private_inputs, - context_inputs, - context_outputs: context_outputs.clone(), - }) - .unwrap(); + let r = loader.dry_run(arg).unwrap(); println!("return value: {:?}", r); write_context_output( - &context_outputs.lock().unwrap().to_vec(), + &context_output_data.lock().unwrap().to_vec(), sequence.context_output, ) .unwrap(); @@ -223,63 +195,33 @@ pub fn exec_dry_run_service( } } -pub fn exec_dry_run( +pub fn exec_dry_run>( zkwasm_k: u32, wasm_binary: Vec, phantom_functions: Vec, - public_inputs: Vec, - private_inputs: Vec, - context_inputs: Vec, - context_outputs: Arc>>, + arg: Arg, ) -> Result<()> { - let loader = ZkWasmLoader::::new(zkwasm_k, wasm_binary, phantom_functions)?; + let loader = + ZkWasmLoader::::new(zkwasm_k, wasm_binary, phantom_functions)?; - loader.dry_run(ExecutionArg { - public_inputs, - private_inputs, - context_inputs, - context_outputs, - })?; + loader.dry_run(arg)?; Ok(()) } -pub fn exec_create_proof( +pub fn exec_create_proof>( prefix: &'static str, zkwasm_k: u32, wasm_binary: Vec, phantom_functions: Vec, output_dir: &PathBuf, - public_inputs: Vec, - private_inputs: Vec, - context_inputs: Vec, - context_outputs: Arc>>, + param_dir: &PathBuf, + arg: Arg, ) -> Result<()> { - let loader = ZkWasmLoader::::new(zkwasm_k, wasm_binary, phantom_functions)?; + let loader = + ZkWasmLoader::::new(zkwasm_k, wasm_binary, phantom_functions)?; - let params = load_or_build_unsafe_params::( - zkwasm_k, - Some(&output_dir.join(format!("K{}.params", zkwasm_k))), - ); - - let vkey = load_vkey::>( - ¶ms, - &output_dir.join(format!("{}.{}.vkey.data", prefix, 0)), - ); - - let (circuit, instances) = loader.circuit_with_witness(ExecutionArg { - public_inputs, - private_inputs, - context_inputs, - context_outputs, - })?; - - { - store_instance( - &vec![instances.clone()], - &output_dir.join(format!("{}.{}.instance.data", prefix, 0)), - ); - } + let (circuit, instances, _) = loader.circuit_with_witness(arg)?; if true { info!("Mock test..."); @@ -287,14 +229,15 @@ pub fn exec_create_proof( info!("Mock test passed"); } - let proof = loader.create_proof(¶ms, vkey, circuit, &instances)?; - - { - let proof_path = output_dir.join(format!("{}.{}.transcript.data", prefix, 0)); - println!("write transcript to {:?}", proof_path); - let mut fd = std::fs::File::create(&proof_path)?; - fd.write_all(&proof)?; - } + let circuit: CircuitInfo> = CircuitInfo::new( + circuit, + prefix.to_string(), + vec![instances], + zkwasm_k as usize, + circuits_batcher::args::HashType::Poseidon, + ); + circuit.proofloadinfo.save(output_dir); + circuit.exec_create_proof(output_dir, param_dir, 0); info!("Proof has been created."); @@ -303,230 +246,39 @@ pub fn exec_create_proof( pub fn exec_verify_proof( prefix: &'static str, - zkwasm_k: u32, - wasm_binary: Vec, - phantom_functions: Vec, - output_dir: &PathBuf, - proof_path: &PathBuf, - instance_path: &PathBuf, -) -> Result<()> { - let instances = { - let mut instance = vec![]; - let mut fd = std::fs::File::open(&instance_path).unwrap(); - while let Ok(f) = Fr::read(&mut fd) { - instance.push(f); - } - - instance - }; - let params = load_or_build_unsafe_params::( - zkwasm_k, - Some(&output_dir.join(format!("K{}.params", zkwasm_k))), - ); - - let loader = ZkWasmLoader::::new(zkwasm_k, wasm_binary, phantom_functions)?; - - let vkey = load_vkey::>( - ¶ms, - &output_dir.join(format!("{}.{}.vkey.data", prefix, 0)), - ); - - let proof = load_proof(proof_path); - - loader.verify_proof(¶ms, vkey, instances, proof)?; - - info!("Verifing proof passed"); - - Ok(()) -} - -pub fn exec_aggregate_create_proof( - zkwasm_k: u32, - aggregate_k: u32, - prefix: &'static str, - wasm_binary: Vec, - phantom_functions: Vec, output_dir: &PathBuf, - public_inputs: Vec>, - private_inputs: Vec>, - context_inputs: Vec>, - context_outputs: Vec>>>, -) -> Result<()> { - assert_eq!(public_inputs.len(), private_inputs.len()); - - let loader = ZkWasmLoader::::new(zkwasm_k, wasm_binary, phantom_functions)?; - - let (circuits, instances) = public_inputs - .into_iter() - .zip(private_inputs.into_iter()) - .zip(context_inputs.into_iter()) - .zip(context_outputs.into_iter()) - .fold( - Ok::<_, anyhow::Error>((vec![], vec![])), - |acc, (((public_inputs, private_inputs), context_inputs), context_outputs)| { - acc.and_then(|(mut circuits, mut instances)| { - let (circuit, instance) = loader.circuit_with_witness(ExecutionArg { - public_inputs, - private_inputs, - context_inputs, - context_outputs, - })?; - - circuits.push(circuit); - instances.push(vec![instance]); - - Ok((circuits, instances)) - }) - }, - )?; - - let (aggregate_circuit, aggregate_instances) = run_circuit_unsafe_full_pass::( - &output_dir.as_path(), - prefix, - zkwasm_k, - circuits, - instances, - TranscriptHash::Poseidon, - vec![], - vec![], - vec![], - false, - ) - .unwrap(); - - run_circuit_unsafe_full_pass::( - &output_dir.as_path(), - AGGREGATE_PREFIX, - aggregate_k, - vec![aggregate_circuit], - vec![vec![aggregate_instances]], - TranscriptHash::Sha, - vec![], - vec![], - vec![], - true, - ); - - Ok(()) -} - -pub fn exec_verify_aggregate_proof( - aggregate_k: u32, - output_dir: &PathBuf, - proof_path: &PathBuf, - instances_path: &PathBuf, - n_proofs: usize, + param_dir: &PathBuf, ) -> Result<()> { + let load_info = output_dir.join(format!("{}.loadinfo.json", prefix)); + let proofloadinfo = ProofLoadInfo::load(&load_info); + let proofs: Vec> = + ProofInfo::load_proof(&output_dir, ¶m_dir, &proofloadinfo); let params = load_or_build_unsafe_params::( - aggregate_k, - Some(&output_dir.join(format!("K{}.params", aggregate_k))), - ); - - let proof = load_proof(&proof_path.as_path()); - let vkey = load_vkey::>( - ¶ms, - &output_dir.join(format!("{}.{}.vkey.data", AGGREGATE_PREFIX, 0)), + proofloadinfo.k as u32, + Some(¶m_dir.join(format!("K{}.params", proofloadinfo.k))), ); - - let public_inputs_size: u32 = 3 * n_proofs as u32; - - let instances = load_instance::(&[public_inputs_size], &instances_path); - - let params_verifier: ParamsVerifier = - params.verifier(public_inputs_size as usize).unwrap(); - let strategy = SingleVerifier::new(¶ms_verifier); - - verify_proof( - ¶ms_verifier, - &vkey, - strategy, - &[&instances.iter().map(|x| &x[..]).collect::>()[..]], - &mut ShaRead::<_, _, _, sha2::Sha256>::init(&proof[..]), - ) - .unwrap(); - - info!("Verifing Aggregate Proof Passed."); - - Ok(()) -} - -pub fn exec_solidity_aggregate_proof( - zkwasm_k: u32, - aggregate_k: u32, - max_public_inputs_size: usize, - output_dir: &PathBuf, - proof_path: &PathBuf, - sol_path: &PathBuf, - instances_path: &PathBuf, - n_proofs: usize, - aux_only: bool, -) -> Result<()> { - let zkwasm_params_verifier: ParamsVerifier = { - let params = load_or_build_unsafe_params::( - zkwasm_k, - Some(&output_dir.join(format!("K{}.params", zkwasm_k))), - ); - - params.verifier(max_public_inputs_size).unwrap() - }; - - let (verifier_params_verifier, vkey, instances, proof) = { - let public_inputs_size = 3 * n_proofs; - - let params = load_or_build_unsafe_params::( - aggregate_k, - Some(&output_dir.join(format!("K{}.params", aggregate_k))), - ); - - let params_verifier = params.verifier(public_inputs_size).unwrap(); - - let vkey = load_vkey::>( - ¶ms, - &output_dir.join(format!("{}.{}.vkey.data", AGGREGATE_PREFIX, 0)), + let mut public_inputs_size = 0; + for proof in proofs.iter() { + public_inputs_size = usize::max( + public_inputs_size, + proof + .instances + .iter() + .fold(0, |acc, x| usize::max(acc, x.len())), ); + } - let instances = load_instance::(&[public_inputs_size as u32], &instances_path); - let proof = load_proof(&proof_path.as_path()); - - (params_verifier, vkey, instances, proof) - }; - - if !aux_only { - let path_in = { - let mut path = sol_path.clone(); - path.push("templates"); - path - }; - let path_out = { - let mut path = sol_path.clone(); - path.push("contracts"); - path - }; - solidity_render( - &(path_in.to_str().unwrap().to_owned() + "/*"), - path_out.to_str().unwrap(), - vec![( - "AggregatorConfig.sol.tera".to_owned(), - "AggregatorConfig.sol".to_owned(), - )], - "AggregatorVerifierStepStart.sol.tera", - "AggregatorVerifierStepEnd.sol.tera", - |i| format!("AggregatorVerifierStep{}.sol", i + 1), - &zkwasm_params_verifier, - &verifier_params_verifier, - &vkey, - &instances[0], - proof.clone(), + let params_verifier: ParamsVerifier = params.verifier(public_inputs_size).unwrap(); + for (_, proof) in proofs.iter().enumerate() { + native_verifier::verify_single_proof::( + ¶ms_verifier, + &proof.vkey, + &proof.instances, + proof.transcripts.clone(), + TranscriptHash::Poseidon, ); } - - solidity_aux_gen( - &verifier_params_verifier, - &vkey, - &instances[0], - proof, - &output_dir.join(format!("{}.{}.aux.data", AGGREGATE_PREFIX, 0)), - ); + info!("Verifing proof passed"); Ok(()) } diff --git a/crates/cli/src/lib.rs b/crates/cli/src/lib.rs new file mode 100644 index 000000000..ab01392b6 --- /dev/null +++ b/crates/cli/src/lib.rs @@ -0,0 +1,4 @@ +pub mod app_builder; +pub mod args; +pub mod command; +pub mod exec; diff --git a/crates/cli/src/main.rs b/crates/cli/src/main.rs index 8c6f2983f..6cce14460 100644 --- a/crates/cli/src/main.rs +++ b/crates/cli/src/main.rs @@ -1,12 +1,12 @@ use anyhow::Result; use app_builder::AppBuilder; -use args::parse_args; use args::ArgBuilder; use clap::value_parser; use clap::Arg; use clap::ArgAction; use clap::ArgMatches; use command::CommandBuilder; +use specs::args::parse_args; pub mod app_builder; pub mod args; diff --git a/crates/cli/test_cli.sh b/crates/cli/test_cli.sh index 7229a0fb6..bdf25a072 100755 --- a/crates/cli/test_cli.sh +++ b/crates/cli/test_cli.sh @@ -6,14 +6,8 @@ set -x rm -rf output/*.data # Single test -RUST_LOG=info cargo run --release --features cuda -- -k 18 --function zkmain --output ./output --wasm ../zkwasm/wasm/wasm_output.wasm setup -RUST_LOG=info cargo run --release --features cuda -- -k 18 --function zkmain --output ./output --wasm ../zkwasm/wasm/wasm_output.wasm checksum +RUST_LOG=info cargo run --release --features cuda -- -k 18 --function zkmain --param ./params --output ./output --wasm ../zkwasm/wasm/wasm_output.wasm setup +RUST_LOG=info cargo run --release --features cuda -- -k 18 --function zkmain --param ./params --output ./output --wasm ../zkwasm/wasm/wasm_output.wasm checksum -RUST_LOG=info cargo run --release --features cuda -- -k 18 --function zkmain --output ./output --wasm ../zkwasm/wasm/wasm_output.wasm single-prove --public 133:i64 --public 2:i64 -RUST_LOG=info cargo run --release --features cuda -- -k 18 --function zkmain --output ./output --wasm ../zkwasm/wasm/wasm_output.wasm single-verify --proof output/zkwasm.0.transcript.data --instance output/zkwasm.0.instance.data - -RUST_LOG=info cargo run --release --features cuda -- -k 18 --function zkmain --output ./output --wasm ../zkwasm/wasm/wasm_output.wasm aggregate-prove --public 133:i64 --public 2:i64 -RUST_LOG=info cargo run --release --features cuda -- -k 18 --function zkmain --output ./output --wasm ../zkwasm/wasm/wasm_output.wasm aggregate-verify --proof output/aggregate-circuit.0.transcript.data --instances output/aggregate-circuit.0.instance.data -if [ -d "sol" ]; then - RUST_LOG=info cargo run --release --features cuda -- -k 18 --function zkmain --output ./output --wasm ../zkwasm/wasm/wasm_output.wasm solidity-aggregate-verifier --proof output/aggregate-circuit.0.transcript.data --instances output/aggregate-circuit.0.instance.data -fi +RUST_LOG=info cargo run --release --features cuda -- -k 18 --function zkmain --param ./params --output ./output --wasm ../zkwasm/wasm/wasm_output.wasm single-prove --public 133:i64 --public 2:i64 +RUST_LOG=info cargo run --release --features cuda -- -k 18 --function zkmain --param ./params --output ./output --wasm ../zkwasm/wasm/wasm_output.wasm single-verify diff --git a/crates/host/Cargo.toml b/crates/host/Cargo.toml new file mode 100644 index 000000000..9311d9d05 --- /dev/null +++ b/crates/host/Cargo.toml @@ -0,0 +1,45 @@ +[package] +name = "delphinus-host" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +ark-std = { version = "0.3.0", features = ["print-trace"] } +bitvec = "1.0.1" +downcast-rs = "1.2.0" +hex = "0.4.3" +log = "0.4.17" +num-integer = "0.1" +num-bigint = { version = "0.4", features = ["rand"] } +num-traits = "0.2.15" +wabt = "0.10.0" +lazy_static = "1.4.0" +rand = "0.8.4" +specs = { path = "../specs" } +strum = "0.24.1" +strum_macros = "0.24.1" +serde = { version = "1.0", features = ["derive"] } +serde_json = "1.0" +delphinus-zkwasm = { path = "../zkwasm" } + +ff = "0.12" +sha2 = "0.10.6" +poseidon = { git = "https://github.com/lanbones/poseidon" } + +anyhow.workspace = true +halo2aggregator-s.workspace = true +halo2_proofs.workspace = true +parity-wasm.workspace = true +wasmi.workspace = true + +# TODO put the host circuits into features +zkwasm-host-circuits = { git = "https://github.com/DelphinusLab/zkWasm-host-circuits.git", branch="main" } + +[dev-dependencies] +rusty-fork = "0.3.0" + +[features] +default = [] +cuda = ["halo2_proofs/cuda", "specs/cuda"] diff --git a/crates/host/src/host/ecc_helper/bls381/mod.rs b/crates/host/src/host/ecc_helper/bls381/mod.rs new file mode 100644 index 000000000..badfe5699 --- /dev/null +++ b/crates/host/src/host/ecc_helper/bls381/mod.rs @@ -0,0 +1,52 @@ +pub mod pair; +pub mod sum; +use ark_std::Zero; +use halo2_proofs::arithmetic::CurveAffine; +use halo2_proofs::pairing::bls12_381::Fp2 as Bls381Fq2; +use halo2_proofs::pairing::bls12_381::Fq as Bls381Fq; +use halo2_proofs::pairing::bls12_381::G1Affine; +use num_bigint::BigUint; +use num_traits::FromPrimitive; +use std::ops::AddAssign; + +use super::bn_to_field; +use super::field_to_bn; + +fn fetch_fq(limbs: &Vec, index: usize) -> Bls381Fq { + let mut bn = BigUint::zero(); + for i in 0..8 { + bn.add_assign(BigUint::from_u64(limbs[index * 8 + i]).unwrap() << (i * 54)) + } + bn_to_field(&bn) +} + +fn fetch_fq2(limbs: &Vec, index: usize) -> Bls381Fq2 { + Bls381Fq2 { + c0: fetch_fq(limbs, index), + c1: fetch_fq(limbs, index + 1), + } +} + +fn fetch_g1(limbs: &Vec, g1_identity: bool) -> G1Affine { + if g1_identity { + G1Affine::identity() + } else { + let opt: Option<_> = G1Affine::from_xy(fetch_fq(limbs, 0), fetch_fq(limbs, 1)).into(); + opt.expect("from xy failed, not on curve") + } +} + +fn bls381_fq_to_limbs(result_limbs: &mut Vec, f: Bls381Fq) { + let mut bn = field_to_bn(&f); + for _ in 0..8 { + let d: BigUint = BigUint::from(1u64 << 54); + let r = bn.clone() % d.clone(); + let value = if r == BigUint::from(0 as u32) { + 0 as u64 + } else { + r.to_u64_digits()[0] + }; + bn = bn / d; + result_limbs.append(&mut vec![value]); + } +} diff --git a/crates/host/src/host/ecc_helper/bls381/pair/mod.rs b/crates/host/src/host/ecc_helper/bls381/pair/mod.rs new file mode 100644 index 000000000..b1e6c6d0c --- /dev/null +++ b/crates/host/src/host/ecc_helper/bls381/pair/mod.rs @@ -0,0 +1,135 @@ +use super::bls381_fq_to_limbs; +use super::fetch_fq; +use super::fetch_fq2; +use delphinus_zkwasm::runtime::host::host_env::HostEnv; +use delphinus_zkwasm::runtime::host::ForeignContext; +use halo2_proofs::arithmetic::CurveAffine; +use halo2_proofs::pairing::bls12_381::pairing; +use halo2_proofs::pairing::bls12_381::G1Affine; +use halo2_proofs::pairing::bls12_381::G2Affine; +use halo2_proofs::pairing::bls12_381::Gt as Bls381Gt; +use std::rc::Rc; +use zkwasm_host_circuits::host::ForeignInst; + +#[derive(Default)] +struct BlsPairContext { + pub limbs: Vec, + pub g1_identity: bool, + pub g2_identity: bool, + pub result_limbs: Vec, + pub result_cursor: usize, + pub input_cursor: usize, +} + +impl BlsPairContext { + fn bls381_gt_to_limbs(&mut self, g: Bls381Gt) { + bls381_fq_to_limbs(&mut self.result_limbs, g.0.c0.c0.c0); + bls381_fq_to_limbs(&mut self.result_limbs, g.0.c0.c0.c1); + bls381_fq_to_limbs(&mut self.result_limbs, g.0.c0.c1.c0); + bls381_fq_to_limbs(&mut self.result_limbs, g.0.c0.c1.c1); + bls381_fq_to_limbs(&mut self.result_limbs, g.0.c0.c2.c0); + bls381_fq_to_limbs(&mut self.result_limbs, g.0.c0.c2.c1); + bls381_fq_to_limbs(&mut self.result_limbs, g.0.c0.c0.c0); + bls381_fq_to_limbs(&mut self.result_limbs, g.0.c0.c0.c1); + bls381_fq_to_limbs(&mut self.result_limbs, g.0.c0.c1.c0); + bls381_fq_to_limbs(&mut self.result_limbs, g.0.c0.c1.c1); + bls381_fq_to_limbs(&mut self.result_limbs, g.0.c0.c2.c0); + bls381_fq_to_limbs(&mut self.result_limbs, g.0.c0.c2.c1); + bls381_fq_to_limbs(&mut self.result_limbs, g.0.c1.c0.c0); + bls381_fq_to_limbs(&mut self.result_limbs, g.0.c1.c0.c1); + bls381_fq_to_limbs(&mut self.result_limbs, g.0.c1.c1.c0); + bls381_fq_to_limbs(&mut self.result_limbs, g.0.c1.c1.c1); + bls381_fq_to_limbs(&mut self.result_limbs, g.0.c1.c2.c0); + bls381_fq_to_limbs(&mut self.result_limbs, g.0.c1.c2.c1); + bls381_fq_to_limbs(&mut self.result_limbs, g.0.c1.c0.c0); + bls381_fq_to_limbs(&mut self.result_limbs, g.0.c1.c0.c1); + bls381_fq_to_limbs(&mut self.result_limbs, g.0.c1.c1.c0); + bls381_fq_to_limbs(&mut self.result_limbs, g.0.c1.c1.c1); + bls381_fq_to_limbs(&mut self.result_limbs, g.0.c1.c2.c0); + bls381_fq_to_limbs(&mut self.result_limbs, g.0.c1.c2.c1); + } +} + +impl ForeignContext for BlsPairContext {} + +use specs::external_host_call_table::ExternalHostCallSignature; +pub fn register_blspair_foreign(env: &mut HostEnv) { + let foreign_blspair_plugin = env + .external_env + .register_plugin("foreign_blspair", Box::new(BlsPairContext::default())); + + env.external_env.register_function( + "blspair_g1", + ForeignInst::BlsPairG1 as usize, + ExternalHostCallSignature::Argument, + foreign_blspair_plugin.clone(), + Rc::new( + |context: &mut dyn ForeignContext, args: wasmi::RuntimeArgs| { + let context = context.downcast_mut::().unwrap(); + if context.input_cursor == 16 { + let t: u64 = args.nth(0); + context.g1_identity = t != 0; + context.input_cursor = 0; + } else { + context.limbs.push(args.nth(0)); + context.input_cursor += 1; + } + None + }, + ), + ); + env.external_env.register_function( + "blspair_g2", + ForeignInst::BlsPairG2 as usize, + ExternalHostCallSignature::Argument, + foreign_blspair_plugin.clone(), + Rc::new( + |context: &mut dyn ForeignContext, args: wasmi::RuntimeArgs| { + let context = context.downcast_mut::().unwrap(); + if context.input_cursor == 32 { + let t: u64 = args.nth(0); + context.g2_identity = t != 0; + let g1 = if context.g1_identity { + G1Affine::identity() + } else { + G1Affine::from_xy(fetch_fq(&context.limbs, 0), fetch_fq(&context.limbs, 1)) + .unwrap() + }; + let g2 = if context.g2_identity { + G2Affine::identity() + } else { + G2Affine { + x: fetch_fq2(&context.limbs, 2), + y: fetch_fq2(&context.limbs, 4), + infinity: (0 as u8).into(), + } + }; + let ab = pairing(&g1, &g2); + log::debug!("gt {:?}", ab); + context.bls381_gt_to_limbs(ab); + } else { + context.limbs.push(args.nth(0)); + context.input_cursor += 1; + }; + None + }, + ), + ); + + env.external_env.register_function( + "blspair_pop", + ForeignInst::BlsPairG3 as usize, + ExternalHostCallSignature::Return, + foreign_blspair_plugin.clone(), + Rc::new( + |context: &mut dyn ForeignContext, _args: wasmi::RuntimeArgs| { + let context = context.downcast_mut::().unwrap(); + let ret = Some(wasmi::RuntimeValue::I64( + context.result_limbs[context.result_cursor] as i64, + )); + context.result_cursor += 1; + ret + }, + ), + ); +} diff --git a/crates/host/src/host/ecc_helper/bls381/sum/mod.rs b/crates/host/src/host/ecc_helper/bls381/sum/mod.rs new file mode 100644 index 000000000..4679c5938 --- /dev/null +++ b/crates/host/src/host/ecc_helper/bls381/sum/mod.rs @@ -0,0 +1,100 @@ +use delphinus_zkwasm::runtime::host::host_env::HostEnv; +use delphinus_zkwasm::runtime::host::ForeignContext; +use halo2_proofs::pairing::bls12_381::G1Affine; +use std::ops::Add; +use std::rc::Rc; + +use super::bls381_fq_to_limbs; +use super::fetch_g1; + +use zkwasm_host_circuits::host::ForeignInst; + +#[derive(Default)] +struct BlsSumContext { + pub limbs: Vec, + pub g1_identity: Vec, + pub result_limbs: Option>, + pub result_cursor: usize, + pub input_cursor: usize, +} + +impl BlsSumContext { + fn bls381_result_to_limbs(&mut self, g: G1Affine) { + let mut limbs = vec![]; + bls381_fq_to_limbs(&mut limbs, g.x); + bls381_fq_to_limbs(&mut limbs, g.y); + self.result_limbs = Some(limbs); + if g.is_identity().into() { + self.result_limbs.as_mut().unwrap().append(&mut vec![1u64]); + } else { + self.result_limbs.as_mut().unwrap().append(&mut vec![0u64]); + } + } +} + +impl ForeignContext for BlsSumContext {} + +use specs::external_host_call_table::ExternalHostCallSignature; +pub fn register_blssum_foreign(env: &mut HostEnv) { + let foreign_blssum_plugin = env + .external_env + .register_plugin("foreign_blssum", Box::new(BlsSumContext::default())); + + env.external_env.register_function( + "blssum_g1", + ForeignInst::BlsSumG1 as usize, + ExternalHostCallSignature::Argument, + foreign_blssum_plugin.clone(), + Rc::new( + |context: &mut dyn ForeignContext, args: wasmi::RuntimeArgs| { + let context = context.downcast_mut::().unwrap(); + if context.input_cursor == 16 { + let t: u64 = args.nth(0); + context.g1_identity.push(t != 0); + context.input_cursor = 0; + } else { + context.limbs.push(args.nth(0)); + context.input_cursor += 1; + } + None + }, + ), + ); + + env.external_env.register_function( + "blssum_pop", + ForeignInst::BlsSumResult as usize, + ExternalHostCallSignature::Return, + foreign_blssum_plugin.clone(), + Rc::new( + |context: &mut dyn ForeignContext, _args: wasmi::RuntimeArgs| { + let context = context.downcast_mut::().unwrap(); + context.result_limbs.clone().map_or_else( + || { + let fqs = context + .limbs + .chunks(16) + .zip(context.g1_identity.clone()) + .map(|(limbs, identity)| fetch_g1(&limbs.to_vec(), identity)) + .collect::>(); + let g1result = + fqs[1..fqs.len()] + .into_iter() + .fold(fqs[0], |acc: G1Affine, x| { + let acc = acc.add(x.clone()).into(); + acc + }); + context.bls381_result_to_limbs(g1result); + }, + |_| (), + ); + let limbs = context.result_limbs.clone().unwrap(); + let ret = Some(wasmi::RuntimeValue::I64( + limbs[context.result_cursor] as i64, + )); + context.result_cursor += 1; + ret + }, + ), + ); +} diff --git a/crates/host/src/host/ecc_helper/bn254/mod.rs b/crates/host/src/host/ecc_helper/bn254/mod.rs new file mode 100644 index 000000000..d2514e3c1 --- /dev/null +++ b/crates/host/src/host/ecc_helper/bn254/mod.rs @@ -0,0 +1,68 @@ +pub mod pair; +pub mod sum; +use ark_std::Zero; +use halo2_proofs::arithmetic::CurveAffine; +use halo2_proofs::pairing::bn256::Fq as BN254Fq; +use halo2_proofs::pairing::bn256::Fq2 as BN254Fq2; +use halo2_proofs::pairing::bn256::Fr; +use halo2_proofs::pairing::bn256::G1Affine; +use num_bigint::BigUint; +use num_traits::FromPrimitive; +use std::ops::AddAssign; +use std::ops::Shl; + +const LIMBSZ: usize = 54; +const LIMBNB: usize = 5; + +use super::bn_to_field; +use super::field_to_bn; + +fn fetch_fr(limbs: &Vec) -> Fr { + let mut bn = BigUint::zero(); + for i in 0..4 { + bn.add_assign(BigUint::from_u64(limbs[i]).unwrap() << (i * 64)) + } + bn_to_field(&bn) +} + +pub fn fetch_fq(limbs: &Vec, index: usize) -> BN254Fq { + let mut bn = BigUint::zero(); + for i in 0..LIMBNB { + bn.add_assign(BigUint::from_u64(limbs[index * LIMBNB + i]).unwrap() << (i * LIMBSZ)) + } + bn_to_field(&bn) +} + +pub fn fetch_fq2(limbs: &Vec, index: usize) -> BN254Fq2 { + BN254Fq2 { + c0: fetch_fq(limbs, index), + c1: fetch_fq(limbs, index + 1), + } +} + +/// decode g1 from limbs where limbs[11] indicates whether the point is identity +fn fetch_g1(limbs: &Vec) -> G1Affine { + assert_eq!(limbs.len(), LIMBNB * 2 + 1); + let g1_identity = limbs[LIMBNB * 2]; + if g1_identity == 1 { + G1Affine::generator() + } else { + let opt: Option<_> = G1Affine::from_xy(fetch_fq(limbs, 0), fetch_fq(limbs, 1)).into(); + opt.expect("from xy failed, not on curve") + } +} + +pub fn bn254_fq_to_limbs(result_limbs: &mut Vec, f: BN254Fq) { + let mut bn = field_to_bn(&f); + for _ in 0..LIMBNB { + let d: BigUint = BigUint::from(1 as u64).shl(LIMBSZ); + let r = bn.clone() % d.clone(); + let value = if r == BigUint::from(0 as u32) { + 0 as u64 + } else { + r.to_u64_digits()[0] + }; + bn = bn / d; + result_limbs.append(&mut vec![value]); + } +} diff --git a/crates/host/src/host/ecc_helper/bn254/pair/mod.rs b/crates/host/src/host/ecc_helper/bn254/pair/mod.rs new file mode 100644 index 000000000..6b00b32b8 --- /dev/null +++ b/crates/host/src/host/ecc_helper/bn254/pair/mod.rs @@ -0,0 +1,154 @@ +use delphinus_zkwasm::runtime::host::host_env::HostEnv; +use delphinus_zkwasm::runtime::host::ForeignContext; +use halo2_proofs::arithmetic::CurveAffine; +use halo2_proofs::pairing::bn256::pairing; +use halo2_proofs::pairing::bn256::G1Affine; +use halo2_proofs::pairing::bn256::G2Affine; +use halo2_proofs::pairing::bn256::Gt as BN254Gt; +use halo2_proofs::pairing::group::prime::PrimeCurveAffine; +use std::rc::Rc; + +use super::bn254_fq_to_limbs; +use super::fetch_fq; +use super::fetch_fq2; +use super::LIMBNB; + +use zkwasm_host_circuits::host::ForeignInst::Bn254PairG1; +use zkwasm_host_circuits::host::ForeignInst::Bn254PairG2; +use zkwasm_host_circuits::host::ForeignInst::Bn254PairG3; + +#[derive(Default)] +struct BN254PairContext { + pub limbs: Vec, + pub g1_identity: bool, + pub g2_identity: bool, + pub gt: Option, + pub result_limbs: Vec, + pub result_cursor: usize, + pub input_cursor: usize, +} + +impl BN254PairContext { + fn bn254_gt_to_limbs(&mut self, g: BN254Gt) { + bn254_fq_to_limbs(&mut self.result_limbs, g.0.c0.c0.c0); + bn254_fq_to_limbs(&mut self.result_limbs, g.0.c0.c0.c1); + bn254_fq_to_limbs(&mut self.result_limbs, g.0.c0.c1.c0); + bn254_fq_to_limbs(&mut self.result_limbs, g.0.c0.c1.c1); + bn254_fq_to_limbs(&mut self.result_limbs, g.0.c0.c2.c0); + bn254_fq_to_limbs(&mut self.result_limbs, g.0.c0.c2.c1); + bn254_fq_to_limbs(&mut self.result_limbs, g.0.c0.c0.c0); + bn254_fq_to_limbs(&mut self.result_limbs, g.0.c0.c0.c1); + bn254_fq_to_limbs(&mut self.result_limbs, g.0.c0.c1.c0); + bn254_fq_to_limbs(&mut self.result_limbs, g.0.c0.c1.c1); + bn254_fq_to_limbs(&mut self.result_limbs, g.0.c0.c2.c0); + bn254_fq_to_limbs(&mut self.result_limbs, g.0.c0.c2.c1); + bn254_fq_to_limbs(&mut self.result_limbs, g.0.c1.c0.c0); + bn254_fq_to_limbs(&mut self.result_limbs, g.0.c1.c0.c1); + bn254_fq_to_limbs(&mut self.result_limbs, g.0.c1.c1.c0); + bn254_fq_to_limbs(&mut self.result_limbs, g.0.c1.c1.c1); + bn254_fq_to_limbs(&mut self.result_limbs, g.0.c1.c2.c0); + bn254_fq_to_limbs(&mut self.result_limbs, g.0.c1.c2.c1); + bn254_fq_to_limbs(&mut self.result_limbs, g.0.c1.c0.c0); + bn254_fq_to_limbs(&mut self.result_limbs, g.0.c1.c0.c1); + bn254_fq_to_limbs(&mut self.result_limbs, g.0.c1.c1.c0); + bn254_fq_to_limbs(&mut self.result_limbs, g.0.c1.c1.c1); + bn254_fq_to_limbs(&mut self.result_limbs, g.0.c1.c2.c0); + bn254_fq_to_limbs(&mut self.result_limbs, g.0.c1.c2.c1); + } +} + +impl ForeignContext for BN254PairContext {} + +use specs::external_host_call_table::ExternalHostCallSignature; +pub fn register_bn254pair_foreign(env: &mut HostEnv) { + let foreign_blspair_plugin = env + .external_env + .register_plugin("foreign_blspair", Box::new(BN254PairContext::default())); + + env.external_env.register_function( + "bn254pair_g1", + Bn254PairG1 as usize, + ExternalHostCallSignature::Argument, + foreign_blspair_plugin.clone(), + Rc::new( + |context: &mut dyn ForeignContext, args: wasmi::RuntimeArgs| { + let context = context.downcast_mut::().unwrap(); + if context.input_cursor == LIMBNB * 2 { + let t: u64 = args.nth(0); + context.g1_identity = t != 0; + context.input_cursor = 0; + } else { + context.limbs.push(args.nth(0)); + context.input_cursor += 1; + } + None + }, + ), + ); + env.external_env.register_function( + "bn254pair_g2", + Bn254PairG2 as usize, + ExternalHostCallSignature::Argument, + foreign_blspair_plugin.clone(), + Rc::new( + |context: &mut dyn ForeignContext, args: wasmi::RuntimeArgs| { + let context = context.downcast_mut::().unwrap(); + if context.input_cursor == LIMBNB * 4 { + let t: u64 = args.nth(0); + context.g2_identity = t != 0; + let g1 = if context.g1_identity { + G1Affine::identity() + } else { + let opt: Option<_> = G1Affine::from_xy( + fetch_fq(&context.limbs, 0), + fetch_fq(&context.limbs, 1), + ) + .into(); + opt.expect("invalid g1 affine") + }; + let g2 = if context.g2_identity { + G2Affine::identity() + } else { + let opt: Option<_> = G2Affine { + x: fetch_fq2(&context.limbs, 2), + y: fetch_fq2(&context.limbs, 4), + } + .into(); + opt.expect("invalid g2 affine") + }; + context.input_cursor = 0; + context.limbs = vec![]; + let ab = pairing(&g1, &g2); + context.gt = Some(context.gt.map_or_else(|| ab, |x| x + ab)); + //log::debug!("\n\ngt is {:?}", context.gt); + } else { + context.limbs.push(args.nth(0)); + context.input_cursor += 1; + }; + None + }, + ), + ); + + env.external_env.register_function( + "bn254pair_pop", + Bn254PairG3 as usize, + ExternalHostCallSignature::Return, + foreign_blspair_plugin.clone(), + Rc::new( + |context: &mut dyn ForeignContext, _args: wasmi::RuntimeArgs| { + let context = context.downcast_mut::().unwrap(); + if context.result_cursor == 0 { + let gt = context.gt.unwrap(); + log::debug!("\n\ngt is {:?}", context.gt); + context.bn254_gt_to_limbs(gt); + } + let ret = Some(wasmi::RuntimeValue::I64( + context.result_limbs[context.result_cursor] as i64, + )); + context.result_cursor += 1; + ret + }, + ), + ); +} diff --git a/crates/host/src/host/ecc_helper/bn254/sum/mod.rs b/crates/host/src/host/ecc_helper/bn254/sum/mod.rs new file mode 100644 index 000000000..2ae7a8301 --- /dev/null +++ b/crates/host/src/host/ecc_helper/bn254/sum/mod.rs @@ -0,0 +1,157 @@ +use delphinus_zkwasm::runtime::host::host_env::HostEnv; +use delphinus_zkwasm::runtime::host::ForeignContext; +use halo2_proofs::pairing::bn256::G1Affine; +use halo2_proofs::pairing::group::prime::PrimeCurveAffine; +use std::ops::Add; +use std::rc::Rc; +use zkwasm_host_circuits::host::ForeignInst::Bn254SumG1; +use zkwasm_host_circuits::host::ForeignInst::Bn254SumNew; +use zkwasm_host_circuits::host::ForeignInst::Bn254SumResult; +use zkwasm_host_circuits::host::ForeignInst::Bn254SumScalar; + +use super::bn254_fq_to_limbs; +use super::fetch_fr; +use super::fetch_g1; + +struct BN254SumContext { + pub acc: G1Affine, + pub limbs: Vec, + pub coeffs: Vec, + pub result_limbs: Option>, + pub result_cursor: usize, +} + +impl BN254SumContext { + fn bn254_result_to_limbs(&mut self, g: G1Affine) { + let mut limbs = vec![]; + bn254_fq_to_limbs(&mut limbs, g.x); + bn254_fq_to_limbs(&mut limbs, g.y); + self.result_limbs = Some(limbs); + if g.is_identity().into() { + self.result_limbs.as_mut().unwrap().append(&mut vec![1u64]); + } else { + self.result_limbs.as_mut().unwrap().append(&mut vec![0u64]); + } + } + + pub fn default() -> Self { + BN254SumContext { + acc: G1Affine::identity(), + limbs: vec![], + coeffs: vec![], + result_limbs: None, + result_cursor: 0, + } + } + + pub fn bn254_sum_new(&mut self, new: usize) { + log::debug!("new bn254 sum context"); + self.result_limbs = None; + self.result_cursor = 0; + self.limbs = vec![]; + self.coeffs = vec![]; + if new != 0 { + G1Affine::identity(); + } + } + + fn bn254_sum_push_scalar(&mut self, v: u64) { + log::debug!("push scalar {}", v); + self.coeffs.push(v) + } + + fn bn254_sum_push_limb(&mut self, v: u64) { + log::debug!("push limb {}", v); + self.limbs.push(v) + } +} + +impl ForeignContext for BN254SumContext {} + +/* + * ForeignInst::Bn254SumNew + * ForeignInst::Bn254SumScalar + * ForeignInst::Bn254SumG1 + * ForeignInst::Bn254SumResult + */ + +use specs::external_host_call_table::ExternalHostCallSignature; +pub fn register_bn254sum_foreign(env: &mut HostEnv) { + let foreign_bn254sum_plugin = env + .external_env + .register_plugin("foreign_bn254sum", Box::new(BN254SumContext::default())); + + env.external_env.register_function( + "bn254_sum_new", + Bn254SumNew as usize, + ExternalHostCallSignature::Argument, + foreign_bn254sum_plugin.clone(), + Rc::new( + |context: &mut dyn ForeignContext, args: wasmi::RuntimeArgs| { + let context = context.downcast_mut::().unwrap(); + context.bn254_sum_new(args.nth::(0) as usize); + None + }, + ), + ); + + env.external_env.register_function( + "bn254_sum_scalar", + Bn254SumScalar as usize, + ExternalHostCallSignature::Argument, + foreign_bn254sum_plugin.clone(), + Rc::new( + |context: &mut dyn ForeignContext, args: wasmi::RuntimeArgs| { + let context = context.downcast_mut::().unwrap(); + context.bn254_sum_push_scalar(args.nth::(0)); + None + }, + ), + ); + + env.external_env.register_function( + "bn254_sum_g1", + Bn254SumG1 as usize, + ExternalHostCallSignature::Argument, + foreign_bn254sum_plugin.clone(), + Rc::new( + |context: &mut dyn ForeignContext, args: wasmi::RuntimeArgs| { + let context = context.downcast_mut::().unwrap(); + context.bn254_sum_push_limb(args.nth::(0)); + None + }, + ), + ); + + env.external_env.register_function( + "bn254_sum_finalize", + Bn254SumResult as usize, + ExternalHostCallSignature::Return, + foreign_bn254sum_plugin.clone(), + Rc::new( + |context: &mut dyn ForeignContext, _args: wasmi::RuntimeArgs| { + let context = context.downcast_mut::().unwrap(); + log::debug!("calculate finalize"); + context.result_limbs.clone().map_or_else( + || { + let coeff = fetch_fr(&context.coeffs); + log::debug!("coeff is {:?}", coeff); + let g1 = fetch_g1(&context.limbs); + log::debug!("g1 is {:?}", g1); + let next = g1 * coeff; + let g1result = context.acc.add(next).into(); + log::debug!("msm result: {:?}", g1result); + context.bn254_result_to_limbs(g1result); + }, + |_| (), + ); + let limbs = context.result_limbs.clone().unwrap(); + let ret = Some(wasmi::RuntimeValue::I64( + limbs[context.result_cursor] as i64, + )); + context.result_cursor += 1; + ret + }, + ), + ); +} diff --git a/crates/host/src/host/ecc_helper/jubjub/mod.rs b/crates/host/src/host/ecc_helper/jubjub/mod.rs new file mode 100644 index 000000000..a9993ed46 --- /dev/null +++ b/crates/host/src/host/ecc_helper/jubjub/mod.rs @@ -0,0 +1,44 @@ +pub mod sum; +use ark_std::Zero; +use halo2_proofs::pairing::bn256::Fr as BabyJubjubFq; +use num_bigint::BigUint; +use num_traits::FromPrimitive; +use std::ops::AddAssign; +use std::ops::Shl; +use zkwasm_host_circuits::host::jubjub; + +const LIMBSZ: usize = 64; +const LIMBNB: usize = 4; + +use super::bn_to_field; +use super::field_to_bn; + +pub fn fetch_fq(limbs: &Vec, index: usize) -> BabyJubjubFq { + let mut bn = BigUint::zero(); + for i in 0..LIMBNB { + bn.add_assign(BigUint::from_u64(limbs[index * LIMBNB + i]).unwrap() << (i * LIMBSZ)) + } + bn_to_field(&bn) +} + +fn fetch_g1(limbs: &Vec) -> jubjub::Point { + jubjub::Point { + x: fetch_fq(limbs, 0), + y: fetch_fq(limbs, 1), + } +} + +pub fn babyjubjub_fq_to_limbs(result_limbs: &mut Vec, f: BabyJubjubFq) { + let mut bn = field_to_bn(&f); + for _ in 0..LIMBNB { + let d: BigUint = BigUint::from(1 as u64).shl(LIMBSZ); + let r = bn.clone() % d.clone(); + let value = if r == BigUint::from(0 as u32) { + 0 as u64 + } else { + r.to_u64_digits()[0] + }; + bn = bn / d; + result_limbs.append(&mut vec![value]); + } +} diff --git a/crates/host/src/host/ecc_helper/jubjub/sum/mod.rs b/crates/host/src/host/ecc_helper/jubjub/sum/mod.rs new file mode 100644 index 000000000..45b7fe65f --- /dev/null +++ b/crates/host/src/host/ecc_helper/jubjub/sum/mod.rs @@ -0,0 +1,160 @@ +use delphinus_zkwasm::runtime::host::host_env::HostEnv; +use delphinus_zkwasm::runtime::host::ForeignContext; +use num_bigint::BigUint; +use std::rc::Rc; + +use zkwasm_host_circuits::host::ForeignInst::JubjubSumNew; +use zkwasm_host_circuits::host::ForeignInst::JubjubSumPush; +use zkwasm_host_circuits::host::ForeignInst::JubjubSumResult; + +use zkwasm_host_circuits::host::jubjub; + +use super::babyjubjub_fq_to_limbs; +use super::fetch_g1; +use super::LIMBNB; + +fn fetch_biguint(_limbs: &Vec) -> BigUint { + BigUint::from_bytes_le( + _limbs + .iter() + .map(|x| x.to_le_bytes()) + .flatten() + .collect::>() + .as_slice(), + ) +} + +pub struct BabyJubjubSumContext { + pub acc: jubjub::Point, + pub limbs: Vec, + pub coeffs: Vec, + pub result_limbs: Option>, + pub result_cursor: usize, + pub input_cursor: usize, +} + +impl BabyJubjubSumContext { + pub fn default() -> Self { + BabyJubjubSumContext { + acc: jubjub::Point::identity(), + limbs: vec![], + coeffs: vec![], + result_limbs: None, + result_cursor: 0, + input_cursor: 0, + } + } + + pub fn babyjubjub_sum_new(&mut self, new: usize) { + self.result_limbs = None; + self.result_cursor = 0; + self.limbs = vec![]; + self.input_cursor = 0; + self.coeffs = vec![]; + if new != 0 { + self.acc = jubjub::Point::identity(); + } + } + + pub fn babyjubjub_sum_push(&mut self, v: u64) { + if self.input_cursor < LIMBNB * 2 { + self.limbs.push(v); + self.input_cursor += 1; + } else if self.input_cursor < LIMBNB * 2 + 4 { + self.coeffs.push(v); + self.input_cursor += 1; + if self.input_cursor == LIMBNB * 2 + 4 { + self.input_cursor = 0; + } + } + } + + pub fn babyjubjub_sum_finalize(&mut self) -> u64 { + let limbs = self.result_limbs.clone(); + match limbs { + None => { + assert!(self.limbs.len() == LIMBNB * 2); + let coeff = fetch_biguint(&self.coeffs.to_vec()); + let g1 = fetch_g1(&self.limbs.to_vec()); + log::debug!("acc is {:?}", self.acc); + log::debug!("g1 is {:?}", g1); + log::debug!("coeff is {:?} {}", coeff, self.coeffs.len()); + self.acc = self + .acc + .projective() + .add(&g1.mul_scalar(&coeff).projective()) + .affine(); + log::debug!("msm result: {:?}", self.acc); + self.babyjubjub_result_to_limbs(self.acc.clone()); + } + _ => (), + }; + let ret = self.result_limbs.as_ref().unwrap()[self.result_cursor]; + self.result_cursor += 1; + + ret + } +} + +impl BabyJubjubSumContext { + fn babyjubjub_result_to_limbs(&mut self, g: jubjub::Point) { + let mut limbs = vec![]; + babyjubjub_fq_to_limbs(&mut limbs, g.x); + babyjubjub_fq_to_limbs(&mut limbs, g.y); + self.result_limbs = Some(limbs); + } +} + +impl ForeignContext for BabyJubjubSumContext {} + +use specs::external_host_call_table::ExternalHostCallSignature; +pub fn register_babyjubjubsum_foreign(env: &mut HostEnv) { + let foreign_babyjubjubsum_plugin = env.external_env.register_plugin( + "foreign_babyjubjubsum", + Box::new(BabyJubjubSumContext::default()), + ); + + env.external_env.register_function( + "babyjubjub_sum_new", + JubjubSumNew as usize, + ExternalHostCallSignature::Argument, + foreign_babyjubjubsum_plugin.clone(), + Rc::new( + |context: &mut dyn ForeignContext, args: wasmi::RuntimeArgs| { + let context = context.downcast_mut::().unwrap(); + context.babyjubjub_sum_new(args.nth::(0) as usize); + None + }, + ), + ); + + env.external_env.register_function( + "babyjubjub_sum_push", + JubjubSumPush as usize, + ExternalHostCallSignature::Argument, + foreign_babyjubjubsum_plugin.clone(), + Rc::new( + |context: &mut dyn ForeignContext, args: wasmi::RuntimeArgs| { + let context = context.downcast_mut::().unwrap(); + context.babyjubjub_sum_push(args.nth(0)); + None + }, + ), + ); + + env.external_env.register_function( + "babyjubjub_sum_finalize", + JubjubSumResult as usize, + ExternalHostCallSignature::Return, + foreign_babyjubjubsum_plugin.clone(), + Rc::new( + |context: &mut dyn ForeignContext, _args: wasmi::RuntimeArgs| { + let context = context.downcast_mut::().unwrap(); + let ret = Some(wasmi::RuntimeValue::I64( + context.babyjubjub_sum_finalize() as i64 + )); + ret + }, + ), + ); +} diff --git a/crates/host/src/host/ecc_helper/mod.rs b/crates/host/src/host/ecc_helper/mod.rs new file mode 100644 index 000000000..69e00f636 --- /dev/null +++ b/crates/host/src/host/ecc_helper/mod.rs @@ -0,0 +1,20 @@ +pub mod bls381; +pub mod bn254; +pub mod jubjub; +pub mod test; + +use halo2_proofs::arithmetic::BaseExt; +use num_bigint::BigUint; + +pub fn bn_to_field(bn: &BigUint) -> F { + let mut bytes = bn.to_bytes_le(); + bytes.resize(48, 0); + let mut bytes = &bytes[..]; + F::read(&mut bytes).unwrap() +} + +pub fn field_to_bn(f: &F) -> BigUint { + let mut bytes: Vec = Vec::new(); + f.write(&mut bytes).unwrap(); + BigUint::from_bytes_le(&bytes[..]) +} diff --git a/crates/host/src/host/ecc_helper/test.rs b/crates/host/src/host/ecc_helper/test.rs new file mode 100644 index 000000000..a8aa7bdd5 --- /dev/null +++ b/crates/host/src/host/ecc_helper/test.rs @@ -0,0 +1,109 @@ +#[cfg(test)] +pub(crate) mod tests { + use super::super::bn_to_field; + use halo2_proofs::arithmetic::CurveAffine; + use halo2_proofs::pairing::bn256::pairing; + use halo2_proofs::pairing::bn256::Fq2; + use halo2_proofs::pairing::bn256::G1Affine; + use halo2_proofs::pairing::bn256::G2Affine; + use num_bigint::BigUint; + //use core::ops::Add; + use std::str::FromStr; + fn get_g1(a: Vec<&str>) -> G1Affine { + G1Affine::from_xy( + bn_to_field(&BigUint::from_str(a[0]).unwrap()), + bn_to_field(&BigUint::from_str(a[1]).unwrap()), + ) + .unwrap() + } + fn get_g2(b: Vec<&str>) -> G2Affine { + G2Affine::from_xy( + Fq2 { + c0: bn_to_field(&BigUint::from_str(b[0]).unwrap()), + c1: bn_to_field(&BigUint::from_str(b[1]).unwrap()), + }, + Fq2 { + c0: bn_to_field(&BigUint::from_str(b[2]).unwrap()), + c1: bn_to_field(&BigUint::from_str(b[3]).unwrap()), + }, + ) + .unwrap() + } + + #[test] + fn test_bn254_add() { + let x = get_g1(vec![ + "11374933784481898583367503420546349347921686681304441661567497326629776056309", + "5039612884785796428364890828411823498920067180913949386530820955328247505500", + ]); + + let y = get_g1(vec![ + "6346696605408467183253691272432638422411966063101221796219900165046456247801", + "16021838921913636763711766864306630139800454605152352295402262906962367559814", + ]); + + let z: G1Affine = (x + y).into(); + println!("msm {:?}", z); + + let a = get_g1(vec![ + "11642537973992842197841129792593344678309686386610379404309438937881134387046", + "16038677464958343056835043065894747361239845934514535107990003321228770537757", + ]); + + let b = get_g2(vec![ + "47825847124631411811576281994805528104052872047575749583058110663112377001", + "8744222678452503383790834725135834161307861625945158048012780534319795560143", + "9233346029650632520218739027049068980416615687382718198119931453101152827975", + "10471280343341576477249226516274439500456322467064958156008066650244635888622", + ]); + + let pair_ab = pairing(&a, &b); + println!("\npair ab {:?}", pair_ab); + + let c = get_g1(vec![ + "5031514285120295997737123508423040879712685050138383293760355384665904754488", + "6823067879265550319809102199938618241998853703030415114792371967260649452853", + ]); + + let alpha = get_g1(vec![ + "16757480011835372184764354633328853212064194417052169636997013717174005603641", + "12432097195700978348921464455579756029074596339242363943410459715706216986941", + ]); + + let beta = get_g2(vec![ + "17975028126161125746872310568788265990276646416597355097039940884195819358739", + "17401920800019416240372951523628528842571722962428319020407322407751134153696", + "373336161763481738310767706475057352757645836211335436601460549560077507883", + "12596258404235599838080822038113194794755190435330940888082608644071169093526", + ]); + let pair_alphabeta = pairing(&alpha, &beta); + + let gamma = get_g2(vec![ + "10857046999023057135944570762232829481370756359578518086990519993285655852781", + "11559732032986387107991004021392285783925812861821192530917403151452391805634", + "8495653923123431417604973247489272438418190587263600148770280649306958101930", + "4082367875863433681332203403145435568316851327593401208105741076214120093531", + ]); + + let pair_gamma = pairing(&z, &gamma); + println!("\ng1 {:?}", z); + println!("g2 {:?}", gamma); + println!("pair gamma {:?}", pair_gamma); + println!("pair gamma + ab {:?}", pair_ab + pair_gamma); + + let delta = get_g2(vec![ + "3257864888291421116173460527534170713717410433509021668023378246238733003616", + "19501533296056540312008038527562968311092778436941336050675464372460956461923", + "6694920137971073977116331836462792254111247710837228432923435849982682441494", + "17519709022773002523554480652241560921521540950810125413580329045084856923004", + ]); + + let pair_delta = pairing(&c, &delta); + println!( + "\npair gamma + ab + delta {:?}", + pair_ab + pair_gamma + pair_delta + ); + //println!("\npair sum {:?}", pair_ab + pair_gamma + pair_delta - pair_alphabeta); + println!("\npair alpha beta {:?}", pair_alphabeta); + } +} diff --git a/crates/host/src/host/hash_helper/mod.rs b/crates/host/src/host/hash_helper/mod.rs new file mode 100644 index 000000000..dbfe2a9d7 --- /dev/null +++ b/crates/host/src/host/hash_helper/mod.rs @@ -0,0 +1,2 @@ +pub mod poseidon; +pub mod sha256; diff --git a/crates/host/src/host/hash_helper/poseidon.rs b/crates/host/src/host/hash_helper/poseidon.rs new file mode 100644 index 000000000..d924f7414 --- /dev/null +++ b/crates/host/src/host/hash_helper/poseidon.rs @@ -0,0 +1,157 @@ +use delphinus_zkwasm::runtime::host::host_env::HostEnv; +use delphinus_zkwasm::runtime::host::ForeignContext; +use ff::PrimeField; +use halo2_proofs::pairing::bn256::Fr; +use poseidon::Poseidon; +use std::rc::Rc; +pub use zkwasm_host_circuits::host::poseidon::POSEIDON_HASHER; + +use zkwasm_host_circuits::host::Reduce; +use zkwasm_host_circuits::host::ReduceRule; + +use zkwasm_host_circuits::host::ForeignInst::PoseidonFinalize; +use zkwasm_host_circuits::host::ForeignInst::PoseidonNew; +use zkwasm_host_circuits::host::ForeignInst::PoseidonPush; + +/// Foreign functions that supports the following C code library +/// +/// void poseidon(uint64_t* data, uint32_t size, uint64_t* r) +/// { +/// int i; +/// poseidon_new(size); +/// for(i=0; i, +} + +impl Generator { + pub fn gen(&mut self) -> u64 { + let r = self.values[self.cursor]; + self.cursor += 1; + if self.cursor == 4 { + self.cursor = 0; + } + r + } +} + +pub fn new_reduce(rules: Vec>) -> Reduce { + Reduce { cursor: 0, rules } +} + +pub struct PoseidonContext { + pub hasher: Option>, + pub generator: Generator, + pub buf: Vec, + pub fieldreducer: Reduce, +} + +impl PoseidonContext { + pub fn default() -> Self { + PoseidonContext { + hasher: None, + fieldreducer: new_reduce(vec![ReduceRule::Field(Fr::zero(), 64)]), + buf: vec![], + generator: Generator { + cursor: 0, + values: vec![], + }, + } + } + + pub fn poseidon_new(&mut self, new: usize) { + self.buf = vec![]; + if new != 0 { + self.hasher = Some(POSEIDON_HASHER.clone()); + } + } + + pub fn poseidon_push(&mut self, v: u64) { + self.fieldreducer.reduce(v); + if self.fieldreducer.cursor == 0 { + self.buf + .push(self.fieldreducer.rules[0].field_value().unwrap()) + } + } + + pub fn poseidon_finalize(&mut self) -> u64 { + assert!(self.buf.len() == 8); + if self.generator.cursor == 0 { + self.hasher.as_mut().map(|s| { + log::debug!("perform hash with {:?}", self.buf); + let r = s.update_exact(&self.buf.clone().try_into().unwrap()); + let dwords: Vec = r.to_repr().to_vec(); + self.generator.values = dwords + .chunks(8) + .map(|x| u64::from_le_bytes(x.to_vec().try_into().unwrap())) + .collect::>(); + }); + } + self.generator.gen() + } +} + +impl ForeignContext for PoseidonContext {} + +use specs::external_host_call_table::ExternalHostCallSignature; +pub fn register_poseidon_foreign(env: &mut HostEnv) { + let foreign_poseidon_plugin = env + .external_env + .register_plugin("foreign_sh256", Box::new(PoseidonContext::default())); + + env.external_env.register_function( + "poseidon_new", + PoseidonNew as usize, + ExternalHostCallSignature::Argument, + foreign_poseidon_plugin.clone(), + Rc::new( + |context: &mut dyn ForeignContext, args: wasmi::RuntimeArgs| { + let context = context.downcast_mut::().unwrap(); + log::debug!("buf len is {}", context.buf.len()); + context.poseidon_new(args.nth::(0) as usize); + None + }, + ), + ); + + env.external_env.register_function( + "poseidon_push", + PoseidonPush as usize, + ExternalHostCallSignature::Argument, + foreign_poseidon_plugin.clone(), + Rc::new( + |context: &mut dyn ForeignContext, args: wasmi::RuntimeArgs| { + let context = context.downcast_mut::().unwrap(); + context.poseidon_push(args.nth::(0) as u64); + None + }, + ), + ); + + env.external_env.register_function( + "poseidon_finalize", + PoseidonFinalize as usize, + ExternalHostCallSignature::Return, + foreign_poseidon_plugin.clone(), + Rc::new( + |context: &mut dyn ForeignContext, _args: wasmi::RuntimeArgs| { + let context = context.downcast_mut::().unwrap(); + Some(wasmi::RuntimeValue::I64(context.poseidon_finalize() as i64)) + }, + ), + ); +} diff --git a/crates/host/src/host/hash_helper/sha256.rs b/crates/host/src/host/hash_helper/sha256.rs new file mode 100644 index 000000000..4fe54d886 --- /dev/null +++ b/crates/host/src/host/hash_helper/sha256.rs @@ -0,0 +1,144 @@ +use delphinus_zkwasm::runtime::host::host_env::HostEnv; +use delphinus_zkwasm::runtime::host::ForeignContext; +use sha2::Digest; +use std::rc::Rc; +use zkwasm_host_circuits::host::ForeignInst::SHA256Finalize; +use zkwasm_host_circuits::host::ForeignInst::SHA256New; +use zkwasm_host_circuits::host::ForeignInst::SHA256Push; + +use sha2::Sha256; + +/// Foreign functions that supports the following C code library +/// +/// void sha256(uint8_t* data, uint32_t size, uint64_t* r) +/// { +/// int i; +/// sha256_new(size); +/// for(i=0; i, +} + +impl Generator { + fn gen(&mut self) -> u64 { + let r = self.values[self.cursor]; + self.cursor += 1; + r + } +} + +struct Sha256Context { + pub hasher: Option, + pub generator: Generator, + pub size: usize, +} + +impl Sha256Context { + fn default() -> Self { + Sha256Context { + hasher: None, + generator: Generator { + cursor: 0, + values: vec![], + }, + size: 0, + } + } +} + +impl ForeignContext for Sha256Context {} + +use specs::external_host_call_table::ExternalHostCallSignature; +pub fn register_sha256_foreign(env: &mut HostEnv) { + let foreign_sha256_plugin = env + .external_env + .register_plugin("foreign_sh256", Box::new(Sha256Context::default())); + + env.external_env.register_function( + "sha256_new", + SHA256New as usize, + ExternalHostCallSignature::Argument, + foreign_sha256_plugin.clone(), + Rc::new( + |context: &mut dyn ForeignContext, args: wasmi::RuntimeArgs| { + let context = context.downcast_mut::().unwrap(); + let hasher = context + .hasher + .as_mut() + .map_or(Some(Sha256::new()), |_| None); + hasher.map(|s| { + context.hasher = Some(s); + context.size = args.nth::(0) as usize; + }); + None + }, + ), + ); + + env.external_env.register_function( + "sha256_push", + SHA256Push as usize, + ExternalHostCallSignature::Argument, + foreign_sha256_plugin.clone(), + Rc::new( + |context: &mut dyn ForeignContext, args: wasmi::RuntimeArgs| { + let context = context.downcast_mut::().unwrap(); + context.hasher.as_mut().map(|s| { + let sz = if context.size > 8 { + context.size -= 8; + 8 + } else { + let s = context.size; + context.size = 0; + s + }; + let mut r = (args.nth::(0) as u64).to_le_bytes().to_vec(); + r.truncate(sz); + s.update(r); + }); + None + }, + ), + ); + + env.external_env.register_function( + "sha256_finalize", + SHA256Finalize as usize, + ExternalHostCallSignature::Return, + foreign_sha256_plugin.clone(), + Rc::new( + |context: &mut dyn ForeignContext, _args: wasmi::RuntimeArgs| { + let context = context.downcast_mut::().unwrap(); + context.hasher.as_ref().map(|s| { + let dwords: Vec = s.clone().finalize()[..].to_vec(); + context.generator.values = dwords + .chunks(8) + .map(|x| u64::from_le_bytes(x.to_vec().try_into().unwrap())) + .collect::>(); + }); + context.hasher = None; + Some(wasmi::RuntimeValue::I64(context.generator.gen() as i64)) + }, + ), + ); +} diff --git a/crates/host/src/host/merkle_helper/merkle.rs b/crates/host/src/host/merkle_helper/merkle.rs new file mode 100644 index 000000000..cd075c41c --- /dev/null +++ b/crates/host/src/host/merkle_helper/merkle.rs @@ -0,0 +1,307 @@ +use delphinus_zkwasm::runtime::host::host_env::HostEnv; +use delphinus_zkwasm::runtime::host::ForeignContext; +use halo2_proofs::pairing::bn256::Fr; +use std::cell::RefCell; +use std::rc::Rc; +use zkwasm_host_circuits::host::datahash as datahelper; +use zkwasm_host_circuits::host::datahash::DataHashRecord; +use zkwasm_host_circuits::host::db::TreeDB; +use zkwasm_host_circuits::host::merkle::MerkleTree; +use zkwasm_host_circuits::host::mongomerkle as merklehelper; +use zkwasm_host_circuits::host::ForeignInst::MerkleAddress; +use zkwasm_host_circuits::host::ForeignInst::MerkleFetchData; +use zkwasm_host_circuits::host::ForeignInst::MerkleGet; +use zkwasm_host_circuits::host::ForeignInst::MerkleGetRoot; +use zkwasm_host_circuits::host::ForeignInst::MerklePutData; +use zkwasm_host_circuits::host::ForeignInst::MerkleSet; +use zkwasm_host_circuits::host::ForeignInst::MerkleSetRoot; +use zkwasm_host_circuits::host::Reduce; +use zkwasm_host_circuits::host::ReduceRule; + +const MERKLE_TREE_HEIGHT: usize = 32; + +pub struct MerkleContext { + pub set_root: Reduce, + pub get_root: Reduce, + pub address: Reduce, + pub set: Reduce, + pub get: Reduce, + pub data: Vec, + pub data_cursor: usize, + pub fetch: bool, + pub mongo_merkle: Option>, + pub mongo_datahash: datahelper::MongoDataHash, + pub tree_db: Option>>, +} + +fn new_reduce(rules: Vec>) -> Reduce { + Reduce { cursor: 0, rules } +} + +impl MerkleContext { + pub fn new(tree_db: Option>>) -> Self { + MerkleContext { + set_root: new_reduce(vec![ReduceRule::Bytes(vec![], 4)]), + get_root: new_reduce(vec![ReduceRule::Bytes(vec![], 4)]), + address: new_reduce(vec![ReduceRule::U64(0)]), + set: new_reduce(vec![ReduceRule::Bytes(vec![], 4)]), + get: new_reduce(vec![ + ReduceRule::U64(0), + ReduceRule::U64(0), + ReduceRule::U64(0), + ReduceRule::U64(0), + ]), + fetch: false, + data: vec![], + data_cursor: 0, + mongo_merkle: None, + mongo_datahash: datahelper::MongoDataHash::construct([0; 32], tree_db.clone()), + tree_db, + } + } + + pub fn merkle_setroot(&mut self, v: u64) { + self.set_root.reduce(v); + if self.set_root.cursor == 0 { + log::debug!("set root: {:?}", &self.set_root.rules[0].bytes_value()); + self.mongo_merkle = Some(merklehelper::MongoMerkle::construct( + [0; 32], + self.set_root.rules[0] + .bytes_value() + .unwrap() + .try_into() + .unwrap(), + self.tree_db.clone(), + )); + } + } + + pub fn merkle_getroot(&mut self) -> u64 { + let mt = self + .mongo_merkle + .as_ref() + .expect("merkle db not initialized"); + let hash = mt.get_root_hash(); + let values = hash + .chunks(8) + .into_iter() + .map(|x| u64::from_le_bytes(x.to_vec().try_into().unwrap())) + .collect::>(); + let cursor = self.get_root.cursor; + self.get_root.reduce(values[self.get_root.cursor]); + values[cursor] + } + + pub fn merkle_address(&mut self, v: u64) { + self.data = vec![]; + self.fetch = false; + self.address.reduce(v); + } + + pub fn merkle_set(&mut self, v: u64) { + self.set.reduce(v); + if self.set.cursor == 0 { + let address = self.address.rules[0].u64_value().unwrap() as u32; + let index = (address as u64) + (1u64 << MERKLE_TREE_HEIGHT) - 1; + let mt = self + .mongo_merkle + .as_mut() + .expect("merkle db not initialized"); + let hash = self.set.rules[0].bytes_value().unwrap(); + mt.update_leaf_data_with_proof(index, &hash) + .expect("Unexpected failure: update leaf with proof fail"); + // put data and hash into mongo_datahash if the data is binded to the merkle tree leaf + if !self.data.is_empty() { + self.mongo_datahash + .update_record({ + DataHashRecord { + hash: hash.try_into().unwrap(), + data: self + .data + .iter() + .map(|x| x.to_le_bytes()) + .flatten() + .collect::>(), + } + }) + .unwrap(); + } + } + } + + pub fn merkle_get(&mut self) -> u64 { + let address = self.address.rules[0].u64_value().unwrap() as u32; + let index = (address as u64) + (1u64 << MERKLE_TREE_HEIGHT) - 1; + let mt = self + .mongo_merkle + .as_ref() + .expect("merkle db not initialized"); + let (leaf, _) = mt + .get_leaf_with_proof(index) + .expect("Unexpected failure: get leaf fail"); + let cursor = self.get.cursor; + let values = leaf.data_as_u64(); + self.get.reduce(values[self.get.cursor]); + // fetch data if we get the target hash + if self.get.cursor == 0 { + let hash: [u8; 32] = vec![ + self.get.rules[0] + .u64_value() + .unwrap() + .to_le_bytes() + .to_vec(), + self.get.rules[1] + .u64_value() + .unwrap() + .to_le_bytes() + .to_vec(), + self.get.rules[2] + .u64_value() + .unwrap() + .to_le_bytes() + .to_vec(), + self.get.rules[3] + .u64_value() + .unwrap() + .to_le_bytes() + .to_vec(), + ] + .into_iter() + .flatten() + .collect::>() + .try_into() + .unwrap(); + let datahashrecord = self.mongo_datahash.get_record(&hash).unwrap(); + self.data = datahashrecord.map_or(vec![], |r| { + r.data + .chunks_exact(8) + .into_iter() + .into_iter() + .map(|x| u64::from_le_bytes(x.try_into().unwrap())) + .collect::>() + }); + } + values[cursor] + } + + pub fn merkle_fetch_data(&mut self) -> u64 { + if self.fetch == false { + self.fetch = true; + self.data.reverse(); + self.data.len() as u64 + } else { + self.data.pop().unwrap() + } + } + + pub fn merkle_put_data(&mut self, v: u64) { + self.data.push(v); + } +} + +impl MerkleContext {} + +impl ForeignContext for MerkleContext {} + +use specs::external_host_call_table::ExternalHostCallSignature; +pub fn register_merkle_foreign(env: &mut HostEnv, tree_db: Option>>) { + let foreign_merkle_plugin = env + .external_env + .register_plugin("foreign_merkle", Box::new(MerkleContext::new(tree_db))); + + env.external_env.register_function( + "merkle_setroot", + MerkleSetRoot as usize, + ExternalHostCallSignature::Argument, + foreign_merkle_plugin.clone(), + Rc::new( + |context: &mut dyn ForeignContext, args: wasmi::RuntimeArgs| { + let context = context.downcast_mut::().unwrap(); + context.merkle_setroot(args.nth(0)); + None + }, + ), + ); + + env.external_env.register_function( + "merkle_getroot", + MerkleGetRoot as usize, + ExternalHostCallSignature::Return, + foreign_merkle_plugin.clone(), + Rc::new( + |context: &mut dyn ForeignContext, _args: wasmi::RuntimeArgs| { + let context = context.downcast_mut::().unwrap(); + Some(wasmi::RuntimeValue::I64(context.merkle_getroot() as i64)) + }, + ), + ); + + env.external_env.register_function( + "merkle_fetch_data", + MerkleFetchData as usize, + ExternalHostCallSignature::Return, + foreign_merkle_plugin.clone(), + Rc::new( + |context: &mut dyn ForeignContext, _args: wasmi::RuntimeArgs| { + let context = context.downcast_mut::().unwrap(); + Some(wasmi::RuntimeValue::I64(context.merkle_fetch_data() as i64)) + }, + ), + ); + + env.external_env.register_function( + "merkle_address", + MerkleAddress as usize, + ExternalHostCallSignature::Argument, + foreign_merkle_plugin.clone(), + Rc::new( + |context: &mut dyn ForeignContext, args: wasmi::RuntimeArgs| { + let context = context.downcast_mut::().unwrap(); + context.merkle_address(args.nth(0)); + None + }, + ), + ); + + env.external_env.register_function( + "merkle_put_data", + MerklePutData as usize, + ExternalHostCallSignature::Argument, + foreign_merkle_plugin.clone(), + Rc::new( + |context: &mut dyn ForeignContext, args: wasmi::RuntimeArgs| { + let context = context.downcast_mut::().unwrap(); + context.merkle_put_data(args.nth(0)); + None + }, + ), + ); + + env.external_env.register_function( + "merkle_set", + MerkleSet as usize, + ExternalHostCallSignature::Argument, + foreign_merkle_plugin.clone(), + Rc::new( + |context: &mut dyn ForeignContext, args: wasmi::RuntimeArgs| { + let context = context.downcast_mut::().unwrap(); + context.merkle_set(args.nth(0)); + None + }, + ), + ); + + env.external_env.register_function( + "merkle_get", + MerkleGet as usize, + ExternalHostCallSignature::Return, + foreign_merkle_plugin.clone(), + Rc::new( + |context: &mut dyn ForeignContext, _args: wasmi::RuntimeArgs| { + let context = context.downcast_mut::().unwrap(); + let ret = Some(wasmi::RuntimeValue::I64(context.merkle_get() as i64)); + ret + }, + ), + ); +} diff --git a/crates/host/src/host/merkle_helper/mod.rs b/crates/host/src/host/merkle_helper/mod.rs new file mode 100644 index 000000000..bdf9eb8f3 --- /dev/null +++ b/crates/host/src/host/merkle_helper/mod.rs @@ -0,0 +1 @@ +pub mod merkle; diff --git a/crates/host/src/host/mod.rs b/crates/host/src/host/mod.rs new file mode 100644 index 000000000..9b9534c06 --- /dev/null +++ b/crates/host/src/host/mod.rs @@ -0,0 +1,3 @@ +pub mod ecc_helper; +pub mod hash_helper; +pub mod merkle_helper; diff --git a/crates/host/src/lib.rs b/crates/host/src/lib.rs new file mode 100644 index 000000000..735f47f79 --- /dev/null +++ b/crates/host/src/lib.rs @@ -0,0 +1,67 @@ +pub mod host; +use std::cell::RefCell; +use std::rc::Rc; + +use delphinus_zkwasm::foreign::context::runtime::register_context_foreign; +use delphinus_zkwasm::foreign::log_helper::register_log_foreign; +use delphinus_zkwasm::foreign::require_helper::register_require_foreign; +use delphinus_zkwasm::foreign::wasm_input_helper::runtime::register_wasm_input_foreign; +use delphinus_zkwasm::runtime::wasmi_interpreter::WasmRuntimeIO; + +use delphinus_zkwasm::runtime::host::host_env::HostEnv; +use delphinus_zkwasm::runtime::host::HostEnvBuilder; +use std::sync::Arc; +use std::sync::Mutex; +use zkwasm_host_circuits::host::db::TreeDB; + +pub struct ExecutionArg { + /// Public inputs for `wasm_input(1)` + pub public_inputs: Vec, + /// Private inputs for `wasm_input(0)` + pub private_inputs: Vec, + /// Context inputs for `wasm_read_context()` + pub context_inputs: Vec, + /// Context outputs for `wasm_write_context()` + pub context_outputs: Arc>>, + /// db src + pub tree_db: Option>>, +} + +pub struct StandardHostEnvBuilder; + +impl HostEnvBuilder for StandardHostEnvBuilder { + type Arg = ExecutionArg; + + fn create_env_without_value() -> (HostEnv, WasmRuntimeIO) { + let mut env = HostEnv::new(); + let wasm_runtime_io = register_wasm_input_foreign(&mut env, vec![], vec![]); + register_require_foreign(&mut env); + register_log_foreign(&mut env); + register_context_foreign(&mut env, vec![], Arc::new(Mutex::new(vec![]))); + host::hash_helper::poseidon::register_poseidon_foreign(&mut env); + host::merkle_helper::merkle::register_merkle_foreign(&mut env, None); + host::ecc_helper::bn254::sum::register_bn254sum_foreign(&mut env); + host::ecc_helper::bn254::pair::register_bn254pair_foreign(&mut env); + host::ecc_helper::jubjub::sum::register_babyjubjubsum_foreign(&mut env); + env.finalize(); + + (env, wasm_runtime_io) + } + + fn create_env(arg: Self::Arg) -> (HostEnv, WasmRuntimeIO) { + let mut env = HostEnv::new(); + let wasm_runtime_io = + register_wasm_input_foreign(&mut env, arg.public_inputs, arg.private_inputs); + register_require_foreign(&mut env); + register_log_foreign(&mut env); + register_context_foreign(&mut env, arg.context_inputs, arg.context_outputs); + host::hash_helper::poseidon::register_poseidon_foreign(&mut env); + host::merkle_helper::merkle::register_merkle_foreign(&mut env, arg.tree_db); + host::ecc_helper::bn254::sum::register_bn254sum_foreign(&mut env); + host::ecc_helper::bn254::pair::register_bn254pair_foreign(&mut env); + host::ecc_helper::jubjub::sum::register_babyjubjubsum_foreign(&mut env); + env.finalize(); + + (env, wasm_runtime_io) + } +} diff --git a/crates/playground/Cargo.lock b/crates/playground/Cargo.lock index 856e10471..cd0eb8643 100644 --- a/crates/playground/Cargo.lock +++ b/crates/playground/Cargo.lock @@ -17,6 +17,19 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" +[[package]] +name = "ahash" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd7d5a2cecb58716e47d67d5703a249964b14c7be1ec3cad3affc295b2d1c35d" +dependencies = [ + "cfg-if 1.0.0", + "getrandom", + "once_cell", + "version_check", + "zerocopy", +] + [[package]] name = "aho-corasick" version = "1.0.2" @@ -26,6 +39,12 @@ dependencies = [ "memchr", ] +[[package]] +name = "allocator-api2" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0942ffc6dcaadf03badf6e6a2d0228460359d5e34b57ccdc720b7382dfbd5ec5" + [[package]] name = "android-tzdata" version = "0.1.1" @@ -73,6 +92,28 @@ version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" +[[package]] +name = "async-trait" +version = "0.1.74" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a66537f1bb974b254c98ed142ff995236e81b9d0fe4db0575f46612cb15eb0f9" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.27", +] + +[[package]] +name = "atty" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" +dependencies = [ + "hermit-abi 0.1.19", + "libc", + "winapi 0.3.9", +] + [[package]] name = "autocfg" version = "1.1.0" @@ -94,6 +135,18 @@ dependencies = [ "rustc-demangle", ] +[[package]] +name = "base64" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" + +[[package]] +name = "base64" +version = "0.21.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "35636a1494ede3b646cc98f74f8e62c773a38a659ebc777a2cf26b9b74171df9" + [[package]] name = "bitflags" version = "1.3.2" @@ -150,6 +203,27 @@ dependencies = [ "subtle", ] +[[package]] +name = "bson" +version = "2.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "58da0ae1e701ea752cc46c1bb9f39d5ecefc7395c3ecd526261a566d4f16e0c2" +dependencies = [ + "ahash", + "base64 0.13.1", + "bitvec", + "hex", + "indexmap 1.9.3", + "js-sys", + "once_cell", + "rand", + "serde", + "serde_bytes", + "serde_json", + "time", + "uuid", +] + [[package]] name = "bstr" version = "1.6.0" @@ -166,6 +240,12 @@ version = "3.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f1e260c3a9040a7c19a12468758f4c16f31a81a1fe087482be9570ec864bb6c" +[[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.79" @@ -218,6 +298,83 @@ dependencies = [ "phf_codegen", ] +[[package]] +name = "circuits-batcher" +version = "0.1.0" +source = "git+https://github.com/DelphinusLab/continuation-batcher.git#7b486f9eef386c6262fe0d812cb62cc031c0c753" +dependencies = [ + "anyhow", + "ark-std", + "bitvec", + "clap", + "downcast-rs", + "env_logger", + "ff", + "halo2_proofs", + "halo2aggregator-s", + "halo2ecc-s", + "hex", + "lazy_static", + "log", + "lru", + "md5", + "num", + "num-bigint", + "num-derive", + "num-integer", + "num-traits", + "poseidon", + "quote", + "rand", + "serde", + "serde_json", + "sha2", + "strum", + "strum_macros", + "uuid", + "wabt", + "wast", +] + +[[package]] +name = "clap" +version = "3.2.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ea181bf566f71cb9a5d17a59e1871af638180a18fb0035c92ae62b705207123" +dependencies = [ + "atty", + "bitflags 1.3.2", + "clap_derive", + "clap_lex", + "indexmap 1.9.3", + "once_cell", + "strsim", + "termcolor", + "textwrap", +] + +[[package]] +name = "clap_derive" +version = "3.2.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae6371b8bdc8b7d3959e9cf7b22d4435ef3e79e138688421ec654acf8c81b008" +dependencies = [ + "heck", + "proc-macro-error", + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "clap_lex" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2850f2f5a82cbf437dd5af4d49848fbdfc27c157c3d010345776f952765261c5" +dependencies = [ + "os_str_bytes", +] + [[package]] name = "cmake" version = "0.1.50" @@ -244,6 +401,12 @@ version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "21a53c0a4d288377e7415b53dcfc3c04da5cdc2cc95c8d5ac178b58f0b861ad6" +[[package]] +name = "convert_case" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e" + [[package]] name = "core-foundation-sys" version = "0.8.4" @@ -342,6 +505,47 @@ dependencies = [ "cuda-config", ] +[[package]] +name = "darling" +version = "0.13.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a01d95850c592940db9b8194bc39f4bc0e89dee5c4265e4b1807c34a9aba453c" +dependencies = [ + "darling_core", + "darling_macro", +] + +[[package]] +name = "darling_core" +version = "0.13.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "859d65a907b6852c9361e3185c862aae7fafd2887876799fa55f5f99dc40d610" +dependencies = [ + "fnv", + "ident_case", + "proc-macro2", + "quote", + "strsim", + "syn 1.0.109", +] + +[[package]] +name = "darling_macro" +version = "0.13.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c972679f83bdf9c42bd905396b6c3588a843a17f0f16dfcfa3e2c5d57441835" +dependencies = [ + "darling_core", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "data-encoding" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2e66c9d817f1720209181c316d28635c050fa304f9c79e47a520882661b7308" + [[package]] name = "delphinus-zkwasm" version = "0.1.0" @@ -350,6 +554,7 @@ dependencies = [ "ark-std", "bitvec", "downcast-rs", + "ff", "halo2_proofs", "halo2aggregator-s", "hex", @@ -359,14 +564,47 @@ dependencies = [ "num-integer", "num-traits", "parity-wasm", + "poseidon", "rand", "serde", "serde_json", + "sha2", "specs", "strum", "strum_macros", "wabt", "wasmi", + "zkwasm-host-circuits", +] + +[[package]] +name = "deranged" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f32d04922c60427da6f9fef14d042d9edddef64cb9d4ce0d64d0685fbeb1fd3" + +[[package]] +name = "derivative" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fcc3dd5e9e9c0b295d6e1e4d811fb6f157d5ffd784b8d202fc62eac8035a770b" +dependencies = [ + "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]] @@ -383,6 +621,7 @@ checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" dependencies = [ "block-buffer", "crypto-common", + "subtle", ] [[package]] @@ -445,6 +684,37 @@ version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07" +[[package]] +name = "enum-as-inner" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "21cdad81446a7f7dc43f6a77409efeb9733d2fa65553efef6018ef257c959b73" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "env_logger" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a12e6657c4c97ebab115a42dcee77225f7f482cdd841cf7088c657a42e9e00e7" +dependencies = [ + "atty", + "humantime", + "log", + "regex", + "termcolor", +] + +[[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.1" @@ -526,13 +796,19 @@ dependencies = [ "rustacuda_derive", ] +[[package]] +name = "finl_unicode" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8fcfdc7a0362c9f4444381a9e697c79d435fe65b52a37466fc2c1184cee9edc6" + [[package]] name = "flume" version = "0.10.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1657b4441c3403d9f7b3409e47575237dac27b1b5726df654a6ecbf92f0f7577" dependencies = [ - "spin", + "spin 0.9.8", ] [[package]] @@ -541,12 +817,92 @@ version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" +[[package]] +name = "form_urlencoded" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a62bc1cf6f830c2ec14a513a9fb124d0a213a629668a4186f329db21fe045652" +dependencies = [ + "percent-encoding", +] + [[package]] name = "funty" version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" +[[package]] +name = "futures-channel" +version = "0.3.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "955518d47e09b25bbebc7a18df10b81f0c766eaf4c4f1cccef2fca5f2a4fb5f2" +dependencies = [ + "futures-core", +] + +[[package]] +name = "futures-core" +version = "0.3.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4bca583b7e26f571124fe5b7561d49cb2868d79116cfa0eefce955557c6fee8c" + +[[package]] +name = "futures-executor" +version = "0.3.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ccecee823288125bd88b4d7f565c9e58e41858e47ab72e8ea2d64e93624386e0" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fff74096e71ed47f8e023204cfd0aa1289cd54ae5430a9523be060cdb849964" + +[[package]] +name = "futures-macro" +version = "0.3.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "89ca545a94061b6365f2c7355b4b32bd20df3ff95f02da9329b34ccc3bd6ee72" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.27", +] + +[[package]] +name = "futures-sink" +version = "0.3.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f43be4fe21a13b9781a69afa4985b0f6ee0e1afab2c6f454a8cf30e2b2237b6e" + +[[package]] +name = "futures-task" +version = "0.3.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76d3d132be6c0e6aa1534069c705a74a5997a356c0dc2f86a47765e5617c5b65" + +[[package]] +name = "futures-util" +version = "0.3.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26b01e40b772d54cf6c6d721c1d1abd0647a0106a12ecaa1c186273392a69533" +dependencies = [ + "futures-core", + "futures-io", + "futures-macro", + "futures-task", + "memchr", + "pin-project-lite", + "pin-utils", + "slab", +] + [[package]] name = "generic-array" version = "0.14.7" @@ -677,12 +1033,37 @@ dependencies = [ "rayon", ] +[[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.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f93e7192158dbcda357bdec5fb5788eebf8bbac027f3f33e719d29135ae84156" +dependencies = [ + "ahash", + "allocator-api2", +] + [[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.1.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" +dependencies = [ + "libc", +] + [[package]] name = "hermit-abi" version = "0.3.2" @@ -695,6 +1076,26 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" +[[package]] +name = "hmac" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" +dependencies = [ + "digest", +] + +[[package]] +name = "hostname" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c731c3e10504cc8ed35cfe2f1db4c9274c3d35fa486e3b31df46f068ef3e867" +dependencies = [ + "libc", + "match_cfg", + "winapi 0.3.9", +] + [[package]] name = "humansize" version = "2.1.3" @@ -704,6 +1105,12 @@ dependencies = [ "libm", ] +[[package]] +name = "humantime" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" + [[package]] name = "iana-time-zone" version = "0.1.57" @@ -728,8 +1135,35 @@ dependencies = [ ] [[package]] -name = "ignore" -version = "0.4.20" +name = "ident_case" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" + +[[package]] +name = "idna" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "418a0a6fab821475f634efe3ccc45c013f742efe03d853e8d3355d5cb850ecf8" +dependencies = [ + "matches", + "unicode-bidi", + "unicode-normalization", +] + +[[package]] +name = "idna" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d20d6b07bfbc108882d88ed8e37d39636dcc260e15e30c45e6ba089610b917c" +dependencies = [ + "unicode-bidi", + "unicode-normalization", +] + +[[package]] +name = "ignore" +version = "0.4.20" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dbe7873dab538a9a44ad79ede1faf5f30d49f9a5c883ddbab48bce81b64b7492" dependencies = [ @@ -744,13 +1178,51 @@ dependencies = [ "winapi-util", ] +[[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.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8adf3ddd720272c6ea8bf59463c04e0f93d0bbf7c5439b691bca2987e0270897" +dependencies = [ + "equivalent", + "hashbrown 0.14.2", +] + +[[package]] +name = "ipconfig" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b58db92f96b720de98181bbbe63c831e87005ab460c1bf306eb2622b4707997f" +dependencies = [ + "socket2 0.5.4", + "widestring", + "windows-sys", + "winreg", +] + +[[package]] +name = "ipnet" +version = "2.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f518f335dce6725a761382244631d86cf0ccb2863413590b31338feb467f9c3" + [[package]] name = "is-terminal" version = "0.4.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cb0889898416213fab133e1d33a0e5858a48177452750691bde3666d0fdbaf8b" dependencies = [ - "hermit-abi", + "hermit-abi 0.3.2", "rustix", "windows-sys", ] @@ -786,6 +1258,12 @@ version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" +[[package]] +name = "leb128" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "884e2677b40cc8c339eaefcb701c32ef1fd2493d71118dc0ca4b6a736c93bd67" + [[package]] name = "libc" version = "0.2.147" @@ -798,6 +1276,12 @@ version = "0.2.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f7012b1bbb0719e1097c47611d3898568c546d597c2e74d66f6087edd5233ff4" +[[package]] +name = "linked-hash-map" +version = "0.5.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0717cef1bc8b636c6e1c1bbdefc09e6322da8a9321966e8928ef80d20f7f770f" + [[package]] name = "linux-raw-sys" version = "0.4.3" @@ -820,6 +1304,52 @@ version = "0.4.19" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b06a4cde4c0f271a446782e3eff8de789548ce57dbc8eca9292c27f4a42004b4" +[[package]] +name = "lru" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4a83fb7698b3643a0e34f9ae6f2e8f0178c0fd42f8b59d493aa271ff3a5bf21" +dependencies = [ + "hashbrown 0.14.2", +] + +[[package]] +name = "lru-cache" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "31e24f1ad8321ca0e8a1e0ac13f23cb668e6f5466c2c57319f6a5cf1cc8e3b1c" +dependencies = [ + "linked-hash-map", +] + +[[package]] +name = "match_cfg" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ffbee8634e0d45d258acb448e7eaab3fce7a0a467395d4d9f228e3c1f01fb2e4" + +[[package]] +name = "matches" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2532096657941c2fea9c289d370a250971c689d4f143798ff67113ec042024a5" + +[[package]] +name = "md-5" +version = "0.10.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d89e7ee0cfbedfc4da3340218492196241d89eefb6dab27de5df917a6d2e78cf" +dependencies = [ + "cfg-if 1.0.0", + "digest", +] + +[[package]] +name = "md5" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "490cc448043f947bae3cbee9c203358d62dbee0db12107a74be5c30ccfd09771" + [[package]] name = "memchr" version = "2.5.0" @@ -860,6 +1390,64 @@ dependencies = [ "adler", ] +[[package]] +name = "mio" +version = "0.8.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "927a765cd3fc26206e66b296465fa9d3e5ab003e651c1b3c060e7956d96b19d2" +dependencies = [ + "libc", + "wasi", + "windows-sys", +] + +[[package]] +name = "mongodb" +version = "2.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e22d517e7e678e1c9a2983ec704b43f3b22f38b1b7a247ea3ddb36d21578bf4e" +dependencies = [ + "async-trait", + "base64 0.13.1", + "bitflags 1.3.2", + "bson", + "chrono", + "derivative", + "derive_more", + "futures-core", + "futures-executor", + "futures-io", + "futures-util", + "hex", + "hmac", + "lazy_static", + "md-5", + "pbkdf2", + "percent-encoding", + "rand", + "rustc_version_runtime", + "rustls", + "rustls-pemfile", + "serde", + "serde_bytes", + "serde_with", + "sha-1", + "sha2", + "socket2 0.4.9", + "stringprep", + "strsim", + "take_mut", + "thiserror", + "tokio", + "tokio-rustls", + "tokio-util", + "trust-dns-proto", + "trust-dns-resolver", + "typed-builder", + "uuid", + "webpki-roots", +] + [[package]] name = "num" version = "0.4.1" @@ -954,7 +1542,7 @@ version = "1.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" dependencies = [ - "hermit-abi", + "hermit-abi 0.3.2", "libc", ] @@ -973,6 +1561,12 @@ version = "1.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" +[[package]] +name = "os_str_bytes" +version = "6.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2355d85b9a3786f481747ced0e0ff2ba35213a1f9bd406ed906554d7af805a1" + [[package]] name = "pairing" version = "0.22.0" @@ -1003,6 +1597,29 @@ version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "be5e13c266502aadf83426d87d81a0f5d1ef45b8027f5a471c360abfe4bfae92" +[[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 1.0.0", + "libc", + "redox_syscall 0.4.1", + "smallvec", + "windows-targets", +] + [[package]] name = "parse-zoneinfo" version = "0.3.0" @@ -1012,6 +1629,15 @@ dependencies = [ "regex", ] +[[package]] +name = "pbkdf2" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "83a0692ec44e4cf1ef28ca317f14f8f07da2d95ec3fa01f86e4467b725e60917" +dependencies = [ + "digest", +] + [[package]] name = "percent-encoding" version = "2.3.0" @@ -1101,6 +1727,18 @@ dependencies = [ "uncased", ] +[[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 = "playground" version = "0.1.0" @@ -1125,6 +1763,30 @@ version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" +[[package]] +name = "proc-macro-error" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" +dependencies = [ + "proc-macro-error-attr", + "proc-macro2", + "quote", + "syn 1.0.109", + "version_check", +] + +[[package]] +name = "proc-macro-error-attr" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" +dependencies = [ + "proc-macro2", + "quote", + "version_check", +] + [[package]] name = "proc-macro2" version = "1.0.66" @@ -1134,6 +1796,12 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "quick-error" +version = "1.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" + [[package]] name = "quote" version = "1.0.32" @@ -1210,6 +1878,15 @@ dependencies = [ "bitflags 1.3.2", ] +[[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 = "redox_users" version = "0.4.3" @@ -1217,7 +1894,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b033d837a7cf162d7993aded9304e30a83213c648b6e389db233191f891e5c2b" dependencies = [ "getrandom", - "redox_syscall", + "redox_syscall 0.2.16", "thiserror", ] @@ -1250,6 +1927,40 @@ version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e5ea92a5b6195c6ef2a0295ea818b312502c6fc94dde986c5553242e18fd4ce2" +[[package]] +name = "resolv-conf" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "52e44394d2086d010551b14b53b1f24e31647570cd1deb0379e2c21b329aba00" +dependencies = [ + "hostname", + "quick-error", +] + +[[package]] +name = "ring" +version = "0.16.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3053cf52e236a3ed746dfc745aa9cacf1b791d846bdaf412f60a8d7d6e17c8fc" +dependencies = [ + "cc", + "libc", + "once_cell", + "spin 0.5.2", + "untrusted", + "web-sys", + "winapi 0.3.9", +] + +[[package]] +name = "ripemd" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd124222d17ad93a644ed9d011a40f4fb64aa54275c08cc216524a9ea82fb09f" +dependencies = [ + "digest", +] + [[package]] name = "rust-gpu-tools" version = "0.6.2" @@ -1290,6 +2001,34 @@ 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.20", +] + +[[package]] +name = "rustc_version_runtime" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d31b7153270ebf48bf91c65ae5b0c00e749c4cfad505f66530ac74950249582f" +dependencies = [ + "rustc_version 0.2.3", + "semver 0.9.0", +] + [[package]] name = "rustix" version = "0.38.4" @@ -1303,6 +2042,37 @@ dependencies = [ "windows-sys", ] +[[package]] +name = "rustls" +version = "0.21.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd8d6c9f025a446bc4d18ad9632e69aec8f287aa84499ee335599fabd20c3fd8" +dependencies = [ + "log", + "ring", + "rustls-webpki", + "sct", +] + +[[package]] +name = "rustls-pemfile" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2d3987094b1d07b653b7dfdc3f70ce9a1da9c51ac18c1b06b662e4f9a0e9f4b2" +dependencies = [ + "base64 0.21.5", +] + +[[package]] +name = "rustls-webpki" +version = "0.101.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c7d5dece342910d9ba34d259310cae3e0154b873b35408b787b59bce53d34fe" +dependencies = [ + "ring", + "untrusted", +] + [[package]] name = "rustversion" version = "1.0.14" @@ -1330,6 +2100,37 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" +[[package]] +name = "sct" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d53dcdb7c9f8158937a7981b48accfd39a43af418591a5d008c7b22b5e1b7ca4" +dependencies = [ + "ring", + "untrusted", +] + +[[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.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "836fa6a3e1e547f9a2c4040802ec865b5d85f4014efe00555d7090a3dcaa1090" + +[[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.175" @@ -1339,6 +2140,15 @@ dependencies = [ "serde_derive", ] +[[package]] +name = "serde_bytes" +version = "0.11.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab33ec92f677585af6d88c65593ae2375adde54efdbf16d597f2cbc7a6d368ff" +dependencies = [ + "serde", +] + [[package]] name = "serde_derive" version = "1.0.175" @@ -1356,11 +2166,45 @@ version = "1.0.103" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d03b412469450d4404fe8499a268edd7f8b79fecb074b0d812ad64ca21f4031b" dependencies = [ + "indexmap 2.0.2", "itoa", "ryu", "serde", ] +[[package]] +name = "serde_with" +version = "1.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "678b5a069e50bf00ecd22d0cd8ddf7c236f68581b03db652061ed5eb13a312ff" +dependencies = [ + "serde", + "serde_with_macros", +] + +[[package]] +name = "serde_with_macros" +version = "1.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e182d6ec6f05393cc0e5ed1bf81ad6db3a8feedf8ee515ecdd369809bcce8082" +dependencies = [ + "darling", + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "sha-1" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f5058ada175748e33390e40e872bd0fe59a19f265d0158daa551c5a88a76009c" +dependencies = [ + "cfg-if 1.0.0", + "cpufeatures", + "digest", +] + [[package]] name = "sha2" version = "0.10.7" @@ -1372,12 +2216,30 @@ dependencies = [ "digest", ] +[[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 = "siphasher" version = "0.3.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7bd3e3206899af3f8b12af284fafc038cc1dc2b41d1b89dd17297221c5d225de" +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + [[package]] name = "slug" version = "0.1.4" @@ -1387,11 +2249,38 @@ dependencies = [ "deunicode", ] +[[package]] +name = "smallvec" +version = "1.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "942b4a808e05215192e39f4ab80813e599068285906cc91aa64f923db842bd5a" + +[[package]] +name = "socket2" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64a4a911eed85daf18834cfaa86a79b7d266ff93ff5ba14005426219480ed662" +dependencies = [ + "libc", + "winapi 0.3.9", +] + +[[package]] +name = "socket2" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4031e820eb552adee9295814c0ced9e5cf38ddf1e8b7d566d6de8e2538ea989e" +dependencies = [ + "libc", + "windows-sys", +] + [[package]] name = "specs" version = "0.1.0" dependencies = [ "halo2_proofs", + "hex", "lazy_static", "num-bigint", "parity-wasm", @@ -1401,6 +2290,12 @@ dependencies = [ "strum_macros", ] +[[package]] +name = "spin" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" + [[package]] name = "spin" version = "0.9.8" @@ -1416,6 +2311,23 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" +[[package]] +name = "stringprep" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb41d74e231a107a1b4ee36bd1214b11285b77768d2e3824aedafa988fd36ee6" +dependencies = [ + "finl_unicode", + "unicode-bidi", + "unicode-normalization", +] + +[[package]] +name = "strsim" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" + [[package]] name = "strum" version = "0.24.1" @@ -1463,6 +2375,12 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "take_mut" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f764005d11ee5f36500a149ace24e00e3da98b0158b3e2d53a7495660d3f4d60" + [[package]] name = "tap" version = "1.0.1" @@ -1501,6 +2419,21 @@ dependencies = [ "unic-segment", ] +[[package]] +name = "termcolor" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6093bad37da69aab9d123a8091e4be0aa4a03e4d601ec641c327398315f62b64" +dependencies = [ + "winapi-util", +] + +[[package]] +name = "textwrap" +version = "0.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "222a222a5bfe1bba4a77b45ec488a741b3cb8872e5e499451fd7d0129c9c7c3d" + [[package]] name = "thiserror" version = "1.0.44" @@ -1530,6 +2463,158 @@ dependencies = [ "once_cell", ] +[[package]] +name = "time" +version = "0.3.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b0fdd63d58b18d663fbdf70e049f00a22c8e42be082203be7f26589213cd75ea" +dependencies = [ + "deranged", + "itoa", + "serde", + "time-core", + "time-macros", +] + +[[package]] +name = "time-core" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7300fbefb4dadc1af235a9cef3737cea692a9d97e1b9cbcd4ebdae6f8868e6fb" + +[[package]] +name = "time-macros" +version = "0.2.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eb71511c991639bb078fd5bf97757e03914361c48100d52878b8e52b46fb92cd" +dependencies = [ + "time-core", +] + +[[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.33.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4f38200e3ef7995e5ef13baec2f432a6da0aa9ac495b2c0e8f3b7eec2c92d653" +dependencies = [ + "backtrace", + "bytes", + "libc", + "mio", + "num_cpus", + "pin-project-lite", + "signal-hook-registry", + "socket2 0.5.4", + "tokio-macros", + "windows-sys", +] + +[[package]] +name = "tokio-macros" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "630bdcf245f78637c13ec01ffae6187cca34625e8c63150d424b59e55af2675e" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.27", +] + +[[package]] +name = "tokio-rustls" +version = "0.24.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c28327cf380ac148141087fbfb9de9d7bd4e84ab5d2c28fbc911d753de8a7081" +dependencies = [ + "rustls", + "tokio", +] + +[[package]] +name = "tokio-util" +version = "0.7.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d68074620f57a0b21594d9735eb2e98ab38b17f80d3fcb189fca266771ca60d" +dependencies = [ + "bytes", + "futures-core", + "futures-io", + "futures-sink", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "trust-dns-proto" +version = "0.21.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c31f240f59877c3d4bb3b3ea0ec5a6a0cff07323580ff8c7a605cd7d08b255d" +dependencies = [ + "async-trait", + "cfg-if 1.0.0", + "data-encoding", + "enum-as-inner", + "futures-channel", + "futures-io", + "futures-util", + "idna 0.2.3", + "ipnet", + "lazy_static", + "log", + "rand", + "smallvec", + "thiserror", + "tinyvec", + "tokio", + "url", +] + +[[package]] +name = "trust-dns-resolver" +version = "0.21.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e4ba72c2ea84515690c9fcef4c6c660bb9df3036ed1051686de84605b74fd558" +dependencies = [ + "cfg-if 1.0.0", + "futures-util", + "ipconfig", + "lazy_static", + "log", + "lru-cache", + "parking_lot", + "resolv-conf", + "smallvec", + "thiserror", + "tokio", + "trust-dns-proto", +] + +[[package]] +name = "typed-builder" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "89851716b67b937e393b3daa8423e67ddfc4bbbf1654bcf05488e95e0828db0c" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + [[package]] name = "typenum" version = "1.16.0" @@ -1601,12 +2686,60 @@ dependencies = [ "unic-common", ] +[[package]] +name = "unicode-bidi" +version = "0.3.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92888ba5573ff080736b3648696b70cafad7d250551175acbaa4e0385b3e1460" + [[package]] name = "unicode-ident" version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "301abaae475aa91687eb82514b328ab47a211a533026cb25fc3e519b86adfc3c" +[[package]] +name = "unicode-normalization" +version = "0.1.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c5713f0fc4b5db668a2ac63cdb7bb4469d8c9fed047b1d0292cc7b0ce2ba921" +dependencies = [ + "tinyvec", +] + +[[package]] +name = "unicode-width" +version = "0.1.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e51733f11c9c4f72aa0c160008246859e340b00807569a0da0e7a1079b27ba85" + +[[package]] +name = "untrusted" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a" + +[[package]] +name = "url" +version = "2.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "143b538f18257fac9cad154828a57c6bf5157e1aa604d4816b5995bf6de87ae5" +dependencies = [ + "form_urlencoded", + "idna 0.4.0", + "percent-encoding", +] + +[[package]] +name = "uuid" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88ad59a7560b41a70d191093a945f0b87bc1deeda46fb237479708a1d6b6cdfc" +dependencies = [ + "getrandom", + "serde", +] + [[package]] name = "version_check" version = "0.9.4" @@ -1706,6 +2839,15 @@ version = "0.2.87" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ca6ad05a4870b2bf5fe995117d3728437bd27d7cd5f06f13c17443ef369775a1" +[[package]] +name = "wasm-encoder" +version = "0.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c64ac98d5d61192cc45c701b7e4bd0b9aff91e2edfc7a088406cfe2288581e2c" +dependencies = [ + "leb128", +] + [[package]] name = "wasmi" version = "0.11.0" @@ -1735,6 +2877,40 @@ dependencies = [ "parity-wasm", ] +[[package]] +name = "wast" +version = "47.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02b98502f3978adea49551e801a6687678e6015317d7d9470a67fe813393f2a8" +dependencies = [ + "leb128", + "memchr", + "unicode-width", + "wasm-encoder", +] + +[[package]] +name = "web-sys" +version = "0.3.64" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b85cbef8c220a6abc02aefd892dfc0fc23afb1c6a426316ec33253a3877249b" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "webpki-roots" +version = "0.25.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14247bb57be4f377dfb94c72830b8ce8fc6beac03cf4bf7b9732eadd414123fc" + +[[package]] +name = "widestring" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "653f141f39ec16bba3c5abe400a0c60da7468261cc2cbf36805022876bc721a8" + [[package]] name = "winapi" version = "0.2.8" @@ -1853,6 +3029,16 @@ version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a" +[[package]] +name = "winreg" +version = "0.50.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "524e57b2c537c0f9b1e69f1965311ec12182b4122e45035b1508cd24d2adadb1" +dependencies = [ + "cfg-if 1.0.0", + "windows-sys", +] + [[package]] name = "wyz" version = "0.5.1" @@ -1871,3 +3057,49 @@ dependencies = [ "flume", "scopeguard", ] + +[[package]] +name = "zerocopy" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a7af71d8643341260a65f89fa60c0eeaa907f34544d8f6d9b0df72f069b5e74" +dependencies = [ + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9731702e2f0617ad526794ae28fbc6f6ca8849b5ba729666c2a5bc4b6ddee2cd" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.27", +] + +[[package]] +name = "zkwasm-host-circuits" +version = "0.1.0" +source = "git+https://github.com/DelphinusLab/zkWasm-host-circuits.git?branch=main#997af6f26acd12be6ec988c7a14be29a5f1039c4" +dependencies = [ + "ark-std", + "circuits-batcher", + "clap", + "ff", + "halo2_proofs", + "halo2ecc-s", + "hex", + "lazy_static", + "lru", + "mongodb", + "num-bigint", + "poseidon", + "rand", + "ripemd", + "serde", + "serde_json", + "strum", + "strum_macros", + "subtle", +] diff --git a/crates/playground/examples/binary_search.rs b/crates/playground/examples/binary_search.rs index e5164453f..ceb628073 100644 --- a/crates/playground/examples/binary_search.rs +++ b/crates/playground/examples/binary_search.rs @@ -2,16 +2,17 @@ use std::sync::Arc; use std::sync::Mutex; use anyhow::Result; -use delphinus_zkwasm::loader::ExecutionArg; use delphinus_zkwasm::loader::ZkWasmLoader; +use delphinus_zkwasm::runtime::host::default_env::DefaultHostEnvBuilder; +use delphinus_zkwasm::runtime::host::default_env::ExecutionArg; use pairing_bn256::bn256::Bn256; fn main() -> Result<()> { let wasm = std::fs::read("wasm/binary_search.wasm")?; - let loader = ZkWasmLoader::::new(18, wasm, vec![])?; + let loader = ZkWasmLoader::::new(18, wasm, vec![])?; - let (circuit, instances) = loader.circuit_with_witness(ExecutionArg { + let (circuit, instances, _) = loader.circuit_with_witness(ExecutionArg { public_inputs: vec![0], private_inputs: vec![], context_inputs: vec![], diff --git a/crates/playground/examples/context.rs b/crates/playground/examples/context.rs index 0ff82d733..69d7ed0b5 100644 --- a/crates/playground/examples/context.rs +++ b/crates/playground/examples/context.rs @@ -2,8 +2,9 @@ use std::sync::Arc; use std::sync::Mutex; use anyhow::Result; -use delphinus_zkwasm::loader::ExecutionArg; use delphinus_zkwasm::loader::ZkWasmLoader; +use delphinus_zkwasm::runtime::host::default_env::DefaultHostEnvBuilder; +use delphinus_zkwasm::runtime::host::default_env::ExecutionArg; use pairing_bn256::bn256::Bn256; fn main() -> Result<()> { @@ -12,7 +13,7 @@ fn main() -> Result<()> { let context_in: Vec = vec![2, 1]; let context_outputs = Arc::new(Mutex::new(vec![])); - let loader = ZkWasmLoader::::new(18, wasm, vec![])?; + let loader = ZkWasmLoader::::new(18, wasm, vec![])?; let arg = ExecutionArg { public_inputs: vec![], private_inputs: vec![], @@ -20,7 +21,7 @@ fn main() -> Result<()> { context_outputs: context_outputs.clone(), }; - let (circuit, instances) = loader.circuit_with_witness(arg)?; + let (circuit, instances, _) = loader.circuit_with_witness(arg)?; loader.mock_test(&circuit, &instances)?; let arg = ExecutionArg { @@ -30,7 +31,7 @@ fn main() -> Result<()> { context_outputs: Arc::new(Mutex::new(vec![])), }; - let (circuit, instances) = loader.circuit_with_witness(arg)?; + let (circuit, instances, _) = loader.circuit_with_witness(arg)?; loader.mock_test(&circuit, &instances)?; Ok(()) diff --git a/crates/playground/examples/fibonacci.rs b/crates/playground/examples/fibonacci.rs index 0b17df69a..f46e2adab 100644 --- a/crates/playground/examples/fibonacci.rs +++ b/crates/playground/examples/fibonacci.rs @@ -2,16 +2,17 @@ use std::sync::Arc; use std::sync::Mutex; use anyhow::Result; -use delphinus_zkwasm::loader::ExecutionArg; use delphinus_zkwasm::loader::ZkWasmLoader; +use delphinus_zkwasm::runtime::host::default_env::DefaultHostEnvBuilder; +use delphinus_zkwasm::runtime::host::default_env::ExecutionArg; use pairing_bn256::bn256::Bn256; fn main() -> Result<()> { let wasm = std::fs::read("wasm/fibonacci.wasm")?; - let loader = ZkWasmLoader::::new(18, wasm, vec![])?; + let loader = ZkWasmLoader::::new(18, wasm, vec![])?; - let (circuit, instances) = loader.circuit_with_witness(ExecutionArg { + let (circuit, instances, _) = loader.circuit_with_witness(ExecutionArg { public_inputs: vec![5], private_inputs: vec![], context_inputs: vec![], diff --git a/crates/playground/examples/phantom.rs b/crates/playground/examples/phantom.rs index 8e31069cb..a8f62be0c 100644 --- a/crates/playground/examples/phantom.rs +++ b/crates/playground/examples/phantom.rs @@ -2,20 +2,21 @@ use std::sync::Arc; use std::sync::Mutex; use anyhow::Result; -use delphinus_zkwasm::loader::ExecutionArg; use delphinus_zkwasm::loader::ZkWasmLoader; +use delphinus_zkwasm::runtime::host::default_env::DefaultHostEnvBuilder; +use delphinus_zkwasm::runtime::host::default_env::ExecutionArg; use pairing_bn256::bn256::Bn256; fn main() -> Result<()> { let wasm = std::fs::read("wasm/phantom.wasm")?; - let loader = ZkWasmLoader::::new( + let loader = ZkWasmLoader::::new( 18, wasm, - vec!["search"].into_iter().map(|s| s.to_owned()).collect(), + vec!["search".to_owned()], )?; - let (circuit, instances) = loader.circuit_with_witness(ExecutionArg { + let (circuit, instances, _) = loader.circuit_with_witness(ExecutionArg { public_inputs: vec![2], private_inputs: vec![], context_inputs: vec![], diff --git a/crates/specs/Cargo.toml b/crates/specs/Cargo.toml index 50da4e3ff..c0284b460 100644 --- a/crates/specs/Cargo.toml +++ b/crates/specs/Cargo.toml @@ -14,6 +14,7 @@ strum = "0.24.1" strum_macros = "0.24.1" halo2_proofs.workspace = true parity-wasm.workspace = true +hex = "0.4.3" [features] default = [] diff --git a/crates/specs/src/args.rs b/crates/specs/src/args.rs new file mode 100644 index 000000000..a84e66401 --- /dev/null +++ b/crates/specs/src/args.rs @@ -0,0 +1,51 @@ +pub fn parse_args(values: Vec<&str>) -> Vec { + values + .into_iter() + .map(|v| { + let [v, t] = v.split(":").collect::>()[..] else { todo!() }; + match t { + "i64" => { + if v.starts_with("0x") { + vec![ + u64::from_str_radix(String::from(v).trim_start_matches("0x"), 16) + .unwrap(), + ] + } else { + vec![v.parse::().unwrap()] + } + } + "bytes" => { + if !v.starts_with("0x") { + panic!("bytes input need start with 0x"); + } + let bytes = hex::decode(String::from(v).trim_start_matches("0x")).unwrap(); + bytes + .into_iter() + .map(|x| u64::from(x)) + .collect::>() + } + "bytes-packed" => { + if !v.starts_with("0x") { + panic!("bytes input need start with 0x"); + } + let bytes = hex::decode(String::from(v).trim_start_matches("0x")).unwrap(); + let bytes = bytes.chunks(8); + bytes + .into_iter() + .map(|x| { + let mut data = [0u8; 8]; + data[..x.len()].copy_from_slice(x); + + u64::from_le_bytes(data) + }) + .collect::>() + } + + _ => { + panic!("Unsupported input data type: {}", t) + } + } + }) + .flatten() + .collect() +} diff --git a/crates/specs/src/brtable.rs b/crates/specs/src/brtable.rs index c6c3b3211..4e6ce3c03 100644 --- a/crates/specs/src/brtable.rs +++ b/crates/specs/src/brtable.rs @@ -1,8 +1,9 @@ use std::collections::BTreeMap; +use serde::Deserialize; use serde::Serialize; -#[derive(Serialize, Debug, Clone)] +#[derive(Serialize, Deserialize, Debug, Clone)] pub struct BrTableEntry { pub fid: u32, pub iid: u32, @@ -25,7 +26,7 @@ impl BrTable { } } -#[derive(Serialize, Debug, Clone)] +#[derive(Serialize, Deserialize, Debug, Clone)] pub struct ElemEntry { pub table_idx: u32, pub type_idx: u32, @@ -33,7 +34,7 @@ pub struct ElemEntry { pub func_idx: u32, } -#[derive(Debug, Default, Serialize, Clone)] +#[derive(Debug, Default, Serialize, Deserialize, Clone)] pub struct ElemTable(BTreeMap<(u32, u32), ElemEntry>); impl ElemTable { diff --git a/crates/specs/src/configure_table.rs b/crates/specs/src/configure_table.rs index b2c664fd5..b2484fb18 100644 --- a/crates/specs/src/configure_table.rs +++ b/crates/specs/src/configure_table.rs @@ -1,3 +1,4 @@ +use serde::Deserialize; use serde::Serialize; // A wasm page size is 64KB @@ -5,7 +6,7 @@ pub const WASM_BYTES_PER_PAGE: u64 = 64 * 1024 as u64; const WASM_32_MAXIMAL_PAGES_DEFAULT: u32 = 65536; -#[derive(Serialize, Debug, Clone, Copy)] +#[derive(Serialize, Deserialize, Debug, Clone, Copy)] pub struct ConfigureTable { pub init_memory_pages: u32, pub maximal_memory_pages: u32, diff --git a/crates/specs/src/etable.rs b/crates/specs/src/etable.rs index dfa4ef695..ed24a93e9 100644 --- a/crates/specs/src/etable.rs +++ b/crates/specs/src/etable.rs @@ -1,10 +1,11 @@ +use serde::Deserialize; use serde::Serialize; use super::itable::InstructionTableEntry; use crate::host_function::HostPlugin; use crate::step::StepInfo; -#[derive(Clone, Debug, Serialize)] +#[derive(Clone, Debug, Serialize, Deserialize)] pub struct EventTableEntry { pub eid: u32, pub sp: u32, @@ -38,7 +39,7 @@ impl Iterator for RestJops { } } -#[derive(Debug, Default, Clone, Serialize)] +#[derive(Debug, Default, Clone, Serialize, Deserialize)] pub struct EventTable(Vec); impl EventTable { diff --git a/crates/specs/src/external_host_call_table/mod.rs b/crates/specs/src/external_host_call_table/mod.rs index a233e86dc..df425490a 100644 --- a/crates/specs/src/external_host_call_table/mod.rs +++ b/crates/specs/src/external_host_call_table/mod.rs @@ -1,4 +1,5 @@ use serde::ser::SerializeStruct; +use serde::Deserialize; use serde::Serialize; use crate::host_function::Signature; @@ -7,7 +8,7 @@ use crate::types::ValueType; pub mod encode; mod table; -#[derive(Copy, Clone, Debug, PartialEq, Eq, Serialize, PartialOrd, Ord)] +#[derive(Copy, Clone, Debug, PartialEq, Eq, Serialize, Deserialize, PartialOrd, Ord)] pub enum ExternalHostCallSignature { Argument, Return, diff --git a/crates/specs/src/host_function.rs b/crates/specs/src/host_function.rs index e5b0b8431..a3b740589 100644 --- a/crates/specs/src/host_function.rs +++ b/crates/specs/src/host_function.rs @@ -1,9 +1,10 @@ +use serde::Deserialize; use serde::Serialize; use crate::external_host_call_table::ExternalHostCallSignature; use crate::types::ValueType; -#[derive(Debug, Clone, PartialEq, Eq, Serialize)] +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub struct Signature { pub params: Vec, pub return_type: Option, @@ -38,7 +39,7 @@ impl HostFunctionDesc { } } -#[derive(Clone, Debug, Serialize, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)] +#[derive(Clone, Debug, Serialize, Deserialize, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)] pub enum HostPlugin { HostInput = 0, Context, diff --git a/crates/specs/src/imtable.rs b/crates/specs/src/imtable.rs index 8e7081279..5050c2b77 100644 --- a/crates/specs/src/imtable.rs +++ b/crates/specs/src/imtable.rs @@ -2,9 +2,10 @@ use std::cmp::Ordering; use crate::mtable::LocationType; use crate::mtable::VarType; +use serde::Deserialize; use serde::Serialize; -#[derive(Serialize, Debug, Clone)] +#[derive(Serialize, Deserialize, Debug, Clone)] pub struct InitMemoryTableEntry { pub ltype: LocationType, pub is_mutable: bool, @@ -15,7 +16,7 @@ pub struct InitMemoryTableEntry { pub value: u64, } -#[derive(Serialize, Default, Debug, Clone)] +#[derive(Serialize, Deserialize, Default, Debug, Clone)] pub struct InitMemoryTable { entries: Vec, sorted_global_init_entries: Vec, diff --git a/crates/specs/src/itable.rs b/crates/specs/src/itable.rs index 3e7cc9ec4..14ae6e48f 100644 --- a/crates/specs/src/itable.rs +++ b/crates/specs/src/itable.rs @@ -16,6 +16,7 @@ use crate::mtable::MemoryReadSize; use crate::mtable::MemoryStoreSize; use crate::types::ValueType; use num_bigint::BigUint; +use serde::Deserialize; use serde::Serialize; use std::collections::HashSet; use strum_macros::EnumIter; @@ -106,14 +107,14 @@ impl OpcodeClassPlain { } } -#[derive(Copy, Clone, Debug, Serialize, PartialEq, Eq, PartialOrd, Ord)] +#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)] pub enum UnaryOp { Ctz, Clz, Popcnt, } -#[derive(Copy, Clone, Debug, Serialize, PartialEq, Eq, PartialOrd, Ord)] +#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)] pub enum BinOp { Add, Sub, @@ -124,7 +125,7 @@ pub enum BinOp { SignedRem, } -#[derive(Copy, Clone, Debug, Serialize, PartialEq, Eq, PartialOrd, Ord)] +#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)] pub enum ShiftOp { Shl, UnsignedShr, @@ -133,7 +134,7 @@ pub enum ShiftOp { Rotr, } -#[derive(Copy, Clone, Debug, Serialize, EnumIter, PartialEq, Eq, PartialOrd, Ord)] +#[derive(Copy, Clone, Debug, Serialize, Deserialize, EnumIter, PartialEq, Eq, PartialOrd, Ord)] pub enum BitOp { And = 0, Or = 1, @@ -150,7 +151,7 @@ impl BitOp { } } -#[derive(Copy, Clone, Debug, Serialize, PartialEq, Eq, PartialOrd, Ord)] +#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)] pub enum RelOp { Eq, Ne, @@ -164,12 +165,12 @@ pub enum RelOp { UnsignedLe, } -#[derive(Copy, Clone, Debug, Serialize, EnumIter, PartialEq, Eq, PartialOrd, Ord)] +#[derive(Copy, Clone, Debug, Serialize, Deserialize, EnumIter, PartialEq, Eq, PartialOrd, Ord)] pub enum TestOp { Eqz, } -#[derive(Copy, Clone, Debug, Serialize, PartialEq, Eq, PartialOrd, Ord)] +#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)] pub enum ConversionOp { I32WrapI64, I64ExtendI32s, @@ -181,14 +182,14 @@ pub enum ConversionOp { I64Extend32S, } -#[derive(Clone, Debug, Serialize, PartialEq, Eq, PartialOrd, Ord)] +#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)] pub struct BrTarget { pub drop: u32, pub keep: Vec, pub dst_pc: u32, } -#[derive(Clone, Debug, Serialize, PartialEq, Eq, PartialOrd, Ord)] +#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)] pub enum Opcode { LocalGet { vtype: VarType, @@ -585,7 +586,7 @@ impl Into for Opcode { } } -#[derive(Clone, Debug, Serialize)] +#[derive(Clone, Debug, Serialize, Deserialize)] pub struct InstructionTableEntry { pub fid: u32, pub iid: u32, @@ -605,7 +606,7 @@ impl InstructionTableEntry { bn } } -#[derive(Default, Serialize, Debug, Clone)] +#[derive(Default, Serialize, Deserialize, Debug, Clone)] pub struct InstructionTable(Vec); impl InstructionTable { diff --git a/crates/specs/src/jtable.rs b/crates/specs/src/jtable.rs index f9c9179d7..c3f1a07ae 100644 --- a/crates/specs/src/jtable.rs +++ b/crates/specs/src/jtable.rs @@ -1,7 +1,8 @@ use super::itable::InstructionTableEntry; +use serde::Deserialize; use serde::Serialize; -#[derive(Default, Serialize, Debug, Clone)] +#[derive(Default, Serialize, Deserialize, Debug, Clone)] pub struct StaticFrameEntry { pub enable: bool, pub frame_id: u32, @@ -11,7 +12,7 @@ pub struct StaticFrameEntry { pub iid: u32, } -#[derive(Debug, Serialize, Clone)] +#[derive(Debug, Serialize, Deserialize, Clone)] pub struct JumpTableEntry { // caller eid (unique) pub eid: u32, @@ -26,7 +27,7 @@ impl JumpTableEntry { } } -#[derive(Clone, Debug, Default, Serialize)] +#[derive(Clone, Debug, Default, Serialize, Deserialize)] pub struct JumpTable(Vec); impl JumpTable { diff --git a/crates/specs/src/lib.rs b/crates/specs/src/lib.rs index ccb0062b1..3add81166 100644 --- a/crates/specs/src/lib.rs +++ b/crates/specs/src/lib.rs @@ -14,11 +14,13 @@ use itable::InstructionTable; use jtable::JumpTable; use jtable::StaticFrameEntry; use mtable::MTable; +use serde::Deserialize; use serde::Serialize; #[macro_use] extern crate lazy_static; +pub mod args; pub mod brtable; pub mod configure_table; pub mod encode; @@ -32,7 +34,7 @@ pub mod mtable; pub mod step; pub mod types; -#[derive(Default, Serialize, Debug, Clone)] +#[derive(Default, Serialize, Deserialize, Debug, Clone)] pub struct CompilationTable { pub itable: InstructionTable, pub imtable: InitMemoryTable, @@ -42,7 +44,7 @@ pub struct CompilationTable { pub fid_of_entry: u32, } -#[derive(Default, Serialize, Clone)] +#[derive(Default, Serialize, Deserialize, Clone)] pub struct ExecutionTable { pub etable: EventTable, pub mtable: MTable, diff --git a/crates/specs/src/mtable.rs b/crates/specs/src/mtable.rs index f3ac165ef..eaf84bf39 100644 --- a/crates/specs/src/mtable.rs +++ b/crates/specs/src/mtable.rs @@ -1,18 +1,19 @@ use std::collections::HashSet; +use serde::Deserialize; use serde::Serialize; use strum_macros::EnumIter; use crate::imtable::InitMemoryTable; -#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Serialize, Hash)] +#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize, Hash)] pub enum LocationType { Stack = 1, Heap = 2, Global = 3, } -#[derive(Clone, Copy, Debug, PartialEq, Serialize, Hash, Eq)] +#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize, Hash, Eq)] pub enum AccessType { Read = 1, Write = 2, @@ -25,7 +26,9 @@ impl AccessType { } } -#[derive(Clone, Copy, Debug, PartialEq, Eq, EnumIter, Serialize, Hash, PartialOrd, Ord)] +#[derive( + Clone, Copy, Debug, PartialEq, Eq, EnumIter, Serialize, Deserialize, Hash, PartialOrd, Ord, +)] pub enum VarType { I64 = 0, I32 = 1, @@ -40,7 +43,9 @@ impl VarType { } } -#[derive(Clone, Copy, Debug, PartialEq, EnumIter, Serialize, Hash, Eq, PartialOrd, Ord)] +#[derive( + Clone, Copy, Debug, PartialEq, EnumIter, Serialize, Deserialize, Hash, Eq, PartialOrd, Ord, +)] pub enum MemoryReadSize { U8 = 1, S8, @@ -51,7 +56,9 @@ pub enum MemoryReadSize { I64, } -#[derive(Clone, Copy, Debug, PartialEq, EnumIter, Serialize, Hash, Eq, PartialOrd, Ord)] +#[derive( + Clone, Copy, Debug, PartialEq, EnumIter, Serialize, Deserialize, Hash, Eq, PartialOrd, Ord, +)] pub enum MemoryStoreSize { Byte8 = 1, Byte16, @@ -113,7 +120,7 @@ impl MemoryReadSize { } } -#[derive(Clone, Debug, Serialize, Hash, Eq, PartialEq)] +#[derive(Clone, Debug, Serialize, Deserialize, Hash, Eq, PartialEq)] pub struct MemoryTableEntry { pub eid: u32, /* @@ -141,7 +148,7 @@ impl MemoryTableEntry { } } -#[derive(Default, Debug, Serialize, Clone)] +#[derive(Default, Debug, Serialize, Deserialize, Clone)] pub struct MTable(Vec); impl MTable { diff --git a/crates/specs/src/step.rs b/crates/specs/src/step.rs index d27f1f4e4..4b4889a8f 100644 --- a/crates/specs/src/step.rs +++ b/crates/specs/src/step.rs @@ -10,9 +10,10 @@ use crate::mtable::MemoryReadSize; use crate::mtable::MemoryStoreSize; use crate::mtable::VarType; use crate::types::ValueType; +use serde::Deserialize; use serde::Serialize; -#[derive(Debug, Clone, Serialize)] +#[derive(Debug, Clone, Serialize, Deserialize)] pub enum StepInfo { Br { dst_pc: u32, diff --git a/crates/specs/src/types.rs b/crates/specs/src/types.rs index 826663824..f7d3427c8 100644 --- a/crates/specs/src/types.rs +++ b/crates/specs/src/types.rs @@ -1,10 +1,11 @@ +use serde::Deserialize; use serde::Serialize; use crate::external_host_call_table::ExternalHostCallSignature; use crate::host_function::HostPlugin; use crate::mtable::VarType; -#[derive(Clone, Copy, Debug, Serialize, PartialEq, Eq, PartialOrd, Ord)] +#[derive(Clone, Copy, Debug, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)] pub enum ValueType { I32, I64, diff --git a/crates/zkwasm/Cargo.lock b/crates/zkwasm/Cargo.lock deleted file mode 100644 index bcdb69eec..000000000 --- a/crates/zkwasm/Cargo.lock +++ /dev/null @@ -1,2157 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "aho-corasick" -version = "0.7.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc936419f96fa211c1b9166887b38e5e40b19958e5b895be7c1f93adec7071ac" -dependencies = [ - "memchr", -] - -[[package]] -name = "android_system_properties" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" -dependencies = [ - "libc", -] - -[[package]] -name = "anyhow" -version = "1.0.68" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2cb2f989d18dd141ab8ae82f64d1a8cdd37e0840f73a406896cf5e99502fab61" - -[[package]] -name = "ark-std" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1df2c09229cbc5a028b1d70e00fdb2acee28b1055dfb5ca73eea49c5a25c4e7c" -dependencies = [ - "colored", - "num-traits", - "rand", -] - -[[package]] -name = "arrayref" -version = "0.3.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4c527152e37cf757a3f78aae5a06fbeefdb07ccc535c980a3208ee3060dd544" - -[[package]] -name = "arrayvec" -version = "0.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8da52d66c7071e2e3fa2a1e5c6d088fec47b593032b254f5e980de8ea54454d6" - -[[package]] -name = "atty" -version = "0.2.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" -dependencies = [ - "hermit-abi 0.1.19", - "libc", - "winapi 0.3.9", -] - -[[package]] -name = "autocfg" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" - -[[package]] -name = "bitflags" -version = "1.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" - -[[package]] -name = "bitvec" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bc2832c24239b0141d5674bb9174f9d68a8b5b3f2753311927c172ca46f7e9c" -dependencies = [ - "funty", - "radium", - "tap", - "wyz", -] - -[[package]] -name = "blake2b_simd" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72936ee4afc7f8f736d1c38383b56480b5497b4617b4a77bdbf1d2ababc76127" -dependencies = [ - "arrayref", - "arrayvec", - "constant_time_eq", -] - -[[package]] -name = "block-buffer" -version = "0.10.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "69cce20737498f97b993470a6e536b8523f0af7892a4f928cceb1ac5e52ebe7e" -dependencies = [ - "generic-array", -] - -[[package]] -name = "bls12_381" -version = "0.7.0" -source = "git+https://github.com/lanbones/bls12_381.git#31fcd53a340cadbb5558bb75422516b81704a0a1" -dependencies = [ - "ff", - "group", - "pairing", - "rand_core", - "subtle", -] - -[[package]] -name = "bstr" -version = "0.2.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba3569f383e8f1598449f1a423e72e99569137b47740b1da11ef19af3d5c3223" -dependencies = [ - "memchr", -] - -[[package]] -name = "bumpalo" -version = "3.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f1e260c3a9040a7c19a12468758f4c16f31a81a1fe087482be9570ec864bb6c" - -[[package]] -name = "cc" -version = "1.0.78" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a20104e2335ce8a659d6dd92a51a767a0c062599c73b343fd152cb401e828c3d" - -[[package]] -name = "cfg-if" -version = "0.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" - -[[package]] -name = "cfg-if" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" - -[[package]] -name = "chrono" -version = "0.4.23" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "16b0a3d9ed01224b22057780a37bb8c5dbfe1be8ba48678e7bf57ec4b385411f" -dependencies = [ - "iana-time-zone", - "num-integer", - "num-traits", - "winapi 0.3.9", -] - -[[package]] -name = "chrono-tz" -version = "0.6.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "29c39203181991a7dd4343b8005bd804e7a9a37afb8ac070e43771e8c820bbde" -dependencies = [ - "chrono", - "chrono-tz-build", - "phf", -] - -[[package]] -name = "chrono-tz-build" -version = "0.0.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f509c3a87b33437b05e2458750a0700e5bdd6956176773e6c7d6dd15a283a0c" -dependencies = [ - "parse-zoneinfo", - "phf", - "phf_codegen", -] - -[[package]] -name = "clap" -version = "3.2.23" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "71655c45cb9845d3270c9d6df84ebe72b4dad3c2ba3f7023ad47c144e4e473a5" -dependencies = [ - "atty", - "bitflags", - "clap_derive", - "clap_lex", - "indexmap", - "once_cell", - "strsim", - "termcolor", - "textwrap", -] - -[[package]] -name = "clap_derive" -version = "3.2.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea0c8bce528c4be4da13ea6fead8965e95b6073585a2f05204bd8f4119f82a65" -dependencies = [ - "heck", - "proc-macro-error", - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "clap_lex" -version = "0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2850f2f5a82cbf437dd5af4d49848fbdfc27c157c3d010345776f952765261c5" -dependencies = [ - "os_str_bytes", -] - -[[package]] -name = "cmake" -version = "0.1.49" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db34956e100b30725f2eb215f90d4871051239535632f84fea3bc92722c66b7c" -dependencies = [ - "cc", -] - -[[package]] -name = "codespan-reporting" -version = "0.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3538270d33cc669650c4b093848450d380def10c331d38c768e34cac80576e6e" -dependencies = [ - "termcolor", - "unicode-width", -] - -[[package]] -name = "colored" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b3616f750b84d8f0de8a58bda93e08e2a81ad3f523089b05f1dffecab48c6cbd" -dependencies = [ - "atty", - "lazy_static", - "winapi 0.3.9", -] - -[[package]] -name = "constant_time_eq" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "245097e9a4535ee1e3e3931fcfcd55a796a44c643e8596ff6566d68f09b87bbc" - -[[package]] -name = "core-foundation-sys" -version = "0.8.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5827cebf4670468b8772dd191856768aedcb1b0278a04f989f7766351917b9dc" - -[[package]] -name = "core_affinity" -version = "0.5.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f8a03115cc34fb0d7c321dd154a3914b3ca082ccc5c11d91bf7117dbbe7171f" -dependencies = [ - "kernel32-sys", - "libc", - "num_cpus", - "winapi 0.2.8", -] - -[[package]] -name = "cpufeatures" -version = "0.2.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28d997bd5e24a5928dd43e46dc529867e207907fe0b239c3477d924f7f2ca320" -dependencies = [ - "libc", -] - -[[package]] -name = "crossbeam-channel" -version = "0.5.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2dd04ddaf88237dc3b8d8f9a3c1004b506b54b3313403944054d23c0870c521" -dependencies = [ - "cfg-if 1.0.0", - "crossbeam-utils", -] - -[[package]] -name = "crossbeam-deque" -version = "0.8.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "715e8152b692bba2d374b53d4875445368fdf21a94751410af607a5ac677d1fc" -dependencies = [ - "cfg-if 1.0.0", - "crossbeam-epoch", - "crossbeam-utils", -] - -[[package]] -name = "crossbeam-epoch" -version = "0.9.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01a9af1f4c2ef74bb8aa1f7e19706bc72d03598c8a570bb5de72243c7a9d9d5a" -dependencies = [ - "autocfg", - "cfg-if 1.0.0", - "crossbeam-utils", - "memoffset", - "scopeguard", -] - -[[package]] -name = "crossbeam-utils" -version = "0.8.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fb766fa798726286dbbb842f174001dab8abc7b627a1dd86e0b7222a95d929f" -dependencies = [ - "cfg-if 1.0.0", -] - -[[package]] -name = "crypto-common" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" -dependencies = [ - "generic-array", - "typenum", -] - -[[package]] -name = "cuda-config" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ee74643f7430213a1a78320f88649de309b20b80818325575e393f848f79f5d" -dependencies = [ - "glob 0.3.0", -] - -[[package]] -name = "cuda-driver-sys" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d4c552cc0de854877d80bcd1f11db75d42be32962d72a6799b88dcca88fffbd" -dependencies = [ - "cuda-config", -] - -[[package]] -name = "cxx" -version = "1.0.85" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5add3fc1717409d029b20c5b6903fc0c0b02fa6741d820054f4a2efa5e5816fd" -dependencies = [ - "cc", - "cxxbridge-flags", - "cxxbridge-macro", - "link-cplusplus", -] - -[[package]] -name = "cxx-build" -version = "1.0.85" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4c87959ba14bc6fbc61df77c3fcfe180fc32b93538c4f1031dd802ccb5f2ff0" -dependencies = [ - "cc", - "codespan-reporting", - "once_cell", - "proc-macro2", - "quote", - "scratch", - "syn", -] - -[[package]] -name = "cxxbridge-flags" -version = "1.0.85" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "69a3e162fde4e594ed2b07d0f83c6c67b745e7f28ce58c6df5e6b6bef99dfb59" - -[[package]] -name = "cxxbridge-macro" -version = "1.0.85" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3e7e2adeb6a0d4a282e581096b06e1791532b7d576dcde5ccd9382acf55db8e6" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "delphinus-zkwasm" -version = "0.1.0" -dependencies = [ - "anyhow", - "ark-std", - "bitvec", - "clap", - "downcast-rs", - "env_logger", - "halo2_proofs", - "halo2aggregator-s", - "hex", - "lazy_static", - "log", - "md5", - "notify", - "num-bigint", - "num-integer", - "num-traits", - "parity-wasm", - "rand", - "rusty-fork", - "serde", - "serde_json", - "sha2", - "specs", - "strum", - "strum_macros", - "uuid", - "wabt", - "wasmi", - "wast", -] - -[[package]] -name = "deunicode" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "850878694b7933ca4c9569d30a34b55031b9b139ee1fc7b94a527c4ef960d690" - -[[package]] -name = "digest" -version = "0.10.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8168378f4e5023e7218c89c891c0fd8ecdb5e5e4f18cb78f38cf245dd021e76f" -dependencies = [ - "block-buffer", - "crypto-common", -] - -[[package]] -name = "dirs" -version = "4.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca3aa72a6f96ea37bbc5aa912f6788242832f75369bdfdadcb0e38423f100059" -dependencies = [ - "dirs-sys", -] - -[[package]] -name = "dirs-sys" -version = "0.3.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b1d1d91c932ef41c0f2663aa8b0ca0342d444d842c06914aa0a7e352d0bada6" -dependencies = [ - "libc", - "redox_users", - "winapi 0.3.9", -] - -[[package]] -name = "downcast-rs" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ea835d29036a4087793836fa931b08837ad5e957da9e23886b29586fb9b6650" - -[[package]] -name = "ec-gpu" -version = "0.2.0" -source = "git+https://github.com/lanbones/ec-gpu#165d1dd6215f6fd1dd85c83cf430ff511a03a00a" - -[[package]] -name = "ec-gpu-gen" -version = "0.4.0" -source = "git+https://github.com/lanbones/ec-gpu#165d1dd6215f6fd1dd85c83cf430ff511a03a00a" -dependencies = [ - "ark-std", - "bitvec", - "crossbeam-channel", - "ec-gpu", - "execute", - "ff", - "group", - "hex", - "log", - "num_cpus", - "once_cell", - "rayon", - "rust-gpu-tools", - "sha2", - "thiserror", - "yastl", -] - -[[package]] -name = "either" -version = "1.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90e5c1c8368803113bf0c9584fc495a58b86dc8a29edbf8fe877d21d9507e797" - -[[package]] -name = "env_logger" -version = "0.9.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a12e6657c4c97ebab115a42dcee77225f7f482cdd841cf7088c657a42e9e00e7" -dependencies = [ - "atty", - "humantime", - "log", - "regex", - "termcolor", -] - -[[package]] -name = "execute" -version = "0.2.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "313431b1c5e3a6ec9b864333defee57d2ddb50de77abab419e4baedb6cdff292" -dependencies = [ - "execute-command-macro", - "execute-command-tokens", - "generic-array", -] - -[[package]] -name = "execute-command-macro" -version = "0.1.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a5fbc65a0cf735106743f4c38c9a3671c1e734b5c2c20d21a3c93c696daa3157" -dependencies = [ - "execute-command-macro-impl", -] - -[[package]] -name = "execute-command-macro-impl" -version = "0.1.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5109f6bc9cd57feda665da326f3f6c57e0498c8fe9f7d12d7b8abc96719ca91b" -dependencies = [ - "execute-command-tokens", - "quote", - "syn", -] - -[[package]] -name = "execute-command-tokens" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ba569491c70ec8471e34aa7e9c0b9e82bb5d2464c0398442d17d3c4af814e5a" - -[[package]] -name = "fastrand" -version = "1.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a7a407cfaa3385c4ae6b23e84623d48c2798d06e3e6a1878f7f59f17b3f86499" -dependencies = [ - "instant", -] - -[[package]] -name = "ff" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d013fc25338cc558c5c2cfbad646908fb23591e2404481826742b651c9af7160" -dependencies = [ - "bitvec", - "rand_core", - "subtle", -] - -[[package]] -name = "fil-rustacuda" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6313e2871ba9705f4151bb60d96b6f43e7444ed82918ba5fb99fbd448e82c34d" -dependencies = [ - "bitflags", - "cuda-driver-sys", - "rustacuda_core", - "rustacuda_derive", -] - -[[package]] -name = "filetime" -version = "0.2.21" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5cbc844cecaee9d4443931972e1289c8ff485cb4cc2767cb03ca139ed6885153" -dependencies = [ - "cfg-if 1.0.0", - "libc", - "redox_syscall", - "windows-sys 0.48.0", -] - -[[package]] -name = "flume" -version = "0.10.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1657b4441c3403d9f7b3409e47575237dac27b1b5726df654a6ecbf92f0f7577" -dependencies = [ - "spin", -] - -[[package]] -name = "fnv" -version = "1.0.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" - -[[package]] -name = "fsevent-sys" -version = "4.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "76ee7a02da4d231650c7cea31349b889be2f45ddb3ef3032d2ec8185f6313fd2" -dependencies = [ - "libc", -] - -[[package]] -name = "funty" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" - -[[package]] -name = "generic-array" -version = "0.14.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bff49e947297f3312447abdca79f45f4738097cc82b06e72054d2223f601f1b9" -dependencies = [ - "typenum", - "version_check", -] - -[[package]] -name = "getrandom" -version = "0.2.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c05aeb6a22b8f62540c194aac980f2115af067bfe15a0734d7277a768d396b31" -dependencies = [ - "cfg-if 1.0.0", - "libc", - "wasi", -] - -[[package]] -name = "glob" -version = "0.2.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8be18de09a56b60ed0edf84bc9df007e30040691af7acd1c41874faac5895bfb" - -[[package]] -name = "glob" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574" - -[[package]] -name = "globset" -version = "0.4.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a1e17342619edbc21a964c2afbeb6c820c6a2560032872f397bb97ea127bd0a" -dependencies = [ - "aho-corasick", - "bstr", - "fnv", - "log", - "regex", -] - -[[package]] -name = "globwalk" -version = "0.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93e3af942408868f6934a7b85134a3230832b9977cf66125df2f9edcfce4ddcc" -dependencies = [ - "bitflags", - "ignore", - "walkdir", -] - -[[package]] -name = "group" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5dfbfb3a6cfbd390d5c9564ab283a0349b9b9fcd46a706c1eb10e0db70bfbac7" -dependencies = [ - "ff", - "rand_core", - "subtle", -] - -[[package]] -name = "halo2_proofs" -version = "0.1.0-beta.1" -source = "git+https://github.com/junyu0312/halo2?branch=gpu#d641021e6813de5314469862c6c4be08d4a639fd" -dependencies = [ - "ark-std", - "blake2b_simd", - "bumpalo", - "cfg-if 0.1.10", - "core_affinity", - "cuda-driver-sys", - "ec-gpu-gen", - "ff", - "group", - "num-bigint", - "num-integer", - "pairing_bn256", - "rand", - "rand_core", - "rayon", - "subtle", -] - -[[package]] -name = "halo2aggregator-s" -version = "0.1.0" -source = "git+https://github.com/DelphinusLab/halo2aggregator-s.git?tag=bisect-lookup-0.3.2#fa32d533b617f332728dcaee0f9ecbf54e972ec4" -dependencies = [ - "ark-std", - "blake2b_simd", - "halo2_proofs", - "halo2ecc-s", - "lazy_static", - "num-bigint", - "num-integer", - "poseidon", - "sha2", - "tera", -] - -[[package]] -name = "halo2ecc-s" -version = "0.3.2" -source = "git+https://github.com/lanbones/halo2ecc-s.git?tag=bisect-lookup-0.3.2#35fa5cf45810aeabdafc388d1520a01ef5244f50" -dependencies = [ - "halo2_proofs", - "num-bigint", - "num-integer", - "rayon", -] - -[[package]] -name = "hashbrown" -version = "0.12.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" - -[[package]] -name = "heck" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2540771e65fc8cb83cd6e8a237f70c319bd5c29f78ed1084ba5d50eeac86f7f9" - -[[package]] -name = "hermit-abi" -version = "0.1.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" -dependencies = [ - "libc", -] - -[[package]] -name = "hermit-abi" -version = "0.2.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee512640fe35acbfb4bb779db6f0d80704c2cacfa2e39b601ef3e3f47d1ae4c7" -dependencies = [ - "libc", -] - -[[package]] -name = "hex" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" - -[[package]] -name = "humansize" -version = "1.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02296996cb8796d7c6e3bc2d9211b7802812d36999a51bb754123ead7d37d026" - -[[package]] -name = "humantime" -version = "2.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" - -[[package]] -name = "iana-time-zone" -version = "0.1.53" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "64c122667b287044802d6ce17ee2ddf13207ed924c712de9a66a5814d5b64765" -dependencies = [ - "android_system_properties", - "core-foundation-sys", - "iana-time-zone-haiku", - "js-sys", - "wasm-bindgen", - "winapi 0.3.9", -] - -[[package]] -name = "iana-time-zone-haiku" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0703ae284fc167426161c2e3f1da3ea71d94b21bedbcc9494e92b28e334e3dca" -dependencies = [ - "cxx", - "cxx-build", -] - -[[package]] -name = "ignore" -version = "0.4.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "713f1b139373f96a2e0ce3ac931cd01ee973c3c5dd7c40c0c2efe96ad2b6751d" -dependencies = [ - "crossbeam-utils", - "globset", - "lazy_static", - "log", - "memchr", - "regex", - "same-file", - "thread_local", - "walkdir", - "winapi-util", -] - -[[package]] -name = "indexmap" -version = "1.9.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1885e79c1fc4b10f0e172c475f458b7f7b93061064d98c3293e98c5ba0c8b399" -dependencies = [ - "autocfg", - "hashbrown", -] - -[[package]] -name = "inotify" -version = "0.9.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8069d3ec154eb856955c1c0fbffefbf5f3c40a104ec912d4797314c1801abff" -dependencies = [ - "bitflags", - "inotify-sys", - "libc", -] - -[[package]] -name = "inotify-sys" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e05c02b5e89bff3b946cedeca278abc628fe811e604f027c45a8aa3cf793d0eb" -dependencies = [ - "libc", -] - -[[package]] -name = "instant" -version = "0.1.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c" -dependencies = [ - "cfg-if 1.0.0", -] - -[[package]] -name = "itoa" -version = "1.0.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fad582f4b9e86b6caa621cabeb0963332d92eea04729ab12892c2533951e6440" - -[[package]] -name = "js-sys" -version = "0.3.60" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49409df3e3bf0856b916e2ceaca09ee28e6871cf7d9ce97a692cacfdb2a25a47" -dependencies = [ - "wasm-bindgen", -] - -[[package]] -name = "kernel32-sys" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" -dependencies = [ - "winapi 0.2.8", - "winapi-build", -] - -[[package]] -name = "kqueue" -version = "1.0.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c8fc60ba15bf51257aa9807a48a61013db043fcf3a78cb0d916e8e396dcad98" -dependencies = [ - "kqueue-sys", - "libc", -] - -[[package]] -name = "kqueue-sys" -version = "1.0.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8367585489f01bc55dd27404dcf56b95e6da061a256a666ab23be9ba96a2e587" -dependencies = [ - "bitflags", - "libc", -] - -[[package]] -name = "lazy_static" -version = "1.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" - -[[package]] -name = "leb128" -version = "0.2.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "884e2677b40cc8c339eaefcb701c32ef1fd2493d71118dc0ca4b6a736c93bd67" - -[[package]] -name = "libc" -version = "0.2.139" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79" - -[[package]] -name = "libm" -version = "0.2.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "348108ab3fba42ec82ff6e9564fc4ca0247bdccdc68dd8af9764bbc79c3c8ffb" - -[[package]] -name = "link-cplusplus" -version = "1.0.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ecd207c9c713c34f95a097a5b029ac2ce6010530c7b49d7fea24d977dede04f5" -dependencies = [ - "cc", -] - -[[package]] -name = "lock_api" -version = "0.4.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "435011366fe56583b16cf956f9df0095b405b82d76425bc8981c0e22e60ec4df" -dependencies = [ - "autocfg", - "scopeguard", -] - -[[package]] -name = "log" -version = "0.4.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e" -dependencies = [ - "cfg-if 1.0.0", -] - -[[package]] -name = "md5" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "490cc448043f947bae3cbee9c203358d62dbee0db12107a74be5c30ccfd09771" - -[[package]] -name = "memchr" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" - -[[package]] -name = "memoffset" -version = "0.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5de893c32cde5f383baa4c04c5d6dbdd735cfd4a794b0debdb2bb1b421da5ff4" -dependencies = [ - "autocfg", -] - -[[package]] -name = "memory_units" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8452105ba047068f40ff7093dd1d9da90898e63dd61736462e9cdda6a90ad3c3" - -[[package]] -name = "mio" -version = "0.8.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "927a765cd3fc26206e66b296465fa9d3e5ab003e651c1b3c060e7956d96b19d2" -dependencies = [ - "libc", - "log", - "wasi", - "windows-sys 0.48.0", -] - -[[package]] -name = "notify" -version = "6.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5738a2795d57ea20abec2d6d76c6081186709c0024187cd5977265eda6598b51" -dependencies = [ - "bitflags", - "crossbeam-channel", - "filetime", - "fsevent-sys", - "inotify", - "kqueue", - "libc", - "mio", - "walkdir", - "windows-sys 0.45.0", -] - -[[package]] -name = "num-bigint" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f93ab6289c7b344a8a9f60f88d80aa20032336fe78da341afc91c8a2341fc75f" -dependencies = [ - "autocfg", - "num-integer", - "num-traits", - "rand", -] - -[[package]] -name = "num-integer" -version = "0.1.45" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "225d3389fb3509a24c93f5c29eb6bde2586b98d9f016636dff58d7c6f7569cd9" -dependencies = [ - "autocfg", - "num-traits", -] - -[[package]] -name = "num-rational" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0638a1c9d0a3c0914158145bc76cff373a75a627e6ecbfb71cbe6f453a5a19b0" -dependencies = [ - "autocfg", - "num-bigint", - "num-integer", - "num-traits", -] - -[[package]] -name = "num-traits" -version = "0.2.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd" -dependencies = [ - "autocfg", -] - -[[package]] -name = "num_cpus" -version = "1.15.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fac9e2da13b5eb447a6ce3d392f23a29d8694bff781bf03a16cd9ac8697593b" -dependencies = [ - "hermit-abi 0.2.6", - "libc", -] - -[[package]] -name = "once_cell" -version = "1.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86f0b0d4bf799edbc74508c1e8bf170ff5f41238e5f8225603ca7caaae2b7860" - -[[package]] -name = "os_str_bytes" -version = "6.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b7820b9daea5457c9f21c69448905d723fbd21136ccf521748f23fd49e723ee" - -[[package]] -name = "pairing" -version = "0.22.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "135590d8bdba2b31346f9cd1fb2a912329f5135e832a4f422942eb6ead8b6b3b" -dependencies = [ - "group", -] - -[[package]] -name = "pairing_bn256" -version = "0.1.1" -source = "git+https://github.com/lanbones/pairing#5ab08062f53cd29c946f96572aefdb688952d725" -dependencies = [ - "bls12_381", - "ec-gpu", - "ff", - "group", - "rand", - "rand_core", - "static_assertions", - "subtle", -] - -[[package]] -name = "parity-wasm" -version = "0.42.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be5e13c266502aadf83426d87d81a0f5d1ef45b8027f5a471c360abfe4bfae92" - -[[package]] -name = "parse-zoneinfo" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c705f256449c60da65e11ff6626e0c16a0a0b96aaa348de61376b249bc340f41" -dependencies = [ - "regex", -] - -[[package]] -name = "percent-encoding" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "478c572c3d73181ff3c2539045f6eb99e5491218eae919370993b890cdbdd98e" - -[[package]] -name = "pest" -version = "2.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f6e86fb9e7026527a0d46bc308b841d73170ef8f443e1807f6ef88526a816d4" -dependencies = [ - "thiserror", - "ucd-trie", -] - -[[package]] -name = "pest_derive" -version = "2.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96504449aa860c8dcde14f9fba5c58dc6658688ca1fe363589d6327b8662c603" -dependencies = [ - "pest", - "pest_generator", -] - -[[package]] -name = "pest_generator" -version = "2.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "798e0220d1111ae63d66cb66a5dcb3fc2d986d520b98e49e1852bfdb11d7c5e7" -dependencies = [ - "pest", - "pest_meta", - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "pest_meta" -version = "2.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "984298b75898e30a843e278a9f2452c31e349a073a0ce6fd950a12a74464e065" -dependencies = [ - "once_cell", - "pest", - "sha1", -] - -[[package]] -name = "phf" -version = "0.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "928c6535de93548188ef63bb7c4036bd415cd8f36ad25af44b9789b2ee72a48c" -dependencies = [ - "phf_shared", -] - -[[package]] -name = "phf_codegen" -version = "0.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a56ac890c5e3ca598bbdeaa99964edb5b0258a583a9eb6ef4e89fc85d9224770" -dependencies = [ - "phf_generator", - "phf_shared", -] - -[[package]] -name = "phf_generator" -version = "0.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1181c94580fa345f50f19d738aaa39c0ed30a600d95cb2d3e23f94266f14fbf" -dependencies = [ - "phf_shared", - "rand", -] - -[[package]] -name = "phf_shared" -version = "0.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e1fb5f6f826b772a8d4c0394209441e7d37cbbb967ae9c7e0e8134365c9ee676" -dependencies = [ - "siphasher", - "uncased", -] - -[[package]] -name = "poseidon" -version = "0.2.0" -source = "git+https://github.com/lanbones/poseidon#20d881c2125199749055f305d73d514084b65e02" -dependencies = [ - "halo2_proofs", - "subtle", -] - -[[package]] -name = "ppv-lite86" -version = "0.2.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" - -[[package]] -name = "proc-macro-error" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" -dependencies = [ - "proc-macro-error-attr", - "proc-macro2", - "quote", - "syn", - "version_check", -] - -[[package]] -name = "proc-macro-error-attr" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" -dependencies = [ - "proc-macro2", - "quote", - "version_check", -] - -[[package]] -name = "proc-macro2" -version = "1.0.49" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "57a8eca9f9c4ffde41714334dee777596264c7825420f521abc92b5b5deb63a5" -dependencies = [ - "unicode-ident", -] - -[[package]] -name = "quick-error" -version = "1.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" - -[[package]] -name = "quote" -version = "1.0.23" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8856d8364d252a14d474036ea1358d63c9e6965c8e5c1885c18f73d70bff9c7b" -dependencies = [ - "proc-macro2", -] - -[[package]] -name = "radium" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" - -[[package]] -name = "rand" -version = "0.8.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" -dependencies = [ - "libc", - "rand_chacha", - "rand_core", -] - -[[package]] -name = "rand_chacha" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" -dependencies = [ - "ppv-lite86", - "rand_core", -] - -[[package]] -name = "rand_core" -version = "0.6.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" -dependencies = [ - "getrandom", -] - -[[package]] -name = "rayon" -version = "1.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6db3a213adf02b3bcfd2d3846bb41cb22857d131789e01df434fb7e7bc0759b7" -dependencies = [ - "either", - "rayon-core", -] - -[[package]] -name = "rayon-core" -version = "1.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cac410af5d00ab6884528b4ab69d1e8e146e8d471201800fa1b4524126de6ad3" -dependencies = [ - "crossbeam-channel", - "crossbeam-deque", - "crossbeam-utils", - "num_cpus", -] - -[[package]] -name = "redox_syscall" -version = "0.2.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a" -dependencies = [ - "bitflags", -] - -[[package]] -name = "redox_users" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b033d837a7cf162d7993aded9304e30a83213c648b6e389db233191f891e5c2b" -dependencies = [ - "getrandom", - "redox_syscall", - "thiserror", -] - -[[package]] -name = "regex" -version = "1.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e076559ef8e241f2ae3479e36f97bd5741c0330689e217ad51ce2c76808b868a" -dependencies = [ - "aho-corasick", - "memchr", - "regex-syntax", -] - -[[package]] -name = "regex-syntax" -version = "0.6.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "456c603be3e8d448b072f410900c09faf164fbce2d480456f50eea6e25f9c848" - -[[package]] -name = "remove_dir_all" -version = "0.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7" -dependencies = [ - "winapi 0.3.9", -] - -[[package]] -name = "rust-gpu-tools" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b2838e99bd4c9b3e6a963194440c6c5b66721d3f127625d709236ecaa1a730f" -dependencies = [ - "dirs", - "fil-rustacuda", - "hex", - "lazy_static", - "log", - "once_cell", - "sha2", - "temp-env", - "thiserror", -] - -[[package]] -name = "rustacuda_core" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3858b08976dc2f860c5efbbb48cdcb0d4fafca92a6ac0898465af16c0dbe848" - -[[package]] -name = "rustacuda_derive" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43ce8670a1a1d0fc2514a3b846dacdb65646f9bd494b6674cfacbb4ce430bd7e" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "rustversion" -version = "1.0.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5583e89e108996506031660fe09baa5011b9dd0341b89029313006d1fb508d70" - -[[package]] -name = "rusty-fork" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb3dcc6e454c328bb824492db107ab7c0ae8fcffe4ad210136ef014458c1bc4f" -dependencies = [ - "fnv", - "quick-error", - "tempfile", - "wait-timeout", -] - -[[package]] -name = "ryu" -version = "1.0.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b4b9743ed687d4b4bcedf9ff5eaa7398495ae14e61cba0a295704edbc7decde" - -[[package]] -name = "same-file" -version = "1.0.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" -dependencies = [ - "winapi-util", -] - -[[package]] -name = "scopeguard" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" - -[[package]] -name = "scratch" -version = "1.0.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ddccb15bcce173023b3fedd9436f882a0739b8dfb45e4f6b6002bee5929f61b2" - -[[package]] -name = "serde" -version = "1.0.152" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb7d1f0d3021d347a83e556fc4683dea2ea09d87bccdf88ff5c12545d89d5efb" -dependencies = [ - "serde_derive", -] - -[[package]] -name = "serde_derive" -version = "1.0.152" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af487d118eecd09402d70a5d72551860e788df87b464af30e5ea6a38c75c541e" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "serde_json" -version = "1.0.91" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "877c235533714907a8c2464236f5c4b2a17262ef1bd71f38f35ea592c8da6883" -dependencies = [ - "itoa", - "ryu", - "serde", -] - -[[package]] -name = "sha1" -version = "0.10.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f04293dc80c3993519f2d7f6f511707ee7094fe0c6d3406feb330cdb3540eba3" -dependencies = [ - "cfg-if 1.0.0", - "cpufeatures", - "digest", -] - -[[package]] -name = "sha2" -version = "0.10.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "82e6b795fe2e3b1e845bafcb27aa35405c4d47cdfc92af5fc8d3002f76cebdc0" -dependencies = [ - "cfg-if 1.0.0", - "cpufeatures", - "digest", -] - -[[package]] -name = "siphasher" -version = "0.3.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7bd3e3206899af3f8b12af284fafc038cc1dc2b41d1b89dd17297221c5d225de" - -[[package]] -name = "slug" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b3bc762e6a4b6c6fcaade73e77f9ebc6991b676f88bb2358bddb56560f073373" -dependencies = [ - "deunicode", -] - -[[package]] -name = "specs" -version = "0.1.0" -dependencies = [ - "halo2_proofs", - "lazy_static", - "num-bigint", - "parity-wasm", - "serde", - "serde_json", - "strum", - "strum_macros", -] - -[[package]] -name = "spin" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f6002a767bff9e83f8eeecf883ecb8011875a21ae8da43bffb817a57e78cc09" -dependencies = [ - "lock_api", -] - -[[package]] -name = "static_assertions" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" - -[[package]] -name = "strsim" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" - -[[package]] -name = "strum" -version = "0.24.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "063e6045c0e62079840579a7e47a355ae92f60eb74daaf156fb1e84ba164e63f" - -[[package]] -name = "strum_macros" -version = "0.24.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e385be0d24f186b4ce2f9982191e7101bb737312ad61c1f2f984f34bcf85d59" -dependencies = [ - "heck", - "proc-macro2", - "quote", - "rustversion", - "syn", -] - -[[package]] -name = "subtle" -version = "2.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6bdef32e8150c2a081110b42772ffe7d7c9032b606bc226c8260fd97e0976601" - -[[package]] -name = "syn" -version = "1.0.107" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f4064b5b16e03ae50984a5a8ed5d4f8803e6bc1fd170a3cda91a1be4b18e3f5" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "tap" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" - -[[package]] -name = "temp-env" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "45107136c2ddf8c4b87453c02294fd0adf41751796e81e8ba3f7fd951977ab57" -dependencies = [ - "once_cell", -] - -[[package]] -name = "tempfile" -version = "3.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5cdb1ef4eaeeaddc8fbd371e5017057064af0911902ef36b39801f67cc6d79e4" -dependencies = [ - "cfg-if 1.0.0", - "fastrand", - "libc", - "redox_syscall", - "remove_dir_all", - "winapi 0.3.9", -] - -[[package]] -name = "tera" -version = "1.17.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3df578c295f9ec044ff1c829daf31bb7581d5b3c2a7a3d87419afe1f2531438c" -dependencies = [ - "chrono", - "chrono-tz", - "globwalk", - "humansize", - "lazy_static", - "percent-encoding", - "pest", - "pest_derive", - "rand", - "regex", - "serde", - "serde_json", - "slug", - "unic-segment", -] - -[[package]] -name = "termcolor" -version = "1.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bab24d30b911b2376f3a13cc2cd443142f0c81dda04c118693e35b3835757755" -dependencies = [ - "winapi-util", -] - -[[package]] -name = "textwrap" -version = "0.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "222a222a5bfe1bba4a77b45ec488a741b3cb8872e5e499451fd7d0129c9c7c3d" - -[[package]] -name = "thiserror" -version = "1.0.38" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a9cd18aa97d5c45c6603caea1da6628790b37f7a34b6ca89522331c5180fed0" -dependencies = [ - "thiserror-impl", -] - -[[package]] -name = "thiserror-impl" -version = "1.0.38" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1fb327af4685e4d03fa8cbcf1716380da910eeb2bb8be417e7f9fd3fb164f36f" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "thread_local" -version = "1.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5516c27b78311c50bf42c071425c560ac799b11c30b31f87e3081965fe5e0180" -dependencies = [ - "once_cell", -] - -[[package]] -name = "typenum" -version = "1.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "497961ef93d974e23eb6f433eb5fe1b7930b659f06d12dec6fc44a8f554c0bba" - -[[package]] -name = "ucd-trie" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e79c4d996edb816c91e4308506774452e55e95c3c9de07b6729e17e15a5ef81" - -[[package]] -name = "uncased" -version = "0.9.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09b01702b0fd0b3fadcf98e098780badda8742d4f4a7676615cad90e8ac73622" -dependencies = [ - "version_check", -] - -[[package]] -name = "unic-char-property" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8c57a407d9b6fa02b4795eb81c5b6652060a15a7903ea981f3d723e6c0be221" -dependencies = [ - "unic-char-range", -] - -[[package]] -name = "unic-char-range" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0398022d5f700414f6b899e10b8348231abf9173fa93144cbc1a43b9793c1fbc" - -[[package]] -name = "unic-common" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "80d7ff825a6a654ee85a63e80f92f054f904f21e7d12da4e22f9834a4aaa35bc" - -[[package]] -name = "unic-segment" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e4ed5d26be57f84f176157270c112ef57b86debac9cd21daaabbe56db0f88f23" -dependencies = [ - "unic-ucd-segment", -] - -[[package]] -name = "unic-ucd-segment" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2079c122a62205b421f499da10f3ee0f7697f012f55b675e002483c73ea34700" -dependencies = [ - "unic-char-property", - "unic-char-range", - "unic-ucd-version", -] - -[[package]] -name = "unic-ucd-version" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96bd2f2237fe450fcd0a1d2f5f4e91711124f7857ba2e964247776ebeeb7b0c4" -dependencies = [ - "unic-common", -] - -[[package]] -name = "unicode-ident" -version = "1.0.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84a22b9f218b40614adcb3f4ff08b703773ad44fa9423e4e0d346d5db86e4ebc" - -[[package]] -name = "unicode-width" -version = "0.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b" - -[[package]] -name = "uuid" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1674845326ee10d37ca60470760d4288a6f80f304007d92e5c53bab78c9cfd79" -dependencies = [ - "getrandom", - "serde", -] - -[[package]] -name = "version_check" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" - -[[package]] -name = "wabt" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00bef93d5e6c81a293bccf107cf43aa47239382f455ba14869d36695d8963b9c" -dependencies = [ - "serde", - "serde_derive", - "serde_json", - "wabt-sys", -] - -[[package]] -name = "wabt-sys" -version = "0.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a4e043159f63e16986e713e9b5e1c06043df4848565bf672e27c523864c7791" -dependencies = [ - "cc", - "cmake", - "glob 0.2.11", -] - -[[package]] -name = "wait-timeout" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f200f5b12eb75f8c1ed65abd4b2db8a6e1b138a20de009dacee265a2498f3f6" -dependencies = [ - "libc", -] - -[[package]] -name = "walkdir" -version = "2.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "808cf2735cd4b6866113f648b791c6adc5714537bc222d9347bb203386ffda56" -dependencies = [ - "same-file", - "winapi 0.3.9", - "winapi-util", -] - -[[package]] -name = "wasi" -version = "0.11.0+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" - -[[package]] -name = "wasm-bindgen" -version = "0.2.83" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eaf9f5aceeec8be17c128b2e93e031fb8a4d469bb9c4ae2d7dc1888b26887268" -dependencies = [ - "cfg-if 1.0.0", - "wasm-bindgen-macro", -] - -[[package]] -name = "wasm-bindgen-backend" -version = "0.2.83" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c8ffb332579b0557b52d268b91feab8df3615f265d5270fec2a8c95b17c1142" -dependencies = [ - "bumpalo", - "log", - "once_cell", - "proc-macro2", - "quote", - "syn", - "wasm-bindgen-shared", -] - -[[package]] -name = "wasm-bindgen-macro" -version = "0.2.83" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "052be0f94026e6cbc75cdefc9bae13fd6052cdcaf532fa6c45e7ae33a1e6c810" -dependencies = [ - "quote", - "wasm-bindgen-macro-support", -] - -[[package]] -name = "wasm-bindgen-macro-support" -version = "0.2.83" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07bc0c051dc5f23e307b13285f9d75df86bfdf816c5721e573dec1f9b8aa193c" -dependencies = [ - "proc-macro2", - "quote", - "syn", - "wasm-bindgen-backend", - "wasm-bindgen-shared", -] - -[[package]] -name = "wasm-bindgen-shared" -version = "0.2.83" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1c38c045535d93ec4f0b4defec448e4291638ee608530863b1e2ba115d4fff7f" - -[[package]] -name = "wasm-encoder" -version = "0.18.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c64ac98d5d61192cc45c701b7e4bd0b9aff91e2edfc7a088406cfe2288581e2c" -dependencies = [ - "leb128", -] - -[[package]] -name = "wasmi" -version = "0.11.0" -dependencies = [ - "parity-wasm", - "specs", - "wasmi-validation", - "wasmi_core", -] - -[[package]] -name = "wasmi-validation" -version = "0.4.1" -dependencies = [ - "parity-wasm", -] - -[[package]] -name = "wasmi_core" -version = "0.1.0" -dependencies = [ - "downcast-rs", - "libm", - "memory_units", - "num-rational", - "num-traits", - "parity-wasm", -] - -[[package]] -name = "wast" -version = "47.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02b98502f3978adea49551e801a6687678e6015317d7d9470a67fe813393f2a8" -dependencies = [ - "leb128", - "memchr", - "unicode-width", - "wasm-encoder", -] - -[[package]] -name = "winapi" -version = "0.2.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" - -[[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-build" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc" - -[[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-util" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" -dependencies = [ - "winapi 0.3.9", -] - -[[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.1", -] - -[[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.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05d4b17490f70499f20b9e791dcf6a299785ce8af4d709018206dc5b4953e95f" -dependencies = [ - "windows_aarch64_gnullvm 0.48.0", - "windows_aarch64_msvc 0.48.0", - "windows_i686_gnu 0.48.0", - "windows_i686_msvc 0.48.0", - "windows_x86_64_gnu 0.48.0", - "windows_x86_64_gnullvm 0.48.0", - "windows_x86_64_msvc 0.48.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.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91ae572e1b79dba883e0d315474df7305d12f569b400fcf90581b06062f7e1bc" - -[[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.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2ef27e0d7bdfcfc7b868b317c1d32c641a6fe4629c171b8928c7b08d98d7cf3" - -[[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.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "622a1962a7db830d6fd0a69683c80a18fda201879f0f447f065a3b7467daa241" - -[[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.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4542c6e364ce21bf45d69fdd2a8e455fa38d316158cfd43b3ac1c5b1b19f8e00" - -[[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.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca2b8a661f7628cbd23440e50b05d705db3686f894fc9580820623656af974b1" - -[[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.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7896dbc1f41e08872e9d5e8f8baa8fdd2677f29468c4e156210174edc7f7b953" - -[[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.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a" - -[[package]] -name = "wyz" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05f360fc0b24296329c78fda852a1e9ae82de9cf7b27dae4b7f62f118f77b9ed" -dependencies = [ - "tap", -] - -[[package]] -name = "yastl" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ca6c5a4d66c1a9ea261811cf4773c27343de7e5033e1b75ea3f297dc7db3c1a" -dependencies = [ - "flume", - "scopeguard", -] diff --git a/crates/zkwasm/Cargo.toml b/crates/zkwasm/Cargo.toml index 4e95923d4..1393edbe7 100644 --- a/crates/zkwasm/Cargo.toml +++ b/crates/zkwasm/Cargo.toml @@ -22,12 +22,20 @@ strum = "0.24.1" strum_macros = "0.24.1" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" +ff = "0.12" +sha2 = "0.10.6" +poseidon = { git = "https://github.com/lanbones/poseidon" } + anyhow.workspace = true halo2aggregator-s.workspace = true halo2_proofs.workspace = true parity-wasm.workspace = true wasmi.workspace = true +# TODO put the host circuits into features + +zkwasm-host-circuits = { git = "https://github.com/DelphinusLab/zkWasm-host-circuits.git", branch="main" } + [dev-dependencies] rusty-fork = "0.3.0" diff --git a/crates/zkwasm/src/circuits/external_host_call_table/configure.rs b/crates/zkwasm/src/circuits/external_host_call_table/configure.rs index 4fe65ffea..a29e4419c 100644 --- a/crates/zkwasm/src/circuits/external_host_call_table/configure.rs +++ b/crates/zkwasm/src/circuits/external_host_call_table/configure.rs @@ -15,8 +15,8 @@ impl ExternalHostCallTableConfig { pub(in crate::circuits) fn configure(meta: &mut ConstraintSystem) -> Self { Self { idx: meta.fixed_column(), - opcode: meta.advice_column(), - operand: meta.advice_column(), + opcode: meta.named_advice_column("shared_opcodes".to_string()), + operand: meta.named_advice_column("shared_operands".to_string()), _phantom: PhantomData, } } diff --git a/crates/zkwasm/src/circuits/mod.rs b/crates/zkwasm/src/circuits/mod.rs index 4546e91e8..686ba9410 100644 --- a/crates/zkwasm/src/circuits/mod.rs +++ b/crates/zkwasm/src/circuits/mod.rs @@ -23,6 +23,9 @@ pub mod rtable; pub mod test_circuit; pub mod utils; +pub type CompilationTable = specs::CompilationTable; +pub type ExecutionTable = specs::ExecutionTable; + #[derive(Default, Clone)] pub struct TestCircuit { pub tables: Tables, diff --git a/crates/zkwasm/src/circuits/utils/table_entry.rs b/crates/zkwasm/src/circuits/utils/table_entry.rs index 5baf7a8c3..02b0f34f8 100644 --- a/crates/zkwasm/src/circuits/utils/table_entry.rs +++ b/crates/zkwasm/src/circuits/utils/table_entry.rs @@ -99,7 +99,7 @@ impl MemoryWritingTable { fd.write(buf.as_bytes()).unwrap(); } - let mtable = serde_json::to_string(self).unwrap(); + let mtable = serde_json::to_string_pretty(self).unwrap(); let dir = dir.unwrap_or(env::current_dir().unwrap()); write_file(&dir, "memory_writing_table.json", &mtable); diff --git a/crates/zkwasm/src/foreign/context/circuits/config.rs b/crates/zkwasm/src/foreign/context/circuits/config.rs index abce4a5ef..d6f5f3711 100644 --- a/crates/zkwasm/src/foreign/context/circuits/config.rs +++ b/crates/zkwasm/src/foreign/context/circuits/config.rs @@ -15,8 +15,8 @@ use super::ContextContHelperTableConfig; impl ContextContHelperTableConfig { pub fn configure(meta: &mut ConstraintSystem, from_zero_index: Column) -> Self { - let input = meta.advice_column(); - let output = meta.advice_column(); + let input = meta.named_advice_column("context_input".to_string()); + let output = meta.named_advice_column("context_output".to_string()); meta.enable_equality(input); meta.enable_equality(output); diff --git a/crates/zkwasm/src/foreign/context/runtime.rs b/crates/zkwasm/src/foreign/context/runtime.rs index 301fa1e01..1a7ff2751 100644 --- a/crates/zkwasm/src/foreign/context/runtime.rs +++ b/crates/zkwasm/src/foreign/context/runtime.rs @@ -28,11 +28,11 @@ impl Context { } } - fn push_output(&mut self, value: u64) { + pub fn write_context(&mut self, value: u64) { self.outputs.lock().unwrap().push(value) } - fn pop_input(&mut self) -> u64 { + pub fn read_context(&mut self) -> u64 { self.inputs .pop() .expect("Failed to pop value from context_in array, please check you inputs") @@ -62,7 +62,7 @@ pub fn register_context_foreign( Rc::new(|context: &mut dyn ForeignContext, _args: RuntimeArgs| { let context = context.downcast_mut::().unwrap(); - Some(wasmi::RuntimeValue::I64(context.pop_input() as i64)) + Some(wasmi::RuntimeValue::I64(context.read_context() as i64)) }), ); @@ -78,7 +78,7 @@ pub fn register_context_foreign( let context = context.downcast_mut::().unwrap(); let value: i64 = args.nth(0); - context.push_output(value as u64); + context.write_context(value as u64); None }), diff --git a/crates/zkwasm/src/foreign/keccak_helper/mod.rs b/crates/zkwasm/src/foreign/keccak_helper/mod.rs deleted file mode 100644 index 7b788c207..000000000 --- a/crates/zkwasm/src/foreign/keccak_helper/mod.rs +++ /dev/null @@ -1 +0,0 @@ -pub mod test; diff --git a/crates/zkwasm/src/foreign/keccak_helper/test.rs b/crates/zkwasm/src/foreign/keccak_helper/test.rs deleted file mode 100644 index 24ffedbc5..000000000 --- a/crates/zkwasm/src/foreign/keccak_helper/test.rs +++ /dev/null @@ -1,50 +0,0 @@ -#[cfg(test)] -pub(crate) mod tests { - use crate::foreign::wasm_input_helper::runtime::register_wasm_input_foreign; - use crate::runtime::host::host_env::HostEnv; - use crate::test::test_circuit_with_env; - - use crate::circuits::config::set_zkwasm_k; - use rusty_fork::rusty_fork_test; - use std::fs; - - pub(crate) fn prepare_inputs() -> (Vec, Vec) { - let msg = "abcdef"; - let mut msg: Vec = hex::decode(msg) - .unwrap() - .into_iter() - .map(|v| v as u64) - .collect(); - let mut private_inputs = vec![msg.len() as u64]; - private_inputs.append(&mut msg); - - let expected = "acd0c377fe36d5b209125185bc3ac41155ed1bf7103ef9f0c2aff4320460b6df"; - let public_inputs = hex::decode(expected) - .unwrap() - .into_iter() - .map(|v| v as u64) - .collect(); - - (public_inputs, private_inputs) - } - - /* - * FORK the test since it modifies global variable zkwasm_k. - */ - rusty_fork_test! { - #[test] - fn test_keccak() { - set_zkwasm_k(19); - - let (public_inputs, private_inputs) = prepare_inputs(); - - let wasm = fs::read("wasm/keccak.wasm").unwrap(); - - let mut env = HostEnv::new(); - let wasm_runtime_io = register_wasm_input_foreign(&mut env, public_inputs.clone(), private_inputs.clone()); - env.finalize(); - - test_circuit_with_env(env, wasm_runtime_io, wasm, "keccak_digest").unwrap(); - } - } -} diff --git a/crates/zkwasm/src/foreign/log_helper/mod.rs b/crates/zkwasm/src/foreign/log_helper/mod.rs index 790220572..adc62834c 100644 --- a/crates/zkwasm/src/foreign/log_helper/mod.rs +++ b/crates/zkwasm/src/foreign/log_helper/mod.rs @@ -4,6 +4,7 @@ use specs::external_host_call_table::ExternalHostCallSignature; use crate::runtime::host::host_env::HostEnv; use crate::runtime::host::ForeignContext; +use zkwasm_host_circuits::host::ForeignInst::Log; struct Context; impl ForeignContext for Context {} @@ -24,8 +25,8 @@ pub fn register_log_foreign(env: &mut HostEnv) { ); env.external_env.register_function( - "log", - 0, + "wasm_dbg", + Log as usize, ExternalHostCallSignature::Argument, foreign_log_plugin, print, diff --git a/crates/zkwasm/src/foreign/mod.rs b/crates/zkwasm/src/foreign/mod.rs index 047c91cb5..12d9b2c6c 100644 --- a/crates/zkwasm/src/foreign/mod.rs +++ b/crates/zkwasm/src/foreign/mod.rs @@ -1,26 +1,15 @@ -use std::sync::Arc; -use std::sync::Mutex; - use crate::circuits::cell::AllocatedUnlimitedCell; use crate::circuits::config::zkwasm_k; use crate::circuits::etable::allocator::EventTableCellAllocator; use crate::circuits::etable::constraint_builder::ConstraintBuilder; use crate::circuits::etable::EventTableCommonConfig; use crate::circuits::etable::EventTableOpcodeConfig; -use crate::runtime::host::host_env::HostEnv; -use crate::runtime::wasmi_interpreter::WasmRuntimeIO; use halo2_proofs::arithmetic::FieldExt; use halo2_proofs::plonk::ConstraintSystem; use halo2_proofs::plonk::Expression; use halo2_proofs::plonk::VirtualCells; -use self::context::runtime::register_context_foreign; -use self::log_helper::register_log_foreign; -use self::require_helper::register_require_foreign; -use self::wasm_input_helper::runtime::register_wasm_input_foreign; - pub mod context; -pub mod keccak_helper; pub mod log_helper; pub mod require_helper; pub mod wasm_input_helper; @@ -51,21 +40,3 @@ pub(crate) trait EventTableForeignCallConfigBuilder { pub(crate) trait InternalHostPluginBuilder { fn new(index: usize) -> Self; } - -impl HostEnv { - pub fn new_with_full_foreign_plugins( - public_inputs: Vec, - private_inputs: Vec, - context_input: Vec, - context_output: Arc>>, - ) -> (Self, WasmRuntimeIO) { - let mut env = HostEnv::new(); - let wasm_runtime_io = register_wasm_input_foreign(&mut env, public_inputs, private_inputs); - register_require_foreign(&mut env); - register_log_foreign(&mut env); - register_context_foreign(&mut env, context_input, context_output); - env.finalize(); - - (env, wasm_runtime_io) - } -} diff --git a/crates/zkwasm/src/foreign/wasm_input_helper/runtime.rs b/crates/zkwasm/src/foreign/wasm_input_helper/runtime.rs index e2fd16b57..add1ae1a7 100644 --- a/crates/zkwasm/src/foreign/wasm_input_helper/runtime.rs +++ b/crates/zkwasm/src/foreign/wasm_input_helper/runtime.rs @@ -10,11 +10,11 @@ use crate::runtime::wasmi_interpreter::WasmRuntimeIO; use super::Op; -struct Context { - public_inputs: Vec, - private_inputs: Vec, - instance: Rc>>, - output: Rc>>, +pub struct Context { + pub public_inputs: Vec, + pub private_inputs: Vec, + pub instance: Rc>>, + pub output: Rc>>, } impl Context { @@ -46,18 +46,36 @@ impl Context { self.private_inputs.remove(0) } - pub fn push_public(&mut self, value: u64) { + fn push_public(&mut self, value: u64) { let mut instance = self.instance.borrow_mut(); instance.push(value) } - pub fn push_output(&mut self, value: u64) { + fn push_output(&mut self, value: u64) { let mut instance = self.instance.borrow_mut(); instance.push(value); let mut output = self.output.borrow_mut(); output.push(value); } + + pub fn wasm_input(&mut self, arg: i32) -> u64 { + assert!(arg == 0 || arg == 1); + + let input = if arg == 1 { + let value = self.pop_public(); + self.push_public(value); + value + } else { + self.pop_private() + }; + + input + } + + pub fn wasm_output(&mut self, value: u64) { + self.push_output(value); + } } impl ForeignContext for Context {} @@ -75,15 +93,7 @@ pub fn register_wasm_input_foreign( let context = context.downcast_mut::().unwrap(); let arg: i32 = args.nth(0); - assert!(arg == 0 || arg == 1); - - let input = if arg == 1 { - let value = context.pop_public(); - context.push_public(value); - value - } else { - context.pop_private() - }; + let input = context.wasm_input(arg); Some(wasmi::RuntimeValue::I64(input as i64)) }, @@ -94,7 +104,7 @@ pub fn register_wasm_input_foreign( let context = context.downcast_mut::().unwrap(); let value: i64 = args.nth(0); - context.push_output(value as u64); + context.wasm_output(value as u64); None }, diff --git a/crates/zkwasm/src/lib.rs b/crates/zkwasm/src/lib.rs index c850e7b5a..6b12c49ae 100644 --- a/crates/zkwasm/src/lib.rs +++ b/crates/zkwasm/src/lib.rs @@ -17,3 +17,7 @@ pub mod test; #[macro_use] extern crate lazy_static; extern crate downcast_rs; + +pub extern crate halo2_proofs; +pub extern crate halo2aggregator_s; +pub extern crate zkwasm_host_circuits; diff --git a/crates/zkwasm/src/loader/mod.rs b/crates/zkwasm/src/loader/mod.rs index db3d28802..a62ec0b09 100644 --- a/crates/zkwasm/src/loader/mod.rs +++ b/crates/zkwasm/src/loader/mod.rs @@ -1,7 +1,3 @@ -use std::marker::PhantomData; -use std::sync::Arc; -use std::sync::Mutex; - use anyhow::Result; use halo2_proofs::arithmetic::MultiMillerLoop; use halo2_proofs::dev::MockProver; @@ -12,9 +8,12 @@ use halo2_proofs::plonk::SingleVerifier; use halo2_proofs::plonk::VerifyingKey; use halo2_proofs::poly::commitment::Params; use halo2_proofs::poly::commitment::ParamsVerifier; +use std::marker::PhantomData; + use halo2aggregator_s::circuits::utils::load_or_create_proof; use halo2aggregator_s::circuits::utils::TranscriptHash; use halo2aggregator_s::transcript::poseidon::PoseidonRead; + use specs::ExecutionTable; use specs::Tables; use wasmi::tracer::Tracer; @@ -33,6 +32,7 @@ use crate::loader::err::Error; use crate::loader::err::PreCheckErr; use crate::profile::Profiler; use crate::runtime::host::host_env::HostEnv; +use crate::runtime::host::HostEnvBuilder; use crate::runtime::wasmi_interpreter::Execution; use crate::runtime::CompiledImage; use crate::runtime::ExecutionResult; @@ -43,29 +43,20 @@ mod err; const ENTRY: &str = "zkmain"; -pub struct ExecutionArg { - /// Public inputs for `wasm_input(1)` - pub public_inputs: Vec, - /// Private inputs for `wasm_input(0)` - pub private_inputs: Vec, - /// Context inputs for `wasm_read_context()` - pub context_inputs: Vec, - /// Context outputs for `wasm_write_context()` - pub context_outputs: Arc>>, -} - pub struct ExecutionReturn { pub context_output: Vec, } -pub struct ZkWasmLoader { +pub struct ZkWasmLoader> { k: u32, module: wasmi::Module, phantom_functions: Vec, - _data: PhantomData, + _data_arg: PhantomData, + _data_builder: PhantomData, + _data_e: PhantomData, } -impl ZkWasmLoader { +impl> ZkWasmLoader { fn precheck(&self) -> Result<()> { fn check_zkmain_exists(module: &wasmi::Module) -> Result<()> { use parity_wasm::elements::Internal; @@ -109,12 +100,7 @@ impl ZkWasmLoader { } fn circuit_without_witness(&self) -> Result> { - let (env, wasm_runtime_io) = HostEnv::new_with_full_foreign_plugins( - vec![], - vec![], - vec![], - Arc::new(Mutex::new(vec![])), - ); + let (env, wasm_runtime_io) = EnvBuilder::create_env_without_value(); let compiled_module = self.compile(&env)?; @@ -138,7 +124,9 @@ impl ZkWasmLoader { k, module, phantom_functions, - _data: PhantomData, + _data_e: PhantomData, + _data_builder: PhantomData, + _data_arg: PhantomData, }; loader.precheck()?; @@ -154,12 +142,7 @@ impl ZkWasmLoader { } pub fn checksum(&self, params: &Params) -> Result> { - let (env, _) = HostEnv::new_with_full_foreign_plugins( - vec![], - vec![], - vec![], - Arc::new(Mutex::new(vec![])), - ); + let (env, _) = EnvBuilder::create_env_without_value(); let compiled = self.compile(&env)?; let table_with_params = CompilationTableWithParams { @@ -171,44 +154,35 @@ impl ZkWasmLoader { } } -impl ZkWasmLoader { - pub fn dry_run(&self, arg: ExecutionArg) -> Result> { - let (mut env, _) = HostEnv::new_with_full_foreign_plugins( - arg.public_inputs, - arg.private_inputs, - arg.context_inputs, - arg.context_outputs, - ); +impl> ZkWasmLoader { + pub fn dry_run(&self, arg: T) -> Result> { + let (mut env, _) = EnvBuilder::create_env(arg); let compiled_module = self.compile(&env)?; compiled_module.dry_run(&mut env) } - pub fn run(&self, arg: ExecutionArg) -> Result> { - let (mut env, wasm_runtime_io) = HostEnv::new_with_full_foreign_plugins( - arg.public_inputs, - arg.private_inputs, - arg.context_inputs, - arg.context_outputs, - ); - + pub fn run(&self, arg: T, write_to_file: bool) -> Result> { + let (mut env, wasm_runtime_io) = EnvBuilder::create_env(arg); let compiled_module = self.compile(&env)?; let result = compiled_module.run(&mut env, wasm_runtime_io)?; result.tables.profile_tables(); - result.tables.write_json(None); + + if write_to_file { + result.tables.write_json(None); + } Ok(result) } pub fn circuit_with_witness( &self, - arg: ExecutionArg, - ) -> Result<(TestCircuit, Vec)> { - let execution_result = self.run(arg)?; - + arg: T, + ) -> Result<(TestCircuit, Vec, Vec)> { + let execution_result = self.run(arg, true)?; let instance: Vec = execution_result .public_inputs_and_outputs .clone() @@ -224,7 +198,7 @@ impl ZkWasmLoader { println!("output:"); println!("{:?}", execution_result.outputs); - Ok((builder.build_circuit(), instance)) + Ok((builder.build_circuit(), instance, execution_result.outputs)) } pub fn mock_test( @@ -318,10 +292,12 @@ mod tests { use std::path::PathBuf; use crate::circuits::TestCircuit; + use crate::runtime::host::default_env::DefaultHostEnvBuilder; + use crate::runtime::host::default_env::ExecutionArg; use super::ZkWasmLoader; - impl ZkWasmLoader { + impl ZkWasmLoader { pub(crate) fn bench_test(&self, circuit: TestCircuit, instances: Vec) { fn prepare_param(k: u32) -> Params { let path = PathBuf::from(format!("test_param.{}.data", k)); diff --git a/crates/zkwasm/src/runtime/host/default_env.rs b/crates/zkwasm/src/runtime/host/default_env.rs new file mode 100644 index 000000000..29b5b22c0 --- /dev/null +++ b/crates/zkwasm/src/runtime/host/default_env.rs @@ -0,0 +1,73 @@ +use std::sync::Arc; +use std::sync::Mutex; + +use crate::foreign::context::runtime::register_context_foreign; +use crate::foreign::log_helper::register_log_foreign; +use crate::foreign::require_helper::register_require_foreign; +use crate::foreign::wasm_input_helper::runtime::register_wasm_input_foreign; +use crate::runtime::wasmi_interpreter::WasmRuntimeIO; +use specs::args::parse_args; + +use super::host_env::HostEnv; +use super::HostEnvBuilder; + +pub struct ExecutionArg { + /// Public inputs for `wasm_input(1)` + pub public_inputs: Vec, + /// Private inputs for `wasm_input(0)` + pub private_inputs: Vec, + /// Context inputs for `wasm_read_context()` + pub context_inputs: Vec, + /// Context outputs for `wasm_write_context()` + pub context_outputs: Arc>>, +} + +impl super::ContextOutput for ExecutionArg { + fn get_context_outputs(&self) -> Arc>> { + self.context_outputs.clone() + } +} + +impl From for ExecutionArg { + fn from(seq: super::Sequence) -> ExecutionArg { + let private_inputs = parse_args(seq.private_inputs.iter().map(|s| s.as_str()).collect()); + let public_inputs = parse_args(seq.public_inputs.iter().map(|s| s.as_str()).collect()); + let context_inputs = parse_args(seq.context_input.iter().map(|s| s.as_str()).collect()); + let context_outputs = Arc::new(Mutex::new(vec![])); + ExecutionArg { + private_inputs, + public_inputs, + context_inputs, + context_outputs, + } + } +} + +pub struct DefaultHostEnvBuilder; + +impl HostEnvBuilder for DefaultHostEnvBuilder { + type Arg = ExecutionArg; + + fn create_env_without_value() -> (HostEnv, WasmRuntimeIO) { + let mut env = HostEnv::new(); + let wasm_runtime_io = register_wasm_input_foreign(&mut env, vec![], vec![]); + register_require_foreign(&mut env); + register_log_foreign(&mut env); + register_context_foreign(&mut env, vec![], Arc::new(Mutex::new(vec![]))); + env.finalize(); + + (env, wasm_runtime_io) + } + + fn create_env(arg: Self::Arg) -> (HostEnv, WasmRuntimeIO) { + let mut env = HostEnv::new(); + let wasm_runtime_io = + register_wasm_input_foreign(&mut env, arg.public_inputs, arg.private_inputs); + register_require_foreign(&mut env); + register_log_foreign(&mut env); + register_context_foreign(&mut env, arg.context_inputs, arg.context_outputs); + env.finalize(); + + (env, wasm_runtime_io) + } +} diff --git a/crates/zkwasm/src/runtime/host/host_env.rs b/crates/zkwasm/src/runtime/host/host_env.rs index 1a21e8740..cd23d0452 100644 --- a/crates/zkwasm/src/runtime/host/host_env.rs +++ b/crates/zkwasm/src/runtime/host/host_env.rs @@ -19,7 +19,7 @@ use super::internal_circuit_plugin::InternalCircuitEnv; use super::HostFunction; pub struct HostEnv { - pub internal_env: InternalCircuitEnv, + pub(crate) internal_env: InternalCircuitEnv, pub external_env: ExternalCircuitEnv, finalized: Rc>, diff --git a/crates/zkwasm/src/runtime/host/mod.rs b/crates/zkwasm/src/runtime/host/mod.rs index b167318ac..32ac94d1b 100644 --- a/crates/zkwasm/src/runtime/host/mod.rs +++ b/crates/zkwasm/src/runtime/host/mod.rs @@ -1,16 +1,36 @@ +use self::host_env::HostEnv; +use super::wasmi_interpreter::WasmRuntimeIO; use downcast_rs::impl_downcast; use downcast_rs::Downcast; +use serde::Deserialize; +use serde::Serialize; use specs::external_host_call_table::ExternalHostCallSignature; use specs::host_function::HostFunctionDesc; use std::cell::RefCell; +use std::path::PathBuf; use std::rc::Rc; +use std::sync::Arc; +use std::sync::Mutex; use wasmi::RuntimeArgs; use wasmi::RuntimeValue; use wasmi::Signature; -pub mod host_env; +pub trait ContextOutput { + fn get_context_outputs(&self) -> Arc>>; +} + +#[derive(Serialize, Deserialize, Debug, Clone)] +pub struct Sequence { + private_inputs: Vec, + public_inputs: Vec, + context_input: Vec, + pub context_output: Option, +} -mod external_circuit_plugin; +pub mod default_env; +pub mod external_circuit_plugin; + +pub mod host_env; mod internal_circuit_plugin; trait MatchForeignOpSignature { @@ -67,3 +87,13 @@ struct HostFunction { desc: HostFunctionDesc, execution_env: HostFunctionExecutionEnv, } + +/// Implement `HostEnvBuilder` to support customized foreign plugins. +pub trait HostEnvBuilder { + /// Argument type + type Arg; + /// Create an empty env without value, this is used by compiling, computing hash + fn create_env_without_value() -> (HostEnv, WasmRuntimeIO); + /// Create an env with execution parameters, this is used by dry-run, run + fn create_env(env: Self::Arg) -> (HostEnv, WasmRuntimeIO); +} diff --git a/crates/zkwasm/src/test/test_rlp.rs b/crates/zkwasm/src/test/test_rlp.rs index 377a0374f..75d0e8d66 100644 --- a/crates/zkwasm/src/test/test_rlp.rs +++ b/crates/zkwasm/src/test/test_rlp.rs @@ -2,14 +2,19 @@ use std::sync::Arc; use std::sync::Mutex; use crate::circuits::TestCircuit; -use crate::loader::ExecutionArg; use crate::loader::ZkWasmLoader; +use crate::runtime::host::default_env::DefaultHostEnvBuilder; +use crate::runtime::host::default_env::ExecutionArg; use anyhow::Result; use halo2_proofs::pairing::bn256::Bn256; use halo2_proofs::pairing::bn256::Fr; -fn build_circuit() -> Result<(ZkWasmLoader, TestCircuit, Vec)> { +fn build_circuit() -> Result<( + ZkWasmLoader, + TestCircuit, + Vec, +)> { let public_inputs = vec![133]; let private_inputs: Vec = vec![ 14625441452057167097, @@ -149,9 +154,9 @@ fn build_circuit() -> Result<(ZkWasmLoader, TestCircuit, Vec)> { let wasm = std::fs::read("wasm/rlp.wasm").unwrap(); - let loader = ZkWasmLoader::::new(20, wasm, vec![])?; + let loader = ZkWasmLoader::::new(20, wasm, vec![])?; - let (circuit, instances) = loader.circuit_with_witness(ExecutionArg { + let (circuit, instances, _) = loader.circuit_with_witness(ExecutionArg { public_inputs, private_inputs, context_inputs: vec![], diff --git a/crates/zkwasm/wasm/keccak.wasm b/crates/zkwasm/wasm/keccak.wasm deleted file mode 100755 index 473dccc38..000000000 Binary files a/crates/zkwasm/wasm/keccak.wasm and /dev/null differ