Under-Approximating Loops in C Programs for Fast Counterexample Detection

Daniel Kroening, Matt Lewis, Georg Weissenbacher

Abstract

Software model checking often struggles with "deep" bugs that require thousands of loop iterations to trigger. This paper introduces a technique to bypass traditional loop unrolling by replacing loops with mathematical summaries. By using under-approximation and closed-form recurrence equations, the authors' tool, IMPULSE, can detect buffer overflows in constant time relative to loop depth, significantly outperforming state-of-the-art bounded model checkers on real-world benchmarks.

The Bottleneck of Loop Unrolling

Standard software model checkers typically explore programs in a breadth-first manner, checking for bugs after one iteration, then two, and so on. While effective for shallow logic errors, this approach fails when a bug—such as a buffer overflow—only manifests after thousands of iterations. The tool must prove the safety of every preceding iteration before it can reach the error state, leading to an exponential explosion in computational effort. The authors aim to bypass this "loop unrolling" nightmare by jumping directly to the program state after an arbitrary number of iterations.

Methodology: Loop Under-Approximation

To address this, the authors propose Loop Under-Approximation. Instead of unrolling the loop, the technique identifies a path $\pi$ within the loop body that can be summarized mathematically. This summary, or "auxiliary path" $\tilde{\pi}$, represents the cumulative effect of $n$ iterations.

The transformation process: detecting a recurring path and augmenting the loop with its mathematical approximation.

The core of this approach involves several key technical components:

  1. Recurrence Equations: If a loop contains a simple increment like i := i + 1, the tool derives a closed-form polynomial solution (e.g., $i_n = i_0 + n$). This allows the solver to jump directly to the state after $n$ iterations using an auxiliary path.
  2. Sound Under-Approximation: Unlike "acceleration" techniques that attempt to capture all possible loop behaviors, IMPULSE captures a subset of behaviors. This ensures that any counterexample found is a genuine bug (soundness), even if some bugs might be missed (incompleteness).
  3. Bit-Vector Semantics: Unlike many academic tools that treat integers as infinite, IMPULSE models C integers as bit-vectors. This accounts for hardware realities like integer overflow and wrap-around, which are often the source of bugs in C.
A control flow graph illustrating an auxiliary path (dashed) that summarizes $n$ iterations of a loop.

Handling Arrays and Quantifiers

Arrays present a significant challenge for symbolic analysis. The authors represent array updates using quantified conditionals. To maintain performance, they introduce novel quantifier elimination techniques based on the "monotonicity" of loop conditions. For example, if a variable i only increases, a complex logical quantifier can often be replaced with a simple bounds check, drastically reducing the workload for the SMT solver.

Experimental Results: The IMPULSE Tool

The authors implemented their technique in IMPULSE, integrating it with the popular CBMC (C Bounded Model Checker). They evaluated it using the Verisec benchmark suite, which consists of 284 test cases derived from open-source projects like Apache and Sendmail.

Key findings include:

  • Depth Independence: While standard tools like SATABS show exponential performance degradation as buffer sizes (and thus bug depths) increase, IMPULSE's execution time remains nearly constant.
  • New Bug Discovery: IMPULSE successfully detected bugs in 10 benchmarks that were previously considered "safe" because other tools timed out before reaching the necessary depth.
  • Efficiency: In the "Aeon" mail transfer agent benchmark, IMPULSE found deep counterexamples in seconds, whereas previous state-of-the-art techniques took hundreds of seconds or failed entirely.

Conclusion and Future Work

While highly effective for scalars and arrays, IMPULSE currently has limitations regarding dynamic data structures like linked lists or non-linear loop updates (e.g., cryptographic functions). Future work aims to integrate this under-approximation technique with interpolation-based verification to improve performance on "safe" programs, moving beyond counterexample detection toward full safety proofs.

Summary updated

BibTeX
@inproceedings{kroening2013under,
  author = {Daniel Kroening and Matt Lewis and Georg Weissenbacher},
  title = {{Under-Approximating Loops in C Programs for Fast Counterexample Detection}},
  booktitle = {CAV},
  year = {2013},
  doi = {10.1007/978-3-642-39799-8\_26},
}
Figure