Skip to content

Noir 1.0.0-beta.3 support #93

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

Open
wants to merge 6 commits into
base: feat/new-compiler
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ nfa.json
target
/compiler/pkg
/compiler/.yarn
node_modules

Prover.toml
prover.toml
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/nfa/codegen/noir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ pub fn generate_noir_code(
code.push_str(&format!(" capture_group_ids,\n"));
code.push_str(&format!(" capture_group_starts,\n"));
code.push_str(&format!(
" capture_group_start_indices[{}] - match_start as Field,\n",
" capture_group_start_indices[{}],\n",
capture_group_id - 1
));
code.push_str(&format!(" );\n\n"));
Expand Down
2 changes: 1 addition & 1 deletion noir/scripts/gen_regex.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ codegen_regex() {
--decomposed-regex-path "./noir/templates/${template_name}/${template_name}.json" \
--output-file-path ./noir/templates/${template_name} \
--template-name "$template_name_pascal" \
--noir
--proving-framework noir

mv ./noir/templates/${template_name}/${template_name}_regex.nr ./noir/src/common/${template_name}_regex.nr
sed -i 's/zkregex/crate/g' ./noir/src/common/${template_name}_regex.nr
Expand Down
30 changes: 22 additions & 8 deletions noir/src/common/body_hash_regex.nr
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,19 @@ fn check_accept_state(
accept_state_reached
}

/**
* BodyHashRegex matching function
* Regex: (?:\r\n|^)dkim-signature:(?:[a-z]+=[^;]+; )+bh=([a-zA-Z0-9+/=]+);
* @param in_haystack - The input haystack to search from
* @param match_start - The start index in the haystack for the subarray to match from
* @param match_length - The length of the subarray to extract from haystack
* @param current_states - The current states of the NFA at each index in the match subarray
* @param next_states - The next states of the NFA at each index in the match subarray
* @param capture_group_ids - The ids of the capture groups in the match subarray
* @param capture_group_starts - The start positions of the capture groups in the match subarray
* @param capture_group_start_indices - The start indices of the capture groups in the match subarray
* @return - tuple of substring captures as dictated by the regular expression
*/
pub fn regex_match<let MAX_HAYSTACK_LEN: u32, let MAX_MATCH_LEN: u32>(
in_haystack: [u8; MAX_HAYSTACK_LEN],
match_start: u32,
Expand All @@ -71,7 +84,6 @@ pub fn regex_match<let MAX_HAYSTACK_LEN: u32, let MAX_MATCH_LEN: u32>(
capture_group_starts: [Field; MAX_MATCH_LEN],
capture_group_start_indices: [Field; NUM_CAPTURE_GROUPS],
) -> (BoundedVec<u8, CAPTURE_1_MAX_LENGTH>) {
// regex:"(?:\r\n|^)dkim-signature:(?:[a-z]+=[^;]+; )+bh=([a-zA-Z0-9+/=]+);"
// resize haystack
let haystack: [u8; MAX_MATCH_LEN] = select_subarray(in_haystack, match_start, match_length);

Expand Down Expand Up @@ -100,13 +112,15 @@ pub fn regex_match<let MAX_HAYSTACK_LEN: u32, let MAX_MATCH_LEN: u32>(
);
}
assert(reached_end_state == 0, "Did not reach a valid end state");
// Capture Group 1
let capture_1 = capture_substring::<MAX_MATCH_LEN, CAPTURE_1_MAX_LENGTH, 1>(
haystack,
capture_group_ids,
capture_group_starts,
capture_group_start_indices[0],
);

// Capture Group 1
let capture_1 = capture_substring::<MAX_MATCH_LEN, CAPTURE_1_MAX_LENGTH, 1>(
haystack,
capture_group_ids,
capture_group_starts,
capture_group_start_indices[0],
);

(capture_1)
}

30 changes: 22 additions & 8 deletions noir/src/common/email_addr_regex.nr
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,19 @@ fn check_accept_state(
accept_state_reached
}

/**
* EmailAddrRegex matching function
* Regex: ([A-Za-z0-9!#$%&\'*+=?\\-\\^_`{|}~./@]+@[A-Za-z0-9.\\-]+)
* @param in_haystack - The input haystack to search from
* @param match_start - The start index in the haystack for the subarray to match from
* @param match_length - The length of the subarray to extract from haystack
* @param current_states - The current states of the NFA at each index in the match subarray
* @param next_states - The next states of the NFA at each index in the match subarray
* @param capture_group_ids - The ids of the capture groups in the match subarray
* @param capture_group_starts - The start positions of the capture groups in the match subarray
* @param capture_group_start_indices - The start indices of the capture groups in the match subarray
* @return - tuple of substring captures as dictated by the regular expression
*/
pub fn regex_match<let MAX_HAYSTACK_LEN: u32, let MAX_MATCH_LEN: u32>(
in_haystack: [u8; MAX_HAYSTACK_LEN],
match_start: u32,
Expand All @@ -71,7 +84,6 @@ pub fn regex_match<let MAX_HAYSTACK_LEN: u32, let MAX_MATCH_LEN: u32>(
capture_group_starts: [Field; MAX_MATCH_LEN],
capture_group_start_indices: [Field; NUM_CAPTURE_GROUPS],
) -> (BoundedVec<u8, CAPTURE_1_MAX_LENGTH>) {
// regex:"([A-Za-z0-9!#$%&'*+=?\\-\\^_`{|}~./@]+@[A-Za-z0-9.\\-]+)"
// resize haystack
let haystack: [u8; MAX_MATCH_LEN] = select_subarray(in_haystack, match_start, match_length);

Expand Down Expand Up @@ -100,13 +112,15 @@ pub fn regex_match<let MAX_HAYSTACK_LEN: u32, let MAX_MATCH_LEN: u32>(
);
}
assert(reached_end_state == 0, "Did not reach a valid end state");
// Capture Group 1
let capture_1 = capture_substring::<MAX_MATCH_LEN, CAPTURE_1_MAX_LENGTH, 1>(
haystack,
capture_group_ids,
capture_group_starts,
capture_group_start_indices[0],
);

// Capture Group 1
let capture_1 = capture_substring::<MAX_MATCH_LEN, CAPTURE_1_MAX_LENGTH, 1>(
haystack,
capture_group_ids,
capture_group_starts,
capture_group_start_indices[0],
);

(capture_1)
}

30 changes: 22 additions & 8 deletions noir/src/common/email_domain_regex.nr
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,19 @@ fn check_accept_state(
accept_state_reached
}

/**
* EmailDomainRegex matching function
* Regex: [A-Za-z0-9!#$%&\'*+=?\\-\\^_`{|}~./]+@([A-Za-z0-9.\\-@]+)
* @param in_haystack - The input haystack to search from
* @param match_start - The start index in the haystack for the subarray to match from
* @param match_length - The length of the subarray to extract from haystack
* @param current_states - The current states of the NFA at each index in the match subarray
* @param next_states - The next states of the NFA at each index in the match subarray
* @param capture_group_ids - The ids of the capture groups in the match subarray
* @param capture_group_starts - The start positions of the capture groups in the match subarray
* @param capture_group_start_indices - The start indices of the capture groups in the match subarray
* @return - tuple of substring captures as dictated by the regular expression
*/
pub fn regex_match<let MAX_HAYSTACK_LEN: u32, let MAX_MATCH_LEN: u32>(
in_haystack: [u8; MAX_HAYSTACK_LEN],
match_start: u32,
Expand All @@ -71,7 +84,6 @@ pub fn regex_match<let MAX_HAYSTACK_LEN: u32, let MAX_MATCH_LEN: u32>(
capture_group_starts: [Field; MAX_MATCH_LEN],
capture_group_start_indices: [Field; NUM_CAPTURE_GROUPS],
) -> (BoundedVec<u8, CAPTURE_1_MAX_LENGTH>) {
// regex:"[A-Za-z0-9!#$%&'*+=?\\-\\^_`{|}~./]+@([A-Za-z0-9.\\-@]+)"
// resize haystack
let haystack: [u8; MAX_MATCH_LEN] = select_subarray(in_haystack, match_start, match_length);

Expand Down Expand Up @@ -100,13 +112,15 @@ pub fn regex_match<let MAX_HAYSTACK_LEN: u32, let MAX_MATCH_LEN: u32>(
);
}
assert(reached_end_state == 0, "Did not reach a valid end state");
// Capture Group 1
let capture_1 = capture_substring::<MAX_MATCH_LEN, CAPTURE_1_MAX_LENGTH, 1>(
haystack,
capture_group_ids,
capture_group_starts,
capture_group_start_indices[0],
);

// Capture Group 1
let capture_1 = capture_substring::<MAX_MATCH_LEN, CAPTURE_1_MAX_LENGTH, 1>(
haystack,
capture_group_ids,
capture_group_starts,
capture_group_start_indices[0],
);

(capture_1)
}

11 changes: 10 additions & 1 deletion noir/src/common/simple_regex.nr
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,22 @@ fn check_accept_state(
accept_state_reached
}

/**
* SimpleRegex matching function
* Regex: a*b
* @param in_haystack - The input haystack to search from
* @param match_start - The start index in the haystack for the subarray to match from
* @param match_length - The length of the subarray to extract from haystack
* @param current_states - The current states of the NFA at each index in the match subarray
* @param next_states - The next states of the NFA at each index in the match subarray
*/
pub fn regex_match<let MAX_HAYSTACK_LEN: u32, let MAX_MATCH_LEN: u32>(
in_haystack: [u8; MAX_HAYSTACK_LEN],
match_start: u32,
match_length: u32,
current_states: [Field; MAX_MATCH_LEN],
next_states: [Field; MAX_MATCH_LEN],
) {
// regex:"a*b"
// resize haystack
let haystack: [u8; MAX_MATCH_LEN] = select_subarray(in_haystack, match_start, match_length);

Expand All @@ -92,5 +100,6 @@ pub fn regex_match<let MAX_HAYSTACK_LEN: u32, let MAX_MATCH_LEN: u32>(
);
}
assert(reached_end_state == 0, "Did not reach a valid end state");

}

30 changes: 22 additions & 8 deletions noir/src/common/subject_all_regex.nr
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,19 @@ fn check_accept_state(
accept_state_reached
}

/**
* SubjectAllRegex matching function
* Regex: (?:\r\n|^)subject:([a-z]+)\r\n
* @param in_haystack - The input haystack to search from
* @param match_start - The start index in the haystack for the subarray to match from
* @param match_length - The length of the subarray to extract from haystack
* @param current_states - The current states of the NFA at each index in the match subarray
* @param next_states - The next states of the NFA at each index in the match subarray
* @param capture_group_ids - The ids of the capture groups in the match subarray
* @param capture_group_starts - The start positions of the capture groups in the match subarray
* @param capture_group_start_indices - The start indices of the capture groups in the match subarray
* @return - tuple of substring captures as dictated by the regular expression
*/
pub fn regex_match<let MAX_HAYSTACK_LEN: u32, let MAX_MATCH_LEN: u32>(
in_haystack: [u8; MAX_HAYSTACK_LEN],
match_start: u32,
Expand All @@ -71,7 +84,6 @@ pub fn regex_match<let MAX_HAYSTACK_LEN: u32, let MAX_MATCH_LEN: u32>(
capture_group_starts: [Field; MAX_MATCH_LEN],
capture_group_start_indices: [Field; NUM_CAPTURE_GROUPS],
) -> (BoundedVec<u8, CAPTURE_1_MAX_LENGTH>) {
// regex:"(?:\r\n|^)subject:([a-z]+)\r\n"
// resize haystack
let haystack: [u8; MAX_MATCH_LEN] = select_subarray(in_haystack, match_start, match_length);

Expand Down Expand Up @@ -100,13 +112,15 @@ pub fn regex_match<let MAX_HAYSTACK_LEN: u32, let MAX_MATCH_LEN: u32>(
);
}
assert(reached_end_state == 0, "Did not reach a valid end state");
// Capture Group 1
let capture_1 = capture_substring::<MAX_MATCH_LEN, CAPTURE_1_MAX_LENGTH, 1>(
haystack,
capture_group_ids,
capture_group_starts,
capture_group_start_indices[0],
);

// Capture Group 1
let capture_1 = capture_substring::<MAX_MATCH_LEN, CAPTURE_1_MAX_LENGTH, 1>(
haystack,
capture_group_ids,
capture_group_starts,
capture_group_start_indices[0],
);

(capture_1)
}

30 changes: 22 additions & 8 deletions noir/src/common/timestamp_regex.nr
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,19 @@ fn check_accept_state(
accept_state_reached
}

/**
* TimestampRegex matching function
* Regex: (?:\r\n|^)dkim-signature:(?:[a-z]+=[^;]+; )+t=([0-9]+);
* @param in_haystack - The input haystack to search from
* @param match_start - The start index in the haystack for the subarray to match from
* @param match_length - The length of the subarray to extract from haystack
* @param current_states - The current states of the NFA at each index in the match subarray
* @param next_states - The next states of the NFA at each index in the match subarray
* @param capture_group_ids - The ids of the capture groups in the match subarray
* @param capture_group_starts - The start positions of the capture groups in the match subarray
* @param capture_group_start_indices - The start indices of the capture groups in the match subarray
* @return - tuple of substring captures as dictated by the regular expression
*/
pub fn regex_match<let MAX_HAYSTACK_LEN: u32, let MAX_MATCH_LEN: u32>(
in_haystack: [u8; MAX_HAYSTACK_LEN],
match_start: u32,
Expand All @@ -71,7 +84,6 @@ pub fn regex_match<let MAX_HAYSTACK_LEN: u32, let MAX_MATCH_LEN: u32>(
capture_group_starts: [Field; MAX_MATCH_LEN],
capture_group_start_indices: [Field; NUM_CAPTURE_GROUPS],
) -> (BoundedVec<u8, CAPTURE_1_MAX_LENGTH>) {
// regex:"(?:\r\n|^)dkim-signature:(?:[a-z]+=[^;]+; )+t=([0-9]+);"
// resize haystack
let haystack: [u8; MAX_MATCH_LEN] = select_subarray(in_haystack, match_start, match_length);

Expand Down Expand Up @@ -100,13 +112,15 @@ pub fn regex_match<let MAX_HAYSTACK_LEN: u32, let MAX_MATCH_LEN: u32>(
);
}
assert(reached_end_state == 0, "Did not reach a valid end state");
// Capture Group 1
let capture_1 = capture_substring::<MAX_MATCH_LEN, CAPTURE_1_MAX_LENGTH, 1>(
haystack,
capture_group_ids,
capture_group_starts,
capture_group_start_indices[0],
);

// Capture Group 1
let capture_1 = capture_substring::<MAX_MATCH_LEN, CAPTURE_1_MAX_LENGTH, 1>(
haystack,
capture_group_ids,
capture_group_starts,
capture_group_start_indices[0],
);

(capture_1)
}

30 changes: 22 additions & 8 deletions noir/src/common/to_all_regex.nr
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,19 @@ fn check_accept_state(
accept_state_reached
}

/**
* ToAllRegex matching function
* Regex: (?:\r\n|^)to:([^\r\n]+)\r\n
* @param in_haystack - The input haystack to search from
* @param match_start - The start index in the haystack for the subarray to match from
* @param match_length - The length of the subarray to extract from haystack
* @param current_states - The current states of the NFA at each index in the match subarray
* @param next_states - The next states of the NFA at each index in the match subarray
* @param capture_group_ids - The ids of the capture groups in the match subarray
* @param capture_group_starts - The start positions of the capture groups in the match subarray
* @param capture_group_start_indices - The start indices of the capture groups in the match subarray
* @return - tuple of substring captures as dictated by the regular expression
*/
pub fn regex_match<let MAX_HAYSTACK_LEN: u32, let MAX_MATCH_LEN: u32>(
in_haystack: [u8; MAX_HAYSTACK_LEN],
match_start: u32,
Expand All @@ -71,7 +84,6 @@ pub fn regex_match<let MAX_HAYSTACK_LEN: u32, let MAX_MATCH_LEN: u32>(
capture_group_starts: [Field; MAX_MATCH_LEN],
capture_group_start_indices: [Field; NUM_CAPTURE_GROUPS],
) -> (BoundedVec<u8, CAPTURE_1_MAX_LENGTH>) {
// regex:"(?:\r\n|^)to:([^\r\n]+)\r\n"
// resize haystack
let haystack: [u8; MAX_MATCH_LEN] = select_subarray(in_haystack, match_start, match_length);

Expand Down Expand Up @@ -100,13 +112,15 @@ pub fn regex_match<let MAX_HAYSTACK_LEN: u32, let MAX_MATCH_LEN: u32>(
);
}
assert(reached_end_state == 0, "Did not reach a valid end state");
// Capture Group 1
let capture_1 = capture_substring::<MAX_MATCH_LEN, CAPTURE_1_MAX_LENGTH, 1>(
haystack,
capture_group_ids,
capture_group_starts,
capture_group_start_indices[0],
);

// Capture Group 1
let capture_1 = capture_substring::<MAX_MATCH_LEN, CAPTURE_1_MAX_LENGTH, 1>(
haystack,
capture_group_ids,
capture_group_starts,
capture_group_start_indices[0],
);

(capture_1)
}

Loading