Skip to content

Commit f5aff39

Browse files
committed
feat(proof-compression): testing proving
1 parent 3a41246 commit f5aff39

File tree

12 files changed

+511
-217
lines changed

12 files changed

+511
-217
lines changed

crates/proof-compression/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ exclude = ["/data"]
1515
circuit_definitions.workspace = true
1616
fflonk.workspace = true
1717
shivini.workspace = true
18+
gpu-prover.workspace = true
1819
serde = "1"
1920
serde_json = "1"
2021
bincode = "1.3"
@@ -25,3 +26,5 @@ byteorder = "1"
2526
default = ["gpu"]
2627
gpu = []
2728
cpu = []
29+
30+
#TODO: define allocator

crates/proof-compression/src/blob_storage.rs

Lines changed: 88 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
use std::io::{Read, Write};
22

3-
use super::*;
4-
53
pub trait BlobStorage: Send + Sync {
64
fn read_scheduler_vk(&self) -> Box<dyn Read>;
75
fn read_compression_layer_finalization_hint(&self, circuit_id: u8) -> Box<dyn Read>;
@@ -17,9 +15,11 @@ pub trait BlobStorage: Send + Sync {
1715

1816
fn read_fflonk_vk(&self) -> Box<dyn Read>;
1917
fn read_fflonk_precomputation(&self) -> Box<dyn Read + Send + Sync>;
18+
fn read_fflonk_crs(&self) -> Box<dyn Read>;
2019

2120
fn read_plonk_vk(&self) -> Box<dyn Read>;
2221
fn read_plonk_precomputation(&self) -> Box<dyn Read + Send + Sync>;
22+
fn read_plonk_crs(&self) -> Box<dyn Read>;
2323
}
2424

2525
pub trait BlobStorageExt: BlobStorage {
@@ -33,9 +33,11 @@ pub trait BlobStorageExt: BlobStorage {
3333

3434
fn write_fflonk_vk(&self) -> Box<dyn Write>;
3535
fn write_fflonk_precomputation(&self) -> Box<dyn Write>;
36+
fn write_fflonk_crs(&self) -> Box<dyn Write>;
3637

3738
fn write_plonk_vk(&self) -> Box<dyn Write>;
3839
fn write_plonk_precomputation(&self) -> Box<dyn Write>;
40+
fn write_plonk_crs(&self) -> Box<dyn Write>;
3941
}
4042

4143
pub struct FileSystemBlobStorage;
@@ -62,10 +64,10 @@ impl FileSystemBlobStorage {
6264
impl BlobStorage for FileSystemBlobStorage {
6365
fn read_scheduler_vk(&self) -> Box<dyn Read> {
6466
let path = format!("{}/{}_vk.json", Self::DATA_DIR_PATH, Self::SCHEDULER_PREFIX,);
65-
println!("Reading compression layer finalization at path {}", path);
67+
println!("Reading scheduler vk at path {}", path);
6668
Self::open_file(&path)
6769
}
68-
70+
6971
fn read_compression_layer_finalization_hint(&self, circuit_id: u8) -> Box<dyn Read> {
7072
let path = format!(
7173
"{}/{}_{}_hint.json",
@@ -84,18 +86,18 @@ impl BlobStorage for FileSystemBlobStorage {
8486
Self::COMPRESSION_LAYER_PREFIX,
8587
circuit_id
8688
);
87-
println!("Reading compression layer finalization at path {}", path);
89+
println!("Reading compression layer vk at path {}", path);
8890
Self::open_file(&path)
8991
}
9092

9193
fn read_compression_layer_precomputation(&self, circuit_id: u8) -> Box<dyn Read + Send + Sync> {
9294
let path = format!(
93-
"{}/{}_{}_setup_data.bin",
95+
"{}/{}_{}_setup.bin",
9496
Self::DATA_DIR_PATH,
9597
Self::COMPRESSION_LAYER_PREFIX,
9698
circuit_id
9799
);
98-
println!("Reading compression layer finalization at path {}", path);
100+
println!("Reading compression layer precomputation at path {}", path);
99101
Self::open_file(&path)
100102
}
101103

@@ -106,7 +108,7 @@ impl BlobStorage for FileSystemBlobStorage {
106108
Self::COMPRESSION_WRAPPER_PREFIX,
107109
circuit_id
108110
);
109-
println!("Reading compression layer finalization at path {}", path);
111+
println!("Reading compression wrapper finalization at path {}", path);
110112
Self::open_file(&path)
111113
}
112114

@@ -126,36 +128,59 @@ impl BlobStorage for FileSystemBlobStorage {
126128
circuit_id: u8,
127129
) -> Box<dyn Read + Send + Sync> {
128130
let path = format!(
129-
"{}/{}_{}_setup_data.bin",
131+
"{}/{}_{}_setup.bin",
130132
Self::DATA_DIR_PATH,
131133
Self::COMPRESSION_WRAPPER_PREFIX,
132134
circuit_id
133135
);
134-
println!("Reading compression layer finalization at path {}", path);
136+
println!(
137+
"Reading compression wrapper precomputation at path {}",
138+
path
139+
);
135140
Self::open_file(&path)
136141
}
137142

138143
fn read_fflonk_vk(&self) -> Box<dyn Read> {
139-
let path = format!("{}/{}_setup_.bin", Self::DATA_DIR_PATH, Self::FFLONK_PREFIX);
140-
println!("Reading compression layer finalization at path {}", path);
144+
let path = format!("{}/{}_vk.json", Self::DATA_DIR_PATH, Self::FFLONK_PREFIX);
145+
println!("Reading fflonk vk at path {}", path);
141146
Self::open_file(&path)
142147
}
143148

144149
fn read_fflonk_precomputation(&self) -> Box<dyn Read + Send + Sync> {
145-
let path = format!("{}/{}_vk.json", Self::DATA_DIR_PATH, Self::FFLONK_PREFIX);
146-
println!("Reading compression layer finalization at path {}", path);
150+
let path = format!("{}/{}_setup.bin", Self::DATA_DIR_PATH, Self::FFLONK_PREFIX);
151+
println!("Reading fflonk precomputation at path {}", path);
147152
Self::open_file(&path)
148153
}
149154

150155
fn read_plonk_precomputation(&self) -> Box<dyn Read + Send + Sync> {
151-
let path = format!("{}/{}_setup_.bin", Self::DATA_DIR_PATH, Self::PLONK_PREFIX);
152-
println!("Reading compression layer finalization at path {}", path);
156+
let path = format!("{}/{}_setup.bin", Self::DATA_DIR_PATH, Self::PLONK_PREFIX);
157+
println!("Reading plonk precomputation at path {}", path);
153158
Self::open_file(&path)
154159
}
155160

156161
fn read_plonk_vk(&self) -> Box<dyn Read> {
157-
let path = format!("{}/{}_vk.bin", Self::DATA_DIR_PATH, Self::PLONK_PREFIX);
158-
println!("Reading compression layer finalization at path {}", path);
162+
let path = format!("{}/{}_vk.json", Self::DATA_DIR_PATH, Self::PLONK_PREFIX);
163+
println!("Reading plonk vk at path {}", path);
164+
Self::open_file(&path)
165+
}
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);
159184
Self::open_file(&path)
160185
}
161186
}
@@ -179,18 +204,18 @@ impl BlobStorageExt for FileSystemBlobStorage {
179204
Self::COMPRESSION_LAYER_PREFIX,
180205
circuit_id
181206
);
182-
println!("Writeing compression layer finalization at path {}", path);
207+
println!("Writeing compression layer vk at path {}", path);
183208
Self::create_file(&path)
184209
}
185210

