-
Notifications
You must be signed in to change notification settings - Fork 616
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor(prover): Using some std libs instead of thirdparty lib #1573
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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 { | ||
|
@@ -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 {} | ||
|
@@ -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], | ||
); | ||
Comment on lines
+76
to
+87
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Codebase verification Based on the search results, I can now generate the final response: Environment variable usage is consistent but has multiple setters The
The variable is properly validated in 🔗 Analysis chainVerify environment variable usage across the codebase Let's ensure that the Also applies to: 91-102 🏁 Scripts executedThe following scripts were executed for the analysis: Script: #!/bin/bash
# Description: Check for consistent usage of SCROLL_PROVER_ASSETS_DIR environment variable
# Search for all occurrences of the environment variable
echo "Searching for environment variable usage..."
rg -A 2 "SCROLL_PROVER_ASSETS_DIR"
# Search for potential environment variable setters
echo "Checking for environment variable setters..."
ast-grep --pattern 'std::env::set_var($name, $value)'
Length of output: 3884 |
||
} | ||
|
||
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], | ||
); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Consider improving error handling in initialization
The initialization could benefit from better error handling and validation.