Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Features/HC improvements for zk-regex Noir support #8

Closed
wants to merge 9 commits into from
12 changes: 10 additions & 2 deletions packages/compiler/src/bin/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,14 @@ enum Commands {
Decomposed {
#[arg(short, long)]
decomposed_regex_path: String,
#[arg(short, long)]
#[arg(long)]
halo2_dir_path: Option<String>,
#[arg(short, long)]
circom_file_path: Option<String>,
#[arg(short, long)]
template_name: Option<String>,
#[arg(long)]
noir_file_path: Option<String>,
#[arg(short, long)]
gen_substrs: Option<bool>,
},
Expand All @@ -74,12 +76,14 @@ enum Commands {
raw_regex: String,
#[arg(short, long)]
substrs_json_path: Option<String>,
#[arg(short, long)]
#[arg(long)]
halo2_dir_path: Option<String>,
#[arg(short, long)]
circom_file_path: Option<String>,
#[arg(short, long)]
template_name: Option<String>,
#[arg(long)]
noir_file_path: Option<String>,
#[arg(short, long)]
gen_substrs: Option<bool>,
},
Expand All @@ -99,6 +103,7 @@ fn process_decomposed(cli: Cli) {
halo2_dir_path,
circom_file_path,
template_name,
noir_file_path,
gen_substrs,
} = cli.command
{
Expand All @@ -107,6 +112,7 @@ fn process_decomposed(cli: Cli) {
halo2_dir_path.as_deref(),
circom_file_path.as_deref(),
template_name.as_deref(),
noir_file_path.as_deref(),
gen_substrs,
) {
eprintln!("Error: {}", e);
Expand All @@ -122,6 +128,7 @@ fn process_raw(cli: Cli) {
halo2_dir_path,
circom_file_path,
template_name,
noir_file_path,
gen_substrs,
} = cli.command
{
Expand All @@ -131,6 +138,7 @@ fn process_raw(cli: Cli) {
halo2_dir_path.as_deref(),
circom_file_path.as_deref(),
template_name.as_deref(),
noir_file_path.as_deref(),
gen_substrs,
) {
eprintln!("Error: {}", e);
Expand Down
13 changes: 12 additions & 1 deletion packages/compiler/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
mod circom;
mod errors;
mod halo2;
mod noir;
mod regex;
mod structs;
mod wasm;
Expand All @@ -9,6 +10,7 @@ use circom::gen_circom_template;
use errors::CompilerError;
use halo2::gen_halo2_tables;
use itertools::Itertools;
use noir::gen_noir_fn;
use regex::{create_regex_and_dfa_from_str_and_defs, get_regex_and_dfa};
use std::{fs::File, path::PathBuf};
use structs::{DecomposedRegexConfig, RegexAndDFA, SubstringDefinitionsJson};
Expand Down Expand Up @@ -55,6 +57,7 @@ fn generate_outputs(
halo2_dir_path: Option<&str>,
circom_file_path: Option<&str>,
circom_template_name: Option<&str>,
noir_file_path: Option<&str>,
num_public_parts: usize,
gen_substrs: bool,
) -> Result<(), CompilerError> {
Expand Down Expand Up @@ -86,6 +89,10 @@ fn generate_outputs(
)?;
}

if let Some(noir_file_path) = noir_file_path {
gen_noir_fn(regex_and_dfa, &PathBuf::from(noir_file_path), gen_substrs)?;
}

Ok(())
}

Expand All @@ -107,6 +114,7 @@ pub fn gen_from_decomposed(
halo2_dir_path: Option<&str>,
circom_file_path: Option<&str>,
circom_template_name: Option<&str>,
noir_file_path: Option<&str>,
gen_substrs: Option<bool>,
) -> Result<(), CompilerError> {
let mut decomposed_regex_config: DecomposedRegexConfig =
Expand All @@ -126,6 +134,7 @@ pub fn gen_from_decomposed(
halo2_dir_path,
circom_file_path,
circom_template_name,
noir_file_path,
num_public_parts,
gen_substrs,
)?;
Expand Down Expand Up @@ -153,20 +162,22 @@ pub fn gen_from_raw(
halo2_dir_path: Option<&str>,
circom_file_path: Option<&str>,
template_name: Option<&str>,
noir_file_path: Option<&str>,
gen_substrs: Option<bool>,
) -> Result<(), CompilerError> {
let substrs_defs_json = load_substring_definitions_json(substrs_json_path)?;
let num_public_parts = substrs_defs_json.transitions.len();

let regex_and_dfa = create_regex_and_dfa_from_str_and_defs(raw_regex, substrs_defs_json)?;

let gen_substrs = gen_substrs.unwrap_or(true);
let gen_substrs = gen_substrs.unwrap_or(false);

generate_outputs(
&regex_and_dfa,
halo2_dir_path,
circom_file_path,
template_name,
noir_file_path,
num_public_parts,
gen_substrs,
)?;
Expand Down
Loading