Skip to content

Commit 64923f3

Browse files
committed
chore(proof-compressio): cleanup
1 parent fc99447 commit 64923f3

File tree

20 files changed

+1088
-1315
lines changed

20 files changed

+1088
-1315
lines changed

crates/proof-compression/Cargo.toml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,17 @@ exclude = ["/data"]
1313

1414
[dependencies]
1515
circuit_definitions.workspace = true
16-
fflonk.workspace = true
16+
fflonk = {workspace = true, optional = true}
1717
shivini.workspace = true
18-
gpu-prover.workspace = true
18+
gpu-prover = { workspace = true, optional = true}
1919
serde = "1"
2020
serde_json = "1"
2121
bincode = "1.3"
2222
cfg-if = "1.0"
2323
byteorder = "1"
2424

2525
[features]
26-
default = ["gpu"]
26+
default = ["gpu", "fflonk", "gpu-prover"]
2727
gpu = []
2828
cpu = []
29-
30-
#TODO: define allocator
29+
allocator = ["fflonk/allocator", "gpu-prover/allocator"]
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/bin/bash
2+
3+
# Configuration: adjust these variables as needed
4+
BASE_URL="https://aztec-ignition.s3.eu-west-2.amazonaws.com/MAIN+IGNITION/sealed/transcript" # Base URL before the index
5+
FILE_EXT=".dat" # File extension (if any)
6+
START_INDEX=0 # Starting index
7+
END_INDEX=15 # Ending index
8+
9+
# Loop over the desired range of indexes
10+
for ((i=START_INDEX; i<=END_INDEX; i++)); do
11+
# Format the index as two digits (e.g., 01, 02, ..., 10)
12+
FORMATTED_INDEX=$(printf "%02d" "$i")
13+
14+
# Construct the full URL for the current file using the formatted index
15+
FILE_URL="${BASE_URL}${FORMATTED_INDEX}${FILE_EXT}"
16+
17+
echo "Downloading ${FILE_URL} ..."
18+
19+
# Download the file using wget
20+
wget "$FILE_URL"
21+
22+
# Check if the download succeeded; if not, optionally handle errors
23+
if [[ $? -ne 0 ]]; then
24+
echo "Failed to download ${FILE_URL}"
25+
# Optionally break or continue based on your needs
26+
fi
27+
done
28+
29+
echo "Download complete."
File renamed without changes.

crates/proof-compression/src/blob_storage.rs

Lines changed: 13 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,10 @@ pub trait BlobStorage: Send + Sync {
1515

1616
fn read_fflonk_vk(&self) -> Box<dyn Read>;
1717
fn read_fflonk_precomputation(&self) -> Box<dyn Read + Send + Sync>;
18-
fn read_fflonk_crs(&self) -> Box<dyn Read>;
1918

2019
fn read_plonk_vk(&self) -> Box<dyn Read>;
2120
fn read_plonk_precomputation(&self) -> Box<dyn Read + Send + Sync>;
22-
fn read_plonk_crs(&self) -> Box<dyn Read>;
21+
fn read_compact_raw_crs(&self) -> Box<dyn Read + Send + Sync>;
2322
}
2423

