arXiv:2502.18851cs.CRcs.AI2025-02Conference of the …被引 12

用语法无关词嵌入水印,既保代码正确又可检测大模型生成

Marking Code Without Breaking It: Code Watermarking for Detecting LLM-Generated Code

  • 只在非语法关键词中嵌入水印,避免破坏代码结构
  • 跨三语言测试中保持100%正确率,水印可检性强
  • 适合需要验证代码来源的开发者和开源项目

通过水印识别大模型生成代码面临保持功能正确性的挑战。现有方法假设高熵词可安全水印,但我们的分析发现:语法关键词(如关键字)通常熵值最高,导致此类方法易引发逻辑错误。为此,我们提出STONE——一种语法感知的水印方法,仅在非语法词中嵌入水印,确保代码完整性。为全面评估,我们还引入STEM指标,综合平衡正确性、可检测性和不可察觉性。在Python、C++和Java上的实验表明,STONE在保持100%正确率的同时,仍具备强可检测性,且计算开销极低。代码已开源:https://github.com/inistory/STONE-watermarking。

原文摘要 · Abstract (English)

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生成语法感知可检测性

Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。