RoCoMark: Robust Code Watermarking Against LLM-Based Functionality-Preserving Rewriting Attacks
Hongjie Zhang, Xingcheng Li, Hanzhou Wu, Zhihua Xia, Xinpeng Zhang
Abstract
Large Language Models (LLMs) present significant challenges to source tracing of generated code, as LLM rewriting can substantially alter the syntactic and structural characteristics of watermarked code. However, existing watermarking methods often suffer severe performance degradation under LLM-based functionality-preserving rewriting attacks. We attribute this vulnerability not merely to the intensity of rewriting, but to a fundamental distribution mismatch between the perturbations encountered during watermark training and the global, non-deterministic rewriting behaviors induced by LLMs. In order to deal with this challenge, we propose RoCoMark, a Robust Code waterMarking framework that explicitly learns and adapts to LLM rewriting behaviors. RoCoMark is a multi-round minimax game between the watermark embedder and LLM rewriter. In each round, the embedder first learns threat profiling from LLM-rewritten code by optimizing the watermark encoder through contrastive learning and knowledge distillation while mitigating catastrophic representation drift. Then the embedder improves strategies by optimizing the watermark encoder and extractor simultaneously. Finally, an adaptive attack-evolution mechanism based on Reflexion and short- and long-term memory pools is applied, enabling continuous interaction between the watermark embedder and evolving rewriting strategies. This iterative attacker-defender process progressively improves the robustness of the watermark against diverse and previously unseen LLM rewriting behaviors. Extensive experiments on four typical benchmarks, under attacks generated by five LLMs, show the effectiveness of RoCoMark. RoCoMark achieves an average detection AUROC of 74.2% and a Rewrite BitACC of 75.3%, while maintaining a code functionality pass rate above 99.7%.
Create a lesson
Metadata
- Comments
- 17 pages (minor update)
Related papers
Preserve the Vulnerability, Break the Alert: Testing the Robustness of CodeQL Taint Tracking with Natural Rewrites
Shared title terminologycs.CRZhezhen Cao, Weiyuan Ding, Bowen Xu
More Is Never Less: Affordable Robustness to Additive Attacks via Monotone Multiple-Instance Learning
Shared title terminologycs.CRAlexander Herzog, Shae McFadden, Lorenzo Cavallaro
Memory Safety Isn't All You Need: Code Reuse Attacks in Memory Safe Languages
Shared title terminologycs.CREric Cornelissen, Musard Balliu
Evaluating the Robustness of PRNU Source-Camera Attribution to the Fingerprint-Copy Attack: An Open Toolkit with Triangle-Test Detection
Shared title terminologycs.CRZeno J. M. H. Geradts
Beyond Attack-Based Accuracy: Rethinking Adversarial Robustness Evaluation Through Structural Gradient Alignment
Shared title terminologycs.CRHanrui Wang, Yu Luo, Shuo Wang et al.
From Attack Surface to Defense Architecture: Compositional Security for Agentic Coding Harnesses
Shared title terminologycs.CRSimon Hegelich, Bardh Prenkaj, Habiba Sarhan et al.