NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Type-Directed Bounding of Collections in Reactive Programs

Tianhan Lu, Pavol Cerný, Bor-Yuh Evan Chang, Ashutosh Trivedi

TL;DR

Researchers have developed Quantm, a tool that statically verifies whether collection variables (like lists and sets) in reactive programs stay within defined memory bounds. By using a novel refinement type system equipped with "AST counters," the tool can track how many times specific code blocks execute, allowing it to prove safety properties in non-terminating programs and even uncover real-world Denial-of-Service (DoS) vulnerabilities.

What Problem Does This Paper Address?

In modern software, collections are indispensable. However, if a collection grows unchecked—especially in a reactive program like a web server or an operating system thread—it can lead to out-of-memory errors and security risks, such as Denial-of-Service (DoS) attacks.

Verifying bounds on these collections is notoriously difficult for two main reasons:

  1. Non-termination: Reactive programs are designed to run forever. Traditional resource analysis usually relies on finding "loop bounds," but if the main loop is while(true), those methods break down.
  2. Scalability vs. Precision: Standard flow-sensitive analyses (which track state changes line-by-line) are precise but don't scale well to large codebases. Conversely, simple type systems scale well but usually struggle to handle "mutation"—the act of adding or removing elements from a collection.

Methods

The authors introduce a technique called Type-directed Bounding. Instead of trying to prove that a program finishes within a certain time, they focus on a safety property: proving that at any reachable state, the total length of collections is below a specific limit.

Key Innovations:

  • AST Counters: This is the paper's "secret sauce." Every node in the Abstract Syntax Tree (AST) is assigned a counter ($c$) that tracks how many times it has been executed.
  • Refinement Types: The system uses types that include logical predicates. For example, a list might be typed such that its length is defined by the relationship between two counters: len(list) = c_add - c_remove. This allows the type system to stay "flow-insensitive" (one type per variable) while still capturing essential "flow-sensitive" information.
  • Counter Axioms: The tool automatically generates logical rules based on the program's structure. For instance, if two statements are in the same basic block, their counters must be nearly equal.
  • The Quantm Tool: Implemented in Scala as a Java annotation processor, it uses the Z3 SMT solver to automatically check if the user-provided type annotations and the generated counter axioms imply the desired memory bounds.

Datasets

The authors evaluated Quantm on a suite of 12 Java benchmarks, totaling approximately 180,000 lines of code (kloc). These included:

  • Real-world web applications like jforum3 and SpringPetClinic.
  • Projects from the Google Code Archive (e.g., jRecruiter).
  • Complex programs from the DARPA STAC (Space-Time Analysis for Cybersecurity) project, such as TextCrunchr and Image_processor.

Key Insights and Ideas

  • Safety over Liveness: By reframing the problem from "how long does this take?" to "is the state always safe?", the researchers bypassed the headache of non-terminating loops.
  • Decoupling Logic: The system separates the types (which are global and easy to manage) from the counter axioms (which handle the messy details of program flow). This makes the verification modular and much faster than traditional symbolic execution.
  • Inductive Invariants: AST counters allow developers to write invariants that remain true even when a collection is being modified. If you add an item and increment the corresponding counter, the relationship len = counter remains valid.

Key Results

  • Effectiveness: The tool analyzed over 16,000 methods. For methods that actually declared collections (non-vacuous), it successfully verified 82.4% of them.
  • Scalability: The analysis is remarkably fast, averaging 51.9 seconds per 15k lines of code. The entire 180k line suite was processed in about 10 minutes.
  • Vulnerability Discovery: Quantm successfully identified a Denial-of-Service bug in the TextCrunchr benchmark. It found that a specific queue used for decompressing files could grow exponentially when hit with a "Zip bomb," a result the tool correctly refused to verify as bounded.

Limitations and Future Work

  • Manual Annotations: While the authors describe the annotation burden as "light" (about 6.8 summaries per benchmark), users still need to provide the initial refinement types. Future work aims to automate this using abstract interpretation.
  • Complex Data Structures: The current system doesn't handle "lists of lists" well, nor does it track bounds when the size of one collection depends on the content (rather than just the count) of another.
  • Java Specifics: Features like aliasing, dynamic dispatch, and multi-threading are currently handled with simplifying assumptions that can lead to imprecision. The authors view these as orthogonal challenges to be integrated into the type system later.

Summary updated

BibTeX
@inproceedings{lu2019type,
  author = {Tianhan Lu and Pavol Cerný and Bor-Yuh Evan Chang and Ashutosh Trivedi},
  title = {{Type-Directed Bounding of Collections in Reactive Programs}},
  booktitle = {VMCAI},
  year = {2019},
  url = {https://openreview.net/forum?id=8D82FaWzDd},
}
Figure