-
Notifications
You must be signed in to change notification settings - Fork 34
Add string search circuit example using lib (#31) #81
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
base: master
Are you sure you want to change the base?
Add string search circuit example using lib (#31) #81
Conversation
Hi @critesjosh and @signorecello 👋, Just a gentle reminder to please take a moment to review this PR when you get a chance. Thanks a lot for your time and support! |
Just did a quick pass with Claude. do you agree with this analysis? Issues Found
The documentation comments and implementation are contradictory and incorrect:
Problem: The code calls haystack_body.substring_match(needle_body) on line 23 before checking edge cases. According to proper usage, the library should handle the search internally. Actual behavior with empty needle: An empty needle conventionally matches at position 0, but this depends on the library's implementation. The code returns found=true when
The README claims:
Otherwise, it returns (false, 0). This is false. The code at main.nr:23 calls substring_match() unconditionally, then applies selector logic to potentially override the result. The library is always invoked.
README line 69 claims tests cover "Needle longer than haystack" but no such test exists in test_inputs.nr. The tests only cover positive matches.
Line 9 documents that empty needle returns found=true, but this is questionable. In most string search semantics, an empty needle should either:
The current implementation chooses the third option without justification.
Lines 29-35 use Field arithmetic for selector logic (bool_to_field, line 4-6), but this could be simplified with direct boolean logic since Noir supports conditional expressions. What's Correct
Recommendations
|
Thank you for taking the time to do such a detailed review and for running this through Claude 🙏. I agree with your points on the logic error, README mismatch, missing edge case tests, and the semantic ambiguity around empty needles. I’ll:
I’ll push these corrections in the next update. |
…d README, and comprehensive tests
Hi @critesjosh Thank you very much for your thoughtful review and valuable feedback on this project. Following your recommendations, I have carefully revised the project to ensure it aligns fully with Noir best practices and circuit safety standards. Specifically:
These updates make the circuit more robust, compliant with your feedback, and better suited for both educational and practical zero-knowledge use cases. Thank you once again for your insightful feedback and guidance — it has been instrumental in refining this work. |
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.