Skip to content

Commit

Permalink
feat(prover): use params map to initialize provers (#1507)
Browse files Browse the repository at this point in the history
Co-authored-by: amoylan2 <[email protected]>
  • Loading branch information
amoylan2 and amoylan2 authored Aug 27, 2024
1 parent 7f86aec commit 865d65a
Show file tree
Hide file tree
Showing 8 changed files with 116 additions and 37 deletions.
2 changes: 1 addition & 1 deletion common/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"runtime/debug"
)

var tag = "v4.4.51"
var tag = "v4.4.52"

var commit = func() string {
if info, ok := debug.ReadBuildInfo(); ok {
Expand Down
40 changes: 20 additions & 20 deletions prover/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions prover/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions prover/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#![feature(lazy_cell)]
#![feature(core_intrinsics)]

mod config;
mod coordinator_client;
Expand Down
1 change: 1 addition & 0 deletions prover/src/zk_circuits_handler.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
mod common;
mod darwin;
mod darwin_v2;

Expand Down
19 changes: 19 additions & 0 deletions prover/src/zk_circuits_handler/common.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
use std::{collections::BTreeMap, rc::Rc};

use once_cell::sync::OnceCell;

use halo2_proofs::{halo2curves::bn256::Bn256, poly::kzg::commitment::ParamsKZG};

static mut PARAMS_MAP: OnceCell<Rc<BTreeMap<u32, ParamsKZG<Bn256>>>> = OnceCell::new();

pub fn get_params_map<'a, F>(load_params_func: F) -> &'a BTreeMap<u32, ParamsKZG<Bn256>>
where
F: FnOnce() -> BTreeMap<u32, ParamsKZG<Bn256>>,
{
unsafe {
PARAMS_MAP.get_or_init(|| {
let params_map = load_params_func();
Rc::new(params_map)
})
}
}
43 changes: 36 additions & 7 deletions prover/src/zk_circuits_handler/darwin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ use crate::types::{CommonHash, Task};
use std::{cell::RefCell, cmp::Ordering, env, rc::Rc};

use prover_darwin::{
aggregator::Prover as BatchProver, check_chunk_hashes, zkevm::Prover as ChunkProver,
BatchProof, BatchProvingTask, BlockTrace, BundleProof, BundleProvingTask, ChunkInfo,
ChunkProof, ChunkProvingTask,
aggregator::Prover as BatchProver, check_chunk_hashes, common::Prover as CommonProver,
zkevm::Prover as ChunkProver, BatchProof, BatchProvingTask, BlockTrace, BundleProof,
BundleProvingTask, ChunkInfo, ChunkProof, ChunkProvingTask,
};

// Only used for debugging.
Expand All @@ -39,8 +39,8 @@ fn get_block_number(block_trace: &BlockTrace) -> Option<u64> {

#[derive(Default)]
pub struct DarwinHandler {
chunk_prover: Option<RefCell<ChunkProver>>,
batch_prover: Option<RefCell<BatchProver>>,
chunk_prover: Option<RefCell<ChunkProver<'static>>>,
batch_prover: Option<RefCell<BatchProver<'static>>>,

geth_client: Option<Rc<RefCell<GethClient>>>,
}
Expand All @@ -52,15 +52,44 @@ impl DarwinHandler {
assets_dir: &str,
geth_client: Option<Rc<RefCell<GethClient>>>,
) -> Result<Self> {
let class_name = std::intrinsics::type_name::<Self>();
match prover_type {
ProverType::Chunk => Ok(Self {
chunk_prover: Some(RefCell::new(ChunkProver::from_dirs(params_dir, assets_dir))),
chunk_prover: {
let degrees = prover_darwin::config::ZKEVM_DEGREES.clone();
let params_map = super::common::get_params_map(|| {
log::info!(
"calling get_params_map from {}, prover_type: {:?}, degrees: {:?}",
class_name,
prover_type,
degrees
);
CommonProver::load_params_map(params_dir, &degrees)
});
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: {
let degrees = prover_darwin::config::AGG_DEGREES.clone();
let params_map = super::common::get_params_map(|| {
log::info!(
"calling get_params_map from {}, prover_type: {:?}, degrees: {:?}",
class_name,
prover_type,
degrees
);
CommonProver::load_params_map(params_dir, &degrees)
});
Some(RefCell::new(BatchProver::from_params_and_assets(
params_map, assets_dir,
)))
},
chunk_prover: None,
geth_client,
}),
Expand Down
43 changes: 36 additions & 7 deletions prover/src/zk_circuits_handler/darwin_v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ use crate::types::{CommonHash, Task};
use std::{cell::RefCell, cmp::Ordering, env, rc::Rc};

use prover_darwin_v2::{
aggregator::Prover as BatchProver, check_chunk_hashes, zkevm::Prover as ChunkProver,
BatchProof, BatchProvingTask, BlockTrace, BundleProof, BundleProvingTask, ChunkInfo,
ChunkProof, ChunkProvingTask,
aggregator::Prover as BatchProver, check_chunk_hashes, common::Prover as CommonProver,
zkevm::Prover as ChunkProver, BatchProof, BatchProvingTask, BlockTrace, BundleProof,
BundleProvingTask, ChunkInfo, ChunkProof, ChunkProvingTask,
};

// Only used for debugging.
Expand All @@ -39,8 +39,8 @@ fn get_block_number(block_trace: &BlockTrace) -> Option<u64> {

#[derive(Default)]
pub struct DarwinV2Handler {
chunk_prover: Option<RefCell<ChunkProver>>,
batch_prover: Option<RefCell<BatchProver>>,
chunk_prover: Option<RefCell<ChunkProver<'static>>>,
batch_prover: Option<RefCell<BatchProver<'static>>>,

geth_client: Option<Rc<RefCell<GethClient>>>,
}
Expand All @@ -52,15 +52,44 @@ impl DarwinV2Handler {
assets_dir: &str,
geth_client: Option<Rc<RefCell<GethClient>>>,
) -> Result<Self> {
let class_name = std::intrinsics::type_name::<Self>();
match prover_type {
ProverType::Chunk => Ok(Self {
chunk_prover: Some(RefCell::new(ChunkProver::from_dirs(params_dir, assets_dir))),
chunk_prover: {
let degrees = prover_darwin_v2::config::ZKEVM_DEGREES.clone();
let params_map = super::common::get_params_map(|| {
log::info!(
"calling get_params_map from {}, prover_type: {:?}, degrees: {:?}",
class_name,
prover_type,
degrees
);
CommonProver::load_params_map(params_dir, &degrees)
});
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: {
let degrees = prover_darwin_v2::config::AGG_DEGREES.clone();
let params_map = super::common::get_params_map(|| {
log::info!(
"calling get_params_map from {}, prover_type: {:?}, degrees: {:?}",
class_name,
prover_type,
degrees
);
CommonProver::load_params_map(params_dir, &degrees)
});
Some(RefCell::new(BatchProver::from_params_and_assets(
params_map, assets_dir,
)))
},
chunk_prover: None,
geth_client,
}),
Expand Down

0 comments on commit 865d65a

Please sign in to comment.