← Latest papers
🤖 AI

CNnotator: LLM-Guided Memory Safety Annotation Synthesis

The paper introduces CNnotator, a tool that leverages large language models to automatically synthesize and verify memory safety annotations (CN specifications) for legacy C code, demonstrating that current AI models can achieve high success rates in identifying memory usage patterns to facilitate migration to safer languages.

Original authors: Twain Byrnes, Mike Dodds

Published 2026-06-23
📖 4 min read☕ Coffee break read

Original authors: Twain Byrnes, Mike Dodds

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 have an old, handwritten recipe book written in a very dangerous kitchen language called C. In this language, the chef (the programmer) has to manually manage every single ingredient. If they forget to put a lid on a pot, or if they try to use a spoon that's already been thrown in the trash, the whole kitchen can catch fire. These are called memory safety errors, and they cause a huge number of security bugs in the software we use every day.

Modern languages like Rust are like a kitchen with smart appliances: they automatically lock the oven if you try to open it while it's hot, or they won't let you grab a spoon that doesn't exist. But we can't just throw away our old recipe books. We need to figure out exactly how the old chefs were using their ingredients so we can either fix the recipes or translate them into the new, safe language.

The problem is that in the old books, the rules for using ingredients aren't written down. They are hidden in the messy steps. Figuring them out is like trying to guess a secret code just by watching someone cook. It's tedious and easy to get wrong.

The New Tool: CNnotator

The authors built a tool called CNnotator to help with this. Think of it as a team consisting of two people:

  1. The Guessing Chef (The AI): This is a Large Language Model (LLM). It's very good at looking at a messy recipe and guessing, "Oh, I bet this chef is holding onto this spoon until the very end." It tries to write down the hidden rules as a formal contract.
  2. The Strict Inspector (The Formal Tool): This is a computer program called CN. It doesn't trust the Guessing Chef. Its only job is to check the guesses. It takes the written rules and runs the recipe 100 times with different random ingredients to see if the kitchen stays safe.

How It Works (The "Guess-and-Check" Loop)

The tool works in a simple cycle:

  1. Pick a recipe: The tool looks at one function (a specific cooking step) in the C code.
  2. Ask the AI: "Hey AI, write down the rules for how this step handles ingredients."
  3. The AI guesses: The AI writes a "contract" (a set of rules) describing who owns which ingredient and when it's safe to use them.
  4. The Inspector tests: The tool runs the code 100 times based on those rules.
    • If it passes: Great! The rules are likely correct. Move to the next recipe.
    • If it fails: The Inspector says, "You said the spoon was safe, but it exploded!" The tool sends this error back to the AI: "Try again, but fix this specific mistake."
  5. Repeat: The AI tries again, up to six times, until it gets it right or gives up.

The Results

The researchers tested this on 31 different "recipes" (C functions) ranging from simple tasks to slightly complex ones. They tried it with five different AI models.

  • The Star Performer: The AI model called o3 was the best. It got the rules right on the very first try for 90% of the recipes. By the time it was allowed to try again a few times, it succeeded on 97% of them.
  • The Chatbot: Even the older, standard chat model (GPT-4o) did a decent job, getting it right on the first try about 65% of the time.
  • The Safety Net: The tool was also smart enough to spot "broken" recipes. If the code had a guaranteed bug (like trying to use a spoon that was already thrown away), the AI would say, "I can't write a safe rule for this because the recipe itself is broken," and stop.

Why This Matters

The paper argues that we don't need to trust the AI to be perfect. We just need it to be a good guesser. Because we have a strict inspector (the formal tool) that checks every guess, we can trust the final result even if the AI makes mistakes along the way.

This approach suggests that we can now use AI to help us understand and modernize old, dangerous C code, making it safer without having to manually rewrite every single line of code by hand. It's like having a super-fast apprentice who can draft the safety rules, while a master inspector makes sure the building doesn't collapse.

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 →