SynMark improves watermarking of AI-written code against edits
SynMark: Semantic-Coordinate Multi-Bit Watermarking during LLM Code Generation
Cryptography and Security
Summary
Code generated by AI models can be changed by renaming variables or restructuring without altering what it does, which makes embedding hidden watermarks in the code hard. The authors designed SynMark, a new way to hide and detect multi-bit watermarks by focusing on the code’s meaning instead of just its exact words. This method stays reliable even when the code is edited, keeping over 82% watermark accuracy despite all variable names changing. SynMark also boosts the quality of watermarked AI-generated code overall compared to previous techniques.
What this means in practice
- •For software development teams: Embed robust multi-bit watermarks in AI-generated source code to prove ownership even after renaming and restructuring edits.
- •For cybersecurity engineers: Detect unauthorized reuse or modification of AI-written code by recovering embedded watermarks resilient to common code transformations.
Authors
Rui Xu, Weizhi Liu, Zhaoxia Yin
Abstract
LLM-generated code is increasingly reused across downstream applications and often undergoes identifier renaming or structural refactoring, making robustness to functionality-preserving edits essential for generative multi-bit code watermarking. Existing methods commonly derive message routes from surface-token prefixes, so such edits can desynchronize routing and degrade watermark recovery. We propose SynMark, which replaces surface-dependent routing with learned semantic coordinates and further calibrates residual recovery errors after transformation. For watermark embedding, Scope learns semantic coordinates from aligned prefixes of functionally equivalent variants for keyed routing and applies a syntax-aware adaptive bias during generation. For watermark extraction, Traced recomputes semantic routes from transformed code and uses reliability-weighted aggregation to suppress unreliable token contributions. Under 100% identifier renaming, SynMark retains 82.27% and 83.77% BitAcc on CodeLlama and DeepSeek-Coder, respectively. Across three code LMs, it also improves clean BitAcc and Pass@1 by up to 4.53 and 11.18 percentage points over the strongest watermarked baselines.