← Latest papers
💻 computer science

Leaf: An Instrumentation-based Dynamic Analysis Framework for Rust

This paper introduces LEAF, a Rust-native dynamic analysis framework that leverages MIR-level semantic information and runtime facts via an event-driven interface to support diverse analysis tasks with manageable overhead.

Original authors: Mohammad Omidvar Tehrani, Marco Gaboardi, Nick Sumner, Steven Y. Ko

Published 2026-07-17
📖 6 min read🧠 Deep dive

Original authors: Mohammad Omidvar Tehrani, Marco Gaboardi, Nick Sumner, Steven Y. Ko

Original paper licensed under CC BY 4.0 (http://creativecommons.org/licenses/by/4.0/). This is an AI-generated explanation of the paper below. It is not written or endorsed by the authors. For technical accuracy, refer to the original paper. Read full disclaimer

The Detective's Toolkit for Code

Imagine you are a detective trying to solve a crime, but the crime scene is a computer program. In the world of software, "bugs" are the crimes—mistakes that cause programs to crash, leak secrets, or behave strangely. For a long time, detectives had to look at the crime scene after the fact, or try to predict every possible way a criminal could act before they even started. But what if you could put a tiny, invisible camera on every single move the program makes while it's running? You could watch it in real-time, seeing exactly where it trips, what it grabs, and where it goes wrong.

This is the world of dynamic analysis. It's like filming a play while the actors are performing, rather than just reading the script. However, there's a catch: modern programming languages are becoming incredibly complex. One of the most popular new languages is called Rust. Rust is famous for being super safe; it has strict rules about how programs handle memory (the computer's short-term storage) so that they don't accidentally delete things they still need or use things that are already gone. These rules are so strict that they are built into the language's very DNA. The problem is, most of the tools detectives use to watch programs run were built for older, less strict languages. They can see the actors moving, but they can't understand the specific, complex rules Rust actors are following. They miss the "why" behind the "what." This paper asks a simple but difficult question: Can we build a new kind of camera that doesn't just watch Rust programs run, but actually understands Rust's unique rules while doing it?

LEAF: The Rust Detective's New Glasses

The authors of this paper introduce LEAF (which stands for a framework for analyzing Rust programs). Think of LEAF as a pair of high-tech glasses for software detectives. Before LEAF, if you wanted to watch a Rust program run, you had to use tools that were either too dumb to understand Rust's special rules or too heavy and slow to be useful. LEAF changes the game by building a bridge between the program's "blueprint" and its actual performance.

Here is how it works, using a simple analogy. Imagine a chef (the Rust compiler) writing a recipe (the program). The chef writes the recipe in a special, detailed language called MIR (Mid-level Intermediate Representation). This language is like a blueprint that includes not just the ingredients, but also strict rules about who can touch the knife, when the oven can be opened, and how long the food stays fresh. Usually, once the chef finishes the blueprint, it gets turned into a dish (the running program), and the detailed rules are hidden away.

LEAF steps in by modifying the blueprint before the dish is cooked. It takes that detailed blueprint and inserts "probes" (tiny, invisible tags) directly into the instructions. These probes are designed to trigger while the program is actually running. When the program executes a specific rule, these probes pop up and shout out exactly what is happening, preserving the chef's original detailed rules. The authors call this stream of information DMIR (Dynamic MIR). It's like a live commentary that doesn't just say "The chef chopped the onion," but says, "The chef chopped the onion, and remember, in this specific recipe, the onion must be chopped with a left-handed knife, or the whole dish gets ruined."

To prove this isn't just a cool idea but a working tool, the team built three different "detective cases" using LEAF:

  1. A Concolic Executor: This is a super-smart tester that tries to break the program by guessing inputs. It's like a detective who tries every possible key to open a lock. Using LEAF, they built a version that is 11,749 lines of code long and successfully found tricky bugs in complex programs.
  2. A Rust-Specific Sanitizer: This tool hunts for a very specific type of Rust mistake called "use-after-drop." Imagine if you threw away a toy, but then tried to play with it anyway. Rust usually prevents this, but sometimes programmers have to do it manually. LEAF's sanitizer caught these mistakes in a tool that was only 1,746 lines of code.
  3. A Control-Flow Tracer: This is a simple tool that just draws a map of where the program went. It showed that LEAF could track the entire journey of a program with just 646 lines of code.

The team didn't just build these tools; they also measured how much "weight" LEAF adds to the program. They tested it on eight popular real-world Rust programs (like tools for handling web addresses, encryption, and even a WebAssembly runtime). They found that while LEAF does make the program slower and the file bigger, the cost is "meaningful but manageable." For example, in some tests, the program ran about 15 to 70 times slower than usual, and the file size grew significantly, but it still worked. They also found that you can turn off certain features to make it faster if you don't need all the details.

The paper is very clear about what it doesn't do: it doesn't claim to be magic. It admits that the cost of watching the program so closely is high. If you turn on every single sensor, the program can become hundreds of times slower. However, the authors show that by being selective—only watching the parts you care about—you can get the information you need without breaking the program.

In the end, the authors conclude that LEAF is a practical, working framework. It proves that you can watch Rust programs run in real-time while still understanding their complex, safety-first rules. It's not a perfect, zero-cost solution, but it fills a huge gap in the toolbox for anyone trying to keep Rust software safe and bug-free. The code for LEAF and their three detective tools is available for anyone to try, showing that this is a real, usable step forward for the Rust community.

Drowning in papers in your field?

Get daily digests of the most novel papers matching your research keywords — with technical summaries, in your language.

Try Digest →