Skip to content

Commit

Permalink
Merge branch 'develop' into feat/fix_coordinator_bug
Browse files Browse the repository at this point in the history
  • Loading branch information
colinlyguo authored Aug 28, 2024
2 parents d60dce3 + bf48417 commit 0d03a2b
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 57 deletions.
1 change: 0 additions & 1 deletion build/dockerfiles/bridgehistoryapi-api.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ RUN --mount=target=. \
FROM ubuntu:20.04

ENV CGO_LDFLAGS="-Wl,--no-as-needed -ldl"

COPY --from=builder /bin/bridgehistoryapi-api /bin/
WORKDIR /app
ENTRYPOINT ["bridgehistoryapi-api"]
2 changes: 0 additions & 2 deletions build/dockerfiles/bridgehistoryapi-db-cli.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,5 @@ RUN --mount=target=. \
# Pull db_cli into a second stage deploy alpine container
FROM alpine:latest
COPY --from=builder /bin/db_cli /bin/
RUN apk update && apk add ca-certificates
RUN update-ca-certificates
WORKDIR /app
ENTRYPOINT ["db_cli"]
2 changes: 1 addition & 1 deletion build/dockerfiles/bridgehistoryapi-fetcher.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ RUN --mount=target=. \
FROM ubuntu:20.04

ENV CGO_LDFLAGS="-Wl,--no-as-needed -ldl"
RUN apk update && apk add ca-certificates
RUN apt update && apt install ca-certificates -y
RUN update-ca-certificates
COPY --from=builder /bin/bridgehistoryapi-fetcher /bin/
WORKDIR /app
Expand Down
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 0d03a2b

Please sign in to comment.