Disappearing Ink: Obfuscation Breaks N-gram Code Watermarks in Theory and Practice

Gehao Zhang, Mingzhe Li, Eugene Bagdasarian, Shiqing Ma, Juan Zhai


Abstract
Large language models (LLMs) are increasingly used for code generation, making reliable identification of machine-generated code important for attribution, tracking, and misuse detection. Existing code watermarking methods are dominated by N-gram-based schemes, yet their robustness has mostly been evaluated only against simple edits or optimizations. We argue that this significantly overstates security, because software engineering already provides stronger semantics-preserving transformations in the form of code obfuscation.

We study N-gram-based code watermarking under obfuscation. We formally model semantics-preserving transformations as a Markov random walk and prove that, under an intuitive and experimentally supported assumption called distribution consistency, obfuscation can nullify the robustness of N-gram-based watermarks. If the original detector has a false positive rate 𝜖pos, then after obfuscation, its failure rate on watermarked code approaches 1 - 𝜖pos.

We validate this theory on three state-of-the-art watermarking schemes, two LLMs, two programming languages, four benchmarks, and four obfuscators. Across all settings, detectors collapse to near-random performance on obfuscated code (AUROC tightly around 0.5), and for each language, at least one attack leaves all post-obfuscation AUROC scores below 0.6. These results jointly show that current N-gram-based code watermarks are not robust to realistic obfuscation attacks and motivate more semantics-aware alternatives.
Anthology ID:
2026.findings-emnlp.1372
Volume:
Findings of the Association for Computational Linguistics: EMNLP 2026
Month:
October
Year:
2026
Address:
Budapest, Hungary
Editors:
Hung-Yi Lee, Sunipa Dev, Jessy Li, Desmond Elliott
Venue:
Findings
SIG:
SIGDAT
Publisher:
Association for Computational Linguistics
Note:
Pages:
29188–29219
Language:
URL:
https://aclanthology.org/2026.findings-emnlp.1372/
DOI:
Bibkey:
Cite (ACL):
Gehao Zhang, Mingzhe Li, Eugene Bagdasarian, Shiqing Ma, and Juan Zhai. 2026. Disappearing Ink: Obfuscation Breaks N-gram Code Watermarks in Theory and Practice. In Findings of the Association for Computational Linguistics: EMNLP 2026, pages 29188–29219, Budapest, Hungary. Association for Computational Linguistics.
Cite (Informal):
Disappearing Ink: Obfuscation Breaks N-gram Code Watermarks in Theory and Practice (Zhang et al., Findings 2026)
Copy Citation:
PDF:
https://aclanthology.org/2026.findings-emnlp.1372.pdf