186211
fn write_compression_layer_precomputation(&self, circuit_id: u8) -> Box<dyn Write> {
187212
let path = format!(
188-
"{}/{}_{}_setup_data.bin",
213+
"{}/{}_{}_setup.bin",
189214
Self::DATA_DIR_PATH,
190215
Self::COMPRESSION_LAYER_PREFIX,
191216
circuit_id
192217
);
193-
println!("Writeing compression layer finalization at path {}", path);
218+
println!("Writeing compression layer precomputation at path {}", path);
194219
Self::create_file(&path)
195220
}
196221

@@ -201,7 +226,7 @@ impl BlobStorageExt for FileSystemBlobStorage {
201226
Self::COMPRESSION_WRAPPER_PREFIX,
202227
circuit_id
203228
);
204-
println!("Writeing compression layer finalization at path {}", path);
229+
println!("Writeing compression wrapper finalization at path {}", path);
205230
Self::create_file(&path)
206231
}
207232

@@ -212,48 +237,71 @@ impl BlobStorageExt for FileSystemBlobStorage {
212237
Self::COMPRESSION_WRAPPER_PREFIX,
213238
circuit_id
214239
);
215-
println!("Writeing compression layer finalization at path {}", path);
240+
println!("Writeing compression wrapper vk at path {}", path);
216241
Self::create_file(&path)
217242
}
218243

