Skip to content

Commit

Permalink
Update to most recent SDK version
Browse files Browse the repository at this point in the history
  • Loading branch information
omerfirmak committed Jan 31, 2025
1 parent 0ecbb1b commit 81b17a0
Show file tree
Hide file tree
Showing 10 changed files with 172 additions and 220 deletions.
3 changes: 1 addition & 2 deletions prover/Cargo.lock

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

22 changes: 16 additions & 6 deletions prover/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ edition = "2021"


[patch.crates-io]
ethers-signers = { git = "https://github.com/scroll-tech/ethers-rs.git", branch = "v2.0.7" }
ethers-signers = { git = "https://github.com/scroll-tech/ethers-rs.git", branch = "v2.0.7" }
halo2curves = { git = "https://github.com/scroll-tech/halo2curves", branch = "v0.1.0" }
[patch."https://github.com/privacy-scaling-explorations/halo2.git"]
halo2_proofs = { git = "https://github.com/scroll-tech/halo2.git", branch = "v1.1" }
halo2_proofs = { git = "https://github.com/scroll-tech/halo2.git", branch = "v1.1" }
[patch."https://github.com/privacy-scaling-explorations/poseidon.git"]
poseidon = { git = "https://github.com/scroll-tech/poseidon.git", branch = "main" }
[patch."https://github.com/privacy-scaling-explorations/bls12_381"]
Expand All @@ -28,10 +28,20 @@ futures = "0.3.30"
ethers-core = { git = "https://github.com/scroll-tech/ethers-rs.git", branch = "v2.0.7" }
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.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 = "7f8dca4"}
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 = "aa1a9fa" }
base64 = "0.13.1"
reqwest = { version = "0.12.4", features = ["gzip"] }
reqwest-middleware = "0.3"
Expand Down
26 changes: 5 additions & 21 deletions prover/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,14 @@
mod config;
mod prover;
mod types;
mod utils;
mod zk_circuits_handler;

use clap::{ArgAction, Parser};
use prover::LocalProver;
use prover::{LocalProver, LocalProverConfig};
use scroll_proving_sdk::{
config::Config,
prover::ProverBuilder,
utils::{get_version, init_tracing},
};
use utils::get_prover_type;

#[derive(Parser, Debug)]
#[clap(disable_version_flag = true)]
Expand Down Expand Up @@ -43,23 +40,10 @@ async fn main() -> anyhow::Result<()> {
std::process::exit(0);
}

