Abstract
Static program analysis fundamentally involves searching for a proof—such as an invariant or a ranking function—and validating it. Currently, most analyzers are monolithic, tightly coupling the heuristic search for a proof with the validation logic (typically handled by SAT/SMT solvers). This paper proposes Second-Order SAT, a decidable fragment of second-order logic that provides a unified interface for program analysis tasks. By reducing the satisfiability of this fragment to a program synthesis problem, the authors demonstrate that complex properties like safety, termination, and superoptimization can be solved by a general-purpose solver. Despite being NEXPTIME-complete, the approach proves tractable because the proofs required for real-world programs are often remarkably concise.
Introduction
In the current landscape of formal methods, building a static analyzer is a bespoke process. To prove a property like memory safety or loop termination, researchers must manually design heuristics to guess candidate solutions and then invoke a first-order solver (SAT/SMT) to verify them. This design conflates the formulation of the problem with the solving process, making tools fragile and difficult to extend.
The primary bottleneck is the lack of general-purpose second-order solvers. While first-order solvers handle variables representing values, second-order solvers handle variables representing functions or predicates. This paper introduces a decidable fragment of second-order logic, termed Second-Order SAT, and a corresponding solver, Kalashnikov, to bridge this gap.
The Second-Order SAT Framework
Second-Order SAT allows for existential quantification over predicates (second-order variables) and standard quantification over bit-vectors (first-order variables). The authors establish that this fragment is NEXPTIME-complete. While this complexity class is traditionally viewed as a barrier to practicality, the authors argue it is the appropriate class for the inherent difficulty of program analysis.
Reduction to Program Synthesis
The core innovation lies in treating the search for a satisfying predicate as a Finite State Program Synthesis problem. Instead of searching for an abstract mathematical relation, the solver searches for a small, loop-free program in a custom RISC-like language, $\mathcal{L}$, that implements the required predicate. This transforms a logical search into a search for the shortest code sequence that satisfies the specification.
The Kalashnikov Solver
The authors implemented their approach in a tool called Kalashnikov, which utilizes Counterexample-Guided Inductive Synthesis (CEGIS). To navigate the vast search space of programs, Kalashnikov employs three search strategies in parallel:
- Explicit Search: A brute-force enumeration of all possible small programs.
- Symbolic Bounded Model Checking (BMC): Leveraging SAT solvers to find a program that satisfies the current constraints.
- Genetic Programming (GP): An evolutionary approach that "breeds" candidate programs based on their fitness against counterexamples.
The solver uses iterative parameterization, starting with very short programs and small bit-widths, gradually increasing complexity only when necessary.
Experimental Evaluation
Kalashnikov was evaluated on 113 benchmarks across four diverse domains:
- Superoptimization & Deobfuscation: Finding the most efficient equivalent code sequence.
- Termination: Proving that loops eventually terminate using benchmarks from the SVCOMP’15 competition.
- QBF Solving: Solving Quantified Boolean Formula instances.
- Floating Point Verification: Handling IEEE 754 arithmetic properties.
Key Results
- Tractability: The solver successfully handled 59 out of 113 benchmarks. For those solved, the average execution time was frequently under 12 seconds.
- Proof Conciseness: A critical finding was the brevity of the synthesized solutions. For termination proofs, the resulting ranking functions and invariants averaged only 5.7 instructions.
- Unified Interface: The results demonstrate that a single second-order solver can serve as a "black box" backend for disparate analysis tasks, successfully decoupling the problem definition from the search heuristic.
Discussion: The Kolmogorov Connection
The effectiveness of Kalashnikov rests on a central insight: the runtime of the solver is primarily a function of the Kolmogorov complexity (the length of the shortest possible proof) rather than the size of the input program. Even for complex software, the underlying invariants or ranking functions are often surprisingly short. This "short proof" hypothesis explains why a theoretically NEXPTIME-complete problem remains tractable for real-world applications.
Limitations and Future Work
The primary limitation of the current approach is proving unsatisfiability. Because the solver searches from the shortest to the longest programs, it can only declare a problem unsatisfiable after an exhaustive search of an exponentially growing space. Additionally, the authors identified a need for better constant generalization to handle large 32-bit integers more efficiently.
Future work aims to explore how Second-Order SAT can serve as a foundation for adaptive, learning-based analyzers that move from long, complex proofs to more generalized, shorter ones.
Summary updated