TL;DR
This paper introduces a novel technique for automatically inferring the "weakest possible" specifications for unknown procedures within a program. By framing this as a "maximal specification inference" problem and reducing it to a generalized form of logical abduction called "multi-abduction," the authors provide a robust method for synthesizing crucial assumptions that guarantee program correctness without over-constraining the unknown components. This has significant implications for verifying complex software, synthesizing missing code, and improving program repair.
What Problem Does This Paper Address?
In software development, we often encounter situations where we need to verify or synthesize code that relies on external libraries or procedures whose internal workings are unknown or unavailable. To ensure the correctness of our code, we need to make assumptions about these unknown procedures in the form of specifications. The challenge is to find specifications that are just strong enough to guarantee the overall program's correctness, but no stronger. Overly strong specifications can lead to false alarms (missing real bugs) or hinder synthesis efforts. Conversely, overly weak specifications might not be sufficient to prove correctness. This paper tackles the problem of inferring these "maximal" specifications – the weakest possible assumptions that still ensure the desired program properties.
Methods
The core of the paper's contribution lies in its novel approach to maximal specification inference, which is built around a counterexample-guided inductive synthesis (CEGIS) loop. Here's a breakdown of the key techniques:
- Maximal Specification Inference: The problem is formally defined as finding the weakest specifications for unknown procedures ($F_1, \dots, F_n$) that, when assumed, guarantee a program $P$ satisfies its postcondition $\phi$. This involves satisfying three criteria: safety (program correctness), non-triviality (avoiding trivial "false" specifications), and maximality (the weakest possible safe specification).
- Multi-Abduction: The authors introduce and formalize multi-abduction, a generalization of classical logical abduction. While standard abduction infers a single hypothesis to explain an observation, multi-abduction infers multiple hypotheses (specifications for multiple unknown procedures) simultaneously. This is crucial because programs often call several unknown functions. The multi-abduction problem is defined as finding a mapping from unknown predicates (representing procedure specifications) to formulas that satisfy certain logical implications.
- CEGIS Loop: The overall synthesis process works as follows:
- Start with the weakest possible specifications (e.g.,
true) for all unknown procedures. - Use a verifier to check if the program is correct with these specifications.
- If the verifier finds a counterexample (a program path that violates the postcondition), encode this counterexample into a multi-abduction problem.
- Solve the multi-abduction problem to synthesize stronger, yet still maximal, specifications for the unknown procedures.
- Repeat until the verifier can prove the program correct for all paths.
- Encoding Counterexamples: To handle sets of counterexamples efficiently, the authors develop an
ENCODEprocedure that translates a set of loop-free program paths into a single logical formula. This formula is then "flattened" to fit the structure required for multi-abduction. - Linear vs. Non-linear Multi-Abduction: The paper distinguishes between linear multi-abduction (where each unknown predicate appears at most once) and non-linear multi-abduction (where the same predicate can appear multiple times with different arguments, reflecting multiple calls to the same procedure). Algorithms are provided for both cases, with the non-linear case being more complex due to the need to ensure consistent specifications for repeated calls.
Datasets
The paper evaluates its approach on two main sets of benchmarks:
- Parameterized Microbenchmarks: Four microbenchmarks are introduced, parameterized by the number of calls to unknown procedures. These are designed to stress-test the multi-abduction procedure and study its scalability.
- Locks Benchmarks (from SV-COMP): A subset of benchmarks from the Software Verification Competition (SV-COMP) involving non-deterministic lock acquisition and release. These are used to simulate a program repair scenario where code checking lock acquisition is treated as an unknown procedure.
- Windows Device Drivers (from SV-COMP): A collection of Windows device drivers from SV-COMP. Here, the authors abstract kernel routine stubs and initialization code as unknown procedures and synthesize their specifications. This is a key practical application, as manually writing these stubs is common but tedious.
Key Insights and Ideas
- The Power of "Weakest Possible": The core insight is that focusing on inferring the weakest safe specifications is crucial. This avoids over-constraining the system, leading to more accurate verification and more flexible synthesis.
- Multi-Abduction as a Unifying Framework: The paper elegantly demonstrates how a wide range of problems, from verifying open programs to program repair and input-filter synthesis, can be unified under the umbrella of maximal specification inference, solvable via multi-abduction.
- CEGIS is Key for Synthesis: The counterexample-guided approach is essential. By iteratively refining specifications based on failing program paths, the system can effectively learn the necessary assumptions.
- Handling Repeated Procedure Calls is Non-Trivial: The distinction between linear and non-linear multi-abduction highlights the challenge of ensuring consistent specifications when the same procedure is called multiple times within a program. The proposed solution for non-linear cases is a significant technical contribution.
- Practical Applicability to Real-World Code: The successful application to device driver stubs demonstrates that the technique is not just theoretical but can yield practical benefits in complex software verification scenarios.
Key Results
- Scalability: The multi-abduction solver demonstrates good scalability, handling formulas with thousands of Boolean connectives and hundreds of variables in experiments with parameterized microbenchmarks and device drivers.
- Effectiveness on Device Drivers: The approach successfully synthesized maximal specifications for kernel routine stubs and initialization code in Windows device drivers, often matching or over-approximating manually written stubs. For example, for the
cdaudiodriver, a specification forKeWaitForSingleObjectwas synthesized in 15 seconds, involving a multi-abduction query with ~3000 Boolean operators and ~800 quantified variables. - Maximal Specifications Achieved: The evaluation confirms that the synthesized specifications are indeed maximal, meaning they are the weakest possible safe specifications.
- Efficiency: The runtime for synthesizing specifications for device drivers was generally short, ranging from seconds to a few minutes, indicating the practical viability of the approach.
Limitations and Future Work
- Termination Guarantees: While the algorithm terminates for theories with finite ascending chains of implications (like propositional logic), it does not guarantee termination for all first-order theories, particularly in the non-linear multi-abduction case. The paper notes that for their benchmarks, heuristics helped achieve termination, but theoretical guarantees are lacking in general.
- Expressiveness of Specifications: The paper acknowledges that in some theories (e.g., linear real arithmetic), maximal solutions might not be finitely expressible, requiring more expressive logics or constraints.
- Future Work:
- Compositional Analysis for Shape-Data: Combining the multi-abduction approach with bi-abduction for shape analysis to reduce false positives.
- Top-Down Verification: Investigating the effectiveness of the technique for top-down verification, where callers are verified independently of callees.
- Variable Elimination Ordering: Further research into variable elimination ordering strategies for quantifier elimination, especially within the context of specification synthesis.
- Release of Tools: The authors plan to release their tool and the generated SMT-LIB formulas to facilitate further research.
Summary updated