From 9f36774f0ff93c3c3abd28efae6599fc531bb1fb Mon Sep 17 00:00:00 2001 From: Franco Nieddu Date: Tue, 29 Oct 2024 14:24:23 +0100 Subject: [PATCH] refactor!: input to compiler now takes PathBuf --- co-circom/circom-mpc-compiler/src/lib.rs | 30 +++++++++++++++++------- co-circom/co-circom/src/bin/co-circom.rs | 2 +- co-circom/co-circom/src/lib.rs | 2 +- 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/co-circom/circom-mpc-compiler/src/lib.rs b/co-circom/circom-mpc-compiler/src/lib.rs index dacbd8d12..2d3c17c8b 100644 --- a/co-circom/circom-mpc-compiler/src/lib.rs +++ b/co-circom/circom-mpc-compiler/src/lib.rs @@ -104,7 +104,7 @@ impl Default for CompilerConfig { /// * [`CoCircomCompiler::parse`] /// * [`CoCircomCompiler::get_public_inputs`] pub struct CoCircomCompiler { - file: String, + file: PathBuf, phantom_data: PhantomData

, config: CompilerConfig, pub(crate) fun_decls: HashMap, @@ -119,10 +119,14 @@ where P::ScalarField: CircomArkworksPrimeFieldBridge, { // only internally to hold the state - fn new(file: String, config: CompilerConfig) -> Self { - tracing::debug!("creating compiler for circuit {file} with config: {config:?}"); + fn new(file: Pth, config: CompilerConfig) -> Self + where + PathBuf: From, + Pth: std::fmt::Debug, + { + tracing::debug!("creating compiler for circuit {file:?} with config: {config:?}"); Self { - file, + file: PathBuf::from(file), config, current_code_block: vec![], fun_decls: HashMap::new(), @@ -138,7 +142,7 @@ where field.to_bytes_be().as_slice(), ); match circom_parser::run_parser( - self.file.clone(), + self.file.display().to_string(), &self.config.version, self.config.link_library.clone(), &field_dig, @@ -607,7 +611,11 @@ where /// /// - `Ok(inputs)` contains a vector of public inputs as strings. /// - `Err(err)` indicates an error occurred during parsing or compilation. - pub fn get_public_inputs(file: String, config: CompilerConfig) -> Result> { + pub fn get_public_inputs(file: Pth, config: CompilerConfig) -> Result> + where + PathBuf: From, + Pth: std::fmt::Debug, + { Self::new(file, config).get_public_inputs_inner() } @@ -624,10 +632,14 @@ where /// - `Ok(parsed)` contains the parsed compiler, which can be used to construct the MPC-VM. /// Refer to its [documentation](CoCircomCompilerParsed) for usage details. /// - `Err(err)` indicates an error occurred during parsing or compilation. - pub fn parse( - file: String, + pub fn parse( + file: Pth, config: CompilerConfig, - ) -> Result> { + ) -> Result> + where + PathBuf: From, + Pth: std::fmt::Debug, + { Self::new(file, config).parse_inner() } diff --git a/co-circom/co-circom/src/bin/co-circom.rs b/co-circom/co-circom/src/bin/co-circom.rs index cc7aa3821..01f703577 100644 --- a/co-circom/co-circom/src/bin/co-circom.rs +++ b/co-circom/co-circom/src/bin/co-circom.rs @@ -283,7 +283,7 @@ where let start = Instant::now(); let shares = co_circom::split_input::

( input.clone(), - circuit, + circuit_path, config.compiler, config.seeded, config.additive, diff --git a/co-circom/co-circom/src/lib.rs b/co-circom/co-circom/src/lib.rs index bece4042f..ad60ccb56 100644 --- a/co-circom/co-circom/src/lib.rs +++ b/co-circom/co-circom/src/lib.rs @@ -627,7 +627,7 @@ pub fn parse_witness_share_shamir( /// Splits the input according to the provided parameters. pub fn split_input

( input: PathBuf, - circuit_path: String, + circuit_path: PathBuf, config: CompilerConfig, seeded: bool, additive: bool,