-
Notifications
You must be signed in to change notification settings - Fork 27
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 #75
base: main
Are you sure you want to change the base?
Conversation
…aw setting. The substrings are returned as BoundedVec since we don't know their exact length upfront, but we know they're not longer than N. To support both settings (decomposed and raw) we have to use `substring_ranges` instead of `substring_boundaries`.
…gex and input. This fix makes sure this is supported. Changes: - regex_match returns a Vec of substrings instead of an array with known length - per state where substrings have to be extracted; add the byte either to a new substring or an already started one Note that substr_count is used to extract the correct "current" substring from the Vec. This is a workaround - first implementation was using `pop` but this gave an error.
For caret anchor: Mark beginning of input byte array with 255, which makes the check for caret anchor (ˆ) works. Note that ^ is only taken into consideration in the decomposed mode.
…states reachable from state 0. Substrings only get saved when they are part of a path that doesn't reset.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updating the readme to mention the state of Noir support (previously "coming soon").
Also to check that the Theory section is the same for Noir.
Some notes:
|
pinging @olehmisar also, it seems there is not a separate PR for his initial work on the Noir support |
|
@jzaki: Adjusted the Noir status. Wrt the Theory section, the Noir support was aligned to the Circom implementation by testing it for the exact same cases. |
UPDATE: Should have been fixed since noir-lang/noir#6514, do give Noir ≥0.39.0 a spin and see if it helps. |
This PR was previously opened here.
Description
This PR contains implementation of features
gen_substrs
,ˆ
support,$
support and overall bugfixes for the Noir support.This branch has been tested equally as the circom implementation.
All circom tests from the original zk-regex lib have been added in the test-suite. All tests pass with the added features and bugfixes.
ˆ
support is realized by prefixing the input array by 255. This is the same in circom$
support is realized by adding an additional accepting state, to which the previous accepting state transitions for any character. This new state is then added to the accepting states. In the case that$
is at the end of the regex this extra transition is not done and inputs continuing after$
are thus rejected. This solution increases the lookup table size by 255 rowsgen_substrs
lets us extract substrings alongside the regex check. This can be done viadecomposed
orraw
setting.BoundedVec<Field,N>
, because we don't know the exact length beforehandregex_match
function with substring extraction isVec<BoundedVec<Field,N>>
because the total number of substrings is not always known beforehandconsecutive
check in circom)$
is needed also to extract the exact correct substring (otherwise it would just keep extracting until the end of the input)gen_substrs
inraw
to default (this is a change outside of the Noir code, but seemed to make sense)ab
and inputaab
. For the first inputa
it moves into state 1. For the second inputa
it moves into state 0. And then it would stay there. Now, we're adding the possibility for the 2nd occurrence ofa
to move into state 1 again.Note: multiple accepting states that would occur directly from the regex are not supported, same as in the circom impl. (See README comment of original lib here).
This replaces previously opened PRs: noir-lang#2 and noir-lang#1. (Although the steps for manual verification are still valid)
Additional Context
The test suite is built specifically for the Noir zk-regex library. From a database of regex inputs + samples it will generate the required Noir code, create the desired tests and run them. The database has been filled with the equivalents of the tests for circom. Additionally, there are 2 hardcoded test projects for the circom tests that had more complex circuits (combining multiple templates).
PR Checklist*
cargo fmt
on default settings.