Abstract
As Large Language Models (LLMs) increasingly automate software development, protecting the intellectual property (IP) of generated code has become a critical challenge. Existing watermarking techniques often fail due to the low entropy of code or the "disclosure dilemma," where proving ownership requires revealing the secret watermark. This paper introduces RoSeMary, a novel "ML/Crypto codesign" framework. RoSeMary utilizes a CodeT5-based neural network to embed robust, functionality-preserving watermarks through syntactic transformations. Simultaneously, it leverages Zero-Knowledge Proofs (ZKPs) to enable secure, third-party verification without exposing the underlying secret signature. Experimental results on benchmarks like HumanEval and MBPP demonstrate that RoSeMary achieves high detection accuracy (0.97 AUROC) and maintains near-zero functionality loss, providing a practical and secure solution for code IP protection.
Introduction
The rapid adoption of LLMs like GitHub Copilot and Qwen has introduced significant legal and ethical challenges regarding code authorship and plagiarism. Proving that a specific code snippet originated from a particular model is difficult because code is highly structured and has low entropy; minor changes can easily break functionality. Furthermore, traditional watermarking faces a "disclosure dilemma": to prove ownership in a legal setting, the owner must typically reveal the secret watermark, rendering it vulnerable to future removal by adversaries.
The RoSeMary Framework
RoSeMary addresses these challenges by merging deep learning with cryptographic verification. The framework operates in a three-party ecosystem involving the Code LLM owner, the end user, and a third-party arbitrator.
ML Component: Robust Watermark Insertion
Instead of simple lexical swaps, RoSeMary employs a pre-trained CodeT5 backbone to perform "functionality-invariant" transformations. These structural changes—such as swapping for loops for while loops or refactoring nested logic—are harder for adversaries to detect and remove without breaking the code.
The system is trained end-to-end with three primary objectives:
- Fidelity (Functionality Loss $L_f$): Ensuring the watermarked code remains executable and logically identical to the original.
- Detectability (Detectability Loss $L_d$): Making the embedded mark easily identifiable by the extraction model.
- Robustness (Robustness Loss $L_r$): Ensuring the watermark survives common adversarial attacks like variable renaming or refactoring.
Crypto Component: Secure ZKP Verification
RoSeMary’s standout innovation is the use of Zero-Knowledge Proofs (ZKPs) via the Halo2 and EZKL frameworks. When a dispute occurs, the model owner generates a cryptographic proof showing they possess the secret signature corresponding to the code's features. This proof can be verified by an arbitrator in milliseconds without the owner ever revealing the actual secret watermark, thus solving the disclosure dilemma.
Experimental Evaluation
The authors evaluated RoSeMary using standard industry benchmarks: HumanEval, MBPP, and EvalPlus. The models were trained on the CodeSearchNet corpus.
Key Results
- High Detection Accuracy: RoSeMary achieved a 0.97 AUROC across benchmarks, effectively distinguishing watermarked code from clean code.
- Minimal Functionality Impact: The framework maintained a 95%+ pass rate on HumanEval, matching the performance of un-watermarked models.
- Resilience to Attacks: Even under "Variable-rename" attacks affecting 50% of variables, the system maintained an AUROC of 0.93.
- Verification Efficiency: ZKP verification is extremely fast, taking only 120ms, making it suitable for real-world legal audits.
Discussion and Limitations
RoSeMary demonstrates that structural, syntactic transformations are superior to lexical ones for code watermarking. By using CodeT5 as a feature extractor, it significantly outperforms previous state-of-the-art tools like SrcMarker.
However, some limitations remain. There is an "entropy ceiling" where increasing the watermark message length (e.g., beyond 4 bits) reduces detectability in short scripts. Additionally, while verification is fast, generating the ZKP proof takes approximately 6.8 seconds and requires significant memory (~2.8 GB), which may limit its use in high-volume automated scanning. Future work will focus on expanding the framework to languages beyond Python, such as C++ and Java.
Conclusion
RoSeMary represents a significant step forward in securing AI-generated intellectual property. By codesigning machine learning and cryptography, it provides a robust, functionality-preserving, and privacy-respecting solution for the growing challenges of code authorship in the age of LLMs.
Summary updated