You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
<[u8]>::contains does not converge even on fully concrete data (memchr specialization); iter().any verifies in 0.2s #4779
<[u8]>::contains does not converge under Kani even on fully concrete data, while the same predicate written as an explicit scan (iter().any(..)) verifies in ~0.2 s. Core specializes u8-slice contains to a memchr-style routine (SpecSliceContains for u8), and CBMC's symbolic execution appears unable to make progress through it.
We hit this in a production verification suite: three differently-shaped harnesses of a small lookup ([u8; 20]::contains over reserve membership lists) hung for 55–80+ minutes each on CI, including one whose inputs were entirely constant. Replacing the two contains calls with iter().any(|&g| g == id) made the fully symbolic version of the same harness verify in 6.3 s.
Minimal reproduction
#[cfg(kani)]mod verification {/// Does not converge (killed after minutes).#[kani::proof]fncontains_concrete(){let groups:[u8;20] = [0;20];assert!(!groups.contains(&7u8));}/// Same predicate, explicit scan: ~0.2 s.#[kani::proof]fnany_concrete(){let groups:[u8;20] = [0;20];assert!(!groups.iter().any(|&g| g == 7u8));}}
cargo kani --harness any_concrete → VERIFICATION:- SUCCESSFUL, Verification Time: 0.23s. cargo kani --harness contains_concrete → no verdict after 60 s (killed); inside our larger crate the same probe was killed at 150 s, and the real harnesses at 55–80 min.
Environment
kani 0.67.0 (CBMC 6.8.0 as bundled), default flags (no stubs, no unwind bounds)
macOS aarch64 (Apple Silicon) locally; reproduced on ubuntu-latest (x86_64) in CI
edition 2021 crate with no dependencies
Expected
A contains over 20 concrete bytes should be as cheap as the explicit scan — ideally Kani (or the std-library contract shims) would model memchr specializations without symex getting stuck, or at least surface this as a known limitation.
Workaround
An explicit iter().any(..) scan (behavior-identical for prod).
The same memchr path makes str's char-pattern search intractable, which is a much wider blast radius than <[u8]>::contains: str::find(char), str::split(char), contains(char), trim_matches, and anything built on CharSearcher goes through it.
On a string of one byte, with --default-unwind 20 (Kani main at 1640445, CBMC 6.11.0, CBMC capped at 6 GB):
harness (input: one nondeterministic byte)
result
core::str::from_utf8(&b) only
verified, 24.6 s
s.find('.'), s built with from_utf8_unchecked from an ASCII byte
CBMC out of memory after ~99 s
s.split('.').next()
out of memory, ~114 s
b.split(|c| *c == b'.').next() (byte-slice split, no memchr)
verified, 0.55 s
Without an unwind bound, the first three don't produce a verdict within 10 minutes.
Effect on kani autoharness. Over https://github.com/krakenfx/kraken-cli with --bounded-arguments (the default &str bound is 4 bytes), almost every hand-written string parser fails: 22 of the 29 newly harnessed hand-written functions (nearly all taking &str) time out at 120 s or run out of memory. Examples are a two-line version.split('.').next().unwrap_or(version) and .split('.').nth(1).and_then(|m| m.parse().ok()). Lowering --string-bound to 2 or even 1 doesn't help: the same functions still fail, since the cost doesn't come from the string's length. So a model of memchr (or of CharSearcher) would unlock a large share of the string-handling code autoharness reaches.
Activity
feliperodri commentedon Oct 4, 2026
The same
memchrpath makesstr's char-pattern search intractable, which is a much wider blast radius than<[u8]>::contains:str::find(char),str::split(char),contains(char),trim_matches, and anything built onCharSearchergoes through it.On a string of one byte, with
--default-unwind 20(Kanimainat 1640445, CBMC 6.11.0, CBMC capped at 6 GB):core::str::from_utf8(&b)onlys.find('.'),sbuilt withfrom_utf8_uncheckedfrom an ASCII bytes.split('.').next()b.split(|c| *c == b'.').next()(byte-slice split, nomemchr)Without an unwind bound, the first three don't produce a verdict within 10 minutes.
Effect on
kani autoharness. Over https://github.com/krakenfx/kraken-cli with--bounded-arguments(the default&strbound is 4 bytes), almost every hand-written string parser fails: 22 of the 29 newly harnessed hand-written functions (nearly all taking&str) time out at 120 s or run out of memory. Examples are a two-lineversion.split('.').next().unwrap_or(version)and.split('.').nth(1).and_then(|m| m.parse().ok()). Lowering--string-boundto 2 or even 1 doesn't help: the same functions still fail, since the cost doesn't come from the string's length. So a model ofmemchr(or ofCharSearcher) would unlock a large share of the string-handling code autoharness reaches.