English

Optimizing Token Choice for Code Watermarking: An RL Approach

Cryptography and Security 2026-05-26 v3 Computation and Language Machine Learning

Abstract

Protecting intellectual property on LLM-generated code necessitates effective watermarking systems that can operate within code's highly structured, syntactically constrained nature. In this work, we introduce CodeTracer, an innovative adaptive code watermarking framework underpinned by a novel reinforcement learning training paradigm. At its core, CodeTracer features a policy-driven approach that utilizes a parameterized model to intelligently bias token choices during next-token prediction. This strategy ensures that embedded watermarks maintain code functionality while exhibiting subtle yet statistically detectable deviations from typical token distributions. To facilitate policy learning, we devise a comprehensive reward system that seamlessly integrates execution feedback with watermark embedding signals, balancing process-level and outcome-level rewards. Additionally, we employ Gumbel Top-k reparameterization to enable gradient-based optimization of discrete watermarking decisions. Extensive comparative evaluations demonstrate CodeTracer's significant superiority over state-of-the-art baselines in both watermark detectability and the preservation of generated code's functionality. Our code is available at https://github.com/TimeLovercc/CodeTracer.

Keywords

Cite

@article{arxiv.2508.11925,
  title  = {Optimizing Token Choice for Code Watermarking: An RL Approach},
  author = {Zhimeng Guo and Huaisheng Zhu and Siyuan Xu and Hangfan Zhang and Teng Xiao and Minhao Cheng},
  journal= {arXiv preprint arXiv:2508.11925},
  year   = {2026}
}

Comments

ICML 2026, 18 pages, 3 figures

R2 v1 2026-07-01T04:52:51.957Z