RustPruner: A Program Slicing Tool for Rust Programs

Yanfeng Hu, Weihong Chen, Yilong Zhao, Ruiyu Zhang, Liangze Yin, Wei DongSEKE 2024

Abstract

Formal verification is essential for software security but often computationally expensive for large-scale Rust systems. RustPruner is a specialized program slicing tool designed to extract minimal, compilable code segments necessary for verifying specific properties. By integrating low-level control-flow analysis with high-level Abstract Syntax Tree (AST) mapping, RustPruner reduces code volume and verification time while maintaining Rust's strict ownership and lifetime semantics.

Introduction

Program slicing involves stripping away code that does not affect a specific point of interest, such as a variable's value or an assertion. While well-established for C/C++, Rust’s ownership and lifetime models make haphazard code deletion impossible, as it often results in uncompilable code. RustPruner addresses this by ensuring that sliced programs remain semantically valid and compilable, facilitating practical formal verification for complex Rust codebases.

Methodology

The authors propose a three-stage framework to handle the complexities of the Rust language:

Overview of the RustPruner framework, illustrating the integration of Source Code Processing, AST Analysis, and Slicing Implementation.
  1. Source Code Processing: Using the Kani symbolic model checker, Rust code is transformed into a "goto-style" intermediate representation. A backward slicing algorithm, based on CBMC logic, identifies all statements influencing a specified "proof" point.
  2. AST Analysis: Simultaneously, the tool parses source code into an AST using the syn library. A "CodeCollector" identifies the precise "Span" (coordinates) of semantic units like functions and structs.
  3. Slicing Implementation: The tool maps low-level dependencies to high-level AST nodes. By preserving entire semantic blocks when required, RustPruner ensures the output respects Rust’s safety rules.

Evaluation and Results

RustPruner was evaluated on four real-world OS task scheduling modules (Projects A-D), averaging 1,079 lines of code.

Comparison of slice size and verification time relative to the original projects, showing consistent reductions across all test cases.

Key findings include:

  • Code Reduction: The tool achieved significant reductions, such as a 37% decrease in complexity for Project C.
  • Performance: Slicing is extremely fast, ranging from 1.25ms to 24.96ms.
  • Verification Efficiency: Reduced code size directly translated to faster verification times in Kani.
  • Consistency: Sliced programs maintained "verification consistency," producing identical results to the original source.

Conclusion

RustPruner demonstrates that effective Rust slicing requires a dual-layered approach combining control-flow analysis with AST preservation. While currently dependent on Kani and CBMC backends, future work aims to extend support to broader crate ecosystems and complex trait implementations.

Summary updated

BibTeX
@inproceedings{hu2024rustpruner,
  author = {Yanfeng Hu and Weihong Chen and Yilong Zhao and Ruiyu Zhang and Liangze Yin and Wei Dong},
  title = {{RustPruner: A Program Slicing Tool for Rust Programs}},
  booktitle = {SEKE},
  year = {2024},
  doi = {10.18293/seke2024-118},
}
Figure