Abstract
Memory safety defects in C/C++ remain a critical threat to software reliability. While Bounded Model Checking (BMC) offers a mathematical path to bug-free code, scalability issues often limit its application to entire programs. This paper presents the first large-scale empirical study of "unit proofing"—a compositional BMC approach that verifies individual functions in isolation. By introducing a systematic five-step methodology, the authors demonstrate that formal verification can be both cost-effective and highly efficient, detecting 74% of known defects and uncovering 19 previously unknown vulnerabilities in popular embedded operating systems.
The Challenge of Memory Safety
Despite the rise of memory-safe languages like Rust, massive legacy C/C++ codebases continue to power critical infrastructure. Vulnerabilities such as buffer overflows and out-of-bounds reads remain catastrophic, as seen in high-profile outages. Industry leaders have turned to unit proofing to manage complexity, yet the practice has largely remained an "art" lacking standardized methodology or empirical performance data. This study seeks to transform unit proofing into a measurable science.
A Systematic Workflow for Unit Proofing
The authors propose an iterative, feedback-driven workflow using the C Bounded Model Checker (CBMC). Unlike traditional methods requiring exhaustive upfront specifications, this "bottom-up" approach relies on verification feedback to guide proof creation.
The methodology consists of five core steps:
- Construct Initial Proof: Create a harness invoking the target function with symbolic inputs.
- Ensure Termination: Resolve build failures and prevent infinite loops or recursion.
- Ensure Full Coverage: Use coverage reports to identify and reach all code paths by adjusting bounds or allocations.
- Refine Models: Apply "angelic modeling" to handle unknown external functions or variables, creating minimal models to satisfy the checker.
- Verify: Iterate until the unit is fully covered and no memory safety violations remain.
Empirical Evaluation and Results
The methodology was evaluated across four major open-source embedded operating systems: FreeRTOS, Zephyr, Contiki-ng, and RIOT. The authors developed a comprehensive benchmark dataset, now available on GitHub, which includes 73 unique unit proofs, 89 recreated known defects sourced from the National Vulnerability Database, and 19 newly discovered defects found during the study.
Effectiveness and Bug Discovery
The systematic approach proved highly effective, catching 74% of recreated defects out of the box. With minor manual interventions, such as increasing loop bounds, this detection rate rose to 83%. More importantly, the study uncovered 19 previously unknown defects across RIOT, Zephyr, and Contiki-ng. These included critical out-of-bounds reads/writes and arithmetic underflows, five of which have already been assigned CVEs with high severity scores (>8.0).
Efficiency and Cost
A key finding is the predictability and efficiency of the process. Developing a unit proof required a median of 72 minutes, and the proofs themselves executed in a median of just 25 seconds.
This level of efficiency suggests that an engineer could verify approximately 1,200 lines of code per day, making formal verification a viable component of standard development sprints. Furthermore, the time required to run a proof correlates strongly ($R^2 = 0.852$) with the size of the generated verification formula rather than raw lines of code, providing engineers with a reliable way to predict verification costs.
Key Insights
- Compactness: Unit proofs for embedded software are surprisingly small, averaging only 20 lines of code.
- Superiority over Expert Proofs: Systematic proofs were found to be smaller, faster, and more thorough than those written by project experts. In one instance, a systematic proof achieved 100% coverage where an expert proof reached only 10%.
- Automation Potential: 76% of variable models could be derived statically, indicating significant potential for future automation of the unit proofing process.
Limitations and Future Outlook
While promising, the process still requires manual effort, particularly in model generation and loop bound inference. Additionally, unit proofing in isolation may miss "inter-unit" defects arising from complex interactions between separately verified components. Future research will explore extending these results from embedded systems to more state-heavy desktop and server applications.
Summary updated