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

Abstract

Reactive programs, such as web servers and operating system threads, are designed for long-term execution, making traditional resource analysis techniques that rely on termination proofs ineffective. This paper presents Quantm, a static analysis tool that verifies whether collection variables (e.g., lists, sets) remain within defined memory bounds. By employing a refinement type system integrated with "AST counters," Quantm tracks the execution frequency of code blocks to establish safety invariants. Evaluation on 180,000 lines of Java code demonstrates that Quantm is both scalable and effective, successfully identifying real-world Denial-of-Service (DoS) vulnerabilities.

Introduction

In modern software development, collections are indispensable for managing data. However, in reactive environments, unchecked collection growth poses a significant risk of out-of-memory (OOM) errors and security vulnerabilities. Verifying bounds in these programs is challenging because reactive loops (e.g., while(true)) do not terminate, and standard flow-sensitive analyses often fail to scale to large codebases while maintaining the precision needed to handle collection mutations.

Formal Framework: AST Counters and Operational Semantics

The researchers propose a technique called Type-directed Bounding. Rather than proving program termination, the goal is to establish a safety property: at any reachable state, the total length of all collections must be below a specified limit.

The "secret sauce" of this approach is the use of AST Counters. Every node in the Abstract Syntax Tree (AST) is associated with a counter ($c$) that increments each time that specific node is executed. This allows the system to relate the size of a collection to the number of times elements were added or removed.

Figure 1: Operational semantics of the Quantm system, detailing rules for state transitions and counter updates.

As shown in the operational semantics (Figure 1), rules like E-COUNTER explicitly define how the environment $\eta$ is updated by incrementing the counter associated with a statement $s$. This formal foundation allows the type system to remain flow-insensitive—assigning a single type per variable—while still capturing the dynamic state changes necessary for bounding analysis.

Methodology

Quantm utilizes several key innovations to achieve its goals:

  • Refinement Types: Types include logical predicates that define collection lengths based on counter relationships (e.g., len(list) = c_add - c_remove).
  • Counter Axioms: The tool automatically generates logical rules from the program structure. For example, statements within the same basic block must have nearly identical counter values.
  • Automated Verification: Implemented as a Java annotation processor in Scala, Quantm leverages the Z3 SMT solver to verify that user-provided type annotations and generated axioms imply the desired memory safety.

Evaluation and Results

The authors evaluated Quantm on 12 Java benchmarks totaling approximately 180,000 lines of code (kloc), including real-world applications like SpringPetClinic and DARPA STAC projects.

Key Performance Metrics:

  • Effectiveness: Quantm successfully verified 82.4% of methods containing non-vacuous collection declarations.
  • Scalability: The analysis averaged 51.9 seconds per 15k lines of code, processing the entire 180k line suite in roughly 10 minutes.
  • Vulnerability Discovery: The tool identified a critical DoS bug in the TextCrunchr benchmark, where a queue used for decompression could grow exponentially when processing a "Zip bomb." Quantm correctly flagged this as unbounded.

Discussion and Future Work

By reframing the problem from liveness to safety, Quantm bypasses the complexities of non-terminating loops. The decoupling of global types from local counter axioms makes the verification modular and significantly faster than traditional symbolic execution.

However, some limitations remain. Currently, users must provide initial refinement types, though future work aims to automate this via abstract interpretation. Additionally, the system struggles with nested collections (e.g., lists of lists) and complex data dependencies where size depends on element content rather than just operation counts. Future iterations will also look to refine the handling of Java-specific features like aliasing and multi-threading.

Conclusion

Quantm represents a significant step forward in the static verification of reactive programs. By combining refinement types with AST counters, it provides a scalable and precise method for ensuring memory safety in long-running systems, offering a robust defense against resource-exhaustion attacks.

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