diff --git a/prover/Cargo.lock b/prover/Cargo.lock index cff651cc37..34878db5e6 100644 --- a/prover/Cargo.lock +++ b/prover/Cargo.lock @@ -30,18 +30,18 @@ dependencies = [ [[package]] name = "aggregator" -version = "0.12.0" -source = "git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.12.2#6f7b46a3b1ccf9dc448735e8455e1ac6f9e30643" +version = "0.13.0" +source = "git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.13.1#4009e5593f13ba73f64f556011ee5ef47bc4ebf3" dependencies = [ "ark-std 0.3.0", "bitstream-io", - "c-kzg", + "c-kzg 1.0.2", "ctor 0.1.26", "encoder", "env_logger 0.10.2", - "eth-types 0.12.0", + "eth-types 0.13.0 (git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.13.1)", "ethers-core 2.0.7 (git+https://github.com/scroll-tech/ethers-rs.git?branch=v2.0.7)", - "gadgets 0.12.0", + "gadgets 0.13.0 (git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.13.1)", "halo2-base", "halo2-ecc", "halo2_proofs", @@ -51,31 +51,31 @@ dependencies = [ "num-bigint", "once_cell", "rand", - "revm-precompile", - "revm-primitives", + "revm-precompile 7.0.0", + "revm-primitives 4.0.0", "serde", "serde_json", - "snark-verifier", - "snark-verifier-sdk", + "snark-verifier 0.1.0 (git+https://github.com/scroll-tech/snark-verifier?branch=develop)", + "snark-verifier-sdk 0.0.1 (git+https://github.com/scroll-tech/snark-verifier?branch=develop)", "strum 0.25.0", "strum_macros 0.25.3", - "zkevm-circuits 0.12.0", + "zkevm-circuits 0.13.0 (git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.13.1)", ] [[package]] name = "aggregator" version = "0.13.0" -source = "git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.13.1#4009e5593f13ba73f64f556011ee5ef47bc4ebf3" +source = "git+https://github.com/scroll-tech/zkevm-circuits.git?branch=feat/hybrid-snark-agg#667ace4c4526598cdc95e5322da6ccd62d0787a4" dependencies = [ "ark-std 0.3.0", "bitstream-io", - "c-kzg", + "c-kzg 1.0.2", "ctor 0.1.26", "encoder", "env_logger 0.10.2", - "eth-types 0.13.0", + "eth-types 0.13.0 (git+https://github.com/scroll-tech/zkevm-circuits.git?branch=feat/hybrid-snark-agg)", "ethers-core 2.0.7 (git+https://github.com/scroll-tech/ethers-rs.git?branch=v2.0.7)", - "gadgets 0.13.0", + "gadgets 0.13.0 (git+https://github.com/scroll-tech/zkevm-circuits.git?branch=feat/hybrid-snark-agg)", "halo2-base", "halo2-ecc", "halo2_proofs", @@ -85,15 +85,15 @@ dependencies = [ "num-bigint", "once_cell", "rand", - "revm-precompile", - "revm-primitives", + "revm-precompile 7.0.0", + "revm-primitives 4.0.0", "serde", "serde_json", - "snark-verifier", - "snark-verifier-sdk", + "snark-verifier 0.1.0 (git+https://github.com/scroll-tech/snark-verifier?branch=feat/hybrid-snark-agg)", + "snark-verifier-sdk 0.0.1 (git+https://github.com/scroll-tech/snark-verifier?branch=feat/hybrid-snark-agg)", "strum 0.25.0", "strum_macros 0.25.3", - "zkevm-circuits 0.13.0", + "zkevm-circuits 0.13.0 (git+https://github.com/scroll-tech/zkevm-circuits.git?branch=feat/hybrid-snark-agg)", ] [[package]] @@ -123,6 +123,23 @@ version = "0.2.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5c6cb57a04249c6480766f7f7cef5467412af1490f8d1e243141daddada3264f" +[[package]] +name = "alloy-primitives" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a0628ec0ba5b98b3370bb6be17b12f23bfce8ee4ad83823325a20546d9b03b78" +dependencies = [ + "alloy-rlp", + "bytes", + "cfg-if 1.0.0", + "const-hex", + "derive_more", + "hex-literal", + "itoa", + "ruint", + "tiny-keccak", +] + [[package]] name = "alloy-primitives" version = "0.7.4" @@ -151,10 +168,22 @@ version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b155716bab55763c95ba212806cf43d05bcc70e5f35b02bad20cf5ec7fe11fed" dependencies = [ + "alloy-rlp-derive", "arrayvec", "bytes", ] +[[package]] +name = "alloy-rlp-derive" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b09cae092c27b6f1bde952653a22708691802e57bfef4a2973b80bea21efd3f" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.66", +] + [[package]] name = "android-tzdata" version = "0.1.1" @@ -501,6 +530,29 @@ dependencies = [ "serde", ] +[[package]] +name = "bindgen" +version = "0.66.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2b84e06fc203107bfbad243f4aba2af864eb7db3b1cf46ea0a023b0b433d2a7" +dependencies = [ + "bitflags 2.5.0", + "cexpr", + "clang-sys", + "lazy_static", + "lazycell", + "log", + "peeking_take_while", + "prettyplease", + "proc-macro2", + "quote", + "regex", + "rustc-hash", + "shlex", + "syn 2.0.66", + "which", +] + [[package]] name = "bit-set" version = "0.5.3" @@ -634,23 +686,23 @@ checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" [[package]] name = "bus-mapping" -version = "0.12.0" -source = "git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.12.2#6f7b46a3b1ccf9dc448735e8455e1ac6f9e30643" +version = "0.13.0" +source = "git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.13.1#4009e5593f13ba73f64f556011ee5ef47bc4ebf3" dependencies = [ - "eth-types 0.12.0", + "eth-types 0.13.0 (git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.13.1)", "ethers-core 2.0.7 (git+https://github.com/scroll-tech/ethers-rs.git?branch=v2.0.7)", "ethers-providers 2.0.7 (registry+https://github.com/rust-lang/crates.io-index)", "ethers-signers", - "gadgets 0.12.0", + "gadgets 0.13.0 (git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.13.1)", "halo2_proofs", "hex", "itertools 0.11.0", "log", - "mock 0.12.0", - "mpt-zktrie 0.12.0", + "mock 0.13.0 (git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.13.1)", + "mpt-zktrie 0.13.0 (git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.13.1)", "num", "poseidon-circuit", - "revm-precompile", + "revm-precompile 7.0.0", "serde", "serde_json", "strum 0.25.0", @@ -660,22 +712,22 @@ dependencies = [ [[package]] name = "bus-mapping" version = "0.13.0" -source = "git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.13.1#4009e5593f13ba73f64f556011ee5ef47bc4ebf3" +source = "git+https://github.com/scroll-tech/zkevm-circuits.git?branch=feat/hybrid-snark-agg#667ace4c4526598cdc95e5322da6ccd62d0787a4" dependencies = [ - "eth-types 0.13.0", + "eth-types 0.13.0 (git+https://github.com/scroll-tech/zkevm-circuits.git?branch=feat/hybrid-snark-agg)", "ethers-core 2.0.7 (git+https://github.com/scroll-tech/ethers-rs.git?branch=v2.0.7)", "ethers-providers 2.0.7 (registry+https://github.com/rust-lang/crates.io-index)", "ethers-signers", - "gadgets 0.13.0", + "gadgets 0.13.0 (git+https://github.com/scroll-tech/zkevm-circuits.git?branch=feat/hybrid-snark-agg)", "halo2_proofs", "hex", "itertools 0.11.0", "log", - "mock 0.13.0", - "mpt-zktrie 0.13.0", + "mock 0.13.0 (git+https://github.com/scroll-tech/zkevm-circuits.git?branch=feat/hybrid-snark-agg)", + "mpt-zktrie 0.13.0 (git+https://github.com/scroll-tech/zkevm-circuits.git?branch=feat/hybrid-snark-agg)", "num", "poseidon-circuit", - "revm-precompile", + "revm-precompile 7.0.0", "serde", "serde_json", "strum 0.25.0", @@ -703,6 +755,21 @@ dependencies = [ "serde", ] +[[package]] +name = "c-kzg" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac926d808fb72fe09ebf471a091d6d72918876ccf0b4989766093d2d0d24a0ef" +dependencies = [ + "bindgen", + "blst", + "cc", + "glob", + "hex", + "libc", + "serde", +] + [[package]] name = "c-kzg" version = "1.0.2" @@ -728,6 +795,15 @@ dependencies = [ "once_cell", ] +[[package]] +name = "cexpr" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6fac387a98bb7c37292057cffc56d62ecb629900026402633ae9160df93a8766" +dependencies = [ + "nom", +] + [[package]] name = "cfg-if" version = "0.1.10" @@ -764,6 +840,17 @@ dependencies = [ "inout", ] +[[package]] +name = "clang-sys" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b023947811758c97c59bf9d1c188fd619ad4718dcaa767947df1cadb14f39f4" +dependencies = [ + "glob", + "libc", + "libloading", +] + [[package]] name = "clap" version = "4.5.4" @@ -1309,8 +1396,8 @@ dependencies = [ [[package]] name = "eth-types" -version = "0.12.0" -source = "git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.12.2#6f7b46a3b1ccf9dc448735e8455e1ac6f9e30643" +version = "0.13.0" +source = "git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.13.1#4009e5593f13ba73f64f556011ee5ef47bc4ebf3" dependencies = [ "base64 0.13.1", "ethers-core 2.0.7 (git+https://github.com/scroll-tech/ethers-rs.git?branch=v2.0.7)", @@ -1323,8 +1410,8 @@ dependencies = [ "num-bigint", "poseidon-base", "regex", - "revm-precompile", - "revm-primitives", + "revm-precompile 7.0.0", + "revm-primitives 4.0.0", "serde", "serde_json", "serde_with", @@ -1338,7 +1425,7 @@ dependencies = [ [[package]] name = "eth-types" version = "0.13.0" -source = "git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.13.1#4009e5593f13ba73f64f556011ee5ef47bc4ebf3" +source = "git+https://github.com/scroll-tech/zkevm-circuits.git?branch=feat/hybrid-snark-agg#667ace4c4526598cdc95e5322da6ccd62d0787a4" dependencies = [ "base64 0.13.1", "ethers-core 2.0.7 (git+https://github.com/scroll-tech/ethers-rs.git?branch=v2.0.7)", @@ -1351,8 +1438,8 @@ dependencies = [ "num-bigint", "poseidon-base", "regex", - "revm-precompile", - "revm-primitives", + "revm-precompile 7.0.0", + "revm-primitives 4.0.0", "serde", "serde_json", "serde_with", @@ -1557,11 +1644,11 @@ dependencies = [ [[package]] name = "external-tracer" -version = "0.12.0" -source = "git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.12.2#6f7b46a3b1ccf9dc448735e8455e1ac6f9e30643" +version = "0.13.0" +source = "git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.13.1#4009e5593f13ba73f64f556011ee5ef47bc4ebf3" dependencies = [ - "eth-types 0.12.0", - "geth-utils 0.12.0", + "eth-types 0.13.0 (git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.13.1)", + "geth-utils 0.13.0 (git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.13.1)", "log", "serde", "serde_json", @@ -1571,10 +1658,10 @@ dependencies = [ [[package]] name = "external-tracer" version = "0.13.0" -source = "git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.13.1#4009e5593f13ba73f64f556011ee5ef47bc4ebf3" +source = "git+https://github.com/scroll-tech/zkevm-circuits.git?branch=feat/hybrid-snark-agg#667ace4c4526598cdc95e5322da6ccd62d0787a4" dependencies = [ - "eth-types 0.13.0", - "geth-utils 0.13.0", + "eth-types 0.13.0 (git+https://github.com/scroll-tech/zkevm-circuits.git?branch=feat/hybrid-snark-agg)", + "geth-utils 0.13.0 (git+https://github.com/scroll-tech/zkevm-circuits.git?branch=feat/hybrid-snark-agg)", "log", "serde", "serde_json", @@ -1787,10 +1874,10 @@ dependencies = [ [[package]] name = "gadgets" -version = "0.12.0" -source = "git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.12.2#6f7b46a3b1ccf9dc448735e8455e1ac6f9e30643" +version = "0.13.0" +source = "git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.13.1#4009e5593f13ba73f64f556011ee5ef47bc4ebf3" dependencies = [ - "eth-types 0.12.0", + "eth-types 0.13.0 (git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.13.1)", "halo2_proofs", "poseidon-base", "sha3 0.10.8", @@ -1800,9 +1887,9 @@ dependencies = [ [[package]] name = "gadgets" version = "0.13.0" -source = "git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.13.1#4009e5593f13ba73f64f556011ee5ef47bc4ebf3" +source = "git+https://github.com/scroll-tech/zkevm-circuits.git?branch=feat/hybrid-snark-agg#667ace4c4526598cdc95e5322da6ccd62d0787a4" dependencies = [ - "eth-types 0.13.0", + "eth-types 0.13.0 (git+https://github.com/scroll-tech/zkevm-circuits.git?branch=feat/hybrid-snark-agg)", "halo2_proofs", "poseidon-base", "sha3 0.10.8", @@ -1822,8 +1909,8 @@ dependencies = [ [[package]] name = "geth-utils" -version = "0.12.0" -source = "git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.12.2#6f7b46a3b1ccf9dc448735e8455e1ac6f9e30643" +version = "0.13.0" +source = "git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.13.1#4009e5593f13ba73f64f556011ee5ef47bc4ebf3" dependencies = [ "env_logger 0.10.2", "gobuild", @@ -1833,7 +1920,7 @@ dependencies = [ [[package]] name = "geth-utils" version = "0.13.0" -source = "git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.13.1#4009e5593f13ba73f64f556011ee5ef47bc4ebf3" +source = "git+https://github.com/scroll-tech/zkevm-circuits.git?branch=feat/hybrid-snark-agg#667ace4c4526598cdc95e5322da6ccd62d0787a4" dependencies = [ "env_logger 0.10.2", "gobuild", @@ -2159,6 +2246,15 @@ dependencies = [ "digest 0.10.7", ] +[[package]] +name = "home" +version = "0.5.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3d1354bf6b7235cb4a0576c2619fd4ed18183f689b12b006a0ee7329eeff9a5" +dependencies = [ + "windows-sys 0.52.0", +] + [[package]] name = "http" version = "0.2.12" @@ -2551,12 +2647,28 @@ dependencies = [ "spin 0.5.2", ] +[[package]] +name = "lazycell" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" + [[package]] name = "libc" version = "0.2.155" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" +[[package]] +name = "libloading" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4979f22fdb869068da03c9f7528f8297c6fd2606bc3a4affe42e6a823fdb8da4" +dependencies = [ + "cfg-if 1.0.0", + "windows-targets 0.48.5", +] + [[package]] name = "libm" version = "0.2.8" @@ -2634,6 +2746,12 @@ version = "0.3.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" +[[package]] +name = "minimal-lexical" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" + [[package]] name = "miniz_oxide" version = "0.7.3" @@ -2672,13 +2790,13 @@ dependencies = [ [[package]] name = "mock" -version = "0.12.0" -source = "git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.12.2#6f7b46a3b1ccf9dc448735e8455e1ac6f9e30643" +version = "0.13.0" +source = "git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.13.1#4009e5593f13ba73f64f556011ee5ef47bc4ebf3" dependencies = [ - "eth-types 0.12.0", + "eth-types 0.13.0 (git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.13.1)", "ethers-core 2.0.7 (git+https://github.com/scroll-tech/ethers-rs.git?branch=v2.0.7)", "ethers-signers", - "external-tracer 0.12.0", + "external-tracer 0.13.0 (git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.13.1)", "itertools 0.11.0", "log", "rand", @@ -2688,12 +2806,12 @@ dependencies = [ [[package]] name = "mock" version = "0.13.0" -source = "git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.13.1#4009e5593f13ba73f64f556011ee5ef47bc4ebf3" +source = "git+https://github.com/scroll-tech/zkevm-circuits.git?branch=feat/hybrid-snark-agg#667ace4c4526598cdc95e5322da6ccd62d0787a4" dependencies = [ - "eth-types 0.13.0", + "eth-types 0.13.0 (git+https://github.com/scroll-tech/zkevm-circuits.git?branch=feat/hybrid-snark-agg)", "ethers-core 2.0.7 (git+https://github.com/scroll-tech/ethers-rs.git?branch=v2.0.7)", "ethers-signers", - "external-tracer 0.13.0", + "external-tracer 0.13.0 (git+https://github.com/scroll-tech/zkevm-circuits.git?branch=feat/hybrid-snark-agg)", "itertools 0.11.0", "log", "rand", @@ -2702,30 +2820,30 @@ dependencies = [ [[package]] name = "mpt-zktrie" -version = "0.12.0" -source = "git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.12.2#6f7b46a3b1ccf9dc448735e8455e1ac6f9e30643" +version = "0.13.0" +source = "git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.13.1#4009e5593f13ba73f64f556011ee5ef47bc4ebf3" dependencies = [ - "eth-types 0.12.0", + "eth-types 0.13.0 (git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.13.1)", "halo2curves", "hex", "log", "num-bigint", "poseidon-base", - "zktrie 0.3.0 (git+https://github.com/scroll-tech/zktrie.git?branch=main)", + "zktrie", ] [[package]] name = "mpt-zktrie" version = "0.13.0" -source = "git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.13.1#4009e5593f13ba73f64f556011ee5ef47bc4ebf3" +source = "git+https://github.com/scroll-tech/zkevm-circuits.git?branch=feat/hybrid-snark-agg#667ace4c4526598cdc95e5322da6ccd62d0787a4" dependencies = [ - "eth-types 0.13.0", + "eth-types 0.13.0 (git+https://github.com/scroll-tech/zkevm-circuits.git?branch=feat/hybrid-snark-agg)", "halo2curves", "hex", "log", "num-bigint", "poseidon-base", - "zktrie 0.3.0 (git+https://github.com/scroll-tech/zktrie.git?branch=v0.9)", + "zktrie", ] [[package]] @@ -2746,6 +2864,16 @@ dependencies = [ "tempfile", ] +[[package]] +name = "nom" +version = "7.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a" +dependencies = [ + "memchr", + "minimal-lexical", +] + [[package]] name = "num" version = "0.4.3" @@ -3097,6 +3225,12 @@ dependencies = [ "hmac", ] +[[package]] +name = "peeking_take_while" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099" + [[package]] name = "percent-encoding" version = "2.3.1" @@ -3211,6 +3345,16 @@ version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" +[[package]] +name = "prettyplease" +version = "0.2.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f12335488a2f3b0a83b14edad48dca9879ce89b2edd10e80237e4e852dd645e" +dependencies = [ + "proc-macro2", + "syn 2.0.66", +] + [[package]] name = "primitive-types" version = "0.12.2" @@ -3291,8 +3435,8 @@ dependencies = [ "http 1.1.0", "log", "once_cell", - "prover 0.12.0", - "prover 0.13.0", + "prover 0.13.0 (git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.13.1)", + "prover 0.13.0 (git+https://github.com/scroll-tech/zkevm-circuits.git?branch=feat/hybrid-snark-agg)", "rand", "reqwest 0.12.4", "reqwest-middleware", @@ -3301,24 +3445,24 @@ dependencies = [ "serde", "serde_json", "sled", - "snark-verifier-sdk", + "snark-verifier-sdk 0.0.1 (git+https://github.com/scroll-tech/snark-verifier?branch=develop)", "tiny-keccak", "tokio", ] [[package]] name = "prover" -version = "0.12.0" -source = "git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.12.2#6f7b46a3b1ccf9dc448735e8455e1ac6f9e30643" +version = "0.13.0" +source = "git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.13.1#4009e5593f13ba73f64f556011ee5ef47bc4ebf3" dependencies = [ - "aggregator 0.12.0", + "aggregator 0.13.0 (git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.13.1)", "anyhow", "base64 0.13.1", "blake2", - "bus-mapping 0.12.0", + "bus-mapping 0.13.0 (git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.13.1)", "chrono", "dotenvy", - "eth-types 0.12.0", + "eth-types 0.13.0 (git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.13.1)", "ethers-core 2.0.7 (git+https://github.com/scroll-tech/ethers-rs.git?branch=v2.0.7)", "git-version", "halo2_proofs", @@ -3326,7 +3470,7 @@ dependencies = [ "itertools 0.11.0", "log", "log4rs", - "mpt-zktrie 0.12.0", + "mpt-zktrie 0.13.0 (git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.13.1)", "num-bigint", "rand", "rand_xorshift", @@ -3335,24 +3479,24 @@ dependencies = [ "serde_json", "serde_stacker", "sha2", - "snark-verifier", - "snark-verifier-sdk", - "zkevm-circuits 0.12.0", + "snark-verifier 0.1.0 (git+https://github.com/scroll-tech/snark-verifier?branch=develop)", + "snark-verifier-sdk 0.0.1 (git+https://github.com/scroll-tech/snark-verifier?branch=develop)", + "zkevm-circuits 0.13.0 (git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.13.1)", ] [[package]] name = "prover" version = "0.13.0" -source = "git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.13.1#4009e5593f13ba73f64f556011ee5ef47bc4ebf3" +source = "git+https://github.com/scroll-tech/zkevm-circuits.git?branch=feat/hybrid-snark-agg#667ace4c4526598cdc95e5322da6ccd62d0787a4" dependencies = [ - "aggregator 0.13.0", + "aggregator 0.13.0 (git+https://github.com/scroll-tech/zkevm-circuits.git?branch=feat/hybrid-snark-agg)", "anyhow", "base64 0.13.1", "blake2", - "bus-mapping 0.13.0", + "bus-mapping 0.13.0 (git+https://github.com/scroll-tech/zkevm-circuits.git?branch=feat/hybrid-snark-agg)", "chrono", "dotenvy", - "eth-types 0.13.0", + "eth-types 0.13.0 (git+https://github.com/scroll-tech/zkevm-circuits.git?branch=feat/hybrid-snark-agg)", "ethers-core 2.0.7 (git+https://github.com/scroll-tech/ethers-rs.git?branch=v2.0.7)", "git-version", "halo2_proofs", @@ -3360,18 +3504,20 @@ dependencies = [ "itertools 0.11.0", "log", "log4rs", - "mpt-zktrie 0.13.0", + "mpt-zktrie 0.13.0 (git+https://github.com/scroll-tech/zkevm-circuits.git?branch=feat/hybrid-snark-agg)", "num-bigint", "rand", "rand_xorshift", + "revm 3.5.0", "serde", "serde_derive", "serde_json", "serde_stacker", "sha2", - "snark-verifier", - "snark-verifier-sdk", - "zkevm-circuits 0.13.0", + "snark-verifier 0.1.0 (git+https://github.com/scroll-tech/snark-verifier?branch=feat/hybrid-snark-agg)", + "snark-verifier-sdk 0.0.1 (git+https://github.com/scroll-tech/snark-verifier?branch=feat/hybrid-snark-agg)", + "thiserror", + "zkevm-circuits 0.13.0 (git+https://github.com/scroll-tech/zkevm-circuits.git?branch=feat/hybrid-snark-agg)", ] [[package]] @@ -3660,32 +3806,85 @@ dependencies = [ "sha3 0.10.8", ] +[[package]] +name = "revm" +version = "3.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68f4ca8ae0345104523b4af1a8a7ea97cfa1865cdb7a7c25d23c1a18d9b48598" +dependencies = [ + "auto_impl", + "revm-interpreter", + "revm-precompile 2.2.0", +] + +[[package]] +name = "revm-interpreter" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f959cafdf64a7f89b014fa73dc2325001cf654b3d9400260b212d19a2ebe3da0" +dependencies = [ + "revm-primitives 1.3.0", +] + +[[package]] +name = "revm-precompile" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4d360a88223d85709d2e95d4609eb1e19c649c47e28954bfabae5e92bb37e83e" +dependencies = [ + "c-kzg 0.1.1", + "k256", + "num", + "once_cell", + "revm-primitives 1.3.0", + "ripemd", + "secp256k1 0.27.0", + "sha2", + "substrate-bn", +] + [[package]] name = "revm-precompile" version = "7.0.0" source = "git+https://github.com/scroll-tech/revm?branch=scroll-evm-executor/v36#36c304d9e9ba4e4b2d5468d91a6bd27210133b6a" dependencies = [ "aurora-engine-modexp", - "c-kzg", + "c-kzg 1.0.2", "k256", "once_cell", - "revm-primitives", + "revm-primitives 4.0.0", "ripemd", "secp256k1 0.29.0", "sha2", "substrate-bn", ] +[[package]] +name = "revm-primitives" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "51187b852d9e458816a2e19c81f1dd6c924077e1a8fccd16e4f044f865f299d7" +dependencies = [ + "alloy-primitives 0.4.2", + "alloy-rlp", + "auto_impl", + "bitflags 2.5.0", + "bitvec", + "enumn", + "hashbrown 0.14.5", + "hex", +] + [[package]] name = "revm-primitives" version = "4.0.0" source = "git+https://github.com/scroll-tech/revm?branch=scroll-evm-executor/v36#36c304d9e9ba4e4b2d5468d91a6bd27210133b6a" dependencies = [ - "alloy-primitives", + "alloy-primitives 0.7.4", "auto_impl", "bitflags 2.5.0", "bitvec", - "c-kzg", + "c-kzg 1.0.2", "cfg-if 1.0.0", "derive_more", "dyn-clone", @@ -4040,6 +4239,15 @@ dependencies = [ "secp256k1-sys 0.6.1", ] +[[package]] +name = "secp256k1" +version = "0.27.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25996b82292a7a57ed3508f052cfff8640d38d32018784acd714758b43da9c8f" +dependencies = [ + "secp256k1-sys 0.8.1", +] + [[package]] name = "secp256k1" version = "0.29.0" @@ -4059,6 +4267,15 @@ 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 = "secp256k1-sys" version = "0.10.0" @@ -4265,6 +4482,12 @@ dependencies = [ "cfg-if 1.0.0", ] +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + [[package]] name = "signature" version = "2.2.0" @@ -4322,7 +4545,30 @@ dependencies = [ "num-traits", "poseidon", "rand", - "revm", + "revm 2.3.1", + "rlp", + "rustc-hash", + "serde", + "sha3 0.10.8", +] + +[[package]] +name = "snark-verifier" +version = "0.1.0" +source = "git+https://github.com/scroll-tech/snark-verifier?branch=feat/hybrid-snark-agg#0d7c3ae2ea12b864fe8e361c1a2662039ac6c626" +dependencies = [ + "bytes", + "ethereum-types", + "halo2-base", + "halo2-ecc", + "hex", + "itertools 0.12.1", + "num-bigint", + "num-integer", + "num-traits", + "poseidon", + "rand", + "revm 2.3.1", "rlp", "rustc-hash", "serde", @@ -4348,7 +4594,29 @@ dependencies = [ "rand_chacha", "serde", "serde_json", - "snark-verifier", + "snark-verifier 0.1.0 (git+https://github.com/scroll-tech/snark-verifier?branch=develop)", +] + +[[package]] +name = "snark-verifier-sdk" +version = "0.0.1" +source = "git+https://github.com/scroll-tech/snark-verifier?branch=feat/hybrid-snark-agg#0d7c3ae2ea12b864fe8e361c1a2662039ac6c626" +dependencies = [ + "bincode", + "ethereum-types", + "ff", + "halo2-base", + "hex", + "itertools 0.12.1", + "log", + "num-bigint", + "num-integer", + "num-traits", + "rand", + "rand_chacha", + "serde", + "serde_json", + "snark-verifier 0.1.0 (git+https://github.com/scroll-tech/snark-verifier?branch=feat/hybrid-snark-agg)", ] [[package]] @@ -5059,6 +5327,18 @@ version = "0.25.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5f20c57d8d7db6d3b86154206ae5d8fba62dd39573114de97c2cb0578251f8e1" +[[package]] +name = "which" +version = "4.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87ba24419a2078cd2b0f2ede2691b6c66d8e47836da3b6db8265ebad47afbfc7" +dependencies = [ + "either", + "home", + "once_cell", + "rustix", +] + [[package]] name = "winapi" version = "0.3.9" @@ -5337,18 +5617,18 @@ dependencies = [ [[package]] name = "zkevm-circuits" -version = "0.12.0" -source = "git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.12.2#6f7b46a3b1ccf9dc448735e8455e1ac6f9e30643" +version = "0.13.0" +source = "git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.13.1#4009e5593f13ba73f64f556011ee5ef47bc4ebf3" dependencies = [ "array-init", - "bus-mapping 0.12.0", + "bus-mapping 0.13.0 (git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.13.1)", "either", "env_logger 0.10.2", - "eth-types 0.12.0", + "eth-types 0.13.0 (git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.13.1)", "ethers-core 2.0.7 (git+https://github.com/scroll-tech/ethers-rs.git?branch=v2.0.7)", "ethers-signers", "ff", - "gadgets 0.12.0", + "gadgets 0.13.0 (git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.13.1)", "halo2-base", "halo2-ecc", "halo2-mpt-circuits", @@ -5358,8 +5638,8 @@ dependencies = [ "itertools 0.11.0", "log", "misc-precompiled-circuit", - "mock 0.12.0", - "mpt-zktrie 0.12.0", + "mock 0.13.0 (git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.13.1)", + "mpt-zktrie 0.13.0 (git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.13.1)", "num", "num-bigint", "poseidon-circuit", @@ -5370,8 +5650,8 @@ dependencies = [ "serde", "serde_json", "sha3 0.10.8", - "snark-verifier", - "snark-verifier-sdk", + "snark-verifier 0.1.0 (git+https://github.com/scroll-tech/snark-verifier?branch=develop)", + "snark-verifier-sdk 0.0.1 (git+https://github.com/scroll-tech/snark-verifier?branch=develop)", "strum 0.25.0", "strum_macros 0.25.3", "subtle", @@ -5380,17 +5660,17 @@ dependencies = [ [[package]] name = "zkevm-circuits" version = "0.13.0" -source = "git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.13.1#4009e5593f13ba73f64f556011ee5ef47bc4ebf3" +source = "git+https://github.com/scroll-tech/zkevm-circuits.git?branch=feat/hybrid-snark-agg#667ace4c4526598cdc95e5322da6ccd62d0787a4" dependencies = [ "array-init", - "bus-mapping 0.13.0", + "bus-mapping 0.13.0 (git+https://github.com/scroll-tech/zkevm-circuits.git?branch=feat/hybrid-snark-agg)", "either", "env_logger 0.10.2", - "eth-types 0.13.0", + "eth-types 0.13.0 (git+https://github.com/scroll-tech/zkevm-circuits.git?branch=feat/hybrid-snark-agg)", "ethers-core 2.0.7 (git+https://github.com/scroll-tech/ethers-rs.git?branch=v2.0.7)", "ethers-signers", "ff", - "gadgets 0.13.0", + "gadgets 0.13.0 (git+https://github.com/scroll-tech/zkevm-circuits.git?branch=feat/hybrid-snark-agg)", "halo2-base", "halo2-ecc", "halo2-mpt-circuits", @@ -5400,8 +5680,8 @@ dependencies = [ "itertools 0.11.0", "log", "misc-precompiled-circuit", - "mock 0.13.0", - "mpt-zktrie 0.13.0", + "mock 0.13.0 (git+https://github.com/scroll-tech/zkevm-circuits.git?branch=feat/hybrid-snark-agg)", + "mpt-zktrie 0.13.0 (git+https://github.com/scroll-tech/zkevm-circuits.git?branch=feat/hybrid-snark-agg)", "num", "num-bigint", "poseidon-circuit", @@ -5412,43 +5692,20 @@ dependencies = [ "serde", "serde_json", "sha3 0.10.8", - "snark-verifier", - "snark-verifier-sdk", + "snark-verifier 0.1.0 (git+https://github.com/scroll-tech/snark-verifier?branch=feat/hybrid-snark-agg)", + "snark-verifier-sdk 0.0.1 (git+https://github.com/scroll-tech/snark-verifier?branch=feat/hybrid-snark-agg)", "strum 0.25.0", "strum_macros 0.25.3", "subtle", ] -[[package]] -name = "zktrie" -version = "0.3.0" -source = "git+https://github.com/scroll-tech/zktrie.git?branch=main#23181f209e94137f74337b150179aeb80c72e7c8" -dependencies = [ - "gobuild", - "zktrie_rust 0.3.0 (git+https://github.com/scroll-tech/zktrie.git?branch=main)", -] - [[package]] name = "zktrie" version = "0.3.0" source = "git+https://github.com/scroll-tech/zktrie.git?branch=v0.9#460b8c22af65b7809164548cba1e0253b6db5a70" dependencies = [ "gobuild", - "zktrie_rust 0.3.0 (git+https://github.com/scroll-tech/zktrie.git?branch=v0.9)", -] - -[[package]] -name = "zktrie_rust" -version = "0.3.0" -source = "git+https://github.com/scroll-tech/zktrie.git?branch=main#23181f209e94137f74337b150179aeb80c72e7c8" -dependencies = [ - "hex", - "lazy_static", - "num", - "num-derive", - "num-traits", - "strum 0.24.1", - "strum_macros 0.24.3", + "zktrie_rust", ] [[package]] diff --git a/prover/Cargo.toml b/prover/Cargo.toml index 36db6a39b2..7987bfb50c 100644 --- a/prover/Cargo.toml +++ b/prover/Cargo.toml @@ -29,8 +29,8 @@ ethers-core = { git = "https://github.com/scroll-tech/ethers-rs.git", branch = " ethers-providers = { git = "https://github.com/scroll-tech/ethers-rs.git", branch = "v2.0.7" } halo2_proofs = { git = "https://github.com/scroll-tech/halo2.git", branch = "v1.1" } snark-verifier-sdk = { git = "https://github.com/scroll-tech/snark-verifier", branch = "develop", default-features = false, features = ["loader_halo2", "loader_evm", "halo2-pse"] } -prover_darwin = { git = "https://github.com/scroll-tech/zkevm-circuits.git", tag = "v0.12.2", package = "prover", default-features = false, features = ["parallel_syn", "scroll"] } prover_darwin_v2 = { git = "https://github.com/scroll-tech/zkevm-circuits.git", tag = "v0.13.1", package = "prover", default-features = false, features = ["parallel_syn", "scroll"] } +prover_euclid = { git = "https://github.com/scroll-tech/zkevm-circuits.git", branch = "feat/hybrid-snark-agg", package = "prover", default-features = false, features = ["parallel_syn", "scroll"] } base64 = "0.13.1" reqwest = { version = "0.12.4", features = ["gzip"] } reqwest-middleware = "0.3" diff --git a/prover/rust-toolchain b/prover/rust-toolchain deleted file mode 100644 index 27c108be5c..0000000000 --- a/prover/rust-toolchain +++ /dev/null @@ -1 +0,0 @@ -nightly-2023-12-03 diff --git a/prover/rust-toolchain.toml b/prover/rust-toolchain.toml new file mode 100644 index 0000000000..584353ad1c --- /dev/null +++ b/prover/rust-toolchain.toml @@ -0,0 +1,2 @@ +[toolchain] +channel = "nightly-2024-01-25" diff --git a/prover/src/main.rs b/prover/src/main.rs index 75553187a9..acb699e167 100644 --- a/prover/src/main.rs +++ b/prover/src/main.rs @@ -1,4 +1,5 @@ #![feature(lazy_cell)] +#![allow(internal_features)] #![feature(core_intrinsics)] mod config; diff --git a/prover/src/prover.rs b/prover/src/prover.rs index 7de83906e0..7dd20d876d 100644 --- a/prover/src/prover.rs +++ b/prover/src/prover.rs @@ -29,7 +29,10 @@ impl<'a> Prover<'a> { let keystore_path = &config.keystore_path; let keystore_password = &config.keystore_password; - let geth_client = if config.prover_type == ProverType::Chunk { + let geth_client = if matches!( + config.prover_type, + ProverType::ChunkHalo2 | ProverType::ChunkSp1 | ProverType::ChunkAll + ) { Some(Rc::new(RefCell::new( GethClient::new( &config.prover_name, @@ -73,7 +76,10 @@ impl<'a> Prover<'a> { prover_height: None, }; - if self.config.prover_type == ProverType::Chunk { + if matches!( + self.config.prover_type, + ProverType::ChunkHalo2 | ProverType::ChunkSp1 | ProverType::ChunkAll + ) { let latest_block_number = self.get_latest_block_number_value()?; if let Some(v) = latest_block_number { if v.as_u64() == 0 { diff --git a/prover/src/types.rs b/prover/src/types.rs index 513995d6d1..d915fbff68 100644 --- a/prover/src/types.rs +++ b/prover/src/types.rs @@ -8,7 +8,8 @@ pub type CommonHash = H256; #[derive(Debug, Clone, Copy, PartialEq)] pub enum TaskType { Undefined, - Chunk, + ChunkHalo2, + ChunkSp1, Batch, Bundle, } @@ -16,9 +17,10 @@ pub enum TaskType { impl TaskType { fn from_u8(v: u8) -> Self { match v { - 1 => TaskType::Chunk, + 1 => TaskType::ChunkHalo2, 2 => TaskType::Batch, 3 => TaskType::Bundle, + 4 => TaskType::ChunkSp1, _ => TaskType::Undefined, } } @@ -31,9 +33,10 @@ impl Serialize for TaskType { { match *self { TaskType::Undefined => serializer.serialize_u8(0), - TaskType::Chunk => serializer.serialize_u8(1), + TaskType::ChunkHalo2 => serializer.serialize_u8(1), TaskType::Batch => serializer.serialize_u8(2), TaskType::Bundle => serializer.serialize_u8(3), + TaskType::ChunkSp1 => serializer.serialize_u8(4), } } } @@ -56,15 +59,19 @@ impl Default for TaskType { #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] pub enum ProverType { - Chunk, + ChunkHalo2, + ChunkSp1, + ChunkAll, Batch, } impl ProverType { fn from_u8(v: u8) -> Self { match v { - 1 => ProverType::Chunk, + 1 => ProverType::ChunkHalo2, 2 => ProverType::Batch, + 3 => ProverType::ChunkSp1, + 4 => ProverType::ChunkAll, _ => { panic!("invalid prover_type") } @@ -73,8 +80,10 @@ impl ProverType { pub fn to_u8(self) -> u8 { match self { - ProverType::Chunk => 1, + ProverType::ChunkHalo2 => 1, ProverType::Batch => 2, + ProverType::ChunkSp1 => 3, + ProverType::ChunkAll => 4, } } } @@ -85,8 +94,10 @@ impl Serialize for ProverType { S: Serializer, { match *self { - ProverType::Chunk => serializer.serialize_u8(1), + ProverType::ChunkHalo2 => serializer.serialize_u8(1), ProverType::Batch => serializer.serialize_u8(2), + ProverType::ChunkSp1 => serializer.serialize_u8(3), + ProverType::ChunkAll => serializer.serialize_u8(4), } } } diff --git a/prover/src/utils.rs b/prover/src/utils.rs index 18be4ac7a1..57d8511663 100644 --- a/prover/src/utils.rs +++ b/prover/src/utils.rs @@ -26,7 +26,9 @@ pub fn log_init(log_file: Option) { pub fn get_task_types(prover_type: ProverType) -> Vec { match prover_type { - ProverType::Chunk => vec![TaskType::Chunk], + ProverType::ChunkHalo2 => vec![TaskType::ChunkHalo2], + ProverType::ChunkSp1 => vec![TaskType::ChunkSp1], + ProverType::ChunkAll => vec![TaskType::ChunkHalo2, TaskType::ChunkSp1], ProverType::Batch => vec![TaskType::Batch, TaskType::Bundle], } } diff --git a/prover/src/zk_circuits_handler.rs b/prover/src/zk_circuits_handler.rs index d1a8eb38c5..bd225ee320 100644 --- a/prover/src/zk_circuits_handler.rs +++ b/prover/src/zk_circuits_handler.rs @@ -1,6 +1,6 @@ mod common; -mod darwin; mod darwin_v2; +mod euclid; use super::geth_client::GethClient; use crate::{ @@ -9,8 +9,8 @@ use crate::{ utils::get_task_types, }; use anyhow::{bail, Result}; -use darwin::DarwinHandler; use darwin_v2::DarwinV2Handler; +use euclid::EuclidHandler; use std::{cell::RefCell, collections::HashMap, rc::Rc}; type HardForkName = String; @@ -61,7 +61,7 @@ impl<'a> CircuitsHandlerProvider<'a> { &config.low_version_circuit.hard_fork_name ); AssetsDirEnvConfig::enable_first(); - DarwinHandler::new( + DarwinV2Handler::new( prover_type, &config.low_version_circuit.params_path, &config.low_version_circuit.assets_path, @@ -84,7 +84,7 @@ impl<'a> CircuitsHandlerProvider<'a> { &config.high_version_circuit.hard_fork_name ); AssetsDirEnvConfig::enable_second(); - DarwinV2Handler::new( + EuclidHandler::new( prover_type, &config.high_version_circuit.params_path, &config.high_version_circuit.assets_path, diff --git a/prover/src/zk_circuits_handler/darwin.rs b/prover/src/zk_circuits_handler/darwin.rs deleted file mode 100644 index 96618f9508..0000000000 --- a/prover/src/zk_circuits_handler/darwin.rs +++ /dev/null @@ -1,467 +0,0 @@ -use super::{common::*, CircuitsHandler}; -use crate::{ - geth_client::GethClient, - types::{ProverType, TaskType}, -}; -use anyhow::{bail, Context, Ok, Result}; -use once_cell::sync::Lazy; -use serde::Deserialize; - -use crate::types::{CommonHash, Task}; -use std::{cell::RefCell, cmp::Ordering, env, rc::Rc}; - -use prover_darwin::{ - aggregator::Prover as BatchProver, - check_chunk_hashes, - common::Prover as CommonProver, - config::{AGG_DEGREES, ZKEVM_DEGREES}, - zkevm::Prover as ChunkProver, - BatchProof, BatchProvingTask, BlockTrace, BundleProof, BundleProvingTask, ChunkInfo, - ChunkProof, ChunkProvingTask, -}; - -// Only used for debugging. -static OUTPUT_DIR: Lazy> = Lazy::new(|| env::var("PROVER_OUTPUT_DIR").ok()); - -#[derive(Debug, Clone, Deserialize)] -pub struct BatchTaskDetail { - pub chunk_infos: Vec, - #[serde(flatten)] - pub batch_proving_task: BatchProvingTask, -} - -type BundleTaskDetail = BundleProvingTask; - -#[derive(Debug, Clone, Deserialize)] -pub struct ChunkTaskDetail { - pub block_hashes: Vec, -} - -fn get_block_number(block_trace: &BlockTrace) -> Option { - block_trace.header.number.map(|n| n.as_u64()) -} - -#[derive(Default)] -pub struct DarwinHandler { - chunk_prover: Option>>, - batch_prover: Option>>, - - geth_client: Option>>, -} - -impl DarwinHandler { - pub fn new_multi( - prover_types: Vec, - params_dir: &str, - assets_dir: &str, - geth_client: Option>>, - ) -> Result { - let class_name = std::intrinsics::type_name::(); - let prover_types_set = prover_types - .into_iter() - .collect::>(); - let mut handler = Self { - batch_prover: None, - chunk_prover: None, - geth_client, - }; - let degrees: Vec = get_degrees(&prover_types_set, |prover_type| match prover_type { - ProverType::Chunk => ZKEVM_DEGREES.clone(), - ProverType::Batch => AGG_DEGREES.clone(), - }); - let params_map = get_params_map_instance(|| { - log::info!( - "calling get_params_map from {}, prover_types: {:?}, degrees: {:?}", - class_name, - prover_types_set, - degrees - ); - CommonProver::load_params_map(params_dir, °rees) - }); - for prover_type in prover_types_set { - match prover_type { - ProverType::Chunk => { - handler.chunk_prover = Some(RefCell::new(ChunkProver::from_params_and_assets( - params_map, assets_dir, - ))); - } - ProverType::Batch => { - handler.batch_prover = Some(RefCell::new(BatchProver::from_params_and_assets( - params_map, assets_dir, - ))) - } - } - } - Ok(handler) - } - - pub fn new( - prover_type: ProverType, - params_dir: &str, - assets_dir: &str, - geth_client: Option>>, - ) -> Result { - Self::new_multi(vec![prover_type], params_dir, assets_dir, geth_client) - } - - fn gen_chunk_proof_raw(&self, chunk_trace: Vec) -> Result { - if let Some(prover) = self.chunk_prover.as_ref() { - let chunk = ChunkProvingTask::from(chunk_trace); - - let chunk_proof = - prover - .borrow_mut() - .gen_chunk_proof(chunk, None, None, self.get_output_dir())?; - - return Ok(chunk_proof); - } - unreachable!("please check errors in proof_type logic") - } - - fn gen_chunk_proof(&self, task: &crate::types::Task) -> Result { - let chunk_trace = self.gen_chunk_traces(task)?; - let chunk_proof = self.gen_chunk_proof_raw(chunk_trace)?; - Ok(serde_json::to_string(&chunk_proof)?) - } - - fn gen_batch_proof_raw(&self, batch_task_detail: BatchTaskDetail) -> Result { - if let Some(prover) = self.batch_prover.as_ref() { - let chunk_hashes_proofs: Vec<(ChunkInfo, ChunkProof)> = batch_task_detail - .chunk_infos - .clone() - .into_iter() - .zip(batch_task_detail.batch_proving_task.chunk_proofs.clone()) - .collect(); - - let chunk_proofs: Vec = - chunk_hashes_proofs.iter().map(|t| t.1.clone()).collect(); - - let is_valid = prover.borrow_mut().check_protocol_of_chunks(&chunk_proofs); - - if !is_valid { - bail!("non-match chunk protocol") - } - check_chunk_hashes("", &chunk_hashes_proofs).context("failed to check chunk info")?; - let batch_proof = prover.borrow_mut().gen_batch_proof( - batch_task_detail.batch_proving_task, - None, - self.get_output_dir(), - )?; - - return Ok(batch_proof); - } - unreachable!("please check errors in proof_type logic") - } - - fn gen_batch_proof(&self, task: &crate::types::Task) -> Result { - log::info!("[circuit] gen_batch_proof for task {}", task.id); - - let batch_task_detail: BatchTaskDetail = serde_json::from_str(&task.task_data)?; - let batch_proof = self.gen_batch_proof_raw(batch_task_detail)?; - Ok(serde_json::to_string(&batch_proof)?) - } - - fn gen_bundle_proof_raw(&self, bundle_task_detail: BundleTaskDetail) -> Result { - if let Some(prover) = self.batch_prover.as_ref() { - let bundle_proof = prover.borrow_mut().gen_bundle_proof( - bundle_task_detail, - None, - self.get_output_dir(), - )?; - - return Ok(bundle_proof); - } - unreachable!("please check errors in proof_type logic") - } - - fn gen_bundle_proof(&self, task: &crate::types::Task) -> Result { - log::info!("[circuit] gen_bundle_proof for task {}", task.id); - let bundle_task_detail: BundleTaskDetail = serde_json::from_str(&task.task_data)?; - let bundle_proof = self.gen_bundle_proof_raw(bundle_task_detail)?; - Ok(serde_json::to_string(&bundle_proof)?) - } - - fn get_output_dir(&self) -> Option<&str> { - OUTPUT_DIR.as_deref() - } - - fn gen_chunk_traces(&self, task: &Task) -> Result> { - let chunk_task_detail: ChunkTaskDetail = serde_json::from_str(&task.task_data)?; - self.get_sorted_traces_by_hashes(&chunk_task_detail.block_hashes) - } - - fn get_sorted_traces_by_hashes(&self, block_hashes: &[CommonHash]) -> Result> { - if block_hashes.is_empty() { - log::error!("[prover] failed to get sorted traces: block_hashes are empty"); - bail!("block_hashes are empty") - } - - let mut block_traces = Vec::new(); - for hash in block_hashes.iter() { - let trace = self - .geth_client - .as_ref() - .unwrap() - .borrow_mut() - .get_block_trace_by_hash(hash)?; - block_traces.push(trace); - } - - block_traces.sort_by(|a, b| { - if get_block_number(a).is_none() { - Ordering::Less - } else if get_block_number(b).is_none() { - Ordering::Greater - } else { - get_block_number(a) - .unwrap() - .cmp(&get_block_number(b).unwrap()) - } - }); - - let block_numbers: Vec = block_traces - .iter() - .map(|trace| get_block_number(trace).unwrap_or(0)) - .collect(); - let mut i = 0; - while i < block_numbers.len() - 1 { - if block_numbers[i] + 1 != block_numbers[i + 1] { - log::error!( - "[prover] block numbers are not continuous, got {} and {}", - block_numbers[i], - block_numbers[i + 1] - ); - bail!( - "block numbers are not continuous, got {} and {}", - block_numbers[i], - block_numbers[i + 1] - ) - } - i += 1; - } - - Ok(block_traces) - } -} - -impl CircuitsHandler for DarwinHandler { - fn get_vk(&self, task_type: TaskType) -> Option> { - match task_type { - TaskType::Chunk => self - .chunk_prover - .as_ref() - .and_then(|prover| prover.borrow().get_vk()), - TaskType::Batch => self - .batch_prover - .as_ref() - .and_then(|prover| prover.borrow().get_batch_vk()), - TaskType::Bundle => self - .batch_prover - .as_ref() - .and_then(|prover| prover.borrow().get_bundle_vk()), - _ => unreachable!(), - } - } - - fn get_proof_data(&self, task_type: TaskType, task: &crate::types::Task) -> Result { - match task_type { - TaskType::Chunk => self.gen_chunk_proof(task), - TaskType::Batch => self.gen_batch_proof(task), - TaskType::Bundle => self.gen_bundle_proof(task), - _ => unreachable!(), - } - } -} - -// =================================== tests module ======================================== - -#[cfg(test)] -mod tests { - use super::*; - use crate::zk_circuits_handler::utils::encode_vk; - use prover_darwin::utils::chunk_trace_to_witness_block; - use std::{path::PathBuf, sync::LazyLock}; - - #[ctor::ctor] - fn init() { - crate::utils::log_init(None); - log::info!("logger initialized"); - } - - static DEFAULT_WORK_DIR: &str = "/assets"; - static WORK_DIR: LazyLock = LazyLock::new(|| { - std::env::var("DARWIN_TEST_DIR") - .unwrap_or(String::from(DEFAULT_WORK_DIR)) - .trim_end_matches('/') - .to_string() - }); - static PARAMS_PATH: LazyLock = LazyLock::new(|| format!("{}/test_params", *WORK_DIR)); - static ASSETS_PATH: LazyLock = LazyLock::new(|| format!("{}/test_assets", *WORK_DIR)); - static PROOF_DUMP_PATH: LazyLock = - LazyLock::new(|| format!("{}/proof_data", *WORK_DIR)); - static BATCH_DIR_PATH: LazyLock = - LazyLock::new(|| format!("{}/traces/batch_24", *WORK_DIR)); - static BATCH_VK_PATH: LazyLock = - LazyLock::new(|| format!("{}/test_assets/vk_batch.vkey", *WORK_DIR)); - static CHUNK_VK_PATH: LazyLock = - LazyLock::new(|| format!("{}/test_assets/vk_chunk.vkey", *WORK_DIR)); - - #[test] - fn it_works() { - let result = true; - assert!(result); - } - - #[test] - fn test_circuits() -> Result<()> { - let bi_handler = DarwinHandler::new_multi( - vec![ProverType::Chunk, ProverType::Batch], - &PARAMS_PATH, - &ASSETS_PATH, - None, - )?; - - let chunk_handler = bi_handler; - let chunk_vk = chunk_handler.get_vk(TaskType::Chunk).unwrap(); - - check_vk(TaskType::Chunk, chunk_vk, "chunk vk must be available"); - let chunk_dir_paths = get_chunk_dir_paths()?; - log::info!("chunk_dir_paths, {:?}", chunk_dir_paths); - let mut chunk_infos = vec![]; - let mut chunk_proofs = vec![]; - for (id, chunk_path) in chunk_dir_paths.into_iter().enumerate() { - let chunk_id = format!("chunk_proof{}", id + 1); - log::info!("start to process {chunk_id}"); - let chunk_trace = read_chunk_trace(chunk_path)?; - - let chunk_info = traces_to_chunk_info(chunk_trace.clone())?; - chunk_infos.push(chunk_info); - - log::info!("start to prove {chunk_id}"); - let chunk_proof = chunk_handler.gen_chunk_proof_raw(chunk_trace)?; - let proof_data = serde_json::to_string(&chunk_proof)?; - dump_proof(chunk_id, proof_data)?; - chunk_proofs.push(chunk_proof); - } - - let batch_handler = chunk_handler; - let batch_vk = batch_handler.get_vk(TaskType::Batch).unwrap(); - check_vk(TaskType::Batch, batch_vk, "batch vk must be available"); - let batch_task_detail = make_batch_task_detail(chunk_infos, chunk_proofs); - log::info!("start to prove batch"); - let batch_proof = batch_handler.gen_batch_proof_raw(batch_task_detail)?; - let proof_data = serde_json::to_string(&batch_proof)?; - dump_proof("batch_proof".to_string(), proof_data)?; - - Ok(()) - } - - fn make_batch_task_detail(_: Vec, _: Vec) -> BatchTaskDetail { - todo!(); - // BatchTaskDetail { - // chunk_infos, - // batch_proving_task: BatchProvingTask { - // parent_batch_hash: todo!(), - // parent_state_root: todo!(), - // batch_header: todo!(), - // chunk_proofs, - // }, - // } - } - - fn check_vk(proof_type: TaskType, vk: Vec, info: &str) { - log::info!("check_vk, {:?}", proof_type); - let vk_from_file = read_vk(proof_type).unwrap(); - assert_eq!(vk_from_file, encode_vk(vk), "{info}") - } - - fn read_vk(proof_type: TaskType) -> Result { - log::info!("read_vk, {:?}", proof_type); - let vk_file = match proof_type { - TaskType::Chunk => CHUNK_VK_PATH.clone(), - TaskType::Batch => BATCH_VK_PATH.clone(), - TaskType::Bundle => todo!(), - TaskType::Undefined => unreachable!(), - }; - - let data = std::fs::read(vk_file)?; - Ok(encode_vk(data)) - } - - fn read_chunk_trace(path: PathBuf) -> Result> { - log::info!("read_chunk_trace, {:?}", path); - let mut chunk_trace: Vec = vec![]; - - fn read_block_trace(file: &PathBuf) -> Result { - let f = std::fs::File::open(file)?; - Ok(serde_json::from_reader(&f)?) - } - - if path.is_dir() { - let entries = std::fs::read_dir(&path)?; - let mut files: Vec = entries - .into_iter() - .filter_map(|e| { - if e.is_err() { - return None; - } - let entry = e.unwrap(); - if entry.path().is_dir() { - return None; - } - if let Result::Ok(file_name) = entry.file_name().into_string() { - Some(file_name) - } else { - None - } - }) - .collect(); - files.sort(); - - log::info!("files in chunk {:?} is {:?}", path, files); - for file in files { - let block_trace = read_block_trace(&path.join(file))?; - chunk_trace.push(block_trace); - } - } else { - let block_trace = read_block_trace(&path)?; - chunk_trace.push(block_trace); - } - Ok(chunk_trace) - } - - fn get_chunk_dir_paths() -> Result> { - let batch_path = PathBuf::from(BATCH_DIR_PATH.clone()); - let entries = std::fs::read_dir(&batch_path)?; - let mut files: Vec = entries - .filter_map(|e| { - if e.is_err() { - return None; - } - let entry = e.unwrap(); - if entry.path().is_dir() { - if let Result::Ok(file_name) = entry.file_name().into_string() { - Some(file_name) - } else { - None - } - } else { - None - } - }) - .collect(); - files.sort(); - log::info!("files in batch {:?} is {:?}", batch_path, files); - Ok(files.into_iter().map(|f| batch_path.join(f)).collect()) - } - - fn traces_to_chunk_info(chunk_trace: Vec) -> Result { - let witness_block = chunk_trace_to_witness_block(chunk_trace)?; - Ok(ChunkInfo::from_witness_block(&witness_block, false)) - } - - fn dump_proof(id: String, proof_data: String) -> Result<()> { - let dump_path = PathBuf::from(PROOF_DUMP_PATH.clone()); - Ok(std::fs::write(dump_path.join(id), proof_data)?) - } -} diff --git a/prover/src/zk_circuits_handler/darwin_v2.rs b/prover/src/zk_circuits_handler/darwin_v2.rs index fce3871d03..83a74a0c34 100644 --- a/prover/src/zk_circuits_handler/darwin_v2.rs +++ b/prover/src/zk_circuits_handler/darwin_v2.rs @@ -24,7 +24,7 @@ use prover_darwin_v2::{ static OUTPUT_DIR: Lazy> = Lazy::new(|| env::var("PROVER_OUTPUT_DIR").ok()); #[derive(Debug, Clone, Deserialize)] -pub struct BatchTaskDetail { +struct BatchTaskDetail { pub chunk_infos: Vec, #[serde(flatten)] pub batch_proving_task: BatchProvingTask, @@ -66,8 +66,9 @@ impl DarwinV2Handler { geth_client, }; let degrees: Vec = get_degrees(&prover_types_set, |prover_type| match prover_type { - ProverType::Chunk => ZKEVM_DEGREES.clone(), + ProverType::ChunkHalo2 => ZKEVM_DEGREES.clone(), ProverType::Batch => AGG_DEGREES.clone(), + _ => unreachable!("Darwin supports prover types in [ChunkHalo2 and Batch] only"), }); let params_map = get_params_map_instance(|| { log::info!( @@ -80,7 +81,7 @@ impl DarwinV2Handler { }); for prover_type in prover_types_set { match prover_type { - ProverType::Chunk => { + ProverType::ChunkHalo2 => { handler.chunk_prover = Some(RefCell::new(ChunkProver::from_params_and_assets( params_map, assets_dir, ))); @@ -90,6 +91,7 @@ impl DarwinV2Handler { params_map, assets_dir, ))) } + _ => unreachable!("Darwin supports prover types in [ChunkHalo2 and Batch] only"), } } Ok(handler) @@ -247,7 +249,7 @@ impl DarwinV2Handler { impl CircuitsHandler for DarwinV2Handler { fn get_vk(&self, task_type: TaskType) -> Option> { match task_type { - TaskType::Chunk => self + TaskType::ChunkHalo2 => self .chunk_prover .as_ref() .and_then(|prover| prover.borrow().get_vk()), @@ -265,7 +267,7 @@ impl CircuitsHandler for DarwinV2Handler { fn get_proof_data(&self, task_type: TaskType, task: &crate::types::Task) -> Result { match task_type { - TaskType::Chunk => self.gen_chunk_proof(task), + TaskType::ChunkHalo2 => self.gen_chunk_proof(task), TaskType::Batch => self.gen_batch_proof(task), TaskType::Bundle => self.gen_bundle_proof(task), _ => unreachable!(), @@ -319,16 +321,16 @@ mod tests { #[test] fn test_circuits() -> Result<()> { let bi_handler = DarwinV2Handler::new_multi( - vec![ProverType::Chunk, ProverType::Batch], + vec![ProverType::ChunkHalo2, ProverType::Batch], &PARAMS_PATH, &ASSETS_PATH, None, )?; let chunk_handler = bi_handler; - let chunk_vk = chunk_handler.get_vk(TaskType::Chunk).unwrap(); + let chunk_vk = chunk_handler.get_vk(TaskType::ChunkHalo2).unwrap(); - check_vk(TaskType::Chunk, chunk_vk, "chunk vk must be available"); + check_vk(TaskType::ChunkHalo2, chunk_vk, "chunk vk must be available"); let chunk_dir_paths = get_chunk_dir_paths()?; log::info!("chunk_dir_paths, {:?}", chunk_dir_paths); let mut chunk_traces = vec![]; @@ -436,9 +438,10 @@ mod tests { fn read_vk(proof_type: TaskType) -> Result { log::info!("read_vk, {:?}", proof_type); let vk_file = match proof_type { - TaskType::Chunk => CHUNK_VK_PATH.clone(), + TaskType::ChunkHalo2 => CHUNK_VK_PATH.clone(), TaskType::Batch => BATCH_VK_PATH.clone(), TaskType::Bundle => todo!(), + TaskType::ChunkSp1 => todo!(), TaskType::Undefined => unreachable!(), }; diff --git a/prover/src/zk_circuits_handler/euclid.rs b/prover/src/zk_circuits_handler/euclid.rs new file mode 100644 index 0000000000..a79b31bb4e --- /dev/null +++ b/prover/src/zk_circuits_handler/euclid.rs @@ -0,0 +1,311 @@ +use std::{cell::RefCell, cmp::Ordering, env, rc::Rc}; + +use anyhow::{bail, Context, Result}; +use once_cell::sync::Lazy; +use prover_euclid::{ + aggregator::Prover as BatchProver, + check_chunk_hashes, + common::Prover as CommonProver, + config::{AGG_DEGREES, ZKEVM_DEGREES}, + zkevm::Prover as Halo2Prover, + BatchProof, BatchProvingTask, BlockTrace, BundleProof, BundleProvingTask, ChunkInfo, + ChunkProof, ChunkProvingTask, +}; +use serde::Deserialize; + +use crate::{ + geth_client::GethClient, + types::{CommonHash, ProverType, Task, TaskType}, +}; + +use super::{common::*, darwin_v2::ChunkTaskDetail, CircuitsHandler}; +// TODO: enable_post_sp1_prover +// use sp1_prover::Sp1Prover; + +// Only used for debugging. +static OUTPUT_DIR: Lazy> = Lazy::new(|| env::var("PROVER_OUTPUT_DIR").ok()); + +#[derive(Debug, Clone, Deserialize)] +struct BatchTaskDetail { + pub chunk_infos: Vec, + #[serde(flatten)] + pub batch_proving_task: BatchProvingTask, +} + +type BundleTaskDetail = BundleProvingTask; + +struct ChunkProver { + halo2_prover: Option>>, + // TODO: enable_post_sp1_prover + // sp1_prover: Option>, +} + +fn get_block_number(block_trace: &BlockTrace) -> Option { + block_trace.header.number.map(|n| n.as_u64()) +} + +#[derive(Default)] +pub struct EuclidHandler { + chunk_prover: Option, + batch_prover: Option>>, + + geth_client: Option>>, +} + +impl EuclidHandler { + pub fn new_multi( + prover_types: Vec, + params_dir: &str, + assets_dir: &str, + geth_client: Option>>, + ) -> Result { + let class_name = std::intrinsics::type_name::(); + let prover_types_set = prover_types + .into_iter() + .collect::>(); + let mut handler = Self { + batch_prover: None, + chunk_prover: None, + geth_client, + }; + let degrees: Vec = get_degrees(&prover_types_set, |prover_type| match prover_type { + ProverType::ChunkHalo2 | ProverType::ChunkAll => ZKEVM_DEGREES.clone(), + ProverType::ChunkSp1 => ZKEVM_DEGREES.clone(), // TODO(rohit) + ProverType::Batch => AGG_DEGREES.clone(), + }); + let params_map = get_params_map_instance(|| { + log::info!( + "calling get_params_map from {}, prover_types: {:?}, degrees: {:?}", + class_name, + prover_types_set, + degrees + ); + CommonProver::load_params_map(params_dir, °rees) + }); + for prover_type in prover_types_set { + match prover_type { + ProverType::ChunkHalo2 => { + handler.chunk_prover = Some(ChunkProver { + halo2_prover: Some(RefCell::new(Halo2Prover::from_params_and_assets( + params_map, assets_dir, + ))), + // TODO: enable_post_sp1_prover + // sp1_prover: None, + }); + } + ProverType::ChunkSp1 => { + handler.chunk_prover = Some(ChunkProver { + halo2_prover: None, + // TODO: enable_post_sp1_prover + // sp1_prover: Some(RefCell::new(Sp1Prover::new())), + }); + } + ProverType::ChunkAll => { + handler.chunk_prover = Some(ChunkProver { + halo2_prover: Some(RefCell::new(Halo2Prover::from_params_and_assets( + params_map, assets_dir, + ))), + // TODO: enable_post_sp1_prover + // sp1_prover: Some(RefCell::new(Sp1Prover::new())), + }); + } + ProverType::Batch => { + handler.batch_prover = Some(RefCell::new(BatchProver::from_params_and_assets( + params_map, assets_dir, + ))) + } + } + } + Ok(handler) + } + + pub fn new( + prover_type: ProverType, + params_dir: &str, + assets_dir: &str, + geth_client: Option>>, + ) -> Result { + Self::new_multi(vec![prover_type], params_dir, assets_dir, geth_client) + } + + fn gen_halo2_chunk_proof_raw(&self, chunk_trace: Vec) -> Result { + if let Some(prover) = self.chunk_prover.as_ref() { + if let Some(halo2_prover) = prover.halo2_prover.as_ref() { + let chunk = ChunkProvingTask::new(chunk_trace); + + let chunk_proof = halo2_prover.borrow_mut().gen_halo2_chunk_proof( + chunk, + None, + None, + self.get_output_dir(), + )?; + + return Ok(chunk_proof); + } + } + unreachable!("please check errors in proof_type logic") + } + + fn gen_halo2_chunk_proof(&self, task: &crate::types::Task) -> Result { + let chunk_trace = self.gen_chunk_traces(task)?; + let chunk_proof = self.gen_halo2_chunk_proof_raw(chunk_trace)?; + Ok(serde_json::to_string(&chunk_proof)?) + } + + fn gen_sp1_chunk_proof(&self, task: &crate::types::Task) -> Result { + let _ = self.gen_chunk_traces(task)?; + todo!() + } + + fn gen_batch_proof_raw(&self, batch_task_detail: BatchTaskDetail) -> Result { + if let Some(prover) = self.batch_prover.as_ref() { + let chunk_hashes_proofs: Vec<(ChunkInfo, ChunkProof)> = batch_task_detail + .chunk_infos + .clone() + .into_iter() + .zip(batch_task_detail.batch_proving_task.chunk_proofs.clone()) + .collect(); + + let chunk_proofs: Vec = + chunk_hashes_proofs.iter().map(|t| t.1.clone()).collect(); + + let is_valid = prover.borrow_mut().check_protocol_of_chunks(&chunk_proofs); + + if !is_valid { + bail!("non-match chunk protocol") + } + check_chunk_hashes("", &chunk_hashes_proofs).context("failed to check chunk info")?; + let batch_proof = prover.borrow_mut().gen_batch_proof( + batch_task_detail.batch_proving_task, + None, + self.get_output_dir(), + )?; + + return Ok(batch_proof); + } + unreachable!("please check errors in proof_type logic") + } + + fn gen_batch_proof(&self, task: &crate::types::Task) -> Result { + log::info!("[circuit] gen_batch_proof for task {}", task.id); + + let batch_task_detail: BatchTaskDetail = serde_json::from_str(&task.task_data)?; + let batch_proof = self.gen_batch_proof_raw(batch_task_detail)?; + Ok(serde_json::to_string(&batch_proof)?) + } + + fn gen_bundle_proof_raw(&self, bundle_task_detail: BundleTaskDetail) -> Result { + if let Some(prover) = self.batch_prover.as_ref() { + let bundle_proof = prover.borrow_mut().gen_bundle_proof( + bundle_task_detail, + None, + self.get_output_dir(), + )?; + + return Ok(bundle_proof); + } + unreachable!("please check errors in proof_type logic") + } + + fn gen_bundle_proof(&self, task: &crate::types::Task) -> Result { + log::info!("[circuit] gen_bundle_proof for task {}", task.id); + let bundle_task_detail: BundleTaskDetail = serde_json::from_str(&task.task_data)?; + let bundle_proof = self.gen_bundle_proof_raw(bundle_task_detail)?; + Ok(serde_json::to_string(&bundle_proof)?) + } + + fn get_output_dir(&self) -> Option<&str> { + OUTPUT_DIR.as_deref() + } + + fn gen_chunk_traces(&self, task: &Task) -> Result> { + let chunk_task_detail: ChunkTaskDetail = serde_json::from_str(&task.task_data)?; + self.get_sorted_traces_by_hashes(&chunk_task_detail.block_hashes) + } + + fn get_sorted_traces_by_hashes(&self, block_hashes: &[CommonHash]) -> Result> { + if block_hashes.is_empty() { + log::error!("[prover] failed to get sorted traces: block_hashes are empty"); + bail!("block_hashes are empty") + } + + let mut block_traces = Vec::new(); + for hash in block_hashes.iter() { + let trace = self + .geth_client + .as_ref() + .unwrap() + .borrow_mut() + .get_block_trace_by_hash(hash)?; + block_traces.push(trace); + } + + block_traces.sort_by(|a, b| { + if get_block_number(a).is_none() { + Ordering::Less + } else if get_block_number(b).is_none() { + Ordering::Greater + } else { + get_block_number(a) + .unwrap() + .cmp(&get_block_number(b).unwrap()) + } + }); + + let block_numbers: Vec = block_traces + .iter() + .map(|trace| get_block_number(trace).unwrap_or(0)) + .collect(); + let mut i = 0; + while i < block_numbers.len() - 1 { + if block_numbers[i] + 1 != block_numbers[i + 1] { + log::error!( + "[prover] block numbers are not continuous, got {} and {}", + block_numbers[i], + block_numbers[i + 1] + ); + bail!( + "block numbers are not continuous, got {} and {}", + block_numbers[i], + block_numbers[i + 1] + ) + } + i += 1; + } + + Ok(block_traces) + } +} + +impl CircuitsHandler for EuclidHandler { + fn get_vk(&self, task_type: TaskType) -> Option> { + match task_type { + TaskType::ChunkHalo2 => self.chunk_prover.as_ref().and_then(|prover| { + prover + .halo2_prover + .as_ref() + .and_then(|p| p.borrow().get_vk()) + }), + TaskType::ChunkSp1 => unimplemented!(), + TaskType::Batch => self + .batch_prover + .as_ref() + .and_then(|prover| prover.borrow().get_batch_vk()), + TaskType::Bundle => self + .batch_prover + .as_ref() + .and_then(|prover| prover.borrow().get_bundle_vk()), + _ => unreachable!(), + } + } + + fn get_proof_data(&self, task_type: TaskType, task: &crate::types::Task) -> Result { + match task_type { + TaskType::ChunkHalo2 => self.gen_halo2_chunk_proof(task), + TaskType::ChunkSp1 => self.gen_sp1_chunk_proof(task), + TaskType::Batch => self.gen_batch_proof(task), + TaskType::Bundle => self.gen_bundle_proof(task), + _ => unreachable!(), + } + } +}