From acc2dc3178fffe6f0956b617348e3bb8abb92297 Mon Sep 17 00:00:00 2001 From: RogerTaule Date: Mon, 9 Sep 2024 08:56:31 +0200 Subject: [PATCH 1/2] Providing public inputs is now optional --- cli/src/commands/prove.rs | 2 +- cli/src/commands/verify_constraints.rs | 2 +- .../fibonacci-square/src/fibonacci_lib.rs | 29 ++++++++++++------- .../fibonacci-square/src/public_inputs.rs | 2 +- proofman/src/proofman.rs | 8 +++-- proofman/src/witness_library.rs | 2 +- 6 files changed, 28 insertions(+), 17 deletions(-) diff --git a/cli/src/commands/prove.rs b/cli/src/commands/prove.rs index c4fb15ba..72464a7f 100644 --- a/cli/src/commands/prove.rs +++ b/cli/src/commands/prove.rs @@ -51,7 +51,7 @@ pub struct ProveCmd { /// Public inputs path #[clap(short = 'i', long)] - pub public_inputs: PathBuf, + pub public_inputs: Option, /// Setup folder path #[clap(long)] diff --git a/cli/src/commands/verify_constraints.rs b/cli/src/commands/verify_constraints.rs index 547588d3..53679d1e 100644 --- a/cli/src/commands/verify_constraints.rs +++ b/cli/src/commands/verify_constraints.rs @@ -51,7 +51,7 @@ pub struct VerifyConstraintsCmd { /// Public inputs path #[clap(short = 'i', long)] - pub public_inputs: PathBuf, + pub public_inputs: Option, /// Setup folder path #[clap(long)] diff --git a/examples/fibonacci-square/src/fibonacci_lib.rs b/examples/fibonacci-square/src/fibonacci_lib.rs index 1e9afa40..724e4bbf 100644 --- a/examples/fibonacci-square/src/fibonacci_lib.rs +++ b/examples/fibonacci-square/src/fibonacci_lib.rs @@ -15,14 +15,14 @@ use crate::{FibonacciSquare, Pilout, Module}; pub struct FibonacciWitness { pub wcm: WitnessManager, - pub public_inputs_path: PathBuf, + pub public_inputs_path: Option, pub fibonacci: Arc>, pub module: Arc>, pub std_lib: Arc>, } impl FibonacciWitness { - pub fn new(public_inputs_path: PathBuf) -> Self { + pub fn new(public_inputs_path: Option) -> Self { let mut wcm = WitnessManager::new(); let std_lib = Std::new(&mut wcm, None); @@ -35,16 +35,25 @@ impl FibonacciWitness { impl WitnessLibrary for FibonacciWitness { fn start_proof(&mut self, pctx: &mut ProofCtx, ectx: &ExecutionCtx, sctx: &SetupCtx) { - let mut file = File::open(&self.public_inputs_path).unwrap(); + + let public_inputs: FibonacciSquarePublics = if let Some(path) = &self.public_inputs_path { + let mut file = File::open(path).unwrap(); - if !file.metadata().unwrap().is_file() { - panic!("Public inputs file not found"); - } + if !file.metadata().unwrap().is_file() { + panic!("Public inputs file not found"); + } - let mut contents = String::new(); - let _ = file.read_to_string(&mut contents); + let mut contents = String::new(); - let public_inputs: FibonacciSquarePublics = serde_json::from_str(&contents).unwrap(); + let _ = file.read_to_string(&mut contents).map_err(|err| { + format!("Failed to read public inputs file: {}", err) + }); + + serde_json::from_str(&contents).unwrap() + } else { + FibonacciSquarePublics::default() + }; + pctx.public_inputs = public_inputs.into(); self.wcm.start_proof(pctx, ectx, sctx); @@ -70,7 +79,7 @@ impl WitnessLibrary for FibonacciWitness { #[no_mangle] pub extern "Rust" fn init_library( _rom_path: Option, - public_inputs_path: PathBuf, + public_inputs_path: Option, ) -> Result>, Box> { env_logger::builder() .format_timestamp(None) diff --git a/examples/fibonacci-square/src/public_inputs.rs b/examples/fibonacci-square/src/public_inputs.rs index 9b15a717..31ac0624 100644 --- a/examples/fibonacci-square/src/public_inputs.rs +++ b/examples/fibonacci-square/src/public_inputs.rs @@ -1,6 +1,6 @@ use serde::{Deserialize, Serialize}; -#[derive(Debug, Serialize, Deserialize)] +#[derive(Default, Debug, Serialize, Deserialize)] pub struct FibonacciSquarePublics { pub module: u64, pub a: u64, diff --git a/proofman/src/proofman.rs b/proofman/src/proofman.rs index 78040b0e..a6f859cb 100644 --- a/proofman/src/proofman.rs +++ b/proofman/src/proofman.rs @@ -32,7 +32,7 @@ impl ProofMan { pub fn generate_proof( witness_lib_path: PathBuf, rom_path: Option, - public_inputs_path: PathBuf, + public_inputs_path: Option, proving_key_path: PathBuf, output_dir_path: PathBuf, debug_mode: u64, @@ -50,8 +50,10 @@ impl ProofMan { } // Check public_inputs_path is a folder - if !public_inputs_path.exists() { - return Err(format!("Public inputs file not found at path: {:?}", public_inputs_path).into()); + if let Some(publics_path) = public_inputs_path.as_ref() { + if !publics_path.exists() { + return Err(format!("Public inputs file not found at path: {:?}", publics_path).into()); + } } // Check proving_key_path exists diff --git a/proofman/src/witness_library.rs b/proofman/src/witness_library.rs index 3047a361..75092c7c 100644 --- a/proofman/src/witness_library.rs +++ b/proofman/src/witness_library.rs @@ -3,7 +3,7 @@ use std::{error::Error, path::PathBuf}; use proofman_common::{ExecutionCtx, ProofCtx, WitnessPilout, SetupCtx}; /// This is the type of the function that is used to load a witness library. -pub type WitnessLibInitFn = fn(Option, PathBuf) -> Result>, Box>; +pub type WitnessLibInitFn = fn(Option, Option) -> Result>, Box>; pub trait WitnessLibrary { fn start_proof(&mut self, pctx: &mut ProofCtx, ectx: &ExecutionCtx, sctx: &SetupCtx); From 7cbf08fd2aa3e4be2da2bf0897c3c6ef8009dbe6 Mon Sep 17 00:00:00 2001 From: RogerTaule Date: Mon, 9 Sep 2024 09:11:38 +0200 Subject: [PATCH 2/2] Fix format --- proofman/src/witness_library.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/proofman/src/witness_library.rs b/proofman/src/witness_library.rs index 75092c7c..f42f798b 100644 --- a/proofman/src/witness_library.rs +++ b/proofman/src/witness_library.rs @@ -3,7 +3,8 @@ use std::{error::Error, path::PathBuf}; use proofman_common::{ExecutionCtx, ProofCtx, WitnessPilout, SetupCtx}; /// This is the type of the function that is used to load a witness library. -pub type WitnessLibInitFn = fn(Option, Option) -> Result>, Box>; +pub type WitnessLibInitFn = + fn(Option, Option) -> Result>, Box>; pub trait WitnessLibrary { fn start_proof(&mut self, pctx: &mut ProofCtx, ectx: &ExecutionCtx, sctx: &SetupCtx);