Abstract
Fundamentally, every static program analyser searches for a proof through a combination of heuristics providing candidate solutions and a candidate validation technique. Essentially, the heuristic reduces a second-order problem to a first-order/propositional one, while the validation is often just a call to a SAT/SMT solver. This results in a monolithic design of such analyses that conflates the formulation of the problem with the solving process. Consequently, any change to the latter causes changes to the whole analysis. This design is dictated by the state of the art in solver technology. While SAT/SMT solvers have experienced tremendous progress, there are barely any second-order solvers. This paper takes a step towards addressing this situation by proposing a decidable fragment of second-order logic that is still expressive enough to capture numerous program analysis problems (e.g. safety proving, bug finding, termination and non-termination proving, superoptimisation). We refer to the satisfiability problem for this fragment as Second-Order SAT and show it is NEXPTIME-complete. Finally, we build a decision procedure for Second-Order SAT based on program synthesis and present experimental evidence that our approach is tractable for program analysis problems.
Introduction
In traditional static program analysis, tools are often designed as monolithic systems. They combine specific heuristics—designed to guess candidate proofs, such as loop invariants or ranking functions—with a validation step that typically relies on a SAT or SMT solver. This architecture conflates the specification of the problem with the mechanics of the search, making tools fragile, difficult to maintain, and hard to adapt to new domains.
This paper argues that many program analysis tasks—including finding invariants, winning strategies, or optimal code sequences—are naturally second-order problems because they involve searching for functions or predicates rather than simple values. However, general-purpose second-order solvers are rare due to the inherent undecidability of the logic. To bridge this gap, the authors define a decidable fragment of second-order logic and introduce Kalashnikov, a robust, "black-box" solver designed to serve as a standard backend for high-level analysis tools.
The Second-Order SAT Fragment
The authors define Second-Order SAT as a formula featuring existential second-order quantification ($\exists S_1 \dots S_m$) followed by a first-order propositional formula (QBF). To ensure the problem remains decidable, ground terms are interpreted over a finite universe, specifically bit-vectors.
While decidable, the authors prove that Second-Order SAT sits in the NEXPTIME-complete complexity class. This represents a significant jump in theoretical difficulty compared to the NP-completeness of standard SAT, necessitating a highly efficient search strategy for practical application.
The Kalashnikov Solver
The core of the proposed approach is the reduction of Second-Order SAT to Finite State Program Synthesis. The Kalashnikov solver implements this via a Counterexample-Guided Inductive Synthesis (CEGIS) loop:
- Synthesis (SYNTH): The solver attempts to find a candidate "program" (representing the required predicate or function) that satisfies a small set of test inputs.
- Verification (VERIF): A verifier checks the candidate against all possible inputs. If the candidate fails, the verifier generates a counterexample that is fed back into the synthesizer to refine the next guess.
Hybrid Search Strategies
To navigate the vast search space, Kalashnikov employs three concurrent search strategies:
- Explicit Proof Search: An exhaustive enumeration of possible programs, prioritized by length.
- Symbolic Bounded Model Checking (BMC): Utilizing a SAT solver to identify programs of a specific fixed length.
- Genetic Programming (GP): A stochastic search that evolves a population of candidate programs based on their fitness (the number of test cases they successfully pass).
The solver utilizes a "lattice" approach, incrementally increasing parameters such as program length, word width, and the number of constants to ensure the simplest possible solution is found first.
Experimental Evaluation
The solver was evaluated on 113 benchmarks spanning diverse domains:
- Superoptimization: Finding the most efficient instruction sequences.
- Code Deobfuscation: Simplifying complex, obfuscated logic.
- Floating Point Verification: Proving properties within IEEE 754 arithmetic.
- Termination & Non-termination: Synthesizing ranking functions or recurrent sets.
- QBF Solving: Standard benchmarks for Quantified Boolean Formulae.
Key Results
- Effectiveness: Kalashnikov successfully solved 59 out of 113 benchmarks.
- Efficiency: For solvable instances, the solver was remarkably fast. For example, superoptimization tasks were solved in an average of 7.9 seconds.
- Simplicity: The average solution size was small, ranging from 4 to 11 instructions. This supports the hypothesis that many real-world program properties possess concise proofs.
- Strategy Synergy: Genetic Programming and Explicit Search were the most effective during the synthesis phase, while CBMC proved essential for the verification phase.
Discussion: The Kolmogorov Connection
A central insight of this work is the relationship between solver performance and Kolmogorov complexity. The solver's efficiency is tied to the length of the shortest possible proof. Even though the problem is theoretically NEXPTIME-complete, the "short" proofs common in human-written code allow the solver to find solutions quickly. By using SSA-form instructions, the authors provide an optimally concise representation for these proofs.
Furthermore, this approach enables a separation of concerns. Analysis designers can focus on the logical specification of a proof, leaving the algorithmic search to the solver.
Limitations and Future Work
Currently, Kalashnikov is "semi-complete" in practice. While it is highly effective at finding solutions (satisfiability), it struggles to prove unsatisfiability, as this requires exhausting a massive theoretical search bound. Future work will focus on improving generalization—transforming specific proofs into broader ones—and enhancing stochastic search methods to handle longer, more complex proofs where the search space currently explodes.
Summary updated