Skip to content

Commit

Permalink
fix: comments
Browse files Browse the repository at this point in the history
  • Loading branch information
yiweichi committed Jan 21, 2025
1 parent 215a503 commit 7c57b0a
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 120 deletions.
36 changes: 10 additions & 26 deletions prover/Cargo.lock

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

2 changes: 1 addition & 1 deletion prover/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ 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"] }
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"] }
scroll-proving-sdk = { git = "https://github.com/scroll-tech/scroll-proving-sdk.git", rev = "4ae7687"}
scroll-proving-sdk = { git = "https://github.com/scroll-tech/scroll-proving-sdk.git", rev = "92634c6"}
base64 = "0.13.1"
reqwest = { version = "0.12.4", features = ["gzip"] }
reqwest-middleware = "0.3"
Expand Down
131 changes: 41 additions & 90 deletions prover/src/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::{
utils::get_prover_type,
zk_circuits_handler::{CircuitsHandler, CircuitsHandlerProvider},
};
use anyhow::{Context, Result};
use anyhow::Result;
use async_trait::async_trait;
use scroll_proving_sdk::{
config::LocalProverConfig,
Expand All @@ -12,7 +12,7 @@ use scroll_proving_sdk::{
GetVkRequest, GetVkResponse, ProveRequest, ProveResponse, QueryTaskRequest,
QueryTaskResponse, TaskStatus,
},
CircuitType, ProvingService,
ProvingService,
},
};
use std::{
Expand Down Expand Up @@ -44,12 +44,11 @@ impl ProvingService for LocalProver {
}
});

let local_prover_config = self.config.clone();
let vks = self
.circuits_handler_provider
.read()
.await
.init_vks(&local_prover_config, prover_types)
.init_vks(&self.config, prover_types)
.await;
GetVkResponse { vks, error: None }
}
Expand All @@ -59,74 +58,72 @@ impl ProvingService for LocalProver {
.write()
.await
.get_circuits_handler(&req.hard_fork_name, self.prover_types.clone())
.context("failed to get circuit handler")
.unwrap();
.expect("failed to get circuit handler");

match self.do_prove(req.clone(), handler).await {
Ok(resp) => resp,
Err(e) => build_prove_error_response(
String::new(),
TaskStatus::Failed,
None,
String::from(&format!("failed to request proof: {}", e)),
),
Err(e) => ProveResponse {
status: TaskStatus::Failed,
error: Some(format!("failed to request proof: {}", e)),
..Default::default()
},
}
}

async fn query_task(&self, req: QueryTaskRequest) -> QueryTaskResponse {
let handle = self.current_task.lock().unwrap().take();
if let Some(handle) = handle {
if handle.is_finished() {
match handle.await {
Ok(result) => match result {
Ok(proof) => build_query_task_response(
req.task_id,
TaskStatus::Success,
Some(proof),
None,
),
Err(e) => build_query_task_response(
req.task_id,
TaskStatus::Failed,
None,
Some(format!("proving task failed: {}", e)),
),
return match handle.await {
Ok(Ok(proof)) => QueryTaskResponse {
task_id: req.task_id,
status: TaskStatus::Success,
proof: Some(proof),
..Default::default()
},
Err(e) => build_query_task_response(
req.task_id,
TaskStatus::Failed,
None,
Some(format!("proving task panicked: {}", e)),
),
}
Ok(Err(e)) => QueryTaskResponse {
task_id: req.task_id,
status: TaskStatus::Failed,
error: Some(format!("proving task failed: {}", e)),
..Default::default()
},
Err(e) => QueryTaskResponse {
task_id: req.task_id,
status: TaskStatus::Failed,
error: Some(format!("proving task panicked: {}", e)),
..Default::default()
},
};
} else {
*self.current_task.lock().unwrap() = Some(handle);
build_query_task_response(req.task_id, TaskStatus::Proving, None, None)
return QueryTaskResponse {
task_id: req.task_id,
status: TaskStatus::Proving,
..Default::default()
};
}
} else {
build_query_task_response(
req.task_id,
TaskStatus::Failed,
None,
Some("no proving task is running".to_string()),
)
}
// If no handle is found
QueryTaskResponse {
task_id: req.task_id,
status: TaskStatus::Failed,
error: Some("no proving task is running".to_string()),
..Default::default()
}
}
}

impl LocalProver {
pub fn new(config: LocalProverConfig, prover_types: Vec<ProverType>) -> Self {
let circuits_handler_provider = CircuitsHandlerProvider::new(config.clone())
.context("failed to create circuits handler provider")
.unwrap();
.expect("failed to create circuits handler provider");

Self {
config,
prover_types,
circuits_handler_provider: RwLock::new(circuits_handler_provider),
next_task_id: Arc::new(Mutex::new(0)),
current_task: Arc::new(Mutex::new(None)),
// result: Arc::new(Mutex::new(Err(anyhow::Error::msg("prover not started")))),
}
}

Expand Down Expand Up @@ -168,49 +165,3 @@ impl LocalProver {
})
}
}

fn build_prove_error_response(
task_id: String,
status: TaskStatus,
proof: Option<String>,
error_msg: String,
) -> ProveResponse {
ProveResponse {
task_id,
circuit_type: CircuitType::Undefined, // TODO
circuit_version: "".to_string(),
hard_fork_name: "".to_string(),
status,
created_at: 0.0,
started_at: None,
finished_at: None,
compute_time_sec: None,
input: None,
proof,
vk: None,
error: Some(error_msg),
}
}

fn build_query_task_response(
task_id: String,
status: TaskStatus,
proof: Option<String>,
error_msg: Option<String>,
) -> QueryTaskResponse {
QueryTaskResponse {
task_id,
circuit_type: CircuitType::Undefined, // TODO
circuit_version: "".to_string(),
hard_fork_name: "".to_string(),
status,
created_at: 0.0,
started_at: None,
finished_at: None,
compute_time_sec: None,
input: None,
proof,
vk: None,
error: error_msg,
}
}
5 changes: 2 additions & 3 deletions prover/src/zk_circuits_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ impl CircuitsHandlerProvider {
let mut m: HashMap<HardForkName, CircuitsHandlerBuilder> = HashMap::new();

if let Err(e) = AssetsDirEnvConfig::init() {
log::error!("AssetsDirEnvConfig init failed: {:#}", e);
std::process::exit(-2);
panic!("AssetsDirEnvConfig init failed: {:#}", e);
}

fn handler_builder(
Expand Down Expand Up @@ -140,7 +139,7 @@ impl CircuitsHandlerProvider {
config: &LocalProverConfig,
prover_types: Vec<ProverType>,
) -> Vec<String> {
let mut vks: Vec<String> = Vec::new();
let mut vks = Vec::new();
for (hard_fork_name, build) in self.circuits_handler_builder_map.iter() {
let handler =
build(prover_types.clone(), config).expect("failed to build circuits handler");
Expand Down

0 comments on commit 7c57b0a

Please sign in to comment.