Introduction
In software verification and security analysis, a recurring challenge is determining whether a string exists that satisfies a specific set of constraints. For instance, a security analyzer might need to verify if a user-provided input can simultaneously match a complex regular expression (regex) and possess a specific length that triggers a buffer overflow. This paper introduces Z3str3RE, a high-performance Satisfiability Modulo Theories (SMT) solver specifically designed to handle the intersection of regex membership and string length constraints ($T_{LRE}$).
The Computational Complexity of String Constraints
Solving string constraints is notoriously difficult. Most modern solvers rely on automata-based approaches, converting regexes into finite state machines. However, these methods face two primary hurdles:
- State Space Explosion: Operations like regex intersection can lead to an exponential increase in the number of states.
- Length Integration: Reasoning about the mathematical length of a string alongside its structural regex constraints is complex, as length constraints often introduce disjunctions that overwhelm standard solvers.
Methodology: A Length-Aware, Lazy Approach
Z3str3RE, implemented within the Z3 theorem prover, employs a "length-aware" and "lazy" philosophy to mitigate these challenges.
Lazy Length Abstraction
Rather than constructing a full automaton immediately, the solver first extracts a system of linear integer equations representing the possible lengths of strings accepted by a regex. If these lengths are incompatible with the arithmetic constraints, the solver can conclude "unsatisfiable" without performing expensive automata constructions.
Cost-Based Heuristics and Over-Approximation
The solver utilizes cost-based heuristics to estimate the computational expense of automata operations (e.g., intersection or complement), prioritizing "cheaper" operations to find contradictions early. Additionally, a Prefix/Suffix Over-Approximation technique acts as a fast filter; by examining only the boundary characters allowed by a regex, the solver can often prove empty intersections "by inspection."
Refinement Loop
Z3str3RE maintains a symbiotic feedback loop with Z3’s internal arithmetic engine. Length assignments from the arithmetic engine are used to prune the search space for the regex engine, and vice versa.
Experimental Evaluation
The authors evaluated Z3str3RE against a massive suite of 57,256 regex-heavy instances, including:
- AutomatArk: Industrial regex queries.
- RegEx-Collected: Instances from benchmarks like AppScan and Kaluza.
- StringFuzz: Pathological constraints designed to stress-test solvers.
Nearly 75% of these instances are derived from industrial applications, ensuring a practical and robust evaluation.
Key Results
Z3str3RE significantly outperformed state-of-the-art solvers including CVC4, OSTRICH, and its predecessor Z3str3.
- Performance: It achieved a 2.4x speedup over CVC4 and a 13x speedup over OSTRICH.
- Solvability: The tool solved over 10,000 more cases than Z3str3.
- Reliability: Across the entire 57k+ instance benchmark, Z3str3RE produced zero soundness errors and zero crashes.
Conclusion and Future Work
Z3str3RE demonstrates that treating length as a primary filtering mechanism and employing lazy, cost-aware heuristics can dramatically improve the efficiency of string constraint solving. While highly effective for $T_{LRE}$, future work aims to extend these techniques to handle string concatenation, substring operations, and string-to-integer conversions, which are critical for modern web application security analysis.
Summary updated