Quantifying Software Correctness by Combining Architecture Modeling and Formal Program Analysis

Florian Lanzinger, Christian Martin, Frederik Reiche, Samuel Teuber, Robert Heinrich, Alexander Weigl · DOI

Introduction

In critical infrastructure, autonomous systems, and medical devices, software correctness is paramount. However, traditional formal verification often presents a binary choice: a system is either mathematically proven correct or it is not. For large-scale, complex systems, achieving a 100% proof of correctness is frequently infeasible due to state space explosion or the sheer complexity of the mathematical proofs required. Conversely, architectural reliability models often rely on heuristic "expert guesses" for component failure rates, which may not reflect the actual implementation in the source code.

To bridge this gap, the Quac ("Quantifying Architecture and Code") framework introduces a novel approach that moves beyond binary verification. By integrating high-level architectural models with low-level formal code analysis, Quac calculates the specific probability that a complex system will behave correctly under a defined usage profile.

The Quac Workflow

The Quac framework operates through a multi-stage pipeline that translates source code properties into a system-wide probabilistic reliability estimate.

The process begins with Source Code and Contracts, typically written in Java with JML (Java Modeling Language) specifications. Instead of attempting to prove global correctness, the framework identifies Coverage Regions—logical formulas describing the specific subset of inputs for which the code is mathematically proven to satisfy its contract.

These regions are extracted using KeY, a deductive verification tool. Once extracted, they are integrated into the Architectural Model, specifically the Palladio Component Model (PCM). This model describes how components interact and call one another. By combining this architecture with a Usage Profile (a probabilistic distribution of expected inputs), the entire system is translated into a probabilistic program in the PSI language. Finally, a model checker or counter calculates the final Reliability Estimation.

Case Study: Energy Network Simulation

The authors demonstrate Quac using a running example of a simplified energy network. This system consists of three primary components: a WindTurbine (producer), a Consumer, and a Network (load controller).

In this example, the WindTurbine produces energy based on wind speed, and the Consumer uses energy based on demand. The Network tracks the total load. A failure occurs if the consumer attempts to use more load than is available in the network. By defining the usage profile for wind speed and demand as random distributions, Quac can determine the exact probability that the system remains in a "safe" state where demand never exceeds supply.

Key Insights: Soundness and Scalability

A critical feature of Quac is its sound under-approximation. The authors prove that if the coverage regions are correctly derived, the resulting probability is a conservative estimate. Quac will never overstate a system's safety; it only reports the reliability that can be strictly proven from the code.

Furthermore, Quac supports mixed-fidelity modeling. During the early stages of development, architects can use expert estimates for unfinished components. As implementation progresses, these estimates are incrementally replaced with rigorous formal proofs derived from the actual source code.

To handle the "state space explosion" common in complex systems, the framework utilizes approximate model counting via tools like counterSharp. While exact probability calculation is ideal for small examples, approximate counting allows Quac to generate high-accuracy reliability intervals for massive state spaces—such as systems with millions of possible value combinations—in just a few minutes.

Results and Performance

In the energy network case study, KeY automatically identified all necessary coverage regions in approximately 26.3 seconds. The framework correctly calculated an 80% probability of correctness for the given input distributions.

For a more complex scalability study involving multiple producers and sensors, exact counters failed due to memory constraints. However, using approximate counting, the team successfully generated reliability intervals (e.g., [96.58%, 98.95%]) for systems with state spaces as large as 2000 * 2000 * 20 possible values per iteration, completing the analysis in about 5 minutes.

Conclusion and Future Work

Quac represents a significant step forward in making formal verification practical for large-scale software engineering. By quantifying "how correct" a system is, rather than just "if" it is correct, developers can make more informed risk assessments.

Current limitations include constraints on unbounded loops and recursion, as well as a focus on synchronous service calls. Future research aims to extend the framework to handle asynchronous patterns and security properties, such as quantifying a system's resistance to intrusion by modeling attacker capabilities within the usage profile.

Summary updated

BibTeX
@inproceedings{lanzinger2024quantifying,
  author = {Florian Lanzinger and Christian Martin and Frederik Reiche and Samuel Teuber and Robert Heinrich and Alexander Weigl},
  title = {{Quantifying Software Correctness by Combining Architecture Modeling and Formal Program Analysis}},
  booktitle = {SAC},
  year = {2024},
  doi = {10.1145/3605098.3636008},
}
Figure