# RoCoMark: Robust Code Watermarking Against LLM-Based Functionality-Preserving Rewriting Attacks

DevFeed: [RoCoMark: Robust Code Watermarking Against LLM-Based Functionality-Preserving Rewriting Attacks](<https://devfeed.tech/articles/rocomark-robust-code-watermarking-against-llm-based-functionality-preserving-rewriting-attacks-126956.md>)

Original publisher: [Read original article](<https://arxiv.org/abs/2611.11399>)

Author: Hongjie Zhang, Xingcheng Li, Hanzhou Wu, Zhihua Xia, Xinpeng Zhang

Published: 2026-11-10T05:00:00Z

Content type: article

Language: en

Sources: [arXiv: Cryptography and Security](<https://devfeed.tech/sources/arxiv-cryptography-and-security.md>)

Topics: [obfuscation](<https://devfeed.tech/topics/obfuscation.md>), [Large Language Model](<https://devfeed.tech/topics/llm.md>), [Adversarial attacks](<https://devfeed.tech/topics/adversarial-attacks.md>)

Tags: [adaptive](<https://devfeed.tech/tags/adaptive.md>), [attacks](<https://devfeed.tech/tags/attacks.md>), [benchmarks](<https://devfeed.tech/tags/benchmarks.md>), [code](<https://devfeed.tech/tags/code.md>), [cs-cr](<https://devfeed.tech/tags/cs-cr.md>), [detection](<https://devfeed.tech/tags/detection.md>), [experiments](<https://devfeed.tech/tags/experiments.md>), [knowledge-distillation](<https://devfeed.tech/tags/knowledge-distillation.md>), [language-models](<https://devfeed.tech/tags/language-models.md>), [llm](<https://devfeed.tech/tags/llm.md>), [minimax](<https://devfeed.tech/tags/minimax.md>), [robust](<https://devfeed.tech/tags/robust.md>), [robustness](<https://devfeed.tech/tags/robustness.md>), [watermarking](<https://devfeed.tech/tags/watermarking.md>)

## AI overview

RoCoMark addresses code watermark degradation under functionality-preserving LLM rewrites by training the watermark embedder and rewriter in a multi-round minimax process. It profiles rewritten code using contrastive learning and knowledge distillation while mitigating representation drift, jointly optimizes the watermark encoder and extractor, and evolves attacks using Reflexion with short- and long-term memory. Across four benchmarks and attacks generated by five LLMs, the abstract reports average detection AUROC of 74.2%, Rewrite BitACC of 75.3%, and code functionality pass rates above 99.7%.

## Source excerpt

arXiv:2611.11399v1 Announce Type: new 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%.