From a8b277a94b9b036495e35eb2843ae9d2f2d4d7ae Mon Sep 17 00:00:00 2001 From: zhenfei Date: Tue, 20 Jun 2023 14:41:41 -0400 Subject: [PATCH] Documentations; subcircuit for aggregation (#13) * wip * [refactor] refactoring sdk * [refactor] halo2 api * [chore] update cargo.toml * [feat] impl sub-circuit for proof aggregation circuit * [feat] impl sub circuit for multi aggregation * [chore] clean up * [chore] update cargo branch --- Cargo.lock | 2053 +++++++++++++++-- Cargo.toml | 4 +- rustfmt.toml | 2 +- snark-verifier-sdk/Cargo.toml | 6 +- snark-verifier-sdk/benches/standard_plonk.rs | 5 +- snark-verifier-sdk/benches/zkevm.rs | 32 +- .../benches/zkevm_plus_state.rs | 24 +- snark-verifier-sdk/src/aggregation.rs | 131 ++ .../src/aggregation/aggregation_circuit.rs | 243 ++ snark-verifier-sdk/src/aggregation/config.rs | 96 + .../aggregation/multi_aggregation_circuit.rs | 199 ++ snark-verifier-sdk/src/circuit_ext.rs | 28 + snark-verifier-sdk/src/{evm.rs => evm_api.rs} | 16 +- snark-verifier-sdk/src/file_io.rs | 82 + snark-verifier-sdk/src/halo2/aggregation.rs | 522 ----- .../src/{halo2.rs => halo2_api.rs} | 181 +- snark-verifier-sdk/src/lib.rs | 254 +- snark-verifier-sdk/src/param.rs | 10 + snark-verifier-sdk/src/snark.rs | 66 + snark-verifier-sdk/src/snark/mock.rs | 108 + snark-verifier-sdk/src/tests/evm_verifier.rs | 14 +- snark-verifier-sdk/src/tests/mod.rs | 2 +- .../src/tests/single_layer_aggregation.rs | 19 +- .../src/tests/test_circuit_1.rs | 2 +- .../src/tests/test_circuit_2.rs | 2 +- .../src/tests/two_layer_aggregation.rs | 19 +- snark-verifier-sdk/src/types.rs | 52 + snark-verifier/Cargo.toml | 4 +- .../examples/evm-verifier-with-accumulator.rs | 42 +- snark-verifier/examples/evm-verifier.rs | 10 +- snark-verifier/examples/recursion.rs | 20 +- snark-verifier/src/lib.rs | 1 + snark-verifier/src/loader/evm/loader.rs | 4 +- snark-verifier/src/loader/evm/test/tui.rs | 4 +- snark-verifier/src/loader/halo2.rs | 3 +- snark-verifier/src/loader/halo2/loader.rs | 6 +- snark-verifier/src/loader/halo2/shim.rs | 22 +- snark-verifier/src/loader/halo2/test.rs | 2 +- snark-verifier/src/pcs/kzg/accumulator.rs | 2 +- snark-verifier/src/system/halo2.rs | 15 +- snark-verifier/src/system/halo2/test.rs | 25 +- .../src/system/halo2/test/circuit/standard.rs | 12 +- snark-verifier/src/system/halo2/test/kzg.rs | 25 +- .../src/system/halo2/test/kzg/evm.rs | 6 +- .../src/system/halo2/test/kzg/halo2.rs | 43 +- .../src/system/halo2/test/kzg/native.rs | 10 +- snark-verifier/src/system/halo2/transcript.rs | 6 +- .../src/system/halo2/transcript/evm.rs | 10 +- .../src/system/halo2/transcript/halo2.rs | 13 +- snark-verifier/src/util/hash.rs | 4 +- snark-verifier/src/util/hash/poseidon.rs | 4 +- snark-verifier/src/util/msm.rs | 4 +- snark-verifier/src/util/poly.rs | 4 +- snark-verifier/src/util/protocol.rs | 4 +- snark-verifier/src/util/transcript.rs | 3 +- snark-verifier/src/verifier/plonk.rs | 4 +- 56 files changed, 3181 insertions(+), 1303 deletions(-) create mode 100644 snark-verifier-sdk/src/aggregation.rs create mode 100644 snark-verifier-sdk/src/aggregation/aggregation_circuit.rs create mode 100644 snark-verifier-sdk/src/aggregation/config.rs create mode 100644 snark-verifier-sdk/src/aggregation/multi_aggregation_circuit.rs create mode 100644 snark-verifier-sdk/src/circuit_ext.rs rename snark-verifier-sdk/src/{evm.rs => evm_api.rs} (94%) create mode 100644 snark-verifier-sdk/src/file_io.rs delete mode 100644 snark-verifier-sdk/src/halo2/aggregation.rs rename snark-verifier-sdk/src/{halo2.rs => halo2_api.rs} (66%) create mode 100644 snark-verifier-sdk/src/param.rs create mode 100644 snark-verifier-sdk/src/snark.rs create mode 100644 snark-verifier-sdk/src/snark/mock.rs create mode 100644 snark-verifier-sdk/src/types.rs diff --git a/Cargo.lock b/Cargo.lock index f237e5aa..4ae00f00 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -54,9 +54,9 @@ dependencies = [ [[package]] name = "aho-corasick" -version = "0.7.20" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc936419f96fa211c1b9166887b38e5e40b19958e5b895be7c1f93adec7071ac" +checksum = "67fc08ce920c31afb70f013dcce1bfc3a3195de6a228474e45e1f145b36f8d04" dependencies = [ "memchr", ] @@ -78,6 +78,12 @@ dependencies = [ "rand", ] +[[package]] +name = "array-init" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d62b7694a562cdf5a74227903507c56ab2cc8bdd1f781ed5cb4cf9c9f810bfc" + [[package]] name = "arrayref" version = "0.3.7" @@ -98,7 +104,18 @@ checksum = "b9ccdd8f2a161be9bd5c023df56f1b2a0bd1d83872ae53b71a84a12c9bf6e842" dependencies = [ "proc-macro2", "quote", - "syn 2.0.12", + "syn 2.0.18", +] + +[[package]] +name = "async_io_stream" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6d7b9decdf35d8908a7e3ef02f64c5e9b1695e230154c0e8de3969142d9b94c" +dependencies = [ + "futures", + "pharos", + "rustc_version", ] [[package]] @@ -114,9 +131,9 @@ dependencies = [ [[package]] name = "auto_impl" -version = "1.0.1" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a8c1df849285fbacd587de7818cc7d13be6cd2cbcd47a04fb1801b0e2706e33" +checksum = "fee3da8ef1276b0bee5dd1c7258010d8fffd31801447323115a25560e1327b89" dependencies = [ "proc-macro-error", "proc-macro2", @@ -173,6 +190,18 @@ version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3441f0f7b02788e948e47f457ca01f1d7e6d92c693bc132c22b087d3141c03ff" +[[package]] +name = "base64" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" + +[[package]] +name = "base64" +version = "0.21.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "604178f6c5c21f02dc555784810edfb88d34ac2c73b2eae109655649ee73ce3d" + [[package]] name = "base64ct" version = "1.0.1" @@ -228,7 +257,7 @@ version = "0.10.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "46502ad458c9a52b69d4d4d32775c788b7a1b85e8bc9d482d92250fc0e3f8efe" dependencies = [ - "digest 0.10.6", + "digest 0.10.7", ] [[package]] @@ -242,6 +271,16 @@ dependencies = [ "constant_time_eq", ] +[[package]] +name = "block-buffer" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a076c298b9ecdb530ed9d967e74a6027d6a7478924520acddcddc24c1c8ab3ab" +dependencies = [ + "arrayref", + "byte-tools 0.2.0", +] + [[package]] name = "block-buffer" version = "0.7.3" @@ -249,7 +288,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c0940dc441f31689269e10ac70eb1002a3a1d3ad1390e030043662eb7fe4688b" dependencies = [ "block-padding 0.1.5", - "byte-tools", + "byte-tools 0.3.1", "byteorder", "generic-array 0.12.4", ] @@ -279,7 +318,7 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fa79dedbb091f449f1f39e53edf88d5dbe95f895dae6135a8d7b881fb5af73f5" dependencies = [ - "byte-tools", + "byte-tools 0.3.1", ] [[package]] @@ -341,9 +380,36 @@ checksum = "771fe0050b883fcc3ea2359b1a96bcfbc090b7116eae7c3c512c7a083fdf23d3" [[package]] name = "bumpalo" -version = "3.12.0" +version = "3.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0d261e256854913907f67ed06efbc3338dfe6179796deefc1ff763fc1aee5535" +checksum = "a3e2c3daef883ecc1b5d58c15adae93470a91d425f3532ba1695849656af3fc1" + +[[package]] +name = "bus-mapping" +version = "0.1.0" +source = "git+https://github.com/scroll-tech/zkevm-circuits.git?branch=develop#6c9df1a7ecc80bd8eb71f2a182d59012c44b89b3" +dependencies = [ + "eth-types", + "ethers-core", + "ethers-providers", + "ethers-signers", + "gadgets", + "halo2_proofs 0.2.0 (git+https://github.com/scroll-tech/halo2.git?branch=develop)", + "hex", + "itertools", + "keccak256", + "lazy_static", + "log", + "mock", + "once_cell", + "poseidon-circuit", + "rand", + "revm-precompile", + "serde", + "serde_json", + "strum", + "strum_macros", +] [[package]] name = "byte-slice-cast" @@ -351,6 +417,12 @@ version = "1.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c3ac9f8b63eca6fd385229b3675f6cc0dc5c8a5c8a54a59d4f52ffd670d87b0c" +[[package]] +name = "byte-tools" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "560c32574a12a89ecd91f5e742165893f86e3ab98d21f8ea548658eb9eef5f40" + [[package]] name = "byte-tools" version = "0.3.1" @@ -359,9 +431,9 @@ checksum = "e3b5ca7a04898ad4bcd41c90c5285445ff5b791899bb1b0abdd2a2aa791211d7" [[package]] name = "bytecheck" -version = "0.6.10" +version = "0.6.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13fe11640a23eb24562225322cd3e452b93a3d4091d62fab69c70542fcd17d1f" +checksum = "8b6372023ac861f6e6dc89c8344a8f398fb42aaba2b5dbc649ca0c0e9dbcb627" dependencies = [ "bytecheck_derive", "ptr_meta", @@ -370,9 +442,9 @@ dependencies = [ [[package]] name = "bytecheck_derive" -version = "0.6.10" +version = "0.6.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e31225543cb46f81a7e224762764f4a6a0f097b1db0b175f69e8065efaa42de5" +checksum = "a7ec4c6f261935ad534c0c22dbef2201b45918860eb1c574b972bd213a76af61" dependencies = [ "proc-macro2", "quote", @@ -442,9 +514,9 @@ dependencies = [ [[package]] name = "ciborium" -version = "0.2.0" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b0c137568cc60b904a7724001b35ce2630fd00d5d84805fbb608ab89509d788f" +checksum = "effd91f6c78e5a4ace8a5d3c0b6bfaec9e2baaef55f3efc00e45fb2e477ee926" dependencies = [ "ciborium-io", "ciborium-ll", @@ -453,15 +525,15 @@ dependencies = [ [[package]] name = "ciborium-io" -version = "0.2.0" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "346de753af073cc87b52b2083a506b38ac176a44cfb05497b622e27be899b369" +checksum = "cdf919175532b369853f5d5e20b26b43112613fd6fe7aee757e35f7a44642656" [[package]] name = "ciborium-ll" -version = "0.2.0" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "213030a2b5a4e0c0892b6652260cf6ccac84827b83a85a534e178e3906c4cf1b" +checksum = "defaa24ecc093c77630e6c15e17c51f5e187bf35ee514f4e2d67baaa96dae22b" dependencies = [ "ciborium-io", "half", @@ -478,9 +550,9 @@ dependencies = [ [[package]] name = "clap" -version = "3.2.23" +version = "3.2.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "71655c45cb9845d3270c9d6df84ebe72b4dad3c2ba3f7023ad47c144e4e473a5" +checksum = "4ea181bf566f71cb9a5d17a59e1871af638180a18fb0035c92ae62b705207123" dependencies = [ "bitflags", "clap_lex", @@ -506,9 +578,9 @@ dependencies = [ "bincode", "bs58", "coins-core", - "digest 0.10.6", + "digest 0.10.7", "getrandom", - "hmac", + "hmac 0.12.1", "k256", "lazy_static", "serde", @@ -526,7 +598,7 @@ dependencies = [ "coins-bip32", "getrandom", "hex", - "hmac", + "hmac 0.12.1", "pbkdf2 0.11.0", "rand", "sha2 0.10.6", @@ -540,17 +612,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c94090a6663f224feae66ab01e41a2555a8296ee07b5f20dab8888bdefc9f617" dependencies = [ "base58check", - "base64", + "base64 0.12.3", "bech32", "blake2", - "digest 0.10.6", + "digest 0.10.7", "generic-array 0.14.7", "hex", "ripemd", "serde", "serde_derive", "sha2 0.10.6", - "sha3 0.10.6", + "sha3 0.10.8", "thiserror", ] @@ -577,6 +649,12 @@ version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "13418e745008f7349ec7e449155f419a61b92b58a99cc3616942b926825ec76b" +[[package]] +name = "convert_case" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e" + [[package]] name = "convert_case" version = "0.5.0" @@ -585,18 +663,18 @@ checksum = "fb4a24b1aaf0fd0ce8b45161144d6f42cd91677fd5940fd431183eb023b3a2b8" [[package]] name = "cpp_demangle" -version = "0.4.0" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b446fd40bcc17eddd6a4a78f24315eb90afdb3334999ddfd4909985c47722442" +checksum = "2c76f98bdfc7f66172e6c7065f981ebb576ffc903fe4c0561d9f0c2509226dc6" dependencies = [ "cfg-if 1.0.0", ] [[package]] name = "cpufeatures" -version = "0.2.6" +version = "0.2.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "280a9f2d8b3a38871a3c8a46fb80db65e5e5ed97da80c4d08bf27fb63e35e181" +checksum = "3e4c1eaa2012c47becbbad2ab175484c2a84d1185b566fb2cc5b8707343dfe58" dependencies = [ "libc", ] @@ -663,9 +741,9 @@ dependencies = [ [[package]] name = "crossbeam-channel" -version = "0.5.7" +version = "0.5.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf2b3e8478797446514c91ef04bafcb59faba183e621ad488df88983cc14128c" +checksum = "a33c2bf77f2df06183c3aa30d1e96c0695a313d4f9c453cc3762a6db39f99200" dependencies = [ "cfg-if 1.0.0", "crossbeam-utils", @@ -724,7 +802,7 @@ dependencies = [ "crossterm_winapi", "libc", "mio", - "parking_lot", + "parking_lot 0.12.1", "signal-hook", "signal-hook-mio", "winapi", @@ -767,6 +845,16 @@ dependencies = [ "typenum", ] +[[package]] +name = "crypto-mac" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b584a330336237c1eecd3e94266efb216c56ed91225d634cb2991c5f3fd1aeab" +dependencies = [ + "generic-array 0.14.7", + "subtle", +] + [[package]] name = "ctr" version = "0.8.0" @@ -776,13 +864,48 @@ dependencies = [ "cipher", ] +[[package]] +name = "darling" +version = "0.13.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a01d95850c592940db9b8194bc39f4bc0e89dee5c4265e4b1807c34a9aba453c" +dependencies = [ + "darling_core", + "darling_macro", +] + +[[package]] +name = "darling_core" +version = "0.13.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "859d65a907b6852c9361e3185c862aae7fafd2887876799fa55f5f99dc40d610" +dependencies = [ + "fnv", + "ident_case", + "proc-macro2", + "quote", + "strsim", + "syn 1.0.109", +] + +[[package]] +name = "darling_macro" +version = "0.13.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c972679f83bdf9c42bd905396b6c3588a843a17f0f16dfcfa3e2c5d57441835" +dependencies = [ + "darling_core", + "quote", + "syn 1.0.109", +] + [[package]] name = "debugid" version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef552e6f588e446098f6ba40d89ac146c8c7b64aade83c051ee00bb5d2bc18d" dependencies = [ - "uuid 1.3.0", + "uuid 1.3.3", ] [[package]] @@ -795,6 +918,28 @@ dependencies = [ "zeroize", ] +[[package]] +name = "derive_more" +version = "0.99.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fb810d30a7c1953f91334de7244731fc3f3c10d7fe163338a35b9f640960321" +dependencies = [ + "convert_case 0.4.0", + "proc-macro2", + "quote", + "rustc_version", + "syn 1.0.109", +] + +[[package]] +name = "digest" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "03b072242a8cbaf9c145665af9d250c59af3b958f83ed6824e13533cf76d5b90" +dependencies = [ + "generic-array 0.9.1", +] + [[package]] name = "digest" version = "0.8.1" @@ -815,9 +960,9 @@ dependencies = [ [[package]] name = "digest" -version = "0.10.6" +version = "0.10.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8168378f4e5023e7218c89c891c0fd8ecdb5e5e4f18cb78f38cf245dd021e76f" +checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" dependencies = [ "block-buffer 0.10.4", "crypto-common", @@ -851,7 +996,7 @@ dependencies = [ "base16ct", "crypto-bigint", "der", - "digest 0.10.6", + "digest 0.10.7", "ff", "generic-array 0.14.7", "group", @@ -862,6 +1007,26 @@ dependencies = [ "zeroize", ] +[[package]] +name = "encoding_rs" +version = "0.8.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "071a31f4ee85403370b58aca746f01041ede6f0da2730960ad001edc2b71b394" +dependencies = [ + "cfg-if 1.0.0", +] + +[[package]] +name = "enumn" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48016319042fb7c87b78d2993084a831793a897a5cd1a2a67cab9d1eeb4b7d76" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.18", +] + [[package]] name = "env_logger" version = "0.8.4" @@ -875,6 +1040,19 @@ dependencies = [ "termcolor", ] +[[package]] +name = "env_logger" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a12e6657c4c97ebab115a42dcee77225f7f482cdd841cf7088c657a42e9e00e7" +dependencies = [ + "atty", + "humantime", + "log", + "regex", + "termcolor", +] + [[package]] name = "env_logger" version = "0.10.0" @@ -890,13 +1068,13 @@ dependencies = [ [[package]] name = "errno" -version = "0.3.0" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50d6a0976c999d473fe89ad888d5a284e55366d9dc9038b1ba2aa15128c4afa0" +checksum = "4bcfec3a70f97c962c307b2d2c56e358cf1d00b558d74262b5f929ee8cc7e73a" dependencies = [ "errno-dragonfly", "libc", - "windows-sys", + "windows-sys 0.48.0", ] [[package]] @@ -917,20 +1095,46 @@ checksum = "6f65b750ac950f2f825b36d08bef4cda4112e19a7b1a68f6e2bb499413e12440" dependencies = [ "aes", "ctr", - "digest 0.10.6", + "digest 0.10.7", "hex", - "hmac", + "hmac 0.12.1", "pbkdf2 0.11.0", "rand", "scrypt", "serde", "serde_json", "sha2 0.10.6", - "sha3 0.10.6", + "sha3 0.10.8", "thiserror", "uuid 0.8.2", ] +[[package]] +name = "eth-types" +version = "0.1.0" +source = "git+https://github.com/scroll-tech/zkevm-circuits.git?branch=develop#6c9df1a7ecc80bd8eb71f2a182d59012c44b89b3" +dependencies = [ + "ethers-core", + "ethers-signers", + "halo2_proofs 0.2.0 (git+https://github.com/scroll-tech/halo2.git?branch=develop)", + "hex", + "itertools", + "lazy_static", + "libsecp256k1", + "num", + "num-bigint", + "poseidon-circuit", + "regex", + "serde", + "serde_json", + "serde_with", + "sha3 0.10.8", + "strum", + "strum_macros", + "subtle", + "uint", +] + [[package]] name = "ethabi" version = "17.2.0" @@ -943,7 +1147,7 @@ dependencies = [ "regex", "serde", "serde_json", - "sha3 0.10.6", + "sha3 0.10.8", "thiserror", "uint", ] @@ -1007,7 +1211,7 @@ dependencies = [ "arrayvec", "bytes", "chrono", - "convert_case", + "convert_case 0.5.0", "elliptic-curve", "ethabi", "fastrlp", @@ -1028,6 +1232,43 @@ dependencies = [ "unicode-xid", ] +[[package]] +name = "ethers-providers" +version = "0.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e46482e4d1e79b20c338fd9db9e166184eb387f0a4e7c05c5b5c0aa2e8c8900c" +dependencies = [ + "async-trait", + "auto_impl", + "base64 0.13.1", + "ethers-core", + "futures-channel", + "futures-core", + "futures-timer", + "futures-util", + "getrandom", + "hashers", + "hex", + "http", + "once_cell", + "parking_lot 0.11.2", + "pin-project", + "reqwest", + "serde", + "serde_json", + "thiserror", + "tokio", + "tokio-tungstenite", + "tracing", + "tracing-futures", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "wasm-timer", + "web-sys", + "ws_stream_wasm", +] + [[package]] name = "ethers-signers" version = "0.17.0" @@ -1046,6 +1287,18 @@ dependencies = [ "thiserror", ] +[[package]] +name = "external-tracer" +version = "0.1.0" +source = "git+https://github.com/scroll-tech/zkevm-circuits.git?branch=develop#6c9df1a7ecc80bd8eb71f2a182d59012c44b89b3" +dependencies = [ + "eth-types", + "geth-utils", + "log", + "serde", + "serde_json", +] + [[package]] name = "fake-simd" version = "0.1.2" @@ -1133,6 +1386,21 @@ dependencies = [ "static_assertions", ] +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "form_urlencoded" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9c384f161156f5260c24a097c56119f9be8c798586aecc13afbcbe7b7e26bf8" +dependencies = [ + "percent-encoding", +] + [[package]] name = "funty" version = "2.0.0" @@ -1140,98 +1408,345 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" [[package]] -name = "generic-array" -version = "0.12.4" +name = "futures" +version = "0.3.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ffdf9f34f1447443d37393cc6c2b8313aebddcd96906caf34e54c68d8e57d7bd" +checksum = "23342abe12aba583913b2e62f22225ff9c950774065e4bfb61a19cd9770fec40" dependencies = [ - "typenum", + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", ] [[package]] -name = "generic-array" -version = "0.14.7" +name = "futures-channel" +version = "0.3.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" +checksum = "955518d47e09b25bbebc7a18df10b81f0c766eaf4c4f1cccef2fca5f2a4fb5f2" dependencies = [ - "typenum", - "version_check", + "futures-core", + "futures-sink", ] [[package]] -name = "getrandom" -version = "0.2.8" +name = "futures-core" +version = "0.3.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c05aeb6a22b8f62540c194aac980f2115af067bfe15a0734d7277a768d396b31" +checksum = "4bca583b7e26f571124fe5b7561d49cb2868d79116cfa0eefce955557c6fee8c" + +[[package]] +name = "futures-executor" +version = "0.3.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ccecee823288125bd88b4d7f565c9e58e41858e47ab72e8ea2d64e93624386e0" dependencies = [ - "cfg-if 1.0.0", - "js-sys", - "libc", - "wasi", - "wasm-bindgen", + "futures-core", + "futures-task", + "futures-util", ] [[package]] -name = "gimli" -version = "0.27.2" +name = "futures-io" +version = "0.3.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad0a93d233ebf96623465aad4046a8d3aa4da22d4f4beba5388838c8a434bbb4" +checksum = "4fff74096e71ed47f8e023204cfd0aa1289cd54ae5430a9523be060cdb849964" [[package]] -name = "group" -version = "0.12.1" +name = "futures-macro" +version = "0.3.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5dfbfb3a6cfbd390d5c9564ab283a0349b9b9fcd46a706c1eb10e0db70bfbac7" +checksum = "89ca545a94061b6365f2c7355b4b32bd20df3ff95f02da9329b34ccc3bd6ee72" dependencies = [ - "ff", - "rand_core", - "subtle", + "proc-macro2", + "quote", + "syn 2.0.18", ] [[package]] -name = "half" -version = "1.8.2" +name = "futures-sink" +version = "0.3.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eabb4a44450da02c90444cf74558da904edde8fb4e9035a9a6a4e15445af0bd7" +checksum = "f43be4fe21a13b9781a69afa4985b0f6ee0e1afab2c6f454a8cf30e2b2237b6e" [[package]] -name = "halo2-base" -version = "0.2.2" -source = "git+https://github.com/scroll-tech/halo2-lib?branch=minimize-diff#a80505265f36f87a2df40edc22ea468ea2068fb5" -dependencies = [ - "ff", - "halo2_proofs 0.2.0 (git+https://github.com/axiom-crypto/halo2.git?tag=v2023_01_17)", - "halo2_proofs 0.2.0 (git+https://github.com/scroll-tech/halo2.git?branch=halo2-ecc-snark-verifier-0323)", - "itertools", - "num-bigint", - "num-integer", - "num-traits", - "rand_chacha", - "rustc-hash", -] +name = "futures-task" +version = "0.3.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76d3d132be6c0e6aa1534069c705a74a5997a356c0dc2f86a47765e5617c5b65" [[package]] -name = "halo2-ecc" -version = "0.2.2" -source = "git+https://github.com/scroll-tech/halo2-lib?branch=minimize-diff#a80505265f36f87a2df40edc22ea468ea2068fb5" +name = "futures-timer" +version = "3.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e64b03909df88034c26dc1547e8970b91f98bdb65165d6a4e9110d94263dbb2c" + +[[package]] +name = "futures-util" +version = "0.3.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26b01e40b772d54cf6c6d721c1d1abd0647a0106a12ecaa1c186273392a69533" dependencies = [ - "ff", - "group", - "halo2-base", - "itertools", - "num-bigint", - "num-integer", - "num-traits", - "rand", - "rand_chacha", - "rand_core", - "serde", - "serde_json", + "futures-channel", + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "pin-utils", + "slab", ] [[package]] -name = "halo2_proofs" -version = "0.2.0" +name = "fxhash" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c31b6d751ae2c7f11320402d34e41349dd1016f8d5d45e48c4312bc8625af50c" +dependencies = [ + "byteorder", +] + +[[package]] +name = "gadgets" +version = "0.1.0" +source = "git+https://github.com/scroll-tech/zkevm-circuits.git?branch=develop#6c9df1a7ecc80bd8eb71f2a182d59012c44b89b3" +dependencies = [ + "digest 0.7.6", + "eth-types", + "halo2_proofs 0.2.0 (git+https://github.com/scroll-tech/halo2.git?branch=develop)", + "sha3 0.7.3", + "strum", +] + +[[package]] +name = "generic-array" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d00328cedcac5e81c683e5620ca6a30756fc23027ebf9bff405c0e8da1fbb7e" +dependencies = [ + "typenum", +] + +[[package]] +name = "generic-array" +version = "0.12.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ffdf9f34f1447443d37393cc6c2b8313aebddcd96906caf34e54c68d8e57d7bd" +dependencies = [ + "typenum", +] + +[[package]] +name = "generic-array" +version = "0.14.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" +dependencies = [ + "typenum", + "version_check", +] + +[[package]] +name = "geth-utils" +version = "0.1.0" +source = "git+https://github.com/scroll-tech/zkevm-circuits.git?branch=develop#6c9df1a7ecc80bd8eb71f2a182d59012c44b89b3" +dependencies = [ + "env_logger 0.9.3", + "gobuild", + "log", +] + +[[package]] +name = "getrandom" +version = "0.2.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c85e1d9ab2eadba7e5040d4e09cbd6d072b76a557ad64e797c2cb9d4da21d7e4" +dependencies = [ + "cfg-if 1.0.0", + "js-sys", + "libc", + "wasi", + "wasm-bindgen", +] + +[[package]] +name = "gimli" +version = "0.27.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad0a93d233ebf96623465aad4046a8d3aa4da22d4f4beba5388838c8a434bbb4" + +[[package]] +name = "gobuild" +version = "0.1.0-alpha.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "71e156a4ddbf3deb5e8116946c111413bd9a5679bdc1536c78a60618a7a9ac9e" +dependencies = [ + "cc", +] + +[[package]] +name = "group" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5dfbfb3a6cfbd390d5c9564ab283a0349b9b9fcd46a706c1eb10e0db70bfbac7" +dependencies = [ + "ff", + "rand_core", + "subtle", +] + +[[package]] +name = "h2" +version = "0.3.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d357c7ae988e7d2182f7d7871d0b963962420b0678b0997ce7de72001aeab782" +dependencies = [ + "bytes", + "fnv", + "futures-core", + "futures-sink", + "futures-util", + "http", + "indexmap", + "slab", + "tokio", + "tokio-util", + "tracing", +] + +[[package]] +name = "half" +version = "1.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eabb4a44450da02c90444cf74558da904edde8fb4e9035a9a6a4e15445af0bd7" + +[[package]] +name = "halo2-base" +version = "0.2.2" +source = "git+https://github.com/scroll-tech/halo2-lib?branch=develop#c2ea19569db5fedd85a7465ee3841f23be8e7b22" +dependencies = [ + "ff", + "halo2_proofs 0.2.0 (git+https://github.com/axiom-crypto/halo2.git?tag=v2023_01_17)", + "halo2_proofs 0.2.0 (git+https://github.com/scroll-tech/halo2.git?branch=develop)", + "itertools", + "num-bigint", + "num-integer", + "num-traits", + "rand_chacha", + "rustc-hash", +] + +[[package]] +name = "halo2-base" +version = "0.2.2" +source = "git+https://github.com/scroll-tech/halo2-lib?branch=halo2-ecc-snark-verifier-0323#d24871338ade7dd56362de517b718ba14f3e7b90" +dependencies = [ + "ff", + "halo2_proofs 0.2.0 (git+https://github.com/scroll-tech/halo2.git?branch=develop)", + "itertools", + "num-bigint", + "num-integer", + "num-traits", + "rand_chacha", + "rustc-hash", +] + +[[package]] +name = "halo2-base" +version = "0.2.2" +source = "git+https://github.com/scroll-tech/halo2-lib.git?branch=minimize-diff#a80505265f36f87a2df40edc22ea468ea2068fb5" +dependencies = [ + "ff", + "halo2_proofs 0.2.0 (git+https://github.com/scroll-tech/halo2.git?branch=develop)", + "itertools", + "num-bigint", + "num-integer", + "num-traits", + "rand_chacha", + "rustc-hash", +] + +[[package]] +name = "halo2-ecc" +version = "0.2.2" +source = "git+https://github.com/scroll-tech/halo2-lib?branch=develop#c2ea19569db5fedd85a7465ee3841f23be8e7b22" +dependencies = [ + "ff", + "group", + "halo2-base 0.2.2 (git+https://github.com/scroll-tech/halo2-lib?branch=develop)", + "itertools", + "num-bigint", + "num-integer", + "num-traits", + "rand", + "rand_chacha", + "rand_core", + "serde", + "serde_json", +] + +[[package]] +name = "halo2-ecc" +version = "0.2.2" +source = "git+https://github.com/scroll-tech/halo2-lib?branch=halo2-ecc-snark-verifier-0323#d24871338ade7dd56362de517b718ba14f3e7b90" +dependencies = [ + "ff", + "group", + "halo2-base 0.2.2 (git+https://github.com/scroll-tech/halo2-lib?branch=halo2-ecc-snark-verifier-0323)", + "itertools", + "num-bigint", + "num-integer", + "num-traits", + "rand", + "rand_chacha", + "rand_core", + "serde", + "serde_json", +] + +[[package]] +name = "halo2-ecc" +version = "0.2.2" +source = "git+https://github.com/scroll-tech/halo2-lib.git?branch=minimize-diff#a80505265f36f87a2df40edc22ea468ea2068fb5" +dependencies = [ + "ff", + "group", + "halo2-base 0.2.2 (git+https://github.com/scroll-tech/halo2-lib.git?branch=minimize-diff)", + "itertools", + "num-bigint", + "num-integer", + "num-traits", + "rand", + "rand_chacha", + "rand_core", + "serde", + "serde_json", +] + +[[package]] +name = "halo2-mpt-circuits" +version = "0.1.0" +source = "git+https://github.com/scroll-tech/mpt-circuit.git?branch=scroll-dev-0411#ea87f9542097f03773a3a63f7b793141689afe41" +dependencies = [ + "halo2_proofs 0.2.0 (git+https://github.com/scroll-tech/halo2.git?branch=develop)", + "hex", + "lazy_static", + "num-bigint", + "poseidon-circuit", + "rand", + "serde", + "serde_json", + "thiserror", +] + +[[package]] +name = "halo2_proofs" +version = "0.2.0" source = "git+https://github.com/axiom-crypto/halo2.git?tag=v2023_01_17#475e45f52a0774ceb81304dd6a3a97dddd07662e" dependencies = [ "blake2b_simd", @@ -1247,7 +1762,7 @@ dependencies = [ [[package]] name = "halo2_proofs" version = "0.2.0" -source = "git+https://github.com/scroll-tech/halo2.git?branch=halo2-ecc-snark-verifier-0323#2e9710ca3d5291a566a813866e268b994b543249" +source = "git+https://github.com/scroll-tech/halo2.git?branch=develop#9bf3562083dd9bed8a19f651b52bc810f5e2235f" dependencies = [ "ark-std", "blake2b_simd", @@ -1289,7 +1804,7 @@ dependencies = [ [[package]] name = "halo2curves" version = "0.3.1" -source = "git+https://github.com/scroll-tech/halo2curves.git?branch=0.3.1-derive-serde#c0ac1935e5da2a620204b5b011be2c924b1e0155" +source = "git+https://github.com/scroll-tech/halo2curves.git?branch=0.3.1-derive-serde#969f1e44d9713ee4cd552563bd0c762c5d53b56e" dependencies = [ "ff", "group", @@ -1323,6 +1838,18 @@ dependencies = [ "subtle", ] +[[package]] +name = "halo2wrong" +version = "0.1.0" +source = "git+https://github.com/scroll-tech/halo2wrong.git?branch=halo2-ecc-snark-verifier-0323#939d679cb16abf0e820bd606248661e400328afa" +dependencies = [ + "group", + "halo2_proofs 0.2.0 (git+https://github.com/scroll-tech/halo2.git?branch=develop)", + "num-bigint", + "num-integer", + "num-traits", +] + [[package]] name = "hashbrown" version = "0.12.3" @@ -1341,6 +1868,15 @@ dependencies = [ "ahash 0.8.3", ] +[[package]] +name = "hashers" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2bca93b15ea5a746f220e56587f71e73c6165eab783df9e26590069953e3c30" +dependencies = [ + "fxhash", +] + [[package]] name = "heck" version = "0.4.1" @@ -1377,21 +1913,135 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" +[[package]] +name = "hex-literal" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6fe2267d4ed49bc07b63801559be28c718ea06c4738b7a03c94df7386d2cde46" + +[[package]] +name = "hmac" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "126888268dcc288495a26bf004b38c5fdbb31682f992c84ceb046a1f0fe38840" +dependencies = [ + "crypto-mac", + "digest 0.9.0", +] + [[package]] name = "hmac" version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" dependencies = [ - "digest 0.10.6", + "digest 0.10.7", +] + +[[package]] +name = "hmac-drbg" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "17ea0a1394df5b6574da6e0c1ade9e78868c9fb0a4e5ef4428e32da4676b85b1" +dependencies = [ + "digest 0.9.0", + "generic-array 0.14.7", + "hmac 0.8.1", +] + +[[package]] +name = "http" +version = "0.2.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd6effc99afb63425aff9b05836f029929e345a6148a14b7ecd5ab67af944482" +dependencies = [ + "bytes", + "fnv", + "itoa", +] + +[[package]] +name = "http-body" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d5f38f16d184e36f2408a55281cd658ecbd3ca05cce6d6510a176eca393e26d1" +dependencies = [ + "bytes", + "http", + "pin-project-lite", ] +[[package]] +name = "httparse" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d897f394bad6a705d5f4104762e116a75639e470d80901eed05a860a95cb1904" + +[[package]] +name = "httpdate" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421" + [[package]] name = "humantime" version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" +[[package]] +name = "hyper" +version = "0.14.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab302d72a6f11a3b910431ff93aae7e773078c769f0a3ef15fb9ec692ed147d4" +dependencies = [ + "bytes", + "futures-channel", + "futures-core", + "futures-util", + "h2", + "http", + "http-body", + "httparse", + "httpdate", + "itoa", + "pin-project-lite", + "socket2", + "tokio", + "tower-service", + "tracing", + "want", +] + +[[package]] +name = "hyper-rustls" +version = "0.24.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0646026eb1b3eea4cd9ba47912ea5ce9cc07713d105b1a14698f4e6433d348b7" +dependencies = [ + "http", + "hyper", + "rustls 0.21.1", + "tokio", + "tokio-rustls 0.24.0", +] + +[[package]] +name = "ident_case" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" + +[[package]] +name = "idna" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e14ddfc70884202db2244c223200c204c2bda1bc6e0998d11b5e024d657209e6" +dependencies = [ + "unicode-bidi", + "unicode-normalization", +] + [[package]] name = "impl-codec" version = "0.6.0" @@ -1465,29 +2115,38 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c" dependencies = [ "cfg-if 1.0.0", + "js-sys", + "wasm-bindgen", + "web-sys", ] [[package]] name = "io-lifetimes" -version = "1.0.9" +version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09270fd4fa1111bc614ed2246c7ef56239a3063d5be0d1ec3b589c505d400aeb" +checksum = "eae7b9aee968036d54dce06cebaefd919e4472e753296daccd6d344e3e2df0c2" dependencies = [ "hermit-abi 0.3.1", "libc", - "windows-sys", + "windows-sys 0.48.0", ] +[[package]] +name = "ipnet" +version = "2.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12b6ee2129af8d4fb011108c73d99a1b83a85977f23b82460c0ae2e25bb4b57f" + [[package]] name = "is-terminal" -version = "0.4.6" +version = "0.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "256017f749ab3117e93acb91063009e1f1bb56d03965b14c2c8df4eb02c524d8" +checksum = "adcf93614601c8129ddf72e2d5633df827ba6551541c6d8c59520a371475be1f" dependencies = [ "hermit-abi 0.3.1", "io-lifetimes", "rustix", - "windows-sys", + "windows-sys 0.48.0", ] [[package]] @@ -1507,9 +2166,9 @@ checksum = "453ad9f582a441959e5f0d088b02ce04cfe8d51a8eaf077f12ac6d3e94164ca6" [[package]] name = "js-sys" -version = "0.3.61" +version = "0.3.63" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "445dde2150c55e483f3d8416706b97ec8e8237c307e5b7b4b8dd15e6af2a0730" +checksum = "2f37a4a5928311ac501dee68b3c7613a1037d0edb30c8e5427bd832d55d1b790" dependencies = [ "wasm-bindgen", ] @@ -1524,18 +2183,33 @@ dependencies = [ "ecdsa", "elliptic-curve", "sha2 0.10.6", - "sha3 0.10.6", + "sha3 0.10.8", ] [[package]] name = "keccak" -version = "0.1.3" +version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3afef3b6eff9ce9d8ff9b3601125eec7f0c8cbac7abd14f355d053fa56c98768" +checksum = "8f6d5ed8676d904364de097082f4e7d240b571b67989ced0240f08b7f966f940" dependencies = [ "cpufeatures", ] +[[package]] +name = "keccak256" +version = "0.1.0" +source = "git+https://github.com/scroll-tech/zkevm-circuits.git?branch=develop#6c9df1a7ecc80bd8eb71f2a182d59012c44b89b3" +dependencies = [ + "env_logger 0.9.3", + "eth-types", + "halo2_proofs 0.2.0 (git+https://github.com/scroll-tech/halo2.git?branch=develop)", + "itertools", + "lazy_static", + "log", + "num-bigint", + "num-traits", +] + [[package]] name = "lazy_static" version = "1.4.0" @@ -1547,15 +2221,63 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.140" +version = "0.2.144" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b00cc1c228a6782d0f076e7b232802e0c5689d41bb5df366f2a6b6621cfdfe1" + +[[package]] +name = "libsecp256k1" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95b09eff1b35ed3b33b877ced3a691fc7a481919c7e29c53c906226fcf55e2a1" +dependencies = [ + "arrayref", + "base64 0.13.1", + "digest 0.9.0", + "hmac-drbg", + "libsecp256k1-core", + "libsecp256k1-gen-ecmult", + "libsecp256k1-gen-genmult", + "rand", + "serde", + "sha2 0.9.9", + "typenum", +] + +[[package]] +name = "libsecp256k1-core" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5be9b9bb642d8522a44d533eab56c16c738301965504753b03ad1de3425d5451" +dependencies = [ + "crunchy", + "digest 0.9.0", + "subtle", +] + +[[package]] +name = "libsecp256k1-gen-ecmult" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "99227334921fae1a979cf0bfdfcc6b3e5ce376ef57e16fb6fb3ea2ed6095f80c" +checksum = "3038c808c55c87e8a172643a7d87187fc6c4174468159cb3090659d55bcb4809" +dependencies = [ + "libsecp256k1-core", +] + +[[package]] +name = "libsecp256k1-gen-genmult" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3db8d6ba2cec9eacc40e6e8ccc98931840301f1006e95647ceb2dd5c3aa06f7c" +dependencies = [ + "libsecp256k1-core", +] [[package]] name = "linux-raw-sys" -version = "0.3.1" +version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d59d8c75012853d2e872fb56bc8a2e53718e2cafe1a4c823143141c6d90c322f" +checksum = "ef53942eb7bf7ff43a617b3e2c1c4a5ecf5944a7c1bc12d7ee39bbb15e5c1519" [[package]] name = "lock_api" @@ -1576,6 +2298,20 @@ dependencies = [ "cfg-if 1.0.0", ] +[[package]] +name = "maingate" +version = "0.1.0" +source = "git+https://github.com/privacy-scaling-explorations/halo2wrong?tag=v2023_02_02#5905a20b62fcd9f6c269416a39c80de7ced8fb02" +dependencies = [ + "group", + "halo2wrong", + "num-bigint", + "num-integer", + "num-traits", + "rand", + "subtle", +] + [[package]] name = "memchr" version = "2.5.0" @@ -1600,6 +2336,12 @@ dependencies = [ "autocfg", ] +[[package]] +name = "mime" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" + [[package]] name = "miniz_oxide" version = "0.6.2" @@ -1618,7 +2360,38 @@ dependencies = [ "libc", "log", "wasi", - "windows-sys", + "windows-sys 0.45.0", +] + +[[package]] +name = "mock" +version = "0.1.0" +source = "git+https://github.com/scroll-tech/zkevm-circuits.git?branch=develop#6c9df1a7ecc80bd8eb71f2a182d59012c44b89b3" +dependencies = [ + "eth-types", + "ethers-core", + "ethers-signers", + "external-tracer", + "itertools", + "lazy_static", + "rand", + "rand_chacha", +] + +[[package]] +name = "mpt-zktrie" +version = "0.1.0" +source = "git+https://github.com/scroll-tech/zkevm-circuits.git?branch=develop#6c9df1a7ecc80bd8eb71f2a182d59012c44b89b3" +dependencies = [ + "bus-mapping", + "eth-types", + "halo2-mpt-circuits", + "halo2_proofs 0.2.0 (git+https://github.com/scroll-tech/halo2.git?branch=develop)", + "hex", + "lazy_static", + "log", + "num-bigint", + "zktrie", ] [[package]] @@ -1792,9 +2565,9 @@ checksum = "ceedf44fb00f2d1984b0bc98102627ce622e083e49a5bacdb3e514fa4238e267" [[package]] name = "parity-scale-codec" -version = "3.4.0" +version = "3.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "637935964ff85a605d114591d4d2c13c5d1ba2806dae97cea6bf180238a749ac" +checksum = "5ddb756ca205bd108aee3c62c6d3c994e1df84a59b9d6d4a5ea42ee1fd5a9a28" dependencies = [ "arrayvec", "bitvec 1.0.1", @@ -1816,6 +2589,17 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "parking_lot" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d17b78036a60663b797adeaee46f5c9dfebb86948d1255007a1d6be0271ff99" +dependencies = [ + "instant", + "lock_api", + "parking_lot_core 0.8.6", +] + [[package]] name = "parking_lot" version = "0.12.1" @@ -1823,7 +2607,21 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" dependencies = [ "lock_api", - "parking_lot_core", + "parking_lot_core 0.9.7", +] + +[[package]] +name = "parking_lot_core" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60a2cfe6f0ad2bfc16aefa463b497d5c7a5ecd44a23efa72aa342d90177356dc" +dependencies = [ + "cfg-if 1.0.0", + "instant", + "libc", + "redox_syscall 0.2.16", + "smallvec", + "winapi", ] [[package]] @@ -1836,7 +2634,7 @@ dependencies = [ "libc", "redox_syscall 0.2.16", "smallvec", - "windows-sys", + "windows-sys 0.45.0", ] [[package]] @@ -1886,21 +2684,57 @@ checksum = "9f746c4065a8fa3fe23974dd82f15431cc8d40779821001404d10d2e79ca7d79" name = "pbkdf2" version = "0.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "271779f35b581956db91a3e55737327a03aa051e90b1c47aeb189508533adfd7" +checksum = "271779f35b581956db91a3e55737327a03aa051e90b1c47aeb189508533adfd7" +dependencies = [ + "digest 0.10.7", +] + +[[package]] +name = "pbkdf2" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "83a0692ec44e4cf1ef28ca317f14f8f07da2d95ec3fa01f86e4467b725e60917" +dependencies = [ + "digest 0.10.7", + "hmac 0.12.1", + "password-hash 0.4.2", + "sha2 0.10.6", +] + +[[package]] +name = "percent-encoding" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "478c572c3d73181ff3c2539045f6eb99e5491218eae919370993b890cdbdd98e" + +[[package]] +name = "pharos" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e9567389417feee6ce15dd6527a8a1ecac205ef62c2932bcf3d9f6fc5b78b414" +dependencies = [ + "futures", + "rustc_version", +] + +[[package]] +name = "pin-project" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c95a7476719eab1e366eaf73d0260af3021184f18177925b07f54b30089ceead" dependencies = [ - "digest 0.10.6", + "pin-project-internal", ] [[package]] -name = "pbkdf2" -version = "0.11.0" +name = "pin-project-internal" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "83a0692ec44e4cf1ef28ca317f14f8f07da2d95ec3fa01f86e4467b725e60917" +checksum = "39407670928234ebc5e6e580247dd567ad73a3578460c5990f9503df207e8f07" dependencies = [ - "digest 0.10.6", - "hmac", - "password-hash 0.4.2", - "sha2 0.10.6", + "proc-macro2", + "quote", + "syn 2.0.18", ] [[package]] @@ -1909,6 +2743,12 @@ version = "0.2.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e0a7ae3ac2f1173085d398531c705756c94a4c56843785df85a60c1a0afac116" +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + [[package]] name = "pkcs8" version = "0.9.0" @@ -1967,6 +2807,17 @@ dependencies = [ "subtle", ] +[[package]] +name = "poseidon-circuit" +version = "0.1.0" +source = "git+https://github.com/scroll-tech/poseidon-circuit.git?branch=scroll-dev-0408#89e9c0456f0fa00d49cd7920c6b437c66b48db17" +dependencies = [ + "bitvec 1.0.1", + "halo2_proofs 0.2.0 (git+https://github.com/scroll-tech/halo2.git?branch=develop)", + "lazy_static", + "thiserror", +] + [[package]] name = "pprof" version = "0.11.1" @@ -1982,7 +2833,7 @@ dependencies = [ "log", "nix", "once_cell", - "parking_lot", + "parking_lot 0.12.1", "smallvec", "symbolic-demangle", "tempfile", @@ -2065,9 +2916,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.54" +version = "1.0.59" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e472a104799c74b514a57226160104aa483546de37e839ec50e3c2e41dd87534" +checksum = "6aeca18b86b413c660b781aa319e4e2648a3e6f9eadc9b47e9038e6fe9f3451b" dependencies = [ "unicode-ident", ] @@ -2103,9 +2954,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.26" +version = "1.0.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4424af4bf778aae2051a77b60283332f386554255d722233d09fbfc7e30da2fc" +checksum = "1b9ab9c7eadfd8df19006f1cf1a4aed13540ed5cbc047010ece5826e10825488" dependencies = [ "proc-macro2", ] @@ -2152,6 +3003,15 @@ dependencies = [ "getrandom", ] +[[package]] +name = "rand_xorshift" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d25bf25ec5ae4a3f1b92f929810509a2f53d7dca2f50b794ff57e3face536c8f" +dependencies = [ + "rand_core", +] + [[package]] name = "rayon" version = "1.7.0" @@ -2194,9 +3054,9 @@ dependencies = [ [[package]] name = "regex" -version = "1.7.3" +version = "1.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b1f693b24f6ac912f4893ef08244d70b6067480d2f1a46e950c9691e6749d1d" +checksum = "81ca098a9821bd52d6b24fd8b10bd081f47d39c22778cafaa75a2857a62c6390" dependencies = [ "aho-corasick", "memchr", @@ -2205,9 +3065,9 @@ dependencies = [ [[package]] name = "regex-syntax" -version = "0.6.29" +version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1" +checksum = "436b050e76ed2903236f032a59761c1eb99e1b0aead2c257922771dab1fc8c78" [[package]] name = "rend" @@ -2218,6 +3078,45 @@ dependencies = [ "bytecheck", ] +[[package]] +name = "reqwest" +version = "0.11.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cde824a14b7c14f85caff81225f411faacc04a2013f41670f41443742b1c1c55" +dependencies = [ + "base64 0.21.2", + "bytes", + "encoding_rs", + "futures-core", + "futures-util", + "h2", + "http", + "http-body", + "hyper", + "hyper-rustls", + "ipnet", + "js-sys", + "log", + "mime", + "once_cell", + "percent-encoding", + "pin-project-lite", + "rustls 0.21.1", + "rustls-pemfile", + "serde", + "serde_json", + "serde_urlencoded", + "tokio", + "tokio-rustls 0.24.0", + "tower-service", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "webpki-roots", + "winreg", +] + [[package]] name = "revm" version = "2.3.1" @@ -2232,7 +3131,45 @@ dependencies = [ "primitive-types 0.12.1", "revm_precompiles", "rlp", - "sha3 0.10.6", + "sha3 0.10.8", +] + +[[package]] +name = "revm-precompile" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "66837781605c6dcb7f07ad87604eeab3119dae9149d69d8839073dd6f188673d" +dependencies = [ + "k256", + "num", + "once_cell", + "revm-primitives", + "ripemd", + "secp256k1 0.26.0", + "sha2 0.10.6", + "sha3 0.10.8", + "substrate-bn", +] + +[[package]] +name = "revm-primitives" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "304d998f466ffef72d76c7f20b05bf08a96801736a6fb1fdef47d49a292618df" +dependencies = [ + "auto_impl", + "bitvec 1.0.1", + "bytes", + "derive_more", + "enumn", + "fixed-hash 0.8.0", + "hashbrown 0.13.2", + "hex", + "hex-literal", + "primitive-types 0.12.1", + "rlp", + "ruint", + "sha3 0.10.8", ] [[package]] @@ -2247,9 +3184,9 @@ dependencies = [ "once_cell", "primitive-types 0.12.1", "ripemd", - "secp256k1", + "secp256k1 0.24.3", "sha2 0.10.6", - "sha3 0.10.6", + "sha3 0.10.8", "substrate-bn", ] @@ -2260,7 +3197,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7743f17af12fa0b03b803ba12cd6a8d9483a587e89c69445e3909655c0b9fabb" dependencies = [ "crypto-bigint", - "hmac", + "hmac 0.12.1", "zeroize", ] @@ -2273,34 +3210,52 @@ dependencies = [ "bytemuck", ] +[[package]] +name = "ring" +version = "0.16.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3053cf52e236a3ed746dfc745aa9cacf1b791d846bdaf412f60a8d7d6e17c8fc" +dependencies = [ + "cc", + "libc", + "once_cell", + "spin", + "untrusted", + "web-sys", + "winapi", +] + [[package]] name = "ripemd" version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bd124222d17ad93a644ed9d011a40f4fb64aa54275c08cc216524a9ea82fb09f" dependencies = [ - "digest 0.10.6", + "digest 0.10.7", ] [[package]] name = "rkyv" -version = "0.7.40" +version = "0.7.42" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c30f1d45d9aa61cbc8cd1eb87705470892289bb2d01943e7803b873a57404dc3" +checksum = "0200c8230b013893c0b2d6213d6ec64ed2b9be2e0e016682b7224ff82cff5c58" dependencies = [ + "bitvec 1.0.1", "bytecheck", "hashbrown 0.12.3", "ptr_meta", "rend", "rkyv_derive", "seahash", + "tinyvec", + "uuid 1.3.3", ] [[package]] name = "rkyv_derive" -version = "0.7.40" +version = "0.7.42" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff26ed6c7c4dfc2aa9480b86a60e3c7233543a270a680e10758a507c5a4ce476" +checksum = "b2e06b915b5c230a17d7a736d1e2e63ee753c256a8614ef3f5147b13a4f5541d" dependencies = [ "proc-macro2", "quote", @@ -2328,6 +3283,26 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "ruint" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d470e29e933dac4101180fd6574971892315c414cf2961a192729089687cc9b" +dependencies = [ + "derive_more", + "primitive-types 0.12.1", + "rlp", + "ruint-macro", + "rustc_version", + "thiserror", +] + +[[package]] +name = "ruint-macro" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62cc5760263ea229d367e7dff3c0cbf09e4797a125bd87059a6c095804f3b2d1" + [[package]] name = "rust_decimal" version = "1.29.1" @@ -2348,9 +3323,9 @@ dependencies = [ [[package]] name = "rustc-demangle" -version = "0.1.22" +version = "0.1.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d4a36c42d1873f9a77c53bde094f9664d9891bc604a45b4798fd2c389ed12e5b" +checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" [[package]] name = "rustc-hash" @@ -2364,18 +3339,70 @@ version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3e75f6a532d0fd9f7f13144f392b6ad56a32696bfcd9c78f797f16bbb6f072d6" +[[package]] +name = "rustc_version" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" +dependencies = [ + "semver", +] + [[package]] name = "rustix" -version = "0.37.5" +version = "0.37.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0e78cc525325c06b4a7ff02db283472f3c042b7ff0c391f96c6d5ac6f4f91b75" +checksum = "acf8729d8542766f1b2cf77eb034d52f40d375bb8b615d0b147089946e16613d" dependencies = [ "bitflags", "errno", "io-lifetimes", "libc", "linux-raw-sys", - "windows-sys", + "windows-sys 0.48.0", +] + +[[package]] +name = "rustls" +version = "0.20.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fff78fc74d175294f4e83b28343315ffcfb114b156f0185e9741cb5570f50e2f" +dependencies = [ + "log", + "ring", + "sct", + "webpki", +] + +[[package]] +name = "rustls" +version = "0.21.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c911ba11bc8433e811ce56fde130ccf32f5127cab0e0194e9c68c5a5b671791e" +dependencies = [ + "log", + "ring", + "rustls-webpki", + "sct", +] + +[[package]] +name = "rustls-pemfile" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d194b56d58803a43635bdc398cd17e383d6f71f9182b9a192c127ca42494a59b" +dependencies = [ + "base64 0.21.2", +] + +[[package]] +name = "rustls-webpki" +version = "0.100.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d6207cd5ed3d8dca7816f8f3725513a34609c0c765bf652b8c3cb4cfd87db46b" +dependencies = [ + "ring", + "untrusted", ] [[package]] @@ -2420,13 +3447,23 @@ version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e73d6d7c6311ebdbd9184ad6c4447b2f36337e327bda107d3ba9e3c374f9d325" dependencies = [ - "hmac", + "hmac 0.12.1", "password-hash 0.3.2", "pbkdf2 0.10.1", "salsa20", "sha2 0.10.6", ] +[[package]] +name = "sct" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d53dcdb7c9f8158937a7981b48accfd39a43af418591a5d008c7b22b5e1b7ca4" +dependencies = [ + "ring", + "untrusted", +] + [[package]] name = "seahash" version = "4.1.0" @@ -2453,7 +3490,16 @@ version = "0.24.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6b1629c9c557ef9b293568b338dddfc8208c98a18c59d722a9d53f859d9c9b62" dependencies = [ - "secp256k1-sys", + "secp256k1-sys 0.6.1", +] + +[[package]] +name = "secp256k1" +version = "0.26.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4124a35fe33ae14259c490fd70fa199a32b9ce9502f2ee6bc4f81ec06fa65894" +dependencies = [ + "secp256k1-sys 0.8.1", ] [[package]] @@ -2465,37 +3511,103 @@ dependencies = [ "cc", ] +[[package]] +name = "secp256k1-sys" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70a129b9e9efbfb223753b9163c4ab3b13cff7fd9c7f010fbac25ab4099fa07e" +dependencies = [ + "cc", +] + +[[package]] +name = "semver" +version = "1.0.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bebd363326d05ec3e2f532ab7660680f3b02130d780c299bca73469d521bc0ed" + +[[package]] +name = "send_wrapper" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd0b0ec5f1c1ca621c432a25813d8d60c88abe6d3e08a3eb9cf37d97a0fe3d73" + [[package]] name = "serde" -version = "1.0.159" +version = "1.0.163" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c04e8343c3daeec41f58990b9d77068df31209f2af111e059e9fe9646693065" +checksum = "2113ab51b87a539ae008b5c6c02dc020ffa39afd2d83cffcb3f4eb2722cebec2" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.159" +version = "1.0.163" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c614d17805b093df4b147b51339e7e44bf05ef59fba1e45d83500bcfb4d8585" +checksum = "8c805777e3930c8883389c602315a24224bcc738b63905ef87cd1420353ea93e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.12", + "syn 2.0.18", ] [[package]] name = "serde_json" -version = "1.0.95" +version = "1.0.96" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "057d394a50403bcac12672b2b18fb387ab6d289d957dab67dd201875391e52f1" +dependencies = [ + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "serde_urlencoded" +version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d721eca97ac802aa7777b701877c8004d950fc142651367300d21c1cc0194744" +checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" dependencies = [ + "form_urlencoded", "itoa", "ryu", "serde", ] +[[package]] +name = "serde_with" +version = "1.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "678b5a069e50bf00ecd22d0cd8ddf7c236f68581b03db652061ed5eb13a312ff" +dependencies = [ + "serde", + "serde_with_macros", +] + +[[package]] +name = "serde_with_macros" +version = "1.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e182d6ec6f05393cc0e5ed1bf81ad6db3a8feedf8ee515ecdd369809bcce8082" +dependencies = [ + "darling", + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "sha-1" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f5058ada175748e33390e40e872bd0fe59a19f265d0158daa551c5a88a76009c" +dependencies = [ + "cfg-if 1.0.0", + "cpufeatures", + "digest 0.10.7", +] + [[package]] name = "sha2" version = "0.8.2" @@ -2508,6 +3620,19 @@ dependencies = [ "opaque-debug 0.2.3", ] +[[package]] +name = "sha2" +version = "0.9.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4d58a1e1bf39749807d89cf2d98ac2dfa0ff1cb3faa38fbb64dd88ac8013d800" +dependencies = [ + "block-buffer 0.9.0", + "cfg-if 1.0.0", + "cpufeatures", + "digest 0.9.0", + "opaque-debug 0.3.0", +] + [[package]] name = "sha2" version = "0.10.6" @@ -2516,7 +3641,19 @@ checksum = "82e6b795fe2e3b1e845bafcb27aa35405c4d47cdfc92af5fc8d3002f76cebdc0" dependencies = [ "cfg-if 1.0.0", "cpufeatures", - "digest 0.10.6", + "digest 0.10.7", +] + +[[package]] +name = "sha3" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b64dcef59ed4290b9fb562b53df07f564690d6539e8ecdd4728cf392477530bc" +dependencies = [ + "block-buffer 0.3.3", + "byte-tools 0.2.0", + "digest 0.7.6", + "keccak", ] [[package]] @@ -2533,11 +3670,11 @@ dependencies = [ [[package]] name = "sha3" -version = "0.10.6" +version = "0.10.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bdf0c33fae925bdc080598b84bc15c55e7b9a4a43b3c704da051f977469691c9" +checksum = "75872d278a8f37ef87fa0ddbda7802605cb18344497949862c0d4dcb291eba60" dependencies = [ - "digest 0.10.6", + "digest 0.10.7", "keccak", ] @@ -2577,7 +3714,7 @@ version = "1.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "74233d3b3b2f6d4b006dc19dee745e73e2a6bfb6f93607cd3b02bd5b00797d7c" dependencies = [ - "digest 0.10.6", + "digest 0.10.7", "rand_core", ] @@ -2587,6 +3724,15 @@ version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f27f6278552951f1f2b8cf9da965d10969b2efdea95a6ec47987ab46edfe263a" +[[package]] +name = "slab" +version = "0.4.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6528351c9bc8ab22353f9d776db39a20288e8d6c37ef8cfe3317cf875eecfc2d" +dependencies = [ + "autocfg", +] + [[package]] name = "smallvec" version = "1.10.0" @@ -2601,42 +3747,94 @@ dependencies = [ "bytes", "crossterm", "ethereum-types 0.14.1", - "halo2-base", - "halo2-ecc", + "halo2-base 0.2.2 (git+https://github.com/scroll-tech/halo2-lib?branch=develop)", + "halo2-ecc 0.2.2 (git+https://github.com/scroll-tech/halo2-lib?branch=develop)", + "hex", + "itertools", + "lazy_static", + "num-bigint", + "num-integer", + "num-traits", + "paste", + "poseidon 0.2.0 (git+https://github.com/axiom-crypto/halo2.git?branch=axiom/dev)", + "poseidon 0.2.0 (git+https://github.com/scroll-tech/poseidon.git?branch=scroll-dev-0220)", + "rand", + "rand_chacha", + "rayon", + "revm", + "rlp", + "rustc-hash", + "serde", + "serde_json", + "sha3 0.10.8", + "tui", +] + +[[package]] +name = "snark-verifier" +version = "0.1.0" +source = "git+https://github.com/scroll-tech/snark-verifier?branch=halo2-ecc-snark-verifier-0323#ae6a9ef1ba0f5296f98cd6ba2a94f791278be851" +dependencies = [ + "bytes", + "ethereum-types 0.14.1", + "halo2-base 0.2.2 (git+https://github.com/scroll-tech/halo2-lib.git?branch=minimize-diff)", + "halo2-ecc 0.2.2 (git+https://github.com/scroll-tech/halo2-lib.git?branch=minimize-diff)", + "hex", + "itertools", + "lazy_static", + "num-bigint", + "num-integer", + "num-traits", + "poseidon 0.2.0 (git+https://github.com/scroll-tech/poseidon.git?branch=scroll-dev-0220)", + "rand", + "revm", + "rlp", + "rustc-hash", + "serde", + "sha3 0.10.8", +] + +[[package]] +name = "snark-verifier-sdk" +version = "0.0.1" +dependencies = [ + "ark-std", + "bincode", + "criterion", + "criterion-macro", + "crossterm", + "env_logger 0.10.0", + "eth-types", + "ethereum-types 0.14.1", + "ethers-signers", + "halo2-base 0.2.2 (git+https://github.com/scroll-tech/halo2-lib?branch=develop)", "hex", "itertools", "lazy_static", + "log", "num-bigint", "num-integer", "num-traits", "paste", - "poseidon 0.2.0 (git+https://github.com/axiom-crypto/halo2.git?branch=axiom/dev)", - "poseidon 0.2.0 (git+https://github.com/scroll-tech/poseidon.git?branch=scroll-dev-0220)", + "pprof", "rand", "rand_chacha", - "rayon", - "revm", - "rlp", - "rustc-hash", "serde", "serde_json", - "sha3 0.10.6", + "snark-verifier 0.1.0", "tui", + "zkevm-circuits", ] [[package]] name = "snark-verifier-sdk" version = "0.0.1" +source = "git+https://github.com/scroll-tech/snark-verifier?branch=halo2-ecc-snark-verifier-0323#ae6a9ef1ba0f5296f98cd6ba2a94f791278be851" dependencies = [ - "ark-std", "bincode", - "criterion", - "criterion-macro", - "crossterm", "env_logger 0.10.0", "ethereum-types 0.14.1", - "ethers-signers", - "halo2-base", + "halo2-base 0.2.2 (git+https://github.com/scroll-tech/halo2-lib.git?branch=minimize-diff)", "hex", "itertools", "lazy_static", @@ -2644,14 +3842,21 @@ dependencies = [ "num-bigint", "num-integer", "num-traits", - "paste", - "pprof", "rand", "rand_chacha", "serde", "serde_json", - "snark-verifier", - "tui", + "snark-verifier 0.1.0 (git+https://github.com/scroll-tech/snark-verifier?branch=halo2-ecc-snark-verifier-0323)", +] + +[[package]] +name = "socket2" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64a4a911eed85daf18834cfaa86a79b7d266ff93ff5ba14005426219480ed662" +dependencies = [ + "libc", + "winapi", ] [[package]] @@ -2688,6 +3893,12 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9091b6114800a5f2141aee1d1b9d6ca3592ac062dc5decb3764ec5895a47b4eb" +[[package]] +name = "strsim" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" + [[package]] name = "strum" version = "0.24.1" @@ -2738,7 +3949,7 @@ dependencies = [ "debugid", "memmap2", "stable_deref_trait", - "uuid 1.3.0", + "uuid 1.3.3", ] [[package]] @@ -2765,9 +3976,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.12" +version = "2.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "79d9531f94112cfc3e4c8f5f02cb2b58f72c97b7efd85f70203cc6d8efda5927" +checksum = "32d41677bcbe24c20c52e7c70b0d8db04134c5d1066bf98662e2871ad200ea3e" dependencies = [ "proc-macro2", "quote", @@ -2790,7 +4001,7 @@ dependencies = [ "fastrand", "redox_syscall 0.3.5", "rustix", - "windows-sys", + "windows-sys 0.45.0", ] [[package]] @@ -2825,7 +4036,7 @@ checksum = "f9456a42c5b0d803c8cd86e73dd7cc9edd429499f37a3550d286d5e86720569f" dependencies = [ "proc-macro2", "quote", - "syn 2.0.12", + "syn 2.0.18", ] [[package]] @@ -2847,6 +4058,87 @@ dependencies = [ "serde_json", ] +[[package]] +name = "tinyvec" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" + +[[package]] +name = "tokio" +version = "1.28.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0aa32867d44e6f2ce3385e89dceb990188b8bb0fb25b0cf576647a6f98ac5105" +dependencies = [ + "autocfg", + "bytes", + "libc", + "mio", + "pin-project-lite", + "socket2", + "windows-sys 0.48.0", +] + +[[package]] +name = "tokio-rustls" +version = "0.23.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c43ee83903113e03984cb9e5cebe6c04a5116269e900e3ddba8f068a62adda59" +dependencies = [ + "rustls 0.20.8", + "tokio", + "webpki", +] + +[[package]] +name = "tokio-rustls" +version = "0.24.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e0d409377ff5b1e3ca6437aa86c1eb7d40c134bfec254e44c830defa92669db5" +dependencies = [ + "rustls 0.21.1", + "tokio", +] + +[[package]] +name = "tokio-tungstenite" +version = "0.17.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f714dd15bead90401d77e04243611caec13726c2408afd5b31901dfcdcb3b181" +dependencies = [ + "futures-util", + "log", + "rustls 0.20.8", + "tokio", + "tokio-rustls 0.23.4", + "tungstenite", + "webpki", + "webpki-roots", +] + +[[package]] +name = "tokio-util" +version = "0.7.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "806fe8c2c87eccc8b3267cbae29ed3ab2d0bd37fca70ab622e46aaa9375ddb7d" +dependencies = [ + "bytes", + "futures-core", + "futures-sink", + "pin-project-lite", + "tokio", + "tracing", +] + [[package]] name = "toml" version = "0.5.11" @@ -2858,21 +4150,27 @@ dependencies = [ [[package]] name = "toml_datetime" -version = "0.6.1" +version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3ab8ed2edee10b50132aed5f331333428b011c99402b5a534154ed15746f9622" +checksum = "5a76a9312f5ba4c2dec6b9161fdf25d87ad8a09256ccea5a556fef03c706a10f" [[package]] name = "toml_edit" -version = "0.19.8" +version = "0.19.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "239410c8609e8125456927e6707163a3b1fdb40561e4b803bc041f466ccfdc13" +checksum = "2380d56e8670370eee6566b0bfd4265f65b3f432e8c6d85623f728d4fa31f739" dependencies = [ "indexmap", "toml_datetime", "winnow", ] +[[package]] +name = "tower-service" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6bc1c9ce2b5135ac7f93c72918fc37feb872bdc6a5533a8b85eb4b86bfdae52" + [[package]] name = "tracing" version = "0.1.37" @@ -2887,24 +4185,40 @@ dependencies = [ [[package]] name = "tracing-attributes" -version = "0.1.23" +version = "0.1.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4017f8f45139870ca7e672686113917c71c7a6e02d4924eda67186083c03081a" +checksum = "0f57e3ca2a01450b1a921183a9c9cbfda207fd822cef4ccb00a65402cbba7a74" dependencies = [ "proc-macro2", "quote", - "syn 1.0.109", + "syn 2.0.18", ] [[package]] name = "tracing-core" -version = "0.1.30" +version = "0.1.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "24eb03ba0eab1fd845050058ce5e616558e8f8d8fca633e6b163fe25c797213a" +checksum = "0955b8137a1df6f1a2e9a37d8a6656291ff0297c1a97c24e0d8425fe2312f79a" dependencies = [ "once_cell", ] +[[package]] +name = "tracing-futures" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97d095ae15e245a057c8e8451bab9b3ee1e1f68e9ba2b4fbc18d0ac5237835f2" +dependencies = [ + "pin-project", + "tracing", +] + +[[package]] +name = "try-lock" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3528ecfd12c466c6f163363caf2d02a71161dd5e1cc6ae7b34207ea2d42d81ed" + [[package]] name = "tui" version = "0.19.0" @@ -2918,6 +4232,27 @@ dependencies = [ "unicode-width", ] +[[package]] +name = "tungstenite" +version = "0.17.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e27992fd6a8c29ee7eef28fc78349aa244134e10ad447ce3b9f0ac0ed0fa4ce0" +dependencies = [ + "base64 0.13.1", + "byteorder", + "bytes", + "http", + "httparse", + "log", + "rand", + "rustls 0.20.8", + "sha-1", + "thiserror", + "url", + "utf-8", + "webpki", +] + [[package]] name = "typenum" version = "1.16.0" @@ -2936,11 +4271,26 @@ dependencies = [ "static_assertions", ] +[[package]] +name = "unicode-bidi" +version = "0.3.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92888ba5573ff080736b3648696b70cafad7d250551175acbaa4e0385b3e1460" + [[package]] name = "unicode-ident" -version = "1.0.8" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b15811caf2415fb889178633e7724bad2509101cde276048e013b9def5e51fa0" + +[[package]] +name = "unicode-normalization" +version = "0.1.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5464a87b239f13a63a501f2701565754bae92d243d4bb7eb12f6d57d2269bf4" +checksum = "5c5713f0fc4b5db668a2ac63cdb7bb4469d8c9fed047b1d0292cc7b0ce2ba921" +dependencies = [ + "tinyvec", +] [[package]] name = "unicode-segmentation" @@ -2960,6 +4310,29 @@ version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" +[[package]] +name = "untrusted" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a" + +[[package]] +name = "url" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d68c799ae75762b8c3fe375feb6600ef5602c883c5d21eb51c09f22b83c4643" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", +] + +[[package]] +name = "utf-8" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" + [[package]] name = "uuid" version = "0.8.2" @@ -2972,9 +4345,9 @@ dependencies = [ [[package]] name = "uuid" -version = "1.3.0" +version = "1.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1674845326ee10d37ca60470760d4288a6f80f304007d92e5c53bab78c9cfd79" +checksum = "345444e32442451b267fc254ae85a209c64be56d2890e601a0c37ff0c3c5ecd2" [[package]] name = "version_check" @@ -2992,6 +4365,16 @@ dependencies = [ "winapi-util", ] +[[package]] +name = "want" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ce8a968cb1cd110d136ff8b819a556d6fb6d919363c61534f6860c7eb172ba0" +dependencies = [ + "log", + "try-lock", +] + [[package]] name = "wasi" version = "0.11.0+wasi-snapshot-preview1" @@ -3000,9 +4383,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" -version = "0.2.84" +version = "0.2.86" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "31f8dcbc21f30d9b8f2ea926ecb58f6b91192c17e9d33594b3df58b2007ca53b" +checksum = "5bba0e8cb82ba49ff4e229459ff22a191bbe9a1cb3a341610c9c33efc27ddf73" dependencies = [ "cfg-if 1.0.0", "wasm-bindgen-macro", @@ -3010,24 +4393,36 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.84" +version = "0.2.86" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95ce90fd5bcc06af55a641a86428ee4229e44e07033963a2290a8e241607ccb9" +checksum = "19b04bc93f9d6bdee709f6bd2118f57dd6679cf1176a1af464fca3ab0d66d8fb" dependencies = [ "bumpalo", "log", "once_cell", "proc-macro2", "quote", - "syn 1.0.109", + "syn 2.0.18", "wasm-bindgen-shared", ] +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2d1985d03709c53167ce907ff394f5316aa22cb4e12761295c5dc57dacb6297e" +dependencies = [ + "cfg-if 1.0.0", + "js-sys", + "wasm-bindgen", + "web-sys", +] + [[package]] name = "wasm-bindgen-macro" -version = "0.2.84" +version = "0.2.86" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c21f77c0bedc37fd5dc21f897894a5ca01e7bb159884559461862ae90c0b4c5" +checksum = "14d6b024f1a526bb0234f52840389927257beb670610081360e5a03c5df9c258" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -3035,33 +4430,67 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.84" +version = "0.2.86" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2aff81306fcac3c7515ad4e177f521b5c9a15f2b08f4e32d823066102f35a5f6" +checksum = "e128beba882dd1eb6200e1dc92ae6c5dbaa4311aa7bb211ca035779e5efc39f8" dependencies = [ "proc-macro2", "quote", - "syn 1.0.109", + "syn 2.0.18", "wasm-bindgen-backend", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-shared" -version = "0.2.84" +version = "0.2.86" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed9d5b4305409d1fc9482fee2d7f9bcbf24b3972bf59817ef757e23982242a93" + +[[package]] +name = "wasm-timer" +version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0046fef7e28c3804e5e38bfa31ea2a0f73905319b677e57ebe37e49358989b5d" +checksum = "be0ecb0db480561e9a7642b5d3e4187c128914e58aa84330b9493e3eb68c5e7f" +dependencies = [ + "futures", + "js-sys", + "parking_lot 0.11.2", + "pin-utils", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", +] [[package]] name = "web-sys" -version = "0.3.61" +version = "0.3.63" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e33b99f4b23ba3eec1a53ac264e35a755f00e966e0065077d6027c0f575b0b97" +checksum = "3bdd9ef4e984da1187bf8110c5cf5b845fbc87a23602cdf912386a76fcd3a7c2" dependencies = [ "js-sys", "wasm-bindgen", ] +[[package]] +name = "webpki" +version = "0.22.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f095d78192e208183081cc07bc5515ef55216397af48b873e5edcd72637fa1bd" +dependencies = [ + "ring", + "untrusted", +] + +[[package]] +name = "webpki-roots" +version = "0.22.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6c71e40d7d2c34a5106301fb632274ca37242cd0c9d3e64dbece371a40a2d87" +dependencies = [ + "webpki", +] + [[package]] name = "winapi" version = "0.3.9" @@ -3099,7 +4528,16 @@ version = "0.45.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0" dependencies = [ - "windows-targets", + "windows-targets 0.42.2", +] + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.0", ] [[package]] @@ -3108,13 +4546,28 @@ version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8e5180c00cd44c9b1c88adb3693291f1cd93605ded80c250a75d472756b4d071" dependencies = [ - "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_gnullvm", - "windows_x86_64_msvc", + "windows_aarch64_gnullvm 0.42.2", + "windows_aarch64_msvc 0.42.2", + "windows_i686_gnu 0.42.2", + "windows_i686_msvc 0.42.2", + "windows_x86_64_gnu 0.42.2", + "windows_x86_64_gnullvm 0.42.2", + "windows_x86_64_msvc 0.42.2", +] + +[[package]] +name = "windows-targets" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b1eb6f0cd7c80c79759c929114ef071b87354ce476d9d94271031c0497adfd5" +dependencies = [ + "windows_aarch64_gnullvm 0.48.0", + "windows_aarch64_msvc 0.48.0", + "windows_i686_gnu 0.48.0", + "windows_i686_msvc 0.48.0", + "windows_x86_64_gnu 0.48.0", + "windows_x86_64_gnullvm 0.48.0", + "windows_x86_64_msvc 0.48.0", ] [[package]] @@ -3123,51 +4576,121 @@ version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "597a5118570b68bc08d8d59125332c54f1ba9d9adeedeef5b99b02ba2b0698f8" +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91ae572e1b79dba883e0d315474df7305d12f569b400fcf90581b06062f7e1bc" + [[package]] name = "windows_aarch64_msvc" version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e08e8864a60f06ef0d0ff4ba04124db8b0fb3be5776a5cd47641e942e58c4d43" +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2ef27e0d7bdfcfc7b868b317c1d32c641a6fe4629c171b8928c7b08d98d7cf3" + [[package]] name = "windows_i686_gnu" version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c61d927d8da41da96a81f029489353e68739737d3beca43145c8afec9a31a84f" +[[package]] +name = "windows_i686_gnu" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "622a1962a7db830d6fd0a69683c80a18fda201879f0f447f065a3b7467daa241" + [[package]] name = "windows_i686_msvc" version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "44d840b6ec649f480a41c8d80f9c65108b92d89345dd94027bfe06ac444d1060" +[[package]] +name = "windows_i686_msvc" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4542c6e364ce21bf45d69fdd2a8e455fa38d316158cfd43b3ac1c5b1b19f8e00" + [[package]] name = "windows_x86_64_gnu" version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8de912b8b8feb55c064867cf047dda097f92d51efad5b491dfb98f6bbb70cb36" +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca2b8a661f7628cbd23440e50b05d705db3686f894fc9580820623656af974b1" + [[package]] name = "windows_x86_64_gnullvm" version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "26d41b46a36d453748aedef1486d5c7a85db22e56aff34643984ea85514e94a3" +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7896dbc1f41e08872e9d5e8f8baa8fdd2677f29468c4e156210174edc7f7b953" + [[package]] name = "windows_x86_64_msvc" version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9aec5da331524158c6d1a4ac0ab1541149c0b9505fde06423b02f5ef0106b9f0" +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a" + [[package]] name = "winnow" -version = "0.4.1" +version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae8970b36c66498d8ff1d66685dc86b91b29db0c7739899012f63a63814b4b28" +checksum = "61de7bac303dc551fe038e2b3cef0f571087a47571ea6e79a87692ac99b99699" dependencies = [ "memchr", ] +[[package]] +name = "winreg" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "80d0f4e272c85def139476380b12f9ac60926689dd2e01d4923222f40580869d" +dependencies = [ + "winapi", +] + +[[package]] +name = "ws_stream_wasm" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7999f5f4217fe3818726b66257a4475f71e74ffd190776ad053fa159e50737f5" +dependencies = [ + "async_io_stream", + "futures", + "js-sys", + "log", + "pharos", + "rustc_version", + "send_wrapper", + "thiserror", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", +] + [[package]] name = "wyz" version = "0.5.1" @@ -3183,17 +4706,49 @@ version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2a0956f1ba7c7909bfb66c2e9e4124ab6f6482560f6628b5aaeba39207c9aad9" -[[patch.unused]] -name = "ecc" -version = "0.1.0" -source = "git+https://github.com/scroll-tech/halo2wrong.git?branch=halo2-ecc-snark-verifier-0323#939d679cb16abf0e820bd606248661e400328afa" - -[[patch.unused]] -name = "halo2wrong" +[[package]] +name = "zkevm-circuits" version = "0.1.0" -source = "git+https://github.com/scroll-tech/halo2wrong.git?branch=halo2-ecc-snark-verifier-0323#939d679cb16abf0e820bd606248661e400328afa" +source = "git+https://github.com/scroll-tech/zkevm-circuits.git?branch=develop#6c9df1a7ecc80bd8eb71f2a182d59012c44b89b3" +dependencies = [ + "array-init", + "bus-mapping", + "env_logger 0.9.3", + "eth-types", + "ethers-core", + "ethers-signers", + "gadgets", + "halo2-base 0.2.2 (git+https://github.com/scroll-tech/halo2-lib?branch=halo2-ecc-snark-verifier-0323)", + "halo2-ecc 0.2.2 (git+https://github.com/scroll-tech/halo2-lib?branch=halo2-ecc-snark-verifier-0323)", + "halo2_proofs 0.2.0 (git+https://github.com/scroll-tech/halo2.git?branch=develop)", + "hex", + "itertools", + "keccak256", + "lazy_static", + "libsecp256k1", + "log", + "maingate", + "mock", + "mpt-zktrie", + "num", + "num-bigint", + "once_cell", + "rand", + "rand_chacha", + "rand_xorshift", + "rayon", + "sha3 0.10.8", + "snark-verifier 0.1.0 (git+https://github.com/scroll-tech/snark-verifier?branch=halo2-ecc-snark-verifier-0323)", + "snark-verifier-sdk 0.0.1 (git+https://github.com/scroll-tech/snark-verifier?branch=halo2-ecc-snark-verifier-0323)", + "strum", + "strum_macros", + "subtle", +] -[[patch.unused]] -name = "maingate" -version = "0.1.0" -source = "git+https://github.com/scroll-tech/halo2wrong.git?branch=halo2-ecc-snark-verifier-0323#939d679cb16abf0e820bd606248661e400328afa" +[[package]] +name = "zktrie" +version = "0.1.2" +source = "git+https://github.com/scroll-tech/zktrie.git?branch=scroll-dev-0226#1a5562f663a81ff903383db69dc6c9404b63e69d" +dependencies = [ + "gobuild", +] diff --git a/Cargo.toml b/Cargo.toml index c12301d7..b4d7207b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -35,12 +35,10 @@ inherits = "release" debug = true [patch."https://github.com/privacy-scaling-explorations/halo2.git"] -halo2_proofs = { git = "https://github.com/scroll-tech/halo2.git", branch = "halo2-ecc-snark-verifier-0323" } +halo2_proofs = { git = "https://github.com/scroll-tech/halo2.git", branch = "develop" } [patch."https://github.com/privacy-scaling-explorations/poseidon.git"] poseidon = { git = "https://github.com/scroll-tech/poseidon.git", branch = "scroll-dev-0220" } [patch."https://github.com/privacy-scaling-explorations/halo2wrong.git"] -ecc = { git = "https://github.com/scroll-tech/halo2wrong.git", branch = "halo2-ecc-snark-verifier-0323" } halo2wrong = { git = "https://github.com/scroll-tech/halo2wrong.git", branch = "halo2-ecc-snark-verifier-0323" } -maingate = { git = "https://github.com/scroll-tech/halo2wrong", branch = "halo2-ecc-snark-verifier-0323" } [patch."https://github.com/privacy-scaling-explorations/halo2curves.git"] halo2curves = { git = "https://github.com/scroll-tech/halo2curves.git", branch = "0.3.1-derive-serde" } diff --git a/rustfmt.toml b/rustfmt.toml index f5a13f37..eabbd2a9 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -1,2 +1,2 @@ max_width = 100 -use_small_heuristics = "Max" \ No newline at end of file +use_small_heuristics = "Max" \ No newline at end of file diff --git a/snark-verifier-sdk/Cargo.toml b/snark-verifier-sdk/Cargo.toml index 92ee80d8..a5c0da65 100644 --- a/snark-verifier-sdk/Cargo.toml +++ b/snark-verifier-sdk/Cargo.toml @@ -17,8 +17,10 @@ serde_json = "1.0" bincode = "1.3.3" ark-std = { version = "0.3.0", features = ["print-trace"], optional = true } -halo2-base = { git = "https://github.com/scroll-tech/halo2-lib.git", branch = "minimize-diff", default-features=false, features=["halo2-pse","display"] } +halo2-base = { git = "https://github.com/scroll-tech/halo2-lib.git", branch = "develop", default-features=false, features=["halo2-pse","display"] } snark-verifier = { path = "../snark-verifier", default-features = false } +zkevm-circuits = { git = "https://github.com/scroll-tech/zkevm-circuits.git", branch = "develop" } +eth-types = { git = "https://github.com/scroll-tech/zkevm-circuits.git", branch = "develop" } # loader_evm ethereum-types = { version = "0.14", default-features = false, features = ["std"], optional = true } @@ -50,8 +52,6 @@ parallel = ["snark-verifier/parallel"] halo2-pse = ["snark-verifier/halo2-pse"] halo2-axiom = ["snark-verifier/halo2-axiom"] -#zkevm = [ "dep:bus-mapping", "dep:mock" ] - [[bench]] name = "standard_plonk" required-features = ["loader_halo2"] diff --git a/snark-verifier-sdk/benches/standard_plonk.rs b/snark-verifier-sdk/benches/standard_plonk.rs index e19776e9..d5f47811 100644 --- a/snark-verifier-sdk/benches/standard_plonk.rs +++ b/snark-verifier-sdk/benches/standard_plonk.rs @@ -12,11 +12,8 @@ use halo2_proofs::{ use rand::rngs::OsRng; use rand::SeedableRng; use rand_chacha::ChaCha20Rng; -use snark_verifier_sdk::CircuitExt; use snark_verifier_sdk::{ - gen_pk, - halo2::{aggregation::AggregationCircuit, gen_proof_shplonk, gen_snark_shplonk}, - Snark, + gen_pk, gen_proof_shplonk, gen_snark_shplonk, AggregationCircuit, CircuitExt, Snark, }; mod application { diff --git a/snark-verifier-sdk/benches/zkevm.rs b/snark-verifier-sdk/benches/zkevm.rs index f4c3f3fc..b1ef316f 100644 --- a/snark-verifier-sdk/benches/zkevm.rs +++ b/snark-verifier-sdk/benches/zkevm.rs @@ -12,7 +12,7 @@ use snark_verifier_sdk::{ gen_evm_verifier_shplonk, }, gen_pk, - halo2::{ + halo2_api::{ aggregation::load_verify_circuit_degree, aggregation::AggregationCircuit, gen_proof_gwc, gen_proof_shplonk, gen_snark_gwc, gen_snark_shplonk, PoseidonTranscript, POSEIDON_SPEC, }, @@ -66,14 +66,8 @@ fn bench(c: &mut Criterion) { let circuit = zkevm::test_circuit(); let params_app = gen_srs(k); let pk = gen_pk(¶ms_app, &circuit, Some(Path::new("data/zkevm_evm.pkey"))); - let snark = gen_snark_gwc( - ¶ms_app, - &pk, - circuit, - &mut transcript, - &mut rng, - Some(Path::new("data/zkevm_evm.snark")), - ); + let snark = + gen_snark_gwc(¶ms_app, &pk, circuit, &mut rng, Some(Path::new("data/zkevm_evm.snark"))); let snarks = [snark]; // === finished zkevm evm circuit === @@ -96,15 +90,7 @@ fn bench(c: &mut Criterion) { |b, &(params, pk, agg_circuit)| { b.iter(|| { let instances = agg_circuit.instances(); - gen_proof_shplonk( - params, - pk, - agg_circuit.clone(), - instances, - &mut transcript, - &mut rng, - None, - ); + gen_proof_shplonk(params, pk, agg_circuit.clone(), instances, &mut rng, None); }) }, ); @@ -118,15 +104,7 @@ fn bench(c: &mut Criterion) { |b, &(params, pk, agg_circuit)| { b.iter(|| { let instances = agg_circuit.instances(); - gen_proof_gwc( - params, - pk, - agg_circuit.clone(), - instances, - &mut transcript, - &mut rng, - None, - ); + gen_proof_gwc(params, pk, agg_circuit.clone(), instances, &mut rng, None); }) }, ); diff --git a/snark-verifier-sdk/benches/zkevm_plus_state.rs b/snark-verifier-sdk/benches/zkevm_plus_state.rs index 840f8581..0e03cefe 100644 --- a/snark-verifier-sdk/benches/zkevm_plus_state.rs +++ b/snark-verifier-sdk/benches/zkevm_plus_state.rs @@ -12,7 +12,7 @@ use snark_verifier_sdk::{ gen_evm_verifier_shplonk, }, gen_pk, - halo2::{ + halo2_api::{ aggregation::load_verify_circuit_degree, aggregation::AggregationCircuit, gen_proof_gwc, gen_proof_shplonk, gen_snark_gwc, gen_snark_shplonk, PoseidonTranscript, POSEIDON_SPEC, }, @@ -80,7 +80,6 @@ fn bench(c: &mut Criterion) { ¶ms_app, &pk, evm_circuit, - &mut transcript, &mut rng, Some(Path::new("data/zkevm_evm.snark")), ) @@ -91,7 +90,6 @@ fn bench(c: &mut Criterion) { ¶ms_app, &pk, state_circuit, - &mut transcript, &mut rng, Some(Path::new("data/zkevm_state.snark")), ) @@ -118,15 +116,7 @@ fn bench(c: &mut Criterion) { |b, &(params, pk, agg_circuit)| { b.iter(|| { let instances = agg_circuit.instances(); - gen_proof_shplonk( - params, - pk, - agg_circuit.clone(), - instances, - &mut transcript, - &mut rng, - None, - ); + gen_proof_shplonk(params, pk, agg_circuit.clone(), instances, &mut rng, None); }) }, ); @@ -140,15 +130,7 @@ fn bench(c: &mut Criterion) { |b, &(params, pk, agg_circuit)| { b.iter(|| { let instances = agg_circuit.instances(); - gen_proof_gwc( - params, - pk, - agg_circuit.clone(), - instances, - &mut transcript, - &mut rng, - None, - ); + gen_proof_gwc(params, pk, agg_circuit.clone(), instances, &mut rng, None); }) }, ); diff --git a/snark-verifier-sdk/src/aggregation.rs b/snark-verifier-sdk/src/aggregation.rs new file mode 100644 index 00000000..bbf9cde0 --- /dev/null +++ b/snark-verifier-sdk/src/aggregation.rs @@ -0,0 +1,131 @@ +#![allow(clippy::clone_on_copy)] +use crate::{ + types::{BaseFieldEccChip, Halo2Loader, Plonk, PoseidonTranscript, POSEIDON_SPEC}, + SnarkWitness, +}; +#[cfg(feature = "display")] +use ark_std::end_timer; +#[cfg(feature = "display")] +use ark_std::start_timer; +use halo2_base::{ + halo2_proofs::{ + circuit::Value, + halo2curves::bn256::{Fr, G1Affine}, + }, + AssignedValue, +}; +use itertools::Itertools; +use snark_verifier::{ + loader::halo2::EccInstructions, + pcs::{ + kzg::{KzgAccumulator, KzgAs}, + AccumulationScheme, MultiOpenScheme, PolynomialCommitmentScheme, + }, + verifier::PlonkVerifier, +}; +use std::{fs::File, rc::Rc}; + +use config::AggregationConfigParams; + +pub mod aggregation_circuit; +pub mod config; +pub mod multi_aggregation_circuit; + +pub fn load_verify_circuit_degree() -> u32 { + let path = std::env::var("VERIFY_CONFIG") + .unwrap_or_else(|_| "./configs/verify_circuit.config".to_string()); + let params: AggregationConfigParams = serde_json::from_reader( + File::open(path.as_str()).unwrap_or_else(|_| panic!("{path} does not exist")), + ) + .unwrap(); + params.degree +} + +pub fn flatten_accumulator<'a>( + accumulator: KzgAccumulator>>, +) -> Vec> { + let KzgAccumulator { lhs, rhs } = accumulator; + let lhs = lhs.into_assigned(); + let rhs = rhs.into_assigned(); + + lhs.x + .truncation + .limbs + .into_iter() + .chain(lhs.y.truncation.limbs.into_iter()) + .chain(rhs.x.truncation.limbs.into_iter()) + .chain(rhs.y.truncation.limbs.into_iter()) + .collect() +} + +#[allow(clippy::type_complexity)] +/// Core function used in `synthesize` to aggregate multiple `snarks`. +/// +/// Returns the assigned instances of previous snarks and the new final pair that needs to be verified in a pairing check. +/// For each previous snark, we concatenate all instances into a single vector. We return a vector of vectors, +/// one vector per snark, for convenience. +pub fn aggregate<'a, PCS>( + svk: &PCS::SuccinctVerifyingKey, + loader: &Rc>, + snarks: &[SnarkWitness], + as_proof: Value<&'_ [u8]>, +) -> ( + Vec>::AssignedScalar>>, + KzgAccumulator>>, +) +where + PCS: PolynomialCommitmentScheme< + G1Affine, + Rc>, + Accumulator = KzgAccumulator>>, + > + MultiOpenScheme>>, +{ + let assign_instances = |instances: &[Vec>]| { + instances + .iter() + .map(|instances| { + instances.iter().map(|instance| loader.assign_scalar(*instance)).collect_vec() + }) + .collect_vec() + }; + + // TODO pre-allocate capacity better + let mut previous_instances = Vec::with_capacity(snarks.len()); + let mut transcript = PoseidonTranscript::>, _>::from_spec( + loader, + Value::unknown(), + POSEIDON_SPEC.clone(), + ); + + let mut accumulators = snarks + .iter() + .flat_map(|snark| { + let protocol = snark.protocol.loaded(loader); + // TODO use 1d vector + let instances = assign_instances(&snark.instances); + + // read the transcript and perform Fiat-Shamir + // run through verification computation and produce the final pair `succinct` + transcript.new_stream(snark.proof()); + let proof = Plonk::::read_proof(svk, &protocol, &instances, &mut transcript); + let accumulator = Plonk::::succinct_verify(svk, &protocol, &instances, &proof); + + previous_instances.push( + instances.into_iter().flatten().map(|scalar| scalar.into_assigned()).collect(), + ); + + accumulator + }) + .collect_vec(); + + let accumulator = if accumulators.len() > 1 { + transcript.new_stream(as_proof); + let proof = + KzgAs::::read_proof(&Default::default(), &accumulators, &mut transcript).unwrap(); + KzgAs::::verify(&Default::default(), &accumulators, &proof).unwrap() + } else { + accumulators.pop().unwrap() + }; + + (previous_instances, accumulator) +} diff --git a/snark-verifier-sdk/src/aggregation/aggregation_circuit.rs b/snark-verifier-sdk/src/aggregation/aggregation_circuit.rs new file mode 100644 index 00000000..7c6ed973 --- /dev/null +++ b/snark-verifier-sdk/src/aggregation/aggregation_circuit.rs @@ -0,0 +1,243 @@ +use std::fs::File; + +use halo2_base::{ + halo2_proofs::{ + circuit::{Layouter, SimpleFloorPlanner, Value}, + halo2curves::bn256::{Bn256, Fr}, + plonk::{self, Circuit, ConstraintSystem, Error, Selector}, + poly::{commitment::ParamsProver, kzg::commitment::ParamsKZG}, + }, + Context, ContextParams, +}; +use itertools::Itertools; +use rand::Rng; +use snark_verifier::{ + loader::native::NativeLoader, + pcs::{kzg::KzgAccumulator, AccumulationSchemeProver}, + util::arithmetic::fe_to_limbs, + verifier::PlonkVerifier, +}; +use zkevm_circuits::{ + util::{Challenges, SubCircuit}, + witness::Block, +}; + +use crate::{ + aggregation::{ + aggregate, + config::{AggregationConfig, AggregationConfigParams}, + flatten_accumulator, POSEIDON_SPEC, + }, + types::{Halo2Loader, KzgAs, KzgBDFG, PoseidonTranscript, Shplonk, Svk}, + CircuitExt, Snark, SnarkWitness, BITS, LIMBS, +}; + +/// Aggregation circuit that does not re-expose any public inputs from aggregated snarks +/// +/// This is mostly a reference implementation. In practice one will probably need to re-implement the circuit for one's particular use case with specific instance logic. +#[derive(Clone)] +pub struct AggregationCircuit { + pub(crate) svk: Svk, + pub(crate) snarks: Vec, + // the public instances from previous snarks that were aggregated, now collected as PRIVATE assigned values + // the user can optionally append these to `inner.assigned_instances` to expose them + pub(crate) instances: Vec, + // accumulation scheme proof, private input + pub(crate) as_proof: Value>, +} + +impl AggregationCircuit { + pub fn new( + params: &ParamsKZG, + snarks: impl IntoIterator, + rng: impl Rng + Send, + ) -> Self { + let svk = params.get_g()[0].into(); + let snarks = snarks.into_iter().collect_vec(); + + // TODO: this is all redundant calculation to get the public output + // Halo2 should just be able to expose public output to instance column directly + let mut transcript_read = + PoseidonTranscript::::from_spec(&[], POSEIDON_SPEC.clone()); + let accumulators = snarks + .iter() + .flat_map(|snark| { + transcript_read.new_stream(snark.proof.as_slice()); + let proof = Shplonk::read_proof( + &svk, + &snark.protocol, + &snark.instances, + &mut transcript_read, + ); + Shplonk::succinct_verify(&svk, &snark.protocol, &snark.instances, &proof) + }) + .collect_vec(); + + let (accumulator, as_proof) = { + let mut transcript_write = PoseidonTranscript::>::from_spec( + vec![], + POSEIDON_SPEC.clone(), + ); + // We always use SHPLONK for accumulation scheme when aggregating proofs + let accumulator = + KzgAs::create_proof(&Default::default(), &accumulators, &mut transcript_write, rng) + .unwrap(); + (accumulator, transcript_write.finalize()) + }; + + let KzgAccumulator { lhs, rhs } = accumulator; + let instances = [lhs.x, lhs.y, rhs.x, rhs.y].map(fe_to_limbs::<_, _, LIMBS, BITS>).concat(); + + Self { + svk, + snarks: snarks.into_iter().map_into().collect(), + instances, + as_proof: Value::known(as_proof), + } + } + + pub fn instance(&self) -> Vec { + self.instances.clone() + } + + pub fn succinct_verifying_key(&self) -> &Svk { + &self.svk + } + + pub fn snarks(&self) -> &[SnarkWitness] { + &self.snarks + } + + pub fn as_proof(&self) -> Value<&[u8]> { + self.as_proof.as_ref().map(Vec::as_slice) + } +} + +impl CircuitExt for AggregationCircuit { + fn num_instance(&self) -> Vec { + // [..lhs, ..rhs] + vec![4 * LIMBS] + } + + fn instances(&self) -> Vec> { + vec![self.instance()] + } + + fn accumulator_indices() -> Option> { + Some((0..4 * LIMBS).map(|idx| (0, idx)).collect()) + } + + fn selectors(config: &Self::Config) -> Vec { + config.gate().basic_gates[0].iter().map(|gate| gate.q_enable).collect() + } +} + +impl Circuit for AggregationCircuit { + type Config = AggregationConfig; + type FloorPlanner = SimpleFloorPlanner; + + fn without_witnesses(&self) -> Self { + Self { + svk: self.svk, + snarks: self.snarks.iter().map(SnarkWitness::without_witnesses).collect(), + instances: Vec::new(), + as_proof: Value::unknown(), + } + } + + fn configure(meta: &mut ConstraintSystem) -> Self::Config { + let path = std::env::var("VERIFY_CONFIG") + .unwrap_or_else(|_| "configs/verify_circuit.config".to_owned()); + let params: AggregationConfigParams = serde_json::from_reader( + File::open(path.as_str()).unwrap_or_else(|_| panic!("{path:?} does not exist")), + ) + .unwrap(); + + AggregationConfig::configure(meta, params) + } + + fn synthesize( + &self, + config: Self::Config, + mut layouter: impl Layouter, + ) -> Result<(), plonk::Error> { + let challenge = Challenges::default(); + self.synthesize_sub(&config, &challenge, &mut layouter) + } +} + +impl SubCircuit for AggregationCircuit { + type Config = AggregationConfig; + + fn new_from_block(_block: &Block) -> Self { + // we cannot instantiate a new Self from a single block + unimplemented!() + } + + /// Return the minimum number of rows required to prove the block + /// Row numbers without/with padding are both returned. + fn min_num_rows_block(_block: &Block) -> (usize, usize) { + // there is no min num rows per block for aggregation circuit + unimplemented!() + } + + /// Compute the public inputs for this circuit. + fn instance(&self) -> Vec> { + >::instances(self) + } + + /// Make the assignments to the BatchHashCircuit + fn synthesize_sub( + &self, + config: &Self::Config, + _challenges: &Challenges>, + layouter: &mut impl Layouter, + ) -> Result<(), Error> { + #[cfg(feature = "display")] + let witness_time = start_timer!(|| "synthesize | Aggregation Circuit"); + config.range().load_lookup_table(layouter).expect("load range lookup table"); + let mut first_pass = halo2_base::SKIP_FIRST_PASS; + let mut instances = vec![]; + layouter + .assign_region( + || "", + |region| { + if first_pass { + first_pass = false; + return Ok(()); + } + let ctx = Context::new( + region, + ContextParams { + max_rows: config.gate().max_rows, + num_context_ids: 1, + fixed_columns: config.gate().constants.clone(), + }, + ); + + let ecc_chip = config.ecc_chip(); + let loader = Halo2Loader::new(ecc_chip, ctx); + let (_, acc) = + aggregate::(&self.svk, &loader, &self.snarks, self.as_proof()); + + instances.extend( + flatten_accumulator(acc).iter().map(|assigned| assigned.cell().clone()), + ); + + config.range().finalize(&mut loader.ctx_mut()); + #[cfg(feature = "display")] + loader.ctx_mut().print_stats(&["Range"]); + Ok(()) + }, + ) + .unwrap(); + + // Expose instances + for (i, cell) in instances.into_iter().enumerate() { + layouter.constrain_instance(cell, config.instance, i)?; + } + #[cfg(feature = "display")] + end_timer!(witness_time); + Ok(()) + } +} diff --git a/snark-verifier-sdk/src/aggregation/config.rs b/snark-verifier-sdk/src/aggregation/config.rs new file mode 100644 index 00000000..e92da838 --- /dev/null +++ b/snark-verifier-sdk/src/aggregation/config.rs @@ -0,0 +1,96 @@ +use halo2_base::{ + halo2_proofs::{ + halo2curves::bn256::{Fq, Fr, G1Affine}, + plonk::{Column, ConstraintSystem, Expression, Instance}, + }, + utils::modulus, +}; +use snark_verifier::loader::halo2::halo2_ecc::{ + ecc::{BaseFieldEccChip, EccChip}, + fields::fp::{FpConfig, FpStrategy}, +}; +use zkevm_circuits::util::{Challenges, SubCircuitConfig}; + +use crate::{BITS, LIMBS}; + +#[derive(serde::Serialize, serde::Deserialize, Clone, Debug)] +/// Parameters for aggregation circuit configs. +pub struct AggregationConfigParams { + pub strategy: FpStrategy, + pub degree: u32, + pub num_advice: Vec, + pub num_lookup_advice: Vec, + pub num_fixed: usize, + pub lookup_bits: usize, + pub limb_bits: usize, + pub num_limbs: usize, +} + +#[derive(Clone, Debug)] +/// Configurations for aggregation circuit +pub struct AggregationConfig { + /// Non-native field chip configurations + pub base_field_config: FpConfig, + /// Instance for public input + pub instance: Column, +} + +impl AggregationConfig { + /// Build a configuration from parameters. + pub fn configure(meta: &mut ConstraintSystem, params: AggregationConfigParams) -> Self { + assert!( + params.limb_bits == BITS && params.num_limbs == LIMBS, + "For now we fix limb_bits = {}, otherwise change code", + BITS + ); + let base_field_config = FpConfig::configure( + meta, + params.strategy, + ¶ms.num_advice, + ¶ms.num_lookup_advice, + params.num_fixed, + params.lookup_bits, + BITS, + LIMBS, + modulus::(), + 0, + params.degree as usize, + ); + + let instance = meta.instance_column(); + meta.enable_equality(instance); + + Self { base_field_config, instance } + } + + /// Range gate configuration + pub fn range(&self) -> &halo2_base::gates::range::RangeConfig { + &self.base_field_config.range + } + + /// Flex gate configuration + pub fn gate(&self) -> &halo2_base::gates::flex_gate::FlexGateConfig { + &self.base_field_config.range.gate + } + + /// Ecc gate configuration + pub fn ecc_chip(&self) -> BaseFieldEccChip { + EccChip::construct(self.base_field_config.clone()) + } +} + +/// Auxiliary arguments for AggregationCircuit's Config +#[derive(Clone, Debug)] +pub struct AggregationConfigArgs { + pub param: AggregationConfigParams, + pub challenges: Challenges>, +} + +impl SubCircuitConfig for AggregationConfig { + type ConfigArgs = AggregationConfigArgs; + + /// Return a new AggregationConfig + fn new(meta: &mut ConstraintSystem, config_args: Self::ConfigArgs) -> Self { + Self::configure(meta, config_args.param) + } +} diff --git a/snark-verifier-sdk/src/aggregation/multi_aggregation_circuit.rs b/snark-verifier-sdk/src/aggregation/multi_aggregation_circuit.rs new file mode 100644 index 00000000..967c29af --- /dev/null +++ b/snark-verifier-sdk/src/aggregation/multi_aggregation_circuit.rs @@ -0,0 +1,199 @@ +#![allow(clippy::clone_on_copy)] +use crate::{ + aggregation::{aggregate, flatten_accumulator}, + types::Halo2Loader, + CircuitExt, Snark, LIMBS, +}; +#[cfg(feature = "display")] +use ark_std::end_timer; +#[cfg(feature = "display")] +use ark_std::start_timer; +use halo2_base::utils::value_to_option; +use halo2_base::{ + halo2_proofs::{ + circuit::{Layouter, SimpleFloorPlanner, Value}, + halo2curves::bn256::{Bn256, Fr}, + plonk::{self, Circuit, Error, Selector}, + poly::kzg::commitment::ParamsKZG, + }, + Context, ContextParams, +}; +use itertools::Itertools; +use rand::Rng; +use snark_verifier::pcs::kzg::{Bdfg21, Kzg}; +use zkevm_circuits::{ + util::{Challenges, SubCircuit}, + witness::Block, +}; + +use super::{aggregation_circuit::AggregationCircuit, config::AggregationConfig}; + +/// This circuit takes multiple SNARKs and passes through all of their instances except the old accumulators. +/// +/// * If `has_prev_accumulator = true`, we assume all SNARKs are of aggregation circuits with old accumulators +/// only in the first instance column. +/// * Otherwise if `has_prev_accumulator = false`, then all previous instances are passed through. +#[derive(Clone)] +pub struct PublicAggregationCircuit { + pub aggregation: AggregationCircuit, + pub has_prev_accumulator: bool, +} + +impl PublicAggregationCircuit { + pub fn new( + params: &ParamsKZG, + snarks: Vec, + has_prev_accumulator: bool, + rng: &mut (impl Rng + Send), + ) -> Self { + Self { aggregation: AggregationCircuit::new(params, snarks, rng), has_prev_accumulator } + } +} + +impl CircuitExt for PublicAggregationCircuit { + fn num_instance(&self) -> Vec { + let prev_num = self + .aggregation + .snarks + .iter() + .map(|snark| snark.instances.iter().map(|instance| instance.len()).sum::()) + .sum::() + - self.aggregation.snarks.len() * 4 * LIMBS * usize::from(self.has_prev_accumulator); + vec![4 * LIMBS + prev_num] + } + + fn instances(&self) -> Vec> { + let start_idx = 4 * LIMBS * usize::from(self.has_prev_accumulator); + let instance = self + .aggregation + .instances + .iter() + .cloned() + .chain(self.aggregation.snarks.iter().flat_map(|snark| { + snark.instances.iter().enumerate().flat_map(|(i, instance)| { + instance[usize::from(i == 0) * start_idx..] + .iter() + .map(|v| value_to_option(*v).unwrap()) + }) + })) + .collect_vec(); + vec![instance] + } + + fn accumulator_indices() -> Option> { + Some((0..4 * LIMBS).map(|idx| (0, idx)).collect()) + } + + fn selectors(config: &Self::Config) -> Vec { + AggregationCircuit::selectors(config) + } +} + +impl Circuit for PublicAggregationCircuit { + type Config = AggregationConfig; + type FloorPlanner = SimpleFloorPlanner; + + fn without_witnesses(&self) -> Self { + Self { + aggregation: self.aggregation.without_witnesses(), + has_prev_accumulator: self.has_prev_accumulator, + } + } + + fn configure(meta: &mut plonk::ConstraintSystem) -> Self::Config { + AggregationCircuit::configure(meta) + } + + fn synthesize( + &self, + config: Self::Config, + mut layouter: impl Layouter, + ) -> Result<(), plonk::Error> { + let challenge = Challenges::default(); + self.synthesize_sub(&config, &challenge, &mut layouter) + } +} + +impl SubCircuit for PublicAggregationCircuit { + type Config = AggregationConfig; + + fn new_from_block(_block: &Block) -> Self { + // we cannot instantiate a new Self from a single block + unimplemented!() + } + + /// Return the minimum number of rows required to prove the block + /// Row numbers without/with padding are both returned. + fn min_num_rows_block(_block: &Block) -> (usize, usize) { + // there is no min num rows per block for aggregation circuit + unimplemented!() + } + + /// Compute the public inputs for this circuit. + fn instance(&self) -> Vec> { + >::instances(self) + } + + /// Make the assignments to the BatchHashCircuit + fn synthesize_sub( + &self, + config: &Self::Config, + _challenges: &Challenges>, + layouter: &mut impl Layouter, + ) -> Result<(), Error> { + #[cfg(feature = "display")] + let witness_time = start_timer!(|| { "synthesize | EVM verifier" }); + config.range().load_lookup_table(layouter).expect("load range lookup table"); + let mut first_pass = halo2_base::SKIP_FIRST_PASS; + let mut instances = vec![]; + layouter + .assign_region( + || "", + |region| { + if first_pass { + first_pass = false; + return Ok(()); + } + let ctx = Context::new( + region, + ContextParams { + max_rows: config.gate().max_rows, + num_context_ids: 1, + fixed_columns: config.gate().constants.clone(), + }, + ); + + let ecc_chip = config.ecc_chip(); + let loader = Halo2Loader::new(ecc_chip, ctx); + let (prev_instances, acc) = aggregate::>( + &self.aggregation.svk, + &loader, + &self.aggregation.snarks, + self.aggregation.as_proof(), + ); + + // accumulator + instances.extend(flatten_accumulator(acc).iter().map(|a| a.cell().clone())); + // prev instances except accumulators + let start_idx = 4 * LIMBS * usize::from(self.has_prev_accumulator); + for prev_instance in prev_instances { + instances + .extend(prev_instance[start_idx..].iter().map(|a| a.cell().clone())); + } + + config.range().finalize(&mut loader.ctx_mut()); + #[cfg(feature = "display")] + loader.ctx_mut().print_stats(&["Range"]); + Ok(()) + }, + ) + .unwrap(); + // Expose instances + for (i, cell) in instances.into_iter().enumerate() { + layouter.constrain_instance(cell, config.instance, i)?; + } + #[cfg(feature = "display")] + end_timer!(witness_time); + Ok(()) + } +} diff --git a/snark-verifier-sdk/src/circuit_ext.rs b/snark-verifier-sdk/src/circuit_ext.rs new file mode 100644 index 00000000..e0ed0753 --- /dev/null +++ b/snark-verifier-sdk/src/circuit_ext.rs @@ -0,0 +1,28 @@ +use halo2_base::halo2_proofs::{ + arithmetic::Field, + plonk::{Circuit, Selector}, +}; + +/// Circuit Extension trait that exposes related APIs. +pub trait CircuitExt: Circuit { + /// Return the number of instances of the circuit. + /// This may depend on extra circuit parameters but NOT on private witnesses. + fn num_instance(&self) -> Vec { + vec![] + } + + /// Expose the instance for the circuit + fn instances(&self) -> Vec> { + vec![] + } + + /// The indices of the accumulator + fn accumulator_indices() -> Option> { + None + } + + /// Output the simple selector columns (before selector compression) of the circuit + fn selectors(_: &Self::Config) -> Vec { + vec![] + } +} diff --git a/snark-verifier-sdk/src/evm.rs b/snark-verifier-sdk/src/evm_api.rs similarity index 94% rename from snark-verifier-sdk/src/evm.rs rename to snark-verifier-sdk/src/evm_api.rs index 0fe87aad..4f53e94f 100644 --- a/snark-verifier-sdk/src/evm.rs +++ b/snark-verifier-sdk/src/evm_api.rs @@ -1,6 +1,9 @@ -use super::{CircuitExt, Plonk}; +use crate::{circuit_ext::CircuitExt, types::Plonk}; + +#[cfg(feature = "display")] +use ark_std::end_timer; #[cfg(feature = "display")] -use ark_std::{end_timer, start_timer}; +use ark_std::start_timer; use ethereum_types::Address; use halo2_base::halo2_proofs::{ halo2curves::bn256::{Bn256, Fq, Fr, G1Affine}, @@ -29,7 +32,7 @@ use snark_verifier::{ system::halo2::{compile, transcript::evm::EvmTranscript, Config}, verifier::PlonkVerifier, }; -use std::{fs, io, path::Path, rc::Rc}; +use std::{fs, path::Path, rc::Rc}; /// Generates a proof for evm verification using either SHPLONK or GWC proving method. Uses Keccak for Fiat-Shamir. pub fn gen_evm_proof<'params, C, P, V>( @@ -191,10 +194,3 @@ pub fn evm_verify(deployment_code: Vec, instances: Vec>, proof: Vec< }; assert!(success); } - -pub fn write_calldata(instances: &[Vec], proof: &[u8], path: &Path) -> io::Result { - let calldata = encode_calldata(instances, proof); - let calldata = hex::encode(calldata); - fs::write(path, &calldata)?; - Ok(calldata) -} diff --git a/snark-verifier-sdk/src/file_io.rs b/snark-verifier-sdk/src/file_io.rs new file mode 100644 index 00000000..b56c4591 --- /dev/null +++ b/snark-verifier-sdk/src/file_io.rs @@ -0,0 +1,82 @@ +use std::{ + fs::{write, File}, + io::{BufReader, BufWriter}, + path::Path, +}; + +use halo2_base::halo2_proofs::{ + halo2curves::bn256::{Fr, G1Affine}, + plonk::{Circuit, ProvingKey}, + SerdeFormat, +}; +use itertools::Itertools; +use snark_verifier::loader::evm::encode_calldata; + +use crate::Snark; + +/// Read instances from the disk +pub fn read_instances(path: impl AsRef) -> Result>, bincode::Error> { + let f = File::open(path)?; + let reader = BufReader::new(f); + let instances: Vec> = bincode::deserialize_from(reader)?; + instances + .into_iter() + .map(|instance_column| { + instance_column + .iter() + .map(|bytes| { + Option::from(Fr::from_bytes(bytes)).ok_or(Box::new(bincode::ErrorKind::Custom( + "Invalid finite field point".to_owned(), + ))) + }) + .collect::, _>>() + }) + .collect() +} + +/// Write instances to the disk +pub fn write_instances(instances: &[&[Fr]], path: impl AsRef) { + let instances: Vec> = instances + .iter() + .map(|instance_column| instance_column.iter().map(|x| x.to_bytes()).collect_vec()) + .collect_vec(); + let f = BufWriter::new(File::create(path).unwrap()); + bincode::serialize_into(f, &instances).unwrap(); +} + +/// Read proving key from the disk +pub fn read_pk>(path: &Path) -> std::io::Result> { + let f = File::open(path)?; + #[cfg(feature = "display")] + let read_time = start_timer!(|| format!("Reading pkey from {path:?}")); + + // BufReader is indeed MUCH faster than Read + let mut bufreader = BufReader::new(f); + // But it's even faster to load the whole file into memory first and then process, + // HOWEVER this requires twice as much memory to initialize + // let initial_buffer_size = f.metadata().map(|m| m.len() as usize + 1).unwrap_or(0); + // let mut bufreader = Vec::with_capacity(initial_buffer_size); + // f.read_to_end(&mut bufreader)?; + let pk = ProvingKey::read::<_, C>(&mut bufreader, SerdeFormat::RawBytesUnchecked).unwrap(); + + #[cfg(feature = "display")] + end_timer!(read_time); + + Ok(pk) +} + +/// Tries to deserialize a SNARK from the specified `path` using `bincode`. +/// +/// WARNING: The user must keep track of whether the SNARK was generated using the GWC or SHPLONK multi-open scheme. +pub fn read_snark(path: impl AsRef) -> Result { + let f = File::open(path).map_err(Box::::from)?; + bincode::deserialize_from(f) +} + +/// Write the calldata to disk +pub fn write_calldata(instances: &[Vec], proof: &[u8], path: &Path) -> std::io::Result { + let calldata = encode_calldata(instances, proof); + let calldata = hex::encode(calldata); + write(path, &calldata)?; + Ok(calldata) +} diff --git a/snark-verifier-sdk/src/halo2/aggregation.rs b/snark-verifier-sdk/src/halo2/aggregation.rs deleted file mode 100644 index 7e874627..00000000 --- a/snark-verifier-sdk/src/halo2/aggregation.rs +++ /dev/null @@ -1,522 +0,0 @@ -#![allow(clippy::clone_on_copy)] -use crate::{Plonk, BITS, LIMBS}; -#[cfg(feature = "display")] -use ark_std::{end_timer, start_timer}; -use halo2_base::{ - halo2_proofs::{ - circuit::{Layouter, SimpleFloorPlanner, Value}, - halo2curves::bn256::{Bn256, Fq, Fr, G1Affine}, - plonk::{self, Circuit, Column, ConstraintSystem, Instance, Selector}, - poly::{commitment::ParamsProver, kzg::commitment::ParamsKZG}, - }, - utils::value_to_option, - AssignedValue, -}; -use halo2_base::{Context, ContextParams}; -use itertools::Itertools; -use rand::Rng; -use snark_verifier::{ - loader::{ - self, - halo2::{ - halo2_ecc::{self, ecc::EccChip}, - EccInstructions, - }, - native::NativeLoader, - }, - pcs::{ - kzg::{Bdfg21, Kzg, KzgAccumulator, KzgAs, KzgSuccinctVerifyingKey}, - AccumulationScheme, AccumulationSchemeProver, MultiOpenScheme, PolynomialCommitmentScheme, - }, - util::arithmetic::fe_to_limbs, - verifier::PlonkVerifier, -}; -use std::{fs::File, rc::Rc}; - -use super::{CircuitExt, PoseidonTranscript, Snark, SnarkWitness, POSEIDON_SPEC}; - -pub type Svk = KzgSuccinctVerifyingKey; -pub type BaseFieldEccChip = halo2_ecc::ecc::BaseFieldEccChip; -pub type Halo2Loader<'a> = loader::halo2::Halo2Loader<'a, G1Affine, BaseFieldEccChip>; -pub type Shplonk = Plonk>; - -pub fn load_verify_circuit_degree() -> u32 { - let path = std::env::var("VERIFY_CONFIG") - .unwrap_or_else(|_| "./configs/verify_circuit.config".to_string()); - let params: AggregationConfigParams = serde_json::from_reader( - File::open(path.as_str()).unwrap_or_else(|_| panic!("{path} does not exist")), - ) - .unwrap(); - params.degree -} - -pub fn flatten_accumulator<'a>( - accumulator: KzgAccumulator>>, -) -> Vec> { - let KzgAccumulator { lhs, rhs } = accumulator; - let lhs = lhs.into_assigned(); - let rhs = rhs.into_assigned(); - - lhs.x - .truncation - .limbs - .into_iter() - .chain(lhs.y.truncation.limbs.into_iter()) - .chain(rhs.x.truncation.limbs.into_iter()) - .chain(rhs.y.truncation.limbs.into_iter()) - .collect() -} - -#[allow(clippy::type_complexity)] -/// Core function used in `synthesize` to aggregate multiple `snarks`. -/// -/// Returns the assigned instances of previous snarks and the new final pair that needs to be verified in a pairing check. -/// For each previous snark, we concatenate all instances into a single vector. We return a vector of vectors, -/// one vector per snark, for convenience. -pub fn aggregate<'a, PCS>( - svk: &PCS::SuccinctVerifyingKey, - loader: &Rc>, - snarks: &[SnarkWitness], - as_proof: Value<&'_ [u8]>, -) -> ( - Vec>::AssignedScalar>>, - KzgAccumulator>>, -) -where - PCS: PolynomialCommitmentScheme< - G1Affine, - Rc>, - Accumulator = KzgAccumulator>>, - > + MultiOpenScheme>>, -{ - let assign_instances = |instances: &[Vec>]| { - instances - .iter() - .map(|instances| { - instances.iter().map(|instance| loader.assign_scalar(*instance)).collect_vec() - }) - .collect_vec() - }; - - // TODO pre-allocate capacity better - let mut previous_instances = Vec::with_capacity(snarks.len()); - let mut transcript = PoseidonTranscript::>, _>::from_spec( - loader, - Value::unknown(), - POSEIDON_SPEC.clone(), - ); - - let mut accumulators = snarks - .iter() - .flat_map(|snark| { - let protocol = snark.protocol.loaded(loader); - // TODO use 1d vector - let instances = assign_instances(&snark.instances); - - // read the transcript and perform Fiat-Shamir - // run through verification computation and produce the final pair `succinct` - transcript.new_stream(snark.proof()); - let proof = Plonk::::read_proof(svk, &protocol, &instances, &mut transcript); - let accumulator = Plonk::::succinct_verify(svk, &protocol, &instances, &proof); - - previous_instances.push( - instances.into_iter().flatten().map(|scalar| scalar.into_assigned()).collect(), - ); - - accumulator - }) - .collect_vec(); - - let accumulator = if accumulators.len() > 1 { - transcript.new_stream(as_proof); - let proof = - KzgAs::::read_proof(&Default::default(), &accumulators, &mut transcript).unwrap(); - KzgAs::::verify(&Default::default(), &accumulators, &proof).unwrap() - } else { - accumulators.pop().unwrap() - }; - - (previous_instances, accumulator) -} - -#[derive(serde::Serialize, serde::Deserialize)] -pub struct AggregationConfigParams { - pub strategy: halo2_ecc::fields::fp::FpStrategy, - pub degree: u32, - pub num_advice: Vec, - pub num_lookup_advice: Vec, - pub num_fixed: usize, - pub lookup_bits: usize, - pub limb_bits: usize, - pub num_limbs: usize, -} - -#[derive(Clone, Debug)] -pub struct AggregationConfig { - pub base_field_config: halo2_ecc::fields::fp::FpConfig, - pub instance: Column, -} - -impl AggregationConfig { - pub fn configure(meta: &mut ConstraintSystem, params: AggregationConfigParams) -> Self { - assert!( - params.limb_bits == BITS && params.num_limbs == LIMBS, - "For now we fix limb_bits = {}, otherwise change code", - BITS - ); - let base_field_config = halo2_ecc::fields::fp::FpConfig::configure( - meta, - params.strategy, - ¶ms.num_advice, - ¶ms.num_lookup_advice, - params.num_fixed, - params.lookup_bits, - BITS, - LIMBS, - halo2_base::utils::modulus::(), - 0, - params.degree as usize, - ); - - let instance = meta.instance_column(); - meta.enable_equality(instance); - - Self { base_field_config, instance } - } - - pub fn range(&self) -> &halo2_base::gates::range::RangeConfig { - &self.base_field_config.range - } - - pub fn gate(&self) -> &halo2_base::gates::flex_gate::FlexGateConfig { - &self.base_field_config.range.gate - } - - pub fn ecc_chip(&self) -> halo2_ecc::ecc::BaseFieldEccChip { - EccChip::construct(self.base_field_config.clone()) - } -} - -/// Aggregation circuit that does not re-expose any public inputs from aggregated snarks -/// -/// This is mostly a reference implementation. In practice one will probably need to re-implement the circuit for one's particular use case with specific instance logic. -#[derive(Clone)] -pub struct AggregationCircuit { - svk: Svk, - snarks: Vec, - // the public instances from previous snarks that were aggregated, now collected as PRIVATE assigned values - // the user can optionally append these to `inner.assigned_instances` to expose them - instances: Vec, - // accumulation scheme proof, private input - as_proof: Value>, -} - -impl AggregationCircuit { - pub fn new( - params: &ParamsKZG, - snarks: impl IntoIterator, - rng: impl Rng + Send, - ) -> Self { - let svk = params.get_g()[0].into(); - let snarks = snarks.into_iter().collect_vec(); - - // TODO: this is all redundant calculation to get the public output - // Halo2 should just be able to expose public output to instance column directly - let mut transcript_read = - PoseidonTranscript::::from_spec(&[], POSEIDON_SPEC.clone()); - let accumulators = snarks - .iter() - .flat_map(|snark| { - transcript_read.new_stream(snark.proof.as_slice()); - let proof = Shplonk::read_proof( - &svk, - &snark.protocol, - &snark.instances, - &mut transcript_read, - ); - Shplonk::succinct_verify(&svk, &snark.protocol, &snark.instances, &proof) - }) - .collect_vec(); - - let (accumulator, as_proof) = { - let mut transcript_write = PoseidonTranscript::>::from_spec( - vec![], - POSEIDON_SPEC.clone(), - ); - // We always use SHPLONK for accumulation scheme when aggregating proofs - let accumulator = KzgAs::>::create_proof( - &Default::default(), - &accumulators, - &mut transcript_write, - rng, - ) - .unwrap(); - (accumulator, transcript_write.finalize()) - }; - - let KzgAccumulator { lhs, rhs } = accumulator; - let instances = [lhs.x, lhs.y, rhs.x, rhs.y].map(fe_to_limbs::<_, _, LIMBS, BITS>).concat(); - - Self { - svk, - snarks: snarks.into_iter().map_into().collect(), - instances, - as_proof: Value::known(as_proof), - } - } - - pub fn instance(&self) -> Vec { - self.instances.clone() - } - - pub fn succinct_verifying_key(&self) -> &Svk { - &self.svk - } - - pub fn snarks(&self) -> &[SnarkWitness] { - &self.snarks - } - - pub fn as_proof(&self) -> Value<&[u8]> { - self.as_proof.as_ref().map(Vec::as_slice) - } -} - -impl CircuitExt for AggregationCircuit { - fn num_instance(&self) -> Vec { - // [..lhs, ..rhs] - vec![4 * LIMBS] - } - - fn instances(&self) -> Vec> { - vec![self.instance()] - } - - fn accumulator_indices() -> Option> { - Some((0..4 * LIMBS).map(|idx| (0, idx)).collect()) - } - - fn selectors(config: &Self::Config) -> Vec { - config.gate().basic_gates[0].iter().map(|gate| gate.q_enable).collect() - } -} - -impl Circuit for AggregationCircuit { - type Config = AggregationConfig; - type FloorPlanner = SimpleFloorPlanner; - - fn without_witnesses(&self) -> Self { - Self { - svk: self.svk, - snarks: self.snarks.iter().map(SnarkWitness::without_witnesses).collect(), - instances: Vec::new(), - as_proof: Value::unknown(), - } - } - - fn configure(meta: &mut plonk::ConstraintSystem) -> Self::Config { - let path = std::env::var("VERIFY_CONFIG") - .unwrap_or_else(|_| "configs/verify_circuit.config".to_owned()); - let params: AggregationConfigParams = serde_json::from_reader( - File::open(path.as_str()).unwrap_or_else(|_| panic!("{path:?} does not exist")), - ) - .unwrap(); - - AggregationConfig::configure(meta, params) - } - - fn synthesize( - &self, - config: Self::Config, - mut layouter: impl Layouter, - ) -> Result<(), plonk::Error> { - #[cfg(feature = "display")] - let witness_time = start_timer!(|| "synthesize | Aggregation Circuit"); - config.range().load_lookup_table(&mut layouter).expect("load range lookup table"); - let mut first_pass = halo2_base::SKIP_FIRST_PASS; - let mut instances = vec![]; - layouter - .assign_region( - || "", - |region| { - if first_pass { - first_pass = false; - return Ok(()); - } - let ctx = Context::new( - region, - ContextParams { - max_rows: config.gate().max_rows, - num_context_ids: 1, - fixed_columns: config.gate().constants.clone(), - }, - ); - - let ecc_chip = config.ecc_chip(); - let loader = Halo2Loader::new(ecc_chip, ctx); - let (_, acc) = aggregate::>( - &self.svk, - &loader, - &self.snarks, - self.as_proof(), - ); - - instances.extend( - flatten_accumulator(acc).iter().map(|assigned| assigned.cell().clone()), - ); - - config.range().finalize(&mut loader.ctx_mut()); - #[cfg(feature = "display")] - loader.ctx_mut().print_stats(&["Range"]); - Ok(()) - }, - ) - .unwrap(); - - // Expose instances - for (i, cell) in instances.into_iter().enumerate() { - layouter.constrain_instance(cell, config.instance, i)?; - } - #[cfg(feature = "display")] - end_timer!(witness_time); - Ok(()) - } -} - -/// This circuit takes multiple SNARKs and passes through all of their instances except the old accumulators. -/// -/// * If `has_prev_accumulator = true`, we assume all SNARKs are of aggregation circuits with old accumulators -/// only in the first instance column. -/// * Otherwise if `has_prev_accumulator = false`, then all previous instances are passed through. -#[derive(Clone)] -pub struct PublicAggregationCircuit { - pub aggregation: AggregationCircuit, - pub has_prev_accumulator: bool, -} - -impl PublicAggregationCircuit { - pub fn new( - params: &ParamsKZG, - snarks: Vec, - has_prev_accumulator: bool, - rng: &mut (impl Rng + Send), - ) -> Self { - Self { aggregation: AggregationCircuit::new(params, snarks, rng), has_prev_accumulator } - } -} - -impl CircuitExt for PublicAggregationCircuit { - fn num_instance(&self) -> Vec { - let prev_num = self - .aggregation - .snarks - .iter() - .map(|snark| snark.instances.iter().map(|instance| instance.len()).sum::()) - .sum::() - - self.aggregation.snarks.len() * 4 * LIMBS * usize::from(self.has_prev_accumulator); - vec![4 * LIMBS + prev_num] - } - - fn instances(&self) -> Vec> { - let start_idx = 4 * LIMBS * usize::from(self.has_prev_accumulator); - let instance = self - .aggregation - .instances - .iter() - .cloned() - .chain(self.aggregation.snarks.iter().flat_map(|snark| { - snark.instances.iter().enumerate().flat_map(|(i, instance)| { - instance[usize::from(i == 0) * start_idx..] - .iter() - .map(|v| value_to_option(*v).unwrap()) - }) - })) - .collect_vec(); - vec![instance] - } - - fn accumulator_indices() -> Option> { - Some((0..4 * LIMBS).map(|idx| (0, idx)).collect()) - } - - fn selectors(config: &Self::Config) -> Vec { - AggregationCircuit::selectors(config) - } -} - -impl Circuit for PublicAggregationCircuit { - type Config = AggregationConfig; - type FloorPlanner = SimpleFloorPlanner; - - fn without_witnesses(&self) -> Self { - Self { - aggregation: self.aggregation.without_witnesses(), - has_prev_accumulator: self.has_prev_accumulator, - } - } - - fn configure(meta: &mut plonk::ConstraintSystem) -> Self::Config { - AggregationCircuit::configure(meta) - } - - fn synthesize( - &self, - config: Self::Config, - mut layouter: impl Layouter, - ) -> Result<(), plonk::Error> { - #[cfg(feature = "display")] - let witness_time = start_timer!(|| { "synthesize | EVM verifier" }); - config.range().load_lookup_table(&mut layouter).expect("load range lookup table"); - let mut first_pass = halo2_base::SKIP_FIRST_PASS; - let mut instances = vec![]; - layouter - .assign_region( - || "", - |region| { - if first_pass { - first_pass = false; - return Ok(()); - } - let ctx = Context::new( - region, - ContextParams { - max_rows: config.gate().max_rows, - num_context_ids: 1, - fixed_columns: config.gate().constants.clone(), - }, - ); - - let ecc_chip = config.ecc_chip(); - let loader = Halo2Loader::new(ecc_chip, ctx); - let (prev_instances, acc) = aggregate::>( - &self.aggregation.svk, - &loader, - &self.aggregation.snarks, - self.aggregation.as_proof(), - ); - - // accumulator - instances.extend(flatten_accumulator(acc).iter().map(|a| a.cell().clone())); - // prev instances except accumulators - let start_idx = 4 * LIMBS * usize::from(self.has_prev_accumulator); - for prev_instance in prev_instances { - instances - .extend(prev_instance[start_idx..].iter().map(|a| a.cell().clone())); - } - - config.range().finalize(&mut loader.ctx_mut()); - #[cfg(feature = "display")] - loader.ctx_mut().print_stats(&["Range"]); - Ok(()) - }, - ) - .unwrap(); - // Expose instances - for (i, cell) in instances.into_iter().enumerate() { - layouter.constrain_instance(cell, config.instance, i)?; - } - #[cfg(feature = "display")] - end_timer!(witness_time); - Ok(()) - } -} diff --git a/snark-verifier-sdk/src/halo2.rs b/snark-verifier-sdk/src/halo2_api.rs similarity index 66% rename from snark-verifier-sdk/src/halo2.rs rename to snark-verifier-sdk/src/halo2_api.rs index fba2237c..3aa0e64a 100644 --- a/snark-verifier-sdk/src/halo2.rs +++ b/snark-verifier-sdk/src/halo2_api.rs @@ -1,69 +1,76 @@ -use super::{read_instances, write_instances, CircuitExt, Snark, SnarkWitness}; +use std::{ + fs::{self, File}, + io::BufWriter, + path::Path, +}; + +use crate::{ + circuit_ext::CircuitExt, + file_io::{read_pk, read_snark}, + read_instances, + types::{PoseidonTranscript, POSEIDON_SPEC}, + write_instances, Snark, +}; + #[cfg(feature = "display")] -use ark_std::{end_timer, start_timer}; +use ark_std::end_timer; +#[cfg(feature = "display")] +use ark_std::start_timer; use halo2_base::halo2_proofs::{ - self, poly::kzg::strategy::SingleStrategy, transcript::TranscriptReadBuffer, -}; -use halo2_proofs::{ - circuit::Layouter, - halo2curves::{ - bn256::{Bn256, Fr, G1Affine}, - group::ff::Field, - }, - plonk::{ - create_proof, keygen_vk, verify_proof, Circuit, ConstraintSystem, Error, ProvingKey, - VerifyingKey, - }, + halo2curves::bn256::{Bn256, Fr, G1Affine}, + plonk::{create_proof, keygen_pk, keygen_vk, verify_proof, Circuit, ProvingKey, VerifyingKey}, poly::{ commitment::{ParamsProver, Prover, Verifier}, kzg::{ commitment::{KZGCommitmentScheme, ParamsKZG}, msm::DualMSM, multiopen::{ProverGWC, ProverSHPLONK, VerifierGWC, VerifierSHPLONK}, - strategy::{AccumulatorStrategy, GuardKZG}, + strategy::{AccumulatorStrategy, GuardKZG, SingleStrategy}, }, VerificationStrategy, }, + transcript::TranscriptReadBuffer, + SerdeFormat, {self}, }; use itertools::Itertools; -use lazy_static::lazy_static; use rand::Rng; use snark_verifier::{ - cost::CostEstimation, loader::native::NativeLoader, - pcs::{self, MultiOpenScheme}, system::halo2::{compile, Config}, - util::transcript::TranscriptWrite, - verifier::PlonkProof, - PoseidonSpec, -}; -use std::{ - fs::{self, File}, - marker::PhantomData, - path::Path, }; -pub mod aggregation; +#[allow(clippy::let_and_return)] +pub fn gen_pk>( + params: &ParamsKZG, // TODO: read pk without params + circuit: &C, + path: Option<&Path>, +) -> ProvingKey { + if let Some(path) = path { + if let Ok(pk) = read_pk::(path) { + return pk; + } + } + #[cfg(feature = "display")] + let pk_time = start_timer!(|| "Generating vkey & pkey"); -// Poseidon parameters -const T: usize = 5; -const RATE: usize = 4; -const R_F: usize = 8; -const R_P: usize = 60; + let vk = keygen_vk(params, circuit).unwrap(); + let pk = keygen_pk(params, vk, circuit).unwrap(); -pub type PoseidonTranscript = - snark_verifier::system::halo2::transcript::halo2::PoseidonTranscript< - G1Affine, - L, - S, - T, - RATE, - R_F, - R_P, - >; + #[cfg(feature = "display")] + end_timer!(pk_time); + + if let Some(path) = path { + #[cfg(feature = "display")] + let write_time = start_timer!(|| format!("Writing pkey to {path:?}")); -lazy_static! { - pub static ref POSEIDON_SPEC: PoseidonSpec = PoseidonSpec::new(R_F, R_P); + path.parent().and_then(|dir| fs::create_dir_all(dir).ok()).unwrap(); + let mut f = BufWriter::new(File::create(path).unwrap()); + pk.write(&mut f, SerdeFormat::RawBytesUnchecked).unwrap(); + + #[cfg(feature = "display")] + end_timer!(write_time); + } + pk } /// Generates a native proof using either SHPLONK or GWC proving method. Uses Poseidon for Fiat-Shamir. @@ -311,89 +318,3 @@ where { verify_snark::>(verifier_params, snark, vk) } - -/// Tries to deserialize a SNARK from the specified `path` using `bincode`. -/// -/// WARNING: The user must keep track of whether the SNARK was generated using the GWC or SHPLONK multi-open scheme. -pub fn read_snark(path: impl AsRef) -> Result { - let f = File::open(path).map_err(Box::::from)?; - bincode::deserialize_from(f) -} - -pub fn gen_dummy_snark( - params: &ParamsKZG, - vk: Option<&VerifyingKey>, - num_instance: Vec, -) -> Snark -where - ConcreteCircuit: CircuitExt, - MOS: MultiOpenScheme - + CostEstimation>>, -{ - struct CsProxy(PhantomData<(F, C)>); - - impl> Circuit for CsProxy { - type Config = C::Config; - type FloorPlanner = C::FloorPlanner; - - fn without_witnesses(&self) -> Self { - CsProxy(PhantomData) - } - - fn configure(meta: &mut ConstraintSystem) -> Self::Config { - C::configure(meta) - } - - fn synthesize( - &self, - config: Self::Config, - mut layouter: impl Layouter, - ) -> Result<(), Error> { - // when `C` has simple selectors, we tell `CsProxy` not to over-optimize the selectors (e.g., compressing them all into one) by turning all selectors on in the first row - // currently this only works if all simple selector columns are used in the actual circuit and there are overlaps amongst all enabled selectors (i.e., the actual circuit will not optimize constraint system further) - layouter.assign_region( - || "", - |mut region| { - for q in C::selectors(&config).iter() { - q.enable(&mut region, 0)?; - } - Ok(()) - }, - )?; - Ok(()) - } - } - - let dummy_vk = vk - .is_none() - .then(|| keygen_vk(params, &CsProxy::(PhantomData)).unwrap()); - let protocol = compile( - params, - vk.or(dummy_vk.as_ref()).unwrap(), - Config::kzg() - .with_num_instance(num_instance.clone()) - .with_accumulator_indices(ConcreteCircuit::accumulator_indices()), - ); - let instances = num_instance.into_iter().map(|n| vec![Fr::default(); n]).collect(); - let proof = { - let mut transcript = PoseidonTranscript::::new(Vec::new()); - for _ in 0..protocol - .num_witness - .iter() - .chain(Some(&protocol.quotient.num_chunk())) - .sum::() - { - transcript.write_ec_point(G1Affine::default()).unwrap(); - } - for _ in 0..protocol.evaluations.len() { - transcript.write_scalar(Fr::default()).unwrap(); - } - let queries = PlonkProof::::empty_queries(&protocol); - for _ in 0..MOS::estimate_cost(&queries).num_commitment { - transcript.write_ec_point(G1Affine::default()).unwrap(); - } - transcript.finalize() - }; - - Snark::new(protocol, instances, proof) -} diff --git a/snark-verifier-sdk/src/lib.rs b/snark-verifier-sdk/src/lib.rs index 5a4816bb..61991a1b 100644 --- a/snark-verifier-sdk/src/lib.rs +++ b/snark-verifier-sdk/src/lib.rs @@ -1,192 +1,76 @@ -#![feature(associated_type_defaults)] -#[cfg(feature = "display")] -use ark_std::{end_timer, start_timer}; -use halo2_base::halo2_proofs; -use halo2_proofs::{ - circuit::Value, - halo2curves::{ - bn256::{Bn256, Fr, G1Affine}, - group::ff::Field, - }, - plonk::{keygen_pk, keygen_vk, Circuit, ProvingKey, Selector}, - poly::kzg::commitment::ParamsKZG, - SerdeFormat, -}; -use itertools::Itertools; -use serde::{Deserialize, Serialize}; -pub use snark_verifier::loader::native::NativeLoader; -use snark_verifier::{pcs::kzg::LimbsEncoding, verifier, Protocol}; -use std::{ - fs::{self, File}, - io::{self, BufReader, BufWriter}, - path::Path, -}; - #[cfg(feature = "loader_evm")] -pub mod evm; +mod evm_api; #[cfg(feature = "loader_halo2")] -pub mod halo2; +mod halo2_api; #[cfg(test)] mod tests; -pub const LIMBS: usize = 3; -pub const BITS: usize = 88; - -/// PCS be either `Kzg` or `Kzg` -pub type Plonk = verifier::Plonk>; - -#[derive(Clone, Debug, Serialize, Deserialize)] -pub struct Snark { - pub protocol: Protocol, - pub instances: Vec>, - pub proof: Vec, -} - -impl Snark { - pub fn new(protocol: Protocol, instances: Vec>, proof: Vec) -> Self { - Self { protocol, instances, proof } - } -} - -impl From for SnarkWitness { - fn from(snark: Snark) -> Self { - Self { - protocol: snark.protocol, - instances: snark - .instances - .into_iter() - .map(|instances| instances.into_iter().map(Value::known).collect_vec()) - .collect(), - proof: Value::known(snark.proof), - } - } -} - -#[derive(Clone, Debug)] -pub struct SnarkWitness { - pub protocol: Protocol, - pub instances: Vec>>, - pub proof: Value>, -} - -impl SnarkWitness { - pub fn without_witnesses(&self) -> Self { - SnarkWitness { - protocol: self.protocol.clone(), - instances: self - .instances - .iter() - .map(|instances| vec![Value::unknown(); instances.len()]) - .collect(), - proof: Value::unknown(), - } - } - - pub fn proof(&self) -> Value<&[u8]> { - self.proof.as_ref().map(Vec::as_slice) - } -} - -pub trait CircuitExt: Circuit { - /// Return the number of instances of the circuit. - /// This may depend on extra circuit parameters but NOT on private witnesses. - fn num_instance(&self) -> Vec { - vec![] - } - - fn instances(&self) -> Vec> { - vec![] - } - - fn accumulator_indices() -> Option> { - None - } - - /// Output the simple selector columns (before selector compression) of the circuit - fn selectors(_: &Self::Config) -> Vec { - vec![] - } -} - -pub fn read_pk>(path: &Path) -> io::Result> { - let f = File::open(path)?; - #[cfg(feature = "display")] - let read_time = start_timer!(|| format!("Reading pkey from {path:?}")); - - // BufReader is indeed MUCH faster than Read - let mut bufreader = BufReader::new(f); - // But it's even faster to load the whole file into memory first and then process, - // HOWEVER this requires twice as much memory to initialize - // let initial_buffer_size = f.metadata().map(|m| m.len() as usize + 1).unwrap_or(0); - // let mut bufreader = Vec::with_capacity(initial_buffer_size); - // f.read_to_end(&mut bufreader)?; - let pk = ProvingKey::read::<_, C>(&mut bufreader, SerdeFormat::RawBytesUnchecked).unwrap(); - - #[cfg(feature = "display")] - end_timer!(read_time); - - Ok(pk) -} - -#[allow(clippy::let_and_return)] -pub fn gen_pk>( - params: &ParamsKZG, // TODO: read pk without params - circuit: &C, - path: Option<&Path>, -) -> ProvingKey { - if let Some(path) = path { - if let Ok(pk) = read_pk::(path) { - return pk; - } - } - #[cfg(feature = "display")] - let pk_time = start_timer!(|| "Generating vkey & pkey"); - - let vk = keygen_vk(params, circuit).unwrap(); - let pk = keygen_pk(params, vk, circuit).unwrap(); - - #[cfg(feature = "display")] - end_timer!(pk_time); - - if let Some(path) = path { - #[cfg(feature = "display")] - let write_time = start_timer!(|| format!("Writing pkey to {path:?}")); - - path.parent().and_then(|dir| fs::create_dir_all(dir).ok()).unwrap(); - let mut f = BufWriter::new(File::create(path).unwrap()); - pk.write(&mut f, SerdeFormat::RawBytesUnchecked).unwrap(); - - #[cfg(feature = "display")] - end_timer!(write_time); - } - pk -} - -pub fn read_instances(path: impl AsRef) -> Result>, bincode::Error> { - let f = File::open(path)?; - let reader = BufReader::new(f); - let instances: Vec> = bincode::deserialize_from(reader)?; - instances - .into_iter() - .map(|instance_column| { - instance_column - .iter() - .map(|bytes| { - Option::from(Fr::from_bytes(bytes)).ok_or(Box::new(bincode::ErrorKind::Custom( - "Invalid finite field point".to_owned(), - ))) - }) - .collect::, _>>() - }) - .collect() -} +mod aggregation; +mod circuit_ext; +mod file_io; +mod param; +mod snark; +pub mod types; + +pub use aggregation::aggregation_circuit::AggregationCircuit; +pub use aggregation::multi_aggregation_circuit::PublicAggregationCircuit; +pub use circuit_ext::CircuitExt; +pub use param::{BITS, LIMBS}; +pub use snark::{Snark, SnarkWitness}; + +pub use file_io::{ + // read instances from disk + read_instances, + // read pk from disk + read_pk, + // read snark from disk + read_snark, + // write call date to disk + write_calldata, + // write instances to disk + write_instances, +}; -pub fn write_instances(instances: &[&[Fr]], path: impl AsRef) { - let instances: Vec> = instances - .iter() - .map(|instance_column| instance_column.iter().map(|x| x.to_bytes()).collect_vec()) - .collect_vec(); - let f = BufWriter::new(File::create(path).unwrap()); - bincode::serialize_into(f, &instances).unwrap(); -} +#[cfg(feature = "loader_evm")] +pub use evm_api::{ + // encode instances and proofs as calldata + encode_calldata, + // verify instances and proofs with the bytecode + evm_verify, + // generate evm proof with keccak that can be verified by bytecode + gen_evm_proof, + // generate snark proof with keccak and KZG-GWC that can be verified by bytecode + gen_evm_proof_gwc, + // generate evm proof with keccak and KZG-BDFG that can be verified by bytecode + gen_evm_proof_shplonk, + // generate the bytecode that verifies proofs + gen_evm_verifier, + // generate the bytecode that verifies proofs with keccak and KZG-GWC + gen_evm_verifier_gwc, + // generate the bytecode that verifies proofs with keccak and KZG-BDFG + gen_evm_verifier_shplonk, +}; +#[cfg(feature = "loader_halo2")] +pub use halo2_api::{ + // generate pk + gen_pk, + // generate proof with poseidon + gen_proof, + // generate proof with poseidon and KZG-GWC + gen_proof_gwc, + // generate proof with poseidon and KZG-BDFG + gen_proof_shplonk, + // generate a snark struct (proof + witnesses for aggregation circuit) + gen_snark, + // generate a snark struct (proof + witnesses for aggregation circuit) with KZG-GWC + gen_snark_gwc, + // generate a snark struct (proof + witnesses for aggregation circuit) with KZG-BDFG + gen_snark_shplonk, + // verify snark + verify_snark, + // verify snark KZG-GWC + verify_snark_gwc, + // verify snark KZG-BDFG + verify_snark_shplonk, +}; diff --git a/snark-verifier-sdk/src/param.rs b/snark-verifier-sdk/src/param.rs new file mode 100644 index 00000000..01c8a423 --- /dev/null +++ b/snark-verifier-sdk/src/param.rs @@ -0,0 +1,10 @@ +/// Number of limbs for non-native field decomposition +pub const LIMBS: usize = 3; +/// Number of bits for each limb. +pub const BITS: usize = 88; + +// Poseidon parameters +pub(crate) const T: usize = 5; +pub(crate) const RATE: usize = 4; +pub(crate) const R_F: usize = 8; +pub(crate) const R_P: usize = 60; diff --git a/snark-verifier-sdk/src/snark.rs b/snark-verifier-sdk/src/snark.rs new file mode 100644 index 00000000..58e81298 --- /dev/null +++ b/snark-verifier-sdk/src/snark.rs @@ -0,0 +1,66 @@ +use halo2_base::halo2_proofs; +use halo2_proofs::{ + circuit::Value, + halo2curves::bn256::{Fr, G1Affine}, +}; +use itertools::Itertools; +use serde::{Deserialize, Serialize}; +use snark_verifier::Protocol; + +mod mock; + +/// A Snark struct is all one may need to generate witnesses for an aggregation circuit. +#[derive(Clone, Debug, Serialize, Deserialize)] +pub struct Snark { + pub protocol: Protocol, + pub instances: Vec>, + pub proof: Vec, +} + +impl Snark { + pub fn new(protocol: Protocol, instances: Vec>, proof: Vec) -> Self { + Self { protocol, instances, proof } + } +} + +impl From for SnarkWitness { + fn from(snark: Snark) -> Self { + Self { + protocol: snark.protocol, + instances: snark + .instances + .into_iter() + .map(|instances| instances.into_iter().map(Value::known).collect_vec()) + .collect(), + proof: Value::known(snark.proof), + } + } +} + +/// A SnarkWitness struct is a snark converted to witness. +#[derive(Clone, Debug)] +pub struct SnarkWitness { + pub protocol: Protocol, + pub instances: Vec>>, + pub proof: Value>, +} + +impl SnarkWitness { + /// Initialize an empty SnarkWitness with a same struct as self. + pub fn without_witnesses(&self) -> Self { + SnarkWitness { + protocol: self.protocol.clone(), + instances: self + .instances + .iter() + .map(|instances| vec![Value::unknown(); instances.len()]) + .collect(), + proof: Value::unknown(), + } + } + + /// Expose the proof of the witness. + pub fn proof(&self) -> Value<&[u8]> { + self.proof.as_ref().map(Vec::as_slice) + } +} diff --git a/snark-verifier-sdk/src/snark/mock.rs b/snark-verifier-sdk/src/snark/mock.rs new file mode 100644 index 00000000..137b0b3d --- /dev/null +++ b/snark-verifier-sdk/src/snark/mock.rs @@ -0,0 +1,108 @@ +//! Mock Snark +use crate::{circuit_ext::CircuitExt, types::PoseidonTranscript}; + +use super::Snark; +#[cfg(feature = "display")] +use ark_std::end_timer; +#[cfg(feature = "display")] +use ark_std::start_timer; +use halo2_base::halo2_proofs::{self}; +use halo2_proofs::{ + circuit::Layouter, + halo2curves::{ + bn256::{Bn256, Fr, G1Affine}, + group::ff::Field, + }, + plonk::{keygen_vk, Circuit, ConstraintSystem, Error, VerifyingKey}, + poly::kzg::commitment::ParamsKZG, +}; +use snark_verifier::{ + cost::CostEstimation, + loader::native::NativeLoader, + pcs::{ + MultiOpenScheme, {self}, + }, + system::halo2::{compile, Config}, + util::transcript::TranscriptWrite, + verifier::PlonkProof, +}; +use std::marker::PhantomData; + +struct CsProxy(PhantomData<(F, C)>); + +impl> Circuit for CsProxy { + type Config = C::Config; + type FloorPlanner = C::FloorPlanner; + + fn without_witnesses(&self) -> Self { + CsProxy(PhantomData) + } + + fn configure(meta: &mut ConstraintSystem) -> Self::Config { + C::configure(meta) + } + + fn synthesize( + &self, + config: Self::Config, + mut layouter: impl Layouter, + ) -> Result<(), Error> { + // when `C` has simple selectors, we tell `CsProxy` not to over-optimize the selectors (e.g., compressing them all into one) by turning all selectors on in the first row + // currently this only works if all simple selector columns are used in the actual circuit and there are overlaps amongst all enabled selectors (i.e., the actual circuit will not optimize constraint system further) + layouter.assign_region( + || "", + |mut region| { + for q in C::selectors(&config).iter() { + q.enable(&mut region, 0)?; + } + Ok(()) + }, + )?; + Ok(()) + } +} + +/// Generate a Snark for a ConcreteCircuit +pub fn gen_dummy_snark( + params: &ParamsKZG, + vk: Option<&VerifyingKey>, + num_instance: Vec, +) -> Snark +where + ConcreteCircuit: CircuitExt, + MOS: MultiOpenScheme + + CostEstimation>>, +{ + let dummy_vk = vk + .is_none() + .then(|| keygen_vk(params, &CsProxy::(PhantomData)).unwrap()); + let protocol = compile( + params, + vk.or(dummy_vk.as_ref()).unwrap(), + Config::kzg() + .with_num_instance(num_instance.clone()) + .with_accumulator_indices(ConcreteCircuit::accumulator_indices()), + ); + let instances = num_instance.into_iter().map(|n| vec![Fr::default(); n]).collect(); + let proof = { + let mut transcript = PoseidonTranscript::::new(Vec::new()); + for _ in 0..protocol + .num_witness + .iter() + .chain(Some(&protocol.quotient.num_chunk())) + .sum::() + { + transcript.write_ec_point(G1Affine::default()).unwrap(); + } + for _ in 0..protocol.evaluations.len() { + transcript.write_scalar(Fr::default()).unwrap(); + } + let queries = PlonkProof::::empty_queries(&protocol); + for _ in 0..MOS::estimate_cost(&queries).num_commitment { + transcript.write_ec_point(G1Affine::default()).unwrap(); + } + transcript.finalize() + }; + + Snark::new(protocol, instances, proof) +} diff --git a/snark-verifier-sdk/src/tests/evm_verifier.rs b/snark-verifier-sdk/src/tests/evm_verifier.rs index 855f73a6..0c9d7281 100644 --- a/snark-verifier-sdk/src/tests/evm_verifier.rs +++ b/snark-verifier-sdk/src/tests/evm_verifier.rs @@ -1,12 +1,16 @@ use super::TestCircuit1; -use crate::evm::{evm_verify, gen_evm_proof_shplonk, gen_evm_verifier}; -use crate::gen_pk; -use crate::CircuitExt; +use crate::{ + evm_api::{evm_verify, gen_evm_proof_shplonk, gen_evm_verifier}, + halo2_api::gen_pk, + CircuitExt, +}; use ark_std::test_rng; use halo2_base::halo2_proofs; use halo2_proofs::halo2curves::bn256::Bn256; -use snark_verifier::loader::halo2::halo2_ecc::halo2_base::utils::fs::gen_srs; -use snark_verifier::pcs::kzg::{Bdfg21, Kzg}; +use snark_verifier::{ + loader::halo2::halo2_ecc::halo2_base::utils::fs::gen_srs, + pcs::kzg::{Bdfg21, Kzg}, +}; #[test] fn test_evm_verification() { diff --git a/snark-verifier-sdk/src/tests/mod.rs b/snark-verifier-sdk/src/tests/mod.rs index 3ab6481f..22d0737c 100644 --- a/snark-verifier-sdk/src/tests/mod.rs +++ b/snark-verifier-sdk/src/tests/mod.rs @@ -1,6 +1,6 @@ use halo2_base::halo2_proofs; -use halo2_proofs::halo2curves::bn256::Fr; use halo2_proofs::{ + halo2curves::bn256::Fr, plonk::{Advice, Column, ConstraintSystem, Fixed, Instance}, poly::Rotation, }; diff --git a/snark-verifier-sdk/src/tests/single_layer_aggregation.rs b/snark-verifier-sdk/src/tests/single_layer_aggregation.rs index b3886c79..c937d667 100644 --- a/snark-verifier-sdk/src/tests/single_layer_aggregation.rs +++ b/snark-verifier-sdk/src/tests/single_layer_aggregation.rs @@ -1,14 +1,17 @@ use super::{TestCircuit1, TestCircuit2}; -use crate::evm::{evm_verify, gen_evm_proof_shplonk, gen_evm_verifier}; -use crate::halo2::aggregation::AggregationCircuit; -use crate::CircuitExt; -use crate::{gen_pk, halo2::gen_snark_shplonk}; +use crate::{ + aggregation::aggregation_circuit::AggregationCircuit, + evm_api::{evm_verify, gen_evm_proof_shplonk, gen_evm_verifier}, + halo2_api::{gen_pk, gen_snark_shplonk}, + CircuitExt, +}; use ark_std::test_rng; use halo2_base::halo2_proofs; -use halo2_proofs::halo2curves::bn256::Bn256; -use halo2_proofs::poly::commitment::Params; -use snark_verifier::loader::halo2::halo2_ecc::halo2_base::utils::fs::gen_srs; -use snark_verifier::pcs::kzg::{Bdfg21, Kzg}; +use halo2_proofs::{halo2curves::bn256::Bn256, poly::commitment::Params}; +use snark_verifier::{ + loader::halo2::halo2_ecc::halo2_base::utils::fs::gen_srs, + pcs::kzg::{Bdfg21, Kzg}, +}; use std::path::Path; #[test] diff --git a/snark-verifier-sdk/src/tests/test_circuit_1.rs b/snark-verifier-sdk/src/tests/test_circuit_1.rs index cabef61d..f2e1f7ac 100644 --- a/snark-verifier-sdk/src/tests/test_circuit_1.rs +++ b/snark-verifier-sdk/src/tests/test_circuit_1.rs @@ -2,9 +2,9 @@ use super::StandardPlonkConfig; use crate::CircuitExt; use halo2_base::halo2_proofs; -use halo2_proofs::halo2curves::bn256::Fr; use halo2_proofs::{ circuit::{Layouter, SimpleFloorPlanner, Value}, + halo2curves::bn256::Fr, plonk::{Circuit, ConstraintSystem, Error}, }; use rand::RngCore; diff --git a/snark-verifier-sdk/src/tests/test_circuit_2.rs b/snark-verifier-sdk/src/tests/test_circuit_2.rs index f9389ad5..687cbcc5 100644 --- a/snark-verifier-sdk/src/tests/test_circuit_2.rs +++ b/snark-verifier-sdk/src/tests/test_circuit_2.rs @@ -2,9 +2,9 @@ use super::StandardPlonkConfig; use crate::CircuitExt; use halo2_base::halo2_proofs; -use halo2_proofs::halo2curves::bn256::Fr; use halo2_proofs::{ circuit::{Layouter, SimpleFloorPlanner, Value}, + halo2curves::bn256::Fr, plonk::{Circuit, ConstraintSystem, Error}, }; use rand::RngCore; diff --git a/snark-verifier-sdk/src/tests/two_layer_aggregation.rs b/snark-verifier-sdk/src/tests/two_layer_aggregation.rs index 5160417f..25f83f1b 100644 --- a/snark-verifier-sdk/src/tests/two_layer_aggregation.rs +++ b/snark-verifier-sdk/src/tests/two_layer_aggregation.rs @@ -1,14 +1,17 @@ use super::TestCircuit1; -use crate::evm::{evm_verify, gen_evm_proof_shplonk, gen_evm_verifier}; -use crate::halo2::aggregation::AggregationCircuit; -use crate::CircuitExt; -use crate::{gen_pk, halo2::gen_snark_shplonk}; +use crate::{ + aggregation::aggregation_circuit::AggregationCircuit, + evm_api::{evm_verify, gen_evm_proof_shplonk, gen_evm_verifier}, + halo2_api::{gen_pk, gen_snark_shplonk}, + CircuitExt, +}; use ark_std::test_rng; use halo2_base::halo2_proofs; -use halo2_proofs::halo2curves::bn256::Bn256; -use halo2_proofs::poly::commitment::Params; -use snark_verifier::loader::halo2::halo2_ecc::halo2_base::utils::fs::gen_srs; -use snark_verifier::pcs::kzg::{Bdfg21, Kzg}; +use halo2_proofs::{halo2curves::bn256::Bn256, poly::commitment::Params}; +use snark_verifier::{ + loader::halo2::halo2_ecc::halo2_base::utils::fs::gen_srs, + pcs::kzg::{Bdfg21, Kzg}, +}; use std::path::Path; #[test] diff --git a/snark-verifier-sdk/src/types.rs b/snark-verifier-sdk/src/types.rs new file mode 100644 index 00000000..4339bed4 --- /dev/null +++ b/snark-verifier-sdk/src/types.rs @@ -0,0 +1,52 @@ +//! This module concretize generic types with Bn256 curve and BDFG KZG scheme. + +use super::{BITS, LIMBS}; +use halo2_base::halo2_proofs::halo2curves::bn256::{Bn256, Fr, G1Affine}; +use lazy_static::lazy_static; +use snark_verifier::{ + loader::halo2::{halo2_ecc::ecc::BaseFieldEccChip as EccChip, Halo2Loader as Loader}, + pcs::kzg::{ + Bdfg21, Kzg, KzgAs as KzgAccumulationScheme, KzgSuccinctVerifyingKey, LimbsEncoding, + }, + verifier, PoseidonSpec, +}; + +use crate::param::{RATE, R_F, R_P, T}; + +lazy_static! { + pub static ref POSEIDON_SPEC: PoseidonSpec = PoseidonSpec::new(R_F, R_P); +} + +/// Transcript instantiated with Poseidon +pub type PoseidonTranscript = + snark_verifier::system::halo2::transcript::halo2::PoseidonTranscript< + G1Affine, + L, + S, + T, + RATE, + R_F, + R_P, + >; + +/// Plonk configured with PCS. +/// PCS is either `Kzg` or `Kzg` +pub type Plonk = verifier::Plonk>; + +/// KZG instantiated with BDFG21 +pub type KzgBDFG = Kzg; + +/// Accumulator scheme build from KZG over BDFG21 scheme +pub type KzgAs = KzgAccumulationScheme; + +/// SHPlonk +pub type Shplonk = Plonk; + +/// KZG succinct verifying key. +pub type Svk = KzgSuccinctVerifyingKey; + +/// Non-native arithmetic chip +pub type BaseFieldEccChip = EccChip; + +/// Halo2 loader +pub type Halo2Loader<'a> = Loader<'a, G1Affine, BaseFieldEccChip>; diff --git a/snark-verifier/Cargo.toml b/snark-verifier/Cargo.toml index fbc23d99..bb61e79f 100644 --- a/snark-verifier/Cargo.toml +++ b/snark-verifier/Cargo.toml @@ -15,7 +15,7 @@ rustc-hash = "1.1.0" serde = { version = "1.0", features = ["derive"] } # Use halo2-base as non-optional dependency because it re-exports halo2_proofs, halo2curves, and poseidon, using different repos based on feature flag "halo2-axiom" or "halo2-pse" -halo2-base = { git = "https://github.com/scroll-tech/halo2-lib", branch = "minimize-diff", default-features=false, features=["halo2-pse","display"] } +halo2-base = { git = "https://github.com/scroll-tech/halo2-lib", branch = "develop", default-features=false, features=["halo2-pse","display"] } # This poseidon is identical to PSE (for now) but uses axiom's halo2curves; otherwise would require patching poseidon-axiom = { git = "https://github.com/axiom-crypto/halo2.git", branch = "axiom/dev", package = "poseidon", optional = true } poseidon= { git = "https://github.com/privacy-scaling-explorations/poseidon", optional = true } @@ -31,7 +31,7 @@ bytes = { version = "1.2", optional = true } rlp = { version = "0.5", default-features = false, features = ["std"], optional = true } # loader_halo2 -halo2-ecc = { git = "https://github.com/scroll-tech/halo2-lib", branch = "minimize-diff", optional = true, default-features=false, features=["halo2-pse","display"] } +halo2-ecc = { git = "https://github.com/scroll-tech/halo2-lib", branch = "develop", optional = true, default-features=false, features=["halo2-pse","display"] } [dev-dependencies] ark-std = { version = "0.3.0", features = ["print-trace"] } diff --git a/snark-verifier/examples/evm-verifier-with-accumulator.rs b/snark-verifier/examples/evm-verifier-with-accumulator.rs index b2406a93..d2b538ac 100644 --- a/snark-verifier/examples/evm-verifier-with-accumulator.rs +++ b/snark-verifier/examples/evm-verifier-with-accumulator.rs @@ -1,7 +1,7 @@ use ethereum_types::Address; use halo2_base::halo2_proofs::{ - self, poly::kzg::multiopen::{ProverSHPLONK, VerifierSHPLONK}, + {self}, }; use halo2_proofs::{ dev::MockProver, @@ -21,12 +21,16 @@ use itertools::Itertools; use rand::rngs::OsRng; use snark_verifier::{ loader::{ - evm::{self, encode_calldata, EvmLoader, ExecutorBuilder}, + evm::{ + encode_calldata, EvmLoader, ExecutorBuilder, {self}, + }, native::NativeLoader, }, pcs::kzg::{Bdfg21, Kzg, KzgAs, LimbsEncoding}, system::halo2::{compile, transcript::evm::EvmTranscript, Config}, - verifier::{self, PlonkVerifier}, + verifier::{ + PlonkVerifier, {self}, + }, }; use std::{io::Cursor, rc::Rc}; @@ -38,12 +42,14 @@ type As = KzgAs; type Plonk = verifier::Plonk>; mod application { - use super::halo2_proofs::{ - circuit::{Layouter, SimpleFloorPlanner, Value}, - plonk::{Advice, Circuit, Column, ConstraintSystem, Error, Fixed, Instance}, - poly::Rotation, + use super::{ + halo2_proofs::{ + circuit::{Layouter, SimpleFloorPlanner, Value}, + plonk::{Advice, Circuit, Column, ConstraintSystem, Error, Fixed, Instance}, + poly::Rotation, + }, + Fr, }; - use super::Fr; use rand::RngCore; #[derive(Clone, Copy)] @@ -201,20 +207,26 @@ mod application { } mod aggregation { - use super::halo2_proofs::{ - circuit::{Cell, Layouter, SimpleFloorPlanner, Value}, - plonk::{self, Circuit, Column, ConstraintSystem, Instance}, - poly::{commitment::ParamsProver, kzg::commitment::ParamsKZG}, + use super::{ + halo2_proofs::{ + circuit::{Cell, Layouter, SimpleFloorPlanner, Value}, + plonk::{ + Circuit, Column, ConstraintSystem, Instance, {self}, + }, + poly::{commitment::ParamsProver, kzg::commitment::ParamsKZG}, + }, + As, Bn256, Fq, Fr, G1Affine, Plonk, BITS, LIMBS, }; - use super::{As, Plonk, BITS, LIMBS}; - use super::{Bn256, Fq, Fr, G1Affine}; use ark_std::{end_timer, start_timer}; use halo2_base::{Context, ContextParams}; use halo2_ecc::ecc::EccChip; use itertools::Itertools; use rand::rngs::OsRng; use snark_verifier::{ - loader::{self, native::NativeLoader}, + loader::{ + native::NativeLoader, + {self}, + }, pcs::{ kzg::{KzgAccumulator, KzgSuccinctVerifyingKey}, AccumulationScheme, AccumulationSchemeProver, diff --git a/snark-verifier/examples/evm-verifier.rs b/snark-verifier/examples/evm-verifier.rs index 0de7b7e0..71d691dc 100644 --- a/snark-verifier/examples/evm-verifier.rs +++ b/snark-verifier/examples/evm-verifier.rs @@ -1,7 +1,7 @@ use ethereum_types::Address; use halo2_base::halo2_proofs::{ - self, poly::kzg::multiopen::{ProverSHPLONK, VerifierSHPLONK}, + {self}, }; use halo2_proofs::{ circuit::{Layouter, SimpleFloorPlanner, Value}, @@ -24,10 +24,14 @@ use halo2_proofs::{ use itertools::Itertools; use rand::{rngs::OsRng, RngCore}; use snark_verifier::{ - loader::evm::{self, encode_calldata, EvmLoader, ExecutorBuilder}, + loader::evm::{ + encode_calldata, EvmLoader, ExecutorBuilder, {self}, + }, pcs::kzg::{Bdfg21, Kzg}, system::halo2::{compile, transcript::evm::EvmTranscript, Config}, - verifier::{self, PlonkVerifier}, + verifier::{ + PlonkVerifier, {self}, + }, }; use std::rc::Rc; diff --git a/snark-verifier/examples/recursion.rs b/snark-verifier/examples/recursion.rs index eb9a570b..cf3acc15 100644 --- a/snark-verifier/examples/recursion.rs +++ b/snark-verifier/examples/recursion.rs @@ -2,8 +2,7 @@ use ark_std::{end_timer, start_timer}; use common::*; -use halo2_base::halo2_proofs; -use halo2_base::utils::fs::gen_srs; +use halo2_base::{halo2_proofs, utils::fs::gen_srs}; use halo2_proofs::{ circuit::{Layouter, SimpleFloorPlanner, Value}, dev::MockProver, @@ -13,8 +12,8 @@ use halo2_proofs::{ FieldExt, }, plonk::{ - self, create_proof, keygen_pk, keygen_vk, Circuit, ConstraintSystem, Error, ProvingKey, - Selector, VerifyingKey, + create_proof, keygen_pk, keygen_vk, Circuit, ConstraintSystem, Error, ProvingKey, Selector, + VerifyingKey, {self}, }, poly::{ commitment::ParamsProver, @@ -29,17 +28,24 @@ use halo2_proofs::{ use itertools::Itertools; use rand_chacha::rand_core::OsRng; use snark_verifier::{ - loader::{self, native::NativeLoader, Loader, ScalarLoader}, + loader::{ + native::NativeLoader, + Loader, ScalarLoader, {self}, + }, pcs::{ kzg::{Gwc19, Kzg, KzgAccumulator, KzgAs, KzgSuccinctVerifyingKey, LimbsEncoding}, AccumulationScheme, AccumulationSchemeProver, }, - system::halo2::{self, compile, Config}, + system::halo2::{ + compile, Config, {self}, + }, util::{ arithmetic::{fe_to_fe, fe_to_limbs}, hash, }, - verifier::{self, PlonkProof, PlonkVerifier}, + verifier::{ + PlonkProof, PlonkVerifier, {self}, + }, Protocol, }; use std::{fs, iter, marker::PhantomData, rc::Rc}; diff --git a/snark-verifier/src/lib.rs b/snark-verifier/src/lib.rs index 2aa4c1f4..5a2c02c4 100644 --- a/snark-verifier/src/lib.rs +++ b/snark-verifier/src/lib.rs @@ -33,6 +33,7 @@ pub enum Error { Transcript(std::io::ErrorKind, String), } +/// Various parameters for the aggregation circuit. #[derive(Clone, Debug, Serialize, Deserialize)] pub struct Protocol where diff --git a/snark-verifier/src/loader/evm/loader.rs b/snark-verifier/src/loader/evm/loader.rs index 92b95c28..0b5827bf 100644 --- a/snark-verifier/src/loader/evm/loader.rs +++ b/snark-verifier/src/loader/evm/loader.rs @@ -17,7 +17,9 @@ use hex; use std::{ cell::RefCell, collections::HashMap, - fmt::{self, Debug}, + fmt::{ + Debug, {self}, + }, iter, ops::{Add, AddAssign, DerefMut, Mul, MulAssign, Neg, Sub, SubAssign}, rc::Rc, diff --git a/snark-verifier/src/loader/evm/test/tui.rs b/snark-verifier/src/loader/evm/test/tui.rs index 2d6f903f..66ae2bd2 100644 --- a/snark-verifier/src/loader/evm/test/tui.rs +++ b/snark-verifier/src/loader/evm/test/tui.rs @@ -3,8 +3,8 @@ use crate::loader::evm::util::executor::{CallKind, DebugStep}; use crossterm::{ event::{ - self, DisableMouseCapture, EnableMouseCapture, Event, KeyCode, KeyEvent, KeyModifiers, - MouseEvent, MouseEventKind, + DisableMouseCapture, EnableMouseCapture, Event, KeyCode, KeyEvent, KeyModifiers, + MouseEvent, MouseEventKind, {self}, }, execute, terminal::{disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen}, diff --git a/snark-verifier/src/loader/halo2.rs b/snark-verifier/src/loader/halo2.rs index cbafb89c..01cf5eef 100644 --- a/snark-verifier/src/loader/halo2.rs +++ b/snark-verifier/src/loader/halo2.rs @@ -1,6 +1,5 @@ //! `Loader` implementation for generating verifier in [`halo2_proofs`] circuit. -use crate::halo2_proofs::circuit; -use crate::{util::arithmetic::CurveAffine, Protocol}; +use crate::{halo2_proofs::circuit, util::arithmetic::CurveAffine, Protocol}; use std::rc::Rc; pub(crate) mod loader; diff --git a/snark-verifier/src/loader/halo2/loader.rs b/snark-verifier/src/loader/halo2/loader.rs index 2c47f288..f3a33a93 100644 --- a/snark-verifier/src/loader/halo2/loader.rs +++ b/snark-verifier/src/loader/halo2/loader.rs @@ -1,5 +1,5 @@ -use crate::halo2_proofs::circuit; use crate::{ + halo2_proofs::circuit, loader::{ halo2::shim::{EccInstructions, IntegerInstructions}, EcPointLoader, LoadedEcPoint, LoadedScalar, Loader, ScalarLoader, @@ -11,7 +11,9 @@ use crate::{ }; use std::{ cell::{Ref, RefCell, RefMut}, - fmt::{self, Debug}, + fmt::{ + Debug, {self}, + }, marker::PhantomData, ops::{Add, AddAssign, Deref, Mul, MulAssign, Neg, Sub, SubAssign}, rc::Rc, diff --git a/snark-verifier/src/loader/halo2/shim.rs b/snark-verifier/src/loader/halo2/shim.rs index db4bd9dd..b6c254e6 100644 --- a/snark-verifier/src/loader/halo2/shim.rs +++ b/snark-verifier/src/loader/halo2/shim.rs @@ -1,8 +1,10 @@ -use crate::halo2_proofs::{ - circuit::{Cell, Value}, - plonk::Error, +use crate::{ + halo2_proofs::{ + circuit::{Cell, Value}, + plonk::Error, + }, + util::arithmetic::{CurveAffine, FieldExt}, }; -use crate::util::arithmetic::{CurveAffine, FieldExt}; use std::{fmt::Debug, ops::Deref}; pub trait Context: Debug { @@ -156,21 +158,21 @@ pub trait EccInstructions<'a, C: CurveAffine>: Clone + Debug { } mod halo2_lib { - use crate::halo2_proofs::{ - circuit::{Cell, Value}, - halo2curves::CurveAffineExt, - plonk::Error, - }; use crate::{ + halo2_proofs::{ + circuit::{Cell, Value}, + halo2curves::CurveAffineExt, + plonk::Error, + }, loader::halo2::{Context, EccInstructions, IntegerInstructions}, util::arithmetic::{CurveAffine, Field}, }; use halo2_base::{ - self, gates::{flex_gate::FlexGateConfig, GateInstructions, RangeInstructions}, utils::BigPrimeField as PrimeField, AssignedValue, QuantumCell::{Constant, Existing, Witness}, + {self}, }; use halo2_ecc::{ bigint::CRTInteger, diff --git a/snark-verifier/src/loader/halo2/test.rs b/snark-verifier/src/loader/halo2/test.rs index 96de6747..3e4f78cb 100644 --- a/snark-verifier/src/loader/halo2/test.rs +++ b/snark-verifier/src/loader/halo2/test.rs @@ -1,5 +1,5 @@ -use crate::halo2_proofs::circuit::Value; use crate::{ + halo2_proofs::circuit::Value, util::{arithmetic::CurveAffine, Itertools}, Protocol, }; diff --git a/snark-verifier/src/pcs/kzg/accumulator.rs b/snark-verifier/src/pcs/kzg/accumulator.rs index 4adfa314..556529cb 100644 --- a/snark-verifier/src/pcs/kzg/accumulator.rs +++ b/snark-verifier/src/pcs/kzg/accumulator.rs @@ -135,8 +135,8 @@ pub use halo2::LimbsEncodingInstructions; #[cfg(feature = "loader_halo2")] mod halo2 { - use crate::halo2_proofs::{circuit::Value, plonk}; use crate::{ + halo2_proofs::{circuit::Value, plonk}, loader::halo2::{EccInstructions, Halo2Loader, Scalar, Valuetools}, pcs::{ kzg::{KzgAccumulator, LimbsEncoding}, diff --git a/snark-verifier/src/system/halo2.rs b/snark-verifier/src/system/halo2.rs index 34b9020e..d6a68460 100644 --- a/snark-verifier/src/system/halo2.rs +++ b/snark-verifier/src/system/halo2.rs @@ -1,10 +1,15 @@ //! [`halo2_proofs`] proof system -use crate::halo2_proofs::{ - plonk::{self, Any, ConstraintSystem, FirstPhase, SecondPhase, ThirdPhase, VerifyingKey}, - poly::{self, commitment::Params}, - transcript::{EncodedChallenge, Transcript}, -}; use crate::{ + halo2_proofs::{ + plonk::{ + Any, ConstraintSystem, FirstPhase, SecondPhase, ThirdPhase, VerifyingKey, {self}, + }, + poly::{ + commitment::Params, + {self}, + }, + transcript::{EncodedChallenge, Transcript}, + }, util::{ arithmetic::{root_of_unity, CurveAffine, Domain, FieldExt, Rotation}, protocol::{ diff --git a/snark-verifier/src/system/halo2/test.rs b/snark-verifier/src/system/halo2/test.rs index 6994e561..63756ebb 100644 --- a/snark-verifier/src/system/halo2/test.rs +++ b/snark-verifier/src/system/halo2/test.rs @@ -1,15 +1,17 @@ #![allow(dead_code)] #![allow(clippy::all)] -use crate::halo2_proofs::{ - dev::MockProver, - plonk::{create_proof, verify_proof, Circuit, ProvingKey}, - poly::{ - commitment::{CommitmentScheme, Params, ParamsProver, Prover, Verifier}, - VerificationStrategy, +use crate::{ + halo2_proofs::{ + dev::MockProver, + plonk::{create_proof, verify_proof, Circuit, ProvingKey}, + poly::{ + commitment::{CommitmentScheme, Params, ParamsProver, Prover, Verifier}, + VerificationStrategy, + }, + transcript::{EncodedChallenge, TranscriptReadBuffer, TranscriptWriterBuffer}, }, - transcript::{EncodedChallenge, TranscriptReadBuffer, TranscriptWriterBuffer}, + util::arithmetic::CurveAffine, }; -use crate::util::arithmetic::CurveAffine; use rand_chacha::rand_core::RngCore; use std::{fs, io::Cursor}; @@ -203,12 +205,13 @@ macro_rules! halo2_native_verify { $svk:expr, $dk:expr ) => {{ - use $crate::halo2_proofs::poly::commitment::ParamsProver; - use $crate::verifier::PlonkVerifier; + use $crate::{halo2_proofs::poly::commitment::ParamsProver, verifier::PlonkVerifier}; let proof = <$plonk_verifier>::read_proof($svk, $protocol, $instances, $transcript); assert!(<$plonk_verifier>::verify($svk, $dk, $protocol, $instances, &proof)) }}; } -pub(crate) use {halo2_create_snark, halo2_native_verify, halo2_prepare}; +pub(crate) use halo2_create_snark; +pub(crate) use halo2_native_verify; +pub(crate) use halo2_prepare; diff --git a/snark-verifier/src/system/halo2/test/circuit/standard.rs b/snark-verifier/src/system/halo2/test/circuit/standard.rs index b4f3c12e..d7d30b68 100644 --- a/snark-verifier/src/system/halo2/test/circuit/standard.rs +++ b/snark-verifier/src/system/halo2/test/circuit/standard.rs @@ -1,9 +1,11 @@ -use crate::halo2_proofs::{ - circuit::{Layouter, SimpleFloorPlanner, Value}, - plonk::{Advice, Circuit, Column, ConstraintSystem, Error, Fixed, Instance}, - poly::Rotation, +use crate::{ + halo2_proofs::{ + circuit::{Layouter, SimpleFloorPlanner, Value}, + plonk::{Advice, Circuit, Column, ConstraintSystem, Error, Fixed, Instance}, + poly::Rotation, + }, + util::arithmetic::FieldExt, }; -use crate::util::arithmetic::FieldExt; use rand::RngCore; #[allow(dead_code)] diff --git a/snark-verifier/src/system/halo2/test/kzg.rs b/snark-verifier/src/system/halo2/test/kzg.rs index 6cf145db..8e2fbb35 100644 --- a/snark-verifier/src/system/halo2/test/kzg.rs +++ b/snark-verifier/src/system/halo2/test/kzg.rs @@ -1,5 +1,4 @@ -use crate::halo2_proofs::poly::kzg::commitment::ParamsKZG; -use crate::util::arithmetic::MultiMillerLoop; +use crate::{halo2_proofs::poly::kzg::commitment::ParamsKZG, util::arithmetic::MultiMillerLoop}; use rand_chacha::{rand_core::SeedableRng, ChaCha20Rng}; mod native; @@ -36,10 +35,11 @@ macro_rules! halo2_kzg_prepare { ($k:expr, $config:expr, $create_circuit:expr) => {{ use $crate::halo2_curves::bn256::Bn256; #[allow(unused_imports)] - use $crate::system::halo2::test::{ - halo2_prepare, - kzg::{setup, TESTDATA_DIR}, - }; + use $crate::system::halo2::test::halo2_prepare; + #[allow(unused_imports)] + use $crate::system::halo2::test::kzg::setup; + #[allow(unused_imports)] + use $crate::system::halo2::test::kzg::TESTDATA_DIR; halo2_prepare!(TESTDATA_DIR, $k, setup::, $config, $create_circuit) }}; @@ -57,10 +57,10 @@ macro_rules! halo2_kzg_create_snark { $protocol:expr, $circuits:expr ) => {{ - use $crate::halo2_proofs::poly::kzg::{ - commitment::KZGCommitmentScheme, strategy::SingleStrategy, + use $crate::{ + halo2_proofs::poly::kzg::{commitment::KZGCommitmentScheme, strategy::SingleStrategy}, + system::halo2::test::halo2_create_snark, }; - use $crate::system::halo2::test::halo2_create_snark; halo2_create_snark!( KZGCommitmentScheme<_>, @@ -101,6 +101,7 @@ macro_rules! halo2_kzg_native_verify { }}; } -pub(crate) use { - halo2_kzg_config, halo2_kzg_create_snark, halo2_kzg_native_verify, halo2_kzg_prepare, -}; +pub(crate) use halo2_kzg_config; +pub(crate) use halo2_kzg_create_snark; +pub(crate) use halo2_kzg_native_verify; +pub(crate) use halo2_kzg_prepare; diff --git a/snark-verifier/src/system/halo2/test/kzg/evm.rs b/snark-verifier/src/system/halo2/test/kzg/evm.rs index 80439205..4f92c95c 100644 --- a/snark-verifier/src/system/halo2/test/kzg/evm.rs +++ b/snark-verifier/src/system/halo2/test/kzg/evm.rs @@ -1,12 +1,12 @@ -use crate::{halo2_curves, halo2_proofs}; use crate::{ + halo2_curves, halo2_proofs, loader::native::NativeLoader, pcs::kzg::{Bdfg21, Gwc19, Kzg, LimbsEncoding}, system::halo2::{ test::{ kzg::{ - self, halo2_kzg_config, halo2_kzg_create_snark, halo2_kzg_native_verify, - halo2_kzg_prepare, BITS, LIMBS, + halo2_kzg_config, halo2_kzg_create_snark, halo2_kzg_native_verify, + halo2_kzg_prepare, BITS, LIMBS, {self}, }, StandardPlonk, }, diff --git a/snark-verifier/src/system/halo2/test/kzg/halo2.rs b/snark-verifier/src/system/halo2/test/kzg/halo2.rs index 15006fe0..0caa0e38 100644 --- a/snark-verifier/src/system/halo2/test/kzg/halo2.rs +++ b/snark-verifier/src/system/halo2/test/kzg/halo2.rs @@ -1,24 +1,26 @@ -use crate::halo2_curves::bn256::{Bn256, Fq, Fr, G1Affine}; -use crate::halo2_proofs::{ - circuit::{Layouter, SimpleFloorPlanner, Value}, - plonk::{self, create_proof, verify_proof, Circuit, Column, ConstraintSystem, Instance}, - poly::{ - commitment::ParamsProver, - kzg::{ - commitment::{KZGCommitmentScheme, ParamsKZG}, - multiopen::{ProverSHPLONK, VerifierSHPLONK}, - strategy::SingleStrategy, +use crate::{ + halo2_curves::bn256::{Bn256, Fq, Fr, G1Affine}, + halo2_proofs::{ + circuit::{Layouter, SimpleFloorPlanner, Value}, + plonk::{ + create_proof, verify_proof, Circuit, Column, ConstraintSystem, Instance, {self}, + }, + poly::{ + commitment::ParamsProver, + kzg::{ + commitment::{KZGCommitmentScheme, ParamsKZG}, + multiopen::{ProverSHPLONK, VerifierSHPLONK}, + strategy::SingleStrategy, + }, + }, + transcript::{ + Blake2bRead, Blake2bWrite, Challenge255, TranscriptReadBuffer, TranscriptWriterBuffer, }, }, - transcript::{ - Blake2bRead, Blake2bWrite, Challenge255, TranscriptReadBuffer, TranscriptWriterBuffer, - }, -}; -use crate::{ loader::{ - self, halo2::test::{Snark, SnarkWitness}, native::NativeLoader, + {self}, }, pcs::{ kzg::{ @@ -38,17 +40,18 @@ use crate::{ transcript::halo2::{ChallengeScalar, PoseidonTranscript as GenericPoseidonTranscript}, }, util::{arithmetic::fe_to_limbs, Itertools}, - verifier::{self, PlonkVerifier}, + verifier::{ + PlonkVerifier, {self}, + }, }; use ark_std::{end_timer, start_timer}; use halo2_base::{Context, ContextParams}; -use halo2_ecc::ecc::EccChip; -use halo2_ecc::fields::fp::FpConfig; +use halo2_ecc::{ecc::EccChip, fields::fp::FpConfig}; use paste::paste; use rand_chacha::{rand_core::SeedableRng, ChaCha20Rng}; use serde::{Deserialize, Serialize}; -use std::fs::File; use std::{ + fs::File, io::{Cursor, Read, Write}, rc::Rc, }; diff --git a/snark-verifier/src/system/halo2/test/kzg/native.rs b/snark-verifier/src/system/halo2/test/kzg/native.rs index 0801a317..0da8b241 100644 --- a/snark-verifier/src/system/halo2/test/kzg/native.rs +++ b/snark-verifier/src/system/halo2/test/kzg/native.rs @@ -1,9 +1,9 @@ -use crate::halo2_curves::bn256::{Bn256, G1Affine}; -use crate::halo2_proofs::{ - poly::kzg::multiopen::{ProverGWC, ProverSHPLONK, VerifierGWC, VerifierSHPLONK}, - transcript::{Blake2bRead, Blake2bWrite, Challenge255, TranscriptReadBuffer}, -}; use crate::{ + halo2_curves::bn256::{Bn256, G1Affine}, + halo2_proofs::{ + poly::kzg::multiopen::{ProverGWC, ProverSHPLONK, VerifierGWC, VerifierSHPLONK}, + transcript::{Blake2bRead, Blake2bWrite, Challenge255, TranscriptReadBuffer}, + }, pcs::kzg::{Bdfg21, Gwc19, Kzg, LimbsEncoding}, system::halo2::test::{ kzg::{ diff --git a/snark-verifier/src/system/halo2/transcript.rs b/snark-verifier/src/system/halo2/transcript.rs index 2a9cc6ca..49f8a143 100644 --- a/snark-verifier/src/system/halo2/transcript.rs +++ b/snark-verifier/src/system/halo2/transcript.rs @@ -1,8 +1,10 @@ //! Transcripts implemented with both `halo2_proofs::transcript` and //! `crate::util::transcript`. -use crate::halo2_proofs; use crate::{ - loader::native::{self, NativeLoader}, + halo2_proofs, + loader::native::{ + NativeLoader, {self}, + }, util::{ arithmetic::CurveAffine, transcript::{Transcript, TranscriptRead, TranscriptWrite}, diff --git a/snark-verifier/src/system/halo2/transcript/evm.rs b/snark-verifier/src/system/halo2/transcript/evm.rs index d5e1b4d0..079b066e 100644 --- a/snark-verifier/src/system/halo2/transcript/evm.rs +++ b/snark-verifier/src/system/halo2/transcript/evm.rs @@ -1,9 +1,11 @@ //! Transcript for verifier on EVM. -use crate::halo2_proofs; use crate::{ + halo2_proofs, loader::{ evm::{loader::Value, u256_to_fe, EcPoint, EvmLoader, MemoryChunk, Scalar}, - native::{self, NativeLoader}, + native::{ + NativeLoader, {self}, + }, Loader, }, util::{ @@ -17,7 +19,9 @@ use crate::{ use ethereum_types::U256; use halo2_proofs::transcript::EncodedChallenge; use std::{ - io::{self, Read, Write}, + io::{ + Read, Write, {self}, + }, iter, marker::PhantomData, rc::Rc, diff --git a/snark-verifier/src/system/halo2/transcript/halo2.rs b/snark-verifier/src/system/halo2/transcript/halo2.rs index e0967602..2878f60e 100644 --- a/snark-verifier/src/system/halo2/transcript/halo2.rs +++ b/snark-verifier/src/system/halo2/transcript/halo2.rs @@ -1,9 +1,11 @@ //! Transcript for verifier in [`halo2_proofs`] circuit. -use crate::halo2_proofs; use crate::{ + halo2_proofs, loader::{ halo2::{EcPoint, EccInstructions, Halo2Loader, Scalar}, - native::{self, NativeLoader}, + native::{ + NativeLoader, {self}, + }, Loader, ScalarLoader, }, util::{ @@ -16,7 +18,9 @@ use crate::{ }; use halo2_proofs::{circuit::Value, transcript::EncodedChallenge}; use std::{ - io::{self, Read, Write}, + io::{ + Read, Write, {self}, + }, rc::Rc, }; @@ -421,8 +425,7 @@ where } mod halo2_lib { - use crate::halo2_curves::CurveAffineExt; - use crate::system::halo2::transcript::halo2::NativeEncoding; + use crate::{halo2_curves::CurveAffineExt, system::halo2::transcript::halo2::NativeEncoding}; use halo2_base::utils::BigPrimeField as PrimeField; use halo2_ecc::ecc::BaseFieldEccChip; diff --git a/snark-verifier/src/util/hash.rs b/snark-verifier/src/util/hash.rs index 758e26d5..47e988b2 100644 --- a/snark-verifier/src/util/hash.rs +++ b/snark-verifier/src/util/hash.rs @@ -5,4 +5,6 @@ mod poseidon; pub use crate::util::hash::poseidon::Poseidon; #[cfg(feature = "loader_evm")] -pub use sha3::{Digest, Keccak256}; +pub use sha3::Digest; +#[cfg(feature = "loader_evm")] +pub use sha3::Keccak256; diff --git a/snark-verifier/src/util/hash/poseidon.rs b/snark-verifier/src/util/hash/poseidon.rs index 0b04d71b..4b9fc9fe 100644 --- a/snark-verifier/src/util/hash/poseidon.rs +++ b/snark-verifier/src/util/hash/poseidon.rs @@ -1,6 +1,8 @@ -use crate::poseidon::{self, SparseMDSMatrix, Spec}; use crate::{ loader::{LoadedScalar, ScalarLoader}, + poseidon::{ + SparseMDSMatrix, Spec, {self}, + }, util::{arithmetic::FieldExt, Itertools}, }; use std::{iter, marker::PhantomData, mem}; diff --git a/snark-verifier/src/util/msm.rs b/snark-verifier/src/util/msm.rs index 281cd3fa..c8398033 100644 --- a/snark-verifier/src/util/msm.rs +++ b/snark-verifier/src/util/msm.rs @@ -8,7 +8,9 @@ use crate::{ use num_integer::Integer; use std::{ default::Default, - iter::{self, Sum}, + iter::{ + Sum, {self}, + }, mem::size_of, ops::{Add, AddAssign, Mul, MulAssign, Neg, Sub, SubAssign}, }; diff --git a/snark-verifier/src/util/poly.rs b/snark-verifier/src/util/poly.rs index 810ef43d..9eb23c35 100644 --- a/snark-verifier/src/util/poly.rs +++ b/snark-verifier/src/util/poly.rs @@ -1,7 +1,9 @@ use crate::util::{arithmetic::Field, parallelize}; use rand::Rng; use std::{ - iter::{self, Sum}, + iter::{ + Sum, {self}, + }, ops::{ Add, Index, IndexMut, Mul, Range, RangeFrom, RangeFull, RangeInclusive, RangeTo, RangeToInclusive, Sub, diff --git a/snark-verifier/src/util/protocol.rs b/snark-verifier/src/util/protocol.rs index a883a599..e6e698cd 100644 --- a/snark-verifier/src/util/protocol.rs +++ b/snark-verifier/src/util/protocol.rs @@ -13,7 +13,9 @@ use std::{ cmp::max, collections::{BTreeMap, BTreeSet}, fmt::Debug, - iter::{self, Sum}, + iter::{ + Sum, {self}, + }, ops::{Add, Mul, Neg, Sub}, }; diff --git a/snark-verifier/src/util/transcript.rs b/snark-verifier/src/util/transcript.rs index 3337324d..967ed7d2 100644 --- a/snark-verifier/src/util/transcript.rs +++ b/snark-verifier/src/util/transcript.rs @@ -1,6 +1,7 @@ use crate::{ loader::{native::NativeLoader, Loader}, - {util::arithmetic::CurveAffine, Error}, + util::arithmetic::CurveAffine, + Error, }; pub trait Transcript diff --git a/snark-verifier/src/verifier/plonk.rs b/snark-verifier/src/verifier/plonk.rs index 48ba9231..524c3371 100644 --- a/snark-verifier/src/verifier/plonk.rs +++ b/snark-verifier/src/verifier/plonk.rs @@ -1,7 +1,9 @@ use crate::{ cost::{Cost, CostEstimation}, loader::{native::NativeLoader, LoadedScalar, Loader}, - pcs::{self, AccumulatorEncoding, MultiOpenScheme}, + pcs::{ + AccumulatorEncoding, MultiOpenScheme, {self}, + }, util::{ arithmetic::{CurveAffine, Field, Rotation}, msm::Msm,