Using Program Synthesis for Program Analysis

Cristina David, Daniel Kroening, Matt Lewis

Program analysis has traditionally relied on specialized tools designed for specific tasks—safety checkers for invariants, termination analyzers for ranking functions, and superoptimizers for code refinement. This research proposes a paradigm shift: unifying these diverse tasks under the umbrella of Second-Order Synthesis. By decoupling the problem formulation from the solving heuristics, the authors argue that program analysis can be treated as a single logical problem solved by a general-purpose backend.

The Synthesis Fragment

The authors identify a specific fragment of second-order logic, termed the Synthesis Fragment (SF), which is capable of expressing a wide array of analysis tasks. The fragment is defined as:

$$\exists P. \forall x. \sigma(P, x)$$

In this formulation, $P$ represents the functions to be discovered (the "proofs," such as loop invariants or ranking functions), while $\sigma$ is a quantifier-free formula. By framing analysis in this way, the search for a program proof becomes a search for a program that satisfies a specific logical specification.

The Kalashnikov Framework

To solve SF formulas over finite domains, the authors developed Kalashnikov, a tool that reduces the problem to Finite State Program Synthesis using the Counterexample-Guided Inductive Synthesis (CEGIS) framework. Kalashnikov is distinguished by its use of three parallel search strategies to find candidate programs:

  1. Explicit Proof Search: A deterministic, brute-force enumeration of all possible programs, starting from the shortest possible instruction sequences.
  2. Symbolic Bounded Model Checking (BMC): Utilizing SAT/SMT solvers to "fill in the blanks" within a predefined program template.
  3. Genetic Programming (GP): A stochastic evolutionary algorithm that "breeds" programs, using fitness functions based on the number of test cases (counterexamples) a candidate passes.

This multi-strategy approach allows the tool to benefit from the strengths of different domains: the GP can escape local minima that might trap symbolic solvers, while the explicit search ensures that simple solutions are never overlooked.

Optimization via Generalization

Searching the entire space of 32-bit or 64-bit programs is computationally prohibitive. Kalashnikov addresses this through a parameter lattice approach. The solver begins by searching for solutions in a highly restricted domain:

  • Minimal program lengths ($l$).
  • Small word widths ($w$), such as 4-bit integers.
  • A minimal set of constants ($c$).

If a solution is found for a 4-bit version of the problem, the tool attempts to generalize it to the full 32-bit or 64-bit version. This strategy leverages the insight that many fundamental logic proofs (like isolating the least significant bit) function identically regardless of the word size.

Key Results and the "Short Proof" Hypothesis

The authors evaluated Kalashnikov on 96 benchmarks across categories including superoptimization, deobfuscation, and safety/termination proving.

  • Effectiveness: Kalashnikov solved 75 out of 96 benchmarks, with an average successful solve time of 10.3 seconds.
  • Comparison with SyGuS: In a head-to-head comparison on safety benchmarks, Kalashnikov solved 18/20 problems, significantly outperforming the state-of-the-art eSolver, which solved only 7/20.
  • Conciseness: By using a fragment of C as the specification language, the authors achieved specifications roughly 10x smaller than equivalent files in the Syntax-Guided Synthesis (SyGuS) format.

A primary takeaway of the study is the Short Proof Hypothesis. The authors found that the average synthesized solution was only about 6 instructions long. This suggests that while the theoretical search space for functions is massive, the "proofs" required for practical program analysis often have very low Kolmogorov complexity, making them reachable via synthesis.

Limitations

While Kalashnikov is highly effective at finding solutions (satisfiability), it faces challenges with Unsatisfiability. To prove that no solution exists—for instance, to prove a program cannot be optimized further—the tool must exhaustively search up to a massive theoretical bound. This makes the synthesis-based approach currently slower than bespoke tools for proving the absence of a property. Future work aims to integrate earlier detection of unsatisfiability to make synthesis-based analysis more robust for all scenarios.

Summary updated

BibTeX
@inproceedings{david2015using,
  author = {Cristina David and Daniel Kroening and Matt Lewis},
  title = {{Using Program Synthesis for Program Analysis}},
  booktitle = {LPAR},
  year = {2015},
  doi = {10.1007/978-3-662-48899-7\_34},
}
Figure