let cfg: Config = Config::from_file(args.config_file)?;
let mut prover_types = vec![];
cfg.prover.circuit_types.iter().for_each(|circuit_type| {
if let Some(pt) = get_prover_type(*circuit_type) {
if !prover_types.contains(&pt) {
prover_types.push(pt);
}
}
});
let local_prover = LocalProver::new(
cfg.prover
.local
.clone()
.ok_or_else(|| anyhow::anyhow!("Missing local prover configuration"))?,
prover_types,
);
let prover = ProverBuilder::new(cfg)
let cfg = LocalProverConfig::from_file(args.config_file)?;
let sdk_config = cfg.sdk_config.clone();
let local_prover = LocalProver::new(cfg);
let prover = ProverBuilder::new(sdk_config)
.with_proving_service(Box::new(local_prover))
.build()
.await?;
Expand Down
59 changes: 37 additions & 22 deletions prover/src/prover.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
use crate::{
types::ProverType,
utils::get_prover_type,
zk_circuits_handler::{CircuitsHandler, CircuitsHandlerProvider},
};
use anyhow::Result;
use crate::zk_circuits_handler::{CircuitsHandler, CircuitsHandlerProvider};
use anyhow::{anyhow, Result};
use async_trait::async_trait;
use scroll_proving_sdk::{
config::LocalProverConfig,
config::Config as SdkConfig,
prover::{
proving_service::{
GetVkRequest, GetVkResponse, ProveRequest, ProveResponse, QueryTaskRequest,
Expand All @@ -15,15 +11,44 @@ use scroll_proving_sdk::{
ProvingService,
},
};
use serde::{Deserialize, Serialize};
use std::{
fs::File,
sync::{Arc, Mutex},
time::{SystemTime, UNIX_EPOCH},
};
use tokio::{runtime::Handle, sync::RwLock, task::JoinHandle};

#[derive(Clone, Serialize, Deserialize)]
pub struct LocalProverConfig {
pub sdk_config: SdkConfig,
pub high_version_circuit: CircuitConfig,
pub low_version_circuit: CircuitConfig,
}

impl LocalProverConfig {
pub fn from_reader<R>(reader: R) -> Result<Self>
where
R: std::io::Read,
{
serde_json::from_reader(reader).map_err(|e| anyhow!(e))
}

pub fn from_file(file_name: String) -> Result<Self> {
let file = File::open(file_name)?;
Self::from_reader(&file)
}
}

#[derive(Clone, Serialize, Deserialize)]
pub struct CircuitConfig {
pub hard_fork_name: String,
pub params_path: String,
pub assets_path: String,
}

pub struct LocalProver {
config: LocalProverConfig,
prover_types: Vec<ProverType>,
circuits_handler_provider: RwLock<CircuitsHandlerProvider>,
next_task_id: Arc<Mutex<u64>>,
current_task: Arc<Mutex<Option<JoinHandle<Result<String>>>>>,
Expand All @@ -35,20 +60,11 @@ impl ProvingService for LocalProver {
true
}
async fn get_vks(&self, req: GetVkRequest) -> GetVkResponse {
let mut prover_types = vec![];
req.circuit_types.iter().for_each(|circuit_type| {
if let Some(pt) = get_prover_type(*circuit_type) {
if !prover_types.contains(&pt) {
prover_types.push(pt);
}
}
});

let vks = self
.circuits_handler_provider
.read()
.await
.init_vks(&self.config, prover_types)
.init_vks(&self.config, req.proof_types)
.await;
GetVkResponse { vks, error: None }
}
Expand All @@ -57,7 +73,7 @@ impl ProvingService for LocalProver {
.circuits_handler_provider
.write()
.await
.get_circuits_handler(&req.hard_fork_name, self.prover_types.clone())
.get_circuits_handler(&req.hard_fork_name)
.expect("failed to get circuit handler");

match self.do_prove(req, handler).await {
Expand Down Expand Up @@ -114,13 +130,12 @@ impl ProvingService for LocalProver {
}

impl LocalProver {
pub fn new(config: LocalProverConfig, prover_types: Vec<ProverType>) -> Self {
pub fn new(config: LocalProverConfig) -> Self {
let circuits_handler_provider = CircuitsHandlerProvider::new(config.clone())
.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)),
Expand Down Expand Up @@ -150,7 +165,7 @@ impl LocalProver {

Ok(ProveResponse {
task_id: task_id.to_string(),
circuit_type: req.circuit_type,
proof_type: req.proof_type,
circuit_version: req.circuit_version,
hard_fork_name: req.hard_fork_name,
status: TaskStatus::Proving,
Expand Down
40 changes: 0 additions & 40 deletions prover/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,46 +5,6 @@ use scroll_proving_sdk::prover::types::CircuitType;

pub type CommonHash = H256;

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum ProverType {
Chunk,
Batch,
}

impl ProverType {
fn from_u8(v: u8) -> Self {
match v {
1 => ProverType::Chunk,
2 => ProverType::Batch,
_ => {
panic!("invalid prover_type")
}
}
}
}

impl Serialize for ProverType {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
match *self {
ProverType::Chunk => serializer.serialize_u8(1),
ProverType::Batch => serializer.serialize_u8(2),
}
}
}

impl<'de> Deserialize<'de> for ProverType {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
{
let v: u8 = u8::deserialize(deserializer)?;
Ok(ProverType::from_u8(v))
}
}

#[derive(Serialize, Deserialize, Default)]
pub struct Task {
#[serde(rename = "type", default)]
Expand Down
18 changes: 0 additions & 18 deletions prover/src/utils.rs

This file was deleted.

Loading

0 comments on commit 81b17a0

Please sign in to comment.