Skip to content

Commit

Permalink
cli: perf: mask some checkings in release mode
Browse files Browse the repository at this point in the history
  • Loading branch information
junyu0312 committed Nov 9, 2024
1 parent f5acf8c commit 944b5bb
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions crates/cli/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ pub(crate) struct Config {
}

impl Config {
#[cfg(debug_assertions)]
fn image_consistent_check(&self, wasm_image: &[u8]) -> anyhow::Result<()> {
if let Some(expected_wasm_image_md5) = &self.wasm_image_md5 {
let wasm_image_md5 = format!("{:x}", md5::compute(wasm_image));
Expand All @@ -94,6 +95,7 @@ impl Config {
Ok(())
}

#[cfg(debug_assertions)]
fn params_consistent_check(&self, params: &[u8]) -> anyhow::Result<()> {
let params_md5 = format!("{:x}", md5::compute(params));

Expand Down Expand Up @@ -146,6 +148,7 @@ impl Config {
let mut buf = Vec::new();
File::open(wasm_image)?.read_to_end(&mut buf)?;

#[cfg(debug_assertions)]
self.image_consistent_check(&buf)?;

ZkWasmLoader::parse_module(&buf)
Expand All @@ -157,6 +160,7 @@ impl Config {
let mut buf = Vec::new();
File::open(path)?.read_to_end(&mut buf)?;

#[cfg(debug_assertions)]
self.params_consistent_check(&buf)?;

let params = Params::<G1Affine>::read(&mut Cursor::new(&mut buf))?;
Expand All @@ -167,18 +171,21 @@ impl Config {
fn read_circuit_data(
&self,
path: &PathBuf,
expected_md5: &str,
_expected_md5: &str,
) -> anyhow::Result<CircuitData<G1Affine>> {
let mut buf = Vec::new();
File::open(path)?.read_to_end(&mut buf)?;
#[cfg(debug_assertions)]
{
let mut buf = Vec::new();
File::open(path)?.read_to_end(&mut buf)?;

let circuit_data_md5 = format!("{:x}", md5::compute(&buf));
let circuit_data_md5 = format!("{:x}", md5::compute(&buf));

if circuit_data_md5 != expected_md5 {
anyhow::bail!(
"Circuit data is inconsistent with the one used to build the circuit. \
if circuit_data_md5 != _expected_md5 {
anyhow::bail!(
"Circuit data is inconsistent with the one used to build the circuit. \
Maybe you have changed the circuit data after setup the circuit?",
);
);
}
}

let circuit_data = CircuitData::<G1Affine>::read(&mut File::open(path)?)?;
Expand Down

0 comments on commit 944b5bb

Please sign in to comment.