Skip to content

Commit 266298e

Browse files
committed
chore: remove unused util methods
1 parent 14deabc commit 266298e

File tree

6 files changed

+31
-35
lines changed

6 files changed

+31
-35
lines changed

prover/src/aggregator/prover.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::env;
1+
use std::{env, path::PathBuf};
22

33
use aggregator::{decode_bytes, BatchData, BatchHash, BatchHeader, ChunkInfo, MAX_AGG_SNARKS};
44
use eth_types::H256;
@@ -14,7 +14,7 @@ use crate::{
1414
FD_SP1_CHUNK_PROTOCOL,
1515
},
1616
types::BundleProvingTask,
17-
utils::{force_to_read, try_to_read},
17+
utils::{force_read, try_read},
1818
BatchProofV2, BatchProofV2Metadata, BatchProvingTask, BundleProofV2, ChunkKind, ChunkProof,
1919
ChunkProofV2, ParamsMap, ProverError,
2020
};
@@ -68,12 +68,14 @@ impl<'params> Prover<'params> {
6868
// The SNARK protocols for both variants of the Layer-2 SNARK must be available in the
6969
// assets directory before setting up the batch prover. The SNARK protocols are
7070
// specifically for the halo2-route and sp1-route of generating chunk proofs.
71-
let halo2_protocol = force_to_read(assets_dir, &FD_HALO2_CHUNK_PROTOCOL);
72-
let sp1_protocol = force_to_read(assets_dir, &FD_SP1_CHUNK_PROTOCOL);
71+
let halo2_protocol =
72+
force_read(PathBuf::from(assets_dir).join(FD_HALO2_CHUNK_PROTOCOL.clone()));
73+
let sp1_protocol =
74+
force_read(PathBuf::from(assets_dir).join(FD_SP1_CHUNK_PROTOCOL.clone()));
7375

7476
// Try to read the verifying key for both Layer-4 and Layer-6 compression circuits.
75-
let raw_vk_batch = try_to_read(assets_dir, &BATCH_VK_FILENAME);
76-
let raw_vk_bundle = try_to_read(assets_dir, &BUNDLE_VK_FILENAME);
77+
let raw_vk_batch = try_read(PathBuf::from(assets_dir).join(BATCH_VK_FILENAME.clone()));
78+
let raw_vk_bundle = try_read(PathBuf::from(assets_dir).join(BUNDLE_VK_FILENAME.clone()));
7779

7880
if raw_vk_batch.is_none() {
7981
log::warn!(

prover/src/aggregator/verifier.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::env;
1+
use std::{env, path::PathBuf};
22

33
use aggregator::CompressionCircuit;
44
use halo2_proofs::{
@@ -11,7 +11,7 @@ use crate::{
1111
common,
1212
config::{LAYER4_CONFIG_PATH, LAYER4_DEGREE},
1313
consts::{batch_vk_filename, DEPLOYMENT_CODE_FILENAME},
14-
utils::{deploy_and_call, force_to_read, try_to_read},
14+
utils::{deploy_and_call, force_read, try_read},
1515
BatchProofV2, BatchProverError, BundleProofV2, ParamsMap, ProverError,
1616
};
1717

@@ -49,10 +49,12 @@ impl<'params> Verifier<'params> {
4949
/// Panics if the verifying key is not found in the assets directory.
5050
pub fn from_params_and_assets(params_map: &'params ParamsMap, assets_dir: &str) -> Self {
5151
// Read verifying key in the assets directory.
52-
let raw_vk = force_to_read(assets_dir, &batch_vk_filename());
52+
let path = PathBuf::from(assets_dir).join(batch_vk_filename());
53+
let raw_vk = force_read(&path);
5354

5455
// Try to read the bytecode to deploy the verifier contract.
55-
let deployment_code = try_to_read(assets_dir, &DEPLOYMENT_CODE_FILENAME);
56+
let path = PathBuf::from(assets_dir).join(DEPLOYMENT_CODE_FILENAME.clone());
57+
let deployment_code = try_read(&path);
5658

5759
// The Layer-4 compressioe circuit is configured with the shape as per
5860
// [`LAYER4_CONFIG_PATH`].

prover/src/test/batch.rs

+9-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1-
use std::sync::{LazyLock, Mutex};
1+
use std::{
2+
path::PathBuf,
3+
sync::{LazyLock, Mutex},
4+
};
25

36
use crate::{
47
aggregator::{Prover, Verifier},
58
config::{LayerId, BATCH_PROVER_DEGREES},
69
consts::DEPLOYMENT_CODE_FILENAME,
710
types::BundleProvingTask,
8-
utils::{force_to_read, read_env_var},
11+
utils::{force_read, read_env_var},
912
BatchProvingTask, ParamsMap,
1013
};
1114

@@ -37,7 +40,8 @@ pub fn batch_prove(test: &str, batch: BatchProvingTask) {
3740

3841
let params = prover.prover_impl.params(LayerId::Layer4.degree());
3942

40-
let deployment_code = force_to_read(&assets_dir, &DEPLOYMENT_CODE_FILENAME);
43+
let path = PathBuf::from(assets_dir).join(DEPLOYMENT_CODE_FILENAME.clone());
44+
let deployment_code = force_read(&path);
4145

4246
let pk = prover
4347
.prover_impl
@@ -70,7 +74,8 @@ pub fn bundle_prove(test: &str, bundle: BundleProvingTask) {
7074

7175
let params = prover.prover_impl.params(LayerId::Layer4.degree());
7276

73-
let deployment_code = force_to_read(&assets_dir, &DEPLOYMENT_CODE_FILENAME);
77+
let path = PathBuf::from(assets_dir).join(DEPLOYMENT_CODE_FILENAME.clone());
78+
let deployment_code = force_read(&path);
7479

7580
let pk = prover
7681
.prover_impl

prover/src/utils/io.rs

-15
Original file line numberDiff line numberDiff line change
@@ -45,21 +45,6 @@ pub fn serialize_instance(instance: &[Vec<Fr>]) -> Vec<u8> {
4545
serde_json::to_vec(&instances_for_serde).unwrap()
4646
}
4747

48-
pub fn try_to_read(dir: &str, filename: &str) -> Option<Vec<u8>> {
49-
let mut path = PathBuf::from(dir);
50-
path.push(filename);
51-
52-
if path.exists() {
53-
self::read(&path).ok()
54-
} else {
55-
None
56-
}
57-
}
58-
59-
pub fn force_to_read(dir: &str, filename: &str) -> Vec<u8> {
60-
try_to_read(dir, filename).unwrap_or_else(|| panic!("File {filename} must exist in {dir}"))
61-
}
62-
6348
pub fn write_file(folder: &mut PathBuf, filename: &str, buf: &[u8]) {
6449
folder.push(filename);
6550
let mut fd = std::fs::File::create(folder.as_path()).unwrap();

prover/src/zkevm/prover.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::collections::BTreeMap;
1+
use std::{collections::BTreeMap, path::PathBuf};
22

33
use aggregator::ChunkInfo;
44
use halo2_proofs::{halo2curves::bn256::Bn256, poly::kzg::commitment::ParamsKZG};
@@ -10,7 +10,7 @@ use crate::{
1010
consts::CHUNK_VK_FILENAME,
1111
proof::compare_chunk_info,
1212
types::ChunkProvingTask,
13-
utils::try_to_read,
13+
utils::try_read,
1414
zkevm::{
1515
circuit::{calculate_row_usage_of_witness_block, chunk_trace_to_witness_block},
1616
ChunkProverError, ChunkVerifier, RowUsage,
@@ -41,7 +41,8 @@ impl<'params> Prover<'params> {
4141
assets_dir: &str,
4242
) -> Self {
4343
// Try to read the verifying key from disk, but don't panic if not found.
44-
let raw_vk = try_to_read(assets_dir, &CHUNK_VK_FILENAME);
44+
let path = PathBuf::from(assets_dir).join(CHUNK_VK_FILENAME.clone());
45+
let raw_vk = try_read(&path);
4546

4647
// Build the inner prover.
4748
let prover_impl = common::Prover::from_params_map(params_map);

prover/src/zkevm/verifier.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::env;
1+
use std::{env, path::PathBuf};
22

33
use aggregator::CompressionCircuit;
44
use halo2_proofs::{
@@ -11,7 +11,7 @@ use crate::{
1111
common,
1212
config::{LAYER2_CONFIG_PATH, LAYER2_DEGREE},
1313
consts::chunk_vk_filename,
14-
utils::force_to_read,
14+
utils::force_read,
1515
ChunkProofV2, ChunkProverError, ParamsMap, ProverError,
1616
};
1717

@@ -42,7 +42,8 @@ impl<'params> Verifier<'params> {
4242
/// Panics if the verifying key cannot be located in the given assets directory.
4343
pub fn from_params_and_assets(params_map: &'params ParamsMap, assets_dir: &str) -> Self {
4444
// Read the verifying key or panic.
45-
let raw_vk = force_to_read(assets_dir, &chunk_vk_filename());
45+
let path = PathBuf::from(assets_dir).join(chunk_vk_filename());
46+
let raw_vk = force_read(&path);
4647

4748
// The Layer-2 compression circuit is configured with the shape as per
4849
// [`LAYER2_CONFIG_PATH`].

0 commit comments

Comments
 (0)