219244
fn write_compression_wrapper_precomputation(&self, circuit_id: u8) -> Box<dyn Write> {
220245
let path = format!(
221-
"{}/{}_{}_setup_data.bin",
246+
"{}/{}_{}_setup.bin",
222247
Self::DATA_DIR_PATH,
223248
Self::COMPRESSION_WRAPPER_PREFIX,
224249
circuit_id
225250
);
226-
println!("Writeing compression layer finalization at path {}", path);
251+
println!(
252+
"Writeing compression wrapper precomputation at path {}",
253+
path
254+
);
227255
Self::create_file(&path)
228256
}
229257

230258
fn write_fflonk_vk(&self) -> Box<dyn Write> {
231-
let path = format!("{}/{}_setup_.bin", Self::DATA_DIR_PATH, Self::FFLONK_PREFIX);
232-
println!("Writeing compression layer finalization at path {}", path);
259+
let path = format!("{}/{}_vk.json", Self::DATA_DIR_PATH, Self::FFLONK_PREFIX);
260+
println!("Writeing fflonk vk at path {}", path);
233261
Self::create_file(&path)
234262
}
235263

236264
fn write_fflonk_precomputation(&self) -> Box<dyn Write> {
237-
let path = format!("{}/{}_vk.json", Self::DATA_DIR_PATH, Self::FFLONK_PREFIX);
238-
println!("Writeing compression layer finalization at path {}", path);
265+
let path = format!("{}/{}_setup.bin", Self::DATA_DIR_PATH, Self::FFLONK_PREFIX);
266+
println!("Writeing fflonk precomputation at path {}", path);
239267
Self::create_file(&path)
240268
}
241269

242270
fn write_plonk_precomputation(&self) -> Box<dyn Write> {
243-
let path = format!("{}/{}_setup_.bin", Self::DATA_DIR_PATH, Self::PLONK_PREFIX);
244-
println!("Writeing compression layer finalization at path {}", path);
271+
let path = format!("{}/{}_setup.bin", Self::DATA_DIR_PATH, Self::PLONK_PREFIX);
272+
println!("Writeing plonk precomputation at path {}", path);
245273
Self::create_file(&path)
246274
}
247275

248276
fn write_plonk_vk(&self) -> Box<dyn Write> {
249-
let path = format!("{}/{}_vk.bin", Self::DATA_DIR_PATH, Self::PLONK_PREFIX);
250-
println!("Writeing compression layer finalization at path {}", path);
277+
let path = format!("{}/{}_vk.json", Self::DATA_DIR_PATH, Self::PLONK_PREFIX);
278+
println!("Writeing plonk vk at path {}", path);
279+
Self::create_file(&path)
280+
}
281+
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);
251299
Self::create_file(&path)
252300
}
253301
}
254302

255-
pub struct AsyncHandler<T> {
256-
receiver: std::sync::mpsc::Receiver<T>,
303+
pub struct AsyncHandler<T: Send + Sync + 'static> {
304+
receiver: std::thread::JoinHandle<std::sync::mpsc::Receiver<T>>,
257305
}
258306

259307
impl<T> AsyncHandler<T>
@@ -266,12 +314,13 @@ where
266314
{
267315
let receiver = std::thread::spawn(f);
268316

269-
Self {
270-
receiver: receiver.join().unwrap(),
271-
}
317+
Self { receiver }
272318
}
273319

274320
pub fn wait(self) -> T {
275-
self.receiver.recv().unwrap()
321+
self.receiver.join().unwrap().recv().unwrap()
276322
}
277323
}
324+
325+
unsafe impl<T> Send for AsyncHandler<T> where T: Send + Sync {}
326+
unsafe impl<T> Sync for AsyncHandler<T> where T: Send + Sync {}

0 commit comments

Comments
 (0)