← Latest papers
💻 computer science

From Rocq to Metal: A Pipeline for Formally Verified Microcontroller Firmware

This paper presents Encore!, a bare-metal Continuation Passing Style virtual machine that enables the execution of formally verified, Rocq-extracted Scheme firmware on microcontrollers by structuring the core as a provable state-transition function, thereby facilitating AI-assisted generation of safety-critical code with machine-checked guarantees.

Original authors: Valentin Bergeron, Karolina Gorna

Published 2026-06-03
📖 5 min read🧠 Deep dive

Original authors: Valentin Bergeron, Karolina Gorna

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

Imagine you are building a high-security vault for a bank. You need to write the instructions (the "firmware") that tell the vault how to open, close, and count money. In the past, writing these instructions was hard, and checking them for mistakes was even harder. Now, with AI, we can generate these instructions instantly, but that creates a new problem: How do we trust code that was written by a machine we can't fully understand?

This paper, "From Rocq to Metal," presents a solution: a way to write these critical instructions in a language that is mathematically proven to be perfect, and then run that proof directly on tiny, cheap computer chips found in devices like hardware wallets.

Here is the breakdown of their approach using simple analogies:

1. The Problem: The "Heavy Suit" vs. The "Tiny Robot"

Most modern programming languages that allow for "mathematical proof" (like Lean 4 or standard OCaml) are like heavy, high-tech spacesuits. They are great for astronauts (powerful computers), but they are too heavy and bulky for a tiny robot (a microcontroller chip) that has to fit inside a credit card-sized device.

  • The Issue: If you try to put that heavy spacesuit on the tiny robot, the robot collapses under the weight. It doesn't have enough battery (RAM) or storage (Flash) to run the "proof" software.
  • The Old Way: Developers used to write the code in the heavy suit, then manually translate it into a simple language for the robot. But this translation is like a game of "Telephone"—errors creep in, and the mathematical proof is lost.

2. The Solution: "Encore!" (The Lightweight Translator)

The authors built a new tool called Encore!. Think of Encore! as a specialized, ultra-lightweight translator that fits inside the tiny robot's pocket.

  • How it works: You write your instructions in a rigorous, mathematical language called Rocq (which is like writing a recipe in perfect, unchangeable logic).
  • The Magic: Instead of translating the recipe into a messy, error-prone language, Encore! converts it directly into a tiny, efficient "bytecode" that the robot can execute.
  • The Result: The robot runs the exact same logic that was mathematically proven. There is no "Telephone" game; the proof travels all the way to the metal.

3. The Architecture: The "State Machine"

To make this work, the authors reorganized how the software is built. They treat the device like a board game.

  • The Game Board (State): The current situation (e.g., "Waiting for a user to press a button").
  • The Dice Roll (Event): Something happens (e.g., "User pressed the button").
  • The Rulebook (The Proven Core): A pure, mathematical function that says: "If the board is in State A and you roll a 6, the board must move to State B."
  • The Referee (The Unverified Part): The parts of the system that talk to the physical world (reading the button, lighting up the screen). These are the only parts that aren't mathematically proven, but they are kept very small and simple.

Why this matters: The "Rulebook" (the business logic) can grow as big and complex as you want, and it remains 100% provable. The "Referee" stays small and constant. This means you can add complex features without making the security harder to verify.

4. The AI Connection: "Proofs as Code Reviews"

The paper suggests a future where AI helps write the code, but the AI doesn't just guess.

  • Old Way: An AI writes code; a human reads it to check for bugs. This doesn't scale well.
  • New Way: An AI writes the mathematical proof (the theorem). The computer checks the proof. If the proof is valid, the code is guaranteed to be correct.
  • The Analogy: Instead of asking a human to read a 100-page novel to find a typo, you ask a computer to check a 10-page math equation. If the equation is right, the story is right.

5. The Results: It Actually Works

The team tested this on real hardware (a Ledger Flex hardware wallet, which uses a very small, secure chip).

  • They took a transaction signing app (the kind of thing that moves money).
  • They wrote the core logic in Rocq and proved it was correct.
  • They used Encore! to run it on the chip.
  • The Outcome: The chip successfully ran the mathematically proven code, parsed data, and signed transactions, all while fitting within the tiny memory limits of the device.

Summary

The paper proves that you don't have to choose between high security (mathematical proofs) and tiny hardware (microcontrollers). By building a custom, lightweight engine (Encore!) and structuring software like a simple board game, they showed that "perfect" code can run on "imperfect" chips today. This opens the door for AI-generated code that is automatically verified, making critical devices like hardware wallets safer and more reliable.

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 →