Skip to content

Commit

Permalink
stdout for all write fns
Browse files Browse the repository at this point in the history
  • Loading branch information
ytham committed May 31, 2024
1 parent 99f3cad commit 3c6b539
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
5 changes: 3 additions & 2 deletions sdk/src/run/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ pub fn run_cli_on_scaffold<
SnarkCmd::Keygen => {
let srs = read_srs_from_dir_or_install(&srs_path, runner.k() as u32);
let (vk, pk, pinning) = keygen(&mut runner, &srs);
write_keygen_output(&vk, &pk, &pinning, cli.data_path.clone());
write_keygen_output(&vk, &pk, &pinning, cli.data_path.clone(), cli.to_stdout);
let metadata = if should_aggregate {
if input.is_none() {
panic!("The `input` argument is required for keygen with aggregation.");
Expand Down Expand Up @@ -191,7 +191,7 @@ pub fn run_cli_on_scaffold<
);
let agg_params = agg_keygen_output.2.params;
let agg_vk = agg_keygen_output.0.clone();
write_agg_keygen_output(agg_keygen_output, cli.data_path.clone());
write_agg_keygen_output(agg_keygen_output, cli.data_path.clone(), cli.to_stdout);
get_agg_axiom_client_circuit_metadata(
&runner,
&agg_kzg_params,
Expand All @@ -206,6 +206,7 @@ pub fn run_cli_on_scaffold<
metadata,
cli.data_path
.join(PathBuf::from(format!("{}.json", cli.name))),
cli.to_stdout,
);
}
SnarkCmd::Prove => {
Expand Down
22 changes: 10 additions & 12 deletions sdk/src/utils/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,15 @@ pub fn write_keygen_output<CoreParams: Serialize>(
pk: &ProvingKey<G1Affine>,
pinning: &AxiomCircuitPinning<CoreParams>,
data_path: PathBuf,
to_stdout: bool,
) -> String {
let circuit_id = get_circuit_id(vk);
let pk_path = data_path.join(format!("{circuit_id}.pk"));
let vk_path = data_path.join(format!("{circuit_id}.vk"));
let pinning_path = data_path.join(format!("{circuit_id}.pinning"));
write_vk(vk, vk_path);
write_pk(pk, pk_path);
write_pinning(pinning, pinning_path);
write_pinning(pinning, pinning_path, to_stdout);
circuit_id
}

Expand All @@ -70,14 +71,15 @@ pub fn write_agg_keygen_output<CoreParams: Serialize>(
AggregationCircuitPinning<CoreParams>,
),
data_path: PathBuf,
to_stdout: bool,
) -> String {
let circuit_id = get_circuit_id(&keygen_output.0);
let pk_path = data_path.join(format!("{circuit_id}.pk"));
let vk_path = data_path.join(format!("{circuit_id}.vk"));
let pinning_path = data_path.join(format!("{circuit_id}.pinning"));
write_vk(&keygen_output.0, vk_path);
write_pk(&keygen_output.1, pk_path);
write_agg_pinning(&keygen_output.2, pinning_path);
write_agg_pinning(&keygen_output.2, pinning_path, to_stdout);
circuit_id
}

Expand Down Expand Up @@ -116,13 +118,13 @@ pub fn write_pk(pk: &ProvingKey<G1Affine>, pk_path: PathBuf) {
info!("Wrote proving key to {:?}", pk_path);
}

pub fn write_metadata(metadata: AxiomClientCircuitMetadata, metadata_path: PathBuf) {
pub fn write_metadata(metadata: AxiomClientCircuitMetadata, metadata_path: PathBuf, to_stdout: bool) {
if metadata_path.exists() {
fs::remove_file(&metadata_path).unwrap();
}
let f = File::create(&metadata_path)
.unwrap_or_else(|_| panic!("Could not create file at {metadata_path:?}"));
serde_json::to_writer_pretty(&f, &metadata).expect("writing metadata should not fail");
output_to_writer(to_stdout, &f, &metadata);
info!("Wrote circuit metadata to {:?}", metadata_path);
}

Expand Down Expand Up @@ -157,26 +159,28 @@ pub fn read_agg_pk(pk_path: PathBuf, params: AggregationCircuitParams) -> Provin
pub fn write_pinning<CoreParams: Serialize>(
pinning: &AxiomCircuitPinning<CoreParams>,
pinning_path: PathBuf,
to_stdout: bool,
) {
if pinning_path.exists() {
fs::remove_file(&pinning_path).unwrap();
}
let f = File::create(&pinning_path)
.unwrap_or_else(|_| panic!("Could not create file at {pinning_path:?}"));
serde_json::to_writer_pretty(&f, &pinning).expect("writing circuit pinning should not fail");
output_to_writer(to_stdout, &f, &pinning);
info!("Wrote circuit pinning to {:?}", pinning_path);
}

pub fn write_agg_pinning<CoreParams: Serialize>(
pinning: &AggregationCircuitPinning<CoreParams>,
pinning_path: PathBuf,
to_stdout: bool,
) {
if pinning_path.exists() {
fs::remove_file(&pinning_path).unwrap();
}
let f = File::create(&pinning_path)
.unwrap_or_else(|_| panic!("Could not create file at {pinning_path:?}"));
serde_json::to_writer_pretty(&f, &pinning).expect("writing circuit pinning should not fail");
output_to_writer(to_stdout, &f, &pinning);
info!("Wrote circuit pinning to {:?}", pinning_path);
}

Expand Down Expand Up @@ -214,11 +218,6 @@ pub fn write_output(
.unwrap_or_else(|_| panic!("Could not create file at {json_output_path:?}"));

output_to_writer(to_stdout, &f, &output);
// if to_stdout {
// serde_json::to_writer_pretty(&std::io::stdout(), &output).expect("Writing output should not fail");
// } else {
// serde_json::to_writer_pretty(&f, &output).expect("Writing output should not fail");
// }
}

pub fn write_witness_gen_output(
Expand All @@ -230,5 +229,4 @@ pub fn write_witness_gen_output(
let f = File::create(&json_output_path)
.unwrap_or_else(|_| panic!("Could not create file at {json_output_path:?}"));
output_to_writer(to_stdout, &f, &output.compute_results);
// serde_json::to_writer_pretty(&f, &output.compute_results).expect("Writing output should not fail");
}

0 comments on commit 3c6b539

Please sign in to comment.