From abe66c6f7ecd4d7d4991ea3125cc24d7459a4809 Mon Sep 17 00:00:00 2001 From: Mengran Lan Date: Mon, 8 Jul 2024 19:32:34 +0800 Subject: [PATCH] feat(prover): supporting upgrade4 (#1412) Co-authored-by: colin <102356659+colinlyguo@users.noreply.github.com> --- prover/Cargo.lock | 520 +++++------------- prover/Cargo.toml | 4 +- prover/Makefile | 4 - prover/src/config.rs | 7 +- prover/src/coordinator_client.rs | 8 +- prover/src/coordinator_client/types.rs | 43 +- prover/src/main.rs | 2 +- prover/src/prover.rs | 33 +- prover/src/types.rs | 78 ++- prover/src/utils.rs | 9 + prover/src/zk_circuits_handler.rs | 74 +-- prover/src/zk_circuits_handler/curie.rs | 75 +-- .../{bernoulli.rs => darwin.rs} | 185 ++++--- 13 files changed, 468 insertions(+), 574 deletions(-) rename prover/src/zk_circuits_handler/{bernoulli.rs => darwin.rs} (68%) diff --git a/prover/Cargo.lock b/prover/Cargo.lock index 9789a1240a..23da0fdd13 100644 --- a/prover/Cargo.lock +++ b/prover/Cargo.lock @@ -30,14 +30,18 @@ dependencies = [ [[package]] name = "aggregator" -version = "0.1.0" -source = "git+https://github.com/scroll-tech/zkevm-circuits.git?branch=v0.10#cfa71a8abe45c21582a6b7ebb85b5b1c4cff01eb" +version = "0.11.0" +source = "git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.11.4#38a68e22d3d8449bd39a50c22da55b9e741de453" dependencies = [ "ark-std 0.3.0", + "bitstream-io", "c-kzg", + "ctor 0.1.26", + "encoder", "env_logger 0.10.2", - "eth-types 0.1.0", + "eth-types 0.11.0 (git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.11.4)", "ethers-core 2.0.7 (git+https://github.com/scroll-tech/ethers-rs.git?branch=v2.0.7)", + "gadgets 0.11.0 (git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.11.4)", "halo2-base", "halo2-ecc", "halo2_proofs", @@ -47,19 +51,21 @@ dependencies = [ "num-bigint", "once_cell", "rand", - "revm-precompile 2.0.0", - "revm-primitives 3.1.1", + "revm-precompile", + "revm-primitives", "serde", "serde_json", "snark-verifier", "snark-verifier-sdk", - "zkevm-circuits 0.1.0", + "strum 0.25.0", + "strum_macros 0.25.3", + "zkevm-circuits 0.11.0 (git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.11.4)", ] [[package]] name = "aggregator" version = "0.11.0" -source = "git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.11.4#38a68e22d3d8449bd39a50c22da55b9e741de453" +source = "git+https://github.com/scroll-tech/zkevm-circuits.git?branch=feat/agg_recursion#a5337832455b1ed49bc1104a6ed4265dcdc27cdb" dependencies = [ "ark-std 0.3.0", "bitstream-io", @@ -67,9 +73,9 @@ dependencies = [ "ctor 0.1.26", "encoder", "env_logger 0.10.2", - "eth-types 0.11.0", + "eth-types 0.11.0 (git+https://github.com/scroll-tech/zkevm-circuits.git?branch=feat/agg_recursion)", "ethers-core 2.0.7 (git+https://github.com/scroll-tech/ethers-rs.git?branch=v2.0.7)", - "gadgets 0.11.0", + "gadgets 0.11.0 (git+https://github.com/scroll-tech/zkevm-circuits.git?branch=feat/agg_recursion)", "halo2-base", "halo2-ecc", "halo2_proofs", @@ -79,15 +85,15 @@ dependencies = [ "num-bigint", "once_cell", "rand", - "revm-precompile 7.0.0", - "revm-primitives 4.0.0", + "revm-precompile", + "revm-primitives", "serde", "serde_json", "snark-verifier", "snark-verifier-sdk", "strum 0.25.0", "strum_macros 0.25.3", - "zkevm-circuits 0.11.0", + "zkevm-circuits 0.11.0 (git+https://github.com/scroll-tech/zkevm-circuits.git?branch=feat/agg_recursion)", ] [[package]] @@ -128,9 +134,9 @@ dependencies = [ "cfg-if 1.0.0", "const-hex", "derive_more", - "hex-literal 0.4.1", + "hex-literal", "itoa", - "k256 0.13.3", + "k256", "keccak-asm", "proptest", "rand", @@ -450,12 +456,6 @@ dependencies = [ "rustc-demangle", ] -[[package]] -name = "base16ct" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "349a06037c7bf932dd7e7d1f653678b2038b9ad46a74102f1fc7bd7872678cce" - [[package]] name = "base16ct" version = "0.2.0" @@ -596,8 +596,8 @@ name = "bls12_381" version = "0.8.0" source = "git+https://github.com/scroll-tech/bls12_381?branch=feat/impl_scalar_field#2c515f73a2462fef8681c8e884edf1710f52b22a" dependencies = [ - "ff 0.13.0", - "group 0.13.0", + "ff", + "group", "pairing", "pasta_curves", "rand_core", @@ -634,24 +634,25 @@ checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" [[package]] name = "bus-mapping" -version = "0.1.0" -source = "git+https://github.com/scroll-tech/zkevm-circuits.git?branch=v0.10#cfa71a8abe45c21582a6b7ebb85b5b1c4cff01eb" +version = "0.11.0" +source = "git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.11.4#38a68e22d3d8449bd39a50c22da55b9e741de453" dependencies = [ - "eth-types 0.1.0", + "eth-types 0.11.0 (git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.11.4)", "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.1.0", + "external-tracer 0.11.0 (git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.11.4)", + "gadgets 0.11.0 (git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.11.4)", "halo2_proofs", "hex", "itertools 0.11.0", "log", - "mock 0.1.0", - "mpt-zktrie 0.1.0", + "mock 0.11.0 (git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.11.4)", + "mpt-zktrie 0.11.0 (git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.11.4)", "num", "poseidon-circuit", "rand", - "revm-precompile 2.0.0", + "revm-precompile", "serde", "serde_json", "strum 0.25.0", @@ -661,24 +662,22 @@ dependencies = [ [[package]] name = "bus-mapping" version = "0.11.0" -source = "git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.11.4#38a68e22d3d8449bd39a50c22da55b9e741de453" +source = "git+https://github.com/scroll-tech/zkevm-circuits.git?branch=feat/agg_recursion#a5337832455b1ed49bc1104a6ed4265dcdc27cdb" dependencies = [ - "eth-types 0.11.0", + "eth-types 0.11.0 (git+https://github.com/scroll-tech/zkevm-circuits.git?branch=feat/agg_recursion)", "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", - "external-tracer 0.11.0", - "gadgets 0.11.0", + "gadgets 0.11.0 (git+https://github.com/scroll-tech/zkevm-circuits.git?branch=feat/agg_recursion)", "halo2_proofs", "hex", "itertools 0.11.0", "log", - "mock 0.11.0", - "mpt-zktrie 0.11.0", + "mock 0.11.0 (git+https://github.com/scroll-tech/zkevm-circuits.git?branch=feat/agg_recursion)", + "mpt-zktrie 0.11.0 (git+https://github.com/scroll-tech/zkevm-circuits.git?branch=feat/agg_recursion)", "num", "poseidon-circuit", - "rand", - "revm-precompile 7.0.0", + "revm-precompile", "serde", "serde_json", "strum 0.25.0", @@ -817,7 +816,7 @@ dependencies = [ "coins-core", "digest 0.10.7", "hmac", - "k256 0.13.3", + "k256", "serde", "sha2", "thiserror", @@ -992,18 +991,6 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" -[[package]] -name = "crypto-bigint" -version = "0.4.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ef2b4b23cddf68b89b8f8069890e8c270d54e2d5fe1b143820234805e4cb17ef" -dependencies = [ - "generic-array", - "rand_core", - "subtle", - "zeroize", -] - [[package]] name = "crypto-bigint" version = "0.5.5" @@ -1096,15 +1083,6 @@ version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e8566979429cf69b49a5c740c60791108e86440e8be149bbea4fe54d2c32d6e2" -[[package]] -name = "der" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1a467a65c5e759bce6e65eaf91cc29f466cdc57cb65777bd646872a8a1fd4de" -dependencies = [ - "const-oid", -] - [[package]] name = "der" version = "0.7.9" @@ -1172,29 +1150,17 @@ version = "1.0.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0d6ef0072f8a535281e4876be788938b528e9a1d43900b82c2569af7da799125" -[[package]] -name = "ecdsa" -version = "0.14.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "413301934810f597c1d19ca71c8710e99a3f1ba28a0d2ebc01551a2daeea3c5c" -dependencies = [ - "der 0.6.1", - "elliptic-curve 0.12.3", - "rfc6979 0.3.1", - "signature 1.6.4", -] - [[package]] name = "ecdsa" version = "0.16.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ee27f32b5c5292967d2d4a9d7f1e0b0aed2c15daded5a60300e4abb9d8020bca" dependencies = [ - "der 0.7.9", + "der", "digest 0.10.7", - "elliptic-curve 0.13.8", - "rfc6979 0.4.0", - "signature 2.2.0", + "elliptic-curve", + "rfc6979", + "signature", "spki", ] @@ -1204,40 +1170,21 @@ version = "1.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3dca9240753cf90908d7e4aac30f630662b02aebaa1b58a3cadabdb23385b58b" -[[package]] -name = "elliptic-curve" -version = "0.12.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7bb888ab5300a19b8e5bceef25ac745ad065f3c9f7efc6de1b91958110891d3" -dependencies = [ - "base16ct 0.1.1", - "crypto-bigint 0.4.9", - "der 0.6.1", - "digest 0.10.7", - "ff 0.12.1", - "generic-array", - "group 0.12.1", - "rand_core", - "sec1 0.3.0", - "subtle", - "zeroize", -] - [[package]] name = "elliptic-curve" version = "0.13.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b5e6043086bf7973472e0c7dff2142ea0b680d30e18d9cc40f267efbf222bd47" dependencies = [ - "base16ct 0.2.0", - "crypto-bigint 0.5.5", + "base16ct", + "crypto-bigint", "digest 0.10.7", - "ff 0.13.0", + "ff", "generic-array", - "group 0.13.0", + "group", "pkcs8", "rand_core", - "sec1 0.7.3", + "sec1", "subtle", "zeroize", ] @@ -1268,7 +1215,7 @@ dependencies = [ "base64 0.13.1", "bytes", "hex", - "k256 0.13.3", + "k256", "log", "rand", "rlp", @@ -1364,22 +1311,25 @@ dependencies = [ [[package]] name = "eth-types" -version = "0.1.0" -source = "git+https://github.com/scroll-tech/zkevm-circuits.git?branch=v0.10#cfa71a8abe45c21582a6b7ebb85b5b1c4cff01eb" +version = "0.11.0" +source = "git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.11.4#38a68e22d3d8449bd39a50c22da55b9e741de453" dependencies = [ "base64 0.13.1", "ethers-core 2.0.7 (git+https://github.com/scroll-tech/ethers-rs.git?branch=v2.0.7)", "ethers-signers", - "halo2-base", - "halo2_proofs", + "halo2curves", "hex", "itertools 0.11.0", + "log", "num", "num-bigint", - "poseidon-circuit", + "poseidon-base", "regex", + "revm-precompile", + "revm-primitives", "serde", "serde_json", + "serde_stacker", "serde_with", "sha3 0.10.8", "strum 0.25.0", @@ -1391,7 +1341,7 @@ dependencies = [ [[package]] name = "eth-types" version = "0.11.0" -source = "git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.11.4#38a68e22d3d8449bd39a50c22da55b9e741de453" +source = "git+https://github.com/scroll-tech/zkevm-circuits.git?branch=feat/agg_recursion#a5337832455b1ed49bc1104a6ed4265dcdc27cdb" dependencies = [ "base64 0.13.1", "ethers-core 2.0.7 (git+https://github.com/scroll-tech/ethers-rs.git?branch=v2.0.7)", @@ -1404,11 +1354,10 @@ dependencies = [ "num-bigint", "poseidon-base", "regex", - "revm-precompile 7.0.0", - "revm-primitives 4.0.0", + "revm-precompile", + "revm-primitives", "serde", "serde_json", - "serde_stacker", "serde_with", "sha3 0.10.8", "strum 0.25.0", @@ -1474,11 +1423,11 @@ dependencies = [ "arrayvec", "bytes", "chrono", - "elliptic-curve 0.13.8", + "elliptic-curve", "ethabi", "generic-array", "hex", - "k256 0.13.3", + "k256", "num_enum 0.6.1", "open-fastrlp", "rand", @@ -1500,11 +1449,11 @@ dependencies = [ "arrayvec", "bytes", "chrono", - "elliptic-curve 0.13.8", + "elliptic-curve", "ethabi", "generic-array", "hex", - "k256 0.13.3", + "k256", "num_enum 0.6.1", "open-fastrlp", "rand", @@ -1599,7 +1548,7 @@ dependencies = [ "async-trait", "coins-bip32", "coins-bip39", - "elliptic-curve 0.13.8", + "elliptic-curve", "eth-keystore", "ethers-core 2.0.7 (git+https://github.com/scroll-tech/ethers-rs.git?branch=v2.0.7)", "hex", @@ -1611,11 +1560,11 @@ dependencies = [ [[package]] name = "external-tracer" -version = "0.1.0" -source = "git+https://github.com/scroll-tech/zkevm-circuits.git?branch=v0.10#cfa71a8abe45c21582a6b7ebb85b5b1c4cff01eb" +version = "0.11.0" +source = "git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.11.4#38a68e22d3d8449bd39a50c22da55b9e741de453" dependencies = [ - "eth-types 0.1.0", - "geth-utils 0.1.0", + "eth-types 0.11.0 (git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.11.4)", + "geth-utils 0.11.0 (git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.11.4)", "log", "serde", "serde_json", @@ -1625,10 +1574,10 @@ dependencies = [ [[package]] name = "external-tracer" version = "0.11.0" -source = "git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.11.4#38a68e22d3d8449bd39a50c22da55b9e741de453" +source = "git+https://github.com/scroll-tech/zkevm-circuits.git?branch=feat/agg_recursion#a5337832455b1ed49bc1104a6ed4265dcdc27cdb" dependencies = [ - "eth-types 0.11.0", - "geth-utils 0.11.0", + "eth-types 0.11.0 (git+https://github.com/scroll-tech/zkevm-circuits.git?branch=feat/agg_recursion)", + "geth-utils 0.11.0 (git+https://github.com/scroll-tech/zkevm-circuits.git?branch=feat/agg_recursion)", "log", "serde", "serde_json", @@ -1652,16 +1601,6 @@ dependencies = [ "bytes", ] -[[package]] -name = "ff" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d013fc25338cc558c5c2cfbad646908fb23591e2404481826742b651c9af7160" -dependencies = [ - "rand_core", - "subtle", -] - [[package]] name = "ff" version = "0.13.0" @@ -1851,11 +1790,12 @@ dependencies = [ [[package]] name = "gadgets" -version = "0.1.0" -source = "git+https://github.com/scroll-tech/zkevm-circuits.git?branch=v0.10#cfa71a8abe45c21582a6b7ebb85b5b1c4cff01eb" +version = "0.11.0" +source = "git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.11.4#38a68e22d3d8449bd39a50c22da55b9e741de453" dependencies = [ - "eth-types 0.1.0", + "eth-types 0.11.0 (git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.11.4)", "halo2_proofs", + "poseidon-base", "sha3 0.10.8", "strum 0.25.0", ] @@ -1863,9 +1803,9 @@ dependencies = [ [[package]] name = "gadgets" version = "0.11.0" -source = "git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.11.4#38a68e22d3d8449bd39a50c22da55b9e741de453" +source = "git+https://github.com/scroll-tech/zkevm-circuits.git?branch=feat/agg_recursion#a5337832455b1ed49bc1104a6ed4265dcdc27cdb" dependencies = [ - "eth-types 0.11.0", + "eth-types 0.11.0 (git+https://github.com/scroll-tech/zkevm-circuits.git?branch=feat/agg_recursion)", "halo2_proofs", "poseidon-base", "sha3 0.10.8", @@ -1885,8 +1825,8 @@ dependencies = [ [[package]] name = "geth-utils" -version = "0.1.0" -source = "git+https://github.com/scroll-tech/zkevm-circuits.git?branch=v0.10#cfa71a8abe45c21582a6b7ebb85b5b1c4cff01eb" +version = "0.11.0" +source = "git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.11.4#38a68e22d3d8449bd39a50c22da55b9e741de453" dependencies = [ "env_logger 0.10.2", "gobuild", @@ -1896,7 +1836,7 @@ dependencies = [ [[package]] name = "geth-utils" version = "0.11.0" -source = "git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.11.4#38a68e22d3d8449bd39a50c22da55b9e741de453" +source = "git+https://github.com/scroll-tech/zkevm-circuits.git?branch=feat/agg_recursion#a5337832455b1ed49bc1104a6ed4265dcdc27cdb" dependencies = [ "env_logger 0.10.2", "gobuild", @@ -1968,24 +1908,13 @@ dependencies = [ "cc", ] -[[package]] -name = "group" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5dfbfb3a6cfbd390d5c9564ab283a0349b9b9fcd46a706c1eb10e0db70bfbac7" -dependencies = [ - "ff 0.12.1", - "rand_core", - "subtle", -] - [[package]] name = "group" version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f0f9ef7462f7c099f518d754361858f86d8a07af53ba9af0fe635bbccb151a63" dependencies = [ - "ff 0.13.0", + "ff", "rand_core", "subtle", ] @@ -2033,7 +1962,7 @@ name = "halo2-base" version = "0.2.2" source = "git+https://github.com/scroll-tech/halo2-lib?branch=develop#817cace374a9f4b2eca682b1cc36f143255ea25f" dependencies = [ - "ff 0.13.0", + "ff", "halo2_proofs", "itertools 0.10.5", "num-bigint", @@ -2048,8 +1977,8 @@ name = "halo2-ecc" version = "0.2.2" source = "git+https://github.com/scroll-tech/halo2-lib?branch=develop#817cace374a9f4b2eca682b1cc36f143255ea25f" dependencies = [ - "ff 0.13.0", - "group 0.13.0", + "ff", + "group", "halo2-base", "itertools 0.10.5", "num-bigint", @@ -2108,8 +2037,8 @@ source = "git+https://github.com/scroll-tech/halo2.git?branch=v1.1#e5ddf67e5ae16 dependencies = [ "arrayvec", "bitvec", - "ff 0.13.0", - "group 0.13.0", + "ff", + "group", "halo2_proofs", "halo2curves", "lazy_static", @@ -2127,8 +2056,8 @@ dependencies = [ "blake2b_simd", "cfg-if 0.1.10", "crossbeam", - "ff 0.13.0", - "group 0.13.0", + "ff", + "group", "halo2curves", "log", "maybe-rayon", @@ -2150,8 +2079,8 @@ source = "git+https://github.com/scroll-tech/halo2curves?branch=v0.1.0#112f5b9bf dependencies = [ "blake2b_simd", "bls12_381", - "ff 0.13.0", - "group 0.13.0", + "ff", + "group", "lazy_static", "maybe-rayon", "num-bigint", @@ -2218,12 +2147,6 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" -[[package]] -name = "hex-literal" -version = "0.3.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ebdb29d2ea9ed0083cd8cece49bbd968021bd99b0849edb4a9a7ee0fdf6a4e0" - [[package]] name = "hex-literal" version = "0.4.1" @@ -2589,19 +2512,6 @@ dependencies = [ "wasm-bindgen", ] -[[package]] -name = "k256" -version = "0.11.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72c1e0b51e7ec0a97369623508396067a486bd0cbed95a2659a4b863d28cfc8b" -dependencies = [ - "cfg-if 1.0.0", - "ecdsa 0.14.8", - "elliptic-curve 0.12.3", - "sha2", - "sha3 0.10.8", -] - [[package]] name = "k256" version = "0.13.3" @@ -2609,11 +2519,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "956ff9b67e26e1a6a866cb758f12c6f8746208489e3e4a4b5580802f2f0a587b" dependencies = [ "cfg-if 1.0.0", - "ecdsa 0.16.9", - "elliptic-curve 0.13.8", + "ecdsa", + "elliptic-curve", "once_cell", "sha2", - "signature 2.2.0", + "signature", ] [[package]] @@ -2635,20 +2545,6 @@ dependencies = [ "sha3-asm", ] -[[package]] -name = "keccak256" -version = "0.1.0" -source = "git+https://github.com/scroll-tech/zkevm-circuits.git?branch=v0.10#cfa71a8abe45c21582a6b7ebb85b5b1c4cff01eb" -dependencies = [ - "env_logger 0.10.2", - "eth-types 0.1.0", - "halo2_proofs", - "itertools 0.11.0", - "log", - "num-bigint", - "num-traits", -] - [[package]] name = "lazy_static" version = "1.4.0" @@ -2779,13 +2675,13 @@ dependencies = [ [[package]] name = "mock" -version = "0.1.0" -source = "git+https://github.com/scroll-tech/zkevm-circuits.git?branch=v0.10#cfa71a8abe45c21582a6b7ebb85b5b1c4cff01eb" +version = "0.11.0" +source = "git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.11.4#38a68e22d3d8449bd39a50c22da55b9e741de453" dependencies = [ - "eth-types 0.1.0", + "eth-types 0.11.0 (git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.11.4)", "ethers-core 2.0.7 (git+https://github.com/scroll-tech/ethers-rs.git?branch=v2.0.7)", "ethers-signers", - "external-tracer 0.1.0", + "external-tracer 0.11.0 (git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.11.4)", "itertools 0.11.0", "log", "rand", @@ -2795,12 +2691,12 @@ dependencies = [ [[package]] name = "mock" version = "0.11.0" -source = "git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.11.4#38a68e22d3d8449bd39a50c22da55b9e741de453" +source = "git+https://github.com/scroll-tech/zkevm-circuits.git?branch=feat/agg_recursion#a5337832455b1ed49bc1104a6ed4265dcdc27cdb" dependencies = [ - "eth-types 0.11.0", + "eth-types 0.11.0 (git+https://github.com/scroll-tech/zkevm-circuits.git?branch=feat/agg_recursion)", "ethers-core 2.0.7 (git+https://github.com/scroll-tech/ethers-rs.git?branch=v2.0.7)", "ethers-signers", - "external-tracer 0.11.0", + "external-tracer 0.11.0 (git+https://github.com/scroll-tech/zkevm-circuits.git?branch=feat/agg_recursion)", "itertools 0.11.0", "log", "rand", @@ -2809,31 +2705,30 @@ dependencies = [ [[package]] name = "mpt-zktrie" -version = "0.1.0" -source = "git+https://github.com/scroll-tech/zkevm-circuits.git?branch=v0.10#cfa71a8abe45c21582a6b7ebb85b5b1c4cff01eb" +version = "0.11.0" +source = "git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.11.4#38a68e22d3d8449bd39a50c22da55b9e741de453" dependencies = [ - "eth-types 0.1.0", - "halo2-mpt-circuits", - "halo2_proofs", + "eth-types 0.11.0 (git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.11.4)", + "halo2curves", "hex", "log", "num-bigint", - "poseidon-circuit", - "zktrie 0.2.0", + "poseidon-base", + "zktrie", ] [[package]] name = "mpt-zktrie" version = "0.11.0" -source = "git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.11.4#38a68e22d3d8449bd39a50c22da55b9e741de453" +source = "git+https://github.com/scroll-tech/zkevm-circuits.git?branch=feat/agg_recursion#a5337832455b1ed49bc1104a6ed4265dcdc27cdb" dependencies = [ - "eth-types 0.11.0", + "eth-types 0.11.0 (git+https://github.com/scroll-tech/zkevm-circuits.git?branch=feat/agg_recursion)", "halo2curves", "hex", "log", "num-bigint", "poseidon-base", - "zktrie 0.3.0", + "zktrie", ] [[package]] @@ -3088,7 +2983,7 @@ version = "0.23.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "81fec4625e73cf41ef4bb6846cafa6d44736525f442ba45e407c4a000a13996f" dependencies = [ - "group 0.13.0", + "group", ] [[package]] @@ -3172,8 +3067,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d3e57598f73cc7e1b2ac63c79c517b31a0877cd7c402cdcaa311b5208de7a095" dependencies = [ "blake2b_simd", - "ff 0.13.0", - "group 0.13.0", + "ff", + "group", "lazy_static", "rand", "static_assertions", @@ -3270,7 +3165,7 @@ version = "0.10.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7" dependencies = [ - "der 0.7.9", + "der", "spki", ] @@ -3304,7 +3199,7 @@ name = "poseidon-circuit" version = "0.1.0" source = "git+https://github.com/scroll-tech/poseidon-circuit.git?branch=main#7b96835c6201afdbfaf3d13d641efbaaf5db2d20" dependencies = [ - "ff 0.13.0", + "ff", "halo2_proofs", "log", "poseidon-base", @@ -3399,8 +3294,8 @@ dependencies = [ "http 1.1.0", "log", "once_cell", - "prover 0.1.0 (git+https://github.com/scroll-tech/zkevm-circuits.git?branch=v0.10)", - "prover 0.11.0", + "prover 0.11.0 (git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.11.4)", + "prover 0.11.0 (git+https://github.com/scroll-tech/zkevm-circuits.git?branch=feat/agg_recursion)", "rand", "reqwest 0.12.4", "reqwest-middleware", @@ -3416,17 +3311,17 @@ dependencies = [ [[package]] name = "prover" -version = "0.1.0" -source = "git+https://github.com/scroll-tech/zkevm-circuits.git?branch=v0.10#cfa71a8abe45c21582a6b7ebb85b5b1c4cff01eb" +version = "0.11.0" +source = "git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.11.4#38a68e22d3d8449bd39a50c22da55b9e741de453" dependencies = [ - "aggregator 0.1.0", + "aggregator 0.11.0 (git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.11.4)", "anyhow", "base64 0.13.1", "blake2", - "bus-mapping 0.1.0", + "bus-mapping 0.11.0 (git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.11.4)", "chrono", "dotenvy", - "eth-types 0.1.0", + "eth-types 0.11.0 (git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.11.4)", "ethers-core 2.0.7 (git+https://github.com/scroll-tech/ethers-rs.git?branch=v2.0.7)", "git-version", "halo2_proofs", @@ -3434,7 +3329,7 @@ dependencies = [ "itertools 0.11.0", "log", "log4rs", - "mpt-zktrie 0.1.0", + "mpt-zktrie 0.11.0 (git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.11.4)", "num-bigint", "rand", "rand_xorshift", @@ -3445,22 +3340,22 @@ dependencies = [ "sha2", "snark-verifier", "snark-verifier-sdk", - "zkevm-circuits 0.1.0", + "zkevm-circuits 0.11.0 (git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.11.4)", ] [[package]] name = "prover" version = "0.11.0" -source = "git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.11.4#38a68e22d3d8449bd39a50c22da55b9e741de453" +source = "git+https://github.com/scroll-tech/zkevm-circuits.git?branch=feat/agg_recursion#a5337832455b1ed49bc1104a6ed4265dcdc27cdb" dependencies = [ - "aggregator 0.11.0", + "aggregator 0.11.0 (git+https://github.com/scroll-tech/zkevm-circuits.git?branch=feat/agg_recursion)", "anyhow", "base64 0.13.1", "blake2", - "bus-mapping 0.11.0", + "bus-mapping 0.11.0 (git+https://github.com/scroll-tech/zkevm-circuits.git?branch=feat/agg_recursion)", "chrono", "dotenvy", - "eth-types 0.11.0", + "eth-types 0.11.0 (git+https://github.com/scroll-tech/zkevm-circuits.git?branch=feat/agg_recursion)", "ethers-core 2.0.7 (git+https://github.com/scroll-tech/ethers-rs.git?branch=v2.0.7)", "git-version", "halo2_proofs", @@ -3468,7 +3363,7 @@ dependencies = [ "itertools 0.11.0", "log", "log4rs", - "mpt-zktrie 0.11.0", + "mpt-zktrie 0.11.0 (git+https://github.com/scroll-tech/zkevm-circuits.git?branch=feat/agg_recursion)", "num-bigint", "rand", "rand_xorshift", @@ -3479,7 +3374,7 @@ dependencies = [ "sha2", "snark-verifier", "snark-verifier-sdk", - "zkevm-circuits 0.11.0", + "zkevm-circuits 0.11.0 (git+https://github.com/scroll-tech/zkevm-circuits.git?branch=feat/agg_recursion)", ] [[package]] @@ -3768,22 +3663,6 @@ dependencies = [ "sha3 0.10.8", ] -[[package]] -name = "revm-precompile" -version = "2.0.0" -source = "git+https://github.com/scroll-tech/revm?branch=scroll-fix#aebf2e591e622e6bcce2c5d4bf3336935a68cf11" -dependencies = [ - "k256 0.11.6", - "num", - "once_cell", - "revm-primitives 1.0.0", - "ripemd", - "secp256k1 0.26.0", - "sha2", - "sha3 0.10.8", - "substrate-bn", -] - [[package]] name = "revm-precompile" version = "7.0.0" @@ -3791,54 +3670,15 @@ source = "git+https://github.com/scroll-tech/revm?branch=scroll-evm-executor/v36 dependencies = [ "aurora-engine-modexp", "c-kzg", - "k256 0.13.3", + "k256", "once_cell", - "revm-primitives 4.0.0", + "revm-primitives", "ripemd", "secp256k1 0.29.0", "sha2", "substrate-bn", ] -[[package]] -name = "revm-primitives" -version = "1.0.0" -source = "git+https://github.com/scroll-tech/revm?branch=scroll-fix#aebf2e591e622e6bcce2c5d4bf3336935a68cf11" -dependencies = [ - "auto_impl", - "bytes", - "derive_more", - "enumn", - "fixed-hash", - "hashbrown 0.13.2", - "hex", - "hex-literal 0.3.4", - "rlp", - "ruint", - "sha3 0.10.8", -] - -[[package]] -name = "revm-primitives" -version = "3.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cbbc9640790cebcb731289afb7a7d96d16ad94afeb64b5d0b66443bd151e79d6" -dependencies = [ - "alloy-primitives", - "auto_impl", - "bitflags 2.5.0", - "bitvec", - "c-kzg", - "cfg-if 1.0.0", - "derive_more", - "dyn-clone", - "enumn", - "hashbrown 0.14.5", - "hex", - "once_cell", - "serde", -] - [[package]] name = "revm-primitives" version = "4.0.0" @@ -3879,17 +3719,6 @@ dependencies = [ "substrate-bn", ] -[[package]] -name = "rfc6979" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7743f17af12fa0b03b803ba12cd6a8d9483a587e89c69445e3909655c0b9fabb" -dependencies = [ - "crypto-bigint 0.4.9", - "hmac", - "zeroize", -] - [[package]] name = "rfc6979" version = "0.4.0" @@ -4191,27 +4020,14 @@ dependencies = [ "untrusted 0.9.0", ] -[[package]] -name = "sec1" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3be24c1842290c45df0a7bf069e0c268a747ad05a192f2fd7dcfdbc1cba40928" -dependencies = [ - "base16ct 0.1.1", - "der 0.6.1", - "generic-array", - "subtle", - "zeroize", -] - [[package]] name = "sec1" version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d3e97a565f76233a6003f9f5c54be1d9c5bdfa3eccfb189469f11ec4901c47dc" dependencies = [ - "base16ct 0.2.0", - "der 0.7.9", + "base16ct", + "der", "generic-array", "pkcs8", "subtle", @@ -4227,15 +4043,6 @@ dependencies = [ "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]] name = "secp256k1" version = "0.29.0" @@ -4255,15 +4062,6 @@ 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" @@ -4470,16 +4268,6 @@ dependencies = [ "cfg-if 1.0.0", ] -[[package]] -name = "signature" -version = "1.6.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "74233d3b3b2f6d4b006dc19dee745e73e2a6bfb6f93607cd3b02bd5b00797d7c" -dependencies = [ - "digest 0.10.7", - "rand_core", -] - [[package]] name = "signature" version = "2.2.0" @@ -4551,7 +4339,7 @@ source = "git+https://github.com/scroll-tech/snark-verifier?branch=develop#58c46 dependencies = [ "bincode", "ethereum-types", - "ff 0.13.0", + "ff", "halo2-base", "hex", "itertools 0.12.1", @@ -4595,7 +4383,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d91ed6c858b01f942cd56b37a94b3e0a1798290327d1236e4d9cf4eaca44d29d" dependencies = [ "base64ct", - "der 0.7.9", + "der", ] [[package]] @@ -5552,29 +5340,29 @@ dependencies = [ [[package]] name = "zkevm-circuits" -version = "0.1.0" -source = "git+https://github.com/scroll-tech/zkevm-circuits.git?branch=v0.10#cfa71a8abe45c21582a6b7ebb85b5b1c4cff01eb" +version = "0.11.0" +source = "git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.11.4#38a68e22d3d8449bd39a50c22da55b9e741de453" dependencies = [ "array-init", - "bus-mapping 0.1.0", + "bus-mapping 0.11.0 (git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.11.4)", "either", "env_logger 0.10.2", - "eth-types 0.1.0", + "eth-types 0.11.0 (git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.11.4)", "ethers-core 2.0.7 (git+https://github.com/scroll-tech/ethers-rs.git?branch=v2.0.7)", "ethers-signers", - "ff 0.13.0", - "gadgets 0.1.0", + "ff", + "gadgets 0.11.0 (git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.11.4)", "halo2-base", "halo2-ecc", + "halo2-mpt-circuits", "halo2_gadgets", "halo2_proofs", "hex", "itertools 0.11.0", - "keccak256", "log", "misc-precompiled-circuit", - "mock 0.1.0", - "mpt-zktrie 0.1.0", + "mock 0.11.0 (git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.11.4)", + "mpt-zktrie 0.11.0 (git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.11.4)", "num", "num-bigint", "poseidon-circuit", @@ -5595,17 +5383,17 @@ dependencies = [ [[package]] name = "zkevm-circuits" version = "0.11.0" -source = "git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.11.4#38a68e22d3d8449bd39a50c22da55b9e741de453" +source = "git+https://github.com/scroll-tech/zkevm-circuits.git?branch=feat/agg_recursion#a5337832455b1ed49bc1104a6ed4265dcdc27cdb" dependencies = [ "array-init", - "bus-mapping 0.11.0", + "bus-mapping 0.11.0 (git+https://github.com/scroll-tech/zkevm-circuits.git?branch=feat/agg_recursion)", "either", "env_logger 0.10.2", - "eth-types 0.11.0", + "eth-types 0.11.0 (git+https://github.com/scroll-tech/zkevm-circuits.git?branch=feat/agg_recursion)", "ethers-core 2.0.7 (git+https://github.com/scroll-tech/ethers-rs.git?branch=v2.0.7)", "ethers-signers", - "ff 0.13.0", - "gadgets 0.11.0", + "ff", + "gadgets 0.11.0 (git+https://github.com/scroll-tech/zkevm-circuits.git?branch=feat/agg_recursion)", "halo2-base", "halo2-ecc", "halo2-mpt-circuits", @@ -5615,8 +5403,8 @@ dependencies = [ "itertools 0.11.0", "log", "misc-precompiled-circuit", - "mock 0.11.0", - "mpt-zktrie 0.11.0", + "mock 0.11.0 (git+https://github.com/scroll-tech/zkevm-circuits.git?branch=feat/agg_recursion)", + "mpt-zktrie 0.11.0 (git+https://github.com/scroll-tech/zkevm-circuits.git?branch=feat/agg_recursion)", "num", "num-bigint", "poseidon-circuit", @@ -5634,14 +5422,6 @@ dependencies = [ "subtle", ] -[[package]] -name = "zktrie" -version = "0.2.0" -source = "git+https://github.com/scroll-tech/zktrie.git?tag=v0.7.1#a12f2f262ad3e82301e39ecdf9bfe235befc7074" -dependencies = [ - "gobuild", -] - [[package]] name = "zktrie" version = "0.3.0" diff --git a/prover/Cargo.toml b/prover/Cargo.toml index bd145fa562..b7bacf36d7 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 = { git = "https://github.com/scroll-tech/zkevm-circuits.git", branch = "v0.10", default-features = false, features = ["parallel_syn", "scroll", "shanghai"] } -prover_next = { git = "https://github.com/scroll-tech/zkevm-circuits.git", tag = "v0.11.4", package = "prover", default-features = false, features = ["parallel_syn", "scroll"] } +prover_curie = { git = "https://github.com/scroll-tech/zkevm-circuits.git", tag = "v0.11.4", package = "prover", default-features = false, features = ["parallel_syn", "scroll"] } +prover_darwin = { git = "https://github.com/scroll-tech/zkevm-circuits.git", branch = "feat/agg_recursion", 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/Makefile b/prover/Makefile index d0b06e7589..6bcd3faa7f 100644 --- a/prover/Makefile +++ b/prover/Makefile @@ -37,14 +37,10 @@ endif prover: GO_TAG=${GO_TAG} GIT_REV=${GIT_REV} ZK_VERSION=${ZK_VERSION} cargo build --release - rm -rf ./lib && mkdir ./lib - find target/ -name "libzktrie.so" | xargs -I{} cp {} ./lib tests_binary: cargo clean && cargo test --release --no-run ls target/release/deps/prover* | grep -v "\.d" | xargs -I{} ln -sf {} ./prover.test - rm -rf ./lib && mkdir ./lib - find target/ -name "libzktrie.so" | xargs -I{} cp {} ./lib lint: cargo check --all-features diff --git a/prover/src/config.rs b/prover/src/config.rs index 5f301337f9..4e3c1f2ccc 100644 --- a/prover/src/config.rs +++ b/prover/src/config.rs @@ -2,7 +2,7 @@ use anyhow::{bail, Result}; use serde::{Deserialize, Serialize}; use std::fs::File; -use crate::types::ProofType; +use crate::types::ProverType; #[derive(Debug, Serialize, Deserialize)] pub struct CircuitConfig { @@ -24,14 +24,13 @@ pub struct L2GethConfig { pub endpoint: String, } -#[derive(Debug, Serialize, Deserialize)] +#[derive(Debug, Deserialize)] pub struct Config { pub prover_name: String, pub keystore_path: String, pub keystore_password: String, pub db_path: String, - #[serde(default)] - pub proof_type: ProofType, + pub prover_type: ProverType, pub low_version_circuit: CircuitConfig, pub high_version_circuit: CircuitConfig, pub coordinator: CoordinatorConfig, diff --git a/prover/src/coordinator_client.rs b/prover/src/coordinator_client.rs index 52344756ce..56fd58954e 100644 --- a/prover/src/coordinator_client.rs +++ b/prover/src/coordinator_client.rs @@ -21,6 +21,7 @@ pub struct CoordinatorClient<'a> { key_signer: Rc, rt: Runtime, listener: Box, + vks: Vec, } impl<'a> CoordinatorClient<'a> { @@ -28,6 +29,7 @@ impl<'a> CoordinatorClient<'a> { config: &'a Config, key_signer: Rc, listener: Box, + vks: Vec, ) -> Result { let rt = tokio::runtime::Builder::new_current_thread() .enable_all() @@ -46,6 +48,7 @@ impl<'a> CoordinatorClient<'a> { key_signer, rt, listener, + vks, }; client.login()?; Ok(client) @@ -68,12 +71,15 @@ impl<'a> CoordinatorClient<'a> { challenge: token.clone(), prover_name: self.config.prover_name.clone(), prover_version: crate::version::get_version(), + prover_types: vec![self.config.prover_type], + vks: self.vks.clone(), }; - let buffer = login_message.rlp(); + let buffer = rlp::encode(&login_message); let signature = self.key_signer.sign_buffer(&buffer)?; let login_request = LoginRequest { message: login_message, + public_key: self.key_signer.get_public_key(), signature, }; let login_response = self.rt.block_on(api.login(&login_request, &token))?; diff --git a/prover/src/coordinator_client/types.rs b/prover/src/coordinator_client/types.rs index 2f641e2b73..c646a9afd4 100644 --- a/prover/src/coordinator_client/types.rs +++ b/prover/src/coordinator_client/types.rs @@ -1,6 +1,6 @@ use super::errors::ErrorCode; -use crate::types::{ProofFailureType, ProofStatus}; -use rlp::RlpStream; +use crate::types::{ProofFailureType, ProofStatus, ProverType, TaskType}; +use rlp::{Encodable, RlpStream}; use serde::{Deserialize, Serialize}; #[derive(Deserialize)] @@ -15,23 +15,36 @@ pub struct LoginMessage { pub challenge: String, pub prover_name: String, pub prover_version: String, + pub prover_types: Vec, + pub vks: Vec, } -impl LoginMessage { - pub fn rlp(&self) -> Vec { - let mut rlp = RlpStream::new(); - let num_fields = 3; - rlp.begin_list(num_fields); - rlp.append(&self.prover_name); - rlp.append(&self.prover_version); - rlp.append(&self.challenge); - rlp.out().freeze().into() +impl Encodable for LoginMessage { + fn rlp_append(&self, s: &mut RlpStream) { + let num_fields = 5; + s.begin_list(num_fields); + s.append(&self.challenge); + s.append(&self.prover_version); + s.append(&self.prover_name); + // The ProverType in go side is an type alias of uint8 + // A uint8 slice is treated as a string when doing the rlp encoding + let prover_types = self + .prover_types + .iter() + .map(|prover_type: &ProverType| prover_type.to_u8()) + .collect::>(); + s.append(&prover_types); + s.begin_list(self.vks.len()); + for vk in &self.vks { + s.append(vk); + } } } #[derive(Serialize, Deserialize)] pub struct LoginRequest { pub message: LoginMessage, + pub public_key: String, pub signature: String, } @@ -45,16 +58,15 @@ pub type ChallengeResponseData = LoginResponseData; #[derive(Default, Serialize, Deserialize)] pub struct GetTaskRequest { - pub task_type: crate::types::ProofType, + pub task_types: Vec, pub prover_height: Option, - pub vks: Vec, } #[derive(Serialize, Deserialize)] pub struct GetTaskResponseData { pub uuid: String, pub task_id: String, - pub task_type: crate::types::ProofType, + pub task_type: TaskType, pub task_data: String, pub hard_fork_name: String, } @@ -63,12 +75,11 @@ pub struct GetTaskResponseData { pub struct SubmitProofRequest { pub uuid: String, pub task_id: String, - pub task_type: crate::types::ProofType, + pub task_type: TaskType, pub status: ProofStatus, pub proof: String, pub failure_type: Option, pub failure_msg: Option, - pub hard_fork_name: String, } #[derive(Serialize, Deserialize)] diff --git a/prover/src/main.rs b/prover/src/main.rs index d7d2611154..22605a7a5c 100644 --- a/prover/src/main.rs +++ b/prover/src/main.rs @@ -65,7 +65,7 @@ fn main() -> Result<(), Box> { log::info!( "prover start successfully. name: {}, type: {:?}, publickey: {}, version: {}", config.prover_name, - config.proof_type, + config.prover_type, prover.get_public_key(), version::get_version(), ); diff --git a/prover/src/prover.rs b/prover/src/prover.rs index 538e1d2a21..fb943e11ee 100644 --- a/prover/src/prover.rs +++ b/prover/src/prover.rs @@ -8,7 +8,8 @@ use crate::{ coordinator_client::{listener::Listener, types::*, CoordinatorClient}, geth_client::GethClient, key_signer::KeySigner, - types::{ProofFailureType, ProofStatus, ProofType}, + types::{ProofFailureType, ProofStatus, ProverType}, + utils::get_task_types, zk_circuits_handler::{CircuitsHandler, CircuitsHandlerProvider}, }; @@ -24,16 +25,11 @@ pub struct Prover<'a> { impl<'a> Prover<'a> { pub fn new(config: &'a Config, coordinator_listener: Box) -> Result { - let proof_type = config.proof_type; + let prover_type = config.prover_type; let keystore_path = &config.keystore_path; let keystore_password = &config.keystore_password; - let key_signer = Rc::new(KeySigner::new(keystore_path, keystore_password)?); - let coordinator_client = - CoordinatorClient::new(config, Rc::clone(&key_signer), coordinator_listener) - .context("failed to create coordinator_client")?; - - let geth_client = if config.proof_type == ProofType::Chunk { + let geth_client = if config.prover_type == ProverType::Chunk { Some(Rc::new(RefCell::new( GethClient::new( &config.prover_name, @@ -45,9 +41,16 @@ impl<'a> Prover<'a> { None }; - let provider = CircuitsHandlerProvider::new(proof_type, config, geth_client.clone()) + let provider = CircuitsHandlerProvider::new(prover_type, config, geth_client.clone()) .context("failed to create circuits handler provider")?; + let vks = provider.init_vks(prover_type, config, geth_client.clone()); + + let key_signer = Rc::new(KeySigner::new(keystore_path, keystore_password)?); + let coordinator_client = + CoordinatorClient::new(config, Rc::clone(&key_signer), coordinator_listener, vks) + .context("failed to create coordinator_client")?; + let prover = Prover { config, key_signer: Rc::clone(&key_signer), @@ -59,10 +62,6 @@ impl<'a> Prover<'a> { Ok(prover) } - pub fn get_proof_type(&self) -> ProofType { - self.config.proof_type - } - pub fn get_public_key(&self) -> String { self.key_signer.get_public_key() } @@ -70,12 +69,12 @@ impl<'a> Prover<'a> { pub fn fetch_task(&self) -> Result { log::info!("[prover] start to fetch_task"); let mut req = GetTaskRequest { - task_type: self.get_proof_type(), + task_types: get_task_types(self.config.prover_type), prover_height: None, - vks: self.circuits_handler_provider.borrow().get_vks(), + // vks: self.circuits_handler_provider.borrow().get_vks(), }; - if self.get_proof_type() == ProofType::Chunk { + if self.config.prover_type == ProverType::Chunk { let latest_block_number = self.get_latest_block_number_value()?; if let Some(v) = latest_block_number { if v.as_u64() == 0 { @@ -130,7 +129,6 @@ impl<'a> Prover<'a> { task_type: proof_detail.proof_type, status: ProofStatus::Ok, proof: proof_detail.proof_data, - hard_fork_name: task.hard_fork_name.clone(), ..Default::default() }; @@ -151,7 +149,6 @@ impl<'a> Prover<'a> { status: ProofStatus::Error, failure_type: Some(failure_type), failure_msg: Some(error.to_string()), - hard_fork_name: task.hard_fork_name.clone(), ..Default::default() }; self.do_submit(&request) diff --git a/prover/src/types.rs b/prover/src/types.rs index 4c835c92a0..47f2724fc7 100644 --- a/prover/src/types.rs +++ b/prover/src/types.rs @@ -6,57 +6,107 @@ use crate::coordinator_client::types::GetTaskResponseData; pub type CommonHash = H256; #[derive(Debug, Clone, Copy, PartialEq)] -pub enum ProofType { +pub enum TaskType { Undefined, Chunk, Batch, + Bundle, } -impl ProofType { +impl TaskType { fn from_u8(v: u8) -> Self { match v { - 1 => ProofType::Chunk, - 2 => ProofType::Batch, - _ => ProofType::Undefined, + 1 => TaskType::Chunk, + 2 => TaskType::Batch, + 3 => TaskType::Bundle, + _ => TaskType::Undefined, } } } -impl Serialize for ProofType { +impl Serialize for TaskType { fn serialize(&self, serializer: S) -> Result where S: Serializer, { match *self { - ProofType::Undefined => serializer.serialize_i8(0), - ProofType::Chunk => serializer.serialize_i8(1), - ProofType::Batch => serializer.serialize_i8(2), + TaskType::Undefined => serializer.serialize_u8(0), + TaskType::Chunk => serializer.serialize_u8(1), + TaskType::Batch => serializer.serialize_u8(2), + TaskType::Bundle => serializer.serialize_u8(3), } } } -impl<'de> Deserialize<'de> for ProofType { +impl<'de> Deserialize<'de> for TaskType { fn deserialize(deserializer: D) -> Result where D: Deserializer<'de>, { let v: u8 = u8::deserialize(deserializer)?; - Ok(ProofType::from_u8(v)) + Ok(TaskType::from_u8(v)) } } -impl Default for ProofType { +impl Default for TaskType { fn default() -> Self { Self::Undefined } } +#[derive(Debug, Clone, Copy, PartialEq)] +pub enum ProverType { + Chunk, + Batch, +} + +impl ProverType { + fn from_u8(v: u8) -> Self { + match v { + 1 => ProverType::Chunk, + 2 => ProverType::Batch, + _ => { + panic!("invalid prover_type") + } + } + } + + pub fn to_u8(self) -> u8 { + match self { + ProverType::Chunk => 1, + ProverType::Batch => 2, + } + } +} + +impl Serialize for ProverType { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + match *self { + ProverType::Chunk => serializer.serialize_u8(1), + ProverType::Batch => serializer.serialize_u8(2), + } + } +} + +impl<'de> Deserialize<'de> for ProverType { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + let v: u8 = u8::deserialize(deserializer)?; + Ok(ProverType::from_u8(v)) + } +} + #[derive(Serialize, Deserialize, Default)] pub struct Task { pub uuid: String, pub id: String, #[serde(rename = "type", default)] - pub task_type: ProofType, + pub task_type: TaskType, pub task_data: String, #[serde(default)] pub hard_fork_name: String, @@ -100,7 +150,7 @@ impl From for TaskWrapper { pub struct ProofDetail { pub id: String, #[serde(rename = "type", default)] - pub proof_type: ProofType, + pub proof_type: TaskType, pub proof_data: String, pub error: String, } diff --git a/prover/src/utils.rs b/prover/src/utils.rs index 87b7137e33..18be4ac7a1 100644 --- a/prover/src/utils.rs +++ b/prover/src/utils.rs @@ -1,6 +1,8 @@ use env_logger::Env; use std::{fs::OpenOptions, sync::Once}; +use crate::types::{ProverType, TaskType}; + static LOG_INIT: Once = Once::new(); /// Initialize log @@ -21,3 +23,10 @@ pub fn log_init(log_file: Option) { builder.init(); }); } + +pub fn get_task_types(prover_type: ProverType) -> Vec { + match prover_type { + ProverType::Chunk => vec![TaskType::Chunk], + ProverType::Batch => vec![TaskType::Batch, TaskType::Bundle], + } +} diff --git a/prover/src/zk_circuits_handler.rs b/prover/src/zk_circuits_handler.rs index 9d88d58290..936d6d6387 100644 --- a/prover/src/zk_circuits_handler.rs +++ b/prover/src/zk_circuits_handler.rs @@ -1,14 +1,15 @@ -mod bernoulli; mod curie; +mod darwin; use super::geth_client::GethClient; use crate::{ config::{AssetsDirEnvConfig, Config}, - types::{ProofType, Task}, + types::{ProverType, Task, TaskType}, + utils::get_task_types, }; use anyhow::{bail, Result}; -use bernoulli::BaseCircuitsHandler; -use curie::NextCircuitsHandler; +use curie::CurieHandler; +use darwin::DarwinHandler; use std::{cell::RefCell, collections::HashMap, rc::Rc}; type HardForkName = String; @@ -20,38 +21,37 @@ pub mod utils { } pub trait CircuitsHandler { - fn get_vk(&self, task_type: ProofType) -> Option>; + fn get_vk(&self, task_type: TaskType) -> Option>; - fn get_proof_data(&self, task_type: ProofType, task: &Task) -> Result; + fn get_proof_data(&self, task_type: TaskType, task: &Task) -> Result; } type CircuitsHandlerBuilder = fn( - proof_type: ProofType, + prover_type: ProverType, config: &Config, geth_client: Option>>, ) -> Result>; pub struct CircuitsHandlerProvider<'a> { - proof_type: ProofType, + prover_type: ProverType, config: &'a Config, geth_client: Option>>, circuits_handler_builder_map: HashMap, current_hard_fork_name: Option, current_circuit: Option>>, - vks: Vec, } impl<'a> CircuitsHandlerProvider<'a> { pub fn new( - proof_type: ProofType, + prover_type: ProverType, config: &'a Config, geth_client: Option>>, ) -> Result { let mut m: HashMap = HashMap::new(); fn handler_builder( - proof_type: ProofType, + prover_type: ProverType, config: &Config, geth_client: Option>>, ) -> Result> { @@ -60,8 +60,8 @@ impl<'a> CircuitsHandlerProvider<'a> { &config.low_version_circuit.hard_fork_name ); AssetsDirEnvConfig::enable_first(); - BaseCircuitsHandler::new( - proof_type, + CurieHandler::new( + prover_type, &config.low_version_circuit.params_path, &config.low_version_circuit.assets_path, geth_client, @@ -74,7 +74,7 @@ impl<'a> CircuitsHandlerProvider<'a> { ); fn next_handler_builder( - proof_type: ProofType, + prover_type: ProverType, config: &Config, geth_client: Option>>, ) -> Result> { @@ -83,8 +83,8 @@ impl<'a> CircuitsHandlerProvider<'a> { &config.high_version_circuit.hard_fork_name ); AssetsDirEnvConfig::enable_second(); - NextCircuitsHandler::new( - proof_type, + DarwinHandler::new( + prover_type, &config.high_version_circuit.params_path, &config.high_version_circuit.assets_path, geth_client, @@ -97,16 +97,13 @@ impl<'a> CircuitsHandlerProvider<'a> { next_handler_builder, ); - let vks = CircuitsHandlerProvider::init_vks(proof_type, config, &m, geth_client.clone()); - let provider = CircuitsHandlerProvider { - proof_type, + prover_type, config, geth_client, circuits_handler_builder_map: m, current_hard_fork_name: None, current_circuit: None, - vks, }; Ok(provider) @@ -132,7 +129,7 @@ impl<'a> CircuitsHandlerProvider<'a> { ); if let Some(builder) = self.circuits_handler_builder_map.get(hard_fork_name) { log::info!("building circuits handler for {hard_fork_name}"); - let handler = builder(self.proof_type, self.config, self.geth_client.clone()) + let handler = builder(self.prover_type, self.config, self.geth_client.clone()) .expect("failed to build circuits handler"); self.current_hard_fork_name = Some(hard_fork_name.clone()); let rc_handler = Rc::new(handler); @@ -146,27 +143,32 @@ impl<'a> CircuitsHandlerProvider<'a> { } } - fn init_vks( - proof_type: ProofType, + pub fn init_vks( + &self, + prover_type: ProverType, config: &'a Config, - circuits_handler_builder_map: &HashMap, geth_client: Option>>, ) -> Vec { - circuits_handler_builder_map + self.circuits_handler_builder_map .iter() - .map(|(hard_fork_name, build)| { - let handler = build(proof_type, config, geth_client.clone()) + .flat_map(|(hard_fork_name, build)| { + let handler = build(prover_type, config, geth_client.clone()) .expect("failed to build circuits handler"); - let vk = handler - .get_vk(proof_type) - .map_or("".to_string(), utils::encode_vk); - log::info!("vk for {hard_fork_name} is {vk}"); - vk + + get_task_types(prover_type) + .into_iter() + .map(|task_type| { + let vk = handler + .get_vk(task_type) + .map_or("".to_string(), utils::encode_vk); + log::info!( + "vk for {hard_fork_name}, is {vk}, task_type: {:?}", + task_type + ); + vk + }) + .collect::>() }) .collect::>() } - - pub fn get_vks(&self) -> Vec { - self.vks.clone() - } } diff --git a/prover/src/zk_circuits_handler/curie.rs b/prover/src/zk_circuits_handler/curie.rs index 032ea7ca73..39c38e3cd3 100644 --- a/prover/src/zk_circuits_handler/curie.rs +++ b/prover/src/zk_circuits_handler/curie.rs @@ -1,17 +1,22 @@ use super::CircuitsHandler; -use crate::{geth_client::GethClient, types::ProofType}; +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, rc::Rc}; +use std::{cell::RefCell, cmp::Ordering, env, rc::Rc}; -use prover_next::{ +use prover_curie::{ aggregator::Prover as BatchProver, check_chunk_hashes, zkevm::Prover as ChunkProver, BatchProof, BatchProvingTask, BlockTrace, ChunkInfo, ChunkProof, ChunkProvingTask, }; -use super::bernoulli::OUTPUT_DIR; +// Only used for debugging. +static OUTPUT_DIR: Lazy> = Lazy::new(|| env::var("PROVER_OUTPUT_DIR").ok()); #[derive(Deserialize)] pub struct BatchTaskDetail { @@ -29,33 +34,32 @@ fn get_block_number(block_trace: &BlockTrace) -> Option { } #[derive(Default)] -pub struct NextCircuitsHandler { +pub struct CurieHandler { chunk_prover: Option>, batch_prover: Option>, geth_client: Option>>, } -impl NextCircuitsHandler { +impl CurieHandler { pub fn new( - proof_type: ProofType, + prover_type: ProverType, params_dir: &str, assets_dir: &str, geth_client: Option>>, ) -> Result { - match proof_type { - ProofType::Chunk => Ok(Self { + match prover_type { + ProverType::Chunk => Ok(Self { chunk_prover: Some(RefCell::new(ChunkProver::from_dirs(params_dir, assets_dir))), batch_prover: None, geth_client, }), - ProofType::Batch => Ok(Self { + ProverType::Batch => Ok(Self { batch_prover: Some(RefCell::new(BatchProver::from_dirs(params_dir, assets_dir))), chunk_prover: None, geth_client, }), - _ => bail!("proof type invalid"), } } @@ -186,14 +190,14 @@ impl NextCircuitsHandler { } } -impl CircuitsHandler for NextCircuitsHandler { - fn get_vk(&self, task_type: ProofType) -> Option> { +impl CircuitsHandler for CurieHandler { + fn get_vk(&self, task_type: TaskType) -> Option> { match task_type { - ProofType::Chunk => self + TaskType::Chunk => self .chunk_prover .as_ref() .and_then(|prover| prover.borrow().get_vk()), - ProofType::Batch => self + TaskType::Batch => self .batch_prover .as_ref() .and_then(|prover| prover.borrow().get_vk()), @@ -201,10 +205,10 @@ impl CircuitsHandler for NextCircuitsHandler { } } - fn get_proof_data(&self, task_type: ProofType, task: &crate::types::Task) -> Result { + fn get_proof_data(&self, task_type: TaskType, task: &crate::types::Task) -> Result { match task_type { - ProofType::Chunk => self.gen_chunk_proof(task), - ProofType::Batch => self.gen_batch_proof(task), + TaskType::Chunk => self.gen_chunk_proof(task), + TaskType::Batch => self.gen_batch_proof(task), _ => unreachable!(), } } @@ -216,7 +220,7 @@ impl CircuitsHandler for NextCircuitsHandler { mod tests { use super::*; use crate::zk_circuits_handler::utils::encode_vk; - use prover_next::utils::chunk_trace_to_witness_block; + use prover_curie::utils::chunk_trace_to_witness_block; use std::{path::PathBuf, sync::LazyLock}; #[ctor::ctor] @@ -251,12 +255,11 @@ mod tests { #[test] fn test_circuits() -> Result<()> { - let chunk_handler = - NextCircuitsHandler::new(ProofType::Chunk, &PARAMS_PATH, &ASSETS_PATH, None)?; + let chunk_handler = CurieHandler::new(ProverType::Chunk, &PARAMS_PATH, &ASSETS_PATH, None)?; - let chunk_vk = chunk_handler.get_vk(ProofType::Chunk).unwrap(); + let chunk_vk = chunk_handler.get_vk(TaskType::Chunk).unwrap(); - check_vk(ProofType::Chunk, chunk_vk, "chunk vk must be available"); + 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![]; @@ -276,10 +279,9 @@ mod tests { chunk_proofs.push(chunk_proof); } - let batch_handler = - NextCircuitsHandler::new(ProofType::Batch, &PARAMS_PATH, &ASSETS_PATH, None)?; - let batch_vk = batch_handler.get_vk(ProofType::Batch).unwrap(); - check_vk(ProofType::Batch, batch_vk, "batch vk must be available"); + let batch_handler = CurieHandler::new(ProverType::Batch, &PARAMS_PATH, &ASSETS_PATH, None)?; + let batch_vk = batch_handler.get_vk(TaskType::Batch).unwrap(); + check_vk(TaskType::Batch, batch_vk, "batch vk must be available"); let chunk_hashes_proofs = chunk_infos.into_iter().zip(chunk_proofs).collect(); log::info!("start to prove batch"); let batch_proof = batch_handler.gen_batch_proof_raw(chunk_hashes_proofs)?; @@ -289,18 +291,19 @@ mod tests { Ok(()) } - fn check_vk(proof_type: ProofType, vk: Vec, info: &str) { - log::info!("check_vk, {:?}", proof_type); - let vk_from_file = read_vk(proof_type).unwrap(); + fn check_vk(task_type: TaskType, vk: Vec, info: &str) { + log::info!("check_vk, {:?}", task_type); + let vk_from_file = read_vk(task_type).unwrap(); assert_eq!(vk_from_file, encode_vk(vk), "{info}") } - fn read_vk(proof_type: ProofType) -> Result { - log::info!("read_vk, {:?}", proof_type); - let vk_file = match proof_type { - ProofType::Chunk => CHUNK_VK_PATH.clone(), - ProofType::Batch => BATCH_VK_PATH.clone(), - ProofType::Undefined => unreachable!(), + fn read_vk(task_type: TaskType) -> Result { + log::info!("read_vk, {:?}", task_type); + let vk_file = match task_type { + TaskType::Chunk => CHUNK_VK_PATH.clone(), + TaskType::Batch => BATCH_VK_PATH.clone(), + TaskType::Bundle => unreachable!(), + TaskType::Undefined => unreachable!(), }; let data = std::fs::read(vk_file)?; diff --git a/prover/src/zk_circuits_handler/bernoulli.rs b/prover/src/zk_circuits_handler/darwin.rs similarity index 68% rename from prover/src/zk_circuits_handler/bernoulli.rs rename to prover/src/zk_circuits_handler/darwin.rs index bde85c1dc2..c58eb31a44 100644 --- a/prover/src/zk_circuits_handler/bernoulli.rs +++ b/prover/src/zk_circuits_handler/darwin.rs @@ -1,27 +1,36 @@ use super::CircuitsHandler; -use crate::{geth_client::GethClient, types::ProofType}; -use anyhow::{bail, Ok, Result}; +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 prover::{ - aggregator::Prover as BatchProver, zkevm::Prover as ChunkProver, BatchProof, BlockTrace, - ChunkHash, ChunkProof, -}; use std::{cell::RefCell, cmp::Ordering, env, rc::Rc}; +use prover_darwin::{ + aggregator::{Prover as BatchProver, MAX_AGG_SNARKS}, + check_chunk_hashes, + zkevm::Prover as ChunkProver, + BatchProof, BatchProvingTask, BlockTrace, BundleProof, BundleProvingTask, ChunkInfo, + ChunkProof, ChunkProvingTask, +}; + // Only used for debugging. -pub(crate) static OUTPUT_DIR: Lazy> = - Lazy::new(|| env::var("PROVER_OUTPUT_DIR").ok()); +static OUTPUT_DIR: Lazy> = Lazy::new(|| env::var("PROVER_OUTPUT_DIR").ok()); -#[derive(Deserialize)] +#[derive(Debug, Clone, Deserialize)] pub struct BatchTaskDetail { - pub chunk_infos: Vec, - pub chunk_proofs: Vec, + pub chunk_infos: Vec, + #[serde(flatten)] + pub batch_proving_task: BatchProvingTask, } -#[derive(Deserialize)] +type BundleTaskDetail = BundleProvingTask; + +#[derive(Debug, Clone, Deserialize)] pub struct ChunkTaskDetail { pub block_hashes: Vec, } @@ -30,44 +39,44 @@ fn get_block_number(block_trace: &BlockTrace) -> Option { block_trace.header.number.map(|n| n.as_u64()) } -pub struct BaseCircuitsHandler { +#[derive(Default)] +pub struct DarwinHandler { chunk_prover: Option>, batch_prover: Option>, geth_client: Option>>, } -impl BaseCircuitsHandler { +impl DarwinHandler { pub fn new( - proof_type: ProofType, + prover_type: ProverType, params_dir: &str, assets_dir: &str, geth_client: Option>>, ) -> Result { - match proof_type { - ProofType::Chunk => Ok(Self { + match prover_type { + ProverType::Chunk => Ok(Self { chunk_prover: Some(RefCell::new(ChunkProver::from_dirs(params_dir, assets_dir))), batch_prover: None, geth_client, }), - ProofType::Batch => Ok(Self { + ProverType::Batch => Ok(Self { batch_prover: Some(RefCell::new(BatchProver::from_dirs(params_dir, assets_dir))), chunk_prover: None, geth_client, }), - _ => bail!("proof type invalid"), } } fn gen_chunk_proof_raw(&self, chunk_trace: Vec) -> Result { if let Some(prover) = self.chunk_prover.as_ref() { - let chunk_proof = prover.borrow_mut().gen_chunk_proof( - chunk_trace, - None, - None, - self.get_output_dir(), - )?; + 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); } @@ -80,22 +89,26 @@ impl BaseCircuitsHandler { Ok(serde_json::to_string(&chunk_proof)?) } - fn gen_batch_proof_raw( - &self, - chunk_hashes_proofs: Vec<(ChunkHash, ChunkProof)>, - ) -> Result { + 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_chunk_proofs(&chunk_proofs); + let is_valid = prover.borrow_mut().check_protocol_of_chunks(&chunk_proofs); if !is_valid { bail!("non-match chunk protocol") } - - let batch_proof = prover.borrow_mut().gen_agg_evm_proof( - chunk_hashes_proofs, + 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(), )?; @@ -107,12 +120,32 @@ impl BaseCircuitsHandler { fn gen_batch_proof(&self, task: &crate::types::Task) -> Result { log::info!("[circuit] gen_batch_proof for task {}", task.id); - let chunk_hashes_proofs: Vec<(ChunkHash, ChunkProof)> = - self.gen_chunk_hashes_proofs(task)?; - let batch_proof = self.gen_batch_proof_raw(chunk_hashes_proofs)?; + + 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() } @@ -122,17 +155,6 @@ impl BaseCircuitsHandler { self.get_sorted_traces_by_hashes(&chunk_task_detail.block_hashes) } - fn gen_chunk_hashes_proofs(&self, task: &Task) -> Result> { - let batch_task_detail: BatchTaskDetail = serde_json::from_str(&task.task_data)?; - - Ok(batch_task_detail - .chunk_infos - .clone() - .into_iter() - .zip(batch_task_detail.chunk_proofs.clone()) - .collect()) - } - 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"); @@ -187,25 +209,30 @@ impl BaseCircuitsHandler { } } -impl CircuitsHandler for BaseCircuitsHandler { - fn get_vk(&self, task_type: ProofType) -> Option> { +impl CircuitsHandler for DarwinHandler { + fn get_vk(&self, task_type: TaskType) -> Option> { match task_type { - ProofType::Chunk => self + TaskType::Chunk => self .chunk_prover .as_ref() .and_then(|prover| prover.borrow().get_vk()), - ProofType::Batch => self + TaskType::Batch => self .batch_prover .as_ref() - .and_then(|prover| prover.borrow().get_vk()), + .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: ProofType, task: &crate::types::Task) -> Result { + fn get_proof_data(&self, task_type: TaskType, task: &crate::types::Task) -> Result { match task_type { - ProofType::Chunk => self.gen_chunk_proof(task), - ProofType::Batch => self.gen_batch_proof(task), + TaskType::Chunk => self.gen_chunk_proof(task), + TaskType::Batch => self.gen_batch_proof(task), + TaskType::Bundle => self.gen_bundle_proof(task), _ => unreachable!(), } } @@ -217,7 +244,7 @@ impl CircuitsHandler for BaseCircuitsHandler { mod tests { use super::*; use crate::zk_circuits_handler::utils::encode_vk; - use prover::utils::chunk_trace_to_witness_block; + use prover_darwin::utils::chunk_trace_to_witness_block; use std::{path::PathBuf, sync::LazyLock}; #[ctor::ctor] @@ -228,7 +255,7 @@ mod tests { static DEFAULT_WORK_DIR: &str = "/assets"; static WORK_DIR: LazyLock = LazyLock::new(|| { - std::env::var("BERNOULLI_TEST_DIR") + std::env::var("CURIE_TEST_DIR") .unwrap_or(String::from(DEFAULT_WORK_DIR)) .trim_end_matches('/') .to_string() @@ -253,11 +280,11 @@ mod tests { #[test] fn test_circuits() -> Result<()> { let chunk_handler = - BaseCircuitsHandler::new(ProofType::Chunk, &PARAMS_PATH, &ASSETS_PATH, None)?; + DarwinHandler::new(ProverType::Chunk, &PARAMS_PATH, &ASSETS_PATH, None)?; - let chunk_vk = chunk_handler.get_vk(ProofType::Chunk).unwrap(); + let chunk_vk = chunk_handler.get_vk(TaskType::Chunk).unwrap(); - check_vk(ProofType::Chunk, chunk_vk, "chunk vk must be available"); + 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![]; @@ -278,30 +305,44 @@ mod tests { } let batch_handler = - BaseCircuitsHandler::new(ProofType::Batch, &PARAMS_PATH, &ASSETS_PATH, None)?; - let batch_vk = batch_handler.get_vk(ProofType::Batch).unwrap(); - check_vk(ProofType::Batch, batch_vk, "batch vk must be available"); - let chunk_hashes_proofs = chunk_infos.into_iter().zip(chunk_proofs).collect(); + DarwinHandler::new(ProverType::Batch, &PARAMS_PATH, &ASSETS_PATH, None)?; + 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(chunk_hashes_proofs)?; + 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 check_vk(proof_type: ProofType, vk: Vec, info: &str) { + 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: ProofType) -> Result { + fn read_vk(proof_type: TaskType) -> Result { log::info!("read_vk, {:?}", proof_type); let vk_file = match proof_type { - ProofType::Chunk => CHUNK_VK_PATH.clone(), - ProofType::Batch => BATCH_VK_PATH.clone(), - ProofType::Undefined => unreachable!(), + 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)?; @@ -375,9 +416,9 @@ mod tests { Ok(files.into_iter().map(|f| batch_path.join(f)).collect()) } - fn traces_to_chunk_info(chunk_trace: Vec) -> Result { + fn traces_to_chunk_info(chunk_trace: Vec) -> Result { let witness_block = chunk_trace_to_witness_block(chunk_trace)?; - Ok(ChunkHash::from_witness_block(&witness_block, false)) + Ok(ChunkInfo::from_witness_block(&witness_block, false)) } fn dump_proof(id: String, proof_data: String) -> Result<()> {