{"id":22227229,"url":"https://github.com/noir-lang/noir_string_search","last_synced_at":"2025-07-27T19:30:58.006Z","repository":{"id":250888808,"uuid":"831479080","full_name":"noir-lang/noir_string_search","owner":"noir-lang","description":null,"archived":false,"fork":false,"pushed_at":"2025-06-05T12:47:34.000Z","size":224,"stargazers_count":13,"open_issues_count":1,"forks_count":7,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-05T13:43:41.449Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Noir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/noir-lang.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2024-07-20T17:08:46.000Z","updated_at":"2025-06-05T12:47:18.000Z","dependencies_parsed_at":"2024-09-18T02:28:01.693Z","dependency_job_id":"f1f5df03-a58c-4253-a811-55e73c67bc48","html_url":"https://github.com/noir-lang/noir_string_search","commit_stats":null,"previous_names":["noir-lang/noir_string_search"],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/noir-lang/noir_string_search","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/noir-lang%2Fnoir_string_search","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/noir-lang%2Fnoir_string_search/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/noir-lang%2Fnoir_string_search/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/noir-lang%2Fnoir_string_search/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/noir-lang","download_url":"https://codeload.github.com/noir-lang/noir_string_search/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/noir-lang%2Fnoir_string_search/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267413362,"owners_count":24083422,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-27T02:00:11.917Z","response_time":82,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-03T01:01:25.528Z","updated_at":"2025-07-27T19:30:57.967Z","avatar_url":"https://github.com/noir-lang.png","language":"Noir","funding_links":[],"categories":["Libraries"],"sub_categories":["Data Type Manipulation"],"readme":"# noir_string_search\n\nA noir library that can be used to prove that a given \"needle\" substring is present within a larger \"haystack\" string.\n\nFeatures:\n\n- Both the needle and haystack string can have variable runtime lengths (up to a defined maximum)\n- Efficient implementation ~2 gates per haystack byte, ~5 gates per needle byte\n- Both needle and haystack strings can be dynamically constructed in-circuit if required\n\n## Noir version compatibility\n\nThis library is tested with all Noir stable releases from v0.36.0.\n\n## Typedefs\n\nMultiple type definitions represent different hardcoded maximum lengths for the needle/haystack:\n\n```\nHaystack types ranging from 32 max bytes to 16,384 max bytes\nStringBody32\nStringBody64\nStringBody128\nStringBody256\nStringBody512\nStringBody1024\nStringBody2048\nStringBody4096\nStringBody8192\nStringBody16384\n```\n\n```\nNeedle types ranging from 32 bytes to 1,024 max bytes\nSubString32\nSubString64\nSubString128\nSubString256\nSubString512\nSubString1024\n```\n\n## Usage\n\n### Basic usage\n\n```rust\nlet haystack_text = \"the quick brown fox jumped over the lazy dog\".as_bytes();\nlet needle_text = \" the lazy dog\".as_bytes();\n\nlet haystack: StringBody64 = StringBody::new(haystack_text, haystack_text.len());\nlet needle: SubString32 = SubString::new(needle_text, needle_text.len());\n\nlet (result, match_position): (bool, u32) = haystack.substring_match(needle);\n```\n\n### Dynamic needle construction\n\n```rust\nfn validate_account(padded_email_text: [u8; 8192], padded_username: [u8; 100], username_length: u32) {\n\n    let needle_text_init = \"account recovery for\".as_bytes();\n\n    let needle_start: SubString32 = SubString::new(needle_text_init, needle_text_init.len());\n    let needle_end: SubString128 = SubString::new(padded_username, username_length);\n    // use concat_into because SubString128 \u003e SubString32\n    let needle = needle_start.concat_into(needle_end);\n\n    let haystack: StringBody8192 = StringBody::new(padded_email_text, 8192);\n    let (result, match_position): (bool, u32) = haystack.substring_match(needle);\n}\n```\n\n### Costs\n\nMatching a SubString128 with a StringBody1024 costs 6,630 gates (as of noir 0.32.0 and bb 0.46.1)\n\nGate breakdown:\n\n- 2,740 gates: constructing a 14-bit range table\n- 1,280 gates: constructing a 1,024 size `u8` array\n- 160 gates: constructing a 128 size `u8` array\n- 2,444 gates: string matching algorithm\n\nSome rough measurements:\n\n| Haystack Bytes | Needle Bytes | Total Cost | Cost minus range table and byte array init costs |\n| -------------- | ------------ | ---------- | ------------------------------------------------ |\n| 1,024          | 128          | 6,630      | 2,444                                            |\n| 1,024          | 256          | 7,633      | 3,293                                            |\n| 2,048          | 128          | 8,471      | 3,011                                            |\n| 2,048          | 256          | 9,474      | 3,854                                            |\n\nExtrapolating from this table for some very rough estimates: costs for `substring_match` (excluding range table and byte array init costs) are ~6.5 gates per needle byte, ~0.5 gates per haystack byte and a ~1,100 gate constant cost.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnoir-lang%2Fnoir_string_search","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnoir-lang%2Fnoir_string_search","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnoir-lang%2Fnoir_string_search/lists"}