Abstract
String constraint solving is a cornerstone of modern software verification and web security. However, traditional methods often struggle with scalability when handling long strings or complex equalities. This paper introduces SWEEP, a high-performance algorithm that utilizes a compact "dashed string" representation. By transitioning from cubic-time dynamic programming to a linear-time sweep approach inspired by industrial scheduling, SWEEP provides orders-of-magnitude speedups, outperforming established SMT and Constraint Programming (CP) solvers on challenging benchmarks.
Introduction
String constraint solving is critical for tasks such as detecting SQL injection and general software testing. Reasoning about strings is inherently difficult due to their variable lengths. Existing solvers typically use unfolding (treating strings as character arrays) or automata-based representations. While unfolding fails for large buffers, automata can be computationally expensive.
A middle ground is the "dashed string"—a sequence of blocks where each block defines a set of possible characters and a length range (e.g., "1 to 3 lowercase letters"). Previous algorithms for dashed string equality, such as COVER, relied on $O(n^3)$ dynamic programming, which becomes a significant bottleneck as strings grow longer and more complex.
Methodology
The authors propose the SWEEP algorithm to handle equality propagation more efficiently by borrowing from "timetable reasoning" used in industrial scheduling.
Dashed Strings and the Sweep Approach
Dashed strings model strings as concatenations of blocks $S_i^{l_i, u_i}$, where $S$ is the character set and $[l, u]$ is the length bound.
SWEEP performs linear-time passes across strings using two primary operations:
- PUSH: Determines the earliest possible start and end positions for a block.
- STRETCH: Determines the latest possible end position.
Unlike the cubic complexity of COVER, SWEEP operates in $O(n + m)$ time, where $n$ and $m$ are the number of blocks in the compared strings. By calculating "feasible" regions (where a block could be) and "mandatory" regions (where a block must be), the solver prunes impossible characters and tightens length bounds efficiently.
Evaluation and Results
The solver G-STRINGS, enhanced with SWEEP, was evaluated against standard benchmarks (e.g., $a^n b^n$, Hamming distance) and SQL injection instances from the NORN corpus. The authors also introduced 200 new, high-complexity SQL instances with string lengths up to 10,000 to test scalability.
Key results include:
- Scalability: On 10,000-character SQL strings, G-SWEEP solved instances in 0.01 seconds, compared to 100 seconds for the previous G-COVER algorithm.
- Performance: G-SWEEP outperformed state-of-the-art SMT solvers like CVC4 and Z3str3, maintaining a 100% success rate on hard benchmarks where other solvers failed as string length increased.
- Efficiency vs. Precision: While SWEEP provides slightly weaker propagation than COVER (it may miss some inconsistencies in a single pass), its speed allows the solver to explore the search tree far more effectively, leading to faster overall solving times.
Discussion and Future Work
A key insight of this work is the importance of "monotonicity"—ensuring that refining a block doesn't inadvertently expand the search space or break solver logic. While SWEEP is a relaxation, its linear performance makes it superior for practical applications involving long fixed strings.
Future work includes extending sweep-based logic to other constraints such as regular expression matching and lexicographical ordering. Additionally, the authors suggest that adding "explanations" to the propagator could further improve performance by allowing the solver to learn from conflicts during the search process.
Summary updated