Robust and Secure Code Watermarking for Large Language Models via ML/Crypto Codesign
The paper introduces RoSeMary, a novel ML/Crypto codesign framework that utilizes end-to-end training with CodeT5 and zero-knowledge proofs to embed robust, functional, and privacy-preserving watermarks into LLM-generated code, effectively addressing the challenges of low entropy and secure verification.
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 a world where computers don't just chat with us but actually write the blueprints for our digital lives. This is the realm of Large Language Models (LLMs) for code, the super-smart AI assistants that can generate software functions, fix bugs, and build entire programs just by reading a prompt. But here's the catch: when these AIs write code, it's often hard to tell who really owns it. Did a human engineer write it, or did an AI? And if an AI did, which company's AI? This is a big deal because code is valuable intellectual property, like a secret recipe or a patented invention.
To solve this, scientists have been trying to "watermark" AI code. Think of this like a digital invisible ink or a hidden watermark on a banknote. You want to be able to prove, "Hey, this code was made by my AI," without changing how the code works. But there's a tricky problem: code is very rigid. Unlike a story where you can swap words for synonyms, code has to follow strict rules to run. If you change too much to hide a secret message, the program breaks. Furthermore, to prove ownership in court, you usually have to show the secret key (the watermark) to a judge. But if you show the key, bad guys can steal it and fake their own watermarks later. It's a frustrating game of "hide and seek" where the rules of the game make it nearly impossible to win without losing something else.
This is where a new framework called RoSeMary steps in, acting like a clever magician who can hide a secret message in a locked box without ever showing the key. The researchers, a team from the University of California, San Diego and San Diego State University, designed a system that combines machine learning (the AI part) with cryptography (the secret math part). They figured out how to embed a hidden signature into AI-generated code that is tough to remove, keeps the code working perfectly, and—most importantly—allows a judge to verify ownership without ever seeing the actual secret signature.
Here is how RoSeMary pulls off this magic trick. First, it uses a pre-trained AI model called CodeT5, which is like a master chef who has tasted millions of recipes. Instead of just randomly changing code, this chef understands the "flavor" of the code. It takes the original code and a secret message (the watermark) and decides on the best way to tweak the code slightly—like renaming a variable from x to item or changing a while loop to a for loop—so that the secret message is hidden inside these tiny changes. Because the chef knows the rules of cooking (programming), the code still tastes exactly the same (works perfectly) even with the secret ingredient added.
But the real magic happens when it's time to check if the code is authentic. Usually, you'd have to hand over the secret recipe to a judge. RoSeMary uses a cryptographic tool called a Zero-Knowledge Proof (ZKP). Imagine you want to prove to a friend that you know the combination to a safe, but you don't want to tell them the numbers. You could open the safe in front of them, show them the treasure inside, and then close it again. They know you know the combination, but they never saw the numbers. RoSeMary does something similar. The AI owner runs a complex math circuit that checks if the hidden signature is there. It generates a tiny, digital "proof" that says, "Yes, the signature is valid," without revealing what the signature actually is.
The team tested this system on thousands of code examples in languages like Python, Java, and C++. They found that RoSeMary is incredibly good at its job. It successfully hid the watermark in 97.64% of the cases (meaning the code still worked), and it could detect the watermark with an accuracy score of 0.97 (where 1.0 is perfect). Even when bad actors tried to break the watermark by renaming variables or using other AI to rewrite the code, RoSeMary still found the hidden message 98% of the time.
Perhaps the most impressive part is the speed and privacy. The system can generate a proof of ownership in about 7.15 seconds, and a judge can verify that proof in just 118.6 milliseconds (less than a blink of an eye). Crucially, during this entire process, the judge never sees the actual secret watermark. This means the owner can reuse the same watermark over and over again without worrying that someone will steal it and forge a fake claim of ownership.
In short, RoSeMary solves a three-way tug-of-war that has stumped researchers for a while. It manages to keep the code working (fidelity), make the watermark easy to find (detectability), and make it hard to break (robustness), all while keeping the secret key safe from prying eyes. It's a significant step forward in protecting the intellectual property of the AI revolution, ensuring that when an AI writes a masterpiece, the artist gets the credit—and the protection—they deserve.
Drowning in papers in your field?
Get daily digests of the most novel papers matching your research keywords — with technical summaries, in your language.