Marking Code Without Breaking It: Code Watermarking for Detecting LLM-Generated Code
Abstract
Identifying LLM-generated code through watermarking poses a challenge in preserving functional correctness.Previous methods rely on the assumption that watermarking highentropy 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.
Fields of Study & Subjects
Advanced Steganography and Watermarking Techniques
Advanced Malware Detection Techniques
Internet Traffic Analysis and Secure E-voting
Publication details
- Journal / source
- Findings of the Association for Computational Linguistics: EACL 2026
- Publisher
- Association for Computational Linguistics
- Pages
- 3990–4002
- Publication date
- 1 January 2026