Skip to main content
QUICK REVIEW

[Paper Review] KRust: A Formal Executable Semantics of Rust

Feng Wang, Fu Song|arXiv (Cornell University)|Apr 28, 2018
Security and Verification in ComputingComputer Science17 references7 citations
TL;DR

This paper presents KRust, the first formal executable operational semantics of Rust, defined in the $Κ$ framework. It captures core Rust features like ownership, borrowing, and lifetimes, enabling automatic generation of interpreters and formal analysis tools. The semantics has been validated against hundreds of tests, including the official Rust test suite, establishing a solid foundation for formal verification and tool development.

ABSTRACT

Rust is a new and promising high-level system programming language. It provides both memory safety and thread safety through its novel mechanisms such as ownership, moves and borrows. Ownership system ensures that at any point there is only one owner of any given resource. The ownership of a resource can be moved or borrowed according to the lifetimes. The ownership system establishes a clear lifetime for each value and hence does not necessarily need garbage collection. These novel features bring Rust high performance, fine low-level control of C and C++, and unnecessity in garbage collection, which differ Rust from other existing prevalent languages. For formal analysis of Rust programs and helping programmers learn its new mechanisms and features, a formal semantics of Rust is desired and useful as a fundament for developing related tools. In this paper, we present a formal executable operational semantics of a realistic subset of Rust, called KRust. The semantics is defined in K, a rewriting-based executable semantic framework for programming languages. The executable semantics yields automatically a formal interpreter and verification tools for Rust programs. KRust has been thoroughly validated by testing with hundreds of tests, including the official Rust test suite.

Motivation & Objective

  • To address the lack of a formal, executable semantics for Rust, which hinders formal program analysis and tool development.
  • To provide a precise, machine-readable semantics for Rust's unique features—ownership, borrowing, and lifetimes—beyond what existing languages like C++ or Java support.
  • To enable automatic generation of interpreters, model checkers, and symbolic execution engines via the $Κ$ framework.
  • To validate the semantics rigorously using both hand-crafted tests and the official Rust test suite.
  • To lay the foundation for future formal verification of Rust programs and tooling by providing a correct, executable reference.

Proposed method

  • Define a formal operational semantics for a realistic subset of Rust using the $Κ$ framework, a rewriting-based executable semantic framework.
  • Model program state with explicit ownership and borrowing rules, distinguishing mutable and immutable references and enforcing lifetime constraints.
  • Use $Κ$'s modular and executable semantics to generate an interpreter and formal analysis tools automatically.
  • Design the semantics to be extensible and modular, supporting incremental extension with new language features.
  • Validate the semantics through extensive testing, including the official Rust test suite and custom test cases.
  • Ensure correctness and consistency by aligning the semantics with Rust’s actual behavior and type system.

Experimental results

Research questions

  • RQ1How can Rust’s ownership, borrowing, and lifetime system be formally and precisely captured in an executable semantics?
  • RQ2Can a formal semantics for Rust be implemented and validated using the $Κ$ framework to ensure correctness and executability?
  • RQ3To what extent does the formal semantics match the behavior of the actual Rust compiler and standard library?
  • RQ4What formal analysis tools (e.g., model checkers, symbolic executors) can be automatically derived from the semantics?
  • RQ5How can the semantics serve as a reliable foundation for future verification tools and language implementation?

Key findings

  • KRust is the first formal executable semantics of Rust, defined in the $Κ$ framework, enabling automatic generation of interpreters and formal analysis tools.
  • The semantics has been thoroughly tested and passes all official Rust test suite cases and hundreds of hand-crafted tests, confirming its correctness and robustness.
  • The formalization successfully models Rust’s core safety mechanisms: ownership transfer, mutable and immutable borrowing, and lifetime enforcement.
  • The $Κ$-based approach enables modularity and extensibility, allowing future extension to support additional Rust features such as traits, closures, and unsafe code.
  • The semantics serves as a formal reference for implementing and verifying Rust tools, including debuggers, compilers, and static analyzers.
  • The work establishes a foundational step toward formal verification of Rust programs and paves the way for formally verified Rust compilers and runtime systems.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.