Identifying LLM-generated code through watermarking poses a challenge in preserving functional correctness. Previous methods rely on the assumption that watermarking high-entropy tokens effectively maintains output quality. Our analysis reveals a fundamental limitation of this assumption: syntax-critical tokens such as keywords often exhibit the highest entropy, making existing approaches vulnerable to logic corruption. We present STONE, a syntax-aware watermarking method that embeds watermarks only in non-syntactic tokens and preserves code integrity. For its rigorous assessment, we also introduce STEM, a comprehensive framework that balances three critical dimensions: correctness, detectability, and imperceptibility. Across Python, C++, and Java, STONE preserves correctness, sustains strong detectability, and achieves balanced performance with minimal overhead. Our implementation is available at https://anonymous.4open.science/r/STONE-watermarking-AB4B/.
翻译:通过水印技术识别LLM生成的代码在保持功能正确性方面面临挑战。现有方法基于"高熵标记水印能有效维持输出质量"的假设,但我们的分析揭示了该假设的根本局限:语法关键标记(如关键词)通常具有最高熵值,导致现有方法易受逻辑破坏。我们提出STONE——一种语法感知水印方法,仅将水印嵌入非语法标记以保持代码完整性。为进行严谨评估,我们同时提出STEM综合评估框架,该框架平衡三个关键维度:正确性、可检测性与隐蔽性。在Python、C++和Java的测试中,STONE在保持正确性的同时维持了强可检测性,并以最小开销实现了均衡性能。我们的实现发布于https://anonymous.4open.science/r/STONE-watermarking-AB4B/。