Skip to content

Commit 0044de9

Browse files
committed
Allow multi-file record for witness
1 parent 5a2a6c4 commit 0044de9

File tree

3 files changed

+49
-25
lines changed

3 files changed

+49
-25
lines changed

circ_blocks/examples/zxc.rs

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
const PRINT_PROOF: bool = false;
44
const INLINE_SPARTAN_PROOF: bool = true;
55
const TOTAL_NUM_VARS_BOUND: usize = 10000000000;
6+
const MAX_FILE_SIZE: usize = 1073741824;
67

78
use circ::front::zsharp::{self, ZSharpFE};
89
use circ::front::{FrontEnd, Mode};
@@ -33,7 +34,6 @@ use libspartan::{
3334
use merlin::Transcript;
3435
use serde::{Deserialize, Serialize};
3536
use std::time::*;
36-
use std::time::*;
3737

3838
// How many reserved variables (EXCLUDING V) are in front of the actual input / output?
3939
// %BN, %RET, %TS, %AS, %SP, %BP
@@ -239,12 +239,17 @@ struct CompileTimeKnowledge {
239239
}
240240

241241
impl CompileTimeKnowledge {
242-
fn serialize_to_file(&self, benchmark_name: String) -> std::io::Result<()> {
243-
let file_name = format!("../zok_tests/constraints/{benchmark_name}_bin.ctk");
244-
create_dir_all(Path::new(&file_name).parent().unwrap())?;
245-
let mut f = File::create(file_name)?;
242+
fn serialize_to_file(&self, benchmark_name: String, max_file_size: usize) -> std::io::Result<()> {
246243
let content = bincode::serialize(&self).unwrap();
247-
f.write(&content)?;
244+
println!("CTK SIZE: {}", content.len());
245+
for i in 0..content.len().div_ceil(max_file_size) {
246+
let file_name = format!("../zok_tests/constraints/{benchmark_name}_bin_{i}.ctk");
247+
create_dir_all(Path::new(&file_name).parent().unwrap())?;
248+
let mut f = File::create(file_name)?;
249+
let head = max_file_size * i;
250+
let tail = min(max_file_size * (i + 1), content.len());
251+
f.write(&content[head..tail])?;
252+
}
248253
Ok(())
249254
}
250255

@@ -378,12 +383,17 @@ struct RunTimeKnowledge<S: SpartanExtensionField> {
378383
}
379384

380385
impl<S: SpartanExtensionField> RunTimeKnowledge<S> {
381-
fn serialize_to_file(&self, benchmark_name: String) -> std::io::Result<()> {
382-
let file_name = format!("../zok_tests/inputs/{benchmark_name}_bin.rtk");
383-
create_dir_all(Path::new(&file_name).parent().unwrap())?;
384-
let mut f = File::create(file_name)?;
386+
fn serialize_to_file(&self, benchmark_name: String, max_file_size: usize) -> std::io::Result<()> {
385387
let content = bincode::serialize(&self).unwrap();
386-
f.write(&content)?;
388+
println!("RTK SIZE: {}", content.len());
389+
for i in 0..content.len().div_ceil(max_file_size) {
390+
let file_name = format!("../zok_tests/inputs/{benchmark_name}_bin_{i}.rtk");
391+
create_dir_all(Path::new(&file_name).parent().unwrap())?;
392+
let mut f = File::create(file_name)?;
393+
let head = max_file_size * i;
394+
let tail = min(max_file_size * (i + 1), content.len());
395+
f.write(&content[head..tail])?;
396+
}
387397
Ok(())
388398
}
389399

@@ -1589,13 +1599,13 @@ fn main() {
15891599
ctk.write_to_file(benchmark_name.to_string()).unwrap();
15901600
rtk.write_to_file(benchmark_name.to_string()).unwrap();
15911601
}
1592-
if !INLINE_SPARTAN_PROOF {
1593-
// --
1594-
// Write CTK, RTK to file
1595-
// --
1596-
ctk.serialize_to_file(benchmark_name.to_string()).unwrap();
1597-
rtk.serialize_to_file(benchmark_name.to_string()).unwrap();
1598-
} else {
1602+
1603+
// --
1604+
// Write CTK, RTK to file
1605+
// --
1606+
ctk.serialize_to_file(benchmark_name.to_string(), MAX_FILE_SIZE).unwrap();
1607+
rtk.serialize_to_file(benchmark_name.to_string(), MAX_FILE_SIZE).unwrap();
1608+
if INLINE_SPARTAN_PROOF {
15991609
run_spartan_proof(ctk, rtk);
16001610
}
16011611

spartan_parallel/examples/interface.rs

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,17 @@ struct CompileTimeKnowledge {
4242

4343
impl CompileTimeKnowledge {
4444
fn deserialize_from_file(benchmark_name: String) -> CompileTimeKnowledge {
45-
let file_name = format!("../zok_tests/constraints/{}_bin.ctk", benchmark_name);
46-
let mut f = File::open(file_name).unwrap();
45+
// Input can be provided through multiple files, use i to determine the next file label
46+
let mut i = 0;
47+
let mut file_name = format!("../zok_tests/constraints/{benchmark_name}_bin_{i}.ctk");
4748
let mut content: Vec<u8> = Vec::new();
48-
f.read_to_end(&mut content).unwrap();
49+
while let Ok(mut f) = File::open(file_name) {
50+
let mut new_content: Vec<u8> = Vec::new();
51+
f.read_to_end(&mut new_content).unwrap();
52+
content.extend(new_content);
53+
i += 1;
54+
file_name = format!("../zok_tests/constraints/{benchmark_name}_bin_{i}.ctk");
55+
}
4956
bincode::deserialize(&content).unwrap()
5057
}
5158
}
@@ -78,10 +85,17 @@ struct RunTimeKnowledge<S: SpartanExtensionField> {
7885

7986
impl<S: SpartanExtensionField + for<'de> serde::de::Deserialize<'de>> RunTimeKnowledge<S> {
8087
fn deserialize_from_file(benchmark_name: String) -> RunTimeKnowledge<S> {
81-
let file_name = format!("../zok_tests/inputs/{}_bin.rtk", benchmark_name);
82-
let mut f = File::open(file_name).unwrap();
88+
// Input can be provided through multiple files, use i to determine the next file label
89+
let mut i = 0;
90+
let mut file_name = format!("../zok_tests/inputs/{benchmark_name}_bin_{i}.rtk");
8391
let mut content: Vec<u8> = Vec::new();
84-
f.read_to_end(&mut content).unwrap();
92+
while let Ok(mut f) = File::open(file_name) {
93+
let mut new_content: Vec<u8> = Vec::new();
94+
f.read_to_end(&mut new_content).unwrap();
95+
content.extend(new_content);
96+
i += 1;
97+
file_name = format!("../zok_tests/inputs/{benchmark_name}_bin_{i}.rtk");
98+
}
8599
bincode::deserialize(&content).unwrap()
86100
}
87101
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
const u32 REPETITION = 2000
1+
const u32 REPETITION = 10000

0 commit comments

Comments
 (0)