Skip to content

Commit

Permalink
fix(prover): support prover with multi types constructor for test code (
Browse files Browse the repository at this point in the history
  • Loading branch information
amoylan2 authored Aug 28, 2024
1 parent fcfd97a commit 5c9243e
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 53 deletions.
17 changes: 13 additions & 4 deletions coordinator/internal/logic/verifier/verifier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion prover/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ impl Default for TaskType {
}
}

#[derive(Debug, Clone, Copy, PartialEq)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum ProverType {
Chunk,
Batch,
Expand Down
62 changes: 39 additions & 23 deletions prover/src/zk_circuits_handler/darwin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,24 @@ pub struct DarwinHandler {
}

impl DarwinHandler {
pub fn new(
prover_type: ProverType,
pub fn new_multi(
prover_types: Vec<ProverType>,
params_dir: &str,
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: {
let prover_types_set = prover_types
.into_iter()
.collect::<std::collections::HashSet<ProverType>>();
let mut handler = Self {
batch_prover: None,
chunk_prover: None,
geth_client,
};
for prover_type in prover_types_set {
match prover_type {
ProverType::Chunk => {
let degrees = prover_darwin::config::ZKEVM_DEGREES.clone();
let params_map = super::common::get_params_map(|| {
log::info!(
Expand All @@ -66,16 +74,12 @@ impl DarwinHandler {
);
CommonProver::load_params_map(params_dir, &degrees)
});
Some(RefCell::new(ChunkProver::from_params_and_assets(
handler.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: {
ProverType::Batch => {
let degrees = prover_darwin::config::AGG_DEGREES.clone();
let params_map = super::common::get_params_map(|| {
log::info!(
Expand All @@ -86,14 +90,22 @@ impl DarwinHandler {
);
CommonProver::load_params_map(params_dir, &degrees)
});
Some(RefCell::new(BatchProver::from_params_and_assets(
handler.batch_prover = Some(RefCell::new(BatchProver::from_params_and_assets(
params_map, assets_dir,
)))
},
chunk_prover: None,
geth_client,
}),
}
}
}
Ok(handler)
}

pub fn new(
prover_type: ProverType,
params_dir: &str,
assets_dir: &str,
geth_client: Option<Rc<RefCell<GethClient>>>,
) -> Result<Self> {
Self::new_multi(vec![prover_type], params_dir, assets_dir, geth_client)
}

fn gen_chunk_proof_raw(&self, chunk_trace: Vec<BlockTrace>) -> Result<ChunkProof> {
Expand Down Expand Up @@ -306,9 +318,14 @@ mod tests {

#[test]
fn test_circuits() -> Result<()> {
let chunk_handler =
DarwinHandler::new(ProverType::Chunk, &PARAMS_PATH, &ASSETS_PATH, None)?;

let bi_handler = DarwinHandler::new_multi(
vec![ProverType::Chunk, ProverType::Batch],
&PARAMS_PATH,
&ASSETS_PATH,
None,
)?;

let chunk_handler = bi_handler;
let chunk_vk = chunk_handler.get_vk(TaskType::Chunk).unwrap();

check_vk(TaskType::Chunk, chunk_vk, "chunk vk must be available");
Expand All @@ -331,8 +348,7 @@ mod tests {
chunk_proofs.push(chunk_proof);
}

let batch_handler =
DarwinHandler::new(ProverType::Batch, &PARAMS_PATH, &ASSETS_PATH, None)?;
let batch_handler = chunk_handler;
let batch_vk = batch_handler.get_vk(TaskType::Batch).unwrap();
check_vk(TaskType::Batch, batch_vk, "batch vk must be available");
let batch_task_detail = make_batch_task_detail(chunk_infos, chunk_proofs);
Expand Down
66 changes: 41 additions & 25 deletions prover/src/zk_circuits_handler/darwin_v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,25 @@ pub struct DarwinV2Handler {
}

impl DarwinV2Handler {
pub fn new(
prover_type: ProverType,
pub fn new_multi(
prover_types: Vec<ProverType>,
params_dir: &str,
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: {
let degrees = prover_darwin_v2::config::ZKEVM_DEGREES.clone();
let prover_types_set = prover_types
.into_iter()
.collect::<std::collections::HashSet<ProverType>>();
let mut handler = Self {
batch_prover: None,
chunk_prover: None,
geth_client,
};
for prover_type in prover_types_set {
match prover_type {
ProverType::Chunk => {
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: {:?}",
Expand All @@ -66,17 +74,13 @@ impl DarwinV2Handler {
);
CommonProver::load_params_map(params_dir, &degrees)
});
Some(RefCell::new(ChunkProver::from_params_and_assets(
handler.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: {
let degrees = prover_darwin_v2::config::AGG_DEGREES.clone();
ProverType::Batch => {
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: {:?}",
Expand All @@ -86,14 +90,22 @@ impl DarwinV2Handler {
);
CommonProver::load_params_map(params_dir, &degrees)
});
Some(RefCell::new(BatchProver::from_params_and_assets(
handler.batch_prover = Some(RefCell::new(BatchProver::from_params_and_assets(
params_map, assets_dir,
)))
},
chunk_prover: None,
geth_client,
}),
}
}
}
Ok(handler)
}

pub fn new(
prover_type: ProverType,
params_dir: &str,
assets_dir: &str,
geth_client: Option<Rc<RefCell<GethClient>>>,
) -> Result<Self> {
Self::new_multi(vec![prover_type], params_dir, assets_dir, geth_client)
}

fn gen_chunk_proof_raw(&self, chunk_trace: Vec<BlockTrace>) -> Result<ChunkProof> {
Expand Down Expand Up @@ -310,9 +322,14 @@ mod tests {

#[test]
fn test_circuits() -> Result<()> {
let chunk_handler =
DarwinV2Handler::new(ProverType::Chunk, &PARAMS_PATH, &ASSETS_PATH, None)?;

let bi_handler = DarwinV2Handler::new_multi(
vec![ProverType::Chunk, ProverType::Batch],
&PARAMS_PATH,
&ASSETS_PATH,
None,
)?;

let chunk_handler = bi_handler;
let chunk_vk = chunk_handler.get_vk(TaskType::Chunk).unwrap();

check_vk(TaskType::Chunk, chunk_vk, "chunk vk must be available");
Expand All @@ -336,8 +353,7 @@ mod tests {
chunk_proofs.push(chunk_proof);
}

let batch_handler =
DarwinV2Handler::new(ProverType::Batch, &PARAMS_PATH, &ASSETS_PATH, None)?;
let batch_handler = chunk_handler;
let batch_vk = batch_handler.get_vk(TaskType::Batch).unwrap();
check_vk(TaskType::Batch, batch_vk, "batch vk must be available");
let batch_task_detail = make_batch_task_detail(chunk_traces, chunk_proofs, None);
Expand Down

0 comments on commit 5c9243e

Please sign in to comment.