Closed shreyas-londhe closed 1 month ago
Can we add an option for someone to constrain 'only one' or something, meaning that if its on it checks the rest of the string, and if any other substring matches then it returns an argument of 0? Can you also calculate r automatically with fiat shamir on all the inputs? So like the query string, the large string, and the index?
@Divide-By-0
Can we add an option for someone to constrain 'only one' or something, meaning that if its on it checks the rest of the string, and if any other substring matches then it returns an argument of 0?
I think these are two different use cases:
The current template is optimised to follow Case 1.
What I suggest we can do is, we can have two variations for the two cases. For Case 2, we can use Zac's string search algorithm (https://github.com/noir-lang/noir_string_search) which is efficient for that case.
Description
This PR introduces a new circom template called
SubstringMatch
that verifies if a given substring exists within a larger string at a specified index.The
SubstringMatch
template uses a Random Linear Combination (RLC) approach to perform efficient substring comparisons. This method allows for constant-time verification regardless of the input string length, making it suitable for use in zk-SNARKs.Type of Change
Functionality and Usage Example
The
SubstringMatch
template takes the following parameters and inputs:Parameters:
maxLength
: The maximum length of the input stringmaxSubstringLength
: The maximum length of the substring to be matchedInputs:
in
: An array of ASCII values representing the input stringstartIndex
: The starting index of the substring in the input stringrevealedString
: An array of ASCII values representing the substring to be matchedr
: A random value used for the RLC calculationOutput:
isValid
: A signal that is 1 if the substring matches at the given index, 0 otherwiseExample usage:
This example demonstrates how to use the
SubstringMatch
template to verify that the substring "World" exists within the string "Hello, World!" starting at index 7.Checklist: