diff --git a/common/libzkp/impl/Cargo.lock b/common/libzkp/impl/Cargo.lock index 2df231e2b..87d448379 100644 --- a/common/libzkp/impl/Cargo.lock +++ b/common/libzkp/impl/Cargo.lock @@ -31,7 +31,7 @@ dependencies = [ [[package]] name = "aggregator" version = "0.12.0" -source = "git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.12.0#6a1f65a1f99429f3725ef4d6788f5643bb61aa6f" +source = "git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.12.2#6f7b46a3b1ccf9dc448735e8455e1ac6f9e30643" dependencies = [ "ark-std 0.3.0", "bitstream-io", @@ -65,7 +65,7 @@ dependencies = [ [[package]] name = "aggregator" version = "0.13.0" -source = "git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.13.0#cf71a0e324d42f7895363f4f3e8575d79bb7ea97" +source = "git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.13.1#4009e5593f13ba73f64f556011ee5ef47bc4ebf3" dependencies = [ "ark-std 0.3.0", "bitstream-io", @@ -571,7 +571,7 @@ checksum = "a3e2c3daef883ecc1b5d58c15adae93470a91d425f3532ba1695849656af3fc1" [[package]] name = "bus-mapping" version = "0.12.0" -source = "git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.12.0#6a1f65a1f99429f3725ef4d6788f5643bb61aa6f" +source = "git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.12.2#6f7b46a3b1ccf9dc448735e8455e1ac6f9e30643" dependencies = [ "eth-types 0.12.0", "ethers-core", @@ -596,7 +596,7 @@ dependencies = [ [[package]] name = "bus-mapping" version = "0.13.0" -source = "git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.13.0#cf71a0e324d42f7895363f4f3e8575d79bb7ea97" +source = "git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.13.1#4009e5593f13ba73f64f556011ee5ef47bc4ebf3" dependencies = [ "eth-types 0.13.0", "ethers-core", @@ -1183,7 +1183,7 @@ dependencies = [ [[package]] name = "eth-types" version = "0.12.0" -source = "git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.12.0#6a1f65a1f99429f3725ef4d6788f5643bb61aa6f" +source = "git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.12.2#6f7b46a3b1ccf9dc448735e8455e1ac6f9e30643" dependencies = [ "base64 0.13.1", "ethers-core", @@ -1211,7 +1211,7 @@ dependencies = [ [[package]] name = "eth-types" version = "0.13.0" -source = "git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.13.0#cf71a0e324d42f7895363f4f3e8575d79bb7ea97" +source = "git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.13.1#4009e5593f13ba73f64f556011ee5ef47bc4ebf3" dependencies = [ "base64 0.13.1", "ethers-core", @@ -1367,7 +1367,7 @@ dependencies = [ [[package]] name = "external-tracer" version = "0.12.0" -source = "git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.12.0#6a1f65a1f99429f3725ef4d6788f5643bb61aa6f" +source = "git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.12.2#6f7b46a3b1ccf9dc448735e8455e1ac6f9e30643" dependencies = [ "eth-types 0.12.0", "geth-utils 0.12.0", @@ -1380,7 +1380,7 @@ dependencies = [ [[package]] name = "external-tracer" version = "0.13.0" -source = "git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.13.0#cf71a0e324d42f7895363f4f3e8575d79bb7ea97" +source = "git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.13.1#4009e5593f13ba73f64f556011ee5ef47bc4ebf3" dependencies = [ "eth-types 0.13.0", "geth-utils 0.13.0", @@ -1562,7 +1562,7 @@ dependencies = [ [[package]] name = "gadgets" version = "0.12.0" -source = "git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.12.0#6a1f65a1f99429f3725ef4d6788f5643bb61aa6f" +source = "git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.12.2#6f7b46a3b1ccf9dc448735e8455e1ac6f9e30643" dependencies = [ "eth-types 0.12.0", "halo2_proofs", @@ -1574,7 +1574,7 @@ dependencies = [ [[package]] name = "gadgets" version = "0.13.0" -source = "git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.13.0#cf71a0e324d42f7895363f4f3e8575d79bb7ea97" +source = "git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.13.1#4009e5593f13ba73f64f556011ee5ef47bc4ebf3" dependencies = [ "eth-types 0.13.0", "halo2_proofs", @@ -1597,7 +1597,7 @@ dependencies = [ [[package]] name = "geth-utils" version = "0.12.0" -source = "git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.12.0#6a1f65a1f99429f3725ef4d6788f5643bb61aa6f" +source = "git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.12.2#6f7b46a3b1ccf9dc448735e8455e1ac6f9e30643" dependencies = [ "env_logger 0.10.0", "gobuild", @@ -1607,7 +1607,7 @@ dependencies = [ [[package]] name = "geth-utils" version = "0.13.0" -source = "git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.13.0#cf71a0e324d42f7895363f4f3e8575d79bb7ea97" +source = "git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.13.1#4009e5593f13ba73f64f556011ee5ef47bc4ebf3" dependencies = [ "env_logger 0.10.0", "gobuild", @@ -2356,7 +2356,7 @@ dependencies = [ [[package]] name = "mock" version = "0.12.0" -source = "git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.12.0#6a1f65a1f99429f3725ef4d6788f5643bb61aa6f" +source = "git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.12.2#6f7b46a3b1ccf9dc448735e8455e1ac6f9e30643" dependencies = [ "eth-types 0.12.0", "ethers-core", @@ -2371,7 +2371,7 @@ dependencies = [ [[package]] name = "mock" version = "0.13.0" -source = "git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.13.0#cf71a0e324d42f7895363f4f3e8575d79bb7ea97" +source = "git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.13.1#4009e5593f13ba73f64f556011ee5ef47bc4ebf3" dependencies = [ "eth-types 0.13.0", "ethers-core", @@ -2386,7 +2386,7 @@ dependencies = [ [[package]] name = "mpt-zktrie" version = "0.12.0" -source = "git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.12.0#6a1f65a1f99429f3725ef4d6788f5643bb61aa6f" +source = "git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.12.2#6f7b46a3b1ccf9dc448735e8455e1ac6f9e30643" dependencies = [ "eth-types 0.12.0", "halo2curves", @@ -2400,7 +2400,7 @@ dependencies = [ [[package]] name = "mpt-zktrie" version = "0.13.0" -source = "git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.13.0#cf71a0e324d42f7895363f4f3e8575d79bb7ea97" +source = "git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.13.1#4009e5593f13ba73f64f556011ee5ef47bc4ebf3" dependencies = [ "eth-types 0.13.0", "halo2curves", @@ -2872,7 +2872,7 @@ dependencies = [ [[package]] name = "prover" version = "0.12.0" -source = "git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.12.0#6a1f65a1f99429f3725ef4d6788f5643bb61aa6f" +source = "git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.12.2#6f7b46a3b1ccf9dc448735e8455e1ac6f9e30643" dependencies = [ "aggregator 0.12.0", "anyhow", @@ -2906,7 +2906,7 @@ dependencies = [ [[package]] name = "prover" version = "0.13.0" -source = "git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.13.0#cf71a0e324d42f7895363f4f3e8575d79bb7ea97" +source = "git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.13.1#4009e5593f13ba73f64f556011ee5ef47bc4ebf3" dependencies = [ "aggregator 0.13.0", "anyhow", @@ -4543,7 +4543,7 @@ dependencies = [ [[package]] name = "zkevm-circuits" version = "0.12.0" -source = "git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.12.0#6a1f65a1f99429f3725ef4d6788f5643bb61aa6f" +source = "git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.12.2#6f7b46a3b1ccf9dc448735e8455e1ac6f9e30643" dependencies = [ "array-init", "bus-mapping 0.12.0", @@ -4585,7 +4585,7 @@ dependencies = [ [[package]] name = "zkevm-circuits" version = "0.13.0" -source = "git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.13.0#cf71a0e324d42f7895363f4f3e8575d79bb7ea97" +source = "git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.13.1#4009e5593f13ba73f64f556011ee5ef47bc4ebf3" dependencies = [ "array-init", "bus-mapping 0.13.0", diff --git a/common/libzkp/impl/Cargo.toml b/common/libzkp/impl/Cargo.toml index 6d4447bb5..2d4822f99 100644 --- a/common/libzkp/impl/Cargo.toml +++ b/common/libzkp/impl/Cargo.toml @@ -25,9 +25,9 @@ halo2_proofs = { git = "https://github.com/scroll-tech/halo2.git", branch = "v1. snark-verifier-sdk = { git = "https://github.com/scroll-tech/snark-verifier", branch = "develop", default-features = false, features = ["loader_halo2", "loader_evm", "halo2-pse"] } # darwin -prover_v4 = { git = "https://github.com/scroll-tech/zkevm-circuits.git", tag = "v0.12.0", package = "prover", default-features = false, features = ["parallel_syn", "scroll"] } +prover_v4 = { git = "https://github.com/scroll-tech/zkevm-circuits.git", tag = "v0.12.2", package = "prover", default-features = false, features = ["parallel_syn", "scroll"] } # darwin_v2 -prover_v5 = { git = "https://github.com/scroll-tech/zkevm-circuits.git", tag = "v0.13.0", package = "prover", default-features = false, features = ["parallel_syn", "scroll"] } +prover_v5 = { git = "https://github.com/scroll-tech/zkevm-circuits.git", tag = "v0.13.1", package = "prover", default-features = false, features = ["parallel_syn", "scroll"] } base64 = "0.13.0" env_logger = "0.9.0" diff --git a/common/libzkp/impl/src/verifier.rs b/common/libzkp/impl/src/verifier.rs index 258950634..7cdc7384f 100644 --- a/common/libzkp/impl/src/verifier.rs +++ b/common/libzkp/impl/src/verifier.rs @@ -2,10 +2,12 @@ mod darwin; mod darwin_v2; use anyhow::{bail, Result}; -// use darwin::DarwinVerifier; +use darwin::DarwinVerifier; use darwin_v2::DarwinV2Verifier; +use halo2_proofs::{halo2curves::bn256::Bn256, poly::kzg::commitment::ParamsKZG}; +use prover_v4::utils::load_params; use serde::{Deserialize, Serialize}; -use std::{cell::OnceCell, rc::Rc}; +use std::{cell::OnceCell, collections::BTreeMap, rc::Rc}; #[derive(Debug, Clone, Copy, PartialEq)] pub enum TaskType { @@ -36,22 +38,47 @@ type HardForkName = String; struct VerifierPair(HardForkName, Rc>); static mut VERIFIER_HIGH: OnceCell = OnceCell::new(); -// static mut VERIFIER_LOW: OnceCell = OnceCell::new(); +static mut VERIFIER_LOW: OnceCell = OnceCell::new(); +static mut PARAMS_MAP: OnceCell>> = OnceCell::new(); pub fn init(config: VerifierConfig) { - // let low_conf = config.low_version_circuit; - // let verifier = DarwinVerifier::new(&low_conf.params_path, &low_conf.assets_path); + let low_conf = config.low_version_circuit; - // unsafe { - // VERIFIER_LOW - // .set(VerifierPair( - // low_conf.fork_name, - // Rc::new(Box::new(verifier)), - // )) - // .unwrap_unchecked(); - // } + // params should be shared between low and high + let mut params_map = BTreeMap::new(); + for degree in [ + *prover_v4::config::LAYER2_DEGREE, + *prover_v4::config::LAYER4_DEGREE, + ] { + if let std::collections::btree_map::Entry::Vacant(e) = params_map.entry(degree) { + match load_params(&low_conf.params_path, degree, None) { + Ok(params) => { + e.insert(params); + } + Err(e) => panic!( + "failed to load params, degree {}, dir {}, err {}", + degree, low_conf.params_path, e + ), + } + } + } + unsafe { + PARAMS_MAP.set(params_map).unwrap_unchecked(); + } + + let verifier = DarwinVerifier::new(unsafe { PARAMS_MAP.get().unwrap() }, &low_conf.assets_path); + + unsafe { + VERIFIER_LOW + .set(VerifierPair( + low_conf.fork_name, + Rc::new(Box::new(verifier)), + )) + .unwrap_unchecked(); + } let high_conf = config.high_version_circuit; - let verifier = DarwinV2Verifier::new(&high_conf.params_path, &high_conf.assets_path); + let verifier = + DarwinV2Verifier::new(unsafe { PARAMS_MAP.get().unwrap() }, &high_conf.assets_path); unsafe { VERIFIER_HIGH .set(VerifierPair( @@ -64,7 +91,7 @@ pub fn init(config: VerifierConfig) { pub fn get_verifier(fork_name: &str) -> Result>> { unsafe { - if let Some(verifier) = VERIFIER_HIGH.get() { + if let Some(verifier) = VERIFIER_LOW.get() { if verifier.0 == fork_name { return Ok(verifier.1.clone()); } diff --git a/common/libzkp/impl/src/verifier/darwin.rs b/common/libzkp/impl/src/verifier/darwin.rs index 2b299892f..941b1b33d 100644 --- a/common/libzkp/impl/src/verifier/darwin.rs +++ b/common/libzkp/impl/src/verifier/darwin.rs @@ -1,25 +1,24 @@ use super::{ProofVerifier, TaskType}; use anyhow::Result; +use halo2_proofs::{halo2curves::bn256::Bn256, poly::kzg::commitment::ParamsKZG}; use crate::utils::panic_catch; use prover_v4::{ aggregator::Verifier as AggVerifier, zkevm::Verifier, BatchProof, BundleProof, ChunkProof, }; -use std::env; +use std::{collections::BTreeMap, env}; -pub struct DarwinVerifier { - verifier: Verifier, - agg_verifier: AggVerifier, +pub struct DarwinVerifier<'params> { + verifier: Verifier<'params>, + agg_verifier: AggVerifier<'params>, } -impl DarwinVerifier { - #[allow(dead_code)] - pub fn new(params_dir: &str, assets_dir: &str) -> Self { +impl<'params> DarwinVerifier<'params> { + pub fn new(params_map: &'params BTreeMap>, assets_dir: &str) -> Self { env::set_var("SCROLL_PROVER_ASSETS_DIR", assets_dir); - let verifier = Verifier::from_dirs(params_dir, assets_dir); - - let agg_verifier = AggVerifier::from_dirs(params_dir, assets_dir); + let verifier = Verifier::from_params_and_assets(params_map, assets_dir); + let agg_verifier = AggVerifier::from_params_and_assets(params_map, assets_dir); Self { verifier, @@ -28,7 +27,7 @@ impl DarwinVerifier { } } -impl ProofVerifier for DarwinVerifier { +impl<'params> ProofVerifier for DarwinVerifier<'params> { fn verify(&self, task_type: super::TaskType, proof: Vec) -> Result { let result = panic_catch(|| match task_type { TaskType::Chunk => { diff --git a/common/libzkp/impl/src/verifier/darwin_v2.rs b/common/libzkp/impl/src/verifier/darwin_v2.rs index dadc07589..fa36fce4f 100644 --- a/common/libzkp/impl/src/verifier/darwin_v2.rs +++ b/common/libzkp/impl/src/verifier/darwin_v2.rs @@ -1,24 +1,24 @@ use super::{ProofVerifier, TaskType}; use anyhow::Result; +use halo2_proofs::{halo2curves::bn256::Bn256, poly::kzg::commitment::ParamsKZG}; use crate::utils::panic_catch; use prover_v5::{ aggregator::Verifier as AggVerifier, zkevm::Verifier, BatchProof, BundleProof, ChunkProof, }; -use std::env; +use std::{collections::BTreeMap, env}; -pub struct DarwinV2Verifier { - verifier: Verifier, - agg_verifier: AggVerifier, +pub struct DarwinV2Verifier<'params> { + verifier: Verifier<'params>, + agg_verifier: AggVerifier<'params>, } -impl DarwinV2Verifier { - pub fn new(params_dir: &str, assets_dir: &str) -> Self { +impl<'params> DarwinV2Verifier<'params> { + pub fn new(params_map: &'params BTreeMap>, assets_dir: &str) -> Self { env::set_var("SCROLL_PROVER_ASSETS_DIR", assets_dir); - let verifier = Verifier::from_dirs(params_dir, assets_dir); - - let agg_verifier = AggVerifier::from_dirs(params_dir, assets_dir); + let verifier = Verifier::from_params_and_assets(params_map, assets_dir); + let agg_verifier = AggVerifier::from_params_and_assets(params_map, assets_dir); Self { verifier, @@ -27,7 +27,7 @@ impl DarwinV2Verifier { } } -impl ProofVerifier for DarwinV2Verifier { +impl<'params> ProofVerifier for DarwinV2Verifier<'params> { fn verify(&self, task_type: super::TaskType, proof: Vec) -> Result { let result = panic_catch(|| match task_type { TaskType::Chunk => { diff --git a/common/version/version.go b/common/version/version.go index 7a3e7a5e3..645feee7a 100644 --- a/common/version/version.go +++ b/common/version/version.go @@ -5,7 +5,7 @@ import ( "runtime/debug" ) -var tag = "v4.4.49" +var tag = "v4.4.50" var commit = func() string { if info, ok := debug.ReadBuildInfo(); ok {