From 4625d3a63cee0a5776b4f44d0e9c7e69baa8d27e Mon Sep 17 00:00:00 2001 From: Balazs Komuves Date: Thu, 12 Dec 2024 11:07:25 +0100 Subject: [PATCH] serializing circuit data in the recursion example --- .gitignore | 3 +++ plonky2/.gitignore | 2 ++ plonky2/examples/bench_recursion.rs | 14 ++++++++++++++ plonky2/examples/fibonacci_serialization.rs | 19 ++++++------------- 4 files changed, 25 insertions(+), 13 deletions(-) create mode 100644 plonky2/.gitignore diff --git a/.gitignore b/.gitignore index 293a17bb..e38c97fd 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,6 @@ pgo-data.profdata # MacOS nuisances .DS_Store + +# debugging +debug_data \ No newline at end of file diff --git a/plonky2/.gitignore b/plonky2/.gitignore new file mode 100644 index 00000000..e6692e97 --- /dev/null +++ b/plonky2/.gitignore @@ -0,0 +1,2 @@ +.DS_Store +*.json \ No newline at end of file diff --git a/plonky2/examples/bench_recursion.rs b/plonky2/examples/bench_recursion.rs index b45904e9..2b054d54 100644 --- a/plonky2/examples/bench_recursion.rs +++ b/plonky2/examples/bench_recursion.rs @@ -14,6 +14,9 @@ use core::str::FromStr; #[cfg(feature = "std")] use std::sync::Arc; +use std::fs; +use serde::Serialize; + use anyhow::{anyhow, Context as _, Result}; use itertools::Itertools; use log::{info, Level, LevelFilter}; @@ -212,6 +215,7 @@ fn recursive_proof< ) -> Result> where InnerC::Hasher: AlgebraicHasher, + C: Serialize, { let (inner_proof, inner_vd, inner_cd) = inner; let mut builder = CircuitBuilder::::new(config.clone()); @@ -247,6 +251,16 @@ where let proof = prove_with_options::(&data.prover_only, &data.common, pw, &mut timing, &prover_opts)?; timing.print(); +/* + // serialize circuit data and proof + let common_circuit_data_serialized = serde_json::to_string(&data.common).unwrap(); + let verifier_only_circuit_data_serialized = serde_json::to_string(&data.verifier_only).unwrap(); + let proof_serialized = serde_json::to_string(&proof).unwrap(); + fs::write(format!("recursion_{}_common.json", name), common_circuit_data_serialized ).expect("Unable to write file"); + fs::write(format!("recursion_{}_vkey.json" , name), verifier_only_circuit_data_serialized ).expect("Unable to write file"); + fs::write(format!("recursion_{}_proof.json" , name), proof_serialized ).expect("Unable to write file"); +*/ + data.verify(proof.clone())?; Ok((proof, data.verifier_only, data.common)) diff --git a/plonky2/examples/fibonacci_serialization.rs b/plonky2/examples/fibonacci_serialization.rs index 033ce39b..b6d4a9b3 100644 --- a/plonky2/examples/fibonacci_serialization.rs +++ b/plonky2/examples/fibonacci_serialization.rs @@ -42,21 +42,14 @@ fn main() -> Result<()> { let data = builder.build::(); - let common_circuit_data_serialized = serde_json::to_string(&data.common).unwrap(); - fs::write("common_circuit_data.json", common_circuit_data_serialized) - .expect("Unable to write file"); - - let verifier_only_circuit_data_serialized = serde_json::to_string(&data.verifier_only).unwrap(); - fs::write( - "verifier_only_circuit_data.json", - verifier_only_circuit_data_serialized, - ) - .expect("Unable to write file"); - let proof = data.prove(pw)?; - let proof_serialized = serde_json::to_string(&proof).unwrap(); - fs::write("proof_with_public_inputs.json", proof_serialized).expect("Unable to write file"); + let common_circuit_data_serialized = serde_json::to_string(&data.common).unwrap(); + let verifier_only_circuit_data_serialized = serde_json::to_string(&data.verifier_only).unwrap(); + let proof_serialized = serde_json::to_string(&proof).unwrap(); + fs::write("fibonacci_common.json", common_circuit_data_serialized ).expect("Unable to write file"); + fs::write("fibonacci_vkey.json" , verifier_only_circuit_data_serialized ).expect("Unable to write file"); + fs::write("fibonacci_proof.json" , proof_serialized ).expect("Unable to write file"); println!( "100th Fibonacci number mod |F| (starting with {}, {}) is: {}",