The Move Borrow Checker

Sam Blackshear, John C. Mitchell, Todd Nowacki, Shaz QadeerarXiv 2022

Abstract

The Move language provides abstractions for programming with digital assets via a mix of value semantics and reference semantics. Ensuring memory safety in programs with references that access a shared, mutable global ledger is difficult, yet essential for the use-cases targeted by Move. The language meets this challenge with a novel memory model and a modular, intraprocedural static reference safety analysis that leverages key properties of the memory. The analysis ensures the absence of memory safety violations in all Move programs (including ones that link against untrusted code) by running as part of a load-time bytecode verification pass similar to the JVM and CLR. We formalize the static analysis and prove that it enjoys three desirable properties: absence of dangling references, referential transparency for immutable references, and absence of memory leaks.

Introduction

Smart contracts manage digital assets with real-world value, making memory safety a high-stakes requirement. In languages like C, "dangling references" (pointing to memory that has been freed or moved) can lead to catastrophic security vulnerabilities or non-deterministic execution. While languages like Rust solve this at the source-code level, blockchains face a unique challenge: the adversarial environment. An attacker can write malicious bytecode directly to bypass source-level checks. Furthermore, traditional solutions like Garbage Collection (GC) are unsuitable for blockchains because they make "gas metering" (predicting execution cost) unpredictable. Move addresses this by enforcing a strict ownership and borrowing discipline at the virtual machine level, ensuring that digital assets cannot be leaked or double-spent.

Bytecode-Level Reference Safety

Unlike many languages that perform safety checks during compilation, Move’s analysis runs as part of a load-time bytecode verifier. This ensures safety properties hold regardless of which compiler generated the code. The system translates high-level reference operations into specific bytecode instructions that the verifier can analyze for safety violations.

Mapping of source-level reference operations to Move bytecode instructions.

As shown in Figure 2, operations like borrowing a location or reading a reference are mapped to discrete bytecode steps. The checker maintains an abstract directed acyclic graph (DAG) during analysis where nodes represent locations and edges represent "borrows." The analysis enforces that a value cannot be moved or modified if there are active borrows originating from it. When a reference is dropped, its corresponding edges are removed, releasing the parent value for use.

Global Storage and Modular Analysis

Move organizes memory as a forest of trees, where local variables and global storage serve as roots. This structure simplifies alias analysis by using structured access paths. To maintain modularity and speed, Move requires acquires annotations on procedures that touch global storage, turning a global reasoning problem into a local one.

Core primitives for managing global storage in Move.

The primitives shown in Figure 3 allow for publishing, removing, and borrowing resources from global storage. By restricting how these references are used—for example, banning the return of references to global memory—the system ensures that the borrow checker remains fast and efficient enough for real-time transaction validation. This "no-alias" rule for mutable parameters allows developers to reason about code without worrying that changing one variable will secretly affect another.

Evaluation and Results

The Move borrow checker was evaluated on three significant, real-world codebases: Anon (the core framework for the Diem blockchain), StarCoin, and dFinance. The results demonstrate both high performance and high utility:

  • Performance: The checker is highly efficient, analyzing approximately 1,200 bytecode instructions per millisecond on a standard laptop. This speed is crucial for blockchain validators who must verify transactions in real-time.
  • Real-World Utility: References are a core feature rather than a niche one; in the Anon codebase, 60% of procedures use references in their signatures, and nearly half interact with global storage.
  • Formal Guarantees: The system successfully prevents dangling references, memory leaks, and unauthorized access to moved memory, providing referential transparency for immutable references.

Conclusion

The Move borrow checker successfully brings Rust-style memory safety to the bytecode level. By leveraging a tree-shaped memory model and a modular static analysis, it provides formal guarantees against common memory vulnerabilities while remaining performant enough for production blockchain environments. While the analysis is currently conservative regarding complex control flows and global reference returns, it provides a robust foundation for secure smart contract development.

Summary updated

BibTeX
@misc{blackshear2022move,
  author = {Sam Blackshear and John C. Mitchell and Todd Nowacki and Shaz Qadeer},
  title = {{The Move Borrow Checker}},
  year = {2022},
  eprint = {2205.05181},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2205.05181},
}
Figure