English

Towards Generalized and Stealthy Watermarking for Generative Code Models

Cryptography and Security 2025-07-01 v2

Abstract

Generative code models (GCMs) significantly enhance development efficiency through automated code generation and code summarization. However, building and training these models require computational resources and time, necessitating effective digital copyright protection to prevent unauthorized leaks and misuse. Backdoor watermarking, by embedding hidden identifiers, simplifies copyright verification by breaking the model's black-box nature. Current backdoor watermarking techniques face two main challenges: first, limited generalization across different tasks and datasets, causing fluctuating verification rates; second, insufficient stealthiness, as watermarks are easily detected and removed by automated methods. To address these issues, we propose CodeGuard, a novel watermarking method combining attention mechanisms with distributed trigger embedding strategies. Specifically, CodeGuard employs attention mechanisms to identify watermark embedding positions, ensuring verifiability. Moreover, by using homomorphic character replacement, it avoids manual detection, while distributed trigger embedding reduces the likelihood of automated detection. Experimental results demonstrate that CodeGuard achieves up to 100% watermark verification rates in both code summarization and code generation tasks, with no impact on the primary task performance. In terms of stealthiness, CodeGuard performs exceptionally, with a maximum detection rate of only 0.078 against ONION detection methods, significantly lower than baseline methods.

Keywords

Cite

@article{arxiv.2506.20926,
  title  = {Towards Generalized and Stealthy Watermarking for Generative Code Models},
  author = {Haoxuan Li and Jiale Zhang and Xiaobing Sun and Xiapu Luo},
  journal= {arXiv preprint arXiv:2506.20926},
  year   = {2025}
}

Comments

13 pages

R2 v1 2026-07-01T03:33:52.864Z