Compare commits

...

14 Commits

Author SHA1 Message Date
Zhang Zhuo
3868cbf2de clippy 2024-08-27 14:56:12 +08:00
Zhang Zhuo
6369109567 go fmt 2024-08-27 14:50:10 +08:00
Zhang Zhuo
4c86de128f cargo fmt 2024-08-27 14:48:31 +08:00
Zhang Zhuo
772e6f8393 clean 2024-08-27 14:45:20 +08:00
Zhuo Zhang
61da175121 fix build 2024-08-27 14:40:02 +08:00
Zhang Zhuo
b5fddcc231 fix verifier_test.go 2024-08-27 14:33:59 +08:00
Zhang Zhuo
5d9d41699a build 2024-08-27 14:17:17 +08:00
Zhang Zhuo
fcb9f2665f Merge branch 'develop' into fix/coordinator-init-lifetime 2024-08-27 13:58:07 +08:00
lightsing
18df324875 Merge remote-tracking branch 'origin/fix/coordinator-init-lifetime' into fix/coordinator-init-lifetime 2024-08-27 13:57:53 +08:00
lightsing
1fc29c26d7 fix 2024-08-27 13:57:34 +08:00
Zhang Zhuo
a4270cb4a6 Merge branch 'fix/coordinator-init' into fix/coordinator-init-lifetime 2024-08-27 13:57:02 +08:00
Zhang Zhuo
a0b76fa24c tmp 2024-08-27 13:29:32 +08:00
georgehao
a1ab340bcf chore: auto version bump [bot] 2024-08-27 02:46:12 +00:00
Zhang Zhuo
81884aa879 prover: fix loading of degrees 2024-08-27 10:39:40 +08:00
10 changed files with 204 additions and 164 deletions

View File

