Grammar-Guided Code Watermarking with Green Temperature
Abstract
Large language model watermarking embeds detectable statistical signals during decoding, but the resulting changes to token probabilities can degrade generation quality. This trade-off is particularly important for code, where small changes in token selection can break syntax or alter program behavior. Existing code watermarking methods mitigate this risk through entropy-based insertion or syntax-aware token selection, but they do not directly construct the watermark over the set of continuations admitted by the current grammar state. We propose Grammar-Guided Code Watermarking with Green Temperature (GTCW), which integrates grammar-constrained decoding with probability-aware watermarking. At each decoding step, GTCW restricts the candidate set to grammar-admissible tokens and partitions this support into keyed green and red subsets. At eligible high-entropy positions, green temperature reweights the green tokens according to the model's relative preferences, strengthening the watermark signal while retaining the grammar constraint. Across five models and five benchmarks spanning four programming languages, GTCW achieves a mean AUROC of 73.61%, compared with 67.83% for the strongest baseline, while maintaining a mean Pass@1 of 59.18% versus 59.58% for unwatermarked generation. Our implementation is available at https://github.com/hyundong98/GTCW .
Create a lesson
Metadata
- Categories
- cs.CR, cs.AI
Related papers
Constitution-Guided Watermarking
Shared title terminologycs.CRToluwani Aremu, Samuele Poppi, Nils Lukas
Rethinking Visual Provenance: Detection and Watermarking Across Direct Visual Generation and LLM-Driven Code Rendering
Shared title terminologycs.CRZheng Gao, Xiaoyu Li, Zhicheng Bao et al.
RMCW: A Deletion-Robust Watermark Based on Reed--Muller Codes for Language Models
Shared title terminologycs.CRYi Wang, Baicheng Chen, Yu Wang et al.
From Binary to Source Code: Measuring LLMs Reverse Engineering Capabilities on Obfuscated Binaries
Shared title terminologycs.CRDavid Schmidt, Patrick Felbauer, Gabriel Gegenhuber et al.
Bit Accuracy is not Enough: Revisiting User Capacity of Multi-bit Watermarks
Shared title terminologycs.CRXiao Ren, Zhikun Zhang, Linkang Du et al.
Secure-Miner: Improving Secure Code Generation for LLMs by Mining Secure Coding Practices
Shared title terminologycs.CRJunjie Li, Jinqiu Yang