Features/HC improvements for zk-regex Noir support #75
+286
−3
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.