From 22d1598b4161125f959da0b71ca6819dd470a30a Mon Sep 17 00:00:00 2001 From: sinka Date: Sat, 4 Mar 2023 14:04:53 +1100 Subject: [PATCH 01/35] feature: add blspair-foreign 1. add ecc sum host api 2. add ecc pair host api 3. add kvpair op 4. add more host circuits --- Cargo.lock | 1082 ++++++++++++++++++++- Cargo.toml | 7 + ctest/arith.wasm | Bin 0 -> 129 bytes ctest/batchinput.wasm | Bin 0 -> 135 bytes ctest/bls.c | 195 ++++ ctest/bls.wasm | Bin 0 -> 1151 bytes specs/src/lib.rs | 2 +- src/circuits/utils/table_entry.rs | 2 +- src/cli/exec.rs | 20 +- src/foreign/ecc_helper/bls381/mod.rs | 58 ++ src/foreign/ecc_helper/bls381/pair/mod.rs | 137 +++ src/foreign/ecc_helper/bls381/sum/mod.rs | 93 ++ src/foreign/ecc_helper/bn254/mod.rs | 59 ++ src/foreign/ecc_helper/bn254/pair/mod.rs | 157 +++ src/foreign/ecc_helper/bn254/sum/mod.rs | 118 +++ src/foreign/ecc_helper/jubjub/mod.rs | 44 + src/foreign/ecc_helper/jubjub/sum/mod.rs | 141 +++ src/foreign/ecc_helper/mod.rs | 22 + src/foreign/ecc_helper/test.rs | 103 ++ src/foreign/hash_helper/mod.rs | 2 + src/foreign/hash_helper/poseidon.rs | 152 +++ src/foreign/hash_helper/sha256.rs | 149 +++ src/foreign/kv_helper/kvpair.rs | 179 ++++ src/foreign/kv_helper/mod.rs | 1 + src/foreign/log_helper/mod.rs | 5 +- src/foreign/mod.rs | 22 + test_bls.sh | 14 + 27 files changed, 2726 insertions(+), 38 deletions(-) create mode 100755 ctest/arith.wasm create mode 100755 ctest/batchinput.wasm create mode 100644 ctest/bls.c create mode 100755 ctest/bls.wasm create mode 100644 src/foreign/ecc_helper/bls381/mod.rs create mode 100644 src/foreign/ecc_helper/bls381/pair/mod.rs create mode 100644 src/foreign/ecc_helper/bls381/sum/mod.rs create mode 100644 src/foreign/ecc_helper/bn254/mod.rs create mode 100644 src/foreign/ecc_helper/bn254/pair/mod.rs create mode 100644 src/foreign/ecc_helper/bn254/sum/mod.rs create mode 100644 src/foreign/ecc_helper/jubjub/mod.rs create mode 100644 src/foreign/ecc_helper/jubjub/sum/mod.rs create mode 100644 src/foreign/ecc_helper/mod.rs create mode 100644 src/foreign/ecc_helper/test.rs create mode 100644 src/foreign/hash_helper/mod.rs create mode 100644 src/foreign/hash_helper/poseidon.rs create mode 100644 src/foreign/hash_helper/sha256.rs create mode 100644 src/foreign/kv_helper/kvpair.rs create mode 100644 src/foreign/kv_helper/mod.rs create mode 100755 test_bls.sh diff --git a/Cargo.lock b/Cargo.lock index 82691f3fc..737986d9d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,43 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "addr2line" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4fa78e18c64fce05e902adecd7a5eed15a5e0a3439f7b0e169f0252214865e3" +dependencies = [ + "gimli", +] + +[[package]] +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + +[[package]] +name = "ahash" +version = "0.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 = "0.7.20" @@ -11,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_system_properties" version = "0.1.5" @@ -49,6 +92,17 @@ version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8da52d66c7071e2e3fa2a1e5c6d088fec47b593032b254f5e980de8ea54454d6" +[[package]] +name = "async-trait" +version = "0.1.72" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc6dde6e4ed435a4c1ee4e73592f5ba9da2151af10076cc04858746af9352d09" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.27", +] + [[package]] name = "atty" version = "0.2.14" @@ -66,6 +120,33 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" +[[package]] +name = "backtrace" +version = "0.3.68" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4319208da049c43661739c5fade2ba182f09d1dc2299b32298d3a31692b17e12" +dependencies = [ + "addr2line", + "cc", + "cfg-if 1.0.0", + "libc", + "miniz_oxide", + "object", + "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" @@ -116,6 +197,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", + "js-sys", + "lazy_static", + "rand", + "serde", + "serde_bytes", + "serde_json", + "time", + "uuid", +] + [[package]] name = "bstr" version = "0.2.17" @@ -131,6 +233,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.78" @@ -210,7 +318,7 @@ dependencies = [ "proc-macro-error", "proc-macro2", "quote", - "syn", + "syn 1.0.107", ] [[package]] @@ -258,6 +366,12 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "245097e9a4535ee1e3e3931fcfcd55a796a44c643e8596ff6566d68f09b87bbc" +[[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.3" @@ -380,7 +494,7 @@ dependencies = [ "proc-macro2", "quote", "scratch", - "syn", + "syn 1.0.107", ] [[package]] @@ -397,9 +511,50 @@ checksum = "3e7e2adeb6a0d4a282e581096b06e1791532b7d576dcde5ccd9382acf55db8e6" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.107", +] + +[[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.107", +] + +[[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.107", ] +[[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" @@ -410,6 +565,7 @@ dependencies = [ "clap", "downcast-rs", "env_logger", + "ff", "halo2_proofs", "halo2aggregator-s", "hex", @@ -420,6 +576,8 @@ dependencies = [ "num-bigint", "num-integer", "num-traits", + "poseidon", + "quote", "rand", "rusty-fork", "serde", @@ -432,6 +590,31 @@ dependencies = [ "wabt", "wasmi", "wast", + "zkwasm-host-circuits", +] + +[[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.107", +] + +[[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.107", ] [[package]] @@ -448,6 +631,7 @@ checksum = "8168378f4e5023e7218c89c891c0fd8ecdb5e5e4f18cb78f38cf245dd021e76f" dependencies = [ "block-buffer", "crypto-common", + "subtle", ] [[package]] @@ -510,6 +694,18 @@ version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "90e5c1c8368803113bf0c9584fc495a58b86dc8a29edbf8fe877d21d9507e797" +[[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.107", +] + [[package]] name = "env_logger" version = "0.9.3" @@ -551,7 +747,7 @@ checksum = "5109f6bc9cd57feda665da326f3f6c57e0498c8fe9f7d12d7b8abc96719ca91b" dependencies = [ "execute-command-tokens", "quote", - "syn", + "syn 1.0.107", ] [[package]] @@ -600,7 +796,7 @@ checksum = "5cbc844cecaee9d4443931972e1289c8ff485cb4cc2767cb03ca139ed6885153" dependencies = [ "cfg-if 1.0.0", "libc", - "redox_syscall", + "redox_syscall 0.2.16", "windows-sys 0.48.0", ] @@ -610,7 +806,7 @@ version = "0.10.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1657b4441c3403d9f7b3409e47575237dac27b1b5726df654a6ecbf92f0f7577" dependencies = [ - "spin", + "spin 0.9.4", ] [[package]] @@ -619,6 +815,15 @@ version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" +[[package]] +name = "form_urlencoded" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9c384f161156f5260c24a097c56119f9be8c798586aecc13afbcbe7b7e26bf8" +dependencies = [ + "percent-encoding", +] + [[package]] name = "fsevent-sys" version = "4.1.0" @@ -634,6 +839,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.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.6" @@ -655,6 +931,12 @@ dependencies = [ "wasi", ] +[[package]] +name = "gimli" +version = "0.27.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6c80984affa11d98d1b88b66ac8853f143217b399d3c74116778ff8fdb4ed2e" + [[package]] name = "glob" version = "0.2.11" @@ -759,6 +1041,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.0" @@ -789,6 +1081,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 = "1.1.1" @@ -825,6 +1137,33 @@ dependencies = [ "cxx-build", ] +[[package]] +name = "ident_case" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" + +[[package]] +name = "idna" +version = "0.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.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e14ddfc70884202db2244c223200c204c2bda1bc6e0998d11b5e024d657209e6" +dependencies = [ + "unicode-bidi", + "unicode-normalization", +] + [[package]] name = "ignore" version = "0.4.18" @@ -850,7 +1189,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1885e79c1fc4b10f0e172c475f458b7f7b93061064d98c3293e98c5ba0c8b399" dependencies = [ "autocfg", - "hashbrown", + "hashbrown 0.12.3", ] [[package]] @@ -882,6 +1221,24 @@ dependencies = [ "cfg-if 1.0.0", ] +[[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 = "itoa" version = "1.0.5" @@ -941,9 +1298,9 @@ checksum = "884e2677b40cc8c339eaefcb701c32ef1fd2493d71118dc0ca4b6a736c93bd67" [[package]] name = "libc" -version = "0.2.139" +version = "0.2.147" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79" +checksum = "b4668fb0ea861c1df094127ac5f1da3409a82116a4ba74fca2e58ef927159bb3" [[package]] name = "libm" @@ -960,6 +1317,12 @@ dependencies = [ "cc", ] +[[package]] +name = "linked-hash-map" +version = "0.5.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0717cef1bc8b636c6e1c1bbdefc09e6322da8a9321966e8928ef80d20f7f770f" + [[package]] name = "lock_api" version = "0.4.9" @@ -979,6 +1342,45 @@ dependencies = [ "cfg-if 1.0.0", ] +[[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" @@ -1006,6 +1408,15 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8452105ba047068f40ff7093dd1d9da90898e63dd61736462e9cdda6a90ad3c3" +[[package]] +name = "miniz_oxide" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7810e0be55b428ada41041c41f32c9f1a42817901b4ccf45fa3d4b6561e74c7" +dependencies = [ + "adler", +] + [[package]] name = "mio" version = "0.8.8" @@ -1019,14 +1430,61 @@ dependencies = [ ] [[package]] -name = "notify" -version = "6.0.1" +name = "mongodb" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5738a2795d57ea20abec2d6d76c6081186709c0024187cd5977265eda6598b51" +checksum = "ebcd85ec209a5b84fd9f54b9e381f6fa17462bc74160d018fc94fd8b9f61faa8" dependencies = [ + "async-trait", + "base64 0.13.1", "bitflags", - "crossbeam-channel", - "filetime", + "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" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5738a2795d57ea20abec2d6d76c6081186709c0024187cd5977265eda6598b51" +dependencies = [ + "bitflags", + "crossbeam-channel", + "filetime", "fsevent-sys", "inotify", "kqueue", @@ -1089,6 +1547,15 @@ dependencies = [ "libc", ] +[[package]] +name = "object" +version = "0.31.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8bda667d9f2b5051b8833f59f3bf748b28ef54f850f4fcb389a252aa383866d1" +dependencies = [ + "memchr", +] + [[package]] name = "once_cell" version = "1.16.0" @@ -1131,6 +1598,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" @@ -1140,6 +1630,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.2.0" @@ -1176,7 +1675,7 @@ dependencies = [ "pest_meta", "proc-macro2", "quote", - "syn", + "syn 1.0.107", ] [[package]] @@ -1229,10 +1728,22 @@ dependencies = [ "uncased", ] +[[package]] +name = "pin-project-lite" +version = "0.2.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c40d25201921e5ff0c862a505c6557ea88568a4e3ace775ab55e93f2f4f9d57" + +[[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" -source = "git+https://github.com/lanbones/poseidon#20d881c2125199749055f305d73d514084b65e02" +source = "git+https://github.com/lanbones/poseidon#ade94877c8285cc251107418c5effbce36684aa4" dependencies = [ "halo2_proofs", "subtle", @@ -1253,7 +1764,7 @@ dependencies = [ "proc-macro-error-attr", "proc-macro2", "quote", - "syn", + "syn 1.0.107", "version_check", ] @@ -1270,9 +1781,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.49" +version = "1.0.66" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "57a8eca9f9c4ffde41714334dee777596264c7825420f521abc92b5b5deb63a5" +checksum = "18fb31db3f9bddb2ea821cde30a9f70117e3f119938b5ee630b7403aa6e2ead9" dependencies = [ "unicode-ident", ] @@ -1285,9 +1796,9 @@ checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" [[package]] name = "quote" -version = "1.0.23" +version = "1.0.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8856d8364d252a14d474036ea1358d63c9e6965c8e5c1885c18f73d70bff9c7b" +checksum = "5fe8a65d69dd0808184ebb5f836ab526bb259db23c657efa38711b1072ee47f0" dependencies = [ "proc-macro2", ] @@ -1359,6 +1870,15 @@ dependencies = [ "bitflags", ] +[[package]] +name = "redox_syscall" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "567664f262709473930a4bf9e51bf2ebf3348f2e748ccc50dea20646858f8f29" +dependencies = [ + "bitflags", +] + [[package]] name = "redox_users" version = "0.4.3" @@ -1366,7 +1886,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b033d837a7cf162d7993aded9304e30a83213c648b6e389db233191f891e5c2b" dependencies = [ "getrandom", - "redox_syscall", + "redox_syscall 0.2.16", "thiserror", ] @@ -1396,6 +1916,40 @@ dependencies = [ "winapi 0.3.9", ] +[[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.1" @@ -1427,7 +1981,62 @@ checksum = "43ce8670a1a1d0fc2514a3b846dacdb65646f9bd494b6674cfacbb4ce430bd7e" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.107", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" + +[[package]] +name = "rustc_version" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" +dependencies = [ + "semver 0.9.0", +] + +[[package]] +name = "rustc_version" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" +dependencies = [ + "semver 1.0.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 = "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]] @@ -1475,24 +2084,64 @@ version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ddccb15bcce173023b3fedd9436f882a0739b8dfb45e4f6b6002bee5929f61b2" +[[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.152" +version = "1.0.174" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb7d1f0d3021d347a83e556fc4683dea2ea09d87bccdf88ff5c12545d89d5efb" +checksum = "3b88756493a5bd5e5395d53baa70b194b05764ab85b59e43e4b8f4e1192fa9b1" 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.152" +version = "1.0.174" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af487d118eecd09402d70a5d72551860e788df87b464af30e5ea6a38c75c541e" +checksum = "6e5c3a298c7f978e53536f95a63bdc4c4a64550582f31a0359a9afda6aede62e" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.27", ] [[package]] @@ -1501,11 +2150,45 @@ version = "1.0.91" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "877c235533714907a8c2464236f5c4b2a17262ef1bd71f38f35ea592c8da6883" dependencies = [ + "indexmap", "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.107", +] + +[[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 = "sha1" version = "0.10.5" @@ -1528,12 +2211,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" @@ -1543,6 +2244,32 @@ 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" @@ -1557,6 +2284,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.4" @@ -1572,6 +2305,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" @@ -1594,7 +2337,7 @@ dependencies = [ "proc-macro2", "quote", "rustversion", - "syn", + "syn 1.0.107", ] [[package]] @@ -1614,6 +2357,23 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "syn" +version = "2.0.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b60f673f44a8255b9c8c657daf66a596d435f2da81a555b06dc644d080ba45e0" +dependencies = [ + "proc-macro2", + "quote", + "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" @@ -1638,7 +2398,7 @@ dependencies = [ "cfg-if 1.0.0", "fastrand", "libc", - "redox_syscall", + "redox_syscall 0.2.16", "remove_dir_all", "winapi 0.3.9", ] @@ -1697,7 +2457,7 @@ checksum = "1fb327af4685e4d03fa8cbcf1716380da910eeb2bb8be417e7f9fd3fb164f36f" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.107", ] [[package]] @@ -1709,6 +2469,159 @@ dependencies = [ "once_cell", ] +[[package]] +name = "time" +version = "0.3.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59e399c068f43a5d116fedaf73b203fa4f9c519f17e2b34f63221d3792f81446" +dependencies = [ + "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.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96ba15a897f3c86766b757e5ac7221554c6750054d74d5b28844fce5fb36a6c4" +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.29.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "532826ff75199d5833b9d2c5fe410f29235e25704ee5f0ef599fb51c21f4a4da" +dependencies = [ + "autocfg", + "backtrace", + "bytes", + "libc", + "mio", + "num_cpus", + "pin-project-lite", + "signal-hook-registry", + "socket2 0.4.9", + "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.27", +] + +[[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.107", +] + [[package]] name = "typenum" version = "1.16.0" @@ -1780,18 +2693,50 @@ 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.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "84a22b9f218b40614adcb3f4ff08b703773ad44fa9423e4e0d346d5db86e4ebc" +[[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.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d68c799ae75762b8c3fe375feb6600ef5602c883c5d21eb51c09f22b83c4643" +dependencies = [ + "form_urlencoded", + "idna 0.3.0", + "percent-encoding", +] + [[package]] name = "uuid" version = "1.3.0" @@ -1878,7 +2823,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn", + "syn 1.0.107", "wasm-bindgen-shared", ] @@ -1900,7 +2845,7 @@ checksum = "07bc0c051dc5f23e307b13285f9d75df86bfdf816c5721e573dec1f9b8aa193c" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.107", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -1961,6 +2906,41 @@ dependencies = [ "wasm-encoder", ] +[[package]] +name = "web-sys" +version = "0.3.60" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bcda906d8be16e728fd5adc5b729afad4e444e106ab28cd1c7256e54fa61510f" +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" @@ -2136,6 +3116,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" @@ -2154,3 +3144,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#c7b44c3eaff72455eadb9d43b0fcfb78f8a53aae" +dependencies = [ + "ark-std", + "clap", + "ff", + "halo2_proofs", + "halo2aggregator-s", + "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 fd9ff58f0..73505ad2e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,7 +15,9 @@ ark-std = { version = "0.3.0", features = ["print-trace"] } downcast-rs = "1.2.0" env_logger = "0.9.3" halo2aggregator-s = { git = "https://github.com/DelphinusLab/halo2aggregator-s.git", tag = "bisect-lookup-0.3.2", features = ["unsafe"] } +ff = "0.12" halo2_proofs = { git = "https://github.com/junyu0312/halo2", branch = "gpu", default-features = true } +poseidon = { git = "https://github.com/lanbones/poseidon" } log = "0.4.17" md5 = "0.7.0" num-integer = "0.1" @@ -37,6 +39,11 @@ uuid = { version = "1.2.2", features = ["serde", "v4"] } serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" bitvec = "1.0.1" +quote = "1.0.25" + +# 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/ctest/arith.wasm b/ctest/arith.wasm new file mode 100755 index 0000000000000000000000000000000000000000..cfccae5812d8deb432ff7cdb55c3cf4570fe2e16 GIT binary patch literal 129 zcmXAgK?=e!6hvo!YAP*A!JW7Wy-C*|!gi5Gltde?MHj}UH}RTA+{}ab7z`Ir09>h_ ziO)Rf!6ZhM4Yz8}eec3~x&l8@MmtU}T2KjPQIH~fnV;S3UDV}Tw732g?*jce`oRTA UwdIDAIyU&U_=CHKh6acF3;r${-v9sr literal 0 HcmV?d00001 diff --git a/ctest/batchinput.wasm b/ctest/batchinput.wasm new file mode 100755 index 0000000000000000000000000000000000000000..2aa0c495b31561027f5d5a9d7dd59d779173cc1c GIT binary patch literal 135 zcmZQbEY4+QU|?Y6V@_bKX8>Zxx&#KsdL{)X=G440_M+6n(#)b%1_lt1s~o60J~OYN zw1k0?nTe5!m4%U!iHVH^sLQdTgN2)2n29YnH8;Pgl8J$>DmynZGmn9ZONmi|!I43L S(WwCn>YL$A#y|m}95(>@ogk(F literal 0 HcmV?d00001 diff --git a/ctest/bls.c b/ctest/bls.c new file mode 100644 index 000000000..58623bd6c --- /dev/null +++ b/ctest/bls.c @@ -0,0 +1,195 @@ +#include + +void blspair_g1(uint64_t x); +void blspair_g2(uint64_t x); +uint64_t blspair_pop(void); + +void blssum_g1(uint64_t x); +uint64_t blssum_pop(void); + +void blspair(uint64_t* g1, uint64_t* g2, uint64_t* g3) { + int i; + for(i=0;i<17;i++) { + blspair_g1(g1[i]); + } + for(i=0;i<33;i++) { + blspair_g2(g1[i]); + } + for(i=0;i<48;i++) { + g3[i] = blspair_pop(); + } +} + +void blssum(uint32_t size, uint64_t* g1, uint64_t *gr) { + int i; + for (i=0; i#@ECC$~nkYruic}+NNr#qFghuTUi_#)uvWWhY-?PxsO}HgZlT1_(+`4<|TG0iSx02Uuk~E z3m9c)6Qzt6}TmdYL8G9~&9H$cW|AP%Jt)Ow5igEB$C?O3Ix)M8f%PG9<`h z5+husW5gPZSSesX&>Vd9Zn>ywHuM4CU3E;_qx_HGpLi%KY-v za;=zgVhQg3jDVrnr?0( @@ -72,6 +83,14 @@ pub fn compile_image<'a>( let wasm_runtime_io = register_wasm_input_foreign(&mut env, vec![], vec![]); register_require_foreign(&mut env); register_log_foreign(&mut env); + register_kvpair_foreign(&mut env); + register_blspair_foreign(&mut env); + register_blssum_foreign(&mut env); + register_bn254pair_foreign(&mut env); + register_bn254sum_foreign(&mut env); + register_sha256_foreign(&mut env); + register_poseidon_foreign(&mut env); + register_babyjubjubsum_foreign(&mut env); env.finalize(); let imports = ImportsBuilder::new().with_resolver("env", &env); @@ -104,7 +123,6 @@ pub fn build_circuit_without_witness( let module = wasmi::Module::from_buffer(wasm_binary).expect("failed to load wasm"); let (wasm_runtime_io, compiled_module) = compile_image(&module, function_name); - let builder = ZkWasmCircuitBuilder { tables: Tables { compilation_tables: compiled_module.tables, diff --git a/src/foreign/ecc_helper/bls381/mod.rs b/src/foreign/ecc_helper/bls381/mod.rs new file mode 100644 index 000000000..4c4f71292 --- /dev/null +++ b/src/foreign/ecc_helper/bls381/mod.rs @@ -0,0 +1,58 @@ +pub mod sum; +pub mod pair; +use num_bigint::BigUint; +use ark_std::Zero; +use std::ops::AddAssign; +use num_traits::FromPrimitive; +use halo2_proofs::arithmetic::CurveAffine; +use halo2_proofs::pairing::bls12_381::{G1Affine, + Fp2 as Bls381Fq2, + Fq as Bls381Fq, +}; + +use super::{ + bn_to_field, 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/src/foreign/ecc_helper/bls381/pair/mod.rs b/src/foreign/ecc_helper/bls381/pair/mod.rs new file mode 100644 index 000000000..11d4dce68 --- /dev/null +++ b/src/foreign/ecc_helper/bls381/pair/mod.rs @@ -0,0 +1,137 @@ +use std::rc::Rc; +use crate::runtime::host::{host_env::HostEnv, ForeignContext}; +use halo2_proofs::arithmetic::CurveAffine; +use halo2_proofs::pairing::bls12_381::{G1Affine, G2Affine, + Gt as Bls381Gt, + pairing, +}; +use super::{ + bls381_fq_to_limbs, + fetch_fq, + fetch_fq2, +}; +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); + println!("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/src/foreign/ecc_helper/bls381/sum/mod.rs b/src/foreign/ecc_helper/bls381/sum/mod.rs new file mode 100644 index 000000000..7dce4f922 --- /dev/null +++ b/src/foreign/ecc_helper/bls381/sum/mod.rs @@ -0,0 +1,93 @@ +use std::ops::Add; +use std::rc::Rc; +use crate::runtime::host::{host_env::HostEnv, ForeignContext}; +use halo2_proofs::pairing::bls12_381::G1Affine; + +use super::{ + bls381_fq_to_limbs, + 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/src/foreign/ecc_helper/bn254/mod.rs b/src/foreign/ecc_helper/bn254/mod.rs new file mode 100644 index 000000000..38527242d --- /dev/null +++ b/src/foreign/ecc_helper/bn254/mod.rs @@ -0,0 +1,59 @@ +pub mod sum; +pub mod pair; +use num_bigint::BigUint; +use halo2_proofs::pairing::bn256::{ + Fq2 as BN254Fq2, + Fq as BN254Fq, + G1Affine, +}; +use ark_std::Zero; +use std::ops::{AddAssign, Shl}; +use num_traits::FromPrimitive; +use halo2_proofs::arithmetic::CurveAffine; + +const LIMBSZ:usize = 54; +const LIMBNB:usize = 6; + +use super::{bn_to_field, field_to_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), + } +} + +fn fetch_g1(limbs: &Vec, g1_identity: bool) -> G1Affine { + if g1_identity { + 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/src/foreign/ecc_helper/bn254/pair/mod.rs b/src/foreign/ecc_helper/bn254/pair/mod.rs new file mode 100644 index 000000000..71136d74b --- /dev/null +++ b/src/foreign/ecc_helper/bn254/pair/mod.rs @@ -0,0 +1,157 @@ +use std::rc::Rc; +use crate::runtime::host::{host_env::HostEnv, ForeignContext}; +use halo2_proofs::arithmetic::CurveAffine; +use halo2_proofs::pairing::bn256::{G1Affine, G2Affine, + Gt as BN254Gt, + pairing, +}; +use halo2_proofs::pairing::group::prime::PrimeCurveAffine; + +use super::{ + LIMBNB, + bn254_fq_to_limbs, + fetch_fq, + fetch_fq2, +}; + +use zkwasm_host_circuits::host::ForeignInst::{ + Bn254PairG1, + Bn254PairG2, + 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 + )); + //println!("\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(); + println!("\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/src/foreign/ecc_helper/bn254/sum/mod.rs b/src/foreign/ecc_helper/bn254/sum/mod.rs new file mode 100644 index 000000000..cc8b19e3d --- /dev/null +++ b/src/foreign/ecc_helper/bn254/sum/mod.rs @@ -0,0 +1,118 @@ +use std::ops::Add; +use std::rc::Rc; +use crate::runtime::host::{host_env::HostEnv, ForeignContext}; +use halo2_proofs::pairing::bn256::{Fr, G1Affine}; +use halo2_proofs::pairing::group::prime::PrimeCurveAffine; + +use zkwasm_host_circuits::host::ForeignInst::{ + Bn254SumG1, Bn254SumResult, +}; + +use super::{ + LIMBNB, + bn254_fq_to_limbs, + fetch_g1, +}; + +fn fetch_fr(_limbs: &Vec) -> Fr { + //todo!(); + Fr::one() +} + + + +#[derive(Default)] +struct BN254SumContext { + pub limbs: Vec, + pub coeffs: Vec, + pub g1_identity: Vec, + pub result_limbs: Option>, + pub result_cursor: usize, + pub input_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]); + } + } +} + +impl ForeignContext for BN254SumContext {} + +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( + "bn254msm_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(); + if context.input_cursor < LIMBNB*2 { + context.limbs.push(args.nth(0)); + context.input_cursor += 1; + } else if context.input_cursor == LIMBNB*2 { + let t:u64 = args.nth(0); + context.g1_identity.push(t != 0); + context.input_cursor += 1; + } else if context.input_cursor == LIMBNB*2 + 4 { + context.coeffs.push(args.nth(0)); + context.input_cursor = 0; + } else { + context.coeffs.push(args.nth(0)); + context.input_cursor += 1; + } + None + }, + ), + ); + + env.external_env.register_function( + "bn254msm_pop", + Bn254SumResult as usize, + ExternalHostCallSignature::Return, + foreign_bn254sum_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(LIMBNB*2) + .zip(context.coeffs.chunks(4)) + .zip(context.g1_identity.clone()).map(|((limbs, coeffs), identity)| { + let coeff = fetch_fr(&coeffs.to_vec()); + let g1 = fetch_g1(&limbs.to_vec(), identity); + //println!("coeff is {:?}", coeff); + (g1 * coeff).into() + }).collect::>(); + let g1result = fqs[1..fqs.len()].into_iter().fold(fqs[0], |acc:G1Affine, x| { + let acc = acc.add(x.clone()).into(); + acc + }); + //println!("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/src/foreign/ecc_helper/jubjub/mod.rs b/src/foreign/ecc_helper/jubjub/mod.rs new file mode 100644 index 000000000..37b6bb798 --- /dev/null +++ b/src/foreign/ecc_helper/jubjub/mod.rs @@ -0,0 +1,44 @@ +pub mod sum; +use num_bigint::BigUint; +use halo2_proofs::pairing::bn256::{ + Fr as BabyJubjubFq, +}; +use ark_std::Zero; +use std::ops::{AddAssign, Shl}; +use num_traits::FromPrimitive; +use zkwasm_host_circuits::host::jubjub; + +const LIMBSZ:usize = 64; +const LIMBNB:usize = 4; + +use super::{bn_to_field, 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/src/foreign/ecc_helper/jubjub/sum/mod.rs b/src/foreign/ecc_helper/jubjub/sum/mod.rs new file mode 100644 index 000000000..cb2008814 --- /dev/null +++ b/src/foreign/ecc_helper/jubjub/sum/mod.rs @@ -0,0 +1,141 @@ +use std::rc::Rc; +use crate::runtime::host::{host_env::HostEnv, ForeignContext}; +use num_bigint::BigUint; + +use zkwasm_host_circuits::host::ForeignInst::{ + JubjubSumNew, JubjubSumPush, JubjubSumResult, +}; + +use zkwasm_host_circuits::host::jubjub; + +use super::{ + LIMBNB, + babyjubjub_fq_to_limbs, + fetch_g1, +}; + +fn fetch_biguint(_limbs: &Vec) -> BigUint { + BigUint::from_bytes_le(_limbs.iter().map(|x| x.to_le_bytes()).flatten().collect::>().as_slice()) +} + + + +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 { + fn default() -> Self { + BabyJubjubSumContext { + acc: jubjub::Point::identity(), + limbs: vec![], + coeffs: vec![], + result_limbs: None, + result_cursor: 0, + input_cursor: 0, + } + } +} + + +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.result_limbs = None; + context.result_cursor = 0; + context.limbs = vec![]; + context.input_cursor = 0; + context.coeffs = vec![]; + let new = args.nth::(0) as usize; + if new != 0 { + context.acc = jubjub::Point::identity(); + } + 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(); + if context.input_cursor < LIMBNB*2 { + context.limbs.push(args.nth(0)); + context.input_cursor += 1; + } else if context.input_cursor < LIMBNB*2 + 4 { + context.coeffs.push(args.nth(0)); + context.input_cursor += 1; + if context.input_cursor == LIMBNB*2 + 4 { + context.input_cursor = 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 limbs = context.result_limbs.clone(); + match limbs { + None => { + assert!(context.limbs.len() == LIMBNB*2); + let coeff = fetch_biguint(&context.coeffs.to_vec()); + let g1 = fetch_g1(&context.limbs.to_vec()); + println!("acc is {:?}", context.acc); + println!("g1 is {:?}", g1); + println!("coeff is {:?} {}", coeff, context.coeffs.len()); + context.acc = context.acc.projective().add(&g1.mul_scalar(&coeff).projective()).affine(); + println!("msm result: {:?}", context.acc); + context.babyjubjub_result_to_limbs(context.acc.clone()); + }, + _ => {()} + }; + let ret = Some(wasmi::RuntimeValue::I64( + context.result_limbs.as_ref().unwrap()[context.result_cursor] + as i64 + )); + context.result_cursor += 1; + ret + }, + ), + ); +} diff --git a/src/foreign/ecc_helper/mod.rs b/src/foreign/ecc_helper/mod.rs new file mode 100644 index 000000000..5acd05f01 --- /dev/null +++ b/src/foreign/ecc_helper/mod.rs @@ -0,0 +1,22 @@ +pub mod bn254; +pub mod bls381; +pub mod jubjub; +pub mod test; + +use num_bigint::BigUint; +use halo2_proofs::arithmetic::BaseExt; + +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/src/foreign/ecc_helper/test.rs b/src/foreign/ecc_helper/test.rs new file mode 100644 index 000000000..062f4cd18 --- /dev/null +++ b/src/foreign/ecc_helper/test.rs @@ -0,0 +1,103 @@ +#[cfg(test)] +pub(crate) mod tests { + use halo2_proofs::arithmetic::CurveAffine; + use halo2_proofs::pairing::bn256::{G1Affine, G2Affine, Fq2, pairing}; + use super::super::bn_to_field; + 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/src/foreign/hash_helper/mod.rs b/src/foreign/hash_helper/mod.rs new file mode 100644 index 000000000..6105ffad8 --- /dev/null +++ b/src/foreign/hash_helper/mod.rs @@ -0,0 +1,2 @@ +pub mod sha256; +pub mod poseidon; diff --git a/src/foreign/hash_helper/poseidon.rs b/src/foreign/hash_helper/poseidon.rs new file mode 100644 index 000000000..09415c3b5 --- /dev/null +++ b/src/foreign/hash_helper/poseidon.rs @@ -0,0 +1,152 @@ +use std::rc::Rc; +use crate::runtime::host::{host_env::HostEnv, ForeignContext}; +use halo2_proofs::pairing::bn256::Fr; +use ff::PrimeField; +use poseidon::Poseidon; +use zkwasm_host_circuits::host::poseidon::POSEIDON_HASHER; + +use zkwasm_host_circuits::host::{ + Reduce, ReduceRule +}; + + +use zkwasm_host_circuits::host::ForeignInst::{ + PoseidonNew, + PoseidonPush, + PoseidonFinalize, +}; + +/// 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 { + fn gen(&mut self) -> u64 { + let r = self.values[self.cursor]; + self.cursor += 1; + if self.cursor == 4 { + self.cursor = 0; + } + r + } +} + +fn new_reduce(rules: Vec>) -> Reduce { + Reduce { + cursor: 0, + rules + } +} + +struct PoseidonContext { + pub hasher: Option>, + pub generator: Generator, + pub buf: Vec, + pub fieldreducer:Reduce, +} + +impl PoseidonContext { + fn default() -> Self { + PoseidonContext { + hasher: None, + fieldreducer:new_reduce(vec![ReduceRule::Field(Fr::zero(), 64)]), + buf: vec![], + generator: Generator { + cursor: 0, + values: vec![], + }, + } + } +} + + +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(); + println!("buf len is {}", context.buf.len()); + context.buf = vec![]; + let new = args.nth::(0) as usize; + if new != 0 { + context.hasher = Some(POSEIDON_HASHER.clone()); + } + 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.fieldreducer.reduce(args.nth::(0) as u64); + if context.fieldreducer.cursor == 0 { + context.buf.push(context.fieldreducer.rules[0].field_value().unwrap()) + } + 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(); + assert!(context.buf.len() == 8); + if context.generator.cursor == 0 { + context.hasher.as_ref().map(|s| { + println!("perform hash with {:?}", context.buf); + let r = s.clone().update_exact(&context.buf.clone().try_into().unwrap()); + let dwords:Vec = r.to_repr().to_vec(); + context.generator.values = dwords.chunks(8).map(|x| { + u64::from_le_bytes(x.to_vec().try_into().unwrap()) + }).collect::>(); + }); + } + Some(wasmi::RuntimeValue::I64(context.generator.gen() as i64)) + }, + ), + ); +} diff --git a/src/foreign/hash_helper/sha256.rs b/src/foreign/hash_helper/sha256.rs new file mode 100644 index 000000000..b7436cb96 --- /dev/null +++ b/src/foreign/hash_helper/sha256.rs @@ -0,0 +1,149 @@ +use std::rc::Rc; +use crate::runtime::host::{host_env::HostEnv, ForeignContext}; +use sha2::Digest; +use zkwasm_host_circuits::host::ForeignInst::{ + SHA256New, + SHA256Push, + SHA256Finalize, +}; + +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/src/foreign/kv_helper/kvpair.rs b/src/foreign/kv_helper/kvpair.rs new file mode 100644 index 000000000..909c3a117 --- /dev/null +++ b/src/foreign/kv_helper/kvpair.rs @@ -0,0 +1,179 @@ +use std::rc::Rc; +use crate::runtime::host::{host_env::HostEnv, ForeignContext}; +use zkwasm_host_circuits::host::merkle::MerkleTree; +use zkwasm_host_circuits::host::{ + kvpair as kvpairhelper, + Reduce, ReduceRule +}; +use zkwasm_host_circuits::host::ForeignInst::{ + KVPairSet, + KVPairGet, + KVPairAddress, + KVPairGetRoot, + KVPairSetRoot, +}; + +use halo2_proofs::pairing::bn256::Fr; + +const MERKLE_TREE_HEIGHT:usize = 20; + +struct KVPairContext { + pub set_root: Reduce, + pub get_root: Reduce, + pub address: Reduce, + pub set: Reduce, + pub get: Reduce, + pub mongo_merkle: Option>, +} + +fn new_reduce(rules: Vec>) -> Reduce { + Reduce { + cursor: 0, + rules + } +} + +impl KVPairContext { + fn default() -> Self { + KVPairContext { + 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), + ]), + + mongo_merkle: None, + } + } +} + +impl KVPairContext {} + +impl ForeignContext for KVPairContext {} + +use specs::external_host_call_table::ExternalHostCallSignature; +pub fn register_kvpair_foreign(env: &mut HostEnv) { + let foreign_kvpair_plugin = env + .external_env + .register_plugin("foreign_kvpair", Box::new(KVPairContext::default())); + + env.external_env.register_function( + "kvpair_setroot", + KVPairSetRoot as usize, + ExternalHostCallSignature::Argument, + foreign_kvpair_plugin.clone(), + Rc::new( + |context: &mut dyn ForeignContext, args: wasmi::RuntimeArgs| { + let context = context.downcast_mut::().unwrap(); + context.set_root.reduce(args.nth(0)); + if context.set_root.cursor == 0 { + println!("set root: {:?}", &context.set_root.rules[0].bytes_value()); + context.mongo_merkle = Some( + kvpairhelper::MongoMerkle::construct( + [0;32], + context.set_root.rules[0].bytes_value() + .unwrap() + .try_into() + .unwrap() + ) + ); + } + None + }, + ), + ); + + env.external_env.register_function( + "kvpair_getroot", + KVPairGetRoot as usize, + ExternalHostCallSignature::Return, + foreign_kvpair_plugin.clone(), + Rc::new( + |context: &mut dyn ForeignContext, _args: wasmi::RuntimeArgs| { + let context = context.downcast_mut::().unwrap(); + let mt = context.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 = context.get_root.cursor; + context.get_root.reduce(values[context.get_root.cursor]); + Some(wasmi::RuntimeValue::I64(values[cursor] as i64)) + }, + ), + ); + + env.external_env.register_function( + "kvpair_address", + KVPairAddress as usize, + ExternalHostCallSignature::Argument, + foreign_kvpair_plugin.clone(), + Rc::new( + |context: &mut dyn ForeignContext, args: wasmi::RuntimeArgs| { + let context = context.downcast_mut::().unwrap(); + context.address.reduce(args.nth(0)); + None + }, + ), + ); + + + env.external_env.register_function( + "kvpair_set", + KVPairSet as usize, + ExternalHostCallSignature::Argument, + foreign_kvpair_plugin.clone(), + Rc::new( + |context: &mut dyn ForeignContext, args: wasmi::RuntimeArgs| { + let context = context.downcast_mut::().unwrap(); + context.set.reduce(args.nth(0)); + if context.set.cursor == 0 { + let address = context.address.rules[0].u64_value().unwrap() as u32; + let index = (address as u32) + (1u32<().unwrap(); + let address = context.address.rules[0].u64_value().unwrap() as u32; + let index = (address as u32) + (1u32< { @@ -51,6 +64,15 @@ impl HostEnv { 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_kvpair_foreign(&mut env); + register_blspair_foreign(&mut env); + register_blssum_foreign(&mut env); + register_bn254pair_foreign(&mut env); + register_bn254sum_foreign(&mut env); + register_sha256_foreign(&mut env); + register_poseidon_foreign(&mut env); + register_babyjubjubsum_foreign(&mut env); + env.finalize(); (env, wasm_runtime_io) diff --git a/test_bls.sh b/test_bls.sh new file mode 100755 index 000000000..d799d633d --- /dev/null +++ b/test_bls.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +set -e +set -x + +# rm -rf output + +# Single test +RUST_LOG=info cargo run --release -- -k 20 --function zkmain --output ./output --wasm ctest/bls.wasm setup + +RUST_LOG=info cargo run --release -- -k 20 --function zkmain --output ./output --wasm ctest/bls.wasm single-prove +RUST_LOG=info cargo run --release -- -k 20 --function zkmain --output ./output --wasm ctest/bls.wasm single-verify --proof output/zkwasm.0.transcript.data +RUST_LOG=info cargo run --release -- -k 20 --function zkmain --output ./output --wasm ctest/bls.wasm aggregate-prove +RUST_LOG=info cargo run --release -- -k 20 --function zkmain --output ./output --wasm ctest/bls.wasm aggregate-verify --proof output/aggregate-circuit.0.transcript.data --instances output/aggregate-circuit.0.instance.data From ebd777cca42fab63919044d05868c9c97f023cf0 Mon Sep 17 00:00:00 2001 From: cwbhhjl Date: Wed, 19 Jul 2023 21:59:26 +0800 Subject: [PATCH 02/35] expose poseidon, merkle and babyjubjub --- src/foreign/ecc_helper/jubjub/sum/mod.rs | 91 ++++++++++--------- src/foreign/hash_helper/poseidon.rs | 59 ++++++++----- src/foreign/kv_helper/kvpair.rs | 107 ++++++++++++++--------- 3 files changed, 150 insertions(+), 107 deletions(-) diff --git a/src/foreign/ecc_helper/jubjub/sum/mod.rs b/src/foreign/ecc_helper/jubjub/sum/mod.rs index cb2008814..372ab5c8a 100644 --- a/src/foreign/ecc_helper/jubjub/sum/mod.rs +++ b/src/foreign/ecc_helper/jubjub/sum/mod.rs @@ -20,7 +20,7 @@ fn fetch_biguint(_limbs: &Vec) -> BigUint { -struct BabyJubjubSumContext { +pub struct BabyJubjubSumContext { pub acc: jubjub::Point, pub limbs: Vec, pub coeffs: Vec, @@ -30,7 +30,7 @@ struct BabyJubjubSumContext { } impl BabyJubjubSumContext { - fn default() -> Self { + pub fn default() -> Self { BabyJubjubSumContext { acc: jubjub::Point::identity(), limbs: vec![], @@ -40,8 +40,53 @@ impl BabyJubjubSumContext { 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()); + println!("acc is {:?}", self.acc); + println!("g1 is {:?}", g1); + println!("coeff is {:?} {}", coeff, self.coeffs.len()); + self.acc = self.acc.projective().add(&g1.mul_scalar(&coeff).projective()).affine(); + println!("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) { @@ -68,21 +113,12 @@ pub fn register_babyjubjubsum_foreign(env: &mut HostEnv) { Rc::new( |context: &mut dyn ForeignContext, args: wasmi::RuntimeArgs| { let context = context.downcast_mut::().unwrap(); - context.result_limbs = None; - context.result_cursor = 0; - context.limbs = vec![]; - context.input_cursor = 0; - context.coeffs = vec![]; - let new = args.nth::(0) as usize; - if new != 0 { - context.acc = jubjub::Point::identity(); - } + context.babyjubjub_sum_new(args.nth::(0) as usize); None }, ), ); - env.external_env.register_function( "babyjubjub_sum_push", JubjubSumPush as usize, @@ -91,16 +127,7 @@ pub fn register_babyjubjubsum_foreign(env: &mut HostEnv) { Rc::new( |context: &mut dyn ForeignContext, args: wasmi::RuntimeArgs| { let context = context.downcast_mut::().unwrap(); - if context.input_cursor < LIMBNB*2 { - context.limbs.push(args.nth(0)); - context.input_cursor += 1; - } else if context.input_cursor < LIMBNB*2 + 4 { - context.coeffs.push(args.nth(0)); - context.input_cursor += 1; - if context.input_cursor == LIMBNB*2 + 4 { - context.input_cursor = 0; - } - } + context.babyjubjub_sum_push(args.nth(0)); None }, ), @@ -114,26 +141,10 @@ pub fn register_babyjubjubsum_foreign(env: &mut HostEnv) { Rc::new( |context: &mut dyn ForeignContext, _args: wasmi::RuntimeArgs| { let context = context.downcast_mut::().unwrap(); - let limbs = context.result_limbs.clone(); - match limbs { - None => { - assert!(context.limbs.len() == LIMBNB*2); - let coeff = fetch_biguint(&context.coeffs.to_vec()); - let g1 = fetch_g1(&context.limbs.to_vec()); - println!("acc is {:?}", context.acc); - println!("g1 is {:?}", g1); - println!("coeff is {:?} {}", coeff, context.coeffs.len()); - context.acc = context.acc.projective().add(&g1.mul_scalar(&coeff).projective()).affine(); - println!("msm result: {:?}", context.acc); - context.babyjubjub_result_to_limbs(context.acc.clone()); - }, - _ => {()} - }; let ret = Some(wasmi::RuntimeValue::I64( - context.result_limbs.as_ref().unwrap()[context.result_cursor] + context.babyjubjub_sum_finalize() as i64 )); - context.result_cursor += 1; ret }, ), diff --git a/src/foreign/hash_helper/poseidon.rs b/src/foreign/hash_helper/poseidon.rs index 09415c3b5..7eefe5698 100644 --- a/src/foreign/hash_helper/poseidon.rs +++ b/src/foreign/hash_helper/poseidon.rs @@ -36,7 +36,7 @@ use zkwasm_host_circuits::host::ForeignInst::{ /// wasm_dbg(r[3]); /// } -struct Generator { +pub struct Generator { pub cursor: usize, pub values: Vec, } @@ -59,7 +59,7 @@ fn new_reduce(rules: Vec>) -> Reduce { } } -struct PoseidonContext { +pub struct PoseidonContext { pub hasher: Option>, pub generator: Generator, pub buf: Vec, @@ -67,7 +67,7 @@ struct PoseidonContext { } impl PoseidonContext { - fn default() -> Self { + pub fn default() -> Self { PoseidonContext { hasher: None, fieldreducer:new_reduce(vec![ReduceRule::Field(Fr::zero(), 64)]), @@ -78,6 +78,35 @@ impl PoseidonContext { }, } } + + 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_ref().map(|s| { + println!("perform hash with {:?}", self.buf); + let r = s.clone().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() + } } @@ -98,11 +127,7 @@ pub fn register_poseidon_foreign(env: &mut HostEnv) { |context: &mut dyn ForeignContext, args: wasmi::RuntimeArgs| { let context = context.downcast_mut::().unwrap(); println!("buf len is {}", context.buf.len()); - context.buf = vec![]; - let new = args.nth::(0) as usize; - if new != 0 { - context.hasher = Some(POSEIDON_HASHER.clone()); - } + context.poseidon_new(args.nth::(0) as usize); None }, ), @@ -116,10 +141,7 @@ pub fn register_poseidon_foreign(env: &mut HostEnv) { Rc::new( |context: &mut dyn ForeignContext, args: wasmi::RuntimeArgs| { let context = context.downcast_mut::().unwrap(); - context.fieldreducer.reduce(args.nth::(0) as u64); - if context.fieldreducer.cursor == 0 { - context.buf.push(context.fieldreducer.rules[0].field_value().unwrap()) - } + context.poseidon_push(args.nth::(0) as u64); None }, ), @@ -134,18 +156,7 @@ pub fn register_poseidon_foreign(env: &mut HostEnv) { Rc::new( |context: &mut dyn ForeignContext, _args: wasmi::RuntimeArgs| { let context = context.downcast_mut::().unwrap(); - assert!(context.buf.len() == 8); - if context.generator.cursor == 0 { - context.hasher.as_ref().map(|s| { - println!("perform hash with {:?}", context.buf); - let r = s.clone().update_exact(&context.buf.clone().try_into().unwrap()); - let dwords:Vec = r.to_repr().to_vec(); - context.generator.values = dwords.chunks(8).map(|x| { - u64::from_le_bytes(x.to_vec().try_into().unwrap()) - }).collect::>(); - }); - } - Some(wasmi::RuntimeValue::I64(context.generator.gen() as i64)) + Some(wasmi::RuntimeValue::I64(context.poseidon_finalize() as i64)) }, ), ); diff --git a/src/foreign/kv_helper/kvpair.rs b/src/foreign/kv_helper/kvpair.rs index 909c3a117..9ef294a99 100644 --- a/src/foreign/kv_helper/kvpair.rs +++ b/src/foreign/kv_helper/kvpair.rs @@ -17,7 +17,7 @@ use halo2_proofs::pairing::bn256::Fr; const MERKLE_TREE_HEIGHT:usize = 20; -struct KVPairContext { +pub struct KVPairContext { pub set_root: Reduce, pub get_root: Reduce, pub address: Reduce, @@ -34,7 +34,7 @@ fn new_reduce(rules: Vec>) -> Reduce { } impl KVPairContext { - fn default() -> Self { + pub fn default() -> Self { KVPairContext { set_root: new_reduce(vec![ ReduceRule::Bytes(vec![], 4), @@ -58,6 +58,63 @@ impl KVPairContext { mongo_merkle: None, } } + + pub fn kvpair_setroot(&mut self, v: u64) { + self.set_root.reduce(v); + if self.set_root.cursor == 0 { + println!("set root: {:?}", &self.set_root.rules[0].bytes_value()); + self.mongo_merkle = Some( + kvpairhelper::MongoMerkle::construct( + [0;32], + self.set_root.rules[0].bytes_value() + .unwrap() + .try_into() + .unwrap() + ) + ); + } + } + + pub fn kvpair_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 kvpair_address(&mut self, v: u64) { + self.address.reduce(v); + } + + pub fn kvpair_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 u32) + (1u32< u64 { + let address = self.address.rules[0].u64_value().unwrap() as u32; + let index = (address as u32) + (1u32<().unwrap(); - context.set_root.reduce(args.nth(0)); - if context.set_root.cursor == 0 { - println!("set root: {:?}", &context.set_root.rules[0].bytes_value()); - context.mongo_merkle = Some( - kvpairhelper::MongoMerkle::construct( - [0;32], - context.set_root.rules[0].bytes_value() - .unwrap() - .try_into() - .unwrap() - ) - ); - } + context.kvpair_setroot(args.nth(0)); None }, ), @@ -104,14 +149,7 @@ pub fn register_kvpair_foreign(env: &mut HostEnv) { Rc::new( |context: &mut dyn ForeignContext, _args: wasmi::RuntimeArgs| { let context = context.downcast_mut::().unwrap(); - let mt = context.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 = context.get_root.cursor; - context.get_root.reduce(values[context.get_root.cursor]); - Some(wasmi::RuntimeValue::I64(values[cursor] as i64)) + Some(wasmi::RuntimeValue::I64(context.kvpair_getroot() as i64)) }, ), ); @@ -124,7 +162,7 @@ pub fn register_kvpair_foreign(env: &mut HostEnv) { Rc::new( |context: &mut dyn ForeignContext, args: wasmi::RuntimeArgs| { let context = context.downcast_mut::().unwrap(); - context.address.reduce(args.nth(0)); + context.kvpair_address(args.nth(0)); None }, ), @@ -139,16 +177,7 @@ pub fn register_kvpair_foreign(env: &mut HostEnv) { Rc::new( |context: &mut dyn ForeignContext, args: wasmi::RuntimeArgs| { let context = context.downcast_mut::().unwrap(); - context.set.reduce(args.nth(0)); - if context.set.cursor == 0 { - let address = context.address.rules[0].u64_value().unwrap() as u32; - let index = (address as u32) + (1u32<().unwrap(); - let address = context.address.rules[0].u64_value().unwrap() as u32; - let index = (address as u32) + (1u32< Date: Wed, 19 Jul 2023 22:27:35 +0800 Subject: [PATCH 03/35] update gitignore --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index c92ab4826..969019b75 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ /target *.json /output + +.idea/ From 3b19d68afdbce4330b07ced3b036376c34617b64 Mon Sep 17 00:00:00 2001 From: "xingqiang.yuan" Date: Mon, 7 Aug 2023 17:53:20 +0800 Subject: [PATCH 04/35] use log::debug instead of println --- src/foreign/ecc_helper/bls381/pair/mod.rs | 2 +- src/foreign/ecc_helper/bn254/pair/mod.rs | 4 ++-- src/foreign/ecc_helper/jubjub/sum/mod.rs | 8 ++++---- src/foreign/hash_helper/poseidon.rs | 4 ++-- src/foreign/kv_helper/kvpair.rs | 2 +- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/foreign/ecc_helper/bls381/pair/mod.rs b/src/foreign/ecc_helper/bls381/pair/mod.rs index 11d4dce68..bc939ac16 100644 --- a/src/foreign/ecc_helper/bls381/pair/mod.rs +++ b/src/foreign/ecc_helper/bls381/pair/mod.rs @@ -109,7 +109,7 @@ pub fn register_blspair_foreign(env: &mut HostEnv) { } }; let ab = pairing(&g1, &g2); - println!("gt {:?}", ab); + log::debug!("gt {:?}", ab); context.bls381_gt_to_limbs(ab); } else { context.limbs.push(args.nth(0)); diff --git a/src/foreign/ecc_helper/bn254/pair/mod.rs b/src/foreign/ecc_helper/bn254/pair/mod.rs index 71136d74b..e3d087508 100644 --- a/src/foreign/ecc_helper/bn254/pair/mod.rs +++ b/src/foreign/ecc_helper/bn254/pair/mod.rs @@ -125,7 +125,7 @@ pub fn register_bn254pair_foreign(env: &mut HostEnv) { | | ab, |x| x + ab )); - //println!("\n\ngt is {:?}", context.gt); + //log::debug!("\n\ngt is {:?}", context.gt); } else { context.limbs.push(args.nth(0)); context.input_cursor += 1; @@ -145,7 +145,7 @@ pub fn register_bn254pair_foreign(env: &mut HostEnv) { let context = context.downcast_mut::().unwrap(); if context.result_cursor == 0 { let gt = context.gt.unwrap(); - println!("\n\ngt is {:?}", context.gt); + 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)); diff --git a/src/foreign/ecc_helper/jubjub/sum/mod.rs b/src/foreign/ecc_helper/jubjub/sum/mod.rs index 372ab5c8a..b4acee2d9 100644 --- a/src/foreign/ecc_helper/jubjub/sum/mod.rs +++ b/src/foreign/ecc_helper/jubjub/sum/mod.rs @@ -72,11 +72,11 @@ impl BabyJubjubSumContext { assert!(self.limbs.len() == LIMBNB*2); let coeff = fetch_biguint(&self.coeffs.to_vec()); let g1 = fetch_g1(&self.limbs.to_vec()); - println!("acc is {:?}", self.acc); - println!("g1 is {:?}", g1); - println!("coeff is {:?} {}", coeff, self.coeffs.len()); + 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(); - println!("msm result: {:?}", self.acc); + log::debug!("msm result: {:?}", self.acc); self.babyjubjub_result_to_limbs(self.acc.clone()); }, _ => {()} diff --git a/src/foreign/hash_helper/poseidon.rs b/src/foreign/hash_helper/poseidon.rs index 7eefe5698..a5bfc041c 100644 --- a/src/foreign/hash_helper/poseidon.rs +++ b/src/foreign/hash_helper/poseidon.rs @@ -97,7 +97,7 @@ impl PoseidonContext { assert!(self.buf.len() == 8); if self.generator.cursor == 0 { self.hasher.as_ref().map(|s| { - println!("perform hash with {:?}", self.buf); + log::debug!("perform hash with {:?}", self.buf); let r = s.clone().update_exact(&self.buf.clone().try_into().unwrap()); let dwords:Vec = r.to_repr().to_vec(); self.generator.values = dwords.chunks(8).map(|x| { @@ -126,7 +126,7 @@ pub fn register_poseidon_foreign(env: &mut HostEnv) { Rc::new( |context: &mut dyn ForeignContext, args: wasmi::RuntimeArgs| { let context = context.downcast_mut::().unwrap(); - println!("buf len is {}", context.buf.len()); + log::debug!("buf len is {}", context.buf.len()); context.poseidon_new(args.nth::(0) as usize); None }, diff --git a/src/foreign/kv_helper/kvpair.rs b/src/foreign/kv_helper/kvpair.rs index 9ef294a99..184470960 100644 --- a/src/foreign/kv_helper/kvpair.rs +++ b/src/foreign/kv_helper/kvpair.rs @@ -62,7 +62,7 @@ impl KVPairContext { pub fn kvpair_setroot(&mut self, v: u64) { self.set_root.reduce(v); if self.set_root.cursor == 0 { - println!("set root: {:?}", &self.set_root.rules[0].bytes_value()); + log::debug!("set root: {:?}", &self.set_root.rules[0].bytes_value()); self.mongo_merkle = Some( kvpairhelper::MongoMerkle::construct( [0;32], From bc5de39a635174ed003189de9841232b9b4fad65 Mon Sep 17 00:00:00 2001 From: Sinka Date: Sun, 30 Jul 2023 16:11:38 +1000 Subject: [PATCH 05/35] change kvpair helper to merkle helper and add kv cache --- Cargo.lock | 52 ++++- Cargo.toml | 2 +- src/cli/exec.rs | 4 +- src/foreign/kv_helper/kvpair.rs | 200 -------------------- src/foreign/kv_helper/mod.rs | 1 - src/foreign/merkle_helper/merkle.rs | 282 ++++++++++++++++++++++++++++ src/foreign/merkle_helper/mod.rs | 1 + src/foreign/mod.rs | 6 +- 8 files changed, 339 insertions(+), 209 deletions(-) delete mode 100644 src/foreign/kv_helper/kvpair.rs delete mode 100644 src/foreign/kv_helper/mod.rs create mode 100644 src/foreign/merkle_helper/merkle.rs create mode 100644 src/foreign/merkle_helper/mod.rs diff --git a/Cargo.lock b/Cargo.lock index 737986d9d..886d41ac3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -987,7 +987,7 @@ dependencies = [ [[package]] name = "halo2_proofs" version = "0.1.0-beta.1" -source = "git+https://github.com/junyu0312/halo2?branch=gpu#d641021e6813de5314469862c6c4be08d4a639fd" +source = "git+https://github.com/junyu0312/halo2?branch=gpu#e02af42177650c1df552f8a6614d4358621e067e" dependencies = [ "ark-std", "blake2b_simd", @@ -998,8 +998,11 @@ dependencies = [ "ec-gpu-gen", "ff", "group", + "num", "num-bigint", + "num-derive", "num-integer", + "num-traits", "pairing_bn256", "rand", "rand_core", @@ -1494,6 +1497,20 @@ dependencies = [ "windows-sys 0.45.0", ] +[[package]] +name = "num" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b05180d69e3da0e530ba2a1dae5110317e49e3b7f3d41be227dc5f92e49ee7af" +dependencies = [ + "num-bigint", + "num-complex", + "num-integer", + "num-iter", + "num-rational", + "num-traits", +] + [[package]] name = "num-bigint" version = "0.4.3" @@ -1506,6 +1523,26 @@ dependencies = [ "rand", ] +[[package]] +name = "num-complex" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02e0d21255c828d6f128a1e41534206671e8c3ea0c62f32291e808dc82cff17d" +dependencies = [ + "num-traits", +] + +[[package]] +name = "num-derive" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "876a53fff98e03a936a674b29568b0e605f06b29372c2489ff4de23f1949743d" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.107", +] + [[package]] name = "num-integer" version = "0.1.45" @@ -1516,6 +1553,17 @@ dependencies = [ "num-traits", ] +[[package]] +name = "num-iter" +version = "0.1.43" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d03e6c028c5dc5cac6e2dec0efda81fc887605bb3d884578bb6d6bf7514e252" +dependencies = [ + "autocfg", + "num-integer", + "num-traits", +] + [[package]] name = "num-rational" version = "0.4.1" @@ -3148,7 +3196,7 @@ dependencies = [ [[package]] name = "zkwasm-host-circuits" version = "0.1.0" -source = "git+https://github.com/DelphinusLab/zkWasm-host-circuits.git?branch=main#c7b44c3eaff72455eadb9d43b0fcfb78f8a53aae" +source = "git+https://github.com/DelphinusLab/zkWasm-host-circuits.git?branch=heng/poseidon-opt#34e81a3b44cf2f607b5fecdb91717cd15dff90ee" dependencies = [ "ark-std", "clap", diff --git a/Cargo.toml b/Cargo.toml index 73505ad2e..07c5b991e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -43,7 +43,7 @@ quote = "1.0.25" # TODO put the host circuits into features -zkwasm-host-circuits = { git = "https://github.com/DelphinusLab/zkWasm-host-circuits.git", branch="main" } +zkwasm-host-circuits = { git = "https://github.com/DelphinusLab/zkWasm-host-circuits.git", branch="heng/poseidon-opt" } [dev-dependencies] rusty-fork = "0.3.0" diff --git a/src/cli/exec.rs b/src/cli/exec.rs index 9d15ddeae..fafd7cbce 100644 --- a/src/cli/exec.rs +++ b/src/cli/exec.rs @@ -54,7 +54,7 @@ use crate::circuits::TestCircuit; use crate::circuits::ZkWasmCircuitBuilder; use crate::foreign::log_helper::register_log_foreign; use crate::foreign::require_helper::register_require_foreign; -use crate::foreign::kv_helper::kvpair::register_kvpair_foreign; +use crate::foreign::merkle_helper::merkle::register_merkle_foreign; use crate::foreign::wasm_input_helper::runtime::register_wasm_input_foreign; use crate::foreign::hash_helper::sha256::register_sha256_foreign; use crate::foreign::hash_helper::poseidon::register_poseidon_foreign; @@ -83,7 +83,7 @@ pub fn compile_image<'a>( let wasm_runtime_io = register_wasm_input_foreign(&mut env, vec![], vec![]); register_require_foreign(&mut env); register_log_foreign(&mut env); - register_kvpair_foreign(&mut env); + register_merkle_foreign(&mut env); register_blspair_foreign(&mut env); register_blssum_foreign(&mut env); register_bn254pair_foreign(&mut env); diff --git a/src/foreign/kv_helper/kvpair.rs b/src/foreign/kv_helper/kvpair.rs deleted file mode 100644 index 184470960..000000000 --- a/src/foreign/kv_helper/kvpair.rs +++ /dev/null @@ -1,200 +0,0 @@ -use std::rc::Rc; -use crate::runtime::host::{host_env::HostEnv, ForeignContext}; -use zkwasm_host_circuits::host::merkle::MerkleTree; -use zkwasm_host_circuits::host::{ - kvpair as kvpairhelper, - Reduce, ReduceRule -}; -use zkwasm_host_circuits::host::ForeignInst::{ - KVPairSet, - KVPairGet, - KVPairAddress, - KVPairGetRoot, - KVPairSetRoot, -}; - -use halo2_proofs::pairing::bn256::Fr; - -const MERKLE_TREE_HEIGHT:usize = 20; - -pub struct KVPairContext { - pub set_root: Reduce, - pub get_root: Reduce, - pub address: Reduce, - pub set: Reduce, - pub get: Reduce, - pub mongo_merkle: Option>, -} - -fn new_reduce(rules: Vec>) -> Reduce { - Reduce { - cursor: 0, - rules - } -} - -impl KVPairContext { - pub fn default() -> Self { - KVPairContext { - 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), - ]), - - mongo_merkle: None, - } - } - - pub fn kvpair_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( - kvpairhelper::MongoMerkle::construct( - [0;32], - self.set_root.rules[0].bytes_value() - .unwrap() - .try_into() - .unwrap() - ) - ); - } - } - - pub fn kvpair_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 kvpair_address(&mut self, v: u64) { - self.address.reduce(v); - } - - pub fn kvpair_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 u32) + (1u32< u64 { - let address = self.address.rules[0].u64_value().unwrap() as u32; - let index = (address as u32) + (1u32<().unwrap(); - context.kvpair_setroot(args.nth(0)); - None - }, - ), - ); - - env.external_env.register_function( - "kvpair_getroot", - KVPairGetRoot as usize, - ExternalHostCallSignature::Return, - foreign_kvpair_plugin.clone(), - Rc::new( - |context: &mut dyn ForeignContext, _args: wasmi::RuntimeArgs| { - let context = context.downcast_mut::().unwrap(); - Some(wasmi::RuntimeValue::I64(context.kvpair_getroot() as i64)) - }, - ), - ); - - env.external_env.register_function( - "kvpair_address", - KVPairAddress as usize, - ExternalHostCallSignature::Argument, - foreign_kvpair_plugin.clone(), - Rc::new( - |context: &mut dyn ForeignContext, args: wasmi::RuntimeArgs| { - let context = context.downcast_mut::().unwrap(); - context.kvpair_address(args.nth(0)); - None - }, - ), - ); - - - env.external_env.register_function( - "kvpair_set", - KVPairSet as usize, - ExternalHostCallSignature::Argument, - foreign_kvpair_plugin.clone(), - Rc::new( - |context: &mut dyn ForeignContext, args: wasmi::RuntimeArgs| { - let context = context.downcast_mut::().unwrap(); - context.kvpair_set(args.nth(0)); - None - }, - ), - ); - - - env.external_env.register_function( - "kvpair_get", - KVPairGet as usize, - ExternalHostCallSignature::Return, - foreign_kvpair_plugin.clone(), - Rc::new( - |context: &mut dyn ForeignContext, _args: wasmi::RuntimeArgs| { - let context = context.downcast_mut::().unwrap(); - let ret = Some(wasmi::RuntimeValue::I64(context.kvpair_get() as i64)); - ret - }, - ), - ); -} diff --git a/src/foreign/kv_helper/mod.rs b/src/foreign/kv_helper/mod.rs deleted file mode 100644 index dba00017c..000000000 --- a/src/foreign/kv_helper/mod.rs +++ /dev/null @@ -1 +0,0 @@ -pub mod kvpair; diff --git a/src/foreign/merkle_helper/merkle.rs b/src/foreign/merkle_helper/merkle.rs new file mode 100644 index 000000000..6721c03cc --- /dev/null +++ b/src/foreign/merkle_helper/merkle.rs @@ -0,0 +1,282 @@ +use std::rc::Rc; +use crate::runtime::host::{host_env::HostEnv, ForeignContext}; +use zkwasm_host_circuits::host::datahash::DataHashRecord; +use zkwasm_host_circuits::host::merkle::MerkleTree; +use zkwasm_host_circuits::host::{ + mongomerkle as merklehelper, + datahash as datahelper, + Reduce, ReduceRule +}; +use zkwasm_host_circuits::host::ForeignInst::{ + MerkleSet, + MerkleGet, + MerkleAddress, + MerkleGetRoot, + MerkleSetRoot, + MerklePutData, + MerkleFetchData, +}; + +use halo2_proofs::pairing::bn256::Fr; + +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, +} + +fn new_reduce(rules: Vec>) -> Reduce { + Reduce { + cursor: 0, + rules + } +} + +impl MerkleContext { + pub fn default() -> 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]), + } + } + + 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() + ) + ); + } + } + + 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<>(), + } + }).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<>().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) { + let foreign_merkle_plugin = env + .external_env + .register_plugin("foreign_merkle", Box::new(MerkleContext::default())); + + 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/src/foreign/merkle_helper/mod.rs b/src/foreign/merkle_helper/mod.rs new file mode 100644 index 000000000..bdf9eb8f3 --- /dev/null +++ b/src/foreign/merkle_helper/mod.rs @@ -0,0 +1 @@ +pub mod merkle; diff --git a/src/foreign/mod.rs b/src/foreign/mod.rs index 529179b09..307fb7082 100644 --- a/src/foreign/mod.rs +++ b/src/foreign/mod.rs @@ -22,12 +22,12 @@ use self::ecc_helper::{ }; use self::hash_helper::sha256::register_sha256_foreign; use self::hash_helper::poseidon::register_poseidon_foreign; -use self::kv_helper::kvpair::register_kvpair_foreign; +use self::merkle_helper::merkle::register_merkle_foreign; pub mod keccak_helper; pub mod log_helper; pub mod require_helper; -pub mod kv_helper; +pub mod merkle_helper; pub mod ecc_helper; pub mod hash_helper; pub mod wasm_input_helper; @@ -64,7 +64,7 @@ impl HostEnv { 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_kvpair_foreign(&mut env); + register_merkle_foreign(&mut env); register_blspair_foreign(&mut env); register_blssum_foreign(&mut env); register_bn254pair_foreign(&mut env); From 0860690be61ce2bb3e64259c4399dd0f23fe01a6 Mon Sep 17 00:00:00 2001 From: sinka Date: Mon, 7 Aug 2023 14:00:09 +1000 Subject: [PATCH 06/35] track main branch of host circuits --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/foreign/ecc_helper/bls381/pair/mod.rs | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 886d41ac3..eb9b81a54 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3196,7 +3196,7 @@ dependencies = [ [[package]] name = "zkwasm-host-circuits" version = "0.1.0" -source = "git+https://github.com/DelphinusLab/zkWasm-host-circuits.git?branch=heng/poseidon-opt#34e81a3b44cf2f607b5fecdb91717cd15dff90ee" +source = "git+https://github.com/DelphinusLab/zkWasm-host-circuits.git?branch=main#84a279670255bc1334540ce649f8098fb7f124d0" dependencies = [ "ark-std", "clap", diff --git a/Cargo.toml b/Cargo.toml index 07c5b991e..73505ad2e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -43,7 +43,7 @@ quote = "1.0.25" # TODO put the host circuits into features -zkwasm-host-circuits = { git = "https://github.com/DelphinusLab/zkWasm-host-circuits.git", branch="heng/poseidon-opt" } +zkwasm-host-circuits = { git = "https://github.com/DelphinusLab/zkWasm-host-circuits.git", branch="main" } [dev-dependencies] rusty-fork = "0.3.0" diff --git a/src/foreign/ecc_helper/bls381/pair/mod.rs b/src/foreign/ecc_helper/bls381/pair/mod.rs index bc939ac16..ccd06272b 100644 --- a/src/foreign/ecc_helper/bls381/pair/mod.rs +++ b/src/foreign/ecc_helper/bls381/pair/mod.rs @@ -62,7 +62,7 @@ pub fn register_blspair_foreign(env: &mut HostEnv) { env.external_env.register_function( "blspair_g1", - ForeignInst::BlspairG1 as usize, + ForeignInst::BlsPairG1 as usize, ExternalHostCallSignature::Argument, foreign_blspair_plugin.clone(), Rc::new( @@ -82,7 +82,7 @@ pub fn register_blspair_foreign(env: &mut HostEnv) { ); env.external_env.register_function( "blspair_g2", - ForeignInst::BlspairG2 as usize, + ForeignInst::BlsPairG2 as usize, ExternalHostCallSignature::Argument, foreign_blspair_plugin.clone(), Rc::new( @@ -122,7 +122,7 @@ pub fn register_blspair_foreign(env: &mut HostEnv) { env.external_env.register_function( "blspair_pop", - ForeignInst::BlspairG3 as usize, + ForeignInst::BlsPairG3 as usize, ExternalHostCallSignature::Return, foreign_blspair_plugin.clone(), Rc::new( From 384718f12af5f6dc10b470c1fb98e448f0fdf4b1 Mon Sep 17 00:00:00 2001 From: Zhang Junyu Date: Tue, 8 Aug 2023 20:52:06 +0800 Subject: [PATCH 07/35] chore: allow consecutive op index for plugin --- src/foreign/merkle_helper/merkle.rs | 1 - src/runtime/host/external_circuit_plugin.rs | 34 ++++++++++----------- src/runtime/host/host_env.rs | 9 +++--- 3 files changed, 20 insertions(+), 24 deletions(-) diff --git a/src/foreign/merkle_helper/merkle.rs b/src/foreign/merkle_helper/merkle.rs index 6721c03cc..dc3f8057e 100644 --- a/src/foreign/merkle_helper/merkle.rs +++ b/src/foreign/merkle_helper/merkle.rs @@ -110,7 +110,6 @@ impl MerkleContext { let index = (address as u64) + (1u64< Result { - for (name, function) in &self.functions { - if name == function_name { - if function.sig.match_wasmi_signature(signature) { - return Ok(FuncInstance::alloc_host( - signature.clone(), - function.op_index, - )); - } else { - return Err(wasmi::Error::Instantiation(format!( - "Export `{}` doesnt match expected type {:?}", - function_name, signature - ))); - } + if let Some(function) = self.functions.get(function_name) { + if function.sig.match_wasmi_signature(signature) { + Ok(FuncInstance::alloc_host( + signature.clone(), + function.op_index, + )) + } else { + Err(wasmi::Error::Instantiation(format!( + "Export `{}` doesnt match expected type {:?}", + function_name, signature + ))) } + } else { + Err(wasmi::Error::Instantiation(format!( + "Export {} not found", + function_name + ))) } - - return Err(wasmi::Error::Instantiation(format!( - "Export {} not found", - function_name - ))); } } diff --git a/src/runtime/host/host_env.rs b/src/runtime/host/host_env.rs index 4452d5085..2eabdb8cf 100644 --- a/src/runtime/host/host_env.rs +++ b/src/runtime/host/host_env.rs @@ -56,13 +56,10 @@ impl HostEnv { pub fn finalize(&mut self) { let mut lookup = HashMap::::new(); - let mut internal_op_allocator_offset = self.external_env.functions.len(); + let mut internal_op_allocator_offset = 0; for (name, op) in &self.external_env.functions { - assert!( - op.op_index < internal_op_allocator_offset, - "Specify op index too large." - ); + internal_op_allocator_offset = usize::max(internal_op_allocator_offset, op.op_index); lookup .insert( @@ -82,6 +79,8 @@ impl HostEnv { .map(|_| panic!("conflicting op index of foreign function")); } + internal_op_allocator_offset += 1; + for (name, op) in &mut self.internal_env.functions { op.index = Some(internal_op_allocator_offset); From d927ae218c611a77917acf53396c363fa99d17a0 Mon Sep 17 00:00:00 2001 From: "xingqiang.yuan" Date: Fri, 11 Aug 2023 12:00:37 +0800 Subject: [PATCH 08/35] avoid map clone --- src/runtime/host/host_env.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/runtime/host/host_env.rs b/src/runtime/host/host_env.rs index 2eabdb8cf..55d1eed34 100644 --- a/src/runtime/host/host_env.rs +++ b/src/runtime/host/host_env.rs @@ -154,18 +154,20 @@ impl Externals for HostEnv { index: usize, args: RuntimeArgs, ) -> Result, Trap> { - match self.cached_lookup.clone().unwrap().get_mut(&index) { - Some(function) => { - let ctx = function.execution_env.ctx.clone(); + match self.cached_lookup.as_ref().unwrap().get(&index).clone() { + Some(HostFunction { + desc, + execution_env: HostFunctionExecutionEnv { ctx, cb }, + }) => { let mut ctx = (*ctx).borrow_mut(); let ctx = ctx.as_mut(); let start = Instant::now(); - let r = (function.execution_env.cb)(ctx, args); + let r = cb(ctx, args); let duration = start.elapsed(); self.time_profile - .entry(function.desc.name().to_string()) + .entry(desc.name().to_string()) .and_modify(|d| *d += duration.as_millis()) .or_insert(duration.as_millis()); From f8dbf466457ca283b8eecea222f7e78e7c192e24 Mon Sep 17 00:00:00 2001 From: cwbhhjl Date: Wed, 16 Aug 2023 13:39:35 +0800 Subject: [PATCH 09/35] minor updates (#162) 1. expose a few pub apis 2. derive more serialization and descrialization stuff. --- crates/specs/src/brtable.rs | 8 +++---- crates/specs/src/configure_table.rs | 4 ++-- crates/specs/src/etable.rs | 6 ++--- .../specs/src/external_host_call_table/mod.rs | 4 ++-- crates/specs/src/host_function.rs | 6 ++--- crates/specs/src/imtable.rs | 6 ++--- crates/specs/src/itable.rs | 24 +++++++++---------- crates/specs/src/jtable.rs | 8 +++---- crates/specs/src/lib.rs | 6 ++--- crates/specs/src/mtable.rs | 16 ++++++------- crates/specs/src/step.rs | 4 ++-- crates/specs/src/types.rs | 4 ++-- crates/zkwasm/src/circuits/mod.rs | 18 +++++++++++++- .../src/foreign/hash_helper/poseidon.rs | 6 ++--- 14 files changed, 68 insertions(+), 52 deletions(-) diff --git a/crates/specs/src/brtable.rs b/crates/specs/src/brtable.rs index c6c3b3211..b1db371d9 100644 --- a/crates/specs/src/brtable.rs +++ b/crates/specs/src/brtable.rs @@ -1,8 +1,8 @@ use std::collections::BTreeMap; -use serde::Serialize; +use serde::{Serialize, Deserialize}; -#[derive(Serialize, Debug, Clone)] +#[derive(Serialize, Deserialize, Debug, Clone)] pub struct BrTableEntry { pub fid: u32, pub iid: u32, @@ -25,7 +25,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 +33,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 03b8e2cd8..64455b864 100644 --- a/crates/specs/src/configure_table.rs +++ b/crates/specs/src/configure_table.rs @@ -1,10 +1,10 @@ -use serde::Serialize; +use serde::{Serialize, Deserialize}; pub const WASM_PAGE_SIZE: u64 = 65536; 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..9f553d6b1 100644 --- a/crates/specs/src/etable.rs +++ b/crates/specs/src/etable.rs @@ -1,10 +1,10 @@ -use serde::Serialize; +use serde::{Serialize, Deserialize}; 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 +38,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..c02765cd5 100644 --- a/crates/specs/src/external_host_call_table/mod.rs +++ b/crates/specs/src/external_host_call_table/mod.rs @@ -1,5 +1,5 @@ use serde::ser::SerializeStruct; -use serde::Serialize; +use serde::{Deserialize, Serialize}; use crate::host_function::Signature; use crate::types::ValueType; @@ -7,7 +7,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..a3ea3868d 100644 --- a/crates/specs/src/host_function.rs +++ b/crates/specs/src/host_function.rs @@ -1,9 +1,9 @@ -use serde::Serialize; +use serde::{Deserialize, 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 +38,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..5c86622f2 100644 --- a/crates/specs/src/imtable.rs +++ b/crates/specs/src/imtable.rs @@ -2,9 +2,9 @@ use std::cmp::Ordering; use crate::mtable::LocationType; use crate::mtable::VarType; -use serde::Serialize; +use serde::{Serialize, Deserialize}; -#[derive(Serialize, Debug, Clone)] +#[derive(Serialize, Deserialize, Debug, Clone)] pub struct InitMemoryTableEntry { pub ltype: LocationType, pub is_mutable: bool, @@ -15,7 +15,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 c45fb24f4..60b1cffb2 100644 --- a/crates/specs/src/itable.rs +++ b/crates/specs/src/itable.rs @@ -15,7 +15,7 @@ use crate::mtable::MemoryReadSize; use crate::mtable::MemoryStoreSize; use crate::types::ValueType; use num_bigint::BigUint; -use serde::Serialize; +use serde::{Serialize, Deserialize}; use std::collections::HashSet; use strum_macros::EnumIter; @@ -105,14 +105,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, @@ -123,7 +123,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, @@ -132,7 +132,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, @@ -149,7 +149,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, @@ -163,26 +163,26 @@ 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, I64ExtendI32u, } -#[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, @@ -501,7 +501,7 @@ impl Into for Opcode { } } -#[derive(Clone, Debug, Serialize)] +#[derive(Clone, Debug, Serialize, Deserialize)] pub struct InstructionTableEntry { pub fid: u32, pub iid: u32, @@ -521,7 +521,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 630fe0326..6030688fe 100644 --- a/crates/specs/src/jtable.rs +++ b/crates/specs/src/jtable.rs @@ -1,7 +1,7 @@ use super::itable::InstructionTableEntry; -use serde::Serialize; +use serde::{Serialize, Deserialize}; -#[derive(Default, Serialize, Debug, Clone)] +#[derive(Default, Serialize, Deserialize, Debug, Clone)] pub struct StaticFrameEntry { pub frame_id: u32, pub next_frame_id: u32, @@ -10,7 +10,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, @@ -25,7 +25,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..104b341c5 100644 --- a/crates/specs/src/lib.rs +++ b/crates/specs/src/lib.rs @@ -14,7 +14,7 @@ use itable::InstructionTable; use jtable::JumpTable; use jtable::StaticFrameEntry; use mtable::MTable; -use serde::Serialize; +use serde::{Serialize, Deserialize}; #[macro_use] extern crate lazy_static; @@ -32,7 +32,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 +42,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 8a56c6219..b0bb6f471 100644 --- a/crates/specs/src/mtable.rs +++ b/crates/specs/src/mtable.rs @@ -1,18 +1,18 @@ use std::collections::HashSet; -use serde::Serialize; +use serde::{Serialize, Deserialize}; 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 +25,7 @@ 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 +40,7 @@ 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 +51,7 @@ 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 +113,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 +141,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 cb2fcb857..156a4d398 100644 --- a/crates/specs/src/step.rs +++ b/crates/specs/src/step.rs @@ -10,9 +10,9 @@ use crate::mtable::MemoryReadSize; use crate::mtable::MemoryStoreSize; use crate::mtable::VarType; use crate::types::ValueType; -use serde::Serialize; +use serde::{Deserialize, 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..93c4a73be 100644 --- a/crates/specs/src/types.rs +++ b/crates/specs/src/types.rs @@ -1,10 +1,10 @@ -use serde::Serialize; +use serde::{Deserialize, 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/src/circuits/mod.rs b/crates/zkwasm/src/circuits/mod.rs index 36540be87..dad92a0e3 100644 --- a/crates/zkwasm/src/circuits/mod.rs +++ b/crates/zkwasm/src/circuits/mod.rs @@ -27,7 +27,7 @@ use halo2_proofs::transcript::Blake2bWrite; use halo2_proofs::transcript::Challenge255; use num_bigint::BigUint; use rand::rngs::OsRng; -use specs::Tables; +use specs; use std::fs::File; use std::io::Cursor; use std::io::Read; @@ -62,6 +62,10 @@ pub mod rtable; pub mod test_circuit; pub mod utils; +pub type CompilationTable = specs::CompilationTable; +pub type ExecutionTable = specs::ExecutionTable; +pub type Tables = specs::Tables; + #[derive(Default, Clone)] pub struct TestCircuit { pub tables: Tables, @@ -77,6 +81,13 @@ impl TestCircuit { _data: PhantomData, } } + + pub fn new_without_configure(tables: Tables) -> Self { + TestCircuit { + tables, + _data: PhantomData, + } + } } trait Encode { @@ -106,6 +117,11 @@ impl ZkWasmCircuitBuilder { TestCircuit::new(self.tables.clone()) } + pub fn build_circuit_without_configure(&self) -> TestCircuit { + TestCircuit::new_without_configure(self.tables.clone()) + } + + fn prepare_param(&self) -> Params { let path = PathBuf::from(format!("test_param.{}.data", zkwasm_k())); diff --git a/crates/zkwasm/src/foreign/hash_helper/poseidon.rs b/crates/zkwasm/src/foreign/hash_helper/poseidon.rs index a5bfc041c..762cda989 100644 --- a/crates/zkwasm/src/foreign/hash_helper/poseidon.rs +++ b/crates/zkwasm/src/foreign/hash_helper/poseidon.rs @@ -3,7 +3,7 @@ use crate::runtime::host::{host_env::HostEnv, ForeignContext}; use halo2_proofs::pairing::bn256::Fr; use ff::PrimeField; use poseidon::Poseidon; -use zkwasm_host_circuits::host::poseidon::POSEIDON_HASHER; +pub use zkwasm_host_circuits::host::poseidon::POSEIDON_HASHER; use zkwasm_host_circuits::host::{ Reduce, ReduceRule @@ -42,7 +42,7 @@ pub struct Generator { } impl Generator { - fn gen(&mut self) -> u64 { + pub fn gen(&mut self) -> u64 { let r = self.values[self.cursor]; self.cursor += 1; if self.cursor == 4 { @@ -52,7 +52,7 @@ impl Generator { } } -fn new_reduce(rules: Vec>) -> Reduce { +pub fn new_reduce(rules: Vec>) -> Reduce { Reduce { cursor: 0, rules From 1e2bddd2081176d11da87410cb58474b3844ffc8 Mon Sep 17 00:00:00 2001 From: cwbhhjl Date: Tue, 22 Aug 2023 12:05:40 +0800 Subject: [PATCH 10/35] make zkWasm more suitable as a lib (#166) make zkWasm more suitable as a lib --- Cargo.lock | 2 - crates/cli/Cargo.toml | 2 - crates/cli/src/exec.rs | 10 ++-- crates/cli/src/lib.rs | 4 ++ crates/zkwasm/src/foreign/context/runtime.rs | 16 +++---- .../src/foreign/wasm_input_helper/runtime.rs | 48 +++++++++++-------- crates/zkwasm/src/lib.rs | 4 ++ crates/zkwasm/src/loader/mod.rs | 36 ++++++++++---- 8 files changed, 77 insertions(+), 45 deletions(-) create mode 100644 crates/cli/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index 8d91e9cca..e523177d1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -529,8 +529,6 @@ dependencies = [ "clap", "delphinus-zkwasm", "env_logger", - "halo2_proofs", - "halo2aggregator-s", "hex", "log", "md5", diff --git a/crates/cli/Cargo.toml b/crates/cli/Cargo.toml index db037e97b..49b98fd4f 100644 --- a/crates/cli/Cargo.toml +++ b/crates/cli/Cargo.toml @@ -8,8 +8,6 @@ edition = "2021" [dependencies] ark-std = { version = "0.3.0", features = ["print-trace"] } env_logger = "0.9.3" -halo2aggregator-s = { git = "https://github.com/DelphinusLab/halo2aggregator-s.git", tag = "bisect-lookup-0.3.2", features = ["unsafe"] } -halo2_proofs = { git = "https://github.com/junyu0312/halo2", branch = "gpu", default-features = true } log = "0.4.17" md5 = "0.7.0" notify = "6.0.1" diff --git a/crates/cli/src/exec.rs b/crates/cli/src/exec.rs index 13b1093a2..4abf3fa37 100644 --- a/crates/cli/src/exec.rs +++ b/crates/cli/src/exec.rs @@ -1,5 +1,9 @@ +use crate::app_builder::write_context_output; +use crate::args::parse_args; use anyhow::Result; use delphinus_zkwasm::circuits::TestCircuit; +use delphinus_zkwasm::halo2_proofs; +use delphinus_zkwasm::halo2aggregator_s; use delphinus_zkwasm::loader::ExecutionArg; use delphinus_zkwasm::loader::ZkWasmLoader; use halo2_proofs::arithmetic::BaseExt; @@ -35,15 +39,13 @@ use std::path::Path; use std::path::PathBuf; use std::rc::Rc; 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( zkwasm_k: u32, aggregate_k: u32, - prefix: &'static str, + prefix: &str, wasm_binary: Vec, phantom_functions: Vec, output_dir: &PathBuf, @@ -326,7 +328,7 @@ pub fn exec_verify_proof( let proof = load_proof(proof_path); - loader.verify_proof(¶ms, vkey, instances, proof)?; + loader.verify_proof(¶ms, &vkey, &instances, &proof)?; info!("Verifing proof passed"); 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/zkwasm/src/foreign/context/runtime.rs b/crates/zkwasm/src/foreign/context/runtime.rs index 890634f42..657e42435 100644 --- a/crates/zkwasm/src/foreign/context/runtime.rs +++ b/crates/zkwasm/src/foreign/context/runtime.rs @@ -11,13 +11,13 @@ use crate::runtime::host::ForeignContext; use super::Op; -struct Context { - inputs: Vec, - outputs: Rc>>, +pub struct Context { + pub inputs: Vec, + pub outputs: Rc>>, } impl Context { - fn new(context_input: Vec, context_output: Rc>>) -> Self { + pub fn new(context_input: Vec, context_output: Rc>>) -> Self { let mut inputs = context_input.clone(); inputs.reverse(); @@ -27,11 +27,11 @@ impl Context { } } - fn push_output(&mut self, value: u64) { + pub fn write_context(&mut self, value: u64) { self.outputs.borrow_mut().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") @@ -61,7 +61,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)) }), ); @@ -77,7 +77,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/wasm_input_helper/runtime.rs b/crates/zkwasm/src/foreign/wasm_input_helper/runtime.rs index 979058cc8..0229d9504 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 { @@ -32,26 +32,44 @@ impl Context { } } - pub fn pop_public(&mut self) -> u64 { + fn pop_public(&mut self) -> u64 { self.public_inputs.remove(0) } - pub fn pop_private(&mut self) -> u64 { + fn pop_private(&mut self) -> u64 { 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 {} @@ -69,15 +87,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)) }, @@ -88,7 +98,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 22dfb6c7d..18a28aaa3 100644 --- a/crates/zkwasm/src/lib.rs +++ b/crates/zkwasm/src/lib.rs @@ -19,3 +19,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 84cbd5197..89d76d37c 100644 --- a/crates/zkwasm/src/loader/mod.rs +++ b/crates/zkwasm/src/loader/mod.rs @@ -107,7 +107,7 @@ impl ZkWasmLoader { ) } - fn circuit_without_witness(&self) -> Result> { + pub fn circuit_without_witness(&self) -> Result> { let (env, wasm_runtime_io) = HostEnv::new_with_full_foreign_plugins( vec![], vec![], @@ -180,7 +180,11 @@ impl ZkWasmLoader { compiled_module.dry_run(&mut env) } - pub fn run(&self, arg: ExecutionArg) -> Result> { + pub fn run( + &self, + arg: ExecutionArg, + write_to_file: bool, + ) -> Result> { let (mut env, wasm_runtime_io) = HostEnv::new_with_full_foreign_plugins( arg.public_inputs, arg.private_inputs, @@ -193,7 +197,10 @@ impl ZkWasmLoader { 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) } @@ -202,7 +209,7 @@ impl ZkWasmLoader { &self, arg: ExecutionArg, ) -> Result<(TestCircuit, Vec)> { - let execution_result = self.run(arg)?; + let execution_result = self.run(arg, true)?; #[allow(unused_mut)] let mut instance: Vec = execution_result @@ -273,19 +280,28 @@ impl ZkWasmLoader { pub fn verify_proof( &self, params: &Params, - vkey: VerifyingKey, - instances: Vec, - proof: Vec, + vkey: &VerifyingKey, + instances: &[E::Scalar], + proof: &[u8], + ) -> Result<()> { + Self::verify_single_proof(params, vkey, instances, proof) + } + + pub fn verify_single_proof( + params: &Params, + vkey: &VerifyingKey, + instances: &[E::Scalar], + proof: &[u8], ) -> Result<()> { let params_verifier: ParamsVerifier = params.verifier(instances.len()).unwrap(); let strategy = SingleVerifier::new(¶ms_verifier); verify_proof( ¶ms_verifier, - &vkey, + vkey, strategy, - &[&[&instances]], - &mut PoseidonRead::init(&proof[..]), + &[&[instances]], + &mut PoseidonRead::init(proof), ) .unwrap(); From c8afb22f635a18c52d5203f7483d2859b7b7084e Mon Sep 17 00:00:00 2001 From: sinka Date: Thu, 24 Aug 2023 01:12:52 +1000 Subject: [PATCH 11/35] fix poseidon_finalize --- crates/zkwasm/src/foreign/hash_helper/poseidon.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/crates/zkwasm/src/foreign/hash_helper/poseidon.rs b/crates/zkwasm/src/foreign/hash_helper/poseidon.rs index 762cda989..eac9cec24 100644 --- a/crates/zkwasm/src/foreign/hash_helper/poseidon.rs +++ b/crates/zkwasm/src/foreign/hash_helper/poseidon.rs @@ -96,13 +96,13 @@ impl PoseidonContext { pub fn poseidon_finalize(&mut self) -> u64 { assert!(self.buf.len() == 8); if self.generator.cursor == 0 { - self.hasher.as_ref().map(|s| { + self.hasher.as_mut().map(|s| { log::debug!("perform hash with {:?}", self.buf); - let r = s.clone().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::>(); + 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() From 506f88d7e2417860fb6699f880e03fc86434193b Mon Sep 17 00:00:00 2001 From: Zhang Junyu Date: Thu, 24 Aug 2023 18:48:01 +0800 Subject: [PATCH 12/35] name some columns for commitment checking --- .../src/circuits/external_host_call_table/configure.rs | 6 +++--- crates/zkwasm/src/foreign/context/circuits/config.rs | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) 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 9210339d7..f2fb4a386 100644 --- a/crates/zkwasm/src/circuits/external_host_call_table/configure.rs +++ b/crates/zkwasm/src/circuits/external_host_call_table/configure.rs @@ -15,9 +15,9 @@ impl ExternalHostCallTableConfig { pub(in crate::circuits) fn configure(meta: &mut ConstraintSystem) -> Self { Self { idx: meta.fixed_column(), - op: meta.advice_column(), - is_ret: meta.advice_column(), - arg: meta.advice_column(), + op: meta.named_advice_column("shared_operands".to_string()), + is_ret: meta.named_advice_column("shared_is_ret".to_string()), + arg: meta.named_advice_column("shared_arg".to_string()), _phantom: PhantomData, } } 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); From 77681411f9b5e7b5e25cbc718ab04228208c7542 Mon Sep 17 00:00:00 2001 From: sinka Date: Sun, 27 Aug 2023 07:57:11 +1000 Subject: [PATCH 13/35] bump halo2_proofs --- Cargo.lock | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index e523177d1..287afea5c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -999,7 +999,7 @@ dependencies = [ [[package]] name = "halo2_proofs" version = "0.1.0-beta.1" -source = "git+https://github.com/junyu0312/halo2?branch=gpu#e02af42177650c1df552f8a6614d4358621e067e" +source = "git+https://github.com/junyu0312/halo2?branch=gpu#49f0c26b2e60d8886bb9513c26d16b6edd3c369f" dependencies = [ "ark-std", "blake2b_simd", @@ -1010,6 +1010,7 @@ dependencies = [ "ec-gpu-gen", "ff", "group", + "memmap", "num", "num-bigint", "num-derive", @@ -1412,6 +1413,16 @@ version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" +[[package]] +name = "memmap" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6585fd95e7bb50d6cc31e20d4cf9afb4e2ba16c5846fc76793f11218da9c475b" +dependencies = [ + "libc", + "winapi 0.3.9", +] + [[package]] name = "memoffset" version = "0.9.0" From 0a009fd95625b92303f373126bd732cec6e486b7 Mon Sep 17 00:00:00 2001 From: "evan.han" Date: Mon, 28 Aug 2023 12:12:41 +0800 Subject: [PATCH 14/35] support passing db implementation to merkle tree --- Cargo.lock | 2 +- crates/cli/src/exec.rs | 14 +- crates/playground/examples/binary_search.rs | 2 +- crates/playground/examples/context.rs | 2 +- crates/playground/examples/fibonacci.rs | 2 +- crates/playground/examples/phantom.rs | 1 + .../src/foreign/merkle_helper/merkle.rs | 186 ++++++++++-------- crates/zkwasm/src/foreign/mod.rs | 28 +-- crates/zkwasm/src/loader/mod.rs | 15 +- 9 files changed, 147 insertions(+), 105 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 287afea5c..90dfd9edc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3240,7 +3240,7 @@ dependencies = [ [[package]] name = "zkwasm-host-circuits" version = "0.1.0" -source = "git+https://github.com/DelphinusLab/zkWasm-host-circuits.git?branch=main#9b02f05b636b007d50a5cfa5db4274ddb8632198" +source = "git+https://github.com/DelphinusLab/zkWasm-host-circuits.git?branch=main#5d9058fabdf235affc0674219b798eb635ce2ad7" dependencies = [ "ark-std", "clap", diff --git a/crates/cli/src/exec.rs b/crates/cli/src/exec.rs index 4abf3fa37..b9df23e9a 100644 --- a/crates/cli/src/exec.rs +++ b/crates/cli/src/exec.rs @@ -77,7 +77,8 @@ pub fn exec_setup( 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, None)?; let vkey = loader.create_vkey(¶ms)?; @@ -96,7 +97,7 @@ pub fn exec_image_checksum( phantom_functions: Vec, output_dir: &PathBuf, ) -> Result<()> { - let loader = ZkWasmLoader::::new(zkwasm_k, wasm_binary, phantom_functions)?; + let loader = ZkWasmLoader::::new(zkwasm_k, wasm_binary, phantom_functions, None)?; let hash: Fr = loader.checksum()?; @@ -171,6 +172,7 @@ pub fn exec_dry_run_service( zkwasm_k, wasm_binary.clone(), phantom_functions.clone(), + None, ) .unwrap(); @@ -227,7 +229,7 @@ pub fn exec_dry_run( context_inputs: Vec, context_outputs: Rc>>, ) -> Result<()> { - let loader = ZkWasmLoader::::new(zkwasm_k, wasm_binary, phantom_functions)?; + let loader = ZkWasmLoader::::new(zkwasm_k, wasm_binary, phantom_functions, None)?; loader.dry_run(ExecutionArg { public_inputs, @@ -250,7 +252,7 @@ pub fn exec_create_proof( context_inputs: Vec, context_outputs: Rc>>, ) -> Result<()> { - let loader = ZkWasmLoader::::new(zkwasm_k, wasm_binary, phantom_functions)?; + let loader = ZkWasmLoader::::new(zkwasm_k, wasm_binary, phantom_functions, None)?; let params = load_or_build_unsafe_params::( zkwasm_k, @@ -319,7 +321,7 @@ pub fn exec_verify_proof( Some(&output_dir.join(format!("K{}.params", zkwasm_k))), ); - let loader = ZkWasmLoader::::new(zkwasm_k, wasm_binary, phantom_functions)?; + let loader = ZkWasmLoader::::new(zkwasm_k, wasm_binary, phantom_functions, None)?; let vkey = load_vkey::>( ¶ms, @@ -349,7 +351,7 @@ pub fn exec_aggregate_create_proof( ) -> Result<()> { assert_eq!(public_inputs.len(), private_inputs.len()); - let loader = ZkWasmLoader::::new(zkwasm_k, wasm_binary, phantom_functions)?; + let loader = ZkWasmLoader::::new(zkwasm_k, wasm_binary, phantom_functions, None)?; let (circuits, instances) = public_inputs .into_iter() diff --git a/crates/playground/examples/binary_search.rs b/crates/playground/examples/binary_search.rs index 8ad1f65eb..1a7e2e6cd 100644 --- a/crates/playground/examples/binary_search.rs +++ b/crates/playground/examples/binary_search.rs @@ -9,7 +9,7 @@ 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![], None)?; let (circuit, instances) = loader.circuit_with_witness(ExecutionArg { public_inputs: vec![0], diff --git a/crates/playground/examples/context.rs b/crates/playground/examples/context.rs index 58e2e3bce..c3c0ccb19 100644 --- a/crates/playground/examples/context.rs +++ b/crates/playground/examples/context.rs @@ -12,7 +12,7 @@ fn main() -> Result<()> { let context_in: Vec = vec![2, 1]; let context_outputs = Rc::new(RefCell::new(vec![])); - let loader = ZkWasmLoader::::new(18, wasm, vec![])?; + let loader = ZkWasmLoader::::new(18, wasm, vec![], None)?; let arg = ExecutionArg { public_inputs: vec![], private_inputs: vec![], diff --git a/crates/playground/examples/fibonacci.rs b/crates/playground/examples/fibonacci.rs index 5fed10ce4..d20a5064e 100644 --- a/crates/playground/examples/fibonacci.rs +++ b/crates/playground/examples/fibonacci.rs @@ -9,7 +9,7 @@ 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![], None)?; let (circuit, instances) = loader.circuit_with_witness(ExecutionArg { public_inputs: vec![5], diff --git a/crates/playground/examples/phantom.rs b/crates/playground/examples/phantom.rs index 1a32022a2..6f06dd376 100644 --- a/crates/playground/examples/phantom.rs +++ b/crates/playground/examples/phantom.rs @@ -13,6 +13,7 @@ fn main() -> Result<()> { 18, wasm, vec!["search"].into_iter().map(|s| s.to_owned()).collect(), + None, )?; let (circuit, instances) = loader.circuit_with_witness(ExecutionArg { diff --git a/crates/zkwasm/src/foreign/merkle_helper/merkle.rs b/crates/zkwasm/src/foreign/merkle_helper/merkle.rs index dc3f8057e..de973b0cd 100644 --- a/crates/zkwasm/src/foreign/merkle_helper/merkle.rs +++ b/crates/zkwasm/src/foreign/merkle_helper/merkle.rs @@ -1,25 +1,24 @@ +use crate::runtime::host::host_env::HostEnv; +use crate::runtime::host::ForeignContext; +use halo2_proofs::pairing::bn256::Fr; +use std::cell::RefCell; use std::rc::Rc; -use crate::runtime::host::{host_env::HostEnv, ForeignContext}; +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, - datahash as datahelper, - Reduce, ReduceRule -}; -use zkwasm_host_circuits::host::ForeignInst::{ - MerkleSet, - MerkleGet, - MerkleAddress, - MerkleGetRoot, - MerkleSetRoot, - MerklePutData, - MerkleFetchData, -}; - -use halo2_proofs::pairing::bn256::Fr; +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; +const MERKLE_TREE_HEIGHT: usize = 32; pub struct MerkleContext { pub set_root: Reduce, @@ -32,30 +31,20 @@ pub struct MerkleContext { 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 - } + Reduce { cursor: 0, rules } } impl MerkleContext { - pub fn default() -> Self { + 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), - ]), + 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), @@ -66,7 +55,8 @@ impl MerkleContext { data: vec![], data_cursor: 0, mongo_merkle: None, - mongo_datahash: datahelper::MongoDataHash::construct([0;32]), + mongo_datahash: datahelper::MongoDataHash::construct([0; 32], tree_db.clone()), + tree_db, } } @@ -74,24 +64,29 @@ impl MerkleContext { 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.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 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 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] @@ -107,48 +102,83 @@ impl MerkleContext { 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<>(), - } - }).unwrap(); + 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<>().try_into().unwrap(); + 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::>() + .chunks_exact(8) + .into_iter() + .into_iter() + .map(|x| u64::from_le_bytes(x.try_into().unwrap())) + .collect::>() }); } values[cursor] @@ -174,10 +204,10 @@ impl MerkleContext {} impl ForeignContext for MerkleContext {} use specs::external_host_call_table::ExternalHostCallSignature; -pub fn register_merkle_foreign(env: &mut HostEnv) { +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::default())); + .external_env + .register_plugin("foreign_merkle", Box::new(MerkleContext::new(tree_db))); env.external_env.register_function( "merkle_setroot", @@ -219,7 +249,6 @@ pub fn register_merkle_foreign(env: &mut HostEnv) { ), ); - env.external_env.register_function( "merkle_address", MerkleAddress as usize, @@ -248,8 +277,6 @@ pub fn register_merkle_foreign(env: &mut HostEnv) { ), ); - - env.external_env.register_function( "merkle_set", MerkleSet as usize, @@ -264,7 +291,6 @@ pub fn register_merkle_foreign(env: &mut HostEnv) { ), ); - env.external_env.register_function( "merkle_get", MerkleGet as usize, diff --git a/crates/zkwasm/src/foreign/mod.rs b/crates/zkwasm/src/foreign/mod.rs index 1dada24a5..0ce917da5 100644 --- a/crates/zkwasm/src/foreign/mod.rs +++ b/crates/zkwasm/src/foreign/mod.rs @@ -13,29 +13,28 @@ use halo2_proofs::arithmetic::FieldExt; use halo2_proofs::plonk::ConstraintSystem; use halo2_proofs::plonk::Expression; use halo2_proofs::plonk::VirtualCells; +use zkwasm_host_circuits::host::db::TreeDB; use self::context::runtime::register_context_foreign; +use self::ecc_helper::bls381::pair::register_blspair_foreign; +use self::ecc_helper::bls381::sum::register_blssum_foreign; +use self::ecc_helper::bn254::pair::register_bn254pair_foreign; +use self::ecc_helper::bn254::sum::register_bn254sum_foreign; +use self::ecc_helper::jubjub::sum::register_babyjubjubsum_foreign; +use self::hash_helper::poseidon::register_poseidon_foreign; +use self::hash_helper::sha256::register_sha256_foreign; use self::log_helper::register_log_foreign; +use self::merkle_helper::merkle::register_merkle_foreign; use self::require_helper::register_require_foreign; use self::wasm_input_helper::runtime::register_wasm_input_foreign; -use self::ecc_helper::{ - bls381::pair::register_blspair_foreign, - bls381::sum::register_blssum_foreign, - bn254::pair::register_bn254pair_foreign, - bn254::sum::register_bn254sum_foreign, - jubjub::sum::register_babyjubjubsum_foreign, -}; -use self::hash_helper::sha256::register_sha256_foreign; -use self::hash_helper::poseidon::register_poseidon_foreign; -use self::merkle_helper::merkle::register_merkle_foreign; pub mod context; +pub mod ecc_helper; +pub mod hash_helper; pub mod keccak_helper; pub mod log_helper; -pub mod require_helper; pub mod merkle_helper; -pub mod ecc_helper; -pub mod hash_helper; +pub mod require_helper; pub mod wasm_input_helper; pub fn foreign_table_enable_lines() -> usize { @@ -71,12 +70,13 @@ impl HostEnv { private_inputs: Vec, context_input: Vec, context_output: Rc>>, + tree_db: Option>>, ) -> (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_merkle_foreign(&mut env); + register_merkle_foreign(&mut env, tree_db); register_blspair_foreign(&mut env); register_blssum_foreign(&mut env); register_bn254pair_foreign(&mut env); diff --git a/crates/zkwasm/src/loader/mod.rs b/crates/zkwasm/src/loader/mod.rs index 89d76d37c..f8495492b 100644 --- a/crates/zkwasm/src/loader/mod.rs +++ b/crates/zkwasm/src/loader/mod.rs @@ -37,6 +37,7 @@ use crate::runtime::CompiledImage; use crate::runtime::ExecutionResult; use crate::runtime::WasmInterpreter; use anyhow::anyhow; +use zkwasm_host_circuits::host::db::TreeDB; mod err; @@ -62,6 +63,7 @@ pub struct ZkWasmLoader { module: wasmi::Module, phantom_functions: Vec, _data: PhantomData, + tree_db: Option>>, } impl ZkWasmLoader { @@ -113,6 +115,7 @@ impl ZkWasmLoader { vec![], vec![], Rc::new(RefCell::new(vec![])), + None, ); let compiled_module = self.compile(&env)?; @@ -128,7 +131,12 @@ impl ZkWasmLoader { Ok(builder.build_circuit::()) } - pub fn new(k: u32, image: Vec, phantom_functions: Vec) -> Result { + pub fn new( + k: u32, + image: Vec, + phantom_functions: Vec, + tree_db: Option>>, + ) -> Result { set_zkwasm_k(k); let module = wasmi::Module::from_buffer(&image)?; @@ -138,6 +146,7 @@ impl ZkWasmLoader { module, phantom_functions, _data: PhantomData, + tree_db, }; loader.precheck()?; @@ -159,6 +168,7 @@ impl ZkWasmLoader { vec![], vec![], Rc::new(RefCell::new(vec![])), + None, ); let compiled = self.compile(&env)?; @@ -173,6 +183,7 @@ impl ZkWasmLoader { arg.private_inputs, arg.context_inputs, arg.context_outputs, + self.tree_db.clone(), ); let compiled_module = self.compile(&env)?; @@ -190,6 +201,7 @@ impl ZkWasmLoader { arg.private_inputs, arg.context_inputs, arg.context_outputs, + self.tree_db.clone(), ); let compiled_module = self.compile(&env)?; @@ -268,6 +280,7 @@ impl ZkWasmLoader { vec![], vec![], Rc::new(RefCell::new(vec![])), + None, ); let c = self.compile(&env)?; From 3f13ed0c0ac4fbfe59d76be149515ce3eff20dcd Mon Sep 17 00:00:00 2001 From: sinka Date: Sun, 27 Aug 2023 07:57:11 +1000 Subject: [PATCH 15/35] align halo2_proofs and fix compile for cli --- Cargo.lock | 21 +++++++++++++++++++-- crates/cli/src/exec.rs | 4 ++++ crates/zkwasm/Cargo.toml | 2 +- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 90dfd9edc..0feef768d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -550,7 +550,7 @@ dependencies = [ "downcast-rs", "ff", "halo2_proofs", - "halo2aggregator-s", + "halo2aggregator-s 0.1.0 (git+https://github.com/DelphinusLab/halo2aggregator-s.git?branch=absorb-rebase)", "hex", "lazy_static", "log", @@ -1040,6 +1040,23 @@ dependencies = [ "tera", ] +[[package]] +name = "halo2aggregator-s" +version = "0.1.0" +source = "git+https://github.com/DelphinusLab/halo2aggregator-s.git?branch=absorb-rebase#54877843820d5954cb62086330a24c99e282f07f" +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" @@ -3246,7 +3263,7 @@ dependencies = [ "clap", "ff", "halo2_proofs", - "halo2aggregator-s", + "halo2aggregator-s 0.1.0 (git+https://github.com/DelphinusLab/halo2aggregator-s.git?tag=bisect-lookup-0.3.2)", "halo2ecc-s", "hex", "lazy_static", diff --git a/crates/cli/src/exec.rs b/crates/cli/src/exec.rs index b9df23e9a..00c927fd3 100644 --- a/crates/cli/src/exec.rs +++ b/crates/cli/src/exec.rs @@ -385,6 +385,8 @@ pub fn exec_aggregate_create_proof( instances, TranscriptHash::Poseidon, vec![], + vec![], + vec![], false, ) .unwrap(); @@ -397,6 +399,8 @@ pub fn exec_aggregate_create_proof( vec![vec![aggregate_instances]], TranscriptHash::Sha, vec![], + vec![], + vec![], true, ); diff --git a/crates/zkwasm/Cargo.toml b/crates/zkwasm/Cargo.toml index a0be9551b..6e191a06b 100644 --- a/crates/zkwasm/Cargo.toml +++ b/crates/zkwasm/Cargo.toml @@ -9,7 +9,7 @@ edition = "2021" ark-std = { version = "0.3.0", features = ["print-trace"] } bitvec = "1.0.1" downcast-rs = "1.2.0" -halo2aggregator-s = { git = "https://github.com/DelphinusLab/halo2aggregator-s.git", tag = "bisect-lookup-0.3.2", features = ["unsafe"] } +halo2aggregator-s = { git = "https://github.com/DelphinusLab/halo2aggregator-s.git", branch = "absorb-rebase", features = ["unsafe"] } halo2_proofs = { git = "https://github.com/junyu0312/halo2", branch = "gpu", default-features = true } hex = "0.4.3" log = "0.4.17" From 8c8e3726559f8466816b76ba6bcf4bd4cba36440 Mon Sep 17 00:00:00 2001 From: sinka Date: Mon, 28 Aug 2023 19:47:50 +1000 Subject: [PATCH 16/35] bump agg and host-circuits --- Cargo.lock | 63 ++++++++++++++++++++++++++-------------- crates/zkwasm/Cargo.toml | 2 +- 2 files changed, 43 insertions(+), 22 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0feef768d..a43d9e34e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -310,6 +310,43 @@ dependencies = [ "phf_codegen", ] +[[package]] +name = "circuits-batcher" +version = "0.1.0" +source = "git+https://github.com/DelphinusLab/continuation-batcher.git#172f96d318fb7bda31f8175fb8a5140df17054de" +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" @@ -550,7 +587,7 @@ dependencies = [ "downcast-rs", "ff", "halo2_proofs", - "halo2aggregator-s 0.1.0 (git+https://github.com/DelphinusLab/halo2aggregator-s.git?branch=absorb-rebase)", + "halo2aggregator-s", "hex", "lazy_static", "log", @@ -1026,24 +1063,7 @@ dependencies = [ [[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 = "halo2aggregator-s" -version = "0.1.0" -source = "git+https://github.com/DelphinusLab/halo2aggregator-s.git?branch=absorb-rebase#54877843820d5954cb62086330a24c99e282f07f" +source = "git+https://github.com/DelphinusLab/halo2aggregator-s.git?branch=main#11a5ca4f8ae7329775339b697c0a1cdc4ad82ac9" dependencies = [ "ark-std", "blake2b_simd", @@ -3257,13 +3277,14 @@ dependencies = [ [[package]] name = "zkwasm-host-circuits" version = "0.1.0" -source = "git+https://github.com/DelphinusLab/zkWasm-host-circuits.git?branch=main#5d9058fabdf235affc0674219b798eb635ce2ad7" +source = "git+https://github.com/DelphinusLab/zkWasm-host-circuits.git?branch=main#3dc9dfd96c18545e6957d0a16732b7e61dee0726" dependencies = [ "ark-std", + "circuits-batcher", "clap", "ff", "halo2_proofs", - "halo2aggregator-s 0.1.0 (git+https://github.com/DelphinusLab/halo2aggregator-s.git?tag=bisect-lookup-0.3.2)", + "halo2aggregator-s", "halo2ecc-s", "hex", "lazy_static", diff --git a/crates/zkwasm/Cargo.toml b/crates/zkwasm/Cargo.toml index 6e191a06b..149166ee3 100644 --- a/crates/zkwasm/Cargo.toml +++ b/crates/zkwasm/Cargo.toml @@ -9,7 +9,7 @@ edition = "2021" ark-std = { version = "0.3.0", features = ["print-trace"] } bitvec = "1.0.1" downcast-rs = "1.2.0" -halo2aggregator-s = { git = "https://github.com/DelphinusLab/halo2aggregator-s.git", branch = "absorb-rebase", features = ["unsafe"] } +halo2aggregator-s = { git = "https://github.com/DelphinusLab/halo2aggregator-s.git", branch = "main", features = ["unsafe"] } halo2_proofs = { git = "https://github.com/junyu0312/halo2", branch = "gpu", default-features = true } hex = "0.4.3" log = "0.4.17" From 8a523b8a1b58cc5030368d3b4b7e8ac46938efe5 Mon Sep 17 00:00:00 2001 From: sinka Date: Wed, 30 Aug 2023 00:14:00 +1000 Subject: [PATCH 17/35] increase k for agg since it now includes pair --- Cargo.lock | 4 ++-- crates/cli/src/exec.rs | 2 +- crates/cli/src/main.rs | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a43d9e34e..4807ab3c3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1036,7 +1036,7 @@ dependencies = [ [[package]] name = "halo2_proofs" version = "0.1.0-beta.1" -source = "git+https://github.com/junyu0312/halo2?branch=gpu#49f0c26b2e60d8886bb9513c26d16b6edd3c369f" +source = "git+https://github.com/junyu0312/halo2?branch=gpu#1944d4c03bf7a936690665537ae3fede776c76fe" dependencies = [ "ark-std", "blake2b_simd", @@ -1063,7 +1063,7 @@ dependencies = [ [[package]] name = "halo2aggregator-s" version = "0.1.0" -source = "git+https://github.com/DelphinusLab/halo2aggregator-s.git?branch=main#11a5ca4f8ae7329775339b697c0a1cdc4ad82ac9" +source = "git+https://github.com/DelphinusLab/halo2aggregator-s.git?branch=main#219a3065c90ed4f8400853cf9392c81f17ab6ae8" dependencies = [ "ark-std", "blake2b_simd", diff --git a/crates/cli/src/exec.rs b/crates/cli/src/exec.rs index 00c927fd3..b49715cea 100644 --- a/crates/cli/src/exec.rs +++ b/crates/cli/src/exec.rs @@ -425,7 +425,7 @@ pub fn exec_verify_aggregate_proof( &output_dir.join(format!("{}.{}.vkey.data", AGGREGATE_PREFIX, 0)), ); - let public_inputs_size: u32 = 6 + 3 * n_proofs as u32; + let public_inputs_size: u32 = 3 * n_proofs as u32; let instances = load_instance::(&[public_inputs_size], &instances_path); diff --git a/crates/cli/src/main.rs b/crates/cli/src/main.rs index 10edae2e8..80d4ac15a 100644 --- a/crates/cli/src/main.rs +++ b/crates/cli/src/main.rs @@ -81,7 +81,7 @@ impl AppBuilder for SampleApp { const AGGREGATE_K: u32 = 22; #[cfg(not(feature = "checksum"))] - const AGGREGATE_K: u32 = 21; + const AGGREGATE_K: u32 = 22; const MAX_PUBLIC_INPUT_SIZE: usize = 64; From d66603f4b50b184694dcb17f24904be8a1f440bb Mon Sep 17 00:00:00 2001 From: Sinka Date: Mon, 28 Aug 2023 21:05:59 +0800 Subject: [PATCH 18/35] connecting batcher --- Cargo.lock | 5 +- crates/cli/Cargo.toml | 5 +- crates/cli/src/app_builder.rs | 11 ++-- crates/cli/src/exec.rs | 92 +++++++++++++-------------------- crates/zkwasm/src/loader/mod.rs | 55 -------------------- 5 files changed, 47 insertions(+), 121 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4807ab3c3..50867d311 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -313,7 +313,7 @@ dependencies = [ [[package]] name = "circuits-batcher" version = "0.1.0" -source = "git+https://github.com/DelphinusLab/continuation-batcher.git#172f96d318fb7bda31f8175fb8a5140df17054de" +source = "git+https://github.com/DelphinusLab/continuation-batcher.git#fdb8ebe08e229c6e38dd30242b2aba331b14a17b" dependencies = [ "anyhow", "ark-std", @@ -563,9 +563,12 @@ version = "0.1.0" dependencies = [ "anyhow", "ark-std", + "circuits-batcher", "clap", "delphinus-zkwasm", "env_logger", + "halo2_proofs", + "halo2aggregator-s", "hex", "log", "md5", diff --git a/crates/cli/Cargo.toml b/crates/cli/Cargo.toml index 49b98fd4f..58d0ac25c 100644 --- a/crates/cli/Cargo.toml +++ b/crates/cli/Cargo.toml @@ -8,6 +8,8 @@ edition = "2021" [dependencies] ark-std = { version = "0.3.0", features = ["print-trace"] } env_logger = "0.9.3" +halo2aggregator-s = { git = "https://github.com/DelphinusLab/halo2aggregator-s.git", branch="main", features = ["unsafe"] } +halo2_proofs = { git = "https://github.com/junyu0312/halo2", branch = "gpu", default-features = true } log = "0.4.17" md5 = "0.7.0" notify = "6.0.1" @@ -20,8 +22,9 @@ serde_json = "1.0" delphinus-zkwasm = { path = "../zkwasm" } anyhow.workspace = true wasmi.workspace = true +circuits-batcher = { git = "https://github.com/DelphinusLab/continuation-batcher.git" } [features] default = [] checksum = ["delphinus-zkwasm/checksum"] -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 6d4dc228c..0ed936bf4 100644 --- a/crates/cli/src/app_builder.rs +++ b/crates/cli/src/app_builder.rs @@ -183,17 +183,12 @@ pub trait AppBuilder: CommandBuilder { 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); + 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, + &output_dir ) } Some(("aggregate-prove", sub_matches)) => { diff --git a/crates/cli/src/exec.rs b/crates/cli/src/exec.rs index b49715cea..24f94e265 100644 --- a/crates/cli/src/exec.rs +++ b/crates/cli/src/exec.rs @@ -1,12 +1,15 @@ use crate::app_builder::write_context_output; use crate::args::parse_args; use anyhow::Result; +use circuits_batcher::proof::CircuitInfo; +use circuits_batcher::proof::ProofInfo; +use circuits_batcher::proof::ProofLoadInfo; +use circuits_batcher::proof::Prover; use delphinus_zkwasm::circuits::TestCircuit; use delphinus_zkwasm::halo2_proofs; use delphinus_zkwasm::halo2aggregator_s; use delphinus_zkwasm::loader::ExecutionArg; use delphinus_zkwasm::loader::ZkWasmLoader; -use halo2_proofs::arithmetic::BaseExt; use halo2_proofs::pairing::bn256::Bn256; use halo2_proofs::pairing::bn256::Fr; use halo2_proofs::pairing::bn256::G1Affine; @@ -19,8 +22,8 @@ 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::native_verifier; use halo2aggregator_s::solidity_verifier::codegen::solidity_aux_gen; use halo2aggregator_s::solidity_verifier::solidity_render; use halo2aggregator_s::transcript::sha256::ShaRead; @@ -34,7 +37,6 @@ use serde::Deserialize; use serde::Serialize; use std::cell::RefCell; use std::fs; -use std::io::Write; use std::path::Path; use std::path::PathBuf; use std::rc::Rc; @@ -254,16 +256,6 @@ pub fn exec_create_proof( ) -> Result<()> { let loader = ZkWasmLoader::::new(zkwasm_k, wasm_binary, phantom_functions, None)?; - 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, @@ -271,28 +263,21 @@ pub fn exec_create_proof( context_outputs, })?; - { - store_instance( - &vec![instances.clone()], - &output_dir.join(format!("{}.{}.instance.data", prefix, 0)), - ); - } - if true { info!("Mock test..."); loader.mock_test(&circuit, &instances)?; 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.create_proof(output_dir, 0); info!("Proof has been created."); Ok(()) @@ -300,38 +285,33 @@ 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 load_info = output_dir.join(format!("{}.loadinfo.json", prefix)); + let proofloadinfo = ProofLoadInfo::load(&load_info); + let proofs:Vec> = ProofInfo::load_proof(&output_dir, &proofloadinfo); let params = load_or_build_unsafe_params::( - zkwasm_k, - Some(&output_dir.join(format!("K{}.params", zkwasm_k))), + proofloadinfo.k as u32, + Some(&output_dir.join(format!("K{}.params", proofloadinfo.k))), ); + 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 loader = ZkWasmLoader::::new(zkwasm_k, wasm_binary, phantom_functions, None)?; - - 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)?; - + 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, + ); + } info!("Verifing proof passed"); Ok(()) diff --git a/crates/zkwasm/src/loader/mod.rs b/crates/zkwasm/src/loader/mod.rs index f8495492b..5b660f080 100644 --- a/crates/zkwasm/src/loader/mod.rs +++ b/crates/zkwasm/src/loader/mod.rs @@ -6,14 +6,8 @@ use anyhow::Result; use halo2_proofs::arithmetic::MultiMillerLoop; use halo2_proofs::dev::MockProver; use halo2_proofs::plonk::keygen_vk; -use halo2_proofs::plonk::verify_proof; -use halo2_proofs::plonk::SingleVerifier; use halo2_proofs::plonk::VerifyingKey; use halo2_proofs::poly::commitment::Params; -use halo2_proofs::poly::commitment::ParamsVerifier; -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; @@ -256,24 +250,6 @@ impl ZkWasmLoader { Ok(()) } - pub fn create_proof( - &self, - params: &Params, - vkey: VerifyingKey, - circuit: TestCircuit, - instances: Vec, - ) -> Result> { - Ok(load_or_create_proof::( - ¶ms, - vkey, - circuit, - &[&instances], - None, - TranscriptHash::Poseidon, - false, - )) - } - pub fn init_env(&self) -> Result<()> { let (env, _) = HostEnv::new_with_full_foreign_plugins( vec![], @@ -289,35 +265,4 @@ impl ZkWasmLoader { Ok(()) } - - pub fn verify_proof( - &self, - params: &Params, - vkey: &VerifyingKey, - instances: &[E::Scalar], - proof: &[u8], - ) -> Result<()> { - Self::verify_single_proof(params, vkey, instances, proof) - } - - pub fn verify_single_proof( - params: &Params, - vkey: &VerifyingKey, - instances: &[E::Scalar], - proof: &[u8], - ) -> Result<()> { - let params_verifier: ParamsVerifier = params.verifier(instances.len()).unwrap(); - let strategy = SingleVerifier::new(¶ms_verifier); - - verify_proof( - ¶ms_verifier, - vkey, - strategy, - &[&[instances]], - &mut PoseidonRead::init(proof), - ) - .unwrap(); - - Ok(()) - } } From 81fa4e1e58d01198789b547e9b55162d250fd153 Mon Sep 17 00:00:00 2001 From: Sinka Date: Wed, 30 Aug 2023 18:18:58 +0800 Subject: [PATCH 19/35] remove uncessary Cargo.lock in crate/zkwasm --- Cargo.lock | 9 +- crates/zkwasm/Cargo.lock | 2157 -------------------------------------- 2 files changed, 4 insertions(+), 2162 deletions(-) delete mode 100644 crates/zkwasm/Cargo.lock diff --git a/Cargo.lock b/Cargo.lock index 50867d311..97a5b6cc3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -313,7 +313,7 @@ dependencies = [ [[package]] name = "circuits-batcher" version = "0.1.0" -source = "git+https://github.com/DelphinusLab/continuation-batcher.git#fdb8ebe08e229c6e38dd30242b2aba331b14a17b" +source = "git+https://github.com/DelphinusLab/continuation-batcher.git#676b8cca0d17d1b6a8395d6f0514044958677595" dependencies = [ "anyhow", "ark-std", @@ -1039,7 +1039,7 @@ dependencies = [ [[package]] name = "halo2_proofs" version = "0.1.0-beta.1" -source = "git+https://github.com/junyu0312/halo2?branch=gpu#1944d4c03bf7a936690665537ae3fede776c76fe" +source = "git+https://github.com/junyu0312/halo2?branch=gpu#8dbcacf1a9374b64d2e1450db5754fa2ae2b829f" dependencies = [ "ark-std", "blake2b_simd", @@ -1066,7 +1066,7 @@ dependencies = [ [[package]] name = "halo2aggregator-s" version = "0.1.0" -source = "git+https://github.com/DelphinusLab/halo2aggregator-s.git?branch=main#219a3065c90ed4f8400853cf9392c81f17ab6ae8" +source = "git+https://github.com/DelphinusLab/halo2aggregator-s.git?branch=main#d93544206963b916bf074383a7ff2d403fd21ba0" dependencies = [ "ark-std", "blake2b_simd", @@ -3280,14 +3280,13 @@ dependencies = [ [[package]] name = "zkwasm-host-circuits" version = "0.1.0" -source = "git+https://github.com/DelphinusLab/zkWasm-host-circuits.git?branch=main#3dc9dfd96c18545e6957d0a16732b7e61dee0726" +source = "git+https://github.com/DelphinusLab/zkWasm-host-circuits.git?branch=main#9725d6072d1b04e87d07f30f1aea77814a4f7354" dependencies = [ "ark-std", "circuits-batcher", "clap", "ff", "halo2_proofs", - "halo2aggregator-s", "halo2ecc-s", "hex", "lazy_static", 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", -] From bde20825a2f207bf1836b124a3ac1f011457b7bd Mon Sep 17 00:00:00 2001 From: sinka Date: Tue, 5 Sep 2023 18:26:30 +1000 Subject: [PATCH 20/35] bump halo2 version to support better gpu --- Cargo.lock | 92 +++++++++++++++++++++++++++++++++------- crates/zkwasm/Cargo.toml | 2 +- 2 files changed, 78 insertions(+), 16 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e65d93081..147002934 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -313,7 +313,7 @@ dependencies = [ [[package]] name = "circuits-batcher" version = "0.1.0" -source = "git+https://github.com/DelphinusLab/continuation-batcher.git#676b8cca0d17d1b6a8395d6f0514044958677595" +source = "git+https://github.com/DelphinusLab/continuation-batcher.git#84a263c99c1b4f269f5cf54f1e5baa5652d4be27" dependencies = [ "anyhow", "ark-std", @@ -322,9 +322,9 @@ dependencies = [ "downcast-rs", "env_logger", "ff", - "halo2_proofs", + "halo2_proofs 0.1.0-beta.1 (git+https://github.com/DelphinusLab/halo2-gpu-specific.git)", "halo2aggregator-s", - "halo2ecc-s", + "halo2ecc-s 0.3.2 (git+https://github.com/lanbones/halo2ecc-s.git?tag=bisect-lookup-0.3.3)", "hex", "lazy_static", "log", @@ -567,7 +567,7 @@ dependencies = [ "clap", "delphinus-zkwasm", "env_logger", - "halo2_proofs", + "halo2_proofs 0.1.0-beta.1 (git+https://github.com/junyu0312/halo2?branch=gpu)", "halo2aggregator-s", "hex", "log", @@ -589,7 +589,7 @@ dependencies = [ "bitvec", "downcast-rs", "ff", - "halo2_proofs", + "halo2_proofs 0.1.0-beta.1 (git+https://github.com/DelphinusLab/halo2-gpu-specific.git)", "halo2aggregator-s", "hex", "lazy_static", @@ -693,6 +693,29 @@ 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?branch=halo2-opt-v2#784eda53754a5344f75e4b3c533361d628ad1402" +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 = "ec-gpu-gen" version = "0.4.0" @@ -1047,7 +1070,7 @@ dependencies = [ "cfg-if 0.1.10", "core_affinity", "cuda-driver-sys", - "ec-gpu-gen", + "ec-gpu-gen 0.4.0 (git+https://github.com/lanbones/ec-gpu)", "ff", "group", "memmap", @@ -1063,15 +1086,43 @@ dependencies = [ "subtle", ] +[[package]] +name = "halo2_proofs" +version = "0.1.0-beta.1" +source = "git+https://github.com/DelphinusLab/halo2-gpu-specific.git#64ccffddc97faff24a00d248270fe84f6693c130" +dependencies = [ + "ark-std", + "blake2b_simd", + "bumpalo", + "cfg-if 0.1.10", + "core_affinity", + "cuda-driver-sys", + "ec-gpu-gen 0.4.0 (git+https://github.com/lanbones/ec-gpu?branch=halo2-opt-v2)", + "ff", + "group", + "lazy_static", + "memmap", + "num", + "num-bigint", + "num-derive", + "num-integer", + "num-traits", + "pairing_bn256", + "rand", + "rand_core", + "rayon", + "subtle", +] + [[package]] name = "halo2aggregator-s" version = "0.1.0" -source = "git+https://github.com/DelphinusLab/halo2aggregator-s.git?branch=main#d93544206963b916bf074383a7ff2d403fd21ba0" +source = "git+https://github.com/DelphinusLab/halo2aggregator-s.git?branch=main#55e9a9f45ce326107f70511a2741ac3dbef21114" dependencies = [ "ark-std", "blake2b_simd", - "halo2_proofs", - "halo2ecc-s", + "halo2_proofs 0.1.0-beta.1 (git+https://github.com/DelphinusLab/halo2-gpu-specific.git)", + "halo2ecc-s 0.3.2 (git+https://github.com/lanbones/halo2ecc-s.git?tag=bisect-lookup-0.3.3)", "lazy_static", "num-bigint", "num-integer", @@ -1085,7 +1136,18 @@ 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", + "halo2_proofs 0.1.0-beta.1 (git+https://github.com/junyu0312/halo2?branch=gpu)", + "num-bigint", + "num-integer", + "rayon", +] + +[[package]] +name = "halo2ecc-s" +version = "0.3.2" +source = "git+https://github.com/lanbones/halo2ecc-s.git?tag=bisect-lookup-0.3.3#9698edde834f0bd90a82d0ac37803f5be2b093ad" +dependencies = [ + "halo2_proofs 0.1.0-beta.1 (git+https://github.com/DelphinusLab/halo2-gpu-specific.git)", "num-bigint", "num-integer", "rayon", @@ -1858,9 +1920,9 @@ checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" [[package]] name = "poseidon" version = "0.2.0" -source = "git+https://github.com/lanbones/poseidon#ade94877c8285cc251107418c5effbce36684aa4" +source = "git+https://github.com/lanbones/poseidon#df8891073182c5c6cc1e2e7f9d2f4297d3c1565d" dependencies = [ - "halo2_proofs", + "halo2_proofs 0.1.0-beta.1 (git+https://github.com/DelphinusLab/halo2-gpu-specific.git)", "subtle", ] @@ -2388,7 +2450,7 @@ dependencies = [ name = "specs" version = "0.1.0" dependencies = [ - "halo2_proofs", + "halo2_proofs 0.1.0-beta.1 (git+https://github.com/junyu0312/halo2?branch=gpu)", "lazy_static", "num-bigint", "parity-wasm", @@ -3276,8 +3338,8 @@ dependencies = [ "circuits-batcher", "clap", "ff", - "halo2_proofs", - "halo2ecc-s", + "halo2_proofs 0.1.0-beta.1 (git+https://github.com/junyu0312/halo2?branch=gpu)", + "halo2ecc-s 0.3.2 (git+https://github.com/lanbones/halo2ecc-s.git?tag=bisect-lookup-0.3.2)", "hex", "lazy_static", "lru", diff --git a/crates/zkwasm/Cargo.toml b/crates/zkwasm/Cargo.toml index 149166ee3..d82f57115 100644 --- a/crates/zkwasm/Cargo.toml +++ b/crates/zkwasm/Cargo.toml @@ -10,7 +10,7 @@ ark-std = { version = "0.3.0", features = ["print-trace"] } bitvec = "1.0.1" downcast-rs = "1.2.0" halo2aggregator-s = { git = "https://github.com/DelphinusLab/halo2aggregator-s.git", branch = "main", features = ["unsafe"] } -halo2_proofs = { git = "https://github.com/junyu0312/halo2", branch = "gpu", default-features = true } +halo2_proofs = { git = "https://github.com/DelphinusLab/halo2-gpu-specific.git", default-features = true } hex = "0.4.3" log = "0.4.17" num-integer = "0.1" From c74e9bdd9d8a4cb4212935f08457d08d03024c4e Mon Sep 17 00:00:00 2001 From: sinka Date: Tue, 5 Sep 2023 19:36:01 +1000 Subject: [PATCH 21/35] fix: wrong halo2 version in spec --- Cargo.lock | 87 ++++++----------------------------------- crates/cli/Cargo.toml | 2 +- crates/cli/src/exec.rs | 4 +- crates/specs/Cargo.toml | 2 +- 4 files changed, 17 insertions(+), 78 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 147002934..4b0c8faa1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -322,9 +322,9 @@ dependencies = [ "downcast-rs", "env_logger", "ff", - "halo2_proofs 0.1.0-beta.1 (git+https://github.com/DelphinusLab/halo2-gpu-specific.git)", + "halo2_proofs", "halo2aggregator-s", - "halo2ecc-s 0.3.2 (git+https://github.com/lanbones/halo2ecc-s.git?tag=bisect-lookup-0.3.3)", + "halo2ecc-s", "hex", "lazy_static", "log", @@ -567,7 +567,7 @@ dependencies = [ "clap", "delphinus-zkwasm", "env_logger", - "halo2_proofs 0.1.0-beta.1 (git+https://github.com/junyu0312/halo2?branch=gpu)", + "halo2_proofs", "halo2aggregator-s", "hex", "log", @@ -589,7 +589,7 @@ dependencies = [ "bitvec", "downcast-rs", "ff", - "halo2_proofs 0.1.0-beta.1 (git+https://github.com/DelphinusLab/halo2-gpu-specific.git)", + "halo2_proofs", "halo2aggregator-s", "hex", "lazy_static", @@ -716,29 +716,6 @@ dependencies = [ "yastl", ] -[[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.9.0" @@ -1059,33 +1036,6 @@ dependencies = [ "subtle", ] -[[package]] -name = "halo2_proofs" -version = "0.1.0-beta.1" -source = "git+https://github.com/junyu0312/halo2?branch=gpu#8dbcacf1a9374b64d2e1450db5754fa2ae2b829f" -dependencies = [ - "ark-std", - "blake2b_simd", - "bumpalo", - "cfg-if 0.1.10", - "core_affinity", - "cuda-driver-sys", - "ec-gpu-gen 0.4.0 (git+https://github.com/lanbones/ec-gpu)", - "ff", - "group", - "memmap", - "num", - "num-bigint", - "num-derive", - "num-integer", - "num-traits", - "pairing_bn256", - "rand", - "rand_core", - "rayon", - "subtle", -] - [[package]] name = "halo2_proofs" version = "0.1.0-beta.1" @@ -1097,7 +1047,7 @@ dependencies = [ "cfg-if 0.1.10", "core_affinity", "cuda-driver-sys", - "ec-gpu-gen 0.4.0 (git+https://github.com/lanbones/ec-gpu?branch=halo2-opt-v2)", + "ec-gpu-gen", "ff", "group", "lazy_static", @@ -1121,8 +1071,8 @@ source = "git+https://github.com/DelphinusLab/halo2aggregator-s.git?branch=main# dependencies = [ "ark-std", "blake2b_simd", - "halo2_proofs 0.1.0-beta.1 (git+https://github.com/DelphinusLab/halo2-gpu-specific.git)", - "halo2ecc-s 0.3.2 (git+https://github.com/lanbones/halo2ecc-s.git?tag=bisect-lookup-0.3.3)", + "halo2_proofs", + "halo2ecc-s", "lazy_static", "num-bigint", "num-integer", @@ -1131,23 +1081,12 @@ dependencies = [ "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 0.1.0-beta.1 (git+https://github.com/junyu0312/halo2?branch=gpu)", - "num-bigint", - "num-integer", - "rayon", -] - [[package]] name = "halo2ecc-s" version = "0.3.2" source = "git+https://github.com/lanbones/halo2ecc-s.git?tag=bisect-lookup-0.3.3#9698edde834f0bd90a82d0ac37803f5be2b093ad" dependencies = [ - "halo2_proofs 0.1.0-beta.1 (git+https://github.com/DelphinusLab/halo2-gpu-specific.git)", + "halo2_proofs", "num-bigint", "num-integer", "rayon", @@ -1922,7 +1861,7 @@ name = "poseidon" version = "0.2.0" source = "git+https://github.com/lanbones/poseidon#df8891073182c5c6cc1e2e7f9d2f4297d3c1565d" dependencies = [ - "halo2_proofs 0.1.0-beta.1 (git+https://github.com/DelphinusLab/halo2-gpu-specific.git)", + "halo2_proofs", "subtle", ] @@ -2450,7 +2389,7 @@ dependencies = [ name = "specs" version = "0.1.0" dependencies = [ - "halo2_proofs 0.1.0-beta.1 (git+https://github.com/junyu0312/halo2?branch=gpu)", + "halo2_proofs", "lazy_static", "num-bigint", "parity-wasm", @@ -3332,14 +3271,14 @@ dependencies = [ [[package]] name = "zkwasm-host-circuits" version = "0.1.0" -source = "git+https://github.com/DelphinusLab/zkWasm-host-circuits.git?branch=main#9725d6072d1b04e87d07f30f1aea77814a4f7354" +source = "git+https://github.com/DelphinusLab/zkWasm-host-circuits.git?branch=main#e4dbc533b04963c0e3eb2db5101c0b096a0eea8b" dependencies = [ "ark-std", "circuits-batcher", "clap", "ff", - "halo2_proofs 0.1.0-beta.1 (git+https://github.com/junyu0312/halo2?branch=gpu)", - "halo2ecc-s 0.3.2 (git+https://github.com/lanbones/halo2ecc-s.git?tag=bisect-lookup-0.3.2)", + "halo2_proofs", + "halo2ecc-s", "hex", "lazy_static", "lru", diff --git a/crates/cli/Cargo.toml b/crates/cli/Cargo.toml index 58d0ac25c..79493714a 100644 --- a/crates/cli/Cargo.toml +++ b/crates/cli/Cargo.toml @@ -9,7 +9,7 @@ edition = "2021" ark-std = { version = "0.3.0", features = ["print-trace"] } env_logger = "0.9.3" halo2aggregator-s = { git = "https://github.com/DelphinusLab/halo2aggregator-s.git", branch="main", features = ["unsafe"] } -halo2_proofs = { git = "https://github.com/junyu0312/halo2", branch = "gpu", default-features = true } +halo2_proofs = { git = "https://github.com/DelphinusLab/halo2-gpu-specific.git", default-features = true } log = "0.4.17" md5 = "0.7.0" notify = "6.0.1" diff --git a/crates/cli/src/exec.rs b/crates/cli/src/exec.rs index 24f94e265..5e63992c7 100644 --- a/crates/cli/src/exec.rs +++ b/crates/cli/src/exec.rs @@ -277,7 +277,7 @@ pub fn exec_create_proof( circuits_batcher::args::HashType::Poseidon ); circuit.proofloadinfo.save(output_dir); - circuit.create_proof(output_dir, 0); + circuit.create_proof(output_dir, output_dir, 0); info!("Proof has been created."); Ok(()) @@ -289,7 +289,7 @@ pub fn exec_verify_proof( ) -> 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, &proofloadinfo); + let proofs:Vec> = ProofInfo::load_proof(&output_dir, output_dir, &proofloadinfo); let params = load_or_build_unsafe_params::( proofloadinfo.k as u32, Some(&output_dir.join(format!("K{}.params", proofloadinfo.k))), diff --git a/crates/specs/Cargo.toml b/crates/specs/Cargo.toml index 7605238f2..67781753e 100644 --- a/crates/specs/Cargo.toml +++ b/crates/specs/Cargo.toml @@ -6,7 +6,7 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -halo2_proofs = { git = "https://github.com/junyu0312/halo2", branch = "gpu", default-features = true } +halo2_proofs = { git = "https://github.com/DelphinusLab/halo2-gpu-specific.git", default-features = true } lazy_static = "1.4.0" num-bigint = { version = "0.4", features = ["rand"] } parity-wasm = { version = "0.42.0", default-features = false } From 75de63c52419d05b5f733f3ec2e7a8def327a2a1 Mon Sep 17 00:00:00 2001 From: sinka Date: Wed, 30 Aug 2023 16:03:43 +1000 Subject: [PATCH 22/35] remove aggregating from basic cli --- crates/cli/src/app_builder.rs | 76 ++---------- crates/cli/src/args.rs | 7 ++ crates/cli/src/exec.rs | 219 ++-------------------------------- crates/cli/test_cli.sh | 12 +- 4 files changed, 27 insertions(+), 287 deletions(-) diff --git a/crates/cli/src/app_builder.rs b/crates/cli/src/app_builder.rs index 0ed936bf4..5dc21d032 100644 --- a/crates/cli/src/app_builder.rs +++ b/crates/cli/src/app_builder.rs @@ -13,14 +13,11 @@ use std::rc::Rc; 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; #[cfg(feature = "checksum")] 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 { @@ -66,6 +63,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()); @@ -74,9 +72,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); #[cfg(feature = "checksum")] let app = Self::append_image_checksum_subcommand(app); @@ -100,6 +95,9 @@ 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)?; @@ -112,6 +110,7 @@ pub trait AppBuilder: CommandBuilder { wasm_binary, phantom_functions, &output_dir, + ¶m_dir, ), #[cfg(feature = "checksum")] Some(("checksum", _)) => { @@ -172,6 +171,7 @@ pub trait AppBuilder: CommandBuilder { wasm_binary, phantom_functions, &output_dir, + ¶m_dir, public_inputs, private_inputs, context_in, @@ -188,72 +188,10 @@ pub trait AppBuilder: CommandBuilder { exec_verify_proof( Self::NAME, - &output_dir - ) - } - 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(|_| Rc::new(RefCell::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, + ¶m_dir ) } - Some((_, _)) => todo!(), None => todo!(), } diff --git a/crates/cli/src/args.rs b/crates/cli/src/args.rs index fc11b7eb3..dc5bfb6b9 100644 --- a/crates/cli/src/args.rs +++ b/crates/cli/src/args.rs @@ -117,6 +117,13 @@ 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/exec.rs b/crates/cli/src/exec.rs index 5e63992c7..c8d1ec543 100644 --- a/crates/cli/src/exec.rs +++ b/crates/cli/src/exec.rs @@ -12,21 +12,10 @@ use delphinus_zkwasm::loader::ExecutionArg; use delphinus_zkwasm::loader::ZkWasmLoader; 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::TranscriptHash; use halo2aggregator_s::native_verifier; -use halo2aggregator_s::solidity_verifier::codegen::solidity_aux_gen; -use halo2aggregator_s::solidity_verifier::solidity_render; -use halo2aggregator_s::transcript::sha256::ShaRead; use log::debug; use log::error; use log::info; @@ -42,7 +31,7 @@ use std::path::PathBuf; use std::rc::Rc; use wasmi::RuntimeValue; -const AGGREGATE_PREFIX: &'static str = "aggregate-circuit"; +//const AGGREGATE_PREFIX: &'static str = "aggregate-circuit"; pub fn exec_setup( zkwasm_k: u32, @@ -50,13 +39,14 @@ pub fn exec_setup( prefix: &str, wasm_binary: Vec, phantom_functions: Vec, - output_dir: &PathBuf, + _output_dir: &PathBuf, + param_dir: &PathBuf, ) -> Result<()> { 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); @@ -73,7 +63,7 @@ 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); @@ -249,6 +239,7 @@ pub fn exec_create_proof( wasm_binary: Vec, phantom_functions: Vec, output_dir: &PathBuf, + param_dir: &PathBuf, public_inputs: Vec, private_inputs: Vec, context_inputs: Vec, @@ -277,7 +268,7 @@ pub fn exec_create_proof( circuits_batcher::args::HashType::Poseidon ); circuit.proofloadinfo.save(output_dir); - circuit.create_proof(output_dir, output_dir, 0); + circuit.create_proof(output_dir, param_dir, 0); info!("Proof has been created."); Ok(()) @@ -286,13 +277,14 @@ pub fn exec_create_proof( pub fn exec_verify_proof( prefix: &'static str, output_dir: &PathBuf, + 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, output_dir, &proofloadinfo); + let proofs:Vec> = ProofInfo::load_proof(&output_dir, ¶m_dir, &proofloadinfo); let params = load_or_build_unsafe_params::( proofloadinfo.k as u32, - Some(&output_dir.join(format!("K{}.params", proofloadinfo.k))), + Some(¶m_dir.join(format!("K{}.params", proofloadinfo.k))), ); let mut public_inputs_size = 0; for proof in proofs.iter() { @@ -316,194 +308,3 @@ pub fn exec_verify_proof( 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, None)?; - - 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, -) -> Result<()> { - 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)), - ); - - 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 = 6 + 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 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(), - ); - } - - solidity_aux_gen( - &verifier_params_verifier, - &vkey, - &instances[0], - proof, - &output_dir.join(format!("{}.{}.aux.data", AGGREGATE_PREFIX, 0)), - ); - - Ok(()) -} diff --git a/crates/cli/test_cli.sh b/crates/cli/test_cli.sh index beddc5d84..027878eca 100755 --- a/crates/cli/test_cli.sh +++ b/crates/cli/test_cli.sh @@ -6,13 +6,7 @@ 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 --param ./params --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 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 --proof output/zkwasm.0.transcript.data --instance output/zkwasm.0.instance.data From 2c85a7fd29ef0f0cbd57508c323a57ec8b456832 Mon Sep 17 00:00:00 2001 From: sinka Date: Thu, 31 Aug 2023 22:17:25 +1000 Subject: [PATCH 23/35] remove test_cli_checksum.sh --- crates/cli/test_cli_checksum.sh | 23 ----------------------- 1 file changed, 23 deletions(-) delete mode 100755 crates/cli/test_cli_checksum.sh diff --git a/crates/cli/test_cli_checksum.sh b/crates/cli/test_cli_checksum.sh deleted file mode 100755 index 29fc19d7e..000000000 --- a/crates/cli/test_cli_checksum.sh +++ /dev/null @@ -1,23 +0,0 @@ -#!/bin/bash - -set -e -set -x - -rm -rf output/*.data - -# Single test -RUST_LOG=info cargo run --release --features cuda --features checksum -- -k 18 --function zkmain --output ./output --wasm ../zkwasm/wasm/wasm_output.wasm setup -RUST_LOG=info cargo run --release --features cuda --features checksum -- -k 18 --function zkmain --output ./output --wasm ../zkwasm/wasm/wasm_output.wasm checksum - -RUST_LOG=info cargo run --release --features cuda --features checksum -- -k 18 --function zkmain --output ./output --wasm ../zkwasm/wasm/wasm_output.wasm dry-run --public 133:i64 --public 2:i64 - -RUST_LOG=info cargo run --release --features cuda --features checksum -- -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 --features checksum -- -k 18 --function zkmain --output ./output --wasm ../zkwasm/wasm/wasm_output.wasm single-verify --instance output/zkwasm.0.instance.data --proof output/zkwasm.0.transcript.data - -RUST_LOG=info cargo run --release --features cuda --features checksum -- -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 --features checksum -- -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 --features checksum -- -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 From e872503d5c3010dec3745a1c335c8dc3473ca83d Mon Sep 17 00:00:00 2001 From: cwbhhjl Date: Thu, 31 Aug 2023 12:40:33 +0800 Subject: [PATCH 24/35] update wasmi submodule --- .gitmodules | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitmodules b/.gitmodules index 084ccfc30..ff3c5720b 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,3 @@ [submodule "third-party/wasmi"] path = third-party/wasmi - url = git@github.com:DelphinusLab/wasmi.git + url = https://github.com/DelphinusLab/wasmi.git From 28c170e3ad0b7a2fcd405dc4e81b729d4806960a Mon Sep 17 00:00:00 2001 From: sinka Date: Wed, 6 Sep 2023 10:54:30 +1000 Subject: [PATCH 25/35] update README --- README.md | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index c1ea6eccb..c5715414c 100644 --- a/README.md +++ b/README.md @@ -52,6 +52,8 @@ with OPTIONS: -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 @@ -62,15 +64,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. From 0ad6531dda14487558d82925680b8ff8ab7b3543 Mon Sep 17 00:00:00 2001 From: sinka Date: Wed, 6 Sep 2023 11:02:07 +1000 Subject: [PATCH 26/35] remove uncessary ctests --- README.md | 2 +- ctest/arith.wasm | Bin 129 -> 0 bytes ctest/batchinput.wasm | Bin 135 -> 0 bytes ctest/bls.c | 195 ------------------------------------------ ctest/bls.wasm | Bin 1151 -> 0 bytes 5 files changed, 1 insertion(+), 196 deletions(-) delete mode 100755 ctest/arith.wasm delete mode 100755 ctest/batchinput.wasm delete mode 100644 ctest/bls.c delete mode 100755 ctest/bls.wasm diff --git a/README.md b/README.md index c5715414c..8351b5300 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ clang lld wasm code ## Runtime input: -input of wasm function and the top level function must be main. +input of wasm function and the name of the top level function (usually we call the entry function zkmain). ## Proving target: simulation of wasm execution of target wasm bytecode with particular inputs are correct. diff --git a/ctest/arith.wasm b/ctest/arith.wasm deleted file mode 100755 index cfccae5812d8deb432ff7cdb55c3cf4570fe2e16..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 129 zcmXAgK?=e!6hvo!YAP*A!JW7Wy-C*|!gi5Gltde?MHj}UH}RTA+{}ab7z`Ir09>h_ ziO)Rf!6ZhM4Yz8}eec3~x&l8@MmtU}T2KjPQIH~fnV;S3UDV}Tw732g?*jce`oRTA UwdIDAIyU&U_=CHKh6acF3;r${-v9sr diff --git a/ctest/batchinput.wasm b/ctest/batchinput.wasm deleted file mode 100755 index 2aa0c495b31561027f5d5a9d7dd59d779173cc1c..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 135 zcmZQbEY4+QU|?Y6V@_bKX8>Zxx&#KsdL{)X=G440_M+6n(#)b%1_lt1s~o60J~OYN zw1k0?nTe5!m4%U!iHVH^sLQdTgN2)2n29YnH8;Pgl8J$>DmynZGmn9ZONmi|!I43L S(WwCn>YL$A#y|m}95(>@ogk(F diff --git a/ctest/bls.c b/ctest/bls.c deleted file mode 100644 index 58623bd6c..000000000 --- a/ctest/bls.c +++ /dev/null @@ -1,195 +0,0 @@ -#include - -void blspair_g1(uint64_t x); -void blspair_g2(uint64_t x); -uint64_t blspair_pop(void); - -void blssum_g1(uint64_t x); -uint64_t blssum_pop(void); - -void blspair(uint64_t* g1, uint64_t* g2, uint64_t* g3) { - int i; - for(i=0;i<17;i++) { - blspair_g1(g1[i]); - } - for(i=0;i<33;i++) { - blspair_g2(g1[i]); - } - for(i=0;i<48;i++) { - g3[i] = blspair_pop(); - } -} - -void blssum(uint32_t size, uint64_t* g1, uint64_t *gr) { - int i; - for (i=0; i#@ECC$~nkYruic}+NNr#qFghuTUi_#)uvWWhY-?PxsO}HgZlT1_(+`4<|TG0iSx02Uuk~E z3m9c)6Qzt6}TmdYL8G9~&9H$cW|AP%Jt)Ow5igEB$C?O3Ix)M8f%PG9<`h z5+husW5gPZSSesX&>Vd9Zn>ywHuM4CU3E;_qx_HGpLi%KY-v za;=zgVhQg3jDVrnr?0 Date: Fri, 8 Sep 2023 14:48:17 +0800 Subject: [PATCH 27/35] fix output --- crates/cli/src/exec.rs | 2 +- crates/zkwasm/src/loader/mod.rs | 4 ++-- crates/zkwasm/src/runtime/wasmi_interpreter.rs | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/cli/src/exec.rs b/crates/cli/src/exec.rs index c8d1ec543..ba0e197ef 100644 --- a/crates/cli/src/exec.rs +++ b/crates/cli/src/exec.rs @@ -247,7 +247,7 @@ pub fn exec_create_proof( ) -> Result<()> { let loader = ZkWasmLoader::::new(zkwasm_k, wasm_binary, phantom_functions, None)?; - let (circuit, instances) = loader.circuit_with_witness(ExecutionArg { + let (circuit, instances, _) = loader.circuit_with_witness(ExecutionArg { public_inputs, private_inputs, context_inputs, diff --git a/crates/zkwasm/src/loader/mod.rs b/crates/zkwasm/src/loader/mod.rs index 5b660f080..8a08e5664 100644 --- a/crates/zkwasm/src/loader/mod.rs +++ b/crates/zkwasm/src/loader/mod.rs @@ -214,7 +214,7 @@ impl ZkWasmLoader { pub fn circuit_with_witness( &self, arg: ExecutionArg, - ) -> Result<(TestCircuit, Vec)> { + ) -> Result<(TestCircuit, Vec, Vec)> { let execution_result = self.run(arg, true)?; #[allow(unused_mut)] @@ -236,7 +236,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( diff --git a/crates/zkwasm/src/runtime/wasmi_interpreter.rs b/crates/zkwasm/src/runtime/wasmi_interpreter.rs index a8cc7c43e..c3d5f893d 100644 --- a/crates/zkwasm/src/runtime/wasmi_interpreter.rs +++ b/crates/zkwasm/src/runtime/wasmi_interpreter.rs @@ -96,7 +96,7 @@ impl Execution }, result, public_inputs_and_outputs: wasm_io.public_inputs_and_outputs.borrow().clone(), - outputs: wasm_io.public_inputs_and_outputs.borrow().clone(), + outputs: wasm_io.outputs.borrow().clone(), }) } } From 973b565ad720ebf5746285da1ac15b050e4f1223 Mon Sep 17 00:00:00 2001 From: "xingqiang.yuan" Date: Sat, 16 Sep 2023 15:13:27 +0800 Subject: [PATCH 28/35] update batcher --- Cargo.lock | 2 +- crates/cli/src/exec.rs | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4b0c8faa1..1b6821a8b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -313,7 +313,7 @@ dependencies = [ [[package]] name = "circuits-batcher" version = "0.1.0" -source = "git+https://github.com/DelphinusLab/continuation-batcher.git#84a263c99c1b4f269f5cf54f1e5baa5652d4be27" +source = "git+https://github.com/DelphinusLab/continuation-batcher.git#7eccb6358a3b68d13be901791bd0661f0545ea06" dependencies = [ "anyhow", "ark-std", diff --git a/crates/cli/src/exec.rs b/crates/cli/src/exec.rs index ba0e197ef..27d1c3883 100644 --- a/crates/cli/src/exec.rs +++ b/crates/cli/src/exec.rs @@ -4,7 +4,6 @@ use anyhow::Result; use circuits_batcher::proof::CircuitInfo; use circuits_batcher::proof::ProofInfo; use circuits_batcher::proof::ProofLoadInfo; -use circuits_batcher::proof::Prover; use delphinus_zkwasm::circuits::TestCircuit; use delphinus_zkwasm::halo2_proofs; use delphinus_zkwasm::halo2aggregator_s; @@ -268,7 +267,7 @@ pub fn exec_create_proof( circuits_batcher::args::HashType::Poseidon ); circuit.proofloadinfo.save(output_dir); - circuit.create_proof(output_dir, param_dir, 0); + circuit.exec_create_proof(output_dir, param_dir, 0); info!("Proof has been created."); Ok(()) From c3a0d46b56a8497b73f81812d1196239444b5981 Mon Sep 17 00:00:00 2001 From: sinka Date: Sun, 8 Oct 2023 22:18:58 +1100 Subject: [PATCH 29/35] fix: bn254 sum foreign --- crates/zkwasm/src/foreign/ecc_helper/bn254/sum/mod.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/crates/zkwasm/src/foreign/ecc_helper/bn254/sum/mod.rs b/crates/zkwasm/src/foreign/ecc_helper/bn254/sum/mod.rs index 98842cc3b..27ffb0fdf 100644 --- a/crates/zkwasm/src/foreign/ecc_helper/bn254/sum/mod.rs +++ b/crates/zkwasm/src/foreign/ecc_helper/bn254/sum/mod.rs @@ -47,6 +47,7 @@ impl BN254SumContext { 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![]; @@ -58,10 +59,12 @@ impl BN254SumContext { 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) } } @@ -133,14 +136,16 @@ pub fn register_bn254sum_foreign(env: &mut HostEnv) { 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); - //println!("coeff is {:?}", coeff); + log::debug!("g1 is {:?}", g1); let next = g1 * coeff; let g1result = context.acc.add(next).into(); - //println!("msm result: {:?}", g1result); + log::debug!("msm result: {:?}", g1result); context.bn254_result_to_limbs(g1result); }, |_| {()} From 69fa0de27309a1b7acf6fddefcb114c46b2e29cf Mon Sep 17 00:00:00 2001 From: Zhang Junyu Date: Tue, 22 Aug 2023 12:41:33 +0800 Subject: [PATCH 30/35] feat: extract env from loader to support customized plugins --- Cargo.lock | 34 ++++++++ Cargo.toml | 2 +- crates/cli/Cargo.toml | 1 + crates/cli/src/app_builder.rs | 26 +++--- crates/cli/src/exec.rs | 78 ++++++++--------- crates/host/Cargo.toml | 45 ++++++++++ .../src/host}/ecc_helper/bls381/mod.rs | 0 .../src/host}/ecc_helper/bls381/pair/mod.rs | 2 +- .../src/host}/ecc_helper/bls381/sum/mod.rs | 2 +- .../src/host}/ecc_helper/bn254/mod.rs | 0 .../src/host}/ecc_helper/bn254/pair/mod.rs | 2 +- .../src/host}/ecc_helper/bn254/sum/mod.rs | 2 +- .../src/host}/ecc_helper/jubjub/mod.rs | 0 .../src/host}/ecc_helper/jubjub/sum/mod.rs | 2 +- .../src/host}/ecc_helper/mod.rs | 0 .../src/host}/ecc_helper/test.rs | 0 .../src/host}/hash_helper/mod.rs | 0 .../src/host}/hash_helper/poseidon.rs | 2 +- .../src/host}/hash_helper/sha256.rs | 2 +- .../src/host}/keccak_helper/mod.rs | 0 .../src/host}/keccak_helper/test.rs | 0 .../src/host}/merkle_helper/merkle.rs | 4 +- .../src/host}/merkle_helper/mod.rs | 0 crates/host/src/host/mod.rs | 4 + crates/host/src/lib.rs | 65 ++++++++++++++ crates/playground/examples/binary_search.rs | 5 +- crates/playground/examples/context.rs | 5 +- crates/playground/examples/fibonacci.rs | 5 +- crates/playground/examples/phantom.rs | 5 +- crates/zkwasm/src/foreign/mod.rs | 50 ----------- crates/zkwasm/src/loader/mod.rs | 86 +++++-------------- crates/zkwasm/src/runtime/host/default_env.rs | 51 +++++++++++ crates/zkwasm/src/runtime/host/host_env.rs | 2 +- crates/zkwasm/src/runtime/host/mod.rs | 19 +++- crates/zkwasm/src/test/test_rlp.rs | 11 ++- 35 files changed, 325 insertions(+), 187 deletions(-) create mode 100644 crates/host/Cargo.toml rename crates/{zkwasm/src/foreign => host/src/host}/ecc_helper/bls381/mod.rs (100%) rename crates/{zkwasm/src/foreign => host/src/host}/ecc_helper/bls381/pair/mod.rs (98%) rename crates/{zkwasm/src/foreign => host/src/host}/ecc_helper/bls381/sum/mod.rs (97%) rename crates/{zkwasm/src/foreign => host/src/host}/ecc_helper/bn254/mod.rs (100%) rename crates/{zkwasm/src/foreign => host/src/host}/ecc_helper/bn254/pair/mod.rs (98%) rename crates/{zkwasm/src/foreign => host/src/host}/ecc_helper/bn254/sum/mod.rs (98%) rename crates/{zkwasm/src/foreign => host/src/host}/ecc_helper/jubjub/mod.rs (100%) rename crates/{zkwasm/src/foreign => host/src/host}/ecc_helper/jubjub/sum/mod.rs (98%) rename crates/{zkwasm/src/foreign => host/src/host}/ecc_helper/mod.rs (100%) rename crates/{zkwasm/src/foreign => host/src/host}/ecc_helper/test.rs (100%) rename crates/{zkwasm/src/foreign => host/src/host}/hash_helper/mod.rs (100%) rename crates/{zkwasm/src/foreign => host/src/host}/hash_helper/poseidon.rs (98%) rename crates/{zkwasm/src/foreign => host/src/host}/hash_helper/sha256.rs (98%) rename crates/{zkwasm/src/foreign => host/src/host}/keccak_helper/mod.rs (100%) rename crates/{zkwasm/src/foreign => host/src/host}/keccak_helper/test.rs (100%) rename crates/{zkwasm/src/foreign => host/src/host}/merkle_helper/merkle.rs (98%) rename crates/{zkwasm/src/foreign => host/src/host}/merkle_helper/mod.rs (100%) create mode 100644 crates/host/src/host/mod.rs create mode 100644 crates/host/src/lib.rs create mode 100644 crates/zkwasm/src/runtime/host/default_env.rs diff --git a/Cargo.lock b/Cargo.lock index 261b949ce..fb7109fd3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -565,6 +565,7 @@ dependencies = [ "ark-std", "circuits-batcher", "clap", + "delphinus-host", "delphinus-zkwasm", "env_logger", "halo2_proofs", @@ -580,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" 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/crates/cli/Cargo.toml b/crates/cli/Cargo.toml index 6c1ddb711..fe1eca45e 100644 --- a/crates/cli/Cargo.toml +++ b/crates/cli/Cargo.toml @@ -18,6 +18,7 @@ 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 diff --git a/crates/cli/src/app_builder.rs b/crates/cli/src/app_builder.rs index 4e93f2817..3840b44a8 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::cell::RefCell; @@ -135,14 +137,16 @@ pub trait AppBuilder: CommandBuilder { let context_output = Rc::new(RefCell::new(vec![])); - exec_dry_run( + exec_dry_run::( zkwasm_k, wasm_binary, phantom_functions, - public_inputs, - private_inputs, - context_in, - Rc::new(RefCell::new(vec![])), + ExecutionArg { + public_inputs, + private_inputs, + context_inputs: context_in, + context_outputs: Rc::new(RefCell::new(vec![])), + } )?; write_context_output(&context_output.borrow(), context_out_path)?; @@ -161,17 +165,19 @@ 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, ¶m_dir, - public_inputs, - private_inputs, - context_in, - context_out.clone(), + ExecutionArg { + public_inputs, + private_inputs, + context_inputs: context_in, + context_outputs: context_out.clone(), + } )?; write_context_output(&context_out.borrow(), context_out_path)?; diff --git a/crates/cli/src/exec.rs b/crates/cli/src/exec.rs index d8d09fc93..7bb613c93 100644 --- a/crates/cli/src/exec.rs +++ b/crates/cli/src/exec.rs @@ -5,10 +5,8 @@ use circuits_batcher::proof::CircuitInfo; use circuits_batcher::proof::ProofInfo; use circuits_batcher::proof::ProofLoadInfo; use delphinus_zkwasm::circuits::TestCircuit; -use delphinus_zkwasm::halo2_proofs; -use delphinus_zkwasm::halo2aggregator_s; -use delphinus_zkwasm::loader::ExecutionArg; use delphinus_zkwasm::loader::ZkWasmLoader; +use delphinus_zkwasm::runtime::host::HostEnvBuilder; use halo2_proofs::pairing::bn256::Bn256; use halo2_proofs::pairing::bn256::Fr; use halo2_proofs::poly::commitment::ParamsVerifier; @@ -30,6 +28,8 @@ use std::path::PathBuf; use std::rc::Rc; use wasmi::RuntimeValue; use std::io::Write; +use delphinus_host::StandardHostEnvBuilder; +use delphinus_host::ExecutionArg; //const AGGREGATE_PREFIX: &'static str = "aggregate-circuit"; @@ -69,8 +69,11 @@ pub fn exec_setup( info!("Found Verifying at {:?}", vk_path); } else { info!("Create Verifying to {:?}", vk_path); - let loader = - ZkWasmLoader::::new(zkwasm_k, wasm_binary, phantom_functions, None)?; + let loader = ZkWasmLoader::::new( + zkwasm_k, + wasm_binary, + phantom_functions, + )?; let vkey = loader.create_vkey(¶ms)?; @@ -88,7 +91,11 @@ pub fn exec_image_checksum( phantom_functions: Vec, output_dir: &PathBuf, ) -> Result<()> { - let loader = ZkWasmLoader::::new(zkwasm_k, wasm_binary, phantom_functions, None)?; + let loader = ZkWasmLoader::::new( + zkwasm_k, + wasm_binary, + phantom_functions, + )?; let params = load_or_build_unsafe_params::( zkwasm_k, @@ -166,20 +173,20 @@ pub fn exec_dry_run_service( ); let context_outputs = Rc::new(RefCell::new(vec![])); - let loader = ZkWasmLoader::::new( - zkwasm_k, - wasm_binary.clone(), - phantom_functions.clone(), - None, - ) - .unwrap(); - + 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(), + tree_db: None, }) .unwrap(); println!("return value: {:?}", r); @@ -218,47 +225,40 @@ 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: Rc>>, + arg: Arg ) -> Result<()> { - let loader = ZkWasmLoader::::new(zkwasm_k, wasm_binary, phantom_functions, None)?; + 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, param_dir: &PathBuf, - public_inputs: Vec, - private_inputs: Vec, - context_inputs: Vec, - context_outputs: Rc>>, + arg: Arg ) -> Result<()> { - let loader = ZkWasmLoader::::new(zkwasm_k, wasm_binary, phantom_functions, None)?; - - let (circuit, instances, _) = loader.circuit_with_witness(ExecutionArg { - public_inputs, - private_inputs, - context_inputs, - context_outputs, - })?; + let loader = ZkWasmLoader::::new( + zkwasm_k, + wasm_binary, + phantom_functions, + )?; + + + let (circuit, instances, _) = loader.circuit_with_witness(arg)?; if true { info!("Mock test..."); 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/zkwasm/src/foreign/ecc_helper/bls381/mod.rs b/crates/host/src/host/ecc_helper/bls381/mod.rs similarity index 100% rename from crates/zkwasm/src/foreign/ecc_helper/bls381/mod.rs rename to crates/host/src/host/ecc_helper/bls381/mod.rs diff --git a/crates/zkwasm/src/foreign/ecc_helper/bls381/pair/mod.rs b/crates/host/src/host/ecc_helper/bls381/pair/mod.rs similarity index 98% rename from crates/zkwasm/src/foreign/ecc_helper/bls381/pair/mod.rs rename to crates/host/src/host/ecc_helper/bls381/pair/mod.rs index ccd06272b..161d9e5b8 100644 --- a/crates/zkwasm/src/foreign/ecc_helper/bls381/pair/mod.rs +++ b/crates/host/src/host/ecc_helper/bls381/pair/mod.rs @@ -1,5 +1,5 @@ use std::rc::Rc; -use crate::runtime::host::{host_env::HostEnv, ForeignContext}; +use delphinus_zkwasm::runtime::host::{host_env::HostEnv, ForeignContext}; use halo2_proofs::arithmetic::CurveAffine; use halo2_proofs::pairing::bls12_381::{G1Affine, G2Affine, Gt as Bls381Gt, diff --git a/crates/zkwasm/src/foreign/ecc_helper/bls381/sum/mod.rs b/crates/host/src/host/ecc_helper/bls381/sum/mod.rs similarity index 97% rename from crates/zkwasm/src/foreign/ecc_helper/bls381/sum/mod.rs rename to crates/host/src/host/ecc_helper/bls381/sum/mod.rs index 7dce4f922..594d255b3 100644 --- a/crates/zkwasm/src/foreign/ecc_helper/bls381/sum/mod.rs +++ b/crates/host/src/host/ecc_helper/bls381/sum/mod.rs @@ -1,6 +1,6 @@ use std::ops::Add; use std::rc::Rc; -use crate::runtime::host::{host_env::HostEnv, ForeignContext}; +use delphinus_zkwasm::runtime::host::{host_env::HostEnv, ForeignContext}; use halo2_proofs::pairing::bls12_381::G1Affine; use super::{ diff --git a/crates/zkwasm/src/foreign/ecc_helper/bn254/mod.rs b/crates/host/src/host/ecc_helper/bn254/mod.rs similarity index 100% rename from crates/zkwasm/src/foreign/ecc_helper/bn254/mod.rs rename to crates/host/src/host/ecc_helper/bn254/mod.rs diff --git a/crates/zkwasm/src/foreign/ecc_helper/bn254/pair/mod.rs b/crates/host/src/host/ecc_helper/bn254/pair/mod.rs similarity index 98% rename from crates/zkwasm/src/foreign/ecc_helper/bn254/pair/mod.rs rename to crates/host/src/host/ecc_helper/bn254/pair/mod.rs index e3d087508..af5d97302 100644 --- a/crates/zkwasm/src/foreign/ecc_helper/bn254/pair/mod.rs +++ b/crates/host/src/host/ecc_helper/bn254/pair/mod.rs @@ -1,5 +1,5 @@ use std::rc::Rc; -use crate::runtime::host::{host_env::HostEnv, ForeignContext}; +use delphinus_zkwasm::runtime::host::{host_env::HostEnv, ForeignContext}; use halo2_proofs::arithmetic::CurveAffine; use halo2_proofs::pairing::bn256::{G1Affine, G2Affine, Gt as BN254Gt, diff --git a/crates/zkwasm/src/foreign/ecc_helper/bn254/sum/mod.rs b/crates/host/src/host/ecc_helper/bn254/sum/mod.rs similarity index 98% rename from crates/zkwasm/src/foreign/ecc_helper/bn254/sum/mod.rs rename to crates/host/src/host/ecc_helper/bn254/sum/mod.rs index 27ffb0fdf..0c20739c6 100644 --- a/crates/zkwasm/src/foreign/ecc_helper/bn254/sum/mod.rs +++ b/crates/host/src/host/ecc_helper/bn254/sum/mod.rs @@ -1,6 +1,6 @@ use std::rc::Rc; use std::ops::Add; -use crate::runtime::host::{host_env::HostEnv, ForeignContext}; +use delphinus_zkwasm::runtime::host::{host_env::HostEnv, ForeignContext}; use halo2_proofs::pairing::bn256::G1Affine; use halo2_proofs::pairing::group::prime::PrimeCurveAffine; use zkwasm_host_circuits::host::ForeignInst::{ diff --git a/crates/zkwasm/src/foreign/ecc_helper/jubjub/mod.rs b/crates/host/src/host/ecc_helper/jubjub/mod.rs similarity index 100% rename from crates/zkwasm/src/foreign/ecc_helper/jubjub/mod.rs rename to crates/host/src/host/ecc_helper/jubjub/mod.rs diff --git a/crates/zkwasm/src/foreign/ecc_helper/jubjub/sum/mod.rs b/crates/host/src/host/ecc_helper/jubjub/sum/mod.rs similarity index 98% rename from crates/zkwasm/src/foreign/ecc_helper/jubjub/sum/mod.rs rename to crates/host/src/host/ecc_helper/jubjub/sum/mod.rs index b4acee2d9..db450a1d3 100644 --- a/crates/zkwasm/src/foreign/ecc_helper/jubjub/sum/mod.rs +++ b/crates/host/src/host/ecc_helper/jubjub/sum/mod.rs @@ -1,5 +1,5 @@ use std::rc::Rc; -use crate::runtime::host::{host_env::HostEnv, ForeignContext}; +use delphinus_zkwasm::runtime::host::{host_env::HostEnv, ForeignContext}; use num_bigint::BigUint; use zkwasm_host_circuits::host::ForeignInst::{ diff --git a/crates/zkwasm/src/foreign/ecc_helper/mod.rs b/crates/host/src/host/ecc_helper/mod.rs similarity index 100% rename from crates/zkwasm/src/foreign/ecc_helper/mod.rs rename to crates/host/src/host/ecc_helper/mod.rs diff --git a/crates/zkwasm/src/foreign/ecc_helper/test.rs b/crates/host/src/host/ecc_helper/test.rs similarity index 100% rename from crates/zkwasm/src/foreign/ecc_helper/test.rs rename to crates/host/src/host/ecc_helper/test.rs diff --git a/crates/zkwasm/src/foreign/hash_helper/mod.rs b/crates/host/src/host/hash_helper/mod.rs similarity index 100% rename from crates/zkwasm/src/foreign/hash_helper/mod.rs rename to crates/host/src/host/hash_helper/mod.rs diff --git a/crates/zkwasm/src/foreign/hash_helper/poseidon.rs b/crates/host/src/host/hash_helper/poseidon.rs similarity index 98% rename from crates/zkwasm/src/foreign/hash_helper/poseidon.rs rename to crates/host/src/host/hash_helper/poseidon.rs index eac9cec24..77836f5d6 100644 --- a/crates/zkwasm/src/foreign/hash_helper/poseidon.rs +++ b/crates/host/src/host/hash_helper/poseidon.rs @@ -1,5 +1,5 @@ use std::rc::Rc; -use crate::runtime::host::{host_env::HostEnv, ForeignContext}; +use delphinus_zkwasm::runtime::host::{host_env::HostEnv, ForeignContext}; use halo2_proofs::pairing::bn256::Fr; use ff::PrimeField; use poseidon::Poseidon; diff --git a/crates/zkwasm/src/foreign/hash_helper/sha256.rs b/crates/host/src/host/hash_helper/sha256.rs similarity index 98% rename from crates/zkwasm/src/foreign/hash_helper/sha256.rs rename to crates/host/src/host/hash_helper/sha256.rs index b7436cb96..efe3f0f93 100644 --- a/crates/zkwasm/src/foreign/hash_helper/sha256.rs +++ b/crates/host/src/host/hash_helper/sha256.rs @@ -1,5 +1,5 @@ use std::rc::Rc; -use crate::runtime::host::{host_env::HostEnv, ForeignContext}; +use delphinus_zkwasm::runtime::host::{host_env::HostEnv, ForeignContext}; use sha2::Digest; use zkwasm_host_circuits::host::ForeignInst::{ SHA256New, diff --git a/crates/zkwasm/src/foreign/keccak_helper/mod.rs b/crates/host/src/host/keccak_helper/mod.rs similarity index 100% rename from crates/zkwasm/src/foreign/keccak_helper/mod.rs rename to crates/host/src/host/keccak_helper/mod.rs diff --git a/crates/zkwasm/src/foreign/keccak_helper/test.rs b/crates/host/src/host/keccak_helper/test.rs similarity index 100% rename from crates/zkwasm/src/foreign/keccak_helper/test.rs rename to crates/host/src/host/keccak_helper/test.rs diff --git a/crates/zkwasm/src/foreign/merkle_helper/merkle.rs b/crates/host/src/host/merkle_helper/merkle.rs similarity index 98% rename from crates/zkwasm/src/foreign/merkle_helper/merkle.rs rename to crates/host/src/host/merkle_helper/merkle.rs index de973b0cd..cd075c41c 100644 --- a/crates/zkwasm/src/foreign/merkle_helper/merkle.rs +++ b/crates/host/src/host/merkle_helper/merkle.rs @@ -1,5 +1,5 @@ -use crate::runtime::host::host_env::HostEnv; -use crate::runtime::host::ForeignContext; +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; diff --git a/crates/zkwasm/src/foreign/merkle_helper/mod.rs b/crates/host/src/host/merkle_helper/mod.rs similarity index 100% rename from crates/zkwasm/src/foreign/merkle_helper/mod.rs rename to crates/host/src/host/merkle_helper/mod.rs diff --git a/crates/host/src/host/mod.rs b/crates/host/src/host/mod.rs new file mode 100644 index 000000000..82824587c --- /dev/null +++ b/crates/host/src/host/mod.rs @@ -0,0 +1,4 @@ +pub mod ecc_helper; +pub mod hash_helper; +pub mod keccak_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..458a7c946 --- /dev/null +++ b/crates/host/src/lib.rs @@ -0,0 +1,65 @@ +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 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: Rc>>, + /// 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![], Rc::new(RefCell::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/examples/binary_search.rs b/crates/playground/examples/binary_search.rs index 1a7e2e6cd..e53cf55db 100644 --- a/crates/playground/examples/binary_search.rs +++ b/crates/playground/examples/binary_search.rs @@ -2,14 +2,15 @@ use std::cell::RefCell; use std::rc::Rc; 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![], None)?; + let loader = ZkWasmLoader::::new(18, wasm, vec![])?; let (circuit, instances) = loader.circuit_with_witness(ExecutionArg { public_inputs: vec![0], diff --git a/crates/playground/examples/context.rs b/crates/playground/examples/context.rs index c3c0ccb19..280091973 100644 --- a/crates/playground/examples/context.rs +++ b/crates/playground/examples/context.rs @@ -2,8 +2,9 @@ use std::cell::RefCell; use std::rc::Rc; 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 = Rc::new(RefCell::new(vec![])); - let loader = ZkWasmLoader::::new(18, wasm, vec![], None)?; + let loader = ZkWasmLoader::::new(18, wasm, vec![])?; let arg = ExecutionArg { public_inputs: vec![], private_inputs: vec![], diff --git a/crates/playground/examples/fibonacci.rs b/crates/playground/examples/fibonacci.rs index d20a5064e..02cb0c1c1 100644 --- a/crates/playground/examples/fibonacci.rs +++ b/crates/playground/examples/fibonacci.rs @@ -2,14 +2,15 @@ use std::cell::RefCell; use std::rc::Rc; 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![], None)?; + let loader = ZkWasmLoader::::new(18, wasm, vec![])?; let (circuit, instances) = loader.circuit_with_witness(ExecutionArg { public_inputs: vec![5], diff --git a/crates/playground/examples/phantom.rs b/crates/playground/examples/phantom.rs index 6f06dd376..ae58933d3 100644 --- a/crates/playground/examples/phantom.rs +++ b/crates/playground/examples/phantom.rs @@ -2,14 +2,15 @@ use std::cell::RefCell; use std::rc::Rc; 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(), diff --git a/crates/zkwasm/src/foreign/mod.rs b/crates/zkwasm/src/foreign/mod.rs index 0ce917da5..12d9b2c6c 100644 --- a/crates/zkwasm/src/foreign/mod.rs +++ b/crates/zkwasm/src/foreign/mod.rs @@ -1,39 +1,16 @@ -use std::cell::RefCell; -use std::rc::Rc; - 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 zkwasm_host_circuits::host::db::TreeDB; - -use self::context::runtime::register_context_foreign; -use self::ecc_helper::bls381::pair::register_blspair_foreign; -use self::ecc_helper::bls381::sum::register_blssum_foreign; -use self::ecc_helper::bn254::pair::register_bn254pair_foreign; -use self::ecc_helper::bn254::sum::register_bn254sum_foreign; -use self::ecc_helper::jubjub::sum::register_babyjubjubsum_foreign; -use self::hash_helper::poseidon::register_poseidon_foreign; -use self::hash_helper::sha256::register_sha256_foreign; -use self::log_helper::register_log_foreign; -use self::merkle_helper::merkle::register_merkle_foreign; -use self::require_helper::register_require_foreign; -use self::wasm_input_helper::runtime::register_wasm_input_foreign; pub mod context; -pub mod ecc_helper; -pub mod hash_helper; -pub mod keccak_helper; pub mod log_helper; -pub mod merkle_helper; pub mod require_helper; pub mod wasm_input_helper; @@ -63,30 +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: Rc>>, - tree_db: Option>>, - ) -> (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_merkle_foreign(&mut env, tree_db); - register_blspair_foreign(&mut env); - register_blssum_foreign(&mut env); - register_bn254pair_foreign(&mut env); - register_bn254sum_foreign(&mut env); - register_sha256_foreign(&mut env); - register_poseidon_foreign(&mut env); - register_babyjubjubsum_foreign(&mut env); - register_context_foreign(&mut env, context_input, context_output); - env.finalize(); - - (env, wasm_runtime_io) - } -} diff --git a/crates/zkwasm/src/loader/mod.rs b/crates/zkwasm/src/loader/mod.rs index 0757eba42..faea44e7e 100644 --- a/crates/zkwasm/src/loader/mod.rs +++ b/crates/zkwasm/src/loader/mod.rs @@ -1,6 +1,4 @@ -use std::cell::RefCell; use std::marker::PhantomData; -use std::rc::Rc; use anyhow::Result; use halo2_proofs::arithmetic::MultiMillerLoop; @@ -35,41 +33,32 @@ 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; use crate::runtime::WasmInterpreter; use anyhow::anyhow; -use zkwasm_host_circuits::host::db::TreeDB; 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: Rc>>, -} - pub struct ExecutionReturn { pub context_output: Vec, } -pub struct ZkWasmLoader { +pub struct ZkWasmLoader> { k: u32, module: wasmi::Module, phantom_functions: Vec, - _data: PhantomData, - tree_db: Option>>, + _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; @@ -112,14 +101,8 @@ impl ZkWasmLoader { ) } - pub fn circuit_without_witness(&self) -> Result> { - let (env, wasm_runtime_io) = HostEnv::new_with_full_foreign_plugins( - vec![], - vec![], - vec![], - Rc::new(RefCell::new(vec![])), - None, - ); + fn circuit_without_witness(&self) -> Result> { + let (env, wasm_runtime_io) = EnvBuilder::create_env_without_value(); let compiled_module = self.compile(&env)?; @@ -138,7 +121,6 @@ impl ZkWasmLoader { k: u32, image: Vec, phantom_functions: Vec, - tree_db: Option>>, ) -> Result { set_zkwasm_k(k); @@ -148,8 +130,9 @@ impl ZkWasmLoader { k, module, phantom_functions, - _data: PhantomData, - tree_db, + _data_e: PhantomData, + _data_builder: PhantomData, + _data_arg: PhantomData, }; loader.precheck()?; @@ -165,13 +148,7 @@ impl ZkWasmLoader { } pub fn checksum(&self, params: &Params) -> Result> { - let (env, _) = HostEnv::new_with_full_foreign_plugins( - vec![], - vec![], - vec![], - Rc::new(RefCell::new(vec![])), - None, - ); + let (env, _) = EnvBuilder::create_env_without_value(); let compiled = self.compile(&env)?; let table_with_params = CompilationTableWithParams { @@ -183,34 +160,17 @@ 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, - self.tree_db.clone(), - ); +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, - write_to_file: bool, - ) -> 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, - self.tree_db.clone(), - ); - + 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)?; @@ -224,12 +184,8 @@ impl ZkWasmLoader { Ok(result) } - pub fn circuit_with_witness( - &self, - arg: ExecutionArg, - ) -> Result<(TestCircuit, Vec, Vec)> { + pub fn circuit_with_witness(&self, arg: T) -> Result<(TestCircuit, Vec, Vec)> { let execution_result = self.run(arg, true)?; - let instance: Vec = execution_result .public_inputs_and_outputs .clone() @@ -339,10 +295,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..44a100544 --- /dev/null +++ b/crates/zkwasm/src/runtime/host/default_env.rs @@ -0,0 +1,51 @@ +use std::cell::RefCell; +use std::rc::Rc; + +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 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: Rc>>, +} + +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![], Rc::new(RefCell::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..3f6402018 100644 --- a/crates/zkwasm/src/runtime/host/mod.rs +++ b/crates/zkwasm/src/runtime/host/mod.rs @@ -8,9 +8,14 @@ use wasmi::RuntimeArgs; use wasmi::RuntimeValue; use wasmi::Signature; -pub mod host_env; +use self::host_env::HostEnv; + +use super::wasmi_interpreter::WasmRuntimeIO; + +pub mod default_env; +pub mod external_circuit_plugin; -mod external_circuit_plugin; +pub mod host_env; mod internal_circuit_plugin; trait MatchForeignOpSignature { @@ -67,3 +72,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 8b184bda1..739d12bc4 100644 --- a/crates/zkwasm/src/test/test_rlp.rs +++ b/crates/zkwasm/src/test/test_rlp.rs @@ -2,14 +2,19 @@ use std::cell::RefCell; use std::rc::Rc; 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,7 +154,7 @@ fn build_circuit() -> Result<(ZkWasmLoader, TestCircuit, Vec)> { let wasm = std::fs::read("wasm/rlp.wasm").unwrap(); - let loader = ZkWasmLoader::::new(20, wasm, vec![], None)?; + let loader = ZkWasmLoader::::new(20, wasm, vec![], ())?; let (circuit, instances, _) = loader.circuit_with_witness(ExecutionArg { public_inputs, From c26de2182eb481dad7f6affb30b55f0bb529bd2b Mon Sep 17 00:00:00 2001 From: sinka Date: Mon, 16 Oct 2023 11:51:04 +1100 Subject: [PATCH 31/35] resolve pr comments --- README.md | 2 +- crates/cli/src/app_builder.rs | 16 +++++++++------- crates/cli/src/command.rs | 5 +---- crates/cli/src/exec.rs | 21 +++++++++------------ crates/cli/test_cli.sh | 4 ++-- crates/zkwasm/Cargo.toml | 6 ------ crates/zkwasm/src/circuits/mod.rs | 7 ------- test_bls.sh | 14 -------------- 8 files changed, 22 insertions(+), 53 deletions(-) delete mode 100755 test_bls.sh diff --git a/README.md b/README.md index 8351b5300..fa370fe84 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ clang lld wasm code ## Runtime input: -input of wasm function and the name of the top level function (usually we call the entry function zkmain). +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. diff --git a/crates/cli/src/app_builder.rs b/crates/cli/src/app_builder.rs index 3840b44a8..06843fd2a 100644 --- a/crates/cli/src/app_builder.rs +++ b/crates/cli/src/app_builder.rs @@ -102,7 +102,7 @@ pub trait AppBuilder: CommandBuilder { fs::create_dir_all(&output_dir)?; match top_matches.subcommand() { - Some(("setup", _)) => exec_setup( + Some(("setup", _)) => exec_setup::( zkwasm_k, Self::AGGREGATE_K, Self::NAME, @@ -112,7 +112,7 @@ pub trait AppBuilder: CommandBuilder { ¶m_dir, ), Some(("checksum", _)) => { - exec_image_checksum(zkwasm_k, wasm_binary, phantom_functions, &output_dir) + 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); @@ -131,7 +131,12 @@ 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); @@ -184,10 +189,7 @@ pub trait AppBuilder: CommandBuilder { 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); - + Some(("single-verify", _)) => { exec_verify_proof( Self::NAME, &output_dir, 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 7bb613c93..5fa0b5337 100644 --- a/crates/cli/src/exec.rs +++ b/crates/cli/src/exec.rs @@ -7,6 +7,8 @@ use circuits_batcher::proof::ProofLoadInfo; use delphinus_zkwasm::circuits::TestCircuit; use delphinus_zkwasm::loader::ZkWasmLoader; use delphinus_zkwasm::runtime::host::HostEnvBuilder; +use delphinus_zkwasm::runtime::host::default_env::DefaultHostEnvBuilder; +use delphinus_zkwasm::runtime::host::default_env::ExecutionArg; use halo2_proofs::pairing::bn256::Bn256; use halo2_proofs::pairing::bn256::Fr; use halo2_proofs::poly::commitment::ParamsVerifier; @@ -28,12 +30,8 @@ use std::path::PathBuf; use std::rc::Rc; use wasmi::RuntimeValue; use std::io::Write; -use delphinus_host::StandardHostEnvBuilder; -use delphinus_host::ExecutionArg; -//const AGGREGATE_PREFIX: &'static str = "aggregate-circuit"; - -pub fn exec_setup( +pub fn exec_setup( zkwasm_k: u32, aggregate_k: u32, prefix: &str, @@ -41,7 +39,7 @@ pub fn exec_setup( phantom_functions: Vec, _output_dir: &PathBuf, param_dir: &PathBuf, -) -> Result<()> { +) -> Result<()> where Builder: HostEnvBuilder { info!("Setup Params and VerifyingKey"); macro_rules! prepare_params { @@ -69,7 +67,7 @@ pub fn exec_setup( info!("Found Verifying at {:?}", vk_path); } else { info!("Create Verifying to {:?}", vk_path); - let loader = ZkWasmLoader::::new( + let loader = ZkWasmLoader::::new( zkwasm_k, wasm_binary, phantom_functions, @@ -85,13 +83,13 @@ 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( +) -> Result<()> where Builder: HostEnvBuilder { + let loader = ZkWasmLoader::::new( zkwasm_k, wasm_binary, phantom_functions, @@ -174,7 +172,7 @@ pub fn exec_dry_run_service( let context_outputs = Rc::new(RefCell::new(vec![])); let loader = - ZkWasmLoader::::new( + ZkWasmLoader::::new( zkwasm_k, wasm_binary.clone(), phantom_functions.clone(), @@ -186,7 +184,6 @@ pub fn exec_dry_run_service( private_inputs, context_inputs, context_outputs: context_outputs.clone(), - tree_db: None, }) .unwrap(); println!("return value: {:?}", r); diff --git a/crates/cli/test_cli.sh b/crates/cli/test_cli.sh index 0f963e5b6..bdf25a072 100755 --- a/crates/cli/test_cli.sh +++ b/crates/cli/test_cli.sh @@ -7,7 +7,7 @@ rm -rf output/*.data # Single test 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 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 --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 --proof output/zkwasm.0.transcript.data --instance output/zkwasm.0.instance.data +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/zkwasm/Cargo.toml b/crates/zkwasm/Cargo.toml index c892fe520..1393edbe7 100644 --- a/crates/zkwasm/Cargo.toml +++ b/crates/zkwasm/Cargo.toml @@ -22,15 +22,9 @@ 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" } -#parity-wasm = { version = "0.42.0", default-features = false } -#notify = "6.0.1" -#wast = "47.0.0" -#uuid = { version = "1.2.2", features = ["serde", "v4"] } -#quote = "1.0.25" anyhow.workspace = true halo2aggregator-s.workspace = true diff --git a/crates/zkwasm/src/circuits/mod.rs b/crates/zkwasm/src/circuits/mod.rs index dadef01ad..686ba9410 100644 --- a/crates/zkwasm/src/circuits/mod.rs +++ b/crates/zkwasm/src/circuits/mod.rs @@ -39,13 +39,6 @@ impl TestCircuit { _data: PhantomData, } } - - pub fn new_without_configure(tables: Tables) -> Self { - TestCircuit { - tables, - _data: PhantomData, - } - } } trait Encode { diff --git a/test_bls.sh b/test_bls.sh deleted file mode 100755 index d799d633d..000000000 --- a/test_bls.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/bash - -set -e -set -x - -# rm -rf output - -# Single test -RUST_LOG=info cargo run --release -- -k 20 --function zkmain --output ./output --wasm ctest/bls.wasm setup - -RUST_LOG=info cargo run --release -- -k 20 --function zkmain --output ./output --wasm ctest/bls.wasm single-prove -RUST_LOG=info cargo run --release -- -k 20 --function zkmain --output ./output --wasm ctest/bls.wasm single-verify --proof output/zkwasm.0.transcript.data -RUST_LOG=info cargo run --release -- -k 20 --function zkmain --output ./output --wasm ctest/bls.wasm aggregate-prove -RUST_LOG=info cargo run --release -- -k 20 --function zkmain --output ./output --wasm ctest/bls.wasm aggregate-verify --proof output/aggregate-circuit.0.transcript.data --instances output/aggregate-circuit.0.instance.data From 28ffe4dc45888d8ce654ff80f28fa45b21f7adbc Mon Sep 17 00:00:00 2001 From: Sinka Date: Mon, 23 Oct 2023 16:19:12 +0800 Subject: [PATCH 32/35] fmt code --- crates/cli/src/app_builder.rs | 33 ++--- crates/cli/src/args.rs | 1 - crates/cli/src/exec.rs | 70 +++++------ crates/host/src/host/ecc_helper/bls381/mod.rs | 38 +++--- .../src/host/ecc_helper/bls381/pair/mod.rs | 100 ++++++++------- .../src/host/ecc_helper/bls381/sum/mod.rs | 47 ++++--- crates/host/src/host/ecc_helper/bn254/mod.rs | 47 ++++--- .../src/host/ecc_helper/bn254/pair/mod.rs | 117 +++++++++--------- .../host/src/host/ecc_helper/bn254/sum/mod.rs | 39 +++--- crates/host/src/host/ecc_helper/jubjub/mod.rs | 22 ++-- .../src/host/ecc_helper/jubjub/sum/mod.rs | 60 +++++---- crates/host/src/host/ecc_helper/mod.rs | 6 +- crates/host/src/host/ecc_helper/test.rs | 74 ++++++----- crates/host/src/host/hash_helper/mod.rs | 2 +- crates/host/src/host/hash_helper/poseidon.rs | 44 +++---- crates/host/src/host/hash_helper/sha256.rs | 41 +++--- crates/host/src/lib.rs | 4 +- crates/specs/src/brtable.rs | 3 +- crates/specs/src/configure_table.rs | 3 +- crates/specs/src/etable.rs | 3 +- .../specs/src/external_host_call_table/mod.rs | 3 +- crates/specs/src/host_function.rs | 3 +- crates/specs/src/imtable.rs | 3 +- crates/specs/src/itable.rs | 3 +- crates/specs/src/jtable.rs | 3 +- crates/specs/src/lib.rs | 3 +- crates/specs/src/mtable.rs | 15 ++- crates/specs/src/step.rs | 3 +- crates/specs/src/types.rs | 3 +- crates/zkwasm/src/loader/mod.rs | 27 +--- crates/zkwasm/src/runtime/host/default_env.rs | 2 +- crates/zkwasm/src/test/test_rlp.rs | 3 +- 32 files changed, 403 insertions(+), 422 deletions(-) diff --git a/crates/cli/src/app_builder.rs b/crates/cli/src/app_builder.rs index 4adf59da9..078cb1b6b 100644 --- a/crates/cli/src/app_builder.rs +++ b/crates/cli/src/app_builder.rs @@ -94,8 +94,7 @@ 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 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")); @@ -111,9 +110,12 @@ pub trait AppBuilder: CommandBuilder { &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); @@ -131,12 +133,7 @@ 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); @@ -150,8 +147,8 @@ pub trait AppBuilder: CommandBuilder { public_inputs, private_inputs, context_inputs: context_in, - context_outputs: Arc::new(Mutex::new(vec![])) - } + context_outputs: Arc::new(Mutex::new(vec![])), + }, )?; write_context_output(&context_output.lock().unwrap(), context_out_path)?; @@ -182,20 +179,14 @@ pub trait AppBuilder: CommandBuilder { 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", _)) => { - exec_verify_proof( - Self::NAME, - &output_dir, - ¶m_dir - ) - } + 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 dc5bfb6b9..ba65aba75 100644 --- a/crates/cli/src/args.rs +++ b/crates/cli/src/args.rs @@ -123,7 +123,6 @@ pub trait ArgBuilder { ).value_parser(value_parser!(PathBuf)) } - fn proof_path_arg<'a>() -> Arg<'a> { arg!( -p --proof "Path of proof." diff --git a/crates/cli/src/exec.rs b/crates/cli/src/exec.rs index 79dee797d..2c13b8374 100644 --- a/crates/cli/src/exec.rs +++ b/crates/cli/src/exec.rs @@ -6,9 +6,9 @@ use circuits_batcher::proof::ProofInfo; use circuits_batcher::proof::ProofLoadInfo; use delphinus_zkwasm::circuits::TestCircuit; use delphinus_zkwasm::loader::ZkWasmLoader; -use delphinus_zkwasm::runtime::host::HostEnvBuilder; use delphinus_zkwasm::runtime::host::default_env::DefaultHostEnvBuilder; use delphinus_zkwasm::runtime::host::default_env::ExecutionArg; +use delphinus_zkwasm::runtime::host::HostEnvBuilder; use halo2_proofs::pairing::bn256::Bn256; use halo2_proofs::pairing::bn256::Fr; use halo2_proofs::poly::commitment::ParamsVerifier; @@ -24,12 +24,12 @@ 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 std::io::Write; pub fn exec_setup( zkwasm_k: u32, @@ -39,7 +39,10 @@ pub fn exec_setup( phantom_functions: Vec, _output_dir: &PathBuf, param_dir: &PathBuf, -) -> Result<()> where Builder: HostEnvBuilder { +) -> Result<()> +where + Builder: HostEnvBuilder, +{ info!("Setup Params and VerifyingKey"); macro_rules! prepare_params { @@ -67,11 +70,8 @@ pub fn exec_setup( 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,12 +88,12 @@ pub fn exec_image_checksum( wasm_binary: Vec, phantom_functions: Vec, output_dir: &PathBuf, -) -> Result<()> where Builder: HostEnvBuilder { - 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, @@ -222,38 +222,31 @@ 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, - arg: Arg + 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(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, param_dir: &PathBuf, - arg: Arg + arg: Arg, ) -> Result<()> { - let loader = ZkWasmLoader::::new( - zkwasm_k, - wasm_binary, - phantom_functions, - )?; - + let loader = + ZkWasmLoader::::new(zkwasm_k, wasm_binary, phantom_functions)?; let (circuit, instances, _) = loader.circuit_with_witness(arg)?; @@ -263,12 +256,12 @@ pub fn exec_create_proof>( info!("Mock test passed"); } - let circuit: CircuitInfo> = CircuitInfo::new( + let circuit: CircuitInfo> = CircuitInfo::new( circuit, prefix.to_string(), vec![instances], zkwasm_k as usize, - circuits_batcher::args::HashType::Poseidon + circuits_batcher::args::HashType::Poseidon, ); circuit.proofloadinfo.save(output_dir); circuit.exec_create_proof(output_dir, param_dir, 0); @@ -285,17 +278,21 @@ pub fn exec_verify_proof( ) -> 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 proofs: Vec> = + ProofInfo::load_proof(&output_dir, ¶m_dir, &proofloadinfo); let params = load_or_build_unsafe_params::( proofloadinfo.k as u32, Some(¶m_dir.join(format!("K{}.params", proofloadinfo.k))), ); 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())) - ); + public_inputs_size = usize::max( + public_inputs_size, + proof + .instances + .iter() + .fold(0, |acc, x| usize::max(acc, x.len())), + ); } let params_verifier: ParamsVerifier = params.verifier(public_inputs_size).unwrap(); @@ -312,4 +309,3 @@ pub fn exec_verify_proof( Ok(()) } - diff --git a/crates/host/src/host/ecc_helper/bls381/mod.rs b/crates/host/src/host/ecc_helper/bls381/mod.rs index 4c4f71292..badfe5699 100644 --- a/crates/host/src/host/ecc_helper/bls381/mod.rs +++ b/crates/host/src/host/ecc_helper/bls381/mod.rs @@ -1,20 +1,18 @@ -pub mod sum; pub mod pair; -use num_bigint::BigUint; +pub mod sum; use ark_std::Zero; -use std::ops::AddAssign; -use num_traits::FromPrimitive; use halo2_proofs::arithmetic::CurveAffine; -use halo2_proofs::pairing::bls12_381::{G1Affine, - Fp2 as Bls381Fq2, - Fq as Bls381Fq, -}; +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, field_to_bn -}; +use super::bn_to_field; +use super::field_to_bn; -fn fetch_fq(limbs: &Vec, index:usize) -> Bls381Fq { +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)) @@ -22,10 +20,10 @@ fn fetch_fq(limbs: &Vec, index:usize) -> Bls381Fq { bn_to_field(&bn) } -fn fetch_fq2(limbs: &Vec, index:usize) -> Bls381Fq2 { +fn fetch_fq2(limbs: &Vec, index: usize) -> Bls381Fq2 { Bls381Fq2 { - c0: fetch_fq(limbs,index), - c1: fetch_fq(limbs, index+1), + c0: fetch_fq(limbs, index), + c1: fetch_fq(limbs, index + 1), } } @@ -33,10 +31,7 @@ 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(); + let opt: Option<_> = G1Affine::from_xy(fetch_fq(limbs, 0), fetch_fq(limbs, 1)).into(); opt.expect("from xy failed, not on curve") } } @@ -44,7 +39,7 @@ fn fetch_g1(limbs: &Vec, g1_identity: bool) -> G1Affine { 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 d: BigUint = BigUint::from(1u64 << 54); let r = bn.clone() % d.clone(); let value = if r == BigUint::from(0 as u32) { 0 as u64 @@ -53,6 +48,5 @@ fn bls381_fq_to_limbs(result_limbs: &mut Vec, f: Bls381Fq) { }; 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 index 161d9e5b8..b1e6c6d0c 100644 --- a/crates/host/src/host/ecc_helper/bls381/pair/mod.rs +++ b/crates/host/src/host/ecc_helper/bls381/pair/mod.rs @@ -1,15 +1,14 @@ -use std::rc::Rc; -use delphinus_zkwasm::runtime::host::{host_env::HostEnv, ForeignContext}; +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::{G1Affine, G2Affine, - Gt as Bls381Gt, - pairing, -}; -use super::{ - bls381_fq_to_limbs, - fetch_fq, - fetch_fq2, -}; +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)] @@ -24,32 +23,31 @@ struct BlsPairContext { 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); + 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 {} @@ -57,19 +55,19 @@ 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())); + .external_env + .register_plugin("foreign_blspair", Box::new(BlsPairContext::default())); env.external_env.register_function( "blspair_g1", - ForeignInst::BlsPairG1 as usize, + 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); + let t: u64 = args.nth(0); context.g1_identity = t != 0; context.input_cursor = 0; } else { @@ -89,23 +87,21 @@ pub fn register_blspair_foreign(env: &mut HostEnv) { |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 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() + G1Affine::from_xy(fetch_fq(&context.limbs, 0), fetch_fq(&context.limbs, 1)) + .unwrap() }; - let g2 = if context.g2_identity{ + 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() + x: fetch_fq2(&context.limbs, 2), + y: fetch_fq2(&context.limbs, 4), + infinity: (0 as u8).into(), } }; let ab = pairing(&g1, &g2); @@ -128,7 +124,9 @@ pub fn register_blspair_foreign(env: &mut HostEnv) { 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)); + 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 index 594d255b3..4679c5938 100644 --- a/crates/host/src/host/ecc_helper/bls381/sum/mod.rs +++ b/crates/host/src/host/ecc_helper/bls381/sum/mod.rs @@ -1,12 +1,11 @@ +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 delphinus_zkwasm::runtime::host::{host_env::HostEnv, ForeignContext}; -use halo2_proofs::pairing::bls12_381::G1Affine; -use super::{ - bls381_fq_to_limbs, - fetch_g1, -}; +use super::bls381_fq_to_limbs; +use super::fetch_g1; use zkwasm_host_circuits::host::ForeignInst; @@ -22,9 +21,9 @@ struct BlsSumContext { 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.x); bls381_fq_to_limbs(&mut limbs, g.y); - self.result_limbs = Some (limbs); + self.result_limbs = Some(limbs); if g.is_identity().into() { self.result_limbs.as_mut().unwrap().append(&mut vec![1u64]); } else { @@ -38,8 +37,8 @@ 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())); + .external_env + .register_plugin("foreign_blssum", Box::new(BlsSumContext::default())); env.external_env.register_function( "blssum_g1", @@ -50,7 +49,7 @@ pub fn register_blssum_foreign(env: &mut HostEnv) { |context: &mut dyn ForeignContext, args: wasmi::RuntimeArgs| { let context = context.downcast_mut::().unwrap(); if context.input_cursor == 16 { - let t:u64 = args.nth(0); + let t: u64 = args.nth(0); context.g1_identity.push(t != 0); context.input_cursor = 0; } else { @@ -72,19 +71,27 @@ pub fn register_blssum_foreign(env: &mut HostEnv) { 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 - }); + 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)); + 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 index 429d787f1..d2514e3c1 100644 --- a/crates/host/src/host/ecc_helper/bn254/mod.rs +++ b/crates/host/src/host/ecc_helper/bn254/mod.rs @@ -1,21 +1,21 @@ -pub mod sum; pub mod pair; -use num_bigint::BigUint; -use halo2_proofs::pairing::bn256::{ - Fq2 as BN254Fq2, - Fq as BN254Fq, - G1Affine, - Fr, -}; +pub mod sum; use ark_std::Zero; -use std::ops::{AddAssign, Shl}; -use num_traits::FromPrimitive; 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; +const LIMBSZ: usize = 54; +const LIMBNB: usize = 5; -use super::{bn_to_field, field_to_bn}; +use super::bn_to_field; +use super::field_to_bn; fn fetch_fr(limbs: &Vec) -> Fr { let mut bn = BigUint::zero(); @@ -25,7 +25,7 @@ fn fetch_fr(limbs: &Vec) -> Fr { bn_to_field(&bn) } -pub fn fetch_fq(limbs: &Vec, index:usize) -> BN254Fq { +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)) @@ -33,24 +33,21 @@ pub fn fetch_fq(limbs: &Vec, index:usize) -> BN254Fq { bn_to_field(&bn) } -pub fn fetch_fq2(limbs: &Vec, index:usize) -> BN254Fq2 { +pub fn fetch_fq2(limbs: &Vec, index: usize) -> BN254Fq2 { BN254Fq2 { - c0: fetch_fq(limbs,index), - c1: fetch_fq(limbs, index+1), + 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]; + 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(); + let opt: Option<_> = G1Affine::from_xy(fetch_fq(limbs, 0), fetch_fq(limbs, 1)).into(); opt.expect("from xy failed, not on curve") } } @@ -58,7 +55,7 @@ fn fetch_g1(limbs: &Vec) -> G1Affine { 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 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 @@ -67,5 +64,5 @@ pub fn bn254_fq_to_limbs(result_limbs: &mut Vec, f: BN254Fq) { }; 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 index af5d97302..6b00b32b8 100644 --- a/crates/host/src/host/ecc_helper/bn254/pair/mod.rs +++ b/crates/host/src/host/ecc_helper/bn254/pair/mod.rs @@ -1,24 +1,21 @@ -use std::rc::Rc; -use delphinus_zkwasm::runtime::host::{host_env::HostEnv, ForeignContext}; +use delphinus_zkwasm::runtime::host::host_env::HostEnv; +use delphinus_zkwasm::runtime::host::ForeignContext; use halo2_proofs::arithmetic::CurveAffine; -use halo2_proofs::pairing::bn256::{G1Affine, G2Affine, - Gt as BN254Gt, - pairing, -}; +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::{ - LIMBNB, - bn254_fq_to_limbs, - fetch_fq, - fetch_fq2, -}; +use super::bn254_fq_to_limbs; +use super::fetch_fq; +use super::fetch_fq2; +use super::LIMBNB; -use zkwasm_host_circuits::host::ForeignInst::{ - Bn254PairG1, - Bn254PairG2, - Bn254PairG3, -}; +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 { @@ -33,32 +30,31 @@ struct BN254PairContext { 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); + 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 {} @@ -66,8 +62,8 @@ 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())); + .external_env + .register_plugin("foreign_blspair", Box::new(BN254PairContext::default())); env.external_env.register_function( "bn254pair_g1", @@ -77,8 +73,8 @@ pub fn register_bn254pair_foreign(env: &mut HostEnv) { 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); + if context.input_cursor == LIMBNB * 2 { + let t: u64 = args.nth(0); context.g1_identity = t != 0; context.input_cursor = 0; } else { @@ -97,34 +93,33 @@ pub fn register_bn254pair_foreign(env: &mut HostEnv) { 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; + 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( + let opt: Option<_> = G1Affine::from_xy( fetch_fq(&context.limbs, 0), - fetch_fq(&context.limbs, 1) - ).into(); + fetch_fq(&context.limbs, 1), + ) + .into(); opt.expect("invalid g1 affine") }; - let g2 = if context.g2_identity{ + let g2 = if context.g2_identity { G2Affine::identity() } else { - let opt:Option<_> = G2Affine { + let opt: Option<_> = G2Affine { x: fetch_fq2(&context.limbs, 2), y: fetch_fq2(&context.limbs, 4), - }.into(); + } + .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 - )); + 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)); @@ -148,7 +143,9 @@ pub fn register_bn254pair_foreign(env: &mut HostEnv) { 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)); + 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 index 0c20739c6..2ae7a8301 100644 --- a/crates/host/src/host/ecc_helper/bn254/sum/mod.rs +++ b/crates/host/src/host/ecc_helper/bn254/sum/mod.rs @@ -1,17 +1,17 @@ -use std::rc::Rc; -use std::ops::Add; -use delphinus_zkwasm::runtime::host::{host_env::HostEnv, ForeignContext}; +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 zkwasm_host_circuits::host::ForeignInst::{ - Bn254SumNew, Bn254SumScalar, Bn254SumG1, Bn254SumResult, -}; +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, - fetch_g1, - fetch_fr, -}; +use super::bn254_fq_to_limbs; +use super::fetch_fr; +use super::fetch_g1; struct BN254SumContext { pub acc: G1Affine, @@ -21,13 +21,12 @@ struct BN254SumContext { 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); + self.result_limbs = Some(limbs); if g.is_identity().into() { self.result_limbs.as_mut().unwrap().append(&mut vec![1u64]); } else { @@ -45,7 +44,6 @@ impl BN254SumContext { } } - pub fn bn254_sum_new(&mut self, new: usize) { log::debug!("new bn254 sum context"); self.result_limbs = None; @@ -57,7 +55,6 @@ impl BN254SumContext { } } - fn bn254_sum_push_scalar(&mut self, v: u64) { log::debug!("push scalar {}", v); self.coeffs.push(v) @@ -81,8 +78,8 @@ impl ForeignContext for BN254SumContext {} 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())); + .external_env + .register_plugin("foreign_bn254sum", Box::new(BN254SumContext::default())); env.external_env.register_function( "bn254_sum_new", @@ -98,7 +95,6 @@ pub fn register_bn254sum_foreign(env: &mut HostEnv) { ), ); - env.external_env.register_function( "bn254_sum_scalar", Bn254SumScalar as usize, @@ -127,7 +123,6 @@ pub fn register_bn254sum_foreign(env: &mut HostEnv) { ), ); - env.external_env.register_function( "bn254_sum_finalize", Bn254SumResult as usize, @@ -148,10 +143,12 @@ pub fn register_bn254sum_foreign(env: &mut HostEnv) { 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)); + 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 index 37b6bb798..a9993ed46 100644 --- a/crates/host/src/host/ecc_helper/jubjub/mod.rs +++ b/crates/host/src/host/ecc_helper/jubjub/mod.rs @@ -1,19 +1,19 @@ pub mod sum; -use num_bigint::BigUint; -use halo2_proofs::pairing::bn256::{ - Fr as BabyJubjubFq, -}; use ark_std::Zero; -use std::ops::{AddAssign, Shl}; +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; +const LIMBSZ: usize = 64; +const LIMBNB: usize = 4; -use super::{bn_to_field, field_to_bn}; +use super::bn_to_field; +use super::field_to_bn; -pub fn fetch_fq(limbs: &Vec, index:usize) -> BabyJubjubFq { +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)) @@ -31,7 +31,7 @@ fn fetch_g1(limbs: &Vec) -> jubjub::Point { 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 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 @@ -40,5 +40,5 @@ pub fn babyjubjub_fq_to_limbs(result_limbs: &mut Vec, f: BabyJubjubFq) { }; 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 index db450a1d3..45b7fe65f 100644 --- a/crates/host/src/host/ecc_helper/jubjub/sum/mod.rs +++ b/crates/host/src/host/ecc_helper/jubjub/sum/mod.rs @@ -1,25 +1,29 @@ -use std::rc::Rc; -use delphinus_zkwasm::runtime::host::{host_env::HostEnv, ForeignContext}; +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, JubjubSumPush, JubjubSumResult, -}; +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::{ - LIMBNB, - babyjubjub_fq_to_limbs, - fetch_g1, -}; +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()) + 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, @@ -53,13 +57,13 @@ impl BabyJubjubSumContext { } pub fn babyjubjub_sum_push(&mut self, v: u64) { - if self.input_cursor < LIMBNB*2 { + if self.input_cursor < LIMBNB * 2 { self.limbs.push(v); self.input_cursor += 1; - } else if self.input_cursor < LIMBNB*2 + 4 { + } else if self.input_cursor < LIMBNB * 2 + 4 { self.coeffs.push(v); self.input_cursor += 1; - if self.input_cursor == LIMBNB*2 + 4 { + if self.input_cursor == LIMBNB * 2 + 4 { self.input_cursor = 0; } } @@ -69,17 +73,21 @@ impl BabyJubjubSumContext { let limbs = self.result_limbs.clone(); match limbs { None => { - assert!(self.limbs.len() == LIMBNB*2); + 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(); + 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; @@ -93,7 +101,7 @@ impl BabyJubjubSumContext { 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); + self.result_limbs = Some(limbs); } } @@ -101,9 +109,10 @@ 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())); + let foreign_babyjubjubsum_plugin = env.external_env.register_plugin( + "foreign_babyjubjubsum", + Box::new(BabyJubjubSumContext::default()), + ); env.external_env.register_function( "babyjubjub_sum_new", @@ -142,8 +151,7 @@ pub fn register_babyjubjubsum_foreign(env: &mut HostEnv) { |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 + 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 index 5acd05f01..69e00f636 100644 --- a/crates/host/src/host/ecc_helper/mod.rs +++ b/crates/host/src/host/ecc_helper/mod.rs @@ -1,10 +1,10 @@ -pub mod bn254; pub mod bls381; +pub mod bn254; pub mod jubjub; pub mod test; -use num_bigint::BigUint; use halo2_proofs::arithmetic::BaseExt; +use num_bigint::BigUint; pub fn bn_to_field(bn: &BigUint) -> F { let mut bytes = bn.to_bytes_le(); @@ -18,5 +18,3 @@ pub fn field_to_bn(f: &F) -> BigUint { 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 index 062f4cd18..a8aa7bdd5 100644 --- a/crates/host/src/host/ecc_helper/test.rs +++ b/crates/host/src/host/ecc_helper/test.rs @@ -1,33 +1,37 @@ #[cfg(test)] pub(crate) mod tests { - use halo2_proofs::arithmetic::CurveAffine; - use halo2_proofs::pairing::bn256::{G1Affine, G2Affine, Fq2, pairing}; 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() { + 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", @@ -38,7 +42,7 @@ pub(crate) mod tests { "16021838921913636763711766864306630139800454605152352295402262906962367559814", ]); - let z:G1Affine = (x + y).into(); + let z: G1Affine = (x + y).into(); println!("msm {:?}", z); let a = get_g1(vec![ @@ -50,13 +54,12 @@ pub(crate) mod tests { "47825847124631411811576281994805528104052872047575749583058110663112377001", "8744222678452503383790834725135834161307861625945158048012780534319795560143", "9233346029650632520218739027049068980416615687382718198119931453101152827975", - "10471280343341576477249226516274439500456322467064958156008066650244635888622" + "10471280343341576477249226516274439500456322467064958156008066650244635888622", ]); let pair_ab = pairing(&a, &b); println!("\npair ab {:?}", pair_ab); - let c = get_g1(vec![ "5031514285120295997737123508423040879712685050138383293760355384665904754488", "6823067879265550319809102199938618241998853703030415114792371967260649452853", @@ -66,37 +69,40 @@ pub(crate) mod tests { "16757480011835372184764354633328853212064194417052169636997013717174005603641", "12432097195700978348921464455579756029074596339242363943410459715706216986941", ]); - + let beta = get_g2(vec![ "17975028126161125746872310568788265990276646416597355097039940884195819358739", "17401920800019416240372951523628528842571722962428319020407322407751134153696", "373336161763481738310767706475057352757645836211335436601460549560077507883", - "12596258404235599838080822038113194794755190435330940888082608644071169093526" + "12596258404235599838080822038113194794755190435330940888082608644071169093526", ]); let pair_alphabeta = pairing(&alpha, &beta); - + let gamma = get_g2(vec![ "10857046999023057135944570762232829481370756359578518086990519993285655852781", "11559732032986387107991004021392285783925812861821192530917403151452391805634", "8495653923123431417604973247489272438418190587263600148770280649306958101930", - "4082367875863433681332203403145435568316851327593401208105741076214120093531" + "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); - + println!("pair gamma + ab {:?}", pair_ab + pair_gamma); + let delta = get_g2(vec![ "3257864888291421116173460527534170713717410433509021668023378246238733003616", "19501533296056540312008038527562968311092778436941336050675464372460956461923", "6694920137971073977116331836462792254111247710837228432923435849982682441494", - "17519709022773002523554480652241560921521540950810125413580329045084856923004" + "17519709022773002523554480652241560921521540950810125413580329045084856923004", ]); let pair_delta = pairing(&c, &delta); - println!("\npair gamma + ab + delta {:?}", pair_ab + pair_gamma + pair_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 index 6105ffad8..dbfe2a9d7 100644 --- a/crates/host/src/host/hash_helper/mod.rs +++ b/crates/host/src/host/hash_helper/mod.rs @@ -1,2 +1,2 @@ -pub mod sha256; 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 index 77836f5d6..d924f7414 100644 --- a/crates/host/src/host/hash_helper/poseidon.rs +++ b/crates/host/src/host/hash_helper/poseidon.rs @@ -1,20 +1,17 @@ -use std::rc::Rc; -use delphinus_zkwasm::runtime::host::{host_env::HostEnv, ForeignContext}; -use halo2_proofs::pairing::bn256::Fr; +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, ReduceRule -}; +use zkwasm_host_circuits::host::Reduce; +use zkwasm_host_circuits::host::ReduceRule; - -use zkwasm_host_circuits::host::ForeignInst::{ - PoseidonNew, - PoseidonPush, - PoseidonFinalize, -}; +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 /// @@ -53,24 +50,21 @@ impl Generator { } pub fn new_reduce(rules: Vec>) -> Reduce { - Reduce { - cursor: 0, - rules - } + Reduce { cursor: 0, rules } } pub struct PoseidonContext { pub hasher: Option>, pub generator: Generator, pub buf: Vec, - pub fieldreducer:Reduce, + pub fieldreducer: Reduce, } impl PoseidonContext { pub fn default() -> Self { PoseidonContext { hasher: None, - fieldreducer:new_reduce(vec![ReduceRule::Field(Fr::zero(), 64)]), + fieldreducer: new_reduce(vec![ReduceRule::Field(Fr::zero(), 64)]), buf: vec![], generator: Generator { cursor: 0, @@ -89,7 +83,8 @@ impl PoseidonContext { 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()) + self.buf + .push(self.fieldreducer.rules[0].field_value().unwrap()) } } @@ -100,8 +95,9 @@ impl PoseidonContext { 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())}) + self.generator.values = dwords + .chunks(8) + .map(|x| u64::from_le_bytes(x.to_vec().try_into().unwrap())) .collect::>(); }); } @@ -109,14 +105,13 @@ impl PoseidonContext { } } - 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())); + .external_env + .register_plugin("foreign_sh256", Box::new(PoseidonContext::default())); env.external_env.register_function( "poseidon_new", @@ -147,7 +142,6 @@ pub fn register_poseidon_foreign(env: &mut HostEnv) { ), ); - env.external_env.register_function( "poseidon_finalize", PoseidonFinalize as usize, diff --git a/crates/host/src/host/hash_helper/sha256.rs b/crates/host/src/host/hash_helper/sha256.rs index efe3f0f93..53fe49012 100644 --- a/crates/host/src/host/hash_helper/sha256.rs +++ b/crates/host/src/host/hash_helper/sha256.rs @@ -1,15 +1,13 @@ -use std::rc::Rc; -use delphinus_zkwasm::runtime::host::{host_env::HostEnv, ForeignContext}; +use delphinus_zkwasm::runtime::host::host_env::HostEnv; +use delphinus_zkwasm::runtime::host::ForeignContext; use sha2::Digest; -use zkwasm_host_circuits::host::ForeignInst::{ - SHA256New, - SHA256Push, - SHA256Finalize, -}; +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) @@ -49,7 +47,6 @@ impl Generator { } } - struct Sha256Context { pub hasher: Option, pub generator: Generator, @@ -69,14 +66,13 @@ impl Sha256Context { } } - 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())); + .external_env + .register_plugin("foreign_sh256", Box::new(Sha256Context::default())); env.external_env.register_function( "sha256_new", @@ -86,11 +82,10 @@ pub fn register_sha256_foreign(env: &mut HostEnv) { 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 - }); + 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; @@ -109,7 +104,7 @@ pub fn register_sha256_foreign(env: &mut HostEnv) { |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 { + let sz = if context.size > 8 { context.size -= 8; 8 } else { @@ -126,7 +121,6 @@ pub fn register_sha256_foreign(env: &mut HostEnv) { ), ); - env.external_env.register_function( "sha256_finalize", SHA256Finalize as usize, @@ -136,10 +130,11 @@ pub fn register_sha256_foreign(env: &mut HostEnv) { |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::>(); + 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/lib.rs b/crates/host/src/lib.rs index 5fefbbd7d..735f47f79 100644 --- a/crates/host/src/lib.rs +++ b/crates/host/src/lib.rs @@ -10,9 +10,9 @@ use delphinus_zkwasm::runtime::wasmi_interpreter::WasmRuntimeIO; use delphinus_zkwasm::runtime::host::host_env::HostEnv; use delphinus_zkwasm::runtime::host::HostEnvBuilder; -use zkwasm_host_circuits::host::db::TreeDB; use std::sync::Arc; use std::sync::Mutex; +use zkwasm_host_circuits::host::db::TreeDB; pub struct ExecutionArg { /// Public inputs for `wasm_input(1)` @@ -37,7 +37,7 @@ impl HostEnvBuilder for StandardHostEnvBuilder { 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![]))); + 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); diff --git a/crates/specs/src/brtable.rs b/crates/specs/src/brtable.rs index b1db371d9..4e6ce3c03 100644 --- a/crates/specs/src/brtable.rs +++ b/crates/specs/src/brtable.rs @@ -1,6 +1,7 @@ use std::collections::BTreeMap; -use serde::{Serialize, Deserialize}; +use serde::Deserialize; +use serde::Serialize; #[derive(Serialize, Deserialize, Debug, Clone)] pub struct BrTableEntry { diff --git a/crates/specs/src/configure_table.rs b/crates/specs/src/configure_table.rs index 6b5e69060..b2484fb18 100644 --- a/crates/specs/src/configure_table.rs +++ b/crates/specs/src/configure_table.rs @@ -1,4 +1,5 @@ -use serde::{Serialize, Deserialize}; +use serde::Deserialize; +use serde::Serialize; // A wasm page size is 64KB pub const WASM_BYTES_PER_PAGE: u64 = 64 * 1024 as u64; diff --git a/crates/specs/src/etable.rs b/crates/specs/src/etable.rs index 9f553d6b1..ed24a93e9 100644 --- a/crates/specs/src/etable.rs +++ b/crates/specs/src/etable.rs @@ -1,4 +1,5 @@ -use serde::{Serialize, Deserialize}; +use serde::Deserialize; +use serde::Serialize; use super::itable::InstructionTableEntry; use crate::host_function::HostPlugin; diff --git a/crates/specs/src/external_host_call_table/mod.rs b/crates/specs/src/external_host_call_table/mod.rs index c02765cd5..df425490a 100644 --- a/crates/specs/src/external_host_call_table/mod.rs +++ b/crates/specs/src/external_host_call_table/mod.rs @@ -1,5 +1,6 @@ use serde::ser::SerializeStruct; -use serde::{Deserialize, Serialize}; +use serde::Deserialize; +use serde::Serialize; use crate::host_function::Signature; use crate::types::ValueType; diff --git a/crates/specs/src/host_function.rs b/crates/specs/src/host_function.rs index a3ea3868d..a3b740589 100644 --- a/crates/specs/src/host_function.rs +++ b/crates/specs/src/host_function.rs @@ -1,4 +1,5 @@ -use serde::{Deserialize, Serialize}; +use serde::Deserialize; +use serde::Serialize; use crate::external_host_call_table::ExternalHostCallSignature; use crate::types::ValueType; diff --git a/crates/specs/src/imtable.rs b/crates/specs/src/imtable.rs index 5c86622f2..5050c2b77 100644 --- a/crates/specs/src/imtable.rs +++ b/crates/specs/src/imtable.rs @@ -2,7 +2,8 @@ use std::cmp::Ordering; use crate::mtable::LocationType; use crate::mtable::VarType; -use serde::{Serialize, Deserialize}; +use serde::Deserialize; +use serde::Serialize; #[derive(Serialize, Deserialize, Debug, Clone)] pub struct InitMemoryTableEntry { diff --git a/crates/specs/src/itable.rs b/crates/specs/src/itable.rs index 08afec668..14ae6e48f 100644 --- a/crates/specs/src/itable.rs +++ b/crates/specs/src/itable.rs @@ -16,7 +16,8 @@ use crate::mtable::MemoryReadSize; use crate::mtable::MemoryStoreSize; use crate::types::ValueType; use num_bigint::BigUint; -use serde::{Serialize, Deserialize}; +use serde::Deserialize; +use serde::Serialize; use std::collections::HashSet; use strum_macros::EnumIter; diff --git a/crates/specs/src/jtable.rs b/crates/specs/src/jtable.rs index bcfb16bce..c3f1a07ae 100644 --- a/crates/specs/src/jtable.rs +++ b/crates/specs/src/jtable.rs @@ -1,5 +1,6 @@ use super::itable::InstructionTableEntry; -use serde::{Serialize, Deserialize}; +use serde::Deserialize; +use serde::Serialize; #[derive(Default, Serialize, Deserialize, Debug, Clone)] pub struct StaticFrameEntry { diff --git a/crates/specs/src/lib.rs b/crates/specs/src/lib.rs index 104b341c5..27c72a207 100644 --- a/crates/specs/src/lib.rs +++ b/crates/specs/src/lib.rs @@ -14,7 +14,8 @@ use itable::InstructionTable; use jtable::JumpTable; use jtable::StaticFrameEntry; use mtable::MTable; -use serde::{Serialize, Deserialize}; +use serde::Deserialize; +use serde::Serialize; #[macro_use] extern crate lazy_static; diff --git a/crates/specs/src/mtable.rs b/crates/specs/src/mtable.rs index cfdfe7a9d..eaf84bf39 100644 --- a/crates/specs/src/mtable.rs +++ b/crates/specs/src/mtable.rs @@ -1,6 +1,7 @@ use std::collections::HashSet; -use serde::{Serialize, Deserialize}; +use serde::Deserialize; +use serde::Serialize; use strum_macros::EnumIter; use crate::imtable::InitMemoryTable; @@ -25,7 +26,9 @@ impl AccessType { } } -#[derive(Clone, Copy, Debug, PartialEq, Eq, EnumIter, Serialize, Deserialize, 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, Deserialize, 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, Deserialize, Hash, Eq, PartialOrd, Ord)] +#[derive( + Clone, Copy, Debug, PartialEq, EnumIter, Serialize, Deserialize, Hash, Eq, PartialOrd, Ord, +)] pub enum MemoryStoreSize { Byte8 = 1, Byte16, diff --git a/crates/specs/src/step.rs b/crates/specs/src/step.rs index 733d40090..4b4889a8f 100644 --- a/crates/specs/src/step.rs +++ b/crates/specs/src/step.rs @@ -10,7 +10,8 @@ use crate::mtable::MemoryReadSize; use crate::mtable::MemoryStoreSize; use crate::mtable::VarType; use crate::types::ValueType; -use serde::{Deserialize, Serialize}; +use serde::Deserialize; +use serde::Serialize; #[derive(Debug, Clone, Serialize, Deserialize)] pub enum StepInfo { diff --git a/crates/specs/src/types.rs b/crates/specs/src/types.rs index 93c4a73be..f7d3427c8 100644 --- a/crates/specs/src/types.rs +++ b/crates/specs/src/types.rs @@ -1,4 +1,5 @@ -use serde::{Deserialize, Serialize}; +use serde::Deserialize; +use serde::Serialize; use crate::external_host_call_table::ExternalHostCallSignature; use crate::host_function::HostPlugin; diff --git a/crates/zkwasm/src/loader/mod.rs b/crates/zkwasm/src/loader/mod.rs index f3a0bea0e..35b5ce38a 100644 --- a/crates/zkwasm/src/loader/mod.rs +++ b/crates/zkwasm/src/loader/mod.rs @@ -1,4 +1,3 @@ -use std::marker::PhantomData; use anyhow::Result; use halo2_proofs::arithmetic::MultiMillerLoop; use halo2_proofs::dev::MockProver; @@ -9,6 +8,7 @@ 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; @@ -43,19 +43,6 @@ 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, } @@ -67,7 +54,6 @@ pub struct ZkWasmLoader, _data_builder: PhantomData, _data_e: PhantomData, - } impl> ZkWasmLoader { @@ -129,11 +115,7 @@ impl> ZkWasmLoader()) } - pub fn new( - k: u32, - image: Vec, - phantom_functions: Vec, - ) -> Result { + pub fn new(k: u32, image: Vec, phantom_functions: Vec) -> Result { set_zkwasm_k(k); let module = wasmi::Module::from_buffer(&image)?; @@ -196,7 +178,10 @@ impl> ZkWasmLoader Result<(TestCircuit, Vec, Vec)> { + pub fn circuit_with_witness( + &self, + arg: T, + ) -> Result<(TestCircuit, Vec, Vec)> { let execution_result = self.run(arg, true)?; let instance: Vec = execution_result .public_inputs_and_outputs diff --git a/crates/zkwasm/src/runtime/host/default_env.rs b/crates/zkwasm/src/runtime/host/default_env.rs index 57bc97dc1..8a4b125cc 100644 --- a/crates/zkwasm/src/runtime/host/default_env.rs +++ b/crates/zkwasm/src/runtime/host/default_env.rs @@ -1,5 +1,5 @@ -use std::sync::Mutex; use std::sync::Arc; +use std::sync::Mutex; use crate::foreign::context::runtime::register_context_foreign; use crate::foreign::log_helper::register_log_foreign; diff --git a/crates/zkwasm/src/test/test_rlp.rs b/crates/zkwasm/src/test/test_rlp.rs index bb1f88c70..5fca37380 100644 --- a/crates/zkwasm/src/test/test_rlp.rs +++ b/crates/zkwasm/src/test/test_rlp.rs @@ -154,7 +154,8 @@ fn build_circuit() -> Result<( 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 { public_inputs, From 90d704c42236adfc3023d6c2e0a13cbe96d0618c Mon Sep 17 00:00:00 2001 From: Sinka Date: Mon, 23 Oct 2023 22:08:33 +0800 Subject: [PATCH 33/35] fix: abstraction of exec_dry_run_service --- Cargo.lock | 1 + crates/cli/src/app_builder.rs | 7 +- crates/cli/src/args.rs | 56 +--------------- crates/cli/src/exec.rs | 65 ++++++------------- crates/cli/src/main.rs | 2 +- crates/host/src/host/hash_helper/sha256.rs | 2 +- crates/specs/Cargo.toml | 1 + crates/specs/src/args.rs | 51 +++++++++++++++ crates/specs/src/lib.rs | 1 + crates/zkwasm/src/runtime/host/default_env.rs | 22 +++++++ crates/zkwasm/src/runtime/host/mod.rs | 19 +++++- 11 files changed, 122 insertions(+), 105 deletions(-) create mode 100644 crates/specs/src/args.rs diff --git a/Cargo.lock b/Cargo.lock index fb7109fd3..3319b08c8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2421,6 +2421,7 @@ name = "specs" version = "0.1.0" dependencies = [ "halo2_proofs", + "hex", "lazy_static", "num-bigint", "parity-wasm", diff --git a/crates/cli/src/app_builder.rs b/crates/cli/src/app_builder.rs index 078cb1b6b..9687e7515 100644 --- a/crates/cli/src/app_builder.rs +++ b/crates/cli/src/app_builder.rs @@ -133,7 +133,12 @@ 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); diff --git a/crates/cli/src/args.rs b/crates/cli/src/args.rs index ba65aba75..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> { diff --git a/crates/cli/src/exec.rs b/crates/cli/src/exec.rs index 2c13b8374..8a34fcba7 100644 --- a/crates/cli/src/exec.rs +++ b/crates/cli/src/exec.rs @@ -1,14 +1,13 @@ use crate::app_builder::write_context_output; -use crate::args::parse_args; 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::ZkWasmLoader; -use delphinus_zkwasm::runtime::host::default_env::DefaultHostEnvBuilder; -use delphinus_zkwasm::runtime::host::default_env::ExecutionArg; +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::poly::commitment::ParamsVerifier; @@ -21,14 +20,10 @@ 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; pub fn exec_setup( @@ -114,26 +109,22 @@ where 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); @@ -158,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( - 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 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(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(); 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/host/src/host/hash_helper/sha256.rs b/crates/host/src/host/hash_helper/sha256.rs index 53fe49012..4fe54d886 100644 --- a/crates/host/src/host/hash_helper/sha256.rs +++ b/crates/host/src/host/hash_helper/sha256.rs @@ -85,7 +85,7 @@ pub fn register_sha256_foreign(env: &mut HostEnv) { let hasher = context .hasher .as_mut() - .map_or({ Some(Sha256::new()) }, |_| None); + .map_or(Some(Sha256::new()), |_| None); hasher.map(|s| { context.hasher = Some(s); context.size = args.nth::(0) as usize; 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/lib.rs b/crates/specs/src/lib.rs index 27c72a207..3add81166 100644 --- a/crates/specs/src/lib.rs +++ b/crates/specs/src/lib.rs @@ -20,6 +20,7 @@ use serde::Serialize; #[macro_use] extern crate lazy_static; +pub mod args; pub mod brtable; pub mod configure_table; pub mod encode; diff --git a/crates/zkwasm/src/runtime/host/default_env.rs b/crates/zkwasm/src/runtime/host/default_env.rs index 8a4b125cc..29b5b22c0 100644 --- a/crates/zkwasm/src/runtime/host/default_env.rs +++ b/crates/zkwasm/src/runtime/host/default_env.rs @@ -6,6 +6,7 @@ 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; @@ -21,6 +22,27 @@ pub struct ExecutionArg { 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 { diff --git a/crates/zkwasm/src/runtime/host/mod.rs b/crates/zkwasm/src/runtime/host/mod.rs index 3f6402018..32ac94d1b 100644 --- a/crates/zkwasm/src/runtime/host/mod.rs +++ b/crates/zkwasm/src/runtime/host/mod.rs @@ -1,16 +1,31 @@ +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; -use self::host_env::HostEnv; +pub trait ContextOutput { + fn get_context_outputs(&self) -> Arc>>; +} -use super::wasmi_interpreter::WasmRuntimeIO; +#[derive(Serialize, Deserialize, Debug, Clone)] +pub struct Sequence { + private_inputs: Vec, + public_inputs: Vec, + context_input: Vec, + pub context_output: Option, +} pub mod default_env; pub mod external_circuit_plugin; From ebc6d3d363a2ddce0a02d9fe92a6e76a2b49d73a Mon Sep 17 00:00:00 2001 From: Zhang Junyu Date: Tue, 24 Oct 2023 14:07:05 +0800 Subject: [PATCH 34/35] fix compiling error --- crates/cli/src/app_builder.rs | 1 + crates/host/src/host/keccak_helper/mod.rs | 1 - crates/host/src/host/keccak_helper/test.rs | 50 - crates/host/src/host/mod.rs | 1 - crates/playground/Cargo.lock | 1244 ++++++++++++++++++- crates/playground/examples/binary_search.rs | 2 +- crates/playground/examples/context.rs | 4 +- crates/playground/examples/fibonacci.rs | 2 +- crates/playground/examples/phantom.rs | 5 +- crates/zkwasm/src/test/test_rlp.rs | 3 +- crates/zkwasm/wasm/keccak.wasm | Bin 2810 -> 0 bytes 11 files changed, 1246 insertions(+), 67 deletions(-) delete mode 100644 crates/host/src/host/keccak_helper/mod.rs delete mode 100644 crates/host/src/host/keccak_helper/test.rs delete mode 100755 crates/zkwasm/wasm/keccak.wasm diff --git a/crates/cli/src/app_builder.rs b/crates/cli/src/app_builder.rs index 9687e7515..e1d45a6c2 100644 --- a/crates/cli/src/app_builder.rs +++ b/crates/cli/src/app_builder.rs @@ -99,6 +99,7 @@ pub trait AppBuilder: CommandBuilder { 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::( diff --git a/crates/host/src/host/keccak_helper/mod.rs b/crates/host/src/host/keccak_helper/mod.rs deleted file mode 100644 index 7b788c207..000000000 --- a/crates/host/src/host/keccak_helper/mod.rs +++ /dev/null @@ -1 +0,0 @@ -pub mod test; diff --git a/crates/host/src/host/keccak_helper/test.rs b/crates/host/src/host/keccak_helper/test.rs deleted file mode 100644 index 24ffedbc5..000000000 --- a/crates/host/src/host/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/host/src/host/mod.rs b/crates/host/src/host/mod.rs index 82824587c..9b9534c06 100644 --- a/crates/host/src/host/mod.rs +++ b/crates/host/src/host/mod.rs @@ -1,4 +1,3 @@ pub mod ecc_helper; pub mod hash_helper; -pub mod keccak_helper; pub mod merkle_helper; 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 59848da50..ceb628073 100644 --- a/crates/playground/examples/binary_search.rs +++ b/crates/playground/examples/binary_search.rs @@ -12,7 +12,7 @@ fn main() -> Result<()> { 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 89742c9bc..69d7ed0b5 100644 --- a/crates/playground/examples/context.rs +++ b/crates/playground/examples/context.rs @@ -21,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 { @@ -31,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 6b3357176..f46e2adab 100644 --- a/crates/playground/examples/fibonacci.rs +++ b/crates/playground/examples/fibonacci.rs @@ -12,7 +12,7 @@ fn main() -> Result<()> { 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 ef0e1309b..a8f62be0c 100644 --- a/crates/playground/examples/phantom.rs +++ b/crates/playground/examples/phantom.rs @@ -13,11 +13,10 @@ fn main() -> Result<()> { let loader = ZkWasmLoader::::new( 18, wasm, - vec!["search"].into_iter().map(|s| s.to_owned()).collect(), - None, + 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/zkwasm/src/test/test_rlp.rs b/crates/zkwasm/src/test/test_rlp.rs index 5fca37380..75d0e8d66 100644 --- a/crates/zkwasm/src/test/test_rlp.rs +++ b/crates/zkwasm/src/test/test_rlp.rs @@ -154,8 +154,7 @@ fn build_circuit() -> Result<( 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 { public_inputs, diff --git a/crates/zkwasm/wasm/keccak.wasm b/crates/zkwasm/wasm/keccak.wasm deleted file mode 100755 index 473dccc38069afb1cf73449c7261afd3c98a59a3..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2810 zcmd5;&u<(x6t>5+vokw8*-4tD`LPMl&ZgP4O^Y}%6#^8GL|Qm;=b0dw3l+@Ms9HAf&{nTs1OJK2>uNuzUSG5e}PTBpZ)yo_v?F3#GOY6QV1az!d*F* zC%eITEOw)@|H$#K5W$R8dk;SCdUqXveUaf^y}&Tkiwr_9aol=YZBvhOM^lb6M_p(7 zrL1X@mK-fOy69-$nH6VNY1ZkNXoWXBlsZZr#g5v}5cVl>T2qT6N1-F-ur`KO`?!xf zt}JS^M#Pd?nsao)(Tt;MXF50!>*brZ8I)u9HLXHg2DMptNT{I>jyRLUk8-m%hE{NY zxlx--UU|(S4ShIK-l)w65h5siwHZ!sy5P!AZ8jYexk))Kx^hsP%YJhOu9nNSx#Ex< zqMj?G+FXV8IR}eo%PZxGy_~7dyhAlt5LOx2<{Atpu3W6mb+2^QA@?iPa^-A|MD&rH zvR|9jZxRw(zEPW=0})c{dEqKzFSly5>QML|txjw$xKh<-&Y{q7!wXj&3Oa|Rb7oS9 z%H^mFYN5+181v#j%23YLrtiQX*!Mz0Im;_GY6HIXk$Aq~rShs*o1FVkhZ;&nGr7cjX$@s0@q4i9ME?;4aGRK7wRemO*u!RRfT_seU}Y=GJ8Wc>1y zGwY!AJYDn4>tF^bJ)}*)yzI;n9KJ+remQVv4XnLRSN(F!nE_}k?095ECeR?XR)E;R zi-kG{3<~uwV6jj`z*2$0Buy9S5a6&thX5}W>OH`0pjioZm=)+XpefWY zpjW6HfV@!XG+HUpwZMLXt_5xs>Mo#DsBJ)6DD)Hs1^ORI1^OQt7V06ORj6Bl)k0C4 zeizH`cum;9p*~KFowYK^6ns=INKbclLu@#K=hdyL=}TI3n%h zP3Q=nbX&-YePt(uUHiAVnYC;HX_$JgA0p^u3Og~vZBq;%N>K>DG9Ov-s-MN9Mi$%Ik%?gouB8-#+ldX2K+1>| zDi|M_?t#gy98veaNo;RqA0FJRlaR1y;RDL>F$SWYuGb~wklQ60fo7E}8y41OwNd^v8d7_WrE zUp4^C!~f)YQxbrL(~%7jrq2%yOml`ndA{DnFceXWJRkWx&hAF}yz2=PWfB4)!opv0eV z8xW9JJnc;Mao(?=vJkSmYEVrum|z2<>P#k+^VONXYNB`MN8H?7EsEyDada_W!Qgp- sF@^ELWF7)@j29RRBgUA)cn0OOy;-aYn=M9+d5rBy2>gm|j0KE;0bPo<)c^nh From a4076c5b034132ca0da9adae2f8e3662aada59ec Mon Sep 17 00:00:00 2001 From: Sinka Date: Wed, 8 Nov 2023 17:53:22 +0800 Subject: [PATCH 35/35] update README --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index fa370fe84..ac5538aea 100644 --- a/README.md +++ b/README.md @@ -49,6 +49,8 @@ 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.