2524
pub trait BlobStorageExt: BlobStorage {
@@ -33,14 +32,14 @@ pub trait BlobStorageExt: BlobStorage {
3332

3433
fn write_fflonk_vk(&self) -> Box<dyn Write>;
3534
fn write_fflonk_precomputation(&self) -> Box<dyn Write>;
36-
fn write_fflonk_crs(&self) -> Box<dyn Write>;
3735

3836
fn write_plonk_vk(&self) -> Box<dyn Write>;
3937
fn write_plonk_precomputation(&self) -> Box<dyn Write>;
40-
fn write_plonk_crs(&self) -> Box<dyn Write>;
38+
39+
fn write_compact_raw_crs(&self) -> Box<dyn Write>;
4140
}
4241

43-
pub struct FileSystemBlobStorage;
42+
pub(crate) struct FileSystemBlobStorage;
4443

4544
impl FileSystemBlobStorage {
4645
const DATA_DIR_PATH: &str = "./data";
@@ -163,24 +162,9 @@ impl BlobStorage for FileSystemBlobStorage {
163162
println!("Reading plonk vk at path {}", path);
164163
Self::open_file(&path)
165164
}
166-
167-
fn read_fflonk_crs(&self) -> Box<dyn Read> {
168-
let path = format!(
169-
"{}/{}_compact_crs.key.raw",
170-
Self::DATA_DIR_PATH,
171-
Self::FFLONK_PREFIX
172-
);
173-
println!("Reading fflonk CRS at path {}", path);
174-
Self::open_file(&path)
175-
}
176-
177-
fn read_plonk_crs(&self) -> Box<dyn Read> {
178-
let path = format!(
179-
"{}/{}_compact_crs.key.raw",
180-
Self::DATA_DIR_PATH,
181-
Self::PLONK_PREFIX
182-
);
183-
println!("Reading fflonk CRS at path {}", path);
165+
fn read_compact_raw_crs(&self) -> Box<dyn Read + Send + Sync> {
166+
let path = format!("{}/compact_raw_crs.key", Self::DATA_DIR_PATH,);
167+
println!("Reading CRS at path {}", path);
184168
Self::open_file(&path)
185169
}
186170
}
@@ -279,36 +263,22 @@ impl BlobStorageExt for FileSystemBlobStorage {
279263
Self::create_file(&path)
280264
}
281265

282-
fn write_fflonk_crs(&self) -> Box<dyn Write> {
283-
let path = format!(
284-
"{}/{}_compact_crs.key.raw",
285-
Self::DATA_DIR_PATH,
286-
Self::PLONK_PREFIX
287-
);
288-
println!("Writeing fflonk CRS at path {}", path);
289-
Self::create_file(&path)
290-
}
291-
292-
fn write_plonk_crs(&self) -> Box<dyn Write> {
293-
let path = format!(
294-
"{}/{}_compact_crs.key.raw",
295-
Self::DATA_DIR_PATH,
296-
Self::PLONK_PREFIX
297-
);
298-
println!("Writeing plonk CRS at path {}", path);
266+
fn write_compact_raw_crs(&self) -> Box<dyn Write> {
267+
let path = format!("{}/compact_raw_crs.key", Self::DATA_DIR_PATH);
268+
println!("Writeing compact raw CRS at path {}", path);
299269
Self::create_file(&path)
300270
}
301271
}
302272

303-
pub struct AsyncHandler<T: Send + Sync + 'static> {
273+
pub(crate) struct AsyncHandler<T: Send + Sync + 'static> {
304274
receiver: std::thread::JoinHandle<std::sync::mpsc::Receiver<T>>,
305275
}
306276

307277
impl<T> AsyncHandler<T>
308278
where
309279
T: Send + Sync + 'static,
310280
{
311-
pub fn spawn<F>(f: F) -> Self
281+
pub(crate) fn spawn<F>(f: F) -> Self
312282
where
313283
F: FnOnce() -> std::sync::mpsc::Receiver<T> + Send + Sync + 'static,
314284
{
@@ -317,7 +287,7 @@ where
317287
Self { receiver }
318288
}
319289

320-
pub fn wait(self) -> T {
290+
pub(crate) fn wait(self) -> T {
321291
self.receiver.join().unwrap().recv().unwrap()
322292
}
323293
}

crates/proof-compression/src/chain.rs

Lines changed: 41 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
use circuit_definitions::circuit_definitions::aux_layer::compression_modes::{
2+
CompressionMode1, CompressionMode1ForWrapper, CompressionMode2, CompressionMode3,
3+
CompressionMode4, CompressionMode5ForWrapper,
4+
};
5+
16
use super::*;
27

38
pub enum SnarkWrapper {
@@ -9,6 +14,12 @@ pub enum SnarkWrapperProof {
914
FFfonk(FflonkSnarkVerifierCircuitProof),
1015
}
1116

17+
pub type SchedulerProof = franklin_crypto::boojum::cs::implementations::proof::Proof<
18+
GoldilocksField,
19+
circuit_definitions::circuit_definitions::recursion_layer::RecursiveProofsTreeHasher,
20+
GoldilocksExt2,
21+
>;
22+
1223
pub fn run_proof_chain<BS>(
1324
input_proof: SchedulerProof,
1425
snark_wrapper: SnarkWrapper,
@@ -29,7 +40,7 @@ where
2940
}
3041
}
3142

32-
pub(crate) fn run_proof_chain_with_fflonk<BS>(
43+
pub fn run_proof_chain_with_fflonk<BS>(
3344
input_proof: SchedulerProof,
3445
blob_storage: &BS,
3546
) -> FflonkSnarkVerifierCircuitProof
@@ -38,8 +49,10 @@ where
3849
{
3950
let context_manager = SimpleContextManager::new();
4051
let start = std::time::Instant::now();
41-
let snark_context_config =
42-
context_manager.initialize_snark_context_config::<FflonkSnarkWrapper>();
52+
let compact_raw_crs =
53+
<FflonkSnarkWrapper as SnarkWrapperStep>::load_compact_raw_crs(blob_storage);
54+
let fflonk_precomputation = FflonkSnarkWrapper::get_precomputation(blob_storage);
55+
4356
let next_proof =
4457
CompressionMode1::prove_compression_step(input_proof, blob_storage, &context_manager);
4558
let next_proof = CompressionMode2::prove_compression_step::<_, SimpleContextManager>(
@@ -67,7 +80,8 @@ where
6780
start.elapsed().as_secs()
6881
);
6982
let final_proof = FflonkSnarkWrapper::prove_snark_wrapper_step::<_, SimpleContextManager>(
70-
snark_context_config,
83+
compact_raw_crs,
84+
fflonk_precomputation,
7185
next_proof,
7286
blob_storage,
7387
&context_manager,
@@ -79,13 +93,14 @@ where
7993
final_proof
8094
}
8195

82-
pub(crate) fn precompute_proof_chain_with_fflonk<BS>(blob_storage: &BS)
96+
pub fn precompute_proof_chain_with_fflonk<BS>(blob_storage: &BS)
8397
where
8498
BS: BlobStorageExt,
8599
{
86100
let context_manager = SimpleContextManager::new();
87-
let snark_context_config =
88-
context_manager.initialize_snark_context_config::<FflonkSnarkWrapper>();
101+
let compact_raw_crs =
102+
<FflonkSnarkWrapper as SnarkWrapperStep>::load_compact_raw_crs(blob_storage);
103+
89104
let start = std::time::Instant::now();
90105
CompressionMode1::precomputae_and_store_compression_circuits(blob_storage, &context_manager);
91106
CompressionMode2::precomputae_and_store_compression_circuits(blob_storage, &context_manager);
@@ -100,61 +115,68 @@ where
100115
start.elapsed().as_secs()
101116
);
102117
FflonkSnarkWrapper::precompute_and_store_snark_wrapper_circuit(
103-
snark_context_config,
118+
compact_raw_crs,
104119
blob_storage,
105120
&context_manager,
106121
);
107122
println!(
108-
"Precomputation of entire chain took {}s",
123+
"Precomputation of entire chain with fflonk took {}s",
109124
start.elapsed().as_secs()
110125
);
111126
}
112127

113-
pub(crate) fn run_proof_chain_with_plonk<BS>(
128+
pub fn run_proof_chain_with_plonk<BS>(
114129
input_proof: SchedulerProof,
115130
blob_storage: &BS,
116131
) -> PlonkSnarkVerifierCircuitProof
117132
where
118133
BS: BlobStorage,
119134
{
120135
let context_manager = SimpleContextManager::new();
121-
let snark_context_config =
122-
context_manager.initialize_snark_context_config::<PlonkSnarkWrapper>();
123136
let start = std::time::Instant::now();
137+
let compact_raw_crs =
138+
<PlonkSnarkWrapper as SnarkWrapperStep>::load_compact_raw_crs(blob_storage);
139+
let plonk_precomputation = PlonkSnarkWrapper::get_precomputation(blob_storage);
140+
124141
let next_proof = CompressionMode1ForWrapper::prove_compression_step(
125142
input_proof,
126143
blob_storage,
127144
&context_manager,
128145
);
129146

130147
let final_proof = PlonkSnarkWrapper::prove_snark_wrapper_step(
131-
snark_context_config,
148+
compact_raw_crs,
149+
plonk_precomputation,
132150
next_proof,
133151
blob_storage,
134152
&context_manager,
135153
);
136154
println!(
137-
"Entire compression chain took {}s",
155+
"Entire compression chain with plonk took {}s",
138156
start.elapsed().as_secs()
139157
);
140158
final_proof
141159
}
142160

143-
pub(crate) fn precompute_proof_chain_with_plonk<BS>(blob_storage: &BS)
161+
pub fn precompute_proof_chain_with_plonk<BS>(blob_storage: &BS)
144162
where
145163
BS: BlobStorageExt,
146164
{
147165
let context_manager = SimpleContextManager::new();
148-
let snark_context_config =
149-
context_manager.initialize_snark_context_config::<PlonkSnarkWrapper>();
166+
let start = std::time::Instant::now();
167+
let compact_raw_crs =
168+
<PlonkSnarkWrapper as SnarkWrapperStep>::load_compact_raw_crs(blob_storage);
150169
CompressionMode1ForWrapper::precomputae_and_store_compression_circuits(
151170
blob_storage,
152171
&context_manager,
153172
);
154173
PlonkSnarkWrapper::precompute_and_store_snark_wrapper_circuit(
155-
snark_context_config,
174+
compact_raw_crs,
156175
blob_storage,
157176
&context_manager,
158177
);
159-
println!("All steps in this approach precomputed and saved into blob storage");
178+
println!(
179+
"Precomputation of entire chain with fflonk took {}s",
180+
start.elapsed().as_secs()
181+
);
160182
}

0 commit comments

Comments
 (0)