Reasoning About Vectors Using an SMT Theory of Sequences

Ying Sheng, Andres Nötzli, Andrew Reynolds, Yoni Zohar, David L. Dill, Wolfgang Grieskamp, Junkil Park, Shaz Qadeer, Clark W. Barrett, Cesare Tinelli

Automated software verification relies heavily on Satisfiability Modulo Theories (SMT) solvers to prove program correctness. A persistent challenge in this field is the efficient modeling of dynamic data structures, specifically vectors (e.g., std::vector in C++). While the traditional "Theory of Arrays" is a staple of SMT solving, it is designed for fixed-size memory blocks. Modeling dynamic vectors—where length is variable and central to program logic—often requires complex quantified formulas that lead to solver timeouts and instability.

The Theory of Sequences

To address these limitations, this research proposes a native theory of sequences ($T_{Seq}$). Unlike fixed-size arrays, sequences are inherently dynamic. The theory defines a robust set of operations including concatenation, length retrieval, element access, and subsequence extraction.

Table of sequence operations and their SMT-LIB counterparts.

By treating vectors as sequences, verification conditions can be expressed more naturally. For instance, appending an element becomes a simple concatenation rather than a complex update to a fixed-size array model. This shift allows many problems that previously required complex universal quantifiers ($\forall$) to be expressed as simpler, quantifier-free equations.

Modeling Dynamic Vectors

The advantage of sequences becomes clear when formalizing standard programming patterns. Consider a simple swap function in C++. Traditional array-based modeling requires auxiliary variables and complex axioms to handle the implicit length and content updates.

Formalizing a C++ swap function using sequence-based vs. array-based logic.

As shown in the comparison above, the sequence model provides a more direct mapping of the program's semantics to logical constraints, avoiding the need for the explicit length-tracking and content-consistency axioms ($Ax_1, Ax_2$) required by the array model.

Solving Techniques: BASE vs. EXT

Implementing an efficient solver for $T_{Seq}$ requires balancing flexibility with performance. This work introduces two distinct "calculi" (sets of logical rules):

  1. BASE Calculus: Derived from string-solving techniques, it treats sequences as concatenations of elements. While logically sound, it can be computationally expensive because it often reduces simple operations (like reading an index) into complex concatenation problems.
  2. EXT (Extended) Calculus: This is the core innovation. It integrates efficient "read-over-write" reasoning—a hallmark of array solvers—directly into the sequence framework. By using a weak-equivalence graph, the solver can track relationships between sequences without needing to fully expand every concatenation.

Evaluation and Results

The proposed methods were implemented in the cvc5 SMT solver and evaluated against two primary benchmark sets: ARRAYS (551 benchmarks translated from standard SMT-LIB array problems) and DIEM (558 real-world verification conditions for smart contracts).

The results demonstrate a significant performance leap for the integrated sequence approach:

  • Superior Solving Power: On the ARRAYS set, the extended calculus (cvc5-a) solved 390 benchmarks, compared to only 242 for the base version and 170 for Z3.
  • Speedup: On the DIEM set, cvc5-a was roughly 2.47x faster than the base version, completing the benchmarks in 426 seconds compared to 1053 seconds.
  • Robustness: In almost all categories, the new implementation in cvc5 significantly outperformed Z3, which has historically been the industry standard for these verification tasks.

Future Directions

While highly effective, the authors note that the decidability of this specific theory of sequences remains an open question in logic. Future work will focus on technical properties like "polite combination" to better integrate sequences with other theories (like sets or bags) and advocate for the incorporation of these sequence operators into the official SMT-LIB standard.

Summary updated

BibTeX
@article{sheng2023reasoning,
  author = {Ying Sheng and Andres Nötzli and Andrew Reynolds and Yoni Zohar and David L. Dill and Wolfgang Grieskamp and Junkil Park and Shaz Qadeer and Clark W. Barrett and Cesare Tinelli},
  title = {{Reasoning About Vectors Using an SMT Theory of Sequences}},
  journal = {J. Autom. Reason.},
  year = {2023},
  doi = {10.1007/s10817-023-09682-2},
}
Figure