Skip to content

Commit

Permalink
using some std libs instead of thirdparty lib
Browse files Browse the repository at this point in the history
  • Loading branch information
ariesdevil committed Dec 17, 2024
1 parent 45b23ed commit 82fab1a
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 60 deletions.
3 changes: 0 additions & 3 deletions prover/Cargo.lock

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

3 changes: 0 additions & 3 deletions prover/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,16 @@ log = "0.4"
env_logger = "0.11.3"
serde = { version = "1.0.198", features = ["derive"] }
serde_json = "1.0.116"
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"] }
base64 = "0.13.1"
reqwest = { version = "0.12.4", features = ["gzip"] }
reqwest-middleware = "0.3"
reqwest-retry = "0.5"
once_cell = "1.19.0"
hex = "0.4.3"
tiny-keccak = { version = "2.0.0", features = ["sha3", "keccak"] }
rand = "0.8.5"
Expand Down
64 changes: 33 additions & 31 deletions prover/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use crate::types::ProverType;
use anyhow::{bail, Result};
use serde::{Deserialize, Serialize};
use std::fs::File;

use crate::types::ProverType;
use std::{fs::File, sync::OnceLock};

#[derive(Debug, Serialize, Deserialize)]
pub struct CircuitConfig {
Expand Down Expand Up @@ -52,7 +51,7 @@ impl Config {
}

static SCROLL_PROVER_ASSETS_DIR_ENV_NAME: &str = "SCROLL_PROVER_ASSETS_DIR";
static mut SCROLL_PROVER_ASSETS_DIRS: Vec<String> = vec![];
static SCROLL_PROVER_ASSETS_DIRS: OnceLock<Vec<String>> = OnceLock::new();

#[derive(Debug)]
pub struct AssetsDirEnvConfig {}
Expand All @@ -64,39 +63,42 @@ impl AssetsDirEnvConfig {
if dirs.len() != 2 {
bail!("env variable SCROLL_PROVER_ASSETS_DIR value must be 2 parts seperated by comma.")
}
unsafe {
SCROLL_PROVER_ASSETS_DIRS = dirs.into_iter().map(|s| s.to_string()).collect();
log::info!(
"init SCROLL_PROVER_ASSETS_DIRS: {:?}",
SCROLL_PROVER_ASSETS_DIRS
);
}

SCROLL_PROVER_ASSETS_DIRS.get_or_init(|| dirs.into_iter().map(|s| s.to_string()).collect());
log::info!(
"init SCROLL_PROVER_ASSETS_DIRS: {:?}",
SCROLL_PROVER_ASSETS_DIRS
);
Ok(())
}

pub fn enable_first() {
unsafe {
log::info!(
"set env {SCROLL_PROVER_ASSETS_DIR_ENV_NAME} to {}",
&SCROLL_PROVER_ASSETS_DIRS[0]
);
std::env::set_var(
SCROLL_PROVER_ASSETS_DIR_ENV_NAME,
&SCROLL_PROVER_ASSETS_DIRS[0],
);
}
debug_assert!(
SCROLL_PROVER_ASSETS_DIRS.get().is_some()
&& SCROLL_PROVER_ASSETS_DIRS.get().unwrap().len() >= 2
);
log::info!(
"set env {SCROLL_PROVER_ASSETS_DIR_ENV_NAME} to {}",
&SCROLL_PROVER_ASSETS_DIRS.get().unwrap()[0]
);
std::env::set_var(
SCROLL_PROVER_ASSETS_DIR_ENV_NAME,
&SCROLL_PROVER_ASSETS_DIRS.get().unwrap()[0],
);
}

pub fn enable_second() {
unsafe {
log::info!(
"set env {SCROLL_PROVER_ASSETS_DIR_ENV_NAME} to {}",
&SCROLL_PROVER_ASSETS_DIRS[1]
);
std::env::set_var(
SCROLL_PROVER_ASSETS_DIR_ENV_NAME,
&SCROLL_PROVER_ASSETS_DIRS[1],
);
}
debug_assert!(
SCROLL_PROVER_ASSETS_DIRS.get().is_some()
&& SCROLL_PROVER_ASSETS_DIRS.get().unwrap().len() >= 2
);
log::info!(
"set env {SCROLL_PROVER_ASSETS_DIR_ENV_NAME} to {}",
&SCROLL_PROVER_ASSETS_DIRS.get().unwrap()[1]
);
std::env::set_var(
SCROLL_PROVER_ASSETS_DIR_ENV_NAME,
&SCROLL_PROVER_ASSETS_DIRS.get().unwrap()[1],
);
}
}
6 changes: 3 additions & 3 deletions prover/src/version.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::cell::OnceCell;
use std::sync::OnceLock;

