Skip to content

Commit

Permalink
refactor!: input to compiler now takes PathBuf
Browse files Browse the repository at this point in the history
  • Loading branch information
0xThemis authored and dkales committed Nov 5, 2024
1 parent 01095b6 commit 9f36774
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 11 deletions.
30 changes: 21 additions & 9 deletions co-circom/circom-mpc-compiler/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ impl Default for CompilerConfig {
/// * [`CoCircomCompiler::parse`]
/// * [`CoCircomCompiler::get_public_inputs`]
pub struct CoCircomCompiler<P: Pairing> {
file: String,
file: PathBuf,
phantom_data: PhantomData<P>,
config: CompilerConfig,
pub(crate) fun_decls: HashMap<String, FunDecl>,
Expand All @@ -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<Pth>(file: Pth, config: CompilerConfig) -> Self
where
PathBuf: From<Pth>,
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(),
Expand All @@ -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,
Expand Down Expand Up @@ -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<Vec<String>> {
pub fn get_public_inputs<Pth>(file: Pth, config: CompilerConfig) -> Result<Vec<String>>
where
PathBuf: From<Pth>,
Pth: std::fmt::Debug,
{
Self::new(file, config).get_public_inputs_inner()
}

Expand All @@ -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<Pth>(
file: Pth,
config: CompilerConfig,
) -> Result<CoCircomCompilerParsed<P::ScalarField>> {
) -> Result<CoCircomCompilerParsed<P::ScalarField>>
where
PathBuf: From<Pth>,
Pth: std::fmt::Debug,
{
Self::new(file, config).parse_inner()
}

Expand Down
2 changes: 1 addition & 1 deletion co-circom/co-circom/src/bin/co-circom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ where
let start = Instant::now();
let shares = co_circom::split_input::<P>(
input.clone(),
circuit,
circuit_path,
config.compiler,
config.seeded,
config.additive,
Expand Down
2 changes: 1 addition & 1 deletion co-circom/co-circom/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@ pub fn parse_witness_share_shamir<R: Read, F: PrimeField>(
/// Splits the input according to the provided parameters.
pub fn split_input<P>(
input: PathBuf,
circuit_path: String,
circuit_path: PathBuf,
config: CompilerConfig,
seeded: bool,
additive: bool,
Expand Down

0 comments on commit 9f36774

Please sign in to comment.