From 002e857ce78787083e63454c2f48ba90bdf0fc00 Mon Sep 17 00:00:00 2001 From: Matthias Goergens Date: Tue, 19 Nov 2024 18:47:27 +0800 Subject: [PATCH] Fix `serialize_to_file` --- circ_blocks/examples/zxc.rs | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/circ_blocks/examples/zxc.rs b/circ_blocks/examples/zxc.rs index 7f5bacd3..83dfb597 100644 --- a/circ_blocks/examples/zxc.rs +++ b/circ_blocks/examples/zxc.rs @@ -14,7 +14,7 @@ use circ::target::r1cs::{Lc, VarType}; use core::cmp::min; use rug::Integer; -use std::fs::File; +use std::fs::{create_dir_all, File}; use std::io::{BufRead, BufReader, Write}; use circ::cfg::{ @@ -23,7 +23,7 @@ use circ::cfg::{ CircOpt, }; use core::cmp::Ordering; -use std::path::PathBuf; +use std::path::{Path, PathBuf}; use libspartan::{ instance::Instance, Assignment, InputsAssignment, MemsAssignment, SNARKGens, VarsAssignment, @@ -238,16 +238,20 @@ struct CompileTimeKnowledge { impl CompileTimeKnowledge { fn serialize_to_file(&self, benchmark_name: String) -> std::io::Result<()> { - let file_name = format!("../zok_tests/constraints/{}_bin.ctk", benchmark_name); + let file_name = format!("../zok_tests/constraints/{benchmark_name}_bin.ctk"); + create_dir_all(Path::new(&file_name).parent().unwrap())?; let mut f = File::create(file_name)?; + let content = bincode::serialize(&self).unwrap(); f.write(&content)?; Ok(()) } fn write_to_file(&self, benchmark_name: String) -> std::io::Result<()> { - let file_name = format!("../zok_tests/constraints/{}.ctk", benchmark_name); + let file_name = format!("../zok_tests/constraints/{benchmark_name}.ctk"); + create_dir_all(Path::new(&file_name).parent().unwrap())?; let mut f = File::create(file_name)?; + writeln!(&mut f, "Num Blocks: {}", self.block_num_instances)?; writeln!(&mut f, "Max Num Vars: {}", self.num_vars)?; writeln!(&mut f, "Num Inputs: {}", self.num_inputs_unpadded)?; @@ -375,7 +379,8 @@ struct RunTimeKnowledge { impl RunTimeKnowledge { fn serialize_to_file(&self, benchmark_name: String) -> std::io::Result<()> { - let file_name = format!("../zok_tests/inputs/{}_bin.rtk", benchmark_name); + let file_name = format!("../zok_tests/inputs/{benchmark_name}_bin.rtk"); + create_dir_all(Path::new(&file_name).parent().unwrap())?; let mut f = File::create(file_name)?; let content = bincode::serialize(&self).unwrap(); f.write(&content)?; @@ -383,7 +388,9 @@ impl RunTimeKnowledge { } fn write_to_file(&self, benchmark_name: String) -> std::io::Result<()> { - let file_name = format!("../zok_tests/inputs/{}.rtk", benchmark_name); + let dir = "../zok_tests/inputs"; + create_dir_all(dir)?; + let file_name = format!("{dir}/{benchmark_name}.rtk"); let mut f = File::create(file_name)?; writeln!( &mut f,