static DEFAULT_COMMIT: &str = "unknown";
static mut VERSION: OnceCell<String> = OnceCell::new();
static VERSION: OnceLock<String> = OnceLock::new();

pub const TAG: &str = "v0.0.0";
pub const DEFAULT_ZK_VERSION: &str = "000000-000000";
Expand All @@ -14,5 +14,5 @@ fn init_version() -> String {
}

pub fn get_version() -> String {
unsafe { VERSION.get_or_init(init_version).clone() }
VERSION.get_or_init(init_version).clone()
}
21 changes: 9 additions & 12 deletions prover/src/zk_circuits_handler/common.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
use std::{collections::BTreeMap, rc::Rc};

use crate::types::ProverType;

use once_cell::sync::OnceCell;

use halo2_proofs::{halo2curves::bn256::Bn256, poly::kzg::commitment::ParamsKZG};
use std::{
collections::BTreeMap,
sync::{Arc, OnceLock},
};

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

pub fn get_params_map_instance<'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)
})
}
PARAMS_MAP.get_or_init(|| {
let params_map = load_params_func();
Arc::new(params_map)
})
}

pub fn get_degrees<F>(prover_types: &std::collections::HashSet<ProverType>, f: F) -> Vec<u32>
Expand Down
6 changes: 2 additions & 4 deletions prover/src/zk_circuits_handler/darwin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,9 @@ use crate::{
types::{ProverType, TaskType},
};
use anyhow::{bail, Context, Ok, Result};
use once_cell::sync::Lazy;
use serde::Deserialize;

use crate::types::{CommonHash, Task};
use std::{cell::RefCell, cmp::Ordering, env, rc::Rc};

use prover_darwin::{
aggregator::Prover as BatchProver,
check_chunk_hashes,
Expand All @@ -19,9 +16,10 @@ use prover_darwin::{
BatchProof, BatchProvingTask, BlockTrace, BundleProof, BundleProvingTask, ChunkInfo,
ChunkProof, ChunkProvingTask,
};
use std::{cell::RefCell, cmp::Ordering, env, rc::Rc, sync::LazyLock};

// Only used for debugging.
static OUTPUT_DIR: Lazy<Option<String>> = Lazy::new(|| env::var("PROVER_OUTPUT_DIR").ok());
static OUTPUT_DIR: LazyLock<Option<String>> = LazyLock::new(|| env::var("PROVER_OUTPUT_DIR").ok());

#[derive(Debug, Clone, Deserialize)]
pub struct BatchTaskDetail {
Expand Down
6 changes: 2 additions & 4 deletions prover/src/zk_circuits_handler/darwin_v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,9 @@ use crate::{
types::{ProverType, TaskType},
};
use anyhow::{bail, Context, Ok, Result};
use once_cell::sync::Lazy;
use serde::Deserialize;

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,
Expand All @@ -19,9 +16,10 @@ use prover_darwin_v2::{
BatchProof, BatchProvingTask, BlockTrace, BundleProof, BundleProvingTask, ChunkInfo,
ChunkProof, ChunkProvingTask,
};
use std::{cell::RefCell, cmp::Ordering, env, rc::Rc, sync::LazyLock};

// Only used for debugging.
static OUTPUT_DIR: Lazy<Option<String>> = Lazy::new(|| env::var("PROVER_OUTPUT_DIR").ok());
static OUTPUT_DIR: LazyLock<Option<String>> = LazyLock::new(|| env::var("PROVER_OUTPUT_DIR").ok());

#[derive(Debug, Clone, Deserialize)]
pub struct BatchTaskDetail {
Expand Down

0 comments on commit 82fab1a

Please sign in to comment.