Skip to content

Commit

Permalink
Merge pull request #66 from shreyas-londhe/feat/audit-fixes
Browse files Browse the repository at this point in the history
Feat: Compiler Refactor & Audit Fixes
  • Loading branch information
Bisht13 authored Aug 23, 2024
2 parents e1da33f + 57e3483 commit 4cbc5c5
Show file tree
Hide file tree
Showing 11 changed files with 2,435 additions and 1,322 deletions.
122 changes: 92 additions & 30 deletions packages/compiler/src/bin/compiler.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,52 @@
use clap::{Parser, Subcommand};
//! ZK Regex Compiler CLI
//!
//! This binary provides a command-line interface for the ZK Regex Compiler.
//! It supports two main commands: `Decomposed` for working with decomposed regex files,
//! and `Raw` for working with raw regex strings.
//!
//! # Usage
//!
//! ## Decomposed Command
//! Process a decomposed regex file:
//!
//! ```
//! zk-regex decomposed --decomposed-regex-path <PATH> [OPTIONS]
//! ```
//!
//! Options:
//! - `-d, --decomposed-regex-path <PATH>`: Path to the decomposed regex JSON file (required)
//! - `-h, --halo2-dir-path <PATH>`: Directory path for Halo2 output
//! - `-c, --circom-file-path <PATH>`: File path for Circom output
//! - `-t, --template-name <NAME>`: Template name
//! - `-g, --gen-substrs`: Generate substrings
//!
//! Example:
//! ```
//! zk-regex decomposed -d regex.json -h ./halo2_output -c ./circom_output.circom -t MyTemplate -g true
//! ```
//!
//! ## Raw Command
//! Process a raw regex string:
//!
//! ```
//! zk-regex raw --raw-regex <REGEX> [OPTIONS]
//! ```
//!
//! Options:
//! - `-r, --raw-regex <REGEX>`: Raw regex string (required)
//! - `-s, --substrs-json-path <PATH>`: Path to substrings JSON file
//! - `-h, --halo2-dir-path <PATH>`: Directory path for Halo2 output
//! - `-c, --circom-file-path <PATH>`: File path for Circom output
//! - `-t, --template-name <NAME>`: Template name
//! - `-g, --gen-substrs`: Generate substrings
//!
//! Example:
//! ```
//! zk-regex raw -r "a*b+c?" -s substrings.json -h ./halo2_output -c ./circom_output.circom -t MyTemplate -g true
//! ```

use zk_regex_compiler::*;
use clap::{Parser, Subcommand};
use zk_regex_compiler::{gen_from_decomposed, gen_from_raw};

#[derive(Parser, Debug, Clone)]
#[command(author, version, about, long_about = None)]
Expand Down Expand Up @@ -42,37 +88,53 @@ enum Commands {
fn main() {
let cli = Cli::parse();
match cli.command {
Commands::Decomposed {
decomposed_regex_path,
halo2_dir_path,
circom_file_path,
template_name,
Commands::Decomposed { .. } => process_decomposed(cli),
Commands::Raw { .. } => process_raw(cli),
}
}

fn process_decomposed(cli: Cli) {
if let Commands::Decomposed {
decomposed_regex_path,
halo2_dir_path,
circom_file_path,
template_name,
gen_substrs,
} = cli.command
{
if let Err(e) = gen_from_decomposed(
&decomposed_regex_path,
halo2_dir_path.as_deref(),
circom_file_path.as_deref(),
template_name.as_deref(),
gen_substrs,
} => {
gen_from_decomposed(
&decomposed_regex_path,
halo2_dir_path.as_ref().map(|s| s.as_str()),
circom_file_path.as_ref().map(|s| s.as_str()),
template_name.as_ref().map(|s| s.as_str()),
gen_substrs,
);
) {
eprintln!("Error: {}", e);
std::process::exit(1);
}
Commands::Raw {
raw_regex,
substrs_json_path,
halo2_dir_path,
circom_file_path,
template_name,
}
}

fn process_raw(cli: Cli) {
if let Commands::Raw {
raw_regex,
substrs_json_path,
halo2_dir_path,
circom_file_path,
template_name,
gen_substrs,
} = cli.command
{
if let Err(e) = gen_from_raw(
&raw_regex,
substrs_json_path.as_deref(),
halo2_dir_path.as_deref(),
circom_file_path.as_deref(),
template_name.as_deref(),
gen_substrs,
} => {
gen_from_raw(
&raw_regex,
substrs_json_path.as_ref().map(|s| s.as_str()),
halo2_dir_path.as_ref().map(|s| s.as_str()),
circom_file_path.as_ref().map(|s| s.as_str()),
template_name.as_ref().map(|s| s.as_str()),
gen_substrs,
);
) {
eprintln!("Error: {}", e);
std::process::exit(1);
}
}
}
Loading

0 comments on commit 4cbc5c5

Please sign in to comment.