Add string search circuit example using lib (#31) #81
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.
Description
This pull request introduces a robust, circuit-friendly wrapper for substring search using the
noir_string_search
library. The circuit,substring_search
, validates input lengths with assertions and then always calls the underlying library function, using selector logic to guarantee correct output for all cases. This approach ensures the circuit is safe for zero-knowledge proof systems by avoiding control flow branching and handling all edge cases arithmetically.(true, 0)
, following standard library behavior.(false, 0)
.Selector logic is used to mask the result of the library call as appropriate, ensuring all outputs are circuit-safe and preventing assertion failures or panics.
Problem
Addresses the need for a practical example demonstrating integration with the
noir_string_search
library (see noir-examples#31). This implementation demonstrates best practices for integrating external Noir libraries into real-world applications, particularly in the context of zero-knowledge circuits.Summary
(true, 0)
for empty needles (matching standard substring search behavior), and(false, 0)
for needles longer than the haystack.(bool, u32)
for clarity and compatibility with thenoir_string_search
contract.Additional Context
PR Checklist
cargo fmt
on default settings.