@@ -29,10 +29,19 @@ func TestFFI(t *testing.T) {
as := assert.New(t)
cfg := &config.VerifierConfig{
MockMode: false,
ParamsPath: *paramsPath,
AssetsPathLo: *assetsPathLo,
AssetsPathHi: *assetsPathHi,
MockMode: false,
LowVersionCircuit: &config.CircuitConfig{
ParamsPath: *paramsPath,
AssetsPath: *assetsPathLo,
ForkName: "darwin",
MinProverVersion: "",
},
HighVersionCircuit: &config.CircuitConfig{
ParamsPath: *paramsPath,
AssetsPath: *assetsPathHi,
ForkName: "darwinV2",
MinProverVersion: "",
},
}
v, err := NewVerifier(cfg)

40
prover/Cargo.lock generated
View File

@@ -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",
@@ -635,7 +635,7 @@ checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c"
[[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 2.0.7 (git+https://github.com/scroll-tech/ethers-rs.git?branch=v2.0.7)",
@@ -660,7 +660,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 2.0.7 (git+https://github.com/scroll-tech/ethers-rs.git?branch=v2.0.7)",
@@ -1310,7 +1310,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 2.0.7 (git+https://github.com/scroll-tech/ethers-rs.git?branch=v2.0.7)",
@@ -1338,7 +1338,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 2.0.7 (git+https://github.com/scroll-tech/ethers-rs.git?branch=v2.0.7)",
@@ -1558,7 +1558,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",
@@ -1571,7 +1571,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",
@@ -1788,7 +1788,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",
@@ -1800,7 +1800,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",
@@ -1823,7 +1823,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.2",
"gobuild",
@@ -1833,7 +1833,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.2",
"gobuild",
@@ -2673,7 +2673,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 2.0.7 (git+https://github.com/scroll-tech/ethers-rs.git?branch=v2.0.7)",
@@ -2688,7 +2688,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 2.0.7 (git+https://github.com/scroll-tech/ethers-rs.git?branch=v2.0.7)",
@@ -2703,7 +2703,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",
@@ -2717,7 +2717,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",
@@ -3309,7 +3309,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",
@@ -3343,7 +3343,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",
@@ -5338,7 +5338,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",
@@ -5380,7 +5380,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",

View File

@@ -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.0", package = "prover", default-features = false, features = ["parallel_syn", "scroll"] }
prover_darwin_v2 = { git = "https://github.com/scroll-tech/zkevm-circuits.git", tag = "v0.13.0", package = "prover", default-features = false, features = ["parallel_syn", "scroll"] }
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"] }
base64 = "0.13.1"
reqwest = { version = "0.12.4", features = ["gzip"] }
reqwest-middleware = "0.3"

View File

@@ -54,13 +54,23 @@ fn start() -> Result<()> {
std::process::exit(-2);
}
let degrees: Vec<u32> = prover_darwin_v2::config::ZKEVM_DEGREES
.iter()
.copied()
.chain(prover_darwin_v2::config::AGG_DEGREES.iter().copied())
.collect();
let params_map = prover_darwin_v2::common::Prover::load_params_map(
&config.high_version_circuit.params_path,
&degrees,
);
let task_cache = Rc::new(TaskCache::new(&config.db_path)?);
let coordinator_listener = Box::new(ClearCacheCoordinatorListener {
task_cache: task_cache.clone(),
});
let prover = Prover::new(&config, coordinator_listener)?;
let prover = Prover::new(&config, &params_map, coordinator_listener)?;
log::info!(
"prover start successfully. name: {}, type: {:?}, publickey: {}, version: {}",
@@ -71,7 +81,6 @@ fn start() -> Result<()> {
);
let task_processor = TaskProcessor::new(&prover, task_cache);
task_processor.start();
Ok(())

View File

@@ -12,19 +12,24 @@ use crate::{
utils::get_task_types,
zk_circuits_handler::{CircuitsHandler, CircuitsHandlerProvider},
};
use halo2_proofs::{halo2curves::bn256::Bn256, poly::kzg::commitment::ParamsKZG};
use super::types::{ProofDetail, Task};
pub struct Prover<'a> {
config: &'a Config,
key_signer: Rc<KeySigner>,
circuits_handler_provider: RefCell<CircuitsHandlerProvider<'a>>,
circuits_handler_provider: RefCell<CircuitsHandlerProvider<'a, 'a>>,
coordinator_client: RefCell<CoordinatorClient<'a>>,
geth_client: Option<Rc<RefCell<GethClient>>>,
}
impl<'a> Prover<'a> {
pub fn new(config: &'a Config, coordinator_listener: Box<dyn Listener>) -> Result<Self> {
pub fn new(
config: &'a Config,
params_map: &'a std::collections::BTreeMap<u32, ParamsKZG<Bn256>>,
coordinator_listener: Box<dyn Listener>,
) -> Result<Self> {
let prover_type = config.prover_type;
let keystore_path = &config.keystore_path;
let keystore_password = &config.keystore_password;
@@ -41,10 +46,11 @@ impl<'a> Prover<'a> {
None
};
let provider = CircuitsHandlerProvider::new(prover_type, config, geth_client.clone())
.context("failed to create circuits handler provider")?;
let provider =
CircuitsHandlerProvider::new(prover_type, config, params_map, geth_client.clone())
.context("failed to create circuits handler provider")?;
let vks = provider.init_vks(prover_type, config, geth_client.clone());
let vks = provider.init_vks(prover_type, config);
let key_signer = Rc::new(KeySigner::new(keystore_path, keystore_password)?);
let coordinator_client =
@@ -97,7 +103,7 @@ impl<'a> Prover<'a> {
pub fn prove_task(&self, task: &Task) -> Result<ProofDetail> {
log::info!("[prover] start to prove_task, task id: {}", task.id);
let handler: Rc<Box<dyn CircuitsHandler>> = self
let handler: Rc<Box<dyn CircuitsHandler + 'a>> = self
.circuits_handler_provider
.borrow_mut()
.get_circuits_handler(&task.hard_fork_name)
@@ -105,7 +111,11 @@ impl<'a> Prover<'a> {
self.do_prove(task, handler)
}
fn do_prove(&self, task: &Task, handler: Rc<Box<dyn CircuitsHandler>>) -> Result<ProofDetail> {
fn do_prove(
&self,
task: &Task,
handler: Rc<Box<dyn CircuitsHandler + 'a>>,
) -> Result<ProofDetail> {
let mut proof_detail = ProofDetail {
id: task.id.clone(),
proof_type: task.task_type,

View File

@@ -2,13 +2,13 @@ use super::{coordinator_client::ProofStatusNotOKError, prover::Prover, task_cach
use anyhow::{Context, Result};
use std::rc::Rc;
pub struct TaskProcessor<'a> {
prover: &'a Prover<'a>,
task_cache: Rc<TaskCache>,
pub struct TaskProcessor<'a, 'b> {
pub prover: &'a Prover<'b>,
pub task_cache: Rc<TaskCache>,
}
impl<'a> TaskProcessor<'a> {
pub fn new(prover: &'a Prover<'a>, task_cache: Rc<TaskCache>) -> Self {
impl<'a, 'b> TaskProcessor<'a, 'b> {
pub fn new(prover: &'a Prover<'b>, task_cache: Rc<TaskCache>) -> Self {
TaskProcessor { prover, task_cache }
}

View File

@@ -10,7 +10,8 @@ use crate::{
use anyhow::{bail, Result};
use darwin::DarwinHandler;
use darwin_v2::DarwinV2Handler;
use std::{cell::RefCell, collections::HashMap, rc::Rc};
use halo2_proofs::{halo2curves::bn256::Bn256, poly::kzg::commitment::ParamsKZG};
use std::{cell::RefCell, collections::BTreeMap, rc::Rc};
type HardForkName = String;
@@ -26,82 +27,57 @@ pub trait CircuitsHandler {
fn get_proof_data(&self, task_type: TaskType, task: &Task) -> Result<String>;
}
type CircuitsHandlerBuilder = fn(
prover_type: ProverType,
config: &Config,
geth_client: Option<Rc<RefCell<GethClient>>>,
) -> Result<Box<dyn CircuitsHandler>>;
pub struct CircuitsHandlerProvider<'a> {
pub struct CircuitsHandlerProvider<'a, 'b> {
prover_type: ProverType,
config: &'a Config,
geth_client: Option<Rc<RefCell<GethClient>>>,
circuits_handler_builder_map: HashMap<HardForkName, CircuitsHandlerBuilder>,
params_map: &'b BTreeMap<u32, ParamsKZG<Bn256>>,
current_fork_name: Option<HardForkName>,
current_circuit: Option<Rc<Box<dyn CircuitsHandler>>>,
current_circuit: Option<Rc<Box<dyn CircuitsHandler + 'b>>>,
}
impl<'a> CircuitsHandlerProvider<'a> {
impl<'a, 'b> CircuitsHandlerProvider<'a, 'b> {
fn handler_builder(&self) -> Result<Box<dyn CircuitsHandler + 'b>> {
log::info!(
"now init zk circuits handler, hard_fork_name: {}",
&self.config.low_version_circuit.hard_fork_name
);
AssetsDirEnvConfig::enable_first();
DarwinHandler::new(
self.prover_type,
self.params_map,
&self.config.low_version_circuit.assets_path,
self.geth_client.clone(),
)
.map(move |handler| Box::new(handler) as Box<dyn CircuitsHandler + 'b>)
}
fn next_handler_builder(&self) -> Result<Box<dyn CircuitsHandler + 'b>> {
log::info!(
"now init zk circuits handler, hard_fork_name: {}",
&self.config.high_version_circuit.hard_fork_name
);
AssetsDirEnvConfig::enable_second();
DarwinV2Handler::new(
self.prover_type,
self.params_map,
&self.config.high_version_circuit.assets_path,
self.geth_client.clone(),
)
.map(move |handler| Box::new(handler) as Box<dyn CircuitsHandler + 'b>)
}
pub fn new(
prover_type: ProverType,
config: &'a Config,
params_map: &'b BTreeMap<u32, ParamsKZG<Bn256>>,
geth_client: Option<Rc<RefCell<GethClient>>>,
) -> Result<Self> {
let mut m: HashMap<HardForkName, CircuitsHandlerBuilder> = HashMap::new();
fn handler_builder(
prover_type: ProverType,
config: &Config,
geth_client: Option<Rc<RefCell<GethClient>>>,
) -> Result<Box<dyn CircuitsHandler>> {
log::info!(
"now init zk circuits handler, hard_fork_name: {}",
&config.low_version_circuit.hard_fork_name
);
AssetsDirEnvConfig::enable_first();
DarwinHandler::new(
prover_type,
&config.low_version_circuit.params_path,
&config.low_version_circuit.assets_path,
geth_client,
)
.map(|handler| Box::new(handler) as Box<dyn CircuitsHandler>)
}
m.insert(
config.low_version_circuit.hard_fork_name.clone(),
handler_builder,
);
fn next_handler_builder(
prover_type: ProverType,
config: &Config,
geth_client: Option<Rc<RefCell<GethClient>>>,
) -> Result<Box<dyn CircuitsHandler>> {
log::info!(
"now init zk circuits handler, hard_fork_name: {}",
&config.high_version_circuit.hard_fork_name
);
AssetsDirEnvConfig::enable_second();
DarwinV2Handler::new(
prover_type,
&config.high_version_circuit.params_path,
&config.high_version_circuit.assets_path,
geth_client,
)
.map(|handler| Box::new(handler) as Box<dyn CircuitsHandler>)
}
m.insert(
config.high_version_circuit.hard_fork_name.clone(),
next_handler_builder,
);
let provider = CircuitsHandlerProvider {
prover_type,
config,
geth_client,
circuits_handler_builder_map: m,
params_map,
current_fork_name: None,
current_circuit: None,
};
@@ -112,7 +88,7 @@ impl<'a> CircuitsHandlerProvider<'a> {
pub fn get_circuits_handler(
&mut self,
hard_fork_name: &String,
) -> Result<Rc<Box<dyn CircuitsHandler>>> {
) -> Result<Rc<Box<dyn CircuitsHandler + 'b>>> {
match &self.current_fork_name {
Some(fork_name) if fork_name == hard_fork_name => {
log::info!("get circuits handler from cache");
@@ -126,48 +102,62 @@ impl<'a> CircuitsHandlerProvider<'a> {
log::info!(
"failed to get circuits handler from cache, create a new one: {hard_fork_name}"
);
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.prover_type, self.config, self.geth_client.clone())
.expect("failed to build circuits handler");
self.current_fork_name = Some(hard_fork_name.clone());
let rc_handler = Rc::new(handler);
self.current_circuit = Some(rc_handler.clone());
Ok(rc_handler)
} else {
if ![
&self.config.high_version_circuit.hard_fork_name,
&self.config.low_version_circuit.hard_fork_name,
]
.contains(&hard_fork_name)
{
bail!("missing builder, there must be something wrong.")
}
log::info!("building circuits handler for {hard_fork_name}");
self.current_fork_name = Some(hard_fork_name.clone());
let handler = if hard_fork_name == &self.config.high_version_circuit.hard_fork_name
{
self.handler_builder()
.expect("failed to build circuits handler")
} else {
self.next_handler_builder()
.expect("failed to build circuits handler")
};
let rc_handler = Rc::new(handler);
self.current_circuit = Some(rc_handler.clone());
Ok(rc_handler)
}
}
}
pub fn init_vks(
&self,
prover_type: ProverType,
config: &'a Config,
geth_client: Option<Rc<RefCell<GethClient>>>,
) -> Vec<String> {
self.circuits_handler_builder_map
.iter()
.flat_map(|(hard_fork_name, build)| {
let handler = build(prover_type, config, geth_client.clone())
.expect("failed to build circuits handler");
pub fn init_vks(&self, prover_type: ProverType, config: &'a Config) -> Vec<String> {
[
&config.low_version_circuit.hard_fork_name,
&config.high_version_circuit.hard_fork_name,
]
.into_iter()
.flat_map(|hard_fork_name| {
let handler = if hard_fork_name == &self.config.high_version_circuit.hard_fork_name {
self.handler_builder()
.expect("failed to build circuits handler")
} else {
self.next_handler_builder()
.expect("failed to build circuits handler")
};
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
})
.filter(|vk| !vk.is_empty())
.collect::<Vec<String>>()
})
.collect::<Vec<String>>()
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
})
.filter(|vk| !vk.is_empty())
.collect::<Vec<String>>()
})
.collect::<Vec<String>>()
}
}

View File

@@ -4,11 +4,12 @@ use crate::{
types::{ProverType, TaskType},
};
use anyhow::{bail, Context, Ok, Result};
use halo2_proofs::{halo2curves::bn256::Bn256, poly::kzg::commitment::ParamsKZG};
use once_cell::sync::Lazy;
use serde::Deserialize;
use crate::types::{CommonHash, Task};
use std::{cell::RefCell, cmp::Ordering, env, rc::Rc};
use std::{cell::RefCell, cmp::Ordering, collections::BTreeMap, env, rc::Rc};
use prover_darwin::{
aggregator::Prover as BatchProver, check_chunk_hashes, zkevm::Prover as ChunkProver,
@@ -38,29 +39,33 @@ fn get_block_number(block_trace: &BlockTrace) -> Option<u64> {
}
#[derive(Default)]
pub struct DarwinHandler {
chunk_prover: Option<RefCell<ChunkProver>>,
batch_prover: Option<RefCell<BatchProver>>,
pub struct DarwinHandler<'a> {
chunk_prover: Option<RefCell<ChunkProver<'a>>>,
batch_prover: Option<RefCell<BatchProver<'a>>>,
geth_client: Option<Rc<RefCell<GethClient>>>,
}
impl DarwinHandler {
impl<'a> DarwinHandler<'a> {
pub fn new(
prover_type: ProverType,
params_dir: &str,
params_map: &'a BTreeMap<u32, ParamsKZG<Bn256>>,
assets_dir: &str,
geth_client: Option<Rc<RefCell<GethClient>>>,
) -> Result<Self> {
match prover_type {
ProverType::Chunk => Ok(Self {
chunk_prover: Some(RefCell::new(ChunkProver::from_dirs(params_dir, assets_dir))),
chunk_prover: Some(RefCell::new(ChunkProver::from_params_and_assets(
params_map, assets_dir,
))),
batch_prover: None,
geth_client,
}),
ProverType::Batch => Ok(Self {
batch_prover: Some(RefCell::new(BatchProver::from_dirs(params_dir, assets_dir))),
batch_prover: Some(RefCell::new(BatchProver::from_params_and_assets(
params_map, assets_dir,
))),
chunk_prover: None,
geth_client,
}),
@@ -207,7 +212,7 @@ impl DarwinHandler {
}
}
impl CircuitsHandler for DarwinHandler {
impl<'a> CircuitsHandler for DarwinHandler<'a> {
fn get_vk(&self, task_type: TaskType) -> Option<Vec<u8>> {
match task_type {
TaskType::Chunk => self
@@ -277,8 +282,14 @@ mod tests {
#[test]
fn test_circuits() -> Result<()> {
let chunk_handler =
DarwinHandler::new(ProverType::Chunk, &PARAMS_PATH, &ASSETS_PATH, None)?;
let degrees: Vec<u32> = prover_darwin_v2::config::ZKEVM_DEGREES
.iter()
.copied()
.chain(prover_darwin_v2::config::AGG_DEGREES.iter().copied())
.collect();
let params_map = prover_darwin_v2::common::Prover::load_params_map(&PARAMS_PATH, &degrees);
let chunk_handler = DarwinHandler::new(ProverType::Chunk, &params_map, &ASSETS_PATH, None)?;
let chunk_vk = chunk_handler.get_vk(TaskType::Chunk).unwrap();
@@ -302,8 +313,7 @@ mod tests {
chunk_proofs.push(chunk_proof);
}
let batch_handler =
DarwinHandler::new(ProverType::Batch, &PARAMS_PATH, &ASSETS_PATH, None)?;
let batch_handler = DarwinHandler::new(ProverType::Batch, &params_map, &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);

View File

@@ -4,11 +4,12 @@ use crate::{
types::{ProverType, TaskType},
};
use anyhow::{bail, Context, Ok, Result};
use halo2_proofs::{halo2curves::bn256::Bn256, poly::kzg::commitment::ParamsKZG};
use once_cell::sync::Lazy;
use serde::Deserialize;
use crate::types::{CommonHash, Task};
use std::{cell::RefCell, cmp::Ordering, env, rc::Rc};
use std::{cell::RefCell, cmp::Ordering, collections::BTreeMap, env, rc::Rc};
use prover_darwin_v2::{
aggregator::Prover as BatchProver, check_chunk_hashes, zkevm::Prover as ChunkProver,
@@ -38,29 +39,33 @@ fn get_block_number(block_trace: &BlockTrace) -> Option<u64> {
}
#[derive(Default)]
pub struct DarwinV2Handler {
chunk_prover: Option<RefCell<ChunkProver>>,
batch_prover: Option<RefCell<BatchProver>>,
pub struct DarwinV2Handler<'a> {
chunk_prover: Option<RefCell<ChunkProver<'a>>>,
batch_prover: Option<RefCell<BatchProver<'a>>>,
geth_client: Option<Rc<RefCell<GethClient>>>,
}
impl DarwinV2Handler {
impl<'a> DarwinV2Handler<'a> {
pub fn new(
prover_type: ProverType,
params_dir: &str,
params_map: &'a BTreeMap<u32, ParamsKZG<Bn256>>,
assets_dir: &str,
geth_client: Option<Rc<RefCell<GethClient>>>,
) -> Result<Self> {
match prover_type {
ProverType::Chunk => Ok(Self {
chunk_prover: Some(RefCell::new(ChunkProver::from_dirs(params_dir, assets_dir))),
chunk_prover: Some(RefCell::new(ChunkProver::from_params_and_assets(
params_map, assets_dir,
))),
batch_prover: None,
geth_client,
}),
ProverType::Batch => Ok(Self {
batch_prover: Some(RefCell::new(BatchProver::from_dirs(params_dir, assets_dir))),
batch_prover: Some(RefCell::new(BatchProver::from_params_and_assets(
params_map, assets_dir,
))),
chunk_prover: None,
geth_client,
}),
@@ -207,7 +212,7 @@ impl DarwinV2Handler {
}
}
impl CircuitsHandler for DarwinV2Handler {
impl<'a> CircuitsHandler for DarwinV2Handler<'a> {
fn get_vk(&self, task_type: TaskType) -> Option<Vec<u8>> {
match task_type {
TaskType::Chunk => self
@@ -281,8 +286,14 @@ mod tests {
#[test]
fn test_circuits() -> Result<()> {
let degrees: Vec<u32> = prover_darwin_v2::config::ZKEVM_DEGREES
.iter()
.copied()
.chain(prover_darwin_v2::config::AGG_DEGREES.iter().copied())
.collect();
let params_map = prover_darwin_v2::common::Prover::load_params_map(&PARAMS_PATH, &degrees);
let chunk_handler =
DarwinV2Handler::new(ProverType::Chunk, &PARAMS_PATH, &ASSETS_PATH, None)?;
DarwinV2Handler::new(ProverType::Chunk, &params_map, &ASSETS_PATH, None)?;
let chunk_vk = chunk_handler.get_vk(TaskType::Chunk).unwrap();
@@ -308,7 +319,7 @@ mod tests {
}
let batch_handler =
DarwinV2Handler::new(ProverType::Batch, &PARAMS_PATH, &ASSETS_PATH, None)?;
DarwinV2Handler::new(ProverType::Batch, &params_map, &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_traces, chunk_proofs, None);

View File

@@ -15,10 +15,11 @@ import (
"scroll-tech/common/testcontainers"
"scroll-tech/common/utils"
"scroll-tech/common/version"
capp "scroll-tech/coordinator/cmd/api/app"
"scroll-tech/database/migrate"
"scroll-tech/integration-test/orm"
capp "scroll-tech/coordinator/cmd/api/app"
bcmd "scroll-tech/rollup/cmd"
)