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 rigorous evaluation, we also introduce STEM, a comprehensive metric 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 computational overhead. Our implementation is available at https://github.com/inistory/STONE-watermarking.
翻译:通过水印技术识别LLM生成的代码,在保持功能正确性方面面临挑战。现有方法基于"对高熵词元进行水印处理能有效保持输出质量"的假设。我们的分析揭示了该假设的根本局限:语法关键词元(如关键字)往往具有最高熵值,导致现有方法易受逻辑破坏。本文提出STONE——一种语法感知的水印方法,仅将水印嵌入非语法词元以保持代码完整性。为进行严谨评估,我们同时提出STEM综合评估指标,该指标平衡了三个关键维度:正确性、可检测性与不可感知性。在Python、C++和Java的测试中,STONE在保持正确性的同时维持了强可检测性,并以最小计算开销实现了均衡的性能表现。项目实现已发布于https://github.com/inistory/STONE-watermarking。