Grammar-Guided Code Watermarking with Green Temperature

📅 2026-10-04
📈 Citations: 0
✨ Influential: 0
📄 PDF
🤖 AI Summary
This study addresses the inherent conflict between watermark detection signals and generation quality as well as syntactic correctness in code watermarking by proposing the GTCW framework. To the best of our knowledge, this work is the first to construct watermarks over the set of legal continuations permitted by the current syntax state. It integrates syntax-constrained decoding, key-based green-red subset partitioning, and an entropy-aware green-temperature reweighting mechanism to strengthen the watermark signal while guaranteeing code validity. Experimental results demonstrate that GTCW achieves an average AUROC of 73.61% while maintaining a Pass@1 of 59.18%. These findings indicate significant improvements over existing baselines with negligible degradation in generation quality, effectively reconciling robustness with code usability.
📝 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 .
Problem

Research questions and friction points this paper is trying to address.

code watermarking
large language models
generation quality
grammar constraint
Innovation

Methods, ideas, or system contributions that make the work stand out.

Grammar-Guided Watermarking
Green Temperature
Code Generation
Large Language Models
Syntax-Aware Decoding
🔎 Similar Papers