LLM rewriting strips code watermarks, so RoCoMark turns embedder and rewriter into a multi-round game, reaching 74.2% detection AUROC
Synopsis
Large language models can rewrite code while preserving its functionality, substantially altering the syntactic and structural features that existing code watermarks rely on, so detection degrades. RoCoMark places the watermark embedder and an LLM rewriter in a multi-round attacker-defender game: the embedder first learns rewrite-stable representations through contrastive learning and knowledge distillation, then trains against rewriting strategies that evolve alongside it. Across four benchmarks and rewriting attacks from five LLMs, it reaches an average detection AUROC of 74.2%, a rewrite BitACC of 75.3%, and a code functionality pass rate above 99.7%.
Interpretation
RoCoMark keeps a code watermark detectable after an LLM performs a full functionality-preserving rewrite, not only under local perturbations such as variable renaming. Earlier neural code watermarking methods relied on predefined functionality-preserving transformations or fixed attack models and did not treat LLM rewriting as an adversarial threat during training, so their performance degraded under variable substitution, loop-structure replacement and equivalent formula transformations. On four benchmarks, HumanEval, MBPP, EvalPlus and APPS, with rewriting attacks generated by five LLMs, GPT-5.5, DeepSeek-V4-Flash, MiMo-V2.5-Pro, GLM-5 and Claude-Sonnet-4.5, RoCoMark achieves the highest AUROC under all five attacks; under the MiMo-V2.5-Pro attack it reaches an AUROC of 0.7408 and a TPR of 0.4638, above RoSeMary at 0.7182 and 0.4062 and SrcMarker at 0.6948 and 0.3617, while its FPR falls to 0.0463.
The watermark embedder gains robustness by absorbing rewriting strategies round after round, while the rewriter escalates its attack prompts in step, forming a continuing contest. The embedder is first warmed up with variable substitution and abstract syntax tree transformations, then enters threat profiling and strategy improvement, rather than being trained once on a fixed transformation set. Threat profiling uses contrastive learning and knowledge distillation to constrain the encoder representation so that code representations stay stable before and after rewriting; strategy improvement jointly optimizes the encoder and extractor and uses a Reflexion-based prompt evolution mechanism with short- and long-term memory pools to generate stronger rewrites. The ablation on MBPP under MiMo-V2.5-Pro rewrites shows threat profiling raising rewrite AUROC from 0.7061 to 0.7299, strategy improvement bringing it to 0.7320, and multi-round optimization reaching 0.7408 at round 2 before a slight decline to 0.7403 at round 3.
Perspective
The demonstrated scope is Python code: training uses the Python subset of CodeSearchNet, evaluation covers HumanEval, MBPP, EvalPlus and APPS, and attacks come from functionality-preserving rewrites generated by five LLMs plus variable renaming at several ratios. Readers should treat it as an assessment of watermark robustness under rewriting attacks, not as a deployment conclusion for other languages or arbitrary codebases.
Multi-round strategy improvement stops gaining after round 2 and AUROC declines slightly at round 3, which the authors attribute to overfitting to a fixed rewriting distribution. Post-rewrite bit accuracy falls as watermark length grows, with RoCoMark at 0.9122 for 8 bits, which the authors note is constrained by the available transformation space. Robustness to cross-language rewriting is listed as future work.
