diff --git a/Cargo.lock b/Cargo.lock index 96d8e88..078dd80 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -63,9 +63,9 @@ dependencies = [ [[package]] name = "aho-corasick" -version = "1.1.3" +version = "1.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" +checksum = "ddd31a130427c27518df266943a5308ed92d4b226cc639f5a8f1002816174301" dependencies = [ "memchr", ] @@ -78,9 +78,9 @@ checksum = "683d7910e743518b0e34f1186f92494becacb047c7b6bf616c96772180fef923" [[package]] name = "alloy-consensus" -version = "1.0.38" +version = "1.0.41" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a0dd3ed764953a6b20458b2b7abbfdc93d20d14b38babe1a70fe631a443a9f1" +checksum = "b9b151e38e42f1586a01369ec52a6934702731d07e8509a7307331b09f6c46dc" dependencies = [ "alloy-eips", "alloy-primitives", @@ -104,9 +104,9 @@ dependencies = [ [[package]] name = "alloy-consensus-any" -version = "1.0.38" +version = "1.0.41" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9556182afa73cddffa91e64a5aa9508d5e8c912b3a15f26998d2388a824d2c7b" +checksum = "6e2d5e8668ef6215efdb7dcca6f22277b4e483a5650e05f5de22b2350971f4b8" dependencies = [ "alloy-consensus", "alloy-eips", @@ -154,9 +154,9 @@ dependencies = [ [[package]] name = "alloy-eips" -version = "1.0.38" +version = "1.0.41" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "305fa99b538ca7006b0c03cfed24ec6d82beda67aac857ef4714be24231d15e6" +checksum = "e5434834adaf64fa20a6fb90877bc1d33214c41b055cc49f82189c98614368cc" dependencies = [ "alloy-eip2124", "alloy-eip2930", @@ -176,9 +176,9 @@ dependencies = [ [[package]] name = "alloy-json-abi" -version = "1.4.0" +version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2acb6637a9c0e1cdf8971e0ced8f3fa34c04c5e9dccf6bb184f6a64fe0e37d8" +checksum = "5513d5e6bd1cba6bdcf5373470f559f320c05c8c59493b6e98912fbe6733943f" dependencies = [ "alloy-primitives", "alloy-sol-type-parser", @@ -188,9 +188,9 @@ dependencies = [ [[package]] name = "alloy-json-rpc" -version = "1.0.38" +version = "1.0.41" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d91676d242c0ced99c0dd6d0096d7337babe9457cc43407d26aa6367fcf90553" +checksum = "d7c69f6c9c68a1287c9d5ff903d0010726934de0dac10989be37b75a29190d55" dependencies = [ "alloy-primitives", "alloy-sol-types", @@ -203,9 +203,9 @@ dependencies = [ [[package]] name = "alloy-network" -version = "1.0.38" +version = "1.0.41" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77f82150116b30ba92f588b87f08fa97a46a1bd5ffc0d0597efdf0843d36bfda" +checksum = "8eaf2ae05219e73e0979cb2cf55612aafbab191d130f203079805eaf881cca58" dependencies = [ "alloy-consensus", "alloy-consensus-any", @@ -229,9 +229,9 @@ dependencies = [ [[package]] name = "alloy-network-primitives" -version = "1.0.38" +version = "1.0.41" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "223612259a080160ce839a4e5df0125ca403a1d5e7206cc911cea54af5d769aa" +checksum = "e58f4f345cef483eab7374f2b6056973c7419ffe8ad35e994b7a7f5d8e0c7ba4" dependencies = [ "alloy-consensus", "alloy-eips", @@ -242,9 +242,9 @@ dependencies = [ [[package]] name = "alloy-primitives" -version = "1.4.0" +version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b77f7d5e60ad8ae6bd2200b8097919712a07a6db622a4b201e7ead6166f02e5" +checksum = "355bf68a433e0fd7f7d33d5a9fc2583fde70bf5c530f63b80845f8da5505cf28" dependencies = [ "alloy-rlp", "bytes", @@ -253,7 +253,7 @@ dependencies = [ "derive_more 2.0.1", "foldhash 0.2.0", "hashbrown 0.16.0", - "indexmap 2.11.4", + "indexmap 2.12.0", "itoa", "k256", "keccak-asm", @@ -286,14 +286,14 @@ checksum = "64b728d511962dda67c1bc7ea7c03736ec275ed2cf4c35d9585298ac9ccf3b73" dependencies = [ "proc-macro2", "quote", - "syn 2.0.106", + "syn 2.0.108", ] [[package]] name = "alloy-rpc-types-any" -version = "1.0.38" +version = "1.0.41" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23cc57ee0c1ac9fb14854195fc249494da7416591dc4a4d981ddfd5dd93b9bce" +checksum = "fbde0801a32d21c5f111f037bee7e22874836fba7add34ed4a6919932dd7cf23" dependencies = [ "alloy-consensus-any", "alloy-rpc-types-eth", @@ -302,9 +302,9 @@ dependencies = [ [[package]] name = "alloy-rpc-types-eth" -version = "1.0.38" +version = "1.0.41" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d7d47bca1a2a1541e4404aa38b7e262bb4dffd9ac23b4f178729a4ddc5a5caa" +checksum = "361cd87ead4ba7659bda8127902eda92d17fa7ceb18aba1676f7be10f7222487" dependencies = [ "alloy-consensus", "alloy-consensus-any", @@ -323,9 +323,9 @@ dependencies = [ [[package]] name = "alloy-serde" -version = "1.0.38" +version = "1.0.41" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a8468f1a7f9ee3bae73c24eead0239abea720dbf7779384b9c7e20d51bfb6b0" +checksum = "64600fc6c312b7e0ba76f73a381059af044f4f21f43e07f51f1fa76c868fe302" dependencies = [ "alloy-primitives", "serde", @@ -334,9 +334,9 @@ dependencies = [ [[package]] name = "alloy-signer" -version = "1.0.38" +version = "1.0.41" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "33387c90b0a5021f45a5a77c2ce6c49b8f6980e66a318181468fb24cea771670" +checksum = "5772858492b26f780468ae693405f895d6a27dea6e3eab2c36b6217de47c2647" dependencies = [ "alloy-primitives", "async-trait", @@ -349,9 +349,9 @@ dependencies = [ [[package]] name = "alloy-signer-local" -version = "1.0.38" +version = "1.0.41" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b55d9e795c85e36dcea08786d2e7ae9b73cb554b6bea6ac4c212def24e1b4d03" +checksum = "f4195b803d0a992d8dbaab2ca1986fc86533d4bc80967c0cce7668b26ad99ef9" dependencies = [ "alloy-consensus", "alloy-network", @@ -365,41 +365,41 @@ dependencies = [ [[package]] name = "alloy-sol-macro" -version = "1.4.0" +version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78c84c3637bee9b5c4a4d2b93360ee16553d299c3b932712353caf1cea76d0e6" +checksum = "f3ce480400051b5217f19d6e9a82d9010cdde20f1ae9c00d53591e4a1afbb312" dependencies = [ "alloy-sol-macro-expander", "alloy-sol-macro-input", "proc-macro-error2", "proc-macro2", "quote", - "syn 2.0.106", + "syn 2.0.108", ] [[package]] name = "alloy-sol-macro-expander" -version = "1.4.0" +version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a882aa4e1790063362434b9b40d358942b188477ac1c44cfb8a52816ffc0cc17" +checksum = "6d792e205ed3b72f795a8044c52877d2e6b6e9b1d13f431478121d8d4eaa9028" dependencies = [ "alloy-sol-macro-input", "const-hex", "heck 0.5.0", - "indexmap 2.11.4", + "indexmap 2.12.0", "proc-macro-error2", "proc-macro2", "quote", - "syn 2.0.106", + "syn 2.0.108", "syn-solidity", "tiny-keccak", ] [[package]] name = "alloy-sol-macro-input" -version = "1.4.0" +version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "18e5772107f9bb265d8d8c86e0733937bb20d0857ea5425b1b6ddf51a9804042" +checksum = "0bd1247a8f90b465ef3f1207627547ec16940c35597875cdc09c49d58b19693c" dependencies = [ "const-hex", "dunce", @@ -407,15 +407,15 @@ dependencies = [ "macro-string", "proc-macro2", "quote", - "syn 2.0.106", + "syn 2.0.108", "syn-solidity", ] [[package]] name = "alloy-sol-type-parser" -version = "1.4.0" +version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e188b939aa4793edfaaa099cb1be4e620036a775b4bdf24fdc56f1cd6fd45890" +checksum = "954d1b2533b9b2c7959652df3076954ecb1122a28cc740aa84e7b0a49f6ac0a9" dependencies = [ "serde", "winnow 0.7.13", @@ -423,9 +423,9 @@ dependencies = [ [[package]] name = "alloy-sol-types" -version = "1.4.0" +version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3c8a9a909872097caffc05df134e5ef2253a1cdb56d3a9cf0052a042ac763f9" +checksum = "70319350969a3af119da6fb3e9bddb1bce66c9ea933600cb297c8b1850ad2a3c" dependencies = [ "alloy-json-abi", "alloy-primitives", @@ -451,15 +451,15 @@ dependencies = [ [[package]] name = "alloy-tx-macros" -version = "1.0.38" +version = "1.0.41" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7bf39928a5e70c9755d6811a2928131b53ba785ad37c8bf85c90175b5d43b818" +checksum = "f8e52276fdb553d3c11563afad2898f4085165e4093604afe3d78b69afbf408f" dependencies = [ "alloy-primitives", "darling", "proc-macro2", "quote", - "syn 2.0.106", + "syn 2.0.108", ] [[package]] @@ -578,7 +578,7 @@ checksum = "e7e89fe77d1f0f4fe5b96dfc940923d88d17b6a773808124f21e764dfb063c6a" dependencies = [ "proc-macro2", "quote", - "syn 2.0.106", + "syn 2.0.108", ] [[package]] @@ -689,7 +689,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "62945a2f7e6de02a31fe400aa489f0e0f5b2502e69f95f853adb82a96c7a6b60" dependencies = [ "quote", - "syn 2.0.106", + "syn 2.0.108", ] [[package]] @@ -727,7 +727,7 @@ dependencies = [ "num-traits", "proc-macro2", "quote", - "syn 2.0.106", + "syn 2.0.108", ] [[package]] @@ -817,7 +817,7 @@ checksum = "213888f660fddcca0d257e88e54ac05bca01885f258ccdf695bafd77031bb69d" dependencies = [ "proc-macro2", "quote", - "syn 2.0.106", + "syn 2.0.108", ] [[package]] @@ -907,7 +907,7 @@ checksum = "c7c24de15d275a1ecfd47a380fb4d5ec9bfe0933f309ed5e705b775596a3574d" dependencies = [ "proc-macro2", "quote", - "syn 2.0.106", + "syn 2.0.108", ] [[package]] @@ -918,7 +918,7 @@ checksum = "9035ad2d096bed7955a320ee7e2230574d28fd3c3a0f186cbea1ff3c7eed5dbb" dependencies = [ "proc-macro2", "quote", - "syn 2.0.106", + "syn 2.0.108", ] [[package]] @@ -946,7 +946,7 @@ checksum = "ffdcb70bdbc4d478427380519163274ac86e52916e10f0a8889adf0f96d3fee7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.106", + "syn 2.0.108", ] [[package]] @@ -1135,7 +1135,7 @@ dependencies = [ "regex", "rustc-hash 1.1.0", "shlex", - "syn 2.0.106", + "syn 2.0.108", "which", ] @@ -1145,7 +1145,7 @@ version = "0.70.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f49d8fed880d473ea71efb9bf597651e77201bdd4893efe54c9e5d65ae04ce6f" dependencies = [ - "bitflags 2.9.4", + "bitflags 2.10.0", "cexpr", "clang-sys", "itertools 0.13.0", @@ -1156,7 +1156,7 @@ dependencies = [ "regex", "rustc-hash 1.1.0", "shlex", - "syn 2.0.106", + "syn 2.0.108", ] [[package]] @@ -1213,9 +1213,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "bitflags" -version = "2.9.4" +version = "2.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2261d10cca569e4643e526d8dc2e62e433cc8aba21ab764233731f8d369bf394" +checksum = "812e12b5285cc515a9c72a5c1d3b6d46a19dac5acfef5265968c166106e31dd3" [[package]] name = "bitvec" @@ -1268,7 +1268,16 @@ version = "0.10.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" dependencies = [ - "generic-array 0.14.8", + "generic-array 0.14.9", +] + +[[package]] +name = "block2" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cdeb9d870516001442e364c5220d3574d2da8dc765554b4a617230d33fa58ef5" +dependencies = [ + "objc2", ] [[package]] @@ -1414,11 +1423,30 @@ dependencies = [ "thiserror 1.0.69", ] +[[package]] +name = "cbindgen" +version = "0.27.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fce8dd7fcfcbf3a0a87d8f515194b49d6135acab73e18bd380d1d93bb1a15eb" +dependencies = [ + "clap", + "heck 0.4.1", + "indexmap 2.12.0", + "log", + "proc-macro2", + "quote", + "serde", + "serde_json", + "syn 2.0.108", + "tempfile", + "toml", +] + [[package]] name = "cc" -version = "1.2.41" +version = "1.2.43" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac9fe6cdbb24b6ade63616c0a0688e45bb56732262c158df3c0c4bea4ca47cb7" +checksum = "739eb0f94557554b3ca9a86d2d37bebd49c5e6d0c1d2bda35ba5bdac830befc2" dependencies = [ "find-msvc-tools", "jobserver", @@ -1437,9 +1465,15 @@ dependencies = [ [[package]] name = "cfg-if" -version = "1.0.3" +version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2fd1289c04a9ea8cb22300a459a72a385d7c73d3259e2ed7dcb2af674838cfa9" +checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" + +[[package]] +name = "cfg_aliases" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724" [[package]] name = "chrono" @@ -1476,9 +1510,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.5.48" +version = "4.5.50" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2134bb3ea021b78629caa971416385309e0131b351b25e01dc16fb54e1b5fae" +checksum = "0c2cfd7bf8a6017ddaa4e32ffe7403d547790db06bd171c1c53926faab501623" dependencies = [ "clap_builder", "clap_derive", @@ -1486,9 +1520,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.5.48" +version = "4.5.50" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2ba64afa3c0a6df7fa517765e31314e983f51dda798ffba27b988194fb65dc9" +checksum = "0a4c05b9e80c5ccd3a7ef080ad7b6ba7d6fc00a985b8b157197075677c82c7a0" dependencies = [ "anstream", "anstyle", @@ -1498,21 +1532,21 @@ dependencies = [ [[package]] name = "clap_derive" -version = "4.5.47" +version = "4.5.49" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbfd7eae0b0f1a6e63d4b13c9c478de77c2eb546fba158ad50b4203dc24b9f9c" +checksum = "2a0b5487afeab2deb2ff4e03a807ad1a03ac532ff5a2cee5d86884440c7f7671" dependencies = [ "heck 0.5.0", "proc-macro2", "quote", - "syn 2.0.106", + "syn 2.0.108", ] [[package]] name = "clap_lex" -version = "0.7.5" +version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b94f61472cee1439c0b966b47e3aca9ae07e45d070759512cd390ea2bebc6675" +checksum = "a1d728cc89cf3aee9ff92b05e62b19ee65a02b5702cff7d5a377e32c6ae29d8d" [[package]] name = "coins-bip32" @@ -1556,7 +1590,7 @@ dependencies = [ "bech32", "bs58", "digest 0.10.7", - "generic-array 0.14.8", + "generic-array 0.14.9", "hex", "ripemd", "serde", @@ -1603,9 +1637,9 @@ checksum = "0b396d1f76d455557e1218ec8066ae14bba60b4b36ecd55577ba979f5db7ecaa" [[package]] name = "const-hex" -version = "1.16.0" +version = "1.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6407bff74dea37e0fa3dc1c1c974e5d46405f0c987bf9997a0762adce71eda6" +checksum = "3bb320cac8a0750d7f25280aa97b09c26edfe161164238ecbbb31092b079e735" dependencies = [ "cfg-if", "cpufeatures", @@ -1752,7 +1786,7 @@ version = "0.5.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0dc92fb57ca44df6db8059111ab3af99a63d5d0f8375d9972e319a379c6bab76" dependencies = [ - "generic-array 0.14.8", + "generic-array 0.14.9", "rand_core 0.6.4", "subtle", "zeroize", @@ -1764,7 +1798,7 @@ version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" dependencies = [ - "generic-array 0.14.8", + "generic-array 0.14.9", "typenum", ] @@ -1777,6 +1811,17 @@ dependencies = [ "cipher", ] +[[package]] +name = "ctrlc" +version = "3.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73736a89c4aff73035ba2ed2e565061954da00d4970fc9ac25dcc85a2a20d790" +dependencies = [ + "dispatch2", + "nix", + "windows-sys 0.61.2", +] + [[package]] name = "curve25519-dalek" version = "4.1.3" @@ -1790,7 +1835,7 @@ dependencies = [ "rustc_version 0.4.1", "subtle", "zeroize", - "zkm-lib", + "zkm-lib 1.2.1", ] [[package]] @@ -1800,7 +1845,7 @@ source = "git+https://github.com/ziren-patches/curve25519-dalek?branch=patch-4.1 dependencies = [ "proc-macro2", "quote", - "syn 2.0.106", + "syn 2.0.108", ] [[package]] @@ -1825,7 +1870,7 @@ dependencies = [ "quote", "serde", "strsim", - "syn 2.0.106", + "syn 2.0.108", ] [[package]] @@ -1836,7 +1881,7 @@ checksum = "d38308df82d1080de0afee5d069fa14b0326a88c14f15c5ccda35b4a6c414c81" dependencies = [ "darling_core", "quote", - "syn 2.0.106", + "syn 2.0.108", ] [[package]] @@ -1936,9 +1981,9 @@ dependencies = [ [[package]] name = "deranged" -version = "0.5.4" +version = "0.5.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a41953f86f8a05768a6cda24def994fd2f424b04ec5c719cf89989779f199071" +checksum = "ececcb659e7ba858fb4f10388c250a7252eb0a27373f1a72b8748afdd248e587" dependencies = [ "powerfmt", "serde_core", @@ -1981,7 +2026,7 @@ checksum = "cb7330aeadfbe296029522e6c40f315320aba36fc43a5b3632f3795348f3bd22" dependencies = [ "proc-macro2", "quote", - "syn 2.0.106", + "syn 2.0.108", ] [[package]] @@ -1992,7 +2037,7 @@ checksum = "bda628edc44c4bb645fbe0f758797143e4e07926f7ebf4e9bdfbd3d2ce621df3" dependencies = [ "proc-macro2", "quote", - "syn 2.0.106", + "syn 2.0.108", "unicode-xid", ] @@ -2002,7 +2047,7 @@ version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066" dependencies = [ - "generic-array 0.14.8", + "generic-array 0.14.9", ] [[package]] @@ -2059,6 +2104,18 @@ dependencies = [ "winapi", ] +[[package]] +name = "dispatch2" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "89a09f22a6c6069a18470eb92d2298acf25463f14256d24778e1230d789a2aec" +dependencies = [ + "bitflags 2.10.0", + "block2", + "libc", + "objc2", +] + [[package]] name = "displaydoc" version = "0.2.5" @@ -2067,7 +2124,7 @@ checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.106", + "syn 2.0.108", ] [[package]] @@ -2111,7 +2168,7 @@ dependencies = [ "enum-ordinalize", "proc-macro2", "quote", - "syn 2.0.106", + "syn 2.0.108", ] [[package]] @@ -2139,7 +2196,7 @@ dependencies = [ "crypto-bigint", "digest 0.10.7", "ff 0.13.1", - "generic-array 0.14.8", + "generic-array 0.14.9", "group 0.13.0", "hkdf", "pem-rfc7468", @@ -2214,7 +2271,7 @@ dependencies = [ "heck 0.5.0", "proc-macro2", "quote", - "syn 2.0.106", + "syn 2.0.108", ] [[package]] @@ -2235,34 +2292,34 @@ checksum = "f282cfdfe92516eb26c2af8589c274c7c17681f5ecc03c18255fe741c6aa64eb" dependencies = [ "proc-macro2", "quote", - "syn 2.0.106", + "syn 2.0.108", ] [[package]] name = "enum-ordinalize" -version = "4.3.0" +version = "4.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fea0dcfa4e54eeb516fe454635a95753ddd39acda650ce703031c6973e315dd5" +checksum = "4a1091a7bb1f8f2c4b28f1fe2cef4980ca2d410a3d727d67ecc3178c9b0800f0" dependencies = [ "enum-ordinalize-derive", ] [[package]] name = "enum-ordinalize-derive" -version = "4.3.1" +version = "4.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0d28318a75d4aead5c4db25382e8ef717932d0346600cacae6357eb5941bc5ff" +checksum = "8ca9601fb2d62598ee17836250842873a413586e5d7ed88b356e38ddbb0ec631" dependencies = [ "proc-macro2", "quote", - "syn 2.0.106", + "syn 2.0.108", ] [[package]] name = "env_filter" -version = "0.1.3" +version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "186e05a59d4c50738528153b83b0b0194d3a29507dfec16eccd4b342903397d0" +checksum = "1bf3c259d255ca70051b30e2e95b5446cdb8949ac4cd22c0d7fd634d89f568e2" dependencies = [ "log", "regex", @@ -2433,7 +2490,7 @@ dependencies = [ "reqwest 0.11.27", "serde", "serde_json", - "syn 2.0.106", + "syn 2.0.108", "toml", "walkdir", ] @@ -2451,7 +2508,7 @@ dependencies = [ "proc-macro2", "quote", "serde_json", - "syn 2.0.106", + "syn 2.0.108", ] [[package]] @@ -2467,9 +2524,9 @@ dependencies = [ "const-hex", "elliptic-curve", "ethabi", - "generic-array 0.14.8", + "generic-array 0.14.9", "k256", - "num_enum 0.7.4", + "num_enum 0.7.5", "once_cell", "open-fastrlp", "rand 0.8.5", @@ -2477,7 +2534,7 @@ dependencies = [ "serde", "serde_json", "strum", - "syn 2.0.106", + "syn 2.0.108", "tempfile", "thiserror 1.0.69", "tiny-keccak", @@ -2722,11 +2779,17 @@ version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0ce7134b9999ecaf8bcd65542e436736ef32ddca1b3e06094cb6ec5755203b80" +[[package]] +name = "fixedbitset" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d674e81391d1e1ab681a28d99df07927c6d4aa5b027d7da16ba32d1d21ecd99" + [[package]] name = "flate2" -version = "1.1.4" +version = "1.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc5a4e564e38c699f2880d3fda590bedc2e69f3f84cd48b457bd892ce61d0aa9" +checksum = "bfe33edd8e85a12a67454e37f8c75e730830d83e313556ab9ebf9ee7fbeb3bfb" dependencies = [ "crc32fast", "miniz_oxide", @@ -2841,7 +2904,7 @@ checksum = "162ee34ebcb7c64a8abebc059ce0fee27c2262618d7b60ed8faf72fef13c3650" dependencies = [ "proc-macro2", "quote", - "syn 2.0.106", + "syn 2.0.108", ] [[package]] @@ -2938,9 +3001,9 @@ checksum = "1d758ba1b47b00caf47f24925c0074ecb20d6dfcffe7f6d53395c0465674841a" [[package]] name = "generic-array" -version = "0.14.8" +version = "0.14.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1dc8f7d2ded5f9209535e4b3fd4d39c002f30902ff5ce9f64e2c33d549576500" +checksum = "4bb6743198531e02858aeaea5398fcc883e71851fcbcb5a2f773e2fb6cb1edf2" dependencies = [ "typenum", "version_check", @@ -2949,9 +3012,9 @@ dependencies = [ [[package]] name = "generic-array" -version = "1.3.3" +version = "1.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c42bb3faf529935fbba0684910e1a71ecd271d618549d58f430b878619b7f4cf" +checksum = "eaf57c49a95fd1fe24b90b3033bee6dc7e8f1288d51494cb44e627c295e38542" dependencies = [ "rustversion", "serde_core", @@ -2966,19 +3029,19 @@ checksum = "335ff9f135e4384c8150d6f27c6daed433577f86b4750418338c01a1a2528592" dependencies = [ "cfg-if", "libc", - "wasi 0.11.1+wasi-snapshot-preview1", + "wasi", ] [[package]] name = "getrandom" -version = "0.3.3" +version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26145e563e54f2cadc477553f1ec5ee650b00862f0a58bcd12cbdc5f0ea2d2f4" +checksum = "899def5c37c4fd7b2664648c28120ecec138e4d395b459e5ca34f9cce2dd77fd" dependencies = [ "cfg-if", "libc", "r-efi", - "wasi 0.14.7+wasi-0.2.4", + "wasip2", ] [[package]] @@ -2993,7 +3056,7 @@ version = "0.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b903b73e45dc0c6c596f2d37eccece7c1c8bb6e4407b001096387c63d0d93724" dependencies = [ - "bitflags 2.9.4", + "bitflags 2.10.0", "libc", "libgit2-sys", "log", @@ -3053,7 +3116,7 @@ dependencies = [ "futures-sink", "futures-util", "http 0.2.12", - "indexmap 2.11.4", + "indexmap 2.12.0", "slab", "tokio", "tokio-util", @@ -3275,11 +3338,11 @@ dependencies = [ [[package]] name = "home" -version = "0.5.11" +version = "0.5.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "589533453244b0995c858700322199b2becb13b627df2851f64a2775d024abcf" +checksum = "cc627f471c528ff0c4a49e1d5e60450c8f6461dd6d10ba9dcd3a61d3dff7728d" dependencies = [ - "windows-sys 0.59.0", + "windows-sys 0.61.2", ] [[package]] @@ -3472,9 +3535,9 @@ dependencies = [ [[package]] name = "icu_collections" -version = "2.0.0" +version = "2.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "200072f5d0e3614556f94a9930d5dc3e0662a652823904c3a75dc3b0af7fee47" +checksum = "4c6b649701667bbe825c3b7e6388cb521c23d88644678e83c0c4d0a621a34b43" dependencies = [ "displaydoc", "potential_utf", @@ -3485,9 +3548,9 @@ dependencies = [ [[package]] name = "icu_locale_core" -version = "2.0.0" +version = "2.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0cde2700ccaed3872079a65fb1a78f6c0a36c91570f28755dda67bc8f7d9f00a" +checksum = "edba7861004dd3714265b4db54a3c390e880ab658fec5f7db895fae2046b5bb6" dependencies = [ "displaydoc", "litemap", @@ -3498,11 +3561,10 @@ dependencies = [ [[package]] name = "icu_normalizer" -version = "2.0.0" +version = "2.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "436880e8e18df4d7bbc06d58432329d6458cc84531f7ac5f024e93deadb37979" +checksum = "5f6c8828b67bf8908d82127b2054ea1b4427ff0230ee9141c54251934ab1b599" dependencies = [ - "displaydoc", "icu_collections", "icu_normalizer_data", "icu_properties", @@ -3513,42 +3575,38 @@ dependencies = [ [[package]] name = "icu_normalizer_data" -version = "2.0.0" +version = "2.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00210d6893afc98edb752b664b8890f0ef174c8adbb8d0be9710fa66fbbf72d3" +checksum = "7aedcccd01fc5fe81e6b489c15b247b8b0690feb23304303a9e560f37efc560a" [[package]] name = "icu_properties" -version = "2.0.1" +version = "2.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "016c619c1eeb94efb86809b015c58f479963de65bdb6253345c1a1276f22e32b" +checksum = "e93fcd3157766c0c8da2f8cff6ce651a31f0810eaa1c51ec363ef790bbb5fb99" dependencies = [ - "displaydoc", "icu_collections", "icu_locale_core", "icu_properties_data", "icu_provider", - "potential_utf", "zerotrie", "zerovec", ] [[package]] name = "icu_properties_data" -version = "2.0.1" +version = "2.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "298459143998310acd25ffe6810ed544932242d3f07083eee1084d83a71bd632" +checksum = "02845b3647bb045f1100ecd6480ff52f34c35f82d9880e029d329c21d1054899" [[package]] name = "icu_provider" -version = "2.0.0" +version = "2.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "03c80da27b5f4187909049ee2d72f276f0d9f99a42c306bd0131ecfe04d8e5af" +checksum = "85962cf0ce02e1e0a629cc34e7ca3e373ce20dda4c4d7294bbd0bf1fdb59e614" dependencies = [ "displaydoc", "icu_locale_core", - "stable_deref_trait", - "tinystr", "writeable", "yoke", "zerofrom", @@ -3618,7 +3676,7 @@ checksum = "a0eb5a3343abf848c0984fe4604b2b105da9539376e24fc0a3b0007411ae4fd9" dependencies = [ "proc-macro2", "quote", - "syn 2.0.106", + "syn 2.0.108", ] [[package]] @@ -3640,9 +3698,9 @@ dependencies = [ [[package]] name = "indexmap" -version = "2.11.4" +version = "2.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4b0f83760fb341a774ed326568e19f5a863af4a952def8c39f9ab92fd95b88e5" +checksum = "6717a8d2a5a929a1a2eb43a12812498ed141a0bcfb7e8f7844fbdbe4303bba9f" dependencies = [ "equivalent", "hashbrown 0.16.0", @@ -3669,7 +3727,7 @@ version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "879f10e63c20629ecabbb64a8010319738c66a5cd0c29b02d63d272b03751d01" dependencies = [ - "generic-array 0.14.8", + "generic-array 0.14.9", ] [[package]] @@ -3681,17 +3739,6 @@ dependencies = [ "cfg-if", ] -[[package]] -name = "io-uring" -version = "0.7.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "046fa2d4d00aea763528b4950358d0ead425372445dc8ff86312b3c69ff7727b" -dependencies = [ - "bitflags 2.9.4", - "cfg-if", - "libc", -] - [[package]] name = "ipconfig" version = "0.3.2" @@ -3722,9 +3769,9 @@ dependencies = [ [[package]] name = "is_terminal_polyfill" -version = "1.70.1" +version = "1.70.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf" +checksum = "a6cb138bb79a146c1bd460005623e142ef0181e3d0219cb493e02f7d08a35695" [[package]] name = "itertools" @@ -3789,7 +3836,7 @@ checksum = "03343451ff899767262ec32146f6d559dd759fdadf42ff0e227c7c48f72594b4" dependencies = [ "proc-macro2", "quote", - "syn 2.0.106", + "syn 2.0.108", ] [[package]] @@ -3798,15 +3845,15 @@ version = "0.1.34" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9afb3de4395d6b3e67a780b6de64b51c978ecf11cb9a462c66be7d4ca9039d33" dependencies = [ - "getrandom 0.3.3", + "getrandom 0.3.4", "libc", ] [[package]] name = "js-sys" -version = "0.3.81" +version = "0.3.82" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec48937a97411dcb524a265206ccd4c90bb711fca92b2792c407f268825b9305" +checksum = "b011eec8cc36da2aab2d5cff675ec18454fad408585853910a202391cf9f8e65" dependencies = [ "once_cell", "wasm-bindgen", @@ -3853,7 +3900,7 @@ dependencies = [ "serdect", "sha2", "signature", - "zkm-lib", + "zkm-lib 1.2.1", ] [[package]] @@ -3886,7 +3933,7 @@ dependencies = [ "ena", "itertools 0.11.0", "lalrpop-util", - "petgraph", + "petgraph 0.6.5", "regex", "regex-syntax", "string_cache", @@ -3960,7 +4007,7 @@ version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "416f7e718bdb06000964960ffa43b4335ad4012ae8b99060261aa4a8088d5ccb" dependencies = [ - "bitflags 2.9.4", + "bitflags 2.10.0", "libc", ] @@ -4002,9 +4049,9 @@ checksum = "df1d3c3b53da64cf5760482273a98e575c651a67eec7f77df96b5b642de8f039" [[package]] name = "litemap" -version = "0.8.0" +version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "241eaef5fd12c88705a01fc1066c48c4b36e0dd4377dcdc7ec3942cea7a69956" +checksum = "6373607a59f0be73a39b6fe456b8192fcc3585f602af20751600e974dd455e77" [[package]] name = "lock_api" @@ -4047,7 +4094,7 @@ checksum = "1b27834086c65ec3f9387b096d66e99f221cf081c2b738042aa252bcd41204e3" dependencies = [ "proc-macro2", "quote", - "syn 2.0.106", + "syn 2.0.108", ] [[package]] @@ -4123,13 +4170,13 @@ dependencies = [ [[package]] name = "mio" -version = "1.0.4" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78bed444cc8a2160f01cbcf811ef18cac863ad68ae8ca62092e8db51d51c761c" +checksum = "69d83b0086dc8ecf3ce9ae2874b2d1290252e2a30720bea58a5c6639b0092873" dependencies = [ "libc", - "wasi 0.11.1+wasi-snapshot-preview1", - "windows-sys 0.59.0", + "wasi", + "windows-sys 0.61.2", ] [[package]] @@ -4138,12 +4185,30 @@ version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e5ce46fe64a9d73be07dcbe690a38ce1b293be448fd8ce1e6c1b8062c9f72c6a" +[[package]] +name = "multimap" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d87ecb2933e8aeadb3e3a02b828fed80a7528047e68b4f424523a0981a3a084" + [[package]] name = "new_debug_unreachable" version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "650eef8c711430f1a879fdd01d4745a7deea475becfb90269c06775983bbf086" +[[package]] +name = "nix" +version = "0.30.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "74523f3a35e05aba87a1d978330aef40f67b0304ac79c1c00b294c9830543db6" +dependencies = [ + "bitflags 2.10.0", + "cfg-if", + "cfg_aliases", + "libc", +] + [[package]] name = "nohash-hasher" version = "0.2.0" @@ -4306,11 +4371,11 @@ dependencies = [ [[package]] name = "num_enum" -version = "0.7.4" +version = "0.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a973b4e44ce6cad84ce69d797acf9a044532e4184c4f267913d1b546a0727b7a" +checksum = "b1207a7e20ad57b847bbddc6776b968420d38292bbfe2089accff5e19e82454c" dependencies = [ - "num_enum_derive 0.7.4", + "num_enum_derive 0.7.5", "rustversion", ] @@ -4328,14 +4393,14 @@ dependencies = [ [[package]] name = "num_enum_derive" -version = "0.7.4" +version = "0.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77e878c846a8abae00dd069496dbe8751b16ac1c3d6bd2a7283a938e8228f90d" +checksum = "ff32365de1b6743cb203b710788263c44a03de03802daf96092f2da4fe6ba4d7" dependencies = [ "proc-macro-crate 3.4.0", "proc-macro2", "quote", - "syn 2.0.106", + "syn 2.0.108", ] [[package]] @@ -4379,6 +4444,21 @@ dependencies = [ "smallvec", ] +[[package]] +name = "objc2" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b7c2599ce0ec54857b29ce62166b0ed9b4f6f1a70ccc9a71165b6154caca8c05" +dependencies = [ + "objc2-encode", +] + +[[package]] +name = "objc2-encode" +version = "4.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef25abbcd74fb2609453eb695bd2f860d389e457f67dc17cafc8b8cbc89d0c33" + [[package]] name = "object" version = "0.37.3" @@ -4396,9 +4476,9 @@ checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d" [[package]] name = "once_cell_polyfill" -version = "1.70.1" +version = "1.70.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4895175b425cb1f87721b59f0f286c2092bd4af812243672510e1ac53e2e0ad" +checksum = "384b8ab6d37215f3c5301a95a4accb5d64aa607f1fcb26a11b5303878451b4fe" [[package]] name = "open-fastrlp" @@ -4447,7 +4527,7 @@ dependencies = [ "hex", "primeorder", "sha2", - "zkm-lib", + "zkm-lib 1.2.1", ] [[package]] @@ -4806,7 +4886,7 @@ dependencies = [ "proc-macro-crate 3.4.0", "proc-macro2", "quote", - "syn 2.0.106", + "syn 2.0.108", ] [[package]] @@ -4887,6 +4967,12 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1e91099d4268b0e11973f036e885d652fb0b21fedcf69738c627f94db6a44f42" +[[package]] +name = "pathdiff" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df94ce210e5bc13cb6651479fa48d14f601d9858cfe0467f43ae157023b938d3" + [[package]] name = "pbkdf2" version = "0.11.0" @@ -4955,8 +5041,18 @@ version = "0.6.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b4c5cc86750666a3ed20bdaf5ca2a0344f9c67674cae0515bec2da16fbaa47db" dependencies = [ - "fixedbitset", - "indexmap 2.11.4", + "fixedbitset 0.4.2", + "indexmap 2.12.0", +] + +[[package]] +name = "petgraph" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3672b37090dbd86368a4145bc067582552b29c27377cad4e0a306c97f9bd7772" +dependencies = [ + "fixedbitset 0.5.7", + "indexmap 2.12.0", ] [[package]] @@ -4999,7 +5095,7 @@ dependencies = [ "phf_shared", "proc-macro2", "quote", - "syn 2.0.106", + "syn 2.0.108", ] [[package]] @@ -5028,7 +5124,7 @@ checksum = "6e918e4ff8c4549eb882f14b3a4bc8c8bc93de829416eacf579f1207a8fbf861" dependencies = [ "proc-macro2", "quote", - "syn 2.0.106", + "syn 2.0.108", ] [[package]] @@ -5083,14 +5179,14 @@ dependencies = [ "p3-field", "p3-koala-bear", "p3-symmetric", - "zkm-primitives", + "zkm-primitives 1.2.1", ] [[package]] name = "potential_utf" -version = "0.1.3" +version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84df19adbe5b5a0782edcab45899906947ab039ccf4573713735ee7de1e6b08a" +checksum = "b73949432f5e2a09657003c25bca5e19a0e9c84f8058ca374f49e0ebe605af77" dependencies = [ "zerovec", ] @@ -5133,7 +5229,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "479ca8adacdd7ce8f1fb39ce9ecccbfe93a3f1344b3d0d97f20bc0196208f62b" dependencies = [ "proc-macro2", - "syn 2.0.106", + "syn 2.0.108", ] [[package]] @@ -5196,28 +5292,27 @@ dependencies = [ "proc-macro-error-attr2", "proc-macro2", "quote", - "syn 2.0.106", + "syn 2.0.108", ] [[package]] name = "proc-macro2" -version = "1.0.101" +version = "1.0.103" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89ae43fd86e4158d6db51ad8e2b80f313af9cc74f5c0e03ccb87de09998732de" +checksum = "5ee95bc4ef87b8d5ba32e8b7714ccc834865276eab0aed5c9958d00ec45f49e8" dependencies = [ "unicode-ident", ] [[package]] name = "proptest" -version = "1.8.0" +version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2bb0be07becd10686a0bb407298fb425360a5c44a663774406340c59a22de4ce" +checksum = "bee689443a2bd0a16ab0348b52ee43e3b2d1b1f931c8aa5c9f8de4c86fbe8c40" dependencies = [ "bit-set 0.8.0", "bit-vec 0.8.0", - "bitflags 2.9.4", - "lazy_static", + "bitflags 2.10.0", "num-traits", "rand 0.9.2", "rand_chacha 0.9.0", @@ -5259,17 +5354,37 @@ dependencies = [ "itertools 0.10.5", "lazy_static", "log", - "multimap", - "petgraph", + "multimap 0.8.3", + "petgraph 0.6.5", "prettyplease 0.1.25", "prost 0.11.9", - "prost-types", + "prost-types 0.11.9", "regex", "syn 1.0.109", "tempfile", "which", ] +[[package]] +name = "prost-build" +version = "0.13.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "be769465445e8c1474e9c5dac2018218498557af32d9ed057325ec9a41ae81bf" +dependencies = [ + "heck 0.5.0", + "itertools 0.14.0", + "log", + "multimap 0.10.1", + "once_cell", + "petgraph 0.7.1", + "prettyplease 0.2.37", + "prost 0.13.5", + "prost-types 0.13.5", + "regex", + "syn 2.0.108", + "tempfile", +] + [[package]] name = "prost-derive" version = "0.11.9" @@ -5293,7 +5408,7 @@ dependencies = [ "itertools 0.14.0", "proc-macro2", "quote", - "syn 2.0.106", + "syn 2.0.108", ] [[package]] @@ -5305,6 +5420,15 @@ dependencies = [ "prost 0.11.9", ] +[[package]] +name = "prost-types" +version = "0.13.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "52c2c1bf36ddb1a1c396b3601a3cec27c2462e45f07c386894ec3ccf5332bd16" +dependencies = [ + "prost 0.13.5", +] + [[package]] name = "quick-error" version = "1.2.3" @@ -5390,7 +5514,7 @@ version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "99d9a13982dcf210057a8a78572b2217b667c3beacbf3a0d8b454f6f82837d38" dependencies = [ - "getrandom 0.3.3", + "getrandom 0.3.4", "serde", ] @@ -5438,7 +5562,7 @@ version = "0.5.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ed2bf2547551a7053d6fdfafda3f938979645c44812fbfcda098faae3f1a362d" dependencies = [ - "bitflags 2.9.4", + "bitflags 2.10.0", ] [[package]] @@ -5469,14 +5593,14 @@ checksum = "b7186006dcb21920990093f30e3dea63b7d6e977bf1256be20c3563a5db070da" dependencies = [ "proc-macro2", "quote", - "syn 2.0.106", + "syn 2.0.108", ] [[package]] name = "regex" -version = "1.12.1" +version = "1.12.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4a52d8d02cacdb176ef4678de6c052efb4b3da14b78e4db683a4252762be5433" +checksum = "843bc0191f75f3e22651ae5f1e72939ab2f72a4bc30fa80a066bd66edefc24d4" dependencies = [ "aho-corasick", "memchr", @@ -5486,9 +5610,9 @@ dependencies = [ [[package]] name = "regex-automata" -version = "0.4.12" +version = "0.4.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "722166aa0d7438abbaa4d5cc2c649dac844e8c56d82fb3d33e9c34b5cd268fc6" +checksum = "5276caf25ac86c8d810222b3dbb938e512c55c6831a10f3e6ed1c93b84041f1c" dependencies = [ "aho-corasick", "memchr", @@ -5497,9 +5621,9 @@ dependencies = [ [[package]] name = "regex-syntax" -version = "0.8.7" +version = "0.8.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3160422bbd54dd5ecfdca71e5fd59b7b8fe2b1697ab2baf64f6d05dcc66d298" +checksum = "7a2d987857b319362043e95f5353c0535c1f58eec5336fdfcf626430af7def58" [[package]] name = "reqwest" @@ -5547,9 +5671,9 @@ dependencies = [ [[package]] name = "reqwest" -version = "0.12.23" +version = "0.12.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d429f34c8092b2d42c7c93cec323bb4adeb7c67698f70839adec842ec10c7ceb" +checksum = "9d0946410b9f7b082a427e4ef5c8ff541a88b357bc6c637c40db3a68ac70a36f" dependencies = [ "base64 0.22.1", "bytes", @@ -5757,7 +5881,7 @@ version = "0.38.44" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fdb5bc1ae2baa591800df16c9ca78619bf65c0488b41b96ccec5d11220d8c154" dependencies = [ - "bitflags 2.9.4", + "bitflags 2.10.0", "errno", "libc", "linux-raw-sys 0.4.15", @@ -5770,7 +5894,7 @@ version = "1.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cd15f8a2c5551a84d56efdc1cd049089e409ac19a3072d5037a17fd70719ff3e" dependencies = [ - "bitflags 2.9.4", + "bitflags 2.10.0", "errno", "libc", "linux-raw-sys 0.11.0", @@ -5895,7 +6019,7 @@ dependencies = [ "proc-macro-crate 3.4.0", "proc-macro2", "quote", - "syn 2.0.106", + "syn 2.0.108", ] [[package]] @@ -5982,7 +6106,7 @@ checksum = "d3e97a565f76233a6003f9f5c54be1d9c5bdfa3eccfb189469f11ec4901c47dc" dependencies = [ "base16ct", "der", - "generic-array 0.14.8", + "generic-array 0.14.9", "pkcs8", "serdect", "subtle", @@ -6016,7 +6140,7 @@ version = "2.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02" dependencies = [ - "bitflags 2.9.4", + "bitflags 2.10.0", "core-foundation", "core-foundation-sys", "libc", @@ -6109,7 +6233,7 @@ checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79" dependencies = [ "proc-macro2", "quote", - "syn 2.0.106", + "syn 2.0.108", ] [[package]] @@ -6159,15 +6283,15 @@ dependencies = [ [[package]] name = "serde_with" -version = "3.15.0" +version = "3.15.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6093cd8c01b25262b84927e0f7151692158fab02d961e04c979d3903eba7ecc5" +checksum = "aa66c845eee442168b2c8134fec70ac50dc20e760769c8ba0ad1319ca1959b04" dependencies = [ "base64 0.22.1", "chrono", "hex", "indexmap 1.9.3", - "indexmap 2.11.4", + "indexmap 2.12.0", "schemars 0.9.0", "schemars 1.0.4", "serde_core", @@ -6178,14 +6302,14 @@ dependencies = [ [[package]] name = "serde_with_macros" -version = "3.15.0" +version = "3.15.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a7e6c180db0816026a61afa1cff5344fb7ebded7e4d3062772179f2501481c27" +checksum = "b91a903660542fced4e99881aa481bdbaec1634568ee02e0b8bd57c64cb38955" dependencies = [ "darling", "proc-macro2", "quote", - "syn 2.0.106", + "syn 2.0.108", ] [[package]] @@ -6220,7 +6344,7 @@ checksum = "5d69265a08751de7844521fd15003ae0a888e035773ba05695c5c759a6f89eef" dependencies = [ "proc-macro2", "quote", - "syn 2.0.106", + "syn 2.0.108", ] [[package]] @@ -6464,7 +6588,7 @@ dependencies = [ "proc-macro2", "quote", "rustversion", - "syn 2.0.106", + "syn 2.0.108", ] [[package]] @@ -6519,9 +6643,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.106" +version = "2.0.108" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ede7c438028d4436d71104916910f5bb611972c5cfd7f89b8300a8186e6fada6" +checksum = "da58917d35242480a05c2897064da0a80589a2a0476c9a3f2fdc83b53502e917" dependencies = [ "proc-macro2", "quote", @@ -6530,14 +6654,14 @@ dependencies = [ [[package]] name = "syn-solidity" -version = "1.4.0" +version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2375c17f6067adc651d8c2c51658019cef32edfff4a982adaf1d7fd1c039f08b" +checksum = "ff790eb176cc81bb8936aed0f7b9f14fc4670069a2d371b3e3b0ecce908b2cb3" dependencies = [ "paste", "proc-macro2", "quote", - "syn 2.0.106", + "syn 2.0.108", ] [[package]] @@ -6563,7 +6687,7 @@ checksum = "728a70f3dbaf5bab7f0c4b1ac8d7ae5ea60a4b5549c8a5914361c99147a709d2" dependencies = [ "proc-macro2", "quote", - "syn 2.0.106", + "syn 2.0.108", ] [[package]] @@ -6615,7 +6739,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2d31c77bdf42a745371d260a26ca7163f1e0924b64afa0b688e61b5a9fa02f16" dependencies = [ "fastrand", - "getrandom 0.3.3", + "getrandom 0.3.4", "once_cell", "rustix 1.1.2", "windows-sys 0.61.2", @@ -6658,7 +6782,7 @@ checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1" dependencies = [ "proc-macro2", "quote", - "syn 2.0.106", + "syn 2.0.108", ] [[package]] @@ -6669,7 +6793,7 @@ checksum = "3ff15c8ecd7de3849db632e14d18d2571fa09dfc5ed93479bc4485c7a517c913" dependencies = [ "proc-macro2", "quote", - "syn 2.0.106", + "syn 2.0.108", ] [[package]] @@ -6734,9 +6858,9 @@ dependencies = [ [[package]] name = "tinystr" -version = "0.8.1" +version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d4f6d1145dcb577acf783d4e601bc1d76a13337bb54e6233add580b07344c8b" +checksum = "42d3e9c45c09de15d06dd8acf5f4e0e399e85927b7f00711024eb7ae10fa4869" dependencies = [ "displaydoc", "zerovec", @@ -6759,21 +6883,19 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "tokio" -version = "1.47.1" +version = "1.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89e49afdadebb872d3145a5638b59eb0691ea23e46ca484037cfab3b76b95038" +checksum = "ff360e02eab121e0bc37a2d3b4d4dc622e6eda3a8e5253d5435ecf5bd4c68408" dependencies = [ - "backtrace", "bytes", - "io-uring", "libc", "mio", + "parking_lot", "pin-project-lite", "signal-hook-registry", - "slab", "socket2 0.6.1", "tokio-macros", - "windows-sys 0.59.0", + "windows-sys 0.61.2", ] [[package]] @@ -6788,13 +6910,13 @@ dependencies = [ [[package]] name = "tokio-macros" -version = "2.5.0" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e06d43f1345a3bcd39f6a56dbb7dcab2ba47e68e8ac134855e7e2bdbaf8cab8" +checksum = "af407857209536a95c8e56f8231ef2c2e2aff839b22e07a1ffcbc617e9db9fa5" dependencies = [ "proc-macro2", "quote", - "syn 2.0.106", + "syn 2.0.108", ] [[package]] @@ -6893,7 +7015,7 @@ version = "0.19.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1b5bb770da30e5cbfde35a2d7b9b8a2c4b8ef89548a7a6aeab5c9a576e3e7421" dependencies = [ - "indexmap 2.11.4", + "indexmap 2.12.0", "toml_datetime 0.6.11", "winnow 0.5.40", ] @@ -6904,7 +7026,7 @@ version = "0.22.27" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "41fe8c660ae4257887cf66394862d21dbca4a6ddd26f04a3560410406a2f819a" dependencies = [ - "indexmap 2.11.4", + "indexmap 2.12.0", "serde", "serde_spanned", "toml_datetime 0.6.11", @@ -6918,7 +7040,7 @@ version = "0.23.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6485ef6d0d9b5d0ec17244ff7eb05310113c3f316f2d14200d4de56b3cb98f8d" dependencies = [ - "indexmap 2.11.4", + "indexmap 2.12.0", "toml_datetime 0.7.3", "toml_parser", "winnow 0.7.13", @@ -6982,7 +7104,7 @@ checksum = "5bf5e9b9c0f7e0a7c027dcfaba7b2c60816c7049171f679d99ee2ff65d0de8c4" dependencies = [ "prettyplease 0.1.25", "proc-macro2", - "prost-build", + "prost-build 0.11.9", "quote", "syn 1.0.109", ] @@ -7029,7 +7151,7 @@ version = "0.6.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "adc82fd73de2a9722ac5da747f12383d2bfdb93591ee6c58486e0097890f05f2" dependencies = [ - "bitflags 2.9.4", + "bitflags 2.10.0", "bytes", "futures-util", "http 1.3.1", @@ -7085,7 +7207,7 @@ checksum = "81383ab64e72a7a8b8e13130c49e3dab29def6d0c7d76a03087b3cf71c5c6903" dependencies = [ "proc-macro2", "quote", - "syn 2.0.106", + "syn 2.0.108", ] [[package]] @@ -7195,6 +7317,15 @@ dependencies = [ "utf-8", ] +[[package]] +name = "twirp-build-rs" +version = "0.13.0-succinct" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8160cc3d9282e192ec842f1ab44e9d396312ff5472bdab58f5e7f4d882b22eea" +dependencies = [ + "prost-build 0.13.5", +] + [[package]] name = "twirp-rs" version = "0.13.0-succinct" @@ -7208,7 +7339,7 @@ dependencies = [ "http-body-util", "hyper 1.7.0", "prost 0.13.5", - "reqwest 0.12.23", + "reqwest 0.12.24", "serde", "serde_json", "thiserror 1.0.69", @@ -7249,9 +7380,9 @@ checksum = "eaea85b334db583fe3274d12b4cd1880032beab409c0d774be044d4480ab9a94" [[package]] name = "unicode-ident" -version = "1.0.19" +version = "1.0.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f63a545481291138910575129486daeaf8ac54aee4387fe7906919f7830c7d9d" +checksum = "462eeb75aeb73aea900253ce739c8e18a67423fadf006037cd3ff27e82748a06" [[package]] name = "unicode-width" @@ -7339,7 +7470,7 @@ version = "1.18.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2f87b8aa10b915a06587d0dec516c282ff295b475d94abf425d62b57710070a2" dependencies = [ - "getrandom 0.3.3", + "getrandom 0.3.4", "js-sys", "rand 0.9.2", "uuid-macro-internal", @@ -7354,7 +7485,7 @@ checksum = "d9384a660318abfbd7f8932c34d67e4d1ec511095f95972ddc01e19d7ba8413f" dependencies = [ "proc-macro2", "quote", - "syn 2.0.106", + "syn 2.0.108", ] [[package]] @@ -7415,6 +7546,7 @@ dependencies = [ "ark-std 0.5.0", "bincode", "garbled-snark-verifier", + "indexmap 2.12.0", "num-bigint 0.4.6", "rand 0.8.5", "rand_chacha 0.3.1", @@ -7464,15 +7596,6 @@ version = "0.11.1+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b" -[[package]] -name = "wasi" -version = "0.14.7+wasi-0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "883478de20367e224c0090af9cf5f9fa85bed63a95c1abf3afc5c083ebc06e8c" -dependencies = [ - "wasip2", -] - [[package]] name = "wasip2" version = "1.0.1+wasi-0.2.4" @@ -7484,9 +7607,9 @@ dependencies = [ [[package]] name = "wasm-bindgen" -version = "0.2.104" +version = "0.2.105" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1da10c01ae9f1ae40cbfac0bac3b1e724b320abfcf52229f80b547c0d250e2d" +checksum = "da95793dfc411fbbd93f5be7715b0578ec61fe87cb1a42b12eb625caa5c5ea60" dependencies = [ "cfg-if", "once_cell", @@ -7495,25 +7618,11 @@ dependencies = [ "wasm-bindgen-shared", ] -[[package]] -name = "wasm-bindgen-backend" -version = "0.2.104" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "671c9a5a66f49d8a47345ab942e2cb93c7d1d0339065d4f8139c486121b43b19" -dependencies = [ - "bumpalo", - "log", - "proc-macro2", - "quote", - "syn 2.0.106", - "wasm-bindgen-shared", -] - [[package]] name = "wasm-bindgen-futures" -version = "0.4.54" +version = "0.4.55" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e038d41e478cc73bae0ff9b36c60cff1c98b8f38f8d7e8061e79ee63608ac5c" +checksum = "551f88106c6d5e7ccc7cd9a16f312dd3b5d36ea8b4954304657d5dfba115d4a0" dependencies = [ "cfg-if", "js-sys", @@ -7524,9 +7633,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.104" +version = "0.2.105" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ca60477e4c59f5f2986c50191cd972e3a50d8a95603bc9434501cf156a9a119" +checksum = "04264334509e04a7bf8690f2384ef5265f05143a4bff3889ab7a3269adab59c2" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -7534,22 +7643,22 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.104" +version = "0.2.105" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f07d2f20d4da7b26400c9f4a0511e6e0345b040694e8a75bd41d578fa4421d7" +checksum = "420bc339d9f322e562942d52e115d57e950d12d88983a14c79b86859ee6c7ebc" dependencies = [ + "bumpalo", "proc-macro2", "quote", - "syn 2.0.106", - "wasm-bindgen-backend", + "syn 2.0.108", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-shared" -version = "0.2.104" +version = "0.2.105" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bad67dc8b2a1a6e5448428adec4c3e84c43e561d8c9ee8a9e5aabeb193ec41d1" +checksum = "76f218a38c84bcb33c25ec7059b07847d465ce0e0a76b995e134a45adcb6af76" dependencies = [ "unicode-ident", ] @@ -7569,9 +7678,9 @@ dependencies = [ [[package]] name = "web-sys" -version = "0.3.81" +version = "0.3.82" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9367c417a924a74cae129e6a2ae3b47fabb1f8995595ab474029da749a8be120" +checksum = "3a1f95c0d03a47f4ae1f7a64643a6bb97465d9b740f0fa8f90ea33915c99a9a1" dependencies = [ "js-sys", "wasm-bindgen", @@ -7692,7 +7801,7 @@ checksum = "053e2e040ab57b9dc951b72c264860db7eb3b0200ba345b4e4c3b14f67855ddf" dependencies = [ "proc-macro2", "quote", - "syn 2.0.106", + "syn 2.0.108", ] [[package]] @@ -7703,7 +7812,7 @@ checksum = "3f316c4a2570ba26bbec722032c4099d8c8bc095efccdc15688708623367e358" dependencies = [ "proc-macro2", "quote", - "syn 2.0.106", + "syn 2.0.108", ] [[package]] @@ -7997,9 +8106,9 @@ checksum = "f17a85883d4e6d00e8a97c586de764dabcc06133f7f1d55dce5cdc070ad7fe59" [[package]] name = "writeable" -version = "0.6.1" +version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea2f10b9bb0928dfb1b42b65e1f9e36f7f54dbdf08457afefb38afcdec4fa2bb" +checksum = "9edde0db4769d2dc68579893f2306b26c6ecfbe0ef499b013d731b7b9247e0b9" [[package]] name = "ws_stream_wasm" @@ -8046,11 +8155,10 @@ checksum = "09041cd90cf85f7f8b2df60c646f853b7f535ce68f85244eb6731cf89fa498ec" [[package]] name = "yoke" -version = "0.8.0" +version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f41bb01b8226ef4bfd589436a297c53d118f65921786300e427be8d487695cc" +checksum = "72d6e5c6afb84d73944e5cedb052c4680d5657337201555f9f2a16b7406d4954" dependencies = [ - "serde", "stable_deref_trait", "yoke-derive", "zerofrom", @@ -8058,13 +8166,13 @@ dependencies = [ [[package]] name = "yoke-derive" -version = "0.8.0" +version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38da3c9736e16c5d3c8c597a9aaa5d1fa565d0532ae05e27c24aa62fb32c0ab6" +checksum = "b659052874eb698efe5b9e8cf382204678a0086ebf46982b79d6ca3182927e5d" dependencies = [ "proc-macro2", "quote", - "syn 2.0.106", + "syn 2.0.108", "synstructure", ] @@ -8085,7 +8193,7 @@ checksum = "88d2b8d9c68ad2b9e4340d7832716a4d21a22a1154777ad56ea55c51a9cf3831" dependencies = [ "proc-macro2", "quote", - "syn 2.0.106", + "syn 2.0.108", ] [[package]] @@ -8105,7 +8213,7 @@ checksum = "d71e5d6e06ab090c67b5e44993ec16b72dcbaabc526db883a360057678b48502" dependencies = [ "proc-macro2", "quote", - "syn 2.0.106", + "syn 2.0.108", "synstructure", ] @@ -8126,14 +8234,14 @@ checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" dependencies = [ "proc-macro2", "quote", - "syn 2.0.106", + "syn 2.0.108", ] [[package]] name = "zerotrie" -version = "0.2.2" +version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "36f0bbd478583f79edad978b407914f61b2972f5af6fa089686016be8f9af595" +checksum = "2a59c17a5562d507e4b54960e8569ebee33bee890c70aa3fe7b97e85a9fd7851" dependencies = [ "displaydoc", "yoke", @@ -8142,9 +8250,9 @@ dependencies = [ [[package]] name = "zerovec" -version = "0.11.4" +version = "0.11.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7aa2bd55086f1ab526693ecbe444205da57e25f4489879da80635a46d90e73b" +checksum = "6c28719294829477f525be0186d13efa9a3c602f7ec202ca9e353d310fb9a002" dependencies = [ "yoke", "zerofrom", @@ -8153,13 +8261,13 @@ dependencies = [ [[package]] name = "zerovec-derive" -version = "0.11.1" +version = "0.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b96237efa0c878c64bd89c436f661be4e46b2f3eff1ebb976f7ef2321d2f58f" +checksum = "eadce39539ca5cb3985590102671f2567e659fca9666581ad3411d59207951f3" dependencies = [ "proc-macro2", "quote", - "syn 2.0.106", + "syn 2.0.108", ] [[package]] @@ -8211,8 +8319,7 @@ dependencies = [ [[package]] name = "zkm-build" -version = "1.2.1" -source = "git+https://github.com/ProjectZKM/Ziren#23e217e88085fdd1dab18cd6bd07630bcfcaba23" +version = "1.2.2" dependencies = [ "anyhow", "cargo_metadata", @@ -8223,8 +8330,7 @@ dependencies = [ [[package]] name = "zkm-core-executor" -version = "1.2.1" -source = "git+https://github.com/ProjectZKM/Ziren#23e217e88085fdd1dab18cd6bd07630bcfcaba23" +version = "1.2.2" dependencies = [ "anyhow", "bincode", @@ -8258,19 +8364,21 @@ dependencies = [ "typenum", "vec_map", "zkm-curves", - "zkm-primitives", + "zkm-primitives 1.2.2", "zkm-stark", ] [[package]] name = "zkm-core-machine" -version = "1.2.1" -source = "git+https://github.com/ProjectZKM/Ziren#23e217e88085fdd1dab18cd6bd07630bcfcaba23" +version = "1.2.2" dependencies = [ "bincode", + "cbindgen", + "cc", "cfg-if", "elliptic-curve", - "generic-array 1.3.3", + "generic-array 1.3.5", + "glob", "hashbrown 0.14.5", "hex", "itertools 0.13.0", @@ -8289,6 +8397,7 @@ dependencies = [ "p3-poseidon2", "p3-uni-stark", "p3-util", + "pathdiff", "rand 0.8.5", "rayon", "rayon-scan", @@ -8310,20 +8419,36 @@ dependencies = [ "zkm-core-executor", "zkm-curves", "zkm-derive", - "zkm-primitives", + "zkm-primitives 1.2.2", "zkm-stark", ] +[[package]] +name = "zkm-cuda" +version = "1.2.2" +dependencies = [ + "bincode", + "ctrlc", + "prost 0.13.5", + "prost-build 0.13.5", + "serde", + "tokio", + "tracing", + "twirp-build-rs", + "twirp-rs", + "zkm-core-machine", + "zkm-prover", +] + [[package]] name = "zkm-curves" -version = "1.2.1" -source = "git+https://github.com/ProjectZKM/Ziren#23e217e88085fdd1dab18cd6bd07630bcfcaba23" +version = "1.2.2" dependencies = [ "cfg-if", "curve25519-dalek", "dashu", "elliptic-curve", - "generic-array 1.3.3", + "generic-array 1.3.5", "itertools 0.13.0", "k256", "num", @@ -8332,14 +8457,13 @@ dependencies = [ "serde", "snowbridge-amcl", "typenum", - "zkm-primitives", + "zkm-primitives 1.2.2", "zkm-stark", ] [[package]] name = "zkm-derive" -version = "1.2.1" -source = "git+https://github.com/ProjectZKM/Ziren#23e217e88085fdd1dab18cd6bd07630bcfcaba23" +version = "1.2.2" dependencies = [ "quote", "syn 1.0.109", @@ -8348,20 +8472,49 @@ dependencies = [ [[package]] name = "zkm-lib" version = "1.2.1" -source = "git+https://github.com/ProjectZKM/Ziren#23e217e88085fdd1dab18cd6bd07630bcfcaba23" +source = "git+https://github.com/ProjectZKM/Ziren#0792d9712f077df762400804cb87a6055766de3f" +dependencies = [ + "bincode", + "cfg-if", + "elliptic-curve", + "serde", + "sha2", + "zkm-primitives 1.2.1", +] + +[[package]] +name = "zkm-lib" +version = "1.2.2" dependencies = [ "bincode", "cfg-if", "elliptic-curve", "serde", "sha2", - "zkm-primitives", + "zkm-primitives 1.2.2", ] [[package]] name = "zkm-primitives" version = "1.2.1" -source = "git+https://github.com/ProjectZKM/Ziren#23e217e88085fdd1dab18cd6bd07630bcfcaba23" +source = "git+https://github.com/ProjectZKM/Ziren#0792d9712f077df762400804cb87a6055766de3f" +dependencies = [ + "bincode", + "hex", + "lazy_static", + "num-bigint 0.4.6", + "p3-field", + "p3-koala-bear", + "p3-monty-31", + "p3-poseidon2", + "p3-symmetric", + "serde", + "sha2", +] + +[[package]] +name = "zkm-primitives" +version = "1.2.2" dependencies = [ "bincode", "hex", @@ -8378,8 +8531,7 @@ dependencies = [ [[package]] name = "zkm-prover" -version = "1.2.1" -source = "git+https://github.com/ProjectZKM/Ziren#23e217e88085fdd1dab18cd6bd07630bcfcaba23" +version = "1.2.2" dependencies = [ "anyhow", "bincode", @@ -8407,7 +8559,7 @@ dependencies = [ "tracing-subscriber 0.3.20", "zkm-core-executor", "zkm-core-machine", - "zkm-primitives", + "zkm-primitives 1.2.2", "zkm-recursion-circuit", "zkm-recursion-compiler", "zkm-recursion-core", @@ -8417,8 +8569,7 @@ dependencies = [ [[package]] name = "zkm-recursion-circuit" -version = "1.2.1" -source = "git+https://github.com/ProjectZKM/Ziren#23e217e88085fdd1dab18cd6bd07630bcfcaba23" +version = "1.2.2" dependencies = [ "hashbrown 0.14.5", "itertools 0.13.0", @@ -8441,7 +8592,7 @@ dependencies = [ "zkm-core-executor", "zkm-core-machine", "zkm-derive", - "zkm-primitives", + "zkm-primitives 1.2.2", "zkm-recursion-compiler", "zkm-recursion-core", "zkm-recursion-gnark-ffi", @@ -8450,8 +8601,7 @@ dependencies = [ [[package]] name = "zkm-recursion-compiler" -version = "1.2.1" -source = "git+https://github.com/ProjectZKM/Ziren#23e217e88085fdd1dab18cd6bd07630bcfcaba23" +version = "1.2.2" dependencies = [ "backtrace", "itertools 0.13.0", @@ -8463,7 +8613,7 @@ dependencies = [ "tracing", "vec_map", "zkm-core-machine", - "zkm-primitives", + "zkm-primitives 1.2.2", "zkm-recursion-core", "zkm-recursion-derive", "zkm-stark", @@ -8471,11 +8621,13 @@ dependencies = [ [[package]] name = "zkm-recursion-core" -version = "1.2.1" -source = "git+https://github.com/ProjectZKM/Ziren#23e217e88085fdd1dab18cd6bd07630bcfcaba23" +version = "1.2.2" dependencies = [ "backtrace", + "cbindgen", + "cc", "ff 0.13.1", + "glob", "hashbrown 0.14.5", "itertools 0.13.0", "p3-air", @@ -8493,6 +8645,8 @@ dependencies = [ "p3-poseidon2", "p3-symmetric", "p3-util", + "pathdiff", + "rand 0.8.5", "serde", "static_assertions", "thiserror 1.0.69", @@ -8501,14 +8655,13 @@ dependencies = [ "zkhash", "zkm-core-machine", "zkm-derive", - "zkm-primitives", + "zkm-primitives 1.2.2", "zkm-stark", ] [[package]] name = "zkm-recursion-derive" -version = "1.2.1" -source = "git+https://github.com/ProjectZKM/Ziren#23e217e88085fdd1dab18cd6bd07630bcfcaba23" +version = "1.2.2" dependencies = [ "quote", "syn 1.0.109", @@ -8516,8 +8669,7 @@ dependencies = [ [[package]] name = "zkm-recursion-gnark-ffi" -version = "1.2.1" -source = "git+https://github.com/ProjectZKM/Ziren#23e217e88085fdd1dab18cd6bd07630bcfcaba23" +version = "1.2.2" dependencies = [ "anyhow", "bincode", @@ -8541,8 +8693,7 @@ dependencies = [ [[package]] name = "zkm-sdk" -version = "1.2.1" -source = "git+https://github.com/ProjectZKM/Ziren#23e217e88085fdd1dab18cd6bd07630bcfcaba23" +version = "1.2.2" dependencies = [ "alloy-signer", "alloy-signer-local", @@ -8581,15 +8732,15 @@ dependencies = [ "zkm-build", "zkm-core-executor", "zkm-core-machine", - "zkm-primitives", + "zkm-cuda", + "zkm-primitives 1.2.2", "zkm-prover", "zkm-stark", ] [[package]] name = "zkm-stark" -version = "1.2.1" -source = "git+https://github.com/ProjectZKM/Ziren#23e217e88085fdd1dab18cd6bd07630bcfcaba23" +version = "1.2.2" dependencies = [ "arrayref", "hashbrown 0.14.5", @@ -8624,14 +8775,13 @@ dependencies = [ "tracing-forest", "tracing-subscriber 0.3.20", "zkm-derive", - "zkm-primitives", + "zkm-primitives 1.2.2", "zkm-zkvm", ] [[package]] name = "zkm-zkvm" -version = "1.2.1" -source = "git+https://github.com/ProjectZKM/Ziren#23e217e88085fdd1dab18cd6bd07630bcfcaba23" +version = "1.2.2" dependencies = [ "bincode", "cfg-if", @@ -8643,8 +8793,8 @@ dependencies = [ "rand 0.8.5", "serde", "sha2", - "zkm-lib", - "zkm-primitives", + "zkm-lib 1.2.2", + "zkm-primitives 1.2.2", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 74506d4..9a735b9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,9 +20,12 @@ resolver = "2" [workspace.dependencies] garbled-snark-verifier = { path = "./garbled-snark-verifier" } bristol = { path = "./bristol" } -zkm-build = { git = "https://github.com/ProjectZKM/Ziren" } -zkm-sdk = { git = "https://github.com/ProjectZKM/Ziren" } -zkm-zkvm = { git = "https://github.com/ProjectZKM/Ziren" } +#zkm-build = { git = "https://github.com/ProjectZKM/Ziren" } +#zkm-sdk = { git = "https://github.com/ProjectZKM/Ziren" } +#zkm-zkvm = { git = "https://github.com/ProjectZKM/Ziren" } +zkm-build = { path = "../zkMIPS/crates/build" } +zkm-sdk = { path = "../zkMIPS/crates/sdk" } +zkm-zkvm = { path = "../zkMIPS/crates/zkvm/entrypoint" } poseidon2 = { git = "https://github.com/ProjectZKM/poseidon2" } bincode = "1.3.3" sha2 = "0.10.8" diff --git a/README.md b/README.md index a54ce42..e17e82c 100644 --- a/README.md +++ b/README.md @@ -59,10 +59,10 @@ cargo run -r --bin dv-snark Server configuration: 32 core, 480G RAM -| Program | Gates | Cycles | Peak memory | Garbling(s) | Spliting(s) | Single Execution(s) | -|-----------------------------------|---------------------------------------------------------------------------------------|------------------|-------------|-------------|-------------------|---------------------| -| deserialize_compressed_g2_circuit | and variants: 122185357, xor variants: 350864003, not: 550724, total:473600084 | 4268330910 * 68 | 51G | 33s | 480M/(IOPS) = 188 | 178 | -| groth16_verifier_circuit | and variants: 2718558275, xor variants: 7617087185, not: 62381441, total: 10398026901 | | | | | -| dv_snark (use poseidon2) | and variants: 8796030, xor variants: 2365188084, total: 2373984114 | 296796620 * 2374 | 292G | 70s | | +| Program | Gates | Cycles | Peak memory | Garbling(s) | Spliting(s) | Single Execution(s) | +|--------------------------------------------------------|---------------------------------------------------------------------------------------|------------------|-------------|-------------|-------------------|---------------------| +| deserialize_compressed_g2_circuit | and variants: 122185357, xor variants: 350864003, not: 550724, total:473600084 | 4268330910 * 68 | 51G | 33s | 480M/(IOPS) = 188 | 178 | +| groth16_verifier_circuit | and variants: 2718558275, xor variants: 7617087185, not: 62381441, total: 10398026901 | | | | | +| dv_snark with hinted double scalar mul (use poseidon2) | and variants: 6707171, xor variants: 3370130781, total: 3376837952 | 76323964 * 3377 | 374G | 136s | | Proving efficiency: 300k Poseidon2 hashes/s on a single RTX 4090 card. diff --git a/garbled-snark-verifier/src/circuits/dv_snark.rs b/garbled-snark-verifier/src/circuits/dv_snark.rs index afb2bca..d6ede2e 100644 --- a/garbled-snark-verifier/src/circuits/dv_snark.rs +++ b/garbled-snark-verifier/src/circuits/dv_snark.rs @@ -8,7 +8,7 @@ pub fn dv_snark_verifier_circuit(witness: &VerifierPayloadRef) -> Circuit { println!("Compile time: {:?}", start.elapsed()); let start = Instant::now(); - let circuit = builder.build(witness.to_bits()); + let circuit = builder.build(&witness.to_bits()); println!("build circuit time:{:?}", start.elapsed()); circuit @@ -29,55 +29,56 @@ mod test { fn test_dv_snark_verifier_circuit() { // Prepare VerifierPayloadRef let tau = FrRef::from_str( - "490782060457092443021184404188169115419401325819878347174959236155604", + "2730322210350266333305929438402339624225511456370264338590718619370571", ) .unwrap(); let delta = FrRef::from_str( - "409859792668509615016679153954612494269657711226760893245268993658466", + "1668197219006303135911300995268563595632072044933469744573172589503162", ) .unwrap(); let epsilon = FrRef::from_str( - "2880039972651592580549544494658966441531834740391411845954153637005104", + "180534986784443382108991383036395393569817197959638310564367496650276", ) .unwrap(); let commit_p = AffinePointRef { x: [ - 130, 16, 132, 245, 115, 118, 110, 233, 235, 58, 5, 190, 187, 230, 138, 225, 149, - 231, 32, 45, 41, 29, 94, 89, 248, 158, 54, 19, 86, 0, + 243, 1, 124, 124, 28, 184, 224, 34, 217, 222, 182, 31, 42, 252, 194, 222, 40, 36, + 80, 223, 106, 184, 193, 142, 55, 102, 25, 112, 7, 0, ], s: [ - 93, 74, 178, 168, 173, 38, 101, 88, 181, 49, 78, 207, 89, 78, 130, 42, 242, 245, - 88, 5, 253, 250, 54, 182, 177, 249, 82, 57, 147, 0, + 229, 76, 122, 168, 191, 162, 130, 195, 248, 229, 89, 69, 135, 106, 178, 161, 172, + 29, 249, 224, 109, 160, 41, 54, 63, 164, 235, 10, 145, 1, ], }; let kzg_k = AffinePointRef { x: [ - 36, 69, 122, 22, 89, 79, 186, 56, 138, 8, 183, 193, 186, 98, 21, 62, 9, 143, 173, - 24, 89, 195, 126, 73, 241, 118, 71, 103, 223, 0, + 240, 171, 68, 224, 177, 62, 73, 178, 215, 175, 231, 231, 151, 89, 104, 111, 7, 40, + 91, 33, 151, 83, 118, 199, 88, 68, 165, 164, 151, 1, ], s: [ - 12, 122, 106, 168, 104, 248, 117, 18, 171, 218, 85, 138, 31, 80, 250, 230, 176, - 136, 74, 129, 137, 78, 181, 48, 88, 180, 21, 139, 39, 1, + 182, 120, 142, 188, 144, 198, 242, 204, 84, 254, 121, 254, 72, 190, 109, 99, 198, + 59, 168, 17, 124, 224, 37, 14, 69, 114, 133, 198, 2, 1, ], }; let a0 = FrRef::from_str( - "1858232303623355521215721639157430371979542022979851183514844283900649", + "1132675792798759308127577893315934115126328231089219585842855711650311", ) .unwrap(); let b0 = FrRef::from_str( - "3045644831070136055562137919853497607898653327126781771795842528553732", + "3028379641311591322528948616897330931030750894712035609973261306086667", ) .unwrap(); - let public_inputs = [ - FrRef::from_str("9487159538405616582219466419827834782293111327936747259752845028149") - .unwrap(), - FrRef::from_str("22596372664815072823112258091854569627353949811861389086305200952659") - .unwrap(), - ]; + let x1 = + (FrRef::from_str("8201062243878067778315015938357284675413750549").unwrap(), false); + let x2 = + (FrRef::from_str("12188555815513519027948129212942953563582264060").unwrap(), true); + let z = (FrRef::from_str("2328416288857173011062977552890912854869626082").unwrap(), true); + + let public_inputs = [FrRef::from_str("24").unwrap(), FrRef::from_str("13").unwrap()]; let witness = VerifierPayloadRef { - proof: ProofRef { commit_p, kzg_k, a0, b0 }, + proof: ProofRef { commit_p, kzg_k, a0, b0, x1, x2, z }, public_input: PublicInputsRef { public_inputs }, trapdoor: TrapdoorRef { tau, delta, epsilon }, }; diff --git a/garbled-snark-verifier/src/circuits/sect233k1/builder.rs b/garbled-snark-verifier/src/circuits/sect233k1/builder.rs index eac7c2a..f13db69 100644 --- a/garbled-snark-verifier/src/circuits/sect233k1/builder.rs +++ b/garbled-snark-verifier/src/circuits/sect233k1/builder.rs @@ -7,7 +7,6 @@ use std::collections::HashMap; use std::fmt; use std::time::Instant; -use crate::circuits::sect233k1::dv_ckt::WITNESS_BIT_LEN; use rayon::iter::{ IndexedParallelIterator, IntoParallelIterator, IntoParallelRefIterator, ParallelExtend, ParallelIterator, @@ -224,7 +223,7 @@ impl core::ops::Sub for GateCounts { } impl CircuitAdapter { - pub(crate) fn build(&self, witness: [bool; WITNESS_BIT_LEN]) -> Circuit { + pub fn build(&self, witness: &[bool]) -> Circuit { let n_wires = self.next_wire; println!("wires: {n_wires}"); @@ -235,7 +234,7 @@ impl CircuitAdapter { if i.is_multiple_of(10_000_000) { println!("wires: {} M", i / 1_000_000); } - wires.push(new_wirex()); + wires.push(new_wirex_with_id(i as u32)); } println!("init wires took:{:?}", start.elapsed()); @@ -304,8 +303,8 @@ impl CircuitAdapter { // The circuit output is assumed to be the last wire. // Using `expect` for a clearer error message if `wires` is empty. - let output_wire = wires.last().expect("Circuit must have at least one wire").clone(); - Circuit::new(vec![output_wire], gates) + // let output_wire = wires.last().expect("Circuit must have at least one wire").clone(); + Circuit::new(wires, gates) } } diff --git a/garbled-snark-verifier/src/circuits/sect233k1/curve_ckt.rs b/garbled-snark-verifier/src/circuits/sect233k1/curve_ckt.rs index 4b85470..97fff92 100644 --- a/garbled-snark-verifier/src/circuits/sect233k1/curve_ckt.rs +++ b/garbled-snark-verifier/src/circuits/sect233k1/curve_ckt.rs @@ -185,6 +185,43 @@ pub(crate) fn emit_point_add( CurvePoint { x: p3_x, s: p3_s, z: p3_z, t: p3_t } } +// Negation of (X, S, Z, T) is (X, S + T, Z, T) +// Ref: https://github.com/blake-pro/c-xs233/blob/c484485fde47c032594368a915c34d2430378458/xsb233.c#L478 +pub(crate) fn emit_neg_point_with_neg_selector( + bld: &mut T, + p1: &CurvePoint, + neg: usize, +) -> CurvePoint { + let mut r = CurvePoint::identity(bld); + r.x = p1.x; + r.z = p1.z; + r.t = p1.t; + let neg_s = emit_gf_add(bld, &p1.s, &p1.t); + for i in 0..GF_LEN { + let d = bld.xor_wire(p1.s[i], neg_s[i]); + let xd = bld.and_wire(d, neg); + r.s[i] = bld.xor_wire(p1.s[i], xd); + } + r +} +pub(crate) fn emit_neg_point_with_pos_selector( + bld: &mut T, + p1: &CurvePoint, + pos: usize, +) -> CurvePoint { + let mut r = CurvePoint::identity(bld); + r.x = p1.x; + r.z = p1.z; + r.t = p1.t; + let neg_s = emit_gf_add(bld, &p1.s, &p1.t); + for i in 0..GF_LEN { + let d = bld.xor_wire(p1.s[i], neg_s[i]); + let xd = bld.and_wire(d, pos); + r.s[i] = bld.xor_wire(neg_s[i], xd); + } + r +} + /// Apply the Frobenius endomorphism on a point (i.e. square all coordinates). /// /// Squares all coordinates of a xsk233 curve point. @@ -295,21 +332,18 @@ pub(crate) fn template_emit_point_add() -> Template { mod test { use std::{str::FromStr, time::Instant}; - use crate::circuits::sect233k1::{ - builder::CircuitTrait, - gf_ref::bits_to_gfref, - }; + use crate::circuits::sect233k1::{builder::CircuitTrait, gf_ref::bits_to_gfref}; use num_bigint::{BigUint, RandomBits}; use rand::Rng; + use super::{CurvePoint, emit_point_add}; + use crate::circuits::sect233k1::curve_ref::CurvePointRef; use crate::circuits::sect233k1::{ builder::CircuitAdapter, curve_ref::{CurvePointRef as InnerPointRef, point_add as ref_point_add}, gf_ref::{gfref_mul, gfref_to_bits}, }; - use super::{CurvePoint, emit_point_add}; - // Creates a random point ensuring T = X*Z fn random_point() -> InnerPointRef { let mut rng = rand::thread_rng(); @@ -377,4 +411,57 @@ mod test { let c_ptadd_val = InnerPointRef { x: c_ptadd_x, s: c_ptadd_s, z: c_ptadd_z, t: c_ptadd_t }; assert_eq!(c_ptadd_val, ptadd); } + + #[test] + fn test_negative_point_with_neg_selector() { + let p1 = InnerPointRef { + x: BigUint::from_str( + "13283792768796718556929275469989697816663440403339868882741001477299174", + ) + .unwrap(), + s: BigUint::from_str( + "6416386389908495168242210184454780244589215014363767030073322872085145", + ) + .unwrap(), + z: BigUint::from_str("1").unwrap(), + t: BigUint::from_str( + "13283792768796718556929275469989697816663440403339868882741001477299174", + ) + .unwrap(), + }; + let p1_double = ref_point_add(&p1, &p1); + let identity = CurvePointRef::identity(); + + let mut rng = rand::thread_rng(); + let neg_witness = rng.gen_bool(0.5); + println!("neg_witness: {:?}", neg_witness); + + let mut bld = CircuitAdapter::default(); + let c_p1 = CurvePoint { x: bld.fresh(), s: bld.fresh(), z: bld.fresh(), t: bld.fresh() }; + let neg = bld.fresh_one(); + + let c_neg_p1 = super::emit_neg_point_with_neg_selector(&mut bld, &c_p1, neg); + println!("number of neg gates: {:?}", bld.gate_counts()); + let sum = super::emit_point_add(&mut bld, &c_p1, &c_neg_p1); + + let mut witness = Vec::::with_capacity(233 * 4 + 1); + witness.extend(gfref_to_bits(&p1.x)); + witness.extend(gfref_to_bits(&p1.s)); + witness.extend(gfref_to_bits(&p1.z)); + witness.extend(gfref_to_bits(&p1.t)); + witness.push(neg_witness); + let wires = bld.eval_gates(&witness); + + let c_ptadd_x = bits_to_gfref(&sum.x.map(|w_id| wires[w_id])); + let c_ptadd_s = bits_to_gfref(&sum.s.map(|w_id| wires[w_id])); + let c_ptadd_z = bits_to_gfref(&sum.z.map(|w_id| wires[w_id])); + let c_ptadd_t = bits_to_gfref(&sum.t.map(|w_id| wires[w_id])); + + let c_ptadd_val = InnerPointRef { x: c_ptadd_x, s: c_ptadd_s, z: c_ptadd_z, t: c_ptadd_t }; + if neg_witness { + assert_eq!(c_ptadd_val, identity); + } else { + assert_eq!(c_ptadd_val, p1_double); + } + } } diff --git a/garbled-snark-verifier/src/circuits/sect233k1/curve_ref.rs b/garbled-snark-verifier/src/circuits/sect233k1/curve_ref.rs index c92511c..8d315c4 100644 --- a/garbled-snark-verifier/src/circuits/sect233k1/curve_ref.rs +++ b/garbled-snark-verifier/src/circuits/sect233k1/curve_ref.rs @@ -192,6 +192,16 @@ pub(crate) fn point_add(p1: &CurvePointRef, p2: &CurvePointRef) -> CurvePointRef p3 } +// Negation of (X, S, Z, T) is (X, S + T, Z, T) +pub(crate) fn neg_point(p: &CurvePointRef) -> CurvePointRef { + let mut np = CurvePointRef::new(); + np.x = p.x.clone(); + np.s = gfref_add(&p.s, &p.t); + np.z = p.z.clone(); + np.t = p.t.clone(); + np +} + /// Apply the Frobenius endomorphism on a point (i.e. square all coordinates). /// /// Squares all coordinates of a xsk233 curve point. diff --git a/garbled-snark-verifier/src/circuits/sect233k1/curve_scalar_mul_ckt.rs b/garbled-snark-verifier/src/circuits/sect233k1/curve_scalar_mul_ckt.rs index 42454f5..366a968 100644 --- a/garbled-snark-verifier/src/circuits/sect233k1/curve_scalar_mul_ckt.rs +++ b/garbled-snark-verifier/src/circuits/sect233k1/curve_scalar_mul_ckt.rs @@ -1456,5 +1456,289 @@ pub(crate) mod point_scalar_mul { assert_eq!(ckt_out, out_ref); } + + #[test] + // This test just printout the circuit size for tau-adic scalar multiplication + // in case of k1P1 + k2P2 + fn test_tau_adic_sm_circuit_size() { + let window = 5; + let mut bld = CircuitAdapter::default(); + let k1_labels: Fr = bld.fresh(); + let k2_labels: Fr = bld.fresh(); + let p1_labels: CurvePoint = + CurvePoint { x: bld.fresh(), s: bld.fresh(), z: bld.fresh(), t: bld.fresh() }; + let p2_labels: CurvePoint = + CurvePoint { x: bld.fresh(), s: bld.fresh(), z: bld.fresh(), t: bld.fresh() }; + + println!("emit_mul_windowed_tau"); + let st = Instant::now(); + + // k1P1 + k2P2 + let k1p1 = emit_mul_windowed_tau(&mut bld, &k1_labels, &p1_labels, window); + let k2p2 = emit_mul_windowed_tau(&mut bld, &k2_labels, &p2_labels, window); + let res_labels = Template::emit_point_add_custom(&mut bld, &k1p1, &k2p2); + + let st = st.elapsed(); + println!("emit_mul_windowed_tau took {} seconds", st.as_secs()); + let stats = bld.gate_counts(); + println!("{stats}"); + } + } +} + +pub(crate) mod hinted_double_scalar_mul { + use crate::circuits::sect233k1::builder::{CircuitTrait, Template}; + use crate::circuits::sect233k1::curve_ckt::CurvePoint; + use crate::circuits::sect233k1::curve_scalar_mul_ckt::precompute_table::emit_lookup; + use crate::circuits::sect233k1::fr_ckt::Fr; + + const HINTED_DOUBLE_SCALAR_BITS_LENGTH: usize = 155; + + // Compute [x1]P1 + x2[P2] + x3[P3]. + pub(crate) fn emit_hinted_double_scalar_mul( + bld: &mut T, + k1: &Fr, + p1: &CurvePoint, + k2: &Fr, + p2: &CurvePoint, + k3: &Fr, + p3: &CurvePoint, + ) -> CurvePoint { + // precompute table for 3 points + let table = emit_precompute_hinted_table(bld, p1, p2, p3); + + let mut r = CurvePoint::identity(bld); + for i in (0..HINTED_DOUBLE_SCALAR_BITS_LENGTH).rev() { + r = Template::emit_point_add_custom(bld, &r, &r); // r = r * 2 + // get the msb i-th bit of k1, k2, k3 + let lidx = vec![k1[i], k2[i], k3[i]]; + let t_i = emit_lookup(bld, &table, lidx); + r = Template::emit_point_add_custom(bld, &r, &t_i); + } + r + } + + // generate precompute table for hinted double scalar multiplication + pub(crate) fn emit_precompute_hinted_table( + bld: &mut T, + p0: &CurvePoint, + p1: &CurvePoint, + p2: &CurvePoint, + ) -> Vec { + let bs = [ + [0, 0, 0], + [1, 0, 0], + [0, 1, 0], + [1, 1, 0], + [0, 0, 1], + [1, 0, 1], + [0, 1, 1], + [1, 1, 1], + ]; + + let table_size = bs.len(); + let iden = CurvePoint::identity(bld); + + let mut table = Vec::with_capacity(table_size); + table.push(iden); + + for i in 1..table_size { + let temp_point = add_2_points_with_selects(bld, bs[i][0], p0, bs[i][1], p1); + let sel_temp = usize::from((bs[i][0] != 0) || (bs[i][1] != 0)); + let res_point = add_2_points_with_selects(bld, sel_temp, &temp_point, bs[i][2], &p2); + table.push(res_point); + } + table + } + + fn add_2_points_with_selects( + bld: &mut T, + select0: usize, + p0: &CurvePoint, + select1: usize, + p1: &CurvePoint, + ) -> CurvePoint { + if select0 == 0 && select1 == 0 { + return CurvePoint::identity(bld); + } + if select0 == 0 { + return p1.clone(); + } + if select1 == 0 { + return p0.clone(); + } + Template::emit_point_add_custom(bld, p0, p1) + } + + #[cfg(test)] + mod test { + use crate::circuits::sect233k1::builder::{CircuitAdapter, CircuitTrait}; + use crate::circuits::sect233k1::curve_ckt::{ + CurvePoint, emit_neg_point_with_neg_selector, emit_neg_point_with_pos_selector, + }; + use crate::circuits::sect233k1::curve_ref::{ + CurvePointRef, point_add, point_scalar_multiplication, + }; + use crate::circuits::sect233k1::curve_scalar_mul_ckt::hinted_double_scalar_mul::emit_hinted_double_scalar_mul; + use crate::circuits::sect233k1::fr_ckt::Fr; + use crate::circuits::sect233k1::fr_ref::frref_to_bits; + use crate::circuits::sect233k1::gf_ref::{bits_to_gfref, gfref_to_bits}; + use num_bigint::BigUint; + use std::time::Instant; + + // This test just printout the circuit size for hinted double scalar multiplication + // in case of x1P1 + x2P2 + x3P3 + #[test] + fn test_hinted_double_scalar_mul_circuit_size() { + let mut bld = CircuitAdapter::default(); + let x1labels: Fr = bld.fresh(); + let x2labels: Fr = bld.fresh(); + let x3labels: Fr = bld.fresh(); + let p1labels: CurvePoint = + CurvePoint { x: bld.fresh(), s: bld.fresh(), z: bld.fresh(), t: bld.fresh() }; + let p2labels: CurvePoint = + CurvePoint { x: bld.fresh(), s: bld.fresh(), z: bld.fresh(), t: bld.fresh() }; + let p3labels: CurvePoint = + CurvePoint { x: bld.fresh(), s: bld.fresh(), z: bld.fresh(), t: bld.fresh() }; + + println!("emit_triple_scalar_multiplication"); + let st = Instant::now(); + let out_bits = emit_hinted_double_scalar_mul( + &mut bld, &x1labels, &p1labels, &x2labels, &p2labels, &x3labels, &p3labels, + ); + let st = st.elapsed(); + println!("emit_triple_scalar_multiplication took {} seconds", st.as_secs()); + let stats = bld.gate_counts(); + println!("{stats}"); + } + + #[test] + #[ignore] + fn test_hinted_double_scalar_mul_with_selector() { + let p1 = CurvePointRef::generator(); + let p2 = CurvePointRef::generator(); + let expected_output = CurvePointRef::identity(); // = 0 + + let k1_be_bytes = vec![ + 0, 0, 0, 51, 96, 176, 10, 90, 39, 174, 104, 4, 29, 148, 187, 28, 109, 98, 171, 127, + 230, 48, 143, 66, 84, 143, 149, 177, 187, 210, 141, 20, + ]; + let k2_be_bytes = vec![ + 0, 0, 0, 26, 108, 65, 9, 244, 48, 225, 36, 47, 208, 219, 69, 144, 176, 74, 146, + 191, 44, 28, 58, 190, 137, 175, 120, 202, 225, 15, 139, 63, + ]; + let x1_be_bytes = vec![ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 131, 96, 158, 213, 110, 156, 186, 202, 3, + 203, 165, 199, 221, 172, 156, 232, 214, 228, 39, + ]; + let x2_be_bytes = vec![ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 174, 223, 194, 147, 141, 52, 233, 166, 56, + 189, 163, 209, 209, 141, 210, 79, 165, 145, 131, + ]; + let x3_be_bytes = vec![ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 100, 192, 131, 198, 143, 204, 6, 70, 212, + 104, 61, 59, 3, 251, 190, 41, 255, 150, 205, + ]; + + let x1 = BigUint::from_bytes_be(&x1_be_bytes); + let x2 = BigUint::from_bytes_be(&x2_be_bytes); + let x3 = BigUint::from_bytes_be(&x3_be_bytes); + let k1 = BigUint::from_bytes_be(&k1_be_bytes); + let k2 = BigUint::from_bytes_be(&k2_be_bytes); + + let p3_1 = point_scalar_multiplication(&k1, &p1); + let p3_2 = point_scalar_multiplication(&k2, &p2); + let p3 = point_add(&p3_1, &p3_2); + + let x1_neg_w = false; + let x2_neg_w = true; + let x3_neg_w = false; + + // ++++++ + let mut bld = CircuitAdapter::default(); + let mut witness = Vec::::new(); + let x1witness = frref_to_bits(&x1); + let x2witness = frref_to_bits(&x2); + let x3witness = frref_to_bits(&x3); + + let p1witness: Vec = [&p1.x, &p1.s, &p1.z, &p1.t] + .iter() + .flat_map(|k| { + let kb: Vec = gfref_to_bits(k).to_vec(); + kb + }) + .collect(); + + let p2witness: Vec = [&p2.x, &p2.s, &p2.z, &p2.t] + .iter() + .flat_map(|k| { + let kb: Vec = gfref_to_bits(k).to_vec(); + kb + }) + .collect(); + + let p3witness: Vec = [&p3.x, &p3.s, &p3.z, &p3.t] + .iter() + .flat_map(|k| { + let kb: Vec = gfref_to_bits(k).to_vec(); + kb + }) + .collect(); + + let x1labels: Fr = bld.fresh(); + let x1_neg = bld.fresh_one(); + let x2labels: Fr = bld.fresh(); + let x2_neg = bld.fresh_one(); + let x3labels: Fr = bld.fresh(); + let x3_neg = bld.fresh_one(); + let p1labels: CurvePoint = + CurvePoint { x: bld.fresh(), s: bld.fresh(), z: bld.fresh(), t: bld.fresh() }; + let p2labels: CurvePoint = + CurvePoint { x: bld.fresh(), s: bld.fresh(), z: bld.fresh(), t: bld.fresh() }; + let p3labels: CurvePoint = + CurvePoint { x: bld.fresh(), s: bld.fresh(), z: bld.fresh(), t: bld.fresh() }; + + witness.extend_from_slice(&x1witness); + witness.push(x1_neg_w); + witness.extend_from_slice(&x2witness); + witness.push(x2_neg_w); + witness.extend_from_slice(&x3witness); + witness.push(x3_neg_w); + witness.extend_from_slice(&p1witness); + witness.extend_from_slice(&p2witness); + witness.extend_from_slice(&p3witness); + + println!("test_hinted_double_scalar_mul_with_selector"); + let st = Instant::now(); + let new_p1 = emit_neg_point_with_neg_selector(&mut bld, &p1labels, x1_neg); + let new_p2 = emit_neg_point_with_neg_selector(&mut bld, &p2labels, x2_neg); + // because we compute ... + (-zQ). + let new_p3 = emit_neg_point_with_pos_selector(&mut bld, &p3labels, x3_neg); + let out_bits = emit_hinted_double_scalar_mul( + &mut bld, &x1labels, &new_p1, &x2labels, &new_p2, &x3labels, &new_p3, + ); + let st = st.elapsed(); + println!("test_hinted_double_scalar_mul_with_selector took {} seconds", st.as_secs()); + + let stats = bld.gate_counts(); + println!("{stats}"); + + let wires = bld.eval_gates(&witness); + + println!("validating output"); + let ckt_x = out_bits.x.map(|id| wires[id]); + let ckt_s = out_bits.s.map(|id| wires[id]); + let ckt_z = out_bits.z.map(|id| wires[id]); + let ckt_t = out_bits.t.map(|id| wires[id]); + + let ckt_out = CurvePointRef { + x: bits_to_gfref(&ckt_x), + s: bits_to_gfref(&ckt_s), + z: bits_to_gfref(&ckt_z), + t: bits_to_gfref(&ckt_t), + }; + + assert_eq!(ckt_out, expected_output); + } } } diff --git a/garbled-snark-verifier/src/circuits/sect233k1/dv_ckt.rs b/garbled-snark-verifier/src/circuits/sect233k1/dv_ckt.rs index 4953827..a363972 100644 --- a/garbled-snark-verifier/src/circuits/sect233k1/dv_ckt.rs +++ b/garbled-snark-verifier/src/circuits/sect233k1/dv_ckt.rs @@ -4,7 +4,6 @@ use super::{ blake3_ckt, builder::{CircuitAdapter, CircuitTrait}, curve_ckt::AffinePointRef, - curve_scalar_mul_ckt::point_scalar_mul::emit_mul_windowed_tau, fr_ckt::{ FR_LEN, Fr, const_mod_n, emit_fr_add as fr_add, emit_fr_mul as fr_mul, emit_fr_sub as fr_sub, ge_unsigned, @@ -12,8 +11,11 @@ use super::{ fr_ref::{FrRef, frref_to_bits}, }; use crate::circuits::sect233k1::curve_ckt::{ - AffinePoint, CurvePoint, emit_affine_point_is_on_curve, emit_point_add, emit_point_equals, + AffinePoint, CurvePoint, emit_affine_point_is_on_curve, emit_neg_point_with_neg_selector, + emit_neg_point_with_pos_selector, emit_point_equals, }; +use crate::circuits::sect233k1::curve_scalar_mul_ckt::hinted_double_scalar_mul::emit_hinted_double_scalar_mul; +use crate::circuits::sect233k1::fr_ckt::{emit_fr_mul, emit_neg_fr_with_selector, two_to_156}; use crate::circuits::sect233k1::gf_ckt::GF_LEN; #[derive(Debug)] @@ -38,9 +40,13 @@ pub struct ProofRef { pub a0: FrRef, /// b0 pub b0: FrRef, + // x1, x2, z for hinted scalar mul + pub x1: (FrRef, bool), + pub x2: (FrRef, bool), + pub z: (FrRef, bool), } -const PROOF_BIT_LEN: usize = GF_LEN * 2 * 2 + FR_LEN * 2; +const PROOF_BIT_LEN: usize = GF_LEN * 2 * 2 + FR_LEN * 5 + 3; const PUBINP_BIT_LEN: usize = 2 * FR_LEN; const TRAPDOOR_BIT_LEN: usize = 696; @@ -53,6 +59,9 @@ impl ProofRef { let mut kzg_k = self.kzg_k.to_bits(); let mut a0 = frref_to_bits(&self.a0).to_vec(); let mut b0 = frref_to_bits(&self.b0).to_vec(); + let mut x1 = frref_to_bits(&self.x1.0).to_vec(); + let mut x2 = frref_to_bits(&self.x2.0).to_vec(); + let mut z = frref_to_bits(&self.z.0).to_vec(); let mut witness = vec![]; @@ -60,6 +69,12 @@ impl ProofRef { witness.append(&mut kzg_k); witness.append(&mut a0); witness.append(&mut b0); + witness.append(&mut x1); + witness.push(self.x1.1); + witness.append(&mut x2); + witness.push(self.x2.1); + witness.append(&mut z); + witness.push(self.z.1); witness.try_into().unwrap() } @@ -120,7 +135,15 @@ impl VerifierPayloadRef { let commit_p = AffinePoint { x: bld.fresh(), s: bld.fresh() }; let kzg_k = AffinePoint { x: bld.fresh(), s: bld.fresh() }; - let proof = Proof { commit_p, kzg_k, a0: bld.fresh(), b0: bld.fresh() }; + let proof = Proof { + commit_p, + kzg_k, + a0: bld.fresh(), + b0: bld.fresh(), + x1: (bld.fresh(), bld.fresh_one()), + x2: (bld.fresh(), bld.fresh_one()), + z: (bld.fresh(), bld.fresh_one()), + }; (proof, rpin, secrets) } @@ -151,6 +174,10 @@ pub(crate) struct Proof { pub a0: Fr, /// b0 pub b0: Fr, + /// x1, x2, z for hinted scalar mul + pub x1: (Fr, usize), + pub x2: (Fr, usize), + pub z: (Fr, usize), } /// RawPublicInputs @@ -346,6 +373,18 @@ pub(crate) fn verify( let proof_scalars_valid = bld.xor_wire(proof_scalars_invalid, one_wire); // both scalars valid let decoded_points_valid = bld.and_wire(is_proof_commit_p_on_curve, is_proof_kzg_k_on_curve); // both points valid + // decompose + let two_to_156 = two_to_156(bld); + let proof_x1_invalid = ge_unsigned(bld, &proof.x1.0, &two_to_156); + let proof_x2_invalid = ge_unsigned(bld, &proof.x2.0, &two_to_156); + let proof_z_invalid = ge_unsigned(bld, &proof.z.0, &two_to_156); + + let x1x2_invalid = bld.or_wire(proof_x1_invalid, proof_x2_invalid); // either x1, x2 invalid + let decompose_invalid = bld.or_wire(x1x2_invalid, proof_z_invalid); // either x1, x2, z invalid + let decompose_valid = bld.xor_wire(decompose_invalid, one_wire); // all valid + + let proof_scalars_valid = bld.and_wire(proof_scalars_valid, decompose_valid); + let fs_challenge_alpha = get_fs_challenge(bld, proof.commit_p, public_inputs.public_inputs.clone(), vec![], vec![]); @@ -373,18 +412,47 @@ pub(crate) fn verify( }; let tmp0 = fr_sub(bld, &secrets.tau, &fs_challenge_alpha); let v0 = fr_mul(bld, &tmp0, &secrets.epsilon); - - let w = 5; let generator = CurvePoint::generator(bld); - let v0_k = emit_mul_windowed_tau(bld, &v0, &proof_kzg_k, w); - let u0_g = emit_mul_windowed_tau(bld, &u0, &generator, w); - let lhs = emit_point_add(bld, &v0_k, &u0_g); - let rhs: CurvePoint = proof_commit_p; - - let verify_success = emit_point_equals(bld, &lhs, &rhs); - let eq_with_valid_points = bld.and_wire(verify_success, decoded_points_valid); - - bld.and_wire(eq_with_valid_points, proof_scalars_valid) + let identity = CurvePoint::identity(bld); + let mut fr_one = Fr::from([bld.zero(); FR_LEN]); + fr_one[0] = one_wire; + + // check the validation of x1, x2, z: + // u0 = x1/z mod r, v0 = x2/z mod r + let new_x1 = emit_neg_fr_with_selector(bld, &proof.x1.0, proof.x1.1); + let new_x2 = emit_neg_fr_with_selector(bld, &proof.x2.0, proof.x2.1); + let new_z = emit_neg_fr_with_selector(bld, &proof.z.0, proof.z.1); + + let k1z = emit_fr_mul(bld, &u0, &new_z); + let k2z = emit_fr_mul(bld, &v0, &new_z); + let diff1 = fr_sub(bld, &k1z, &new_x1); + let diff2 = fr_sub(bld, &k2z, &new_x2); + + let diff1_not_zero = ge_unsigned(bld, &diff1, &fr_one); + let diff2_not_zero = ge_unsigned(bld, &diff2, &fr_one); + let diff_not_zero = bld.or_wire(diff1_not_zero, diff2_not_zero); + let diff_zero = bld.xor_wire(diff_not_zero, one_wire); // both zero + + // check the validation of hinted double scalar multiplication + // u0 * G + v0 * KZG_K == COMMIT_P + // <=> x1G + x2KZG_K + (-zP) = 0 + let new_p1 = emit_neg_point_with_neg_selector(bld, &generator, proof.x1.1); + let new_p2 = emit_neg_point_with_neg_selector(bld, &proof_kzg_k, proof.x2.1); + let new_p3 = emit_neg_point_with_pos_selector(bld, &proof_commit_p, proof.z.1); + let res = emit_hinted_double_scalar_mul( + bld, + &proof.x1.0, + &new_p1, + &proof.x2.0, + &new_p2, + &proof.z.0, + &new_p3, + ); + let verify_success = emit_point_equals(bld, &res, &identity); + let hinted_success = bld.and_wire(verify_success, diff_zero); + let scalar_valid = bld.and_wire(proof_scalars_valid, decompose_valid); + let scalar_point_valid = bld.and_wire(scalar_valid, decoded_points_valid); + bld.and_wire(hinted_success, scalar_point_valid) } #[cfg(test)] @@ -414,55 +482,56 @@ mod test { // Prepare VerifierPayloadRef let tau = FrRef::from_str( - "490782060457092443021184404188169115419401325819878347174959236155604", + "2730322210350266333305929438402339624225511456370264338590718619370571", ) .unwrap(); let delta = FrRef::from_str( - "409859792668509615016679153954612494269657711226760893245268993658466", + "1668197219006303135911300995268563595632072044933469744573172589503162", ) .unwrap(); let epsilon = FrRef::from_str( - "2880039972651592580549544494658966441531834740391411845954153637005104", + "180534986784443382108991383036395393569817197959638310564367496650276", ) .unwrap(); let commit_p = AffinePointRef { x: [ - 130, 16, 132, 245, 115, 118, 110, 233, 235, 58, 5, 190, 187, 230, 138, 225, 149, - 231, 32, 45, 41, 29, 94, 89, 248, 158, 54, 19, 86, 0, + 243, 1, 124, 124, 28, 184, 224, 34, 217, 222, 182, 31, 42, 252, 194, 222, 40, 36, + 80, 223, 106, 184, 193, 142, 55, 102, 25, 112, 7, 0, ], s: [ - 93, 74, 178, 168, 173, 38, 101, 88, 181, 49, 78, 207, 89, 78, 130, 42, 242, 245, - 88, 5, 253, 250, 54, 182, 177, 249, 82, 57, 147, 0, + 229, 76, 122, 168, 191, 162, 130, 195, 248, 229, 89, 69, 135, 106, 178, 161, 172, + 29, 249, 224, 109, 160, 41, 54, 63, 164, 235, 10, 145, 1, ], }; let kzg_k = AffinePointRef { x: [ - 36, 69, 122, 22, 89, 79, 186, 56, 138, 8, 183, 193, 186, 98, 21, 62, 9, 143, 173, - 24, 89, 195, 126, 73, 241, 118, 71, 103, 223, 0, + 240, 171, 68, 224, 177, 62, 73, 178, 215, 175, 231, 231, 151, 89, 104, 111, 7, 40, + 91, 33, 151, 83, 118, 199, 88, 68, 165, 164, 151, 1, ], s: [ - 12, 122, 106, 168, 104, 248, 117, 18, 171, 218, 85, 138, 31, 80, 250, 230, 176, - 136, 74, 129, 137, 78, 181, 48, 88, 180, 21, 139, 39, 1, + 182, 120, 142, 188, 144, 198, 242, 204, 84, 254, 121, 254, 72, 190, 109, 99, 198, + 59, 168, 17, 124, 224, 37, 14, 69, 114, 133, 198, 2, 1, ], }; let a0 = FrRef::from_str( - "1858232303623355521215721639157430371979542022979851183514844283900649", + "1132675792798759308127577893315934115126328231089219585842855711650311", ) .unwrap(); let b0 = FrRef::from_str( - "3045644831070136055562137919853497607898653327126781771795842528553732", + "3028379641311591322528948616897330931030750894712035609973261306086667", ) .unwrap(); - let public_inputs = [ - FrRef::from_str("9487159538405616582219466419827834782293111327936747259752845028149") - .unwrap(), - FrRef::from_str("22596372664815072823112258091854569627353949811861389086305200952659") - .unwrap(), - ]; + let x1 = + (FrRef::from_str("8201062243878067778315015938357284675413750549").unwrap(), false); + let x2 = + (FrRef::from_str("12188555815513519027948129212942953563582264060").unwrap(), true); + let z = (FrRef::from_str("2328416288857173011062977552890912854869626082").unwrap(), true); + + let public_inputs = [FrRef::from_str("24").unwrap(), FrRef::from_str("13").unwrap()]; let verifier_payload = VerifierPayloadRef { - proof: ProofRef { commit_p, kzg_k, a0, b0 }, + proof: ProofRef { commit_p, kzg_k, a0, b0, x1, x2, z }, public_input: PublicInputsRef { public_inputs }, trapdoor: TrapdoorRef { tau, delta, epsilon }, }; @@ -483,55 +552,56 @@ mod test { // Prepare VerifierPayloadRef let tau = FrRef::from_str( - "490782060457092443021184404188169115419401325819878347174959236155604", + "2730322210350266333305929438402339624225511456370264338590718619370571", ) .unwrap(); let delta = FrRef::from_str( - "409859792668509615016679153954612494269657711226760893245268993658466", + "1668197219006303135911300995268563595632072044933469744573172589503162", ) .unwrap(); let epsilon = FrRef::from_str( - "2880039972651592580549544494658966441531834740391411845954153637005104", + "180534986784443382108991383036395393569817197959638310564367496650276", ) .unwrap(); let commit_p = AffinePointRef { x: [ - 130, 16, 132, 245, 115, 118, 110, 233, 235, 58, 5, 190, 187, 230, 138, 225, 149, - 231, 32, 45, 41, 29, 94, 89, 248, 158, 54, 19, 86, 0, + 243, 1, 124, 124, 28, 184, 224, 34, 217, 222, 182, 31, 42, 252, 194, 222, 40, 36, + 80, 223, 106, 184, 193, 142, 55, 102, 25, 112, 7, 0, ], s: [ - 93, 74, 178, 168, 173, 38, 101, 88, 181, 49, 78, 207, 89, 78, 130, 42, 242, 245, - 88, 5, 253, 250, 54, 182, 177, 249, 82, 57, 147, 0, + 229, 76, 122, 168, 191, 162, 130, 195, 248, 229, 89, 69, 135, 106, 178, 161, 172, + 29, 249, 224, 109, 160, 41, 54, 63, 164, 235, 10, 145, 1, ], }; let kzg_k = AffinePointRef { x: [ - 36, 69, 122, 22, 89, 79, 186, 56, 138, 8, 183, 193, 186, 98, 21, 62, 9, 143, 173, - 24, 89, 195, 126, 73, 241, 118, 71, 103, 223, 0, + 240, 171, 68, 224, 177, 62, 73, 178, 215, 175, 231, 231, 151, 89, 104, 111, 7, 40, + 91, 33, 151, 83, 118, 199, 88, 68, 165, 164, 151, 1, ], s: [ - 12, 122, 106, 168, 104, 248, 117, 18, 171, 218, 85, 138, 31, 80, 250, 230, 176, - 136, 74, 129, 137, 78, 181, 48, 88, 180, 21, 139, 39, 1, + 182, 120, 142, 188, 144, 198, 242, 204, 84, 254, 121, 254, 72, 190, 109, 99, 198, + 59, 168, 17, 124, 224, 37, 14, 69, 114, 133, 198, 2, 1, ], }; let a0 = FrRef::from_str( - "1858232303623355521215721639157430371979542022979851183514844283900649", + "1132675792798759308127577893315934115126328231089219585842855711650311", ) .unwrap(); let b0 = FrRef::from_str( - "3045644831070136055562137919853497607898653327126781771795842528553732", + "3028379641311591322528948616897330931030750894712035609973261306086667", ) .unwrap(); - let public_inputs = [ - FrRef::from_str("10964902444291521893664765711676021715483874668026528518811070427510") - .unwrap(), - FrRef::from_str("22596372664815072823112258091854569627353949811861389086305200952659") - .unwrap(), - ]; + let x1 = + (FrRef::from_str("8201062243878067778315015938357284675413750549").unwrap(), false); + let x2 = + (FrRef::from_str("12188555815513519027948129212942953563582264060").unwrap(), true); + let z = (FrRef::from_str("2328416288857173011062977552890912854869626082").unwrap(), true); + + let public_inputs = [FrRef::from_str("25").unwrap(), FrRef::from_str("13").unwrap()]; let verifier_payload = VerifierPayloadRef { - proof: ProofRef { commit_p, kzg_k, a0, b0 }, + proof: ProofRef { commit_p, kzg_k, a0, b0, x1, x2, z }, public_input: PublicInputsRef { public_inputs }, trapdoor: TrapdoorRef { tau, delta, epsilon }, }; diff --git a/garbled-snark-verifier/src/circuits/sect233k1/dv_ref.rs b/garbled-snark-verifier/src/circuits/sect233k1/dv_ref.rs index b654b53..145f22d 100644 --- a/garbled-snark-verifier/src/circuits/sect233k1/dv_ref.rs +++ b/garbled-snark-verifier/src/circuits/sect233k1/dv_ref.rs @@ -7,7 +7,8 @@ use super::{ fr_ref::FrRef, }; use crate::circuits::sect233k1::curve_ckt::AffinePointRef; -use num_traits::Num; +use crate::circuits::sect233k1::curve_ref::neg_point; +use num_traits::{Num, Zero}; pub(crate) fn get_fs_challenge( commit_p: &AffinePointRef, @@ -91,6 +92,7 @@ pub(crate) fn get_fs_challenge( // } const MOD_HEX: &str = "8000000000000000000000000000069d5bb915bcd46efb1ad5f173abdf"; // n +const TWO_TO_156_HEX: &str = "1000000000000000000000000000000000000000"; fn fr_add(a: &FrRef, b: &FrRef) -> FrRef { let n = FrRef::from_str_radix(MOD_HEX, 16).unwrap(); @@ -114,10 +116,16 @@ pub(crate) fn verify( ) -> bool { let (proof_commit_p, decode_proof_commit_p_success) = CurvePointRef::from_affine_point(&proof.commit_p); + let generator = CurvePointRef::generator(); let (proof_kzg_k, decode_proof_kzg_k_success) = CurvePointRef::from_affine_point(&proof.kzg_k); let n = FrRef::from_str_radix(MOD_HEX, 16).unwrap(); let decode_scalars_success = proof.a0 < n && proof.b0 < n; + // decompose + let two_to_156 = FrRef::from_str_radix(TWO_TO_156_HEX, 16).unwrap(); + let decompose_scalars_check = + proof.x1.0 < two_to_156 && proof.x2.0 < two_to_156 && proof.z.0 < two_to_156; + // let public_inputs_1 = get_pub_hash_from_raw_pub_inputs(&raw_public_inputs); // let public_inputs_0_vk_const = FrRef::from_str(ziren_vk).unwrap(); // vk @@ -146,16 +154,44 @@ pub(crate) fn verify( fr_mul(&t1, &secrets.epsilon) }; let v0 = fr_mul(&fr_sub(&secrets.tau, &fs_challenge_alpha), &secrets.epsilon); + let fr_zero = FrRef::ZERO; + + // check x1, x2, z to u0, v0 + // u0 = x1/z mod r, v0 = x2/z mod r + let new_x1 = if proof.x1.1 { fr_sub(&fr_zero, &proof.x1.0) } else { proof.x1.0.clone() }; + let new_x2 = if proof.x2.1 { fr_sub(&fr_zero, &proof.x2.0) } else { proof.x2.0.clone() }; + let new_z = if proof.z.1 { fr_sub(&fr_zero, &proof.z.0) } else { proof.z.0.clone() }; + + let k1z = fr_mul(&u0, &new_z); + let k2z = fr_mul(&v0, &new_z); + let diff1 = fr_sub(&k1z, &new_x1); + let diff2 = fr_sub(&k2z, &new_x2); + let check_diff1 = diff1.is_zero(); + let check_diff2 = diff2.is_zero(); - let v0_k = point_scalar_multiplication(&v0, &proof_kzg_k); - let u0_g = point_scalar_multiplication(&u0, &CurvePointRef::generator()); - let lhs = point_add(&v0_k, &u0_g); - let rhs: CurvePointRef = proof_commit_p; + // check the validation of hinted double scalar multiplication + // u0 * G + v0 * KZG_K == COMMIT_P + // <=> x1G + x2KZG_K + (-zP) = 0 + let new_p1 = if proof.x1.1 { neg_point(&generator) } else { generator }; + let new_p2 = if proof.x2.1 { neg_point(&proof_kzg_k) } else { proof_kzg_k.clone() }; + let new_p3 = if proof.z.1 { proof_commit_p.clone() } else { neg_point(&proof_commit_p) }; - let proof_pass = point_equals(&lhs, &rhs); // matches - let decode_pass = - decode_proof_commit_p_success & decode_proof_kzg_k_success & decode_scalars_success; - proof_pass & decode_pass + // x1p1 + x2p2 + zp3 == 0 + let x1p1 = point_scalar_multiplication(&proof.x1.0, &new_p1); + let x2p2 = point_scalar_multiplication(&proof.x2.0, &new_p2); + let x3p3 = point_scalar_multiplication(&proof.z.0, &new_p3); + let sum1 = point_add(&x1p1, &x2p2); + let lhs = point_add(&sum1, &x3p3); + let rhs = CurvePointRef::identity(); + let equal = point_equals(&lhs, &rhs); + + decode_scalars_success + && decode_proof_commit_p_success + && decode_proof_kzg_k_success + && decompose_scalars_check + && check_diff1 + && check_diff2 + && equal } #[cfg(test)] @@ -166,131 +202,118 @@ mod test { use std::str::FromStr; #[test] - fn test_verify_over_mock_inputs() { - let secrets = { - let tau = FrRef::from_str( - "490782060457092443021184404188169115419401325819878347174959236155604", - ) - .unwrap(); - let delta = FrRef::from_str( - "409859792668509615016679153954612494269657711226760893245268993658466", - ) - .unwrap(); - let epsilon = FrRef::from_str( - "2880039972651592580549544494658966441531834740391411845954153637005104", - ) - .unwrap(); - TrapdoorRef { tau, delta, epsilon } - }; - - let proof = ProofRef { - commit_p: AffinePointRef { - x: [ - 130, 16, 132, 245, 115, 118, 110, 233, 235, 58, 5, 190, 187, 230, 138, 225, - 149, 231, 32, 45, 41, 29, 94, 89, 248, 158, 54, 19, 86, 0, - ], - s: [ - 93, 74, 178, 168, 173, 38, 101, 88, 181, 49, 78, 207, 89, 78, 130, 42, 242, - 245, 88, 5, 253, 250, 54, 182, 177, 249, 82, 57, 147, 0, - ], - }, - kzg_k: AffinePointRef { - x: [ - 36, 69, 122, 22, 89, 79, 186, 56, 138, 8, 183, 193, 186, 98, 21, 62, 9, 143, - 173, 24, 89, 195, 126, 73, 241, 118, 71, 103, 223, 0, - ], - s: [ - 12, 122, 106, 168, 104, 248, 117, 18, 171, 218, 85, 138, 31, 80, 250, 230, 176, - 136, 74, 129, 137, 78, 181, 48, 88, 180, 21, 139, 39, 1, - ], - }, - a0: FrRef::from_str( - "1858232303623355521215721639157430371979542022979851183514844283900649", - ) - .unwrap(), - b0: FrRef::from_str( - "3045644831070136055562137919853497607898653327126781771795842528553732", - ) - .unwrap(), + fn test_verify_over_mock_inputs_ref() { + // Prepare VerifierPayloadRef + let tau = FrRef::from_str( + "2730322210350266333305929438402339624225511456370264338590718619370571", + ) + .unwrap(); + let delta = FrRef::from_str( + "1668197219006303135911300995268563595632072044933469744573172589503162", + ) + .unwrap(); + let epsilon = FrRef::from_str( + "180534986784443382108991383036395393569817197959638310564367496650276", + ) + .unwrap(); + let commit_p = AffinePointRef { + x: [ + 243, 1, 124, 124, 28, 184, 224, 34, 217, 222, 182, 31, 42, 252, 194, 222, 40, 36, + 80, 223, 106, 184, 193, 142, 55, 102, 25, 112, 7, 0, + ], + s: [ + 229, 76, 122, 168, 191, 162, 130, 195, 248, 229, 89, 69, 135, 106, 178, 161, 172, + 29, 249, 224, 109, 160, 41, 54, 63, 164, 235, 10, 145, 1, + ], }; - - let rpin = PublicInputsRef { - public_inputs: [ - FrRef::from_str( - "9487159538405616582219466419827834782293111327936747259752845028149", - ) - .unwrap(), - FrRef::from_str( - "22596372664815072823112258091854569627353949811861389086305200952659", - ) - .unwrap(), + let kzg_k = AffinePointRef { + x: [ + 240, 171, 68, 224, 177, 62, 73, 178, 215, 175, 231, 231, 151, 89, 104, 111, 7, 40, + 91, 33, 151, 83, 118, 199, 88, 68, 165, 164, 151, 1, + ], + s: [ + 182, 120, 142, 188, 144, 198, 242, 204, 84, 254, 121, 254, 72, 190, 109, 99, 198, + 59, 168, 17, 124, 224, 37, 14, 69, 114, 133, 198, 2, 1, ], }; + let a0 = FrRef::from_str( + "1132675792798759308127577893315934115126328231089219585842855711650311", + ) + .unwrap(); + let b0 = FrRef::from_str( + "3028379641311591322528948616897330931030750894712035609973261306086667", + ) + .unwrap(); + + let x1 = + (FrRef::from_str("8201062243878067778315015938357284675413750549").unwrap(), false); + let x2 = + (FrRef::from_str("12188555815513519027948129212942953563582264060").unwrap(), true); + let z = (FrRef::from_str("2328416288857173011062977552890912854869626082").unwrap(), true); + + let public_inputs = [FrRef::from_str("24").unwrap(), FrRef::from_str("13").unwrap()]; + let proof = ProofRef { commit_p, kzg_k, a0, b0, x1, x2, z }; + let secrets = TrapdoorRef { tau, delta, epsilon }; + let rpin = PublicInputsRef { public_inputs }; let passed = verify(proof, rpin, secrets); assert!(passed); } #[test] - fn test_invalid_proof_over_mock_inputs() { - let secrets = { - let tau = FrRef::from_str( - "490782060457092443021184404188169115419401325819878347174959236155604", - ) - .unwrap(); - let delta = FrRef::from_str( - "409859792668509615016679153954612494269657711226760893245268993658466", - ) - .unwrap(); - let epsilon = FrRef::from_str( - "1880039972651592580549544494658966441531834740391411845954153637005104", - ) - .unwrap(); - TrapdoorRef { tau, delta, epsilon } - }; - - let proof = ProofRef { - commit_p: AffinePointRef { - x: [ - 130, 16, 132, 245, 115, 118, 110, 233, 235, 58, 5, 190, 187, 230, 138, 225, - 149, 231, 32, 45, 41, 29, 94, 89, 248, 158, 54, 19, 86, 0, - ], - s: [ - 93, 74, 178, 168, 173, 38, 101, 88, 181, 49, 78, 207, 89, 78, 130, 42, 242, - 245, 88, 5, 253, 250, 54, 182, 177, 249, 82, 57, 147, 0, - ], - }, - kzg_k: AffinePointRef { - x: [ - 36, 69, 122, 22, 89, 79, 186, 56, 138, 8, 183, 193, 186, 98, 21, 62, 9, 143, - 173, 24, 89, 195, 126, 73, 241, 118, 71, 103, 223, 0, - ], - s: [ - 12, 122, 106, 168, 104, 248, 117, 18, 171, 218, 85, 138, 31, 80, 250, 230, 176, - 136, 74, 129, 137, 78, 181, 48, 88, 180, 21, 139, 39, 1, - ], - }, - a0: FrRef::from_str( - "1858232303623355521215721639157430371979542022979851183514844283900649", - ) - .unwrap(), - b0: FrRef::from_str( - "3045644831070136055562137919853497607898653327126781771795842528553732", - ) - .unwrap(), + fn test_invalid_proof_over_mock_inputs_ref() { + // Prepare VerifierPayloadRef + let tau = FrRef::from_str( + "2730322210350266333305929438402339624225511456370264338590718619370571", + ) + .unwrap(); + let delta = FrRef::from_str( + "1668197219006303135911300995268563595632072044933469744573172589503162", + ) + .unwrap(); + let epsilon = FrRef::from_str( + "180534986784443382108991383036395393569817197959638310564367496650276", + ) + .unwrap(); + let commit_p = AffinePointRef { + x: [ + 243, 1, 124, 124, 28, 184, 224, 34, 217, 222, 182, 31, 42, 252, 194, 222, 40, 36, + 80, 223, 106, 184, 193, 142, 55, 102, 25, 112, 7, 0, + ], + s: [ + 229, 76, 122, 168, 191, 162, 130, 195, 248, 229, 89, 69, 135, 106, 178, 161, 172, + 29, 249, 224, 109, 160, 41, 54, 63, 164, 235, 10, 145, 1, + ], }; - - let rpin = PublicInputsRef { - public_inputs: [ - FrRef::from_str( - "20964902444291521893664765711676021715483874668026528518811070427510", - ) - .unwrap(), - FrRef::from_str( - "22596372664815072823112258091854569627353949811861389086305200952659", - ) - .unwrap(), + let kzg_k = AffinePointRef { + x: [ + 240, 171, 68, 224, 177, 62, 73, 178, 215, 175, 231, 231, 151, 89, 104, 111, 7, 40, + 91, 33, 151, 83, 118, 199, 88, 68, 165, 164, 151, 1, + ], + s: [ + 182, 120, 142, 188, 144, 198, 242, 204, 84, 254, 121, 254, 72, 190, 109, 99, 198, + 59, 168, 17, 124, 224, 37, 14, 69, 114, 133, 198, 2, 1, ], }; + let a0 = FrRef::from_str( + "1132675792798759308127577893315934115126328231089219585842855711650311", + ) + .unwrap(); + let b0 = FrRef::from_str( + "3028379641311591322528948616897330931030750894712035609973261306086667", + ) + .unwrap(); + + let x1 = + (FrRef::from_str("8201062243878067778315015938357284675413750549").unwrap(), false); + let x2 = + (FrRef::from_str("12188555815513519027948129212942953563582264060").unwrap(), true); + let z = (FrRef::from_str("2328416288857173011062977552890912854869626082").unwrap(), true); + + let public_inputs = [FrRef::from_str("25").unwrap(), FrRef::from_str("13").unwrap()]; + + let proof = ProofRef { commit_p, kzg_k, a0, b0, x1, x2, z }; + let secrets = TrapdoorRef { tau, delta, epsilon }; + let rpin = PublicInputsRef { public_inputs }; let passed = verify(proof, rpin, secrets); assert!(!passed); } diff --git a/garbled-snark-verifier/src/circuits/sect233k1/fr_ckt.rs b/garbled-snark-verifier/src/circuits/sect233k1/fr_ckt.rs index 06793d6..456dd4a 100644 --- a/garbled-snark-verifier/src/circuits/sect233k1/fr_ckt.rs +++ b/garbled-snark-verifier/src/circuits/sect233k1/fr_ckt.rs @@ -4,7 +4,7 @@ use super::builder::CircuitTrait; pub(crate) const FR_LEN: usize = 232; -pub(crate) type Fr = [usize; FR_LEN]; +pub type Fr = [usize; FR_LEN]; const REDUCTION_SPLIT: usize = 231; // 2^231 limb boundary const THRESH: usize = 32; @@ -341,6 +341,12 @@ pub(crate) fn const_mod_n(b: &mut T) -> Vec { out } +// little-endian bit vector of the 2^156 +pub(crate) fn two_to_156(b: &mut T) -> Vec { + let mut out = vec![b.zero(); FR_LEN]; + out[156] = b.one(); + out +} pub(crate) fn emit_reduce_pseudo_mersenne( b: &mut T, prod: &[usize], @@ -443,6 +449,14 @@ pub(crate) fn emit_fr_sub(bld: &mut T, a: &Fr, b: &Fr) -> Fr { res } +pub(crate) fn emit_neg_fr_with_selector(bld: &mut T, a: &Fr, neg: usize) -> Fr { + let fr_zero = Fr::from([bld.zero(); FR_LEN]); + let neg_a = emit_fr_sub(bld, &fr_zero, a); + let res = mux_vec(bld, neg, &neg_a, a); + assert_eq!(res.len(), FR_LEN); + let res: Fr = res.try_into().unwrap(); + res +} #[cfg(test)] mod tests { use super::super::{builder::CircuitAdapter, fr_ref::frref_to_bits}; @@ -544,4 +558,109 @@ mod tests { assert_eq!(c_bits_calc, frref_to_bits(&ref_r)); } } + + #[test] + fn test_neg_fr_with_selector() { + let a_be_bytes = vec![ + 0, 0, 0, 112, 122, 134, 9, 72, 42, 50, 80, 245, 101, 17, 165, 12, 108, 176, 165, 95, + 152, 65, 135, 42, 147, 166, 230, 198, 50, 28, 173, 159, + ]; + let a_w = BigUint::from_bytes_be(&a_be_bytes); + let expected_neg_a_be_bytes = vec![ + 0, 0, 0, 15, 133, 121, 246, 183, 213, 205, 175, 10, 154, 238, 90, 243, 147, 85, 247, + 252, 32, 212, 53, 169, 219, 84, 52, 15, 191, 86, 254, 64, + ]; + + let mut bld = CircuitAdapter::default(); + let a: Fr = bld.fresh(); + let neg: usize = bld.fresh_one(); + let neg = emit_neg_fr_with_selector(&mut bld, &a, neg); + let stats = bld.gate_counts(); + println!("{stats}"); + + let mut witness = Vec::::new(); + let awitness = frref_to_bits(&a_w); + witness.extend_from_slice(&awitness); + witness.push(true); // neg selector + + let wires = bld.eval_gates(&witness); + let neg_a_bits: [bool; FR_LEN] = neg.map(|id| wires[id]); + let neg_a_w = BigUint::from_bytes_be(&expected_neg_a_be_bytes); + assert_eq!(neg_a_bits, frref_to_bits(&neg_a_w)); + } + + #[test] + fn test_fr_decompose_mod() { + // test k1 = x1/z mod r and k2 = x2/z mod r + let k1_be_bytes = vec![ + 0, 0, 0, 51, 96, 176, 10, 90, 39, 174, 104, 4, 29, 148, 187, 28, 109, 98, 171, 127, + 230, 48, 143, 66, 84, 143, 149, 177, 187, 210, 141, 20, + ]; + let k2_be_bytes = vec![ + 0, 0, 0, 26, 108, 65, 9, 244, 48, 225, 36, 47, 208, 219, 69, 144, 176, 74, 146, 191, + 44, 28, 58, 190, 137, 175, 120, 202, 225, 15, 139, 63, + ]; + let x1_be_bytes = vec![ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 131, 96, 158, 213, 110, 156, 186, 202, 3, 203, + 165, 199, 221, 172, 156, 232, 214, 228, 39, + ]; + let x2_be_bytes = vec![ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 174, 223, 194, 147, 141, 52, 233, 166, 56, 189, + 163, 209, 209, 141, 210, 79, 165, 145, 131, + ]; + let z_be_bytes = vec![ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 100, 192, 131, 198, 143, 204, 6, 70, 212, 104, + 61, 59, 3, 251, 190, 41, 255, 150, 205, + ]; + let x1 = BigUint::from_bytes_be(&x1_be_bytes); + let x2 = BigUint::from_bytes_be(&x2_be_bytes); + let z = BigUint::from_bytes_be(&z_be_bytes); + let k1 = BigUint::from_bytes_be(&k1_be_bytes); + let k2 = BigUint::from_bytes_be(&k2_be_bytes); + let x1_neg_w = false; + let x2_neg_w = true; + let z_neg_w = false; + + let mut bld = CircuitAdapter::default(); + let k1_fr: Fr = bld.fresh(); + let k2_fr: Fr = bld.fresh(); + let x1_fr: Fr = bld.fresh(); + let x1_neg = bld.fresh_one(); + let x2_fr: Fr = bld.fresh(); + let x2_neg = bld.fresh_one(); + let z_fr: Fr = bld.fresh(); + let z_neg = bld.fresh_one(); + let new_x1 = emit_neg_fr_with_selector(&mut bld, &x1_fr, x1_neg); + let new_x2 = emit_neg_fr_with_selector(&mut bld, &x2_fr, x2_neg); + let new_z = emit_neg_fr_with_selector(&mut bld, &z_fr, z_neg); + let k1z = emit_fr_mul(&mut bld, &k1_fr, &new_z); + let diff1 = emit_fr_sub(&mut bld, &k1z, &new_x1); + let k2z = emit_fr_mul(&mut bld, &k2_fr, &new_z); + let diff2 = emit_fr_sub(&mut bld, &k2z, &new_x2); + let stats = bld.gate_counts(); + println!("{stats}"); + + let mut witness = Vec::::new(); + let k1witness = frref_to_bits(&k1); + let k2witness = frref_to_bits(&k2); + let x1witness = frref_to_bits(&x1); + let x2witness = frref_to_bits(&x2); + let zwitness = frref_to_bits(&z); + + witness.extend_from_slice(&k1witness); + witness.extend_from_slice(&k2witness); + witness.extend_from_slice(&x1witness); + witness.push(x1_neg_w); + witness.extend_from_slice(&x2witness); + witness.push(x2_neg_w); + witness.extend_from_slice(&zwitness); + witness.push(z_neg_w); + + let wires = bld.eval_gates(&witness); + let diff1_bits: [bool; FR_LEN] = diff1.map(|id| wires[id]); + let diff2_bits: [bool; FR_LEN] = diff2.map(|id| wires[id]); + let zero = [false; FR_LEN]; + assert_eq!(diff1_bits, zero); + assert_eq!(diff2_bits, zero); + } } diff --git a/garbled-snark-verifier/src/circuits/sect233k1/fr_ref.rs b/garbled-snark-verifier/src/circuits/sect233k1/fr_ref.rs index a81e93b..cd89d8c 100644 --- a/garbled-snark-verifier/src/circuits/sect233k1/fr_ref.rs +++ b/garbled-snark-verifier/src/circuits/sect233k1/fr_ref.rs @@ -4,7 +4,7 @@ use super::fr_ckt::FR_LEN; pub(crate) type FrRef = BigUint; -pub(crate) fn frref_to_bits(n: &FrRef) -> [bool; FR_LEN] { +pub fn frref_to_bits(n: &FrRef) -> [bool; FR_LEN] { let bytes = n.to_bytes_le(); let mut bits = [false; FR_LEN]; for i in 0..FR_LEN { diff --git a/garbled-snark-verifier/src/circuits/sect233k1/types.rs b/garbled-snark-verifier/src/circuits/sect233k1/types.rs index c7019db..f40afc7 100644 --- a/garbled-snark-verifier/src/circuits/sect233k1/types.rs +++ b/garbled-snark-verifier/src/circuits/sect233k1/types.rs @@ -39,6 +39,9 @@ pub(crate) struct RawProof { pub kzg_k: AffinePointRef, pub a0: FrBits, pub b0: FrBits, + pub x1: (FrBits, bool), + pub x2: (FrBits, bool), + pub z: (FrBits, bool), } impl Into for RawProof { @@ -61,6 +64,9 @@ impl Into for RawProof { kzg_k: self.kzg_k, a0: fr_from_bits_le(&self.a0.0), b0: fr_from_bits_le(&self.b0.0), + x1: (fr_from_bits_le(&self.x1.0.0), self.x1.1), + x2: (fr_from_bits_le(&self.x2.0.0), self.x2.1), + z: (fr_from_bits_le(&self.z.0.0), self.z.1), } } } diff --git a/garbled-snark-verifier/src/core/s.rs b/garbled-snark-verifier/src/core/s.rs index c48d2e9..d2a0251 100644 --- a/garbled-snark-verifier/src/core/s.rs +++ b/garbled-snark-verifier/src/core/s.rs @@ -6,7 +6,8 @@ use serde::{Deserialize, Serialize}; use crate::circuits::bn254::utils::random_seed; use crate::core::utils::{LABEL_SIZE, hash}; -#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize, Default)] +#[repr(C)] +#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize, Default, Eq, Hash)] pub struct S(pub [u8; LABEL_SIZE]); impl S { diff --git a/garbled-snark-verifier/src/core/utils.rs b/garbled-snark-verifier/src/core/utils.rs index b9b9294..9a513ce 100644 --- a/garbled-snark-verifier/src/core/utils.rs +++ b/garbled-snark-verifier/src/core/utils.rs @@ -1,4 +1,4 @@ -use std::{cell::RefCell, rc::Rc, sync::atomic::AtomicU32}; +use std::{cell::RefCell, rc::Rc, slice, sync::atomic::AtomicU32}; use serde::{Deserialize, Serialize}; @@ -9,6 +9,9 @@ use crate::{ use std::sync::atomic::Ordering; +pub const SUB_CIRCUIT_MAX_GATES: usize = 1_000_000; +pub const SUB_INPUT_GATES_PART_SIZE: usize = 200_000; +pub const SUB_INPUT_GATES_PARTS: usize = 5; pub const LABEL_SIZE: usize = 16; // FIXME: set up a private global difference pub static DELTA: S = S::one(); @@ -76,167 +79,100 @@ pub fn hash(input: &[u8]) -> [u8; LABEL_SIZE] { unsafe { *(output.as_ptr() as *const [u8; LABEL_SIZE]) } } -#[derive(Serialize, Deserialize, Default, Debug, Clone)] +#[repr(C)] +#[derive(Default, Debug, Clone, Copy, Serialize, Deserialize)] pub struct SerializableGate { - pub wire_a: Wire, - pub wire_b: Wire, - pub wire_c: Wire, - pub gate_type: GateType, + pub gate_type: u8, + pub wire_a_id: u32, + pub wire_b_id: u32, + pub wire_c_id: u32, pub gid: u32, } -#[derive(Default, Clone, Serialize, Deserialize)] -pub struct SerializableCircuit { - pub gates: Vec, // Must also be serializable - pub garblings: Vec>, +#[repr(C)] +#[derive(Clone, Debug)] +pub struct SerializableSubCircuitGates { + pub gates: [SerializableGate; N], } -impl From<&Circuit> for SerializableCircuit { - fn from(c: &Circuit) -> Self { - //let wires = c.0.iter().map(|w| w.borrow().clone()).collect(); - let gates = - c.1.iter() - .map(|w| SerializableGate { - wire_a: w.wire_a.borrow().clone(), - wire_b: w.wire_b.borrow().clone(), - wire_c: w.wire_c.borrow().clone(), - gate_type: w.gate_type, - gid: w.gid, - }) - .collect(); - Self { gates, garblings: Vec::new() } +pub fn serialize_to_bytes(s: &SerializableSubCircuitGates) -> Vec { + unsafe { + let ptr = s as *const SerializableSubCircuitGates as *const u8; + let bytes = slice::from_raw_parts(ptr, size_of::>()); + bytes.to_vec() } } -impl From<&SerializableCircuit> for Circuit { - fn from(sc: &SerializableCircuit) -> Self { - let mut wires = vec![]; - let gates = sc - .gates - .iter() - .map(|g| { - wires.push(Rc::new(RefCell::new(g.wire_a.clone()))); - wires.push(Rc::new(RefCell::new(g.wire_b.clone()))); - wires.push(Rc::new(RefCell::new(g.wire_c.clone()))); - Gate { - wire_a: wires[wires.len() - 3].clone(), - wire_b: wires[wires.len() - 2].clone(), - wire_c: wires[wires.len() - 1].clone(), - gate_type: g.gate_type, - gid: g.gid, - } - }) - .collect(); - Self(wires, gates) +pub fn deserialize_from_bytes(buf: &[u8]) -> SerializableSubCircuitGates { + assert!(buf.len() >= std::mem::size_of::>()); + unsafe { + let ptr = buf.as_ptr() as *const SerializableSubCircuitGates; + ptr.read_unaligned() } } -struct Reader<'a> { - buf: &'a [u8], - cursor: usize, -} - -impl<'a> Reader<'a> { - pub fn new(buf: &'a [u8]) -> Self { - Reader { buf, cursor: 0 } - } - - fn read_u8(&mut self) -> u8 { - let b = self.buf[self.cursor]; - self.cursor += 1; - b - } - - fn read_u32(&mut self) -> u32 { - let start = self.cursor; - let v = u32::from_le_bytes(self.buf[start..start + 4].try_into().unwrap()); - self.cursor += 4; - v - } - - fn read_u64(&mut self) -> u64 { - let start = self.cursor; - let v = u64::from_le_bytes(self.buf[start..start + 8].try_into().unwrap()); - self.cursor += 8; - v - } - - fn read_s(&mut self) -> S { - let mut arr = [0u8; LABEL_SIZE]; - arr.copy_from_slice(&self.buf[self.cursor..self.cursor + LABEL_SIZE]); - self.cursor += LABEL_SIZE; - S(arr) - } - fn read_option_s(&mut self) -> Option { - match self.read_u8() { - 0 => None, - 1 => Some(self.read_s()), - other => panic!("Invalid Option tag: {}", other), - } - } +#[repr(C)] +#[derive(Default, Clone, Debug, Serialize, Deserialize)] +pub struct SerializableWire { + pub label: S, + pub value: Option, +} - fn skip_option_bool(&mut self) { - if self.read_u8() != 0 { - self.cursor += 1; - } - } +#[repr(C)] +#[derive(Default, Clone, Debug, Serialize, Deserialize)] +pub struct SerializableSubWires { + pub labels: Vec, + pub value: Vec>, +} - fn skip_wire(&mut self) { - // Option - if self.read_u8() != 0 { - self.cursor += LABEL_SIZE; +impl SerializableSubWires { + pub fn from_serialzable_wires(wires: &[SerializableWire]) -> Self { + let mut labels = vec![S::one(); wires.len()]; + let mut value = vec![None; wires.len()]; + for i in 0..wires.len() { + labels[i] = wires[i].label; + value[i] = wires[i].value; } - // Option - self.skip_option_bool(); - } - - fn read_gate_type(&mut self) -> GateType { - let d = self.read_u32(); - GateType::try_from(d as u8).expect("Invalid GateType") + SerializableSubWires { labels, value } } } -pub fn check_guest(buf: &[u8]) { - let mut reader = Reader::new(buf); - - // 1. Read the number of gates from the start of the buffer. - // bincode serializes Vec length as a u64. - let num_gates = reader.read_u64() as usize; - - // 2. Create a vector to store the computed garblings. - let mut computed_garblings = Vec::with_capacity(num_gates); - - // 3. Loop through each gate's data in the stream. - for _ in 0..num_gates { - // For wire_a, read the label and correctly skip the rest of the wire. - let a0 = reader.read_option_s().expect("Missing wire_a label"); - reader.skip_option_bool(); - - // For wire_b, read the label and correctly skip the rest of the wire. - let b0 = reader.read_option_s().expect("Missing wire_b label"); - reader.skip_option_bool(); - - // Skip wire_c entirely. - reader.skip_wire(); - - // Read gate_type and gid. - let gate_type = reader.read_gate_type(); - let gid = reader.read_u32(); - - // Immediately compute the garbling. - let (_, ciphertext) = gate_garbled(a0, b0, gid, gate_type); - computed_garblings.push(ciphertext); - } - - // 4. At this point, the reader is at the start of the serialized `garblings` Vec. - // Read the number of expected garblings. - let num_garblings = reader.read_u64() as usize; - assert_eq!(num_gates, num_garblings, "Mismatch in number of garblings"); - - // 5. Compare computed garblings with expected garblings from the stream. - for i in 0..num_garblings { - let expected_garbling = reader.read_option_s(); - assert_eq!(computed_garblings[i], expected_garbling, "Garbling mismatch at index {}", i); +pub fn check_guest( + sub_gates_parts: &[Vec; SUB_INPUT_GATES_PARTS], + sub_wires: &[u8], + sub_ciphertexts: &[u8], +) -> Vec { + // read sub_ciphertexts: + let mut c_start = 0; + let num_ciphertexts = u64::from_le_bytes(sub_ciphertexts[c_start..c_start + 8].try_into().unwrap()); + c_start += 8; + + // create input for ciphertext check syscall + let mut input = Vec::new(); + let mut index = 0; + for part in 0..SUB_INPUT_GATES_PARTS { + let sub_gates: SerializableSubCircuitGates = deserialize_from_bytes(&sub_gates_parts[part]); + for i in 0..sub_gates.gates.len() { + if sub_gates.gates[i].gate_type == 0 { // and gate + let gate = &sub_gates.gates[i]; + let base = 8usize; + let start_a0 = base + (gate.wire_a_id as usize) * LABEL_SIZE; + let start_b0 = base + (gate.wire_b_id as usize) * LABEL_SIZE; + let a0 = S(sub_wires[start_a0..start_a0 + LABEL_SIZE].try_into().unwrap()); + let gid = gate.gid; + let a1 = a0 ^ DELTA; + let h0 = a0.hash_ext(gid); + let h1 = a1.hash_ext(gid); + input.extend_from_slice(&h0.0); + input.extend_from_slice(&h1.0); + input.extend_from_slice(&sub_wires[start_b0..start_b0 + LABEL_SIZE]); + input.extend_from_slice(&sub_ciphertexts[c_start..c_start + LABEL_SIZE]); + index += 1; + c_start += LABEL_SIZE; + } + } } + assert_eq!(index, num_ciphertexts); + input } diff --git a/garbled-snark-verifier/src/core/wire.rs b/garbled-snark-verifier/src/core/wire.rs index 1eeeacb..067837a 100644 --- a/garbled-snark-verifier/src/core/wire.rs +++ b/garbled-snark-verifier/src/core/wire.rs @@ -8,24 +8,27 @@ pub struct Wire { pub label: Option, // evaluate pub value: Option, + // id in sub-circuit wire list. + // should be removed in case of not using sub-circuits + pub id: Option, } impl Default for Wire { fn default() -> Self { - Self::new() + Self::new(None) } } impl Wire { #[cfg(feature = "garbled")] - pub fn new() -> Self { + pub fn new(id: Option) -> Self { let label = Some(S::random()); - Self { label, value: None } + Self { label, value: None, id } } #[cfg(not(feature = "garbled"))] - pub fn new() -> Self { - Self { label: None, value: None } + pub fn new(id: Option) -> Self { + Self { label: None, value: None, id } } pub fn select(&self, selector: bool) -> S { diff --git a/garbled-snark-verifier/src/lib.rs b/garbled-snark-verifier/src/lib.rs index 6908bff..af71a13 100644 --- a/garbled-snark-verifier/src/lib.rs +++ b/garbled-snark-verifier/src/lib.rs @@ -11,6 +11,9 @@ pub mod bag { pub type Wires = Vec; pub use crate::core::gate::GateCount; pub fn new_wirex() -> Wirex { - Rc::new(RefCell::new(Wire::new())) + Rc::new(RefCell::new(Wire::new(None))) + } + pub fn new_wirex_with_id(id: u32) -> Wirex { + Rc::new(RefCell::new(Wire::new(Some(id)))) } } diff --git a/verifiable-circuit-host/Cargo.toml b/verifiable-circuit-host/Cargo.toml index 5fa10ad..0a617a9 100644 --- a/verifiable-circuit-host/Cargo.toml +++ b/verifiable-circuit-host/Cargo.toml @@ -23,6 +23,7 @@ ark-crypto-primitives = "0.5.0" ark-relations = "0.5.0" ark-ec = "0.5.0" ark-serialize = { version = "0.5.0", default-features = false, features = ["derive"] } +indexmap = "2.12.0" [build-dependencies] zkm-build = { workspace = true } @@ -35,5 +36,9 @@ path = "src/main.rs" name = "dv-snark" path = "src/dv_snark.rs" +[[bin]] +name = "simple-circuit" +path = "src/simple_circuit.rs" + # [features] # cuda = ["zkm-sdk/cuda"] \ No newline at end of file diff --git a/verifiable-circuit-host/src/data/dv-proof b/verifiable-circuit-host/src/data/dv-proof index 2fdb8c3..0ba1cd3 100644 Binary files a/verifiable-circuit-host/src/data/dv-proof and b/verifiable-circuit-host/src/data/dv-proof differ diff --git a/verifiable-circuit-host/src/data/public_inputs.bin b/verifiable-circuit-host/src/data/public_inputs.bin index b57036d..2f0c702 100644 Binary files a/verifiable-circuit-host/src/data/public_inputs.bin and b/verifiable-circuit-host/src/data/public_inputs.bin differ diff --git a/verifiable-circuit-host/src/data/trapdoor.bin b/verifiable-circuit-host/src/data/trapdoor.bin index 2e2354a..6ce2c53 100644 --- a/verifiable-circuit-host/src/data/trapdoor.bin +++ b/verifiable-circuit-host/src/data/trapdoor.bin @@ -1 +1 @@ -Ԉ?7Z\XOA4bN4o#uA"ڋ p'30ǸD$/sPZ Ǹ([j \ No newline at end of file +KDu6>:w_m٢EeU!MvvÅdB z=$ F=oD1"s$E>H \ No newline at end of file diff --git a/verifiable-circuit-host/src/dv_snark.rs b/verifiable-circuit-host/src/dv_snark.rs index 467b561..47d1061 100644 --- a/verifiable-circuit-host/src/dv_snark.rs +++ b/verifiable-circuit-host/src/dv_snark.rs @@ -5,6 +5,7 @@ use zkm_sdk::{ProverClient, ZKMProofWithPublicValues, ZKMStdin, include_elf, uti use garbled_snark_verifier::circuits::dv_snark::dv_snark_verifier_circuit; use garbled_snark_verifier::{bag::Circuit, circuits::sect233k1::types::load_witness_from_files}; +use crate::utils::{SUB_CIRCUIT_MAX_GATES, SUB_INPUT_GATES_PARTS}; mod mem_fs; mod utils; @@ -29,8 +30,8 @@ fn custom_dv_snark_circuit() -> Circuit { for gate in &mut circuit.1 { gate.evaluate(); } - assert!(circuit.0[0].borrow().get_value()); - + // assert!(circuit.0.last().borrow().get_value()); + println!("circuit output: {:?}", circuit.0.last().unwrap().borrow().get_value()); let elapsed = start.elapsed(); info!(step = "Eval circuit", elapsed = ?elapsed); @@ -41,7 +42,7 @@ fn split_circuit() { let mut circuit = custom_dv_snark_circuit(); circuit.gate_counts().print(); println!("Wires: {}", circuit.0.len()); - utils::gen_sub_circuits(&mut circuit, 1_000_000); + utils::gen_sub_circuits(&mut circuit, SUB_CIRCUIT_MAX_GATES); } fn main() { @@ -59,19 +60,40 @@ fn main() { // types of the elements in the input stream must match the types being read in the guest. let mut stdin = ZKMStdin::new(); - // let ser_sc_0 = std::fs::read("garbled_0.bin").unwrap(); - let ser_sc_0 = mem_fs::MemFile::read("garbled_0.bin").unwrap(); - info!("ser_sc_0 size: {:?} bytes", ser_sc_0.len()); + let mut sub_gates: [Vec; SUB_INPUT_GATES_PARTS] = + std::array::from_fn(|_| Vec::new()); + for part in 0..SUB_INPUT_GATES_PARTS { + sub_gates[part] = mem_fs::MemFile::read(format!("msm_garbled_gates_{}.bin", part)).unwrap(); + // sub_gates = std::fs::read(format!("msm_garbled_gates_{}.bin", part)).unwrap(); + info!("sub_gates part {} size: {:?} bytes", part, sub_gates[part].len()); + } + let sub_wires = mem_fs::MemFile::read("msm_garbled_wires.bin").unwrap(); + // let sub_wires = std::fs::read("msm_garbled_wires.bin").unwrap(); + info!("sub_wires size: {:?} bytes", sub_wires.len()); + + let sub_ciphertexts = mem_fs::MemFile::read("msm_garbled_ciphertexts.bin").unwrap(); + // let sub_ciphertexts = std::fs::read("msm_garbled_ciphertexts.bin").unwrap(); + info!("sub_ciphertexts size: {:?} bytes", sub_ciphertexts.len()); // Write the read sub-circuit to a file for inspection or later use. - std::fs::write("garbled_0.bin", &ser_sc_0) - .expect("Failed to write sub-circuit to garbled_0.bin"); - info!("Saved sub-circuit to garbled_0.bin"); + for part in 0..SUB_INPUT_GATES_PARTS { + std::fs::write(format!("msm_garbled_gates_{}.bin", part), &sub_gates[part]) + .expect("Failed to write sub-gate to msm_garbled_gates.bin"); + } + std::fs::write("msm_garbled_wires.bin", &sub_wires) + .expect("Failed to write sub-wires to msm_garbled_wires.bin"); + std::fs::write("msm_garbled_ciphertexts.bin", &sub_ciphertexts) + .expect("Failed to write sub-ciphertexts to msm_garbled_ciphertexts.bin"); + info!("Saved sub-circuit to file"); // info!("Check guest"); // garbled_snark_verifier::core::utils::check_guest(&ser_sc_0); - stdin.write_vec(ser_sc_0); + for i in 0..SUB_INPUT_GATES_PARTS { + stdin.write_vec(sub_gates[i].clone()); + } + stdin.write_vec(sub_wires); + stdin.write_vec(sub_ciphertexts); // Create a `ProverClient` method. let client = ProverClient::new(); diff --git a/verifiable-circuit-host/src/main.rs b/verifiable-circuit-host/src/main.rs index cc76774..d2e344d 100644 --- a/verifiable-circuit-host/src/main.rs +++ b/verifiable-circuit-host/src/main.rs @@ -8,7 +8,7 @@ use ark_std::{UniformRand, test_rng}; use garbled_snark_verifier::{ bag::{Circuit, new_wirex}, circuits::bn254::{fq2::Fq2, g2::G2Affine, pairing::deserialize_compressed_g2_circuit}, - core::utils::{SerializableCircuit, SerializableGate}, + core::utils::SerializableGate, }; use rand::{RngCore, SeedableRng}; use rand_chacha::ChaCha12Rng; @@ -24,6 +24,8 @@ use zkm_sdk::{ProverClient, ZKMProofWithPublicValues, ZKMStdin, include_elf, uti mod dummy_circuit; use crate::dummy_circuit::DummyCircuit; +use crate::utils::{SUB_CIRCUIT_MAX_GATES, SUB_INPUT_GATES_PARTS}; + mod mem_fs; mod utils; @@ -93,7 +95,7 @@ fn split_circuit() { let mut circuit = custom_groth16_verifier_circuit(); circuit.gate_counts().print(); println!("Wires: {}", circuit.0.len()); - utils::gen_sub_circuits(&mut circuit, 7_000_000); + utils::gen_sub_circuits(&mut circuit, SUB_CIRCUIT_MAX_GATES); } fn main() { @@ -111,14 +113,41 @@ fn main() { // types of the elements in the input stream must match the types being read in the guest. let mut stdin = ZKMStdin::new(); - //let ser_sc_0 = std::fs::read("garbled_0.bin").unwrap(); - let ser_sc_0 = mem_fs::MemFile::read("garbled_0.bin").unwrap(); - info!("ser_sc_0 size: {:?} bytes", ser_sc_0.len()); + let mut sub_gates: [Vec; SUB_INPUT_GATES_PARTS] = + std::array::from_fn(|_| Vec::new()); + + for part in 0..SUB_INPUT_GATES_PARTS { + sub_gates[part] = mem_fs::MemFile::read(format!("msm_garbled_gates_{}.bin", part)).unwrap(); + // sub_gates = std::fs::read(format!("garbled_gates_{}.bin", part)).unwrap(); + info!("sub_gates part {} size: {:?} bytes", part, sub_gates[part].len()); + } + let sub_wires = mem_fs::MemFile::read("msm_garbled_wires.bin").unwrap(); + // let sub_wires = std::fs::read("garbled_wires.bin").unwrap(); + info!("sub_wires size: {:?} bytes", sub_wires.len()); + + let sub_ciphertexts = mem_fs::MemFile::read("msm_garbled_ciphertexts.bin").unwrap(); + // let sub_ciphertexts = std::fs::read("garbled_ciphertexts.bin").unwrap(); + info!("sub_ciphertexts size: {:?} bytes", sub_ciphertexts.len()); + + // Write the read sub-circuit to a file for inspection or later use. + for part in 0..SUB_INPUT_GATES_PARTS { + std::fs::write(format!("msm_garbled_gates_{}.bin", part), &sub_gates[part]) + .expect("Failed to write sub-gate to msm_garbled_gates.bin"); + } + std::fs::write("msm_garbled_wires.bin", &sub_wires) + .expect("Failed to write sub-wires to msm_garbled_wires.bin"); + std::fs::write("msm_garbled_ciphertexts.bin", &sub_ciphertexts) + .expect("Failed to write sub-ciphertexts to msm_garbled_ciphertexts.bin"); + info!("Saved sub-circuit to file"); // info!("Check guest"); - // check_guest(&ser_sc_0); + // garbled_snark_verifier::core::utils::check_guest(&ser_sc_0); - stdin.write_vec(ser_sc_0); + for i in 0..SUB_INPUT_GATES_PARTS { + stdin.write_vec(sub_gates[i].clone()); + } + stdin.write_vec(sub_wires); + stdin.write_vec(sub_ciphertexts); // Create a `ProverClient` method. let client = ProverClient::new(); diff --git a/verifiable-circuit-host/src/simple_circuit.rs b/verifiable-circuit-host/src/simple_circuit.rs new file mode 100644 index 0000000..4ed62a6 --- /dev/null +++ b/verifiable-circuit-host/src/simple_circuit.rs @@ -0,0 +1,155 @@ +use std::time::Instant; +use num_bigint::BigUint; +use tracing::info; + +use zkm_sdk::{ProverClient, ZKMProofWithPublicValues, ZKMStdin, include_elf, utils as sdk_utils}; + +use garbled_snark_verifier::circuits::dv_snark::dv_snark_verifier_circuit; +use garbled_snark_verifier::{bag::Circuit, circuits::sect233k1::types::load_witness_from_files}; +use garbled_snark_verifier::circuits::bn254::fq2::Fq2; +use garbled_snark_verifier::circuits::sect233k1::builder::{CircuitAdapter, CircuitTrait}; +use garbled_snark_verifier::circuits::sect233k1::fr_ckt::Fr; +use garbled_snark_verifier::circuits::sect233k1::fr_ref::frref_to_bits; +use garbled_snark_verifier::core::utils::deserialize_from_bytes; +use crate::utils::{SUB_CIRCUIT_MAX_GATES, SUB_INPUT_GATES_PARTS}; + +mod mem_fs; +mod utils; + +/// The ELF we want to execute inside the zkVM. +const ELF: &[u8] = include_elf!("verifiable-circuit"); + +// this circuit receive 2 Fr numbers and a selector bit +// return the selected number +fn custom_simple_circuit() -> Circuit { + let mut bld = CircuitAdapter::default(); + const N: usize = 200; + let a: [usize; N] = bld.fresh(); + let b: [usize; N] = bld.fresh(); + let sel = bld.fresh_one(); + + let mut res = [bld.zero(); N]; + for i in 0..N { + let d = bld.xor_wire(a[i], b[i]); + let xd = bld.and_wire(sel, d); + res[i] = bld.xor_wire(xd, a[i]); + // res[i] = d; + } + + // witness + let k1_be_bytes = vec![ + 0, 0, 0, 51, 96, 176, 10, 90, 39, 174, 104, 4, 29, 148, 187, 28, 109, 98, 171, 127, + 230, 48, 143, 66, 84, 143, 149, 177, 187, 210, 141, 20, + ]; + let k2_be_bytes = vec![ + 0, 0, 0, 26, 108, 65, 9, 244, 48, 225, 36, 47, 208, 219, 69, 144, 176, 74, 146, 191, + 44, 28, 58, 190, 137, 175, 120, 202, 225, 15, 139, 63, + ]; + let k1 = BigUint::from_bytes_be(&k1_be_bytes); + let k2 = BigUint::from_bytes_be(&k2_be_bytes); + let k1witness = frref_to_bits(&k1); + let k2witness = frref_to_bits(&k2); + + let k1witness = k1witness[..N].to_vec(); + let k2witness = k2witness[..N].to_vec(); + + let mut witness = Vec::::new(); + witness.extend_from_slice(&k1witness); + witness.extend_from_slice(&k2witness); + // witness.push(true); // selector k2 + + let circuit = bld.build(&witness); + circuit +} + +fn split_circuit() { + let mut circuit = custom_simple_circuit(); + circuit.gate_counts().print(); + println!("Wires: {}", circuit.0.len()); + utils::gen_sub_circuits(&mut circuit, SUB_CIRCUIT_MAX_GATES); +} + +fn main() { + // Setup logging. + sdk_utils::setup_logger(); + + let start_total = Instant::now(); + + let start = Instant::now(); + split_circuit(); + let elapsed = start.elapsed(); + info!(elapsed = ?elapsed, "split circuit"); + + // The input stream that the guest will read from using `zkm_zkvm::io::read`. Note that the + // types of the elements in the input stream must match the types being read in the guest. + let mut stdin = ZKMStdin::new(); + + let mut sub_gates: [Vec; SUB_INPUT_GATES_PARTS] = + std::array::from_fn(|_| Vec::new()); + + for part in 0..SUB_INPUT_GATES_PARTS { + sub_gates[part] = mem_fs::MemFile::read(format!("msm_garbled_gates_{}.bin", part)).unwrap(); + // sub_gates = std::fs::read(format!("garbled_gates_{}.bin", part)).unwrap(); + info!("sub_gates part {} size: {:?} bytes", part, sub_gates[part].len()); + } + let sub_wires = mem_fs::MemFile::read("msm_garbled_wires.bin").unwrap(); + // let sub_wires = std::fs::read("garbled_wires.bin").unwrap(); + info!("sub_wires size: {:?} bytes", sub_wires.len()); + + let sub_ciphertexts = mem_fs::MemFile::read("msm_garbled_ciphertexts.bin").unwrap(); + // let sub_ciphertexts = std::fs::read("garbled_ciphertexts.bin").unwrap(); + info!("sub_ciphertexts size: {:?} bytes", sub_ciphertexts.len()); + + // Write the read sub-circuit to a file for inspection or later use. + for part in 0..SUB_INPUT_GATES_PARTS { + std::fs::write(format!("msm_garbled_gates_{}.bin", part), &sub_gates[part]) + .expect("Failed to write sub-gate to msm_garbled_gates.bin"); + } + std::fs::write("msm_garbled_wires.bin", &sub_wires) + .expect("Failed to write sub-wires to msm_garbled_wires.bin"); + std::fs::write("msm_garbled_ciphertexts.bin", &sub_ciphertexts) + .expect("Failed to write sub-ciphertexts to msm_garbled_ciphertexts.bin"); + info!("Saved sub-circuit to file"); + + // info!("Check guest"); + // garbled_snark_verifier::core::utils::check_guest(&ser_sc_0); + + for i in 0..SUB_INPUT_GATES_PARTS { + stdin.write_vec(sub_gates[i].clone()); + } + stdin.write_vec(sub_wires); + stdin.write_vec(sub_ciphertexts); + + // Create a `ProverClient` method. + let client = ProverClient::new(); + + let start = Instant::now(); + // Execute the guest using the `ProverClient.execute` method, without generating a proof. + let (_public_values, report) = client.execute(ELF, stdin.clone()).run().unwrap(); + + let elapsed = start.elapsed(); + info!(elapsed = ?elapsed, "executed program with {} cycles", report.total_instruction_count()); + + let start = Instant::now(); + // Generate the proof for the given guest and input. + let (pk, vk) = client.setup(ELF); + let proof = client.prove(&pk, stdin).run().unwrap(); + + let elapsed = start.elapsed(); + info!(step = "generated proof", elapsed =? elapsed, "finish proof generation"); + + // Verify proof and public values + client.verify(&proof, &vk).expect("verification failed"); + // + // // Test a round trip of proof serialization and deserialization. + // proof.save("proof-with-pis.bin").expect("saving proof failed"); + // let deserialized_proof = + // ZKMProofWithPublicValues::load("proof-with-pis.bin").expect("loading proof failed"); + // + // // Verify the deserialized proof. + // client.verify(&deserialized_proof, &vk).expect("verification failed"); + // + // info!("successfully generated and verified proof for the program!"); + // let total_elapsed = start_total.elapsed(); + // info!(elapsed = ?total_elapsed, "total time"); +} diff --git a/verifiable-circuit-host/src/utils.rs b/verifiable-circuit-host/src/utils.rs index a60ffa7..4664c12 100644 --- a/verifiable-circuit-host/src/utils.rs +++ b/verifiable-circuit-host/src/utils.rs @@ -1,8 +1,16 @@ +use std::collections::{HashMap, HashSet}; +use std::io::Write; use crate::mem_fs; -use garbled_snark_verifier::bag::Circuit; -use garbled_snark_verifier::core::utils::{SerializableCircuit, SerializableGate}; +use garbled_snark_verifier::bag::{Circuit, Wire}; +use garbled_snark_verifier::core::utils::{serialize_to_bytes, SerializableGate, SerializableSubCircuitGates, SerializableSubWires, SerializableWire}; use std::time::Instant; use tracing::info; +use indexmap::IndexMap; + +pub const SUB_CIRCUIT_MAX_GATES: usize = 1_000_000; +pub const SUB_INPUT_GATES_PART_SIZE: usize = 200_000; +pub const SUB_INPUT_GATES_PARTS: usize = 5; +pub const FINEST_RATIO_TARGET: usize = 503; // gates / non-free gates pub fn gen_sub_circuits(circuit: &mut Circuit, max_gates: usize) { let start = Instant::now(); @@ -13,36 +21,140 @@ pub fn gen_sub_circuits(circuit: &mut Circuit, max_gates: usize) { let size = circuit.1.len().div_ceil(max_gates); let start = Instant::now(); + let wires: Vec = circuit.0.iter().map(|w| w.borrow().clone()).collect(); + let mut finest = FINEST_RATIO_TARGET; + let mut finest_id = 0; + /// find the sub-circuit with the finest non-free gates ratio circuit.1.chunks(max_gates).enumerate().zip(garbled_gates.chunks_mut(max_gates)).for_each( |((i, w), garblings)| { info!(step = "gen_sub_circuits", "Split batch {i}/{size}"); - let out = SerializableCircuit { - gates: w + let ciphertexts: Vec<_> = garblings + .iter() + .filter_map(|g| g.as_ref().cloned()) + .collect(); + + /// compute non-free gates ratio + let non_free_gates = ciphertexts.len(); + if non_free_gates != 0 { + let ratio = SUB_CIRCUIT_MAX_GATES / non_free_gates; + let dif = { + if FINEST_RATIO_TARGET > ratio { + FINEST_RATIO_TARGET - ratio + } else { + ratio - FINEST_RATIO_TARGET + } + }; + if dif < finest { + finest = dif; + finest_id = i; + } + } + } + ); + info!("finest id: {}, finest dif: {}", finest_id, finest); + // dump subcircuit with the finest ratio + circuit.1.chunks(max_gates).enumerate().zip(garbled_gates.chunks_mut(max_gates)).for_each( + |((i, w), garblings)| { + if i == finest_id { + info!(step = "gen_sub_circuits", "Dumping finest batch {i}/{size}"); + let ciphertexts: Vec<_> = garblings .iter() - .map(|w| SerializableGate { - wire_a: w.wire_a.borrow().clone(), - wire_b: w.wire_b.borrow().clone(), - wire_c: w.wire_c.borrow().clone(), - gate_type: w.gate_type, - gid: w.gid, - }) - .collect(), - garblings: garblings.to_vec(), - }; - // In this demo, we only save the first sub-circuit - if i == 0 { + .filter_map(|g| g.as_ref().cloned()) + .collect(); + + // All of this should be removed. let start = Instant::now(); + let mut sub_wires_map: IndexMap = IndexMap::new(); + let mut next_sub_id = 0; + for gate in w { + let wire_a_id = gate.wire_a.borrow().id.unwrap(); + sub_wires_map.entry(wire_a_id).or_insert_with(|| { + let id = next_sub_id; + next_sub_id += 1; + id + }); + let wire_b_id = gate.wire_b.borrow().id.unwrap(); + sub_wires_map.entry(wire_b_id).or_insert_with(|| { + let id = next_sub_id; + next_sub_id += 1; + id + }); + let wire_c_id = gate.wire_c.borrow().id.unwrap(); + sub_wires_map.entry(wire_c_id).or_insert_with(|| { + let id = next_sub_id; + next_sub_id += 1; + id + }); + } + // Build the vector of sub wires + let serialziable_wires: Vec<_> = sub_wires_map + .keys() + .map(|&id| { + SerializableWire { + label: wires[id as usize].label.unwrap(), + value: wires[id as usize].value, + } + }) + .collect(); + + let sub_wires = SerializableSubWires::from_serialzable_wires(&serialziable_wires); + let elapsed = start.elapsed(); + info!(step = "gen_sub_wires ", elapsed = ?elapsed); + + let mut gates: Vec<_> = w.iter().map(|w| SerializableGate { + gate_type: w.gate_type as u8, + wire_a_id: *sub_wires_map.get(&w.wire_a.borrow().id.unwrap()).unwrap(), + wire_b_id: *sub_wires_map.get(&w.wire_b.borrow().id.unwrap()).unwrap(), + wire_c_id: *sub_wires_map.get(&w.wire_c.borrow().id.unwrap()).unwrap(), + gid: w.gid, + } + ).collect(); + let last_gate = gates.last().unwrap().clone(); + let dummy_gate = SerializableGate { + gate_type: 8, + wire_a_id: last_gate.wire_a_id, + wire_b_id: last_gate.wire_b_id, + wire_c_id: last_gate.wire_c_id, + gid: last_gate.gid, + }; + while gates.len() < SUB_CIRCUIT_MAX_GATES { + gates.push(dummy_gate.clone()); + } + + for part in 0..SUB_INPUT_GATES_PARTS { + let start = part * SUB_INPUT_GATES_PART_SIZE; + let end = start + SUB_INPUT_GATES_PART_SIZE; + let mut array_gates: [SerializableGate; SUB_INPUT_GATES_PART_SIZE] = [SerializableGate::default(); SUB_INPUT_GATES_PART_SIZE]; + array_gates.copy_from_slice(&gates[start..end]); + + let sub_gates: SerializableSubCircuitGates = SerializableSubCircuitGates { + gates: array_gates, + }; + + // serialize each sub-gate array to its own file + let bytes = serialize_to_bytes(&sub_gates); + let mut file = mem_fs::MemFile::create(format!("msm_garbled_gates_{}.bin", part)).unwrap(); + file.write_all(&bytes).unwrap(); + } + bincode::serialize_into( - //std::fs::File::create(format!("garbled_{i}.bin")).unwrap(), - mem_fs::MemFile::create(format!("garbled_{i}.bin")).unwrap(), - &out, + mem_fs::MemFile::create(format!("msm_garbled_wires.bin")).unwrap(), + &sub_wires, ) - .unwrap(); + .unwrap(); + + bincode::serialize_into( + mem_fs::MemFile::create(format!("msm_garbled_ciphertexts.bin")).unwrap(), + &ciphertexts, + ) + .unwrap(); + let elapsed = start.elapsed(); - info!(step = "gen_sub_circuits", elapsed = ?elapsed, "Writing garbled_{i}.bin"); + info!(step = "gen_sub_circuits", elapsed = ?elapsed, "Writing garbled_{i}"); } - }, + } ); + let elapsed = start.elapsed(); info!(step = "gen_sub_circuits", elapsed =? elapsed, "total time"); } diff --git a/verifiable-circuit/src/main.rs b/verifiable-circuit/src/main.rs index 48cb06b..536076d 100644 --- a/verifiable-circuit/src/main.rs +++ b/verifiable-circuit/src/main.rs @@ -10,8 +10,18 @@ extern crate alloc; zkm_zkvm::entrypoint!(main); -use garbled_snark_verifier::core::utils::check_guest; + +use alloc::vec::Vec; +use garbled_snark_verifier::core::utils::{check_guest, SUB_INPUT_GATES_PARTS}; +use zkm_zkvm::lib::ciphertext_check::ciphertext_check; fn main() { - let buf = zkm_zkvm::io::read_vec(); - check_guest(&buf); + let mut sub_gates: [Vec; SUB_INPUT_GATES_PARTS] = core::array::from_fn(|_| Vec::new()); + for i in 0..SUB_INPUT_GATES_PARTS { + sub_gates[i] = zkm_zkvm::io::read_vec(); + } + let sub_wires = zkm_zkvm::io::read_vec(); + let sub_ciphertexts = zkm_zkvm::io::read_vec(); + let input = check_guest(&sub_gates, &sub_wires, &sub_ciphertexts); + let output = ciphertext_check(&input); + assert!(output); }