Abstract
Dynamic arrays, also referred to as vectors, are fundamental data structures used in many programs. Modeling their semantics efficiently is crucial when reasoning about such programs. The theory of arrays is widely supported but is not ideal, because the number of elements is fixed (determined by its index sort) and cannot be adjusted, which is a problem, given that the length of vectors often plays an important role when reasoning about vector programs. In this paper, we propose reasoning about vectors using a theory of sequences. We introduce the theory, propose a basic calculus adapted from one for the theory of strings, and extend it to efficiently handle common vector operations. We prove that our calculus is sound and show how to construct a model when it terminates with a saturated configuration. Finally, we describe an implementation of the calculus in cvc5 and demonstrate its efficacy by evaluating it on verification conditions for smart contracts and benchmarks derived from existing array benchmarks.
Similar content being viewed by others
Notes
We number elements in a sequence starting at 0.
In Bjørner et al. [9], the second argument j denotes the end index, while here it denotes the length of the sub-sequence, in order to be consistent with the theory of strings in the SMT-LIB standard.
It is possible to obtain a similar encoding using the theory of datatypes (see, e.g., [5]); however, here we use uninterpreted functions which are simpler and more widely supported by SMT solvers.
In practice, this is implemented by associating each introduced variable with a witness term as described in Reynolds et al. [26].
Note that this goes beyond Nelson–Oppen combination because the theories \(T_\textsf{LIA}\) and \(T_\textsf{Seq}\) are not disjoint. As a consequence, the exchanged (dis)equalities are not limited to shared variables.
Recall that the meaning of \(\textsf{nth}\) is fixed by the theory only for certain inputs.
References
Alberti, F., Ghilardi, S., Pagani, E.: Cardinality constraints for arrays (decidability results and applications). Formal Methods Syst. Des. 51(3), 545–574 (2017)
Barbosa, H., Barrett, C. W., Brain, M., Kremer, G., Lachnitt, H., Mann, M., Mohamed, A., Mohamed, M., Niemetz, A., Nötzli, A., Ozdemir, A., Preiner, M., Reynolds, A., Sheng, Y., Tinelli, C., Zohar, Y.: cvc5: a versatile and industrial-strength SMT solver. In: TACAS (1), Volume 13243 of Lecture Notes in Computer Science, pp. 415–442. Springer, New York (2022)
Barrett, C.W., Tinelli, C.: Satisfiability modulo theories. In: Handbook of Model Checking, pp. 305–343. Springer, New York (2018)
Barrett, C., Nieuwenhuis, R., Oliveras, A., Tinelli, C.: Splitting on demand in SAT modulo theories. In: Hermann, M., Voronkov, A. (eds.) Proceedings of the 13th International Conference on Logic for Programming, Artificial Intelligence and Reasoning (LPAR’06), Phnom Penh, Cambodia, volume 4246 of Lecture Notes in Computer Science, pp. 512–526. Springer, New York (2006)
Barrett, C.W., Shikanian, I., Tinelli, C.: An abstract decision procedure for a theory of inductive data types. J. Satisf. Boolean Model. Comput. 3(1–2), 21–46 (2007)
Barrett, C., Fontaine, P., Tinelli, C.: The SMT-LIB standard: version 2.6. Technical report. Department of Computer Science, The University of Iowa. www.SMT-LIB.org (2017)
Berzish, M., Ganesh, V., Zheng, Y.: Z3str3: a string solver with theory-aware heuristics. In: Stewart, D., Weissenbacher, G. (eds.) 2017 Formal Methods in Computer Aided Design, FMCAD 2017, Vienna, Austria, October 2–6, 2017, pp. 55–59. IEEE (2017)
Bjørner, N., Tillmann, N., Voronkov, A.: Path feasibility analysis for string-manipulating programs. In: Kowalewski, S., Philippou, A. (eds.) Tools and Algorithms for the Construction and Analysis of Systems, 15th International Conference, TACAS 2009, Held as Part of the Joint European Conferences on Theory and Practice of Software, ETAPS 2009, York, UK, March 22–29, 2009. Proceedings, Volume 5505 of Lecture Notes in Computer Science, pp. 307–321. Springer, New York (2009)
Bjørner, N., Ganesh, V., Michel, R., Veanes, M.: An SMT-LIB format for sequences and regular expressions. SMT 12, 76–86 (2012)
Bjørner, N., de Moura, L., Nachmanson, L., Wintersteiger, C.: Programming Z3. https://theory.stanford.edu/~nikolaj/programmingz3.html#sec-sequences-and-strings (2018)
Bonacina, M.P., Graham-Lengrand, S., Shankar, N.: CDSAT for nondisjoint theories with shared predicates: Arrays with abstract length. In: Déharbe, D., Hyvärinen, A.E.J. (eds.) Proceedings of the 20th Internal Workshop on Satisfiability Modulo Theories Co-located with the 11th International Joint Conference on Automated Reasoning (IJCAR 2022) Part of the 8th Federated Logic Conference (FLoC 2022), Haifa, Israel, August 11–12, 2022, Volume 3185 of CEUR Workshop Proceedings, pp. 18–37. CEUR-WS.org (2022)
Christ, J., Hoenicke, J.: Weakly equivalent arrays. In: FroCos, zvolume 9322 of Lecture Notes in Computer Science, pp. 119–134. Springer, New York (2015)
de Moura, L.M., Bjørner, N.: Z3: an efficient SMT solver. In: TACAS, Volume 4963 of Lecture Notes in Computer Science, pp. 337–340. Springer, New York (2008)
Dershowitz, N., Manna, Z.: Proving termination with multiset orderings. Commun. ACM 22(8), 465–476 (1979)
Elad, N., Rain, S., Immerman, N., Kovács, L., Sagiv, M.: Summing up smart transitions. In: CAV (1), Volume 12759 of Lecture Notes in Computer Science, pp. 317–340. Springer, New York (2021)
Enderton, H.B.: A Mathematical Introduction to Logic, 2nd edn. Academic Press, London (2001)
Falke, S., Merz, F., Sinz, C.: Extending the theory of arrays: memset, memcpy, and beyond. In: VSTTE, Volume 8164 of Lecture Notes in Computer Science, pp. 108–128. Springer, New York (2013)
Ganesh, V., Minnes, M., Solar-Lezama, A., Rinard, M.C.: Word equations with length constraints: what’s decidable? In: Haifa Verification Conference, Volume 7857 of Lecture Notes in Computer Science, pp. 209–226. Springer, New York (2012)
Ghilardi, S., Gianola, A., Kapur, D.: Interpolation and amalgamation for arrays with maxdiff. In: Kiefer, S., Tasson, C. (eds.) Foundations of Software Science and Computation Structures: 24th International Conference, FOSSACS 2021, Held as Part of the European Joint Conferences on Theory and Practice of Software, ETAPS 2021, Luxembourg City, Luxembourg, March 27–April 1, 2021, Proceedings, volume 12650 of Lecture Notes in Computer Science, pp. 268–288. Springer, New York (2021)
Jovanovic, D., Barrett, C.W.: Polite theories revisited. In: Fermüller, C.G., Voronkov, A. (eds.) Logic for Programming, Artificial Intelligence, and Reasoning: 17th International Conference, LPAR-17, Yogyakarta, Indonesia, October 10–15, 2010. Proceedings, Volume 6397 of Lecture Notes in Computer Science, pp. 402–416. Springer, New York (2010)
Liang, T., Reynolds, A., Tinelli, C., Barrett, C.W., Deters, M.: A DPLL(T) theory solver for a theory of strings and regular expressions. In: Biere, A., Bloem, R. (eds.) Computer Aided Verification: 26th International Conference, CAV 2014, Held as Part of the Vienna Summer of Logic, VSL 2014, Vienna, Austria, July 18–22, 2014. Proceedings, Volume 8559 of Lecture Notes in Computer Science, pp. 646–662. Springer, New York (2014)
Nelson, G., Oppen, D.C.: Simplification by cooperating decision procedures. ACM Trans. Program. Lang. Syst. 1(2), 245–257 (1979)
Nieuwenhuis, R., Oliveras, A., Tinelli, C.: Solving SAT and SAT modulo theories: from an abstract Davis–Putnam–Logemann–Loveland procedure to DPLL(T). J. ACM 53(6), 937–977 (2006)
Ranise, S., Ringeissen, C., Zarba, C.G.: Combining data structures with nonstably infinite theories using many-sorted logic. In: Gramlich, B. (ed) Frontiers of Combining Systems, 5th International Workshop, FroCoS 2005, Vienna, Austria, September 19–21, (2005), Proceedings, Volume 3717 of Lecture Notes in Computer Science, pp. 48–64. Springer (2005). https://hal.inria.fr/inria-00070335/
Reynolds, A., Woo, M., Barrett, C.W., Brumley, D., Liang, T., Tinelli, C.: Scaling up DPLL(T) string solvers using context-dependent simplification. In: Majumdar, R., Kuncak, V. (eds.) Computer Aided Verification: 29th International Conference, CAV 2017, Heidelberg, Germany, July 24–28, 2017, Proceedings, Part II, Volume 10427 of Lecture Notes in Computer Science, pp. 453–474. Springer, New York (2017)
Reynolds, A., Nötzli, A., Barrett, C.W., Tinelli, C.: Reductions for strings and regular expressions revisited. In: 2020 Formal Methods in Computer Aided Design, FMCAD 2020, Haifa, Israel, September 21–24, 2020, pp. 225–235. IEEE (2020)
Sheng, Y., Nötzli, A., Reynolds, A., Zohar, Y., Dill, D.L., Grieskamp, W., Park, J., Qadeer, S., Barrett, C.W., Tinelli, C.: Reasoning about vectors using an SMT theory of sequences. In: IJCAR, Volume 13385 of Lecture Notes in Computer Science, pp. 125–143. Springer, New York (2022)
Zhong, J. E., Cheang, K., Qadeer, S., Grieskamp, W., Blackshear, S., Park, J., Zohar, Y., Barrett, C., Dill, D.L.: The Move prover. In: Lahiri, S.K., Wang, C. (eds.) Proceedings of the 32nd International Conference on Computer Aided Verification (CAV ’20), Volume 12224 of Lecture Notes in Computer Science, pp. 137–150. Springer, New York (2020)
Acknowledgements
This work was funded in part by the Stanford Center for Blockchain Research, NSF-BSF Grant Numbers 2110397 (NSF) and 2020704 (BSF), ISF Grant Number 619/21, and Meta Novi. Part of the work was done when the first author was an intern at Meta Novi.
Author information
Authors and Affiliations
Corresponding author
Additional information
Publisher's Note
Springer Nature remains neutral with regard to jurisdictional claims in published maps and institutional affiliations.
Rights and permissions
Springer Nature or its licensor (e.g. a society or other partner) holds exclusive rights to this article under a publishing agreement with the author(s) or other rightsholder(s); author self-archiving of the accepted manuscript version of this article is solely governed by the terms of such publishing agreement and applicable law.
About this article
Cite this article
Sheng, Y., Nötzli, A., Reynolds, A. et al. Reasoning About Vectors: Satisfiability Modulo a Theory of Sequences. J Autom Reasoning 67, 32 (2023). https://doi.org/10.1007/s10817-023-09682-2
Received:
Accepted:
Published:
DOI: https://doi.org/10.1007/s10817-023-09682-2