Manuscript Offprint
arXiv:2610.32017SynMark: Semantic-Coordinate Multi-Bit Watermarking during LLM Code Generation
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.
Index Terms— code generation, multi-bit watermarking, semantic synchronization, syntax-aware embedding
1. INTRODUCTION
Large language models increasingly generate code that is reused across downstream projects, where identifier renaming, reformatting, and structural refactoring are common [1]. However, external records such as generation logs and platform metadata do not travel with reused code, making provenance difficult to maintain after such edits. Generative watermarking addresses this problem by embedding provenance information directly into token selection, allowing the signal to remain with the generated code when external records are unavailable [2, 3].
However, existing generative watermarking methods struggle to trace code fragments after semantics-preserving transformations. They commonly derive keyed message routes and candidate sets directly from surface-token prefixes [4, 5, 6]. Transformations can then impair recovery at

Fig. 1. Token-based and semantic-coordinate routing under identifier renaming. Binary strings are two-bit message symbols; token-based routing uses nearby tokens, while SynMark routes from a semantic coordinate of the full prefix.
two coupled levels: (i) modified prefixes may cause the detector to reconstruct routes or candidate sets different from those used during generation, as illustrated in Fig. 1; and (ii) even under a correct route, renamed, inserted, or rewritten tokens may produce unreliable recovery signals. The former changes message-block assignment, while the latter degrades token-level recovery after routing. Increasing the watermark bias cannot correct either failure and may alter syntax-sensitive token choices, reducing functional correctness. Robust recovery therefore requires both stable semantic routing references and calibration of the residual transformation-induced variation in token-level recovery signals.
We propose SynMark, a generative multi-bit watermarking framework that embeds watermark messages during LLM code generation. Unlike existing methods that directly couple keyed routing to surface-token prefixes, Scope first maps each prefix to a discrete semantic coordinate learned from aligned, functionally equivalent code variants and performs keyed block assignment on this intermediate reference. During generation, Scope also applies a syntax-aware adaptive bias to limit watermark-induced changes at syntax-sensitive positions. Since semantic routing reduces but does not eliminate transformation-induced variation, Traced recomputes semantic routes during extraction and calibrates the remaining token-level recovery signals through candidate-score correction and reliability-weighted aggregation.
We evaluate SynMark on HumanEval with OpenCoder, CodeLlama, and DeepSeek-Coder against MPAC, CredID, XMark, and CodeIP. SynMark improves 8-bit message re-covery across all three generators, retains higher Pass@1 than competing watermarked methods, and achieves stronger recovery under identifier renaming and random code transformations.
Our main contributions are summarized as follows:
• Semantic-coordinate routing. We introduce a causal routing mechanism that learns discrete semantic coordinates from aligned prefixes of functionally equivalent code, reducing dependence on surface-token references during both embedding and extraction.
• Syntax-aware watermark embedding. We develop an adaptive logit bias that limits watermark-induced changes at syntax-sensitive positions while retaining the default embedding strength elsewhere.
• Reliability-weighted extraction. We design Traced to compensate for residual transformation-induced drift in token-level recovery signals through candidate-score correction and reliability-weighted aggregation.
Multi-bit watermarking links generation positions to message symbols through keyed vocabulary partitions. MPAC routes symbols from preceding tokens [4], CredID combines prefix cues with model logits [5], and XMark uses keyed vocabulary permutations for reliable message recovery [6]. For code generation, prior work studies watermark-aware token constraints [3], grammar-guided multi-bit encoding [9], syntax-critical decisions [10], and user-level tracing [11]. These methods improve detection and tracing, yet token-level routing, grammar constraints, and fixed candidate construction remain sensitive to renaming, reformatting, and structural rewrites. SynMark uses semantic-coordinate routing and reliability-weighted extraction to improve recovery after semantics-preserving transformations.
3. PROPOSED METHOD
3.1. Problem Formulation and Threat Model
Given a prompt , an -bit watermark message , and a secret key , SynMark generates and recovers after edits . For code expected to carry a watermark, the detector outputs , and we evaluate bit-level recovery. For an even payload length , we split into two-bit blocks, where
Semantic-Coordinate Watermark Embedding

Reliability-Weighted Watermark Extraction
Fig. 2. Overview of SynMark. Scope embeds during generation; Traced recomputes routes for reliability-weighted extraction from transformed code.
and with . The mapper uses states, and the keyed bijection assigns states to message blocks. Figure 2 summarizes Scope embedding and Traced extraction; Traced reuses the tokenizer, frozen embeddings, and trained mapper for correction and reliability weighting.
Threat model. We consider post-generation attacks where an adversary edits watermarked code y to weaken the watermark while preserving functionality, without access to the secret key or detector feedback. These edits include identifier renaming, semantics-preserving structural refactoring, and comment/dead-code insertion. The detector recovers the watermark message from . Full re-synthesis, code regeneration, functionality-changing edits, and key compromise are out of scope.
3.2. Semantic-Coordinate Watermark Embedding
Scope trains a causal mapper to assign aligned prefixes of functionality-preserving variants to shared discrete coordinates. For each snippet , we construct . During transformation, we retain correspondences between preserved AST nodes and map their end offsets to BPE boundaries using tokenizer offsets, yielding ; inserted or deleted nodes without counterparts are omitted. Mini-batch Sinkhorn converts clean-prefix logits into balanced soft assignments , shared as stop-gradient targets with aligned transformed prefixes. Let if , and otherwise. The mapper uses frozen generator embeddings, normalization/projection layers, a GRU prefix encoder, and an S-way classifier. Its pair-weighted loss is:
(1)
The Scope objective is . Here, aligns paired representations, and balance state usage globally and within sequences, and and regularize representation geometry and prediction confidence. AST alignment is used only during training.
Let be the non-special-token vocabulary. At position , and . For , defines ; the same parameterizes . SynMark sets and . Complementary coding yields multi-hot candidate indicators: a token supports only outside the -th shard in both partitions [6]. Detection recomputes coordinates and candidate sets from transformed-code prefixes, so block assignment does not use absolute token positions. This anchors block assignment to learned coordinates rather than surface tokens, reducing its direct dependence on token identity. Traced then handles the remaining variation in token-level recovery signals.
Let be the frozen LLM pre-watermark logit, the syntax-sensitive tokens (keywords, operators, whitespace/formatting), and the original top-1 token. Define the target margin as
Let denote the default bias and margin floor. At position , is the dtype-dependent numerical slack; the adaptive bias is:
For active gates, the clipped bias prevents any boosted target token from overtaking the original top-1 token. When , the strongest target token is already close to the original top-1, so the default bias is retained to preserve watermark strength.
3.3. Reliability-Weighted Watermark Extraction
At detection, Traced recomputes from using and , rebuilds , and forms . It runs only during extraction and does not affect generation. We define
For transformed-code length , concatenates learned embeddings of the token hash, sanitized token, lexical type, and route with and . Sanitization maps identifiers and literals to shared categories. Surface and position features contextualize only Traced; determines block assignment. A BiGRU produces , and a shared network outputs a scalar correction for each
Table 1. Comparison of watermark recovery and functional correctness on HumanEval across three code LMs, reported as BitAcc/Pass@1 (%).
| Method | OpenCoder | CodeLlama | DeepSeek |
|---|---|---|---|
| Unwatermarked | -/40.24 | -/21.95 | -/34.76 |
| CredID [5] | 68.60/26.83 | 81.86/7.32 | 81.10/16.46 |
| XMark [6] | 75.00/25.61 | 83.99/8.54 | 79.19/6.71 |
| MPAC [4] | 77.74/23.78 | 77.29/2.44 | 82.93/12.20 |
| CodeIP [9] | 77.31/26.83 | 69.33/6.10 | 69.56/2.44 |
| SynMark (Ours) | 80.26/36.99 | 88.52/19.72 | 86.99/27.03 |
candidate :
Here is the learned embedding of candidate symbol ; combines context, raw membership, and centered membership to adjust candidate-relative scores.
The reliability branch sets , with matching and scalar ; initialization , gives before reliability training. For block , Traced computes
The denominator normalizes reliability weights with a unit lower bound on their squared sum; empty blocks use zero scores. We then compute and .
During Traced training, the fixed Scope module embeds sampled messages, and clean/transformed inputs share labels. With , the correction stage trains the feature and candidate embeddings, BiGRU, and using . The reliability stage freezes these modules and trains only the reliability branch initialized at using . For , define and . We use , , and . The residual penalty prevents corrections from dominating raw membership signals. Inference converts each selected symbol into two bits.
4. EXPERIMENTS
4.1. Experimental Setup
We train generator-specific Scope and Traced modules on MBPP (320/80 train/validation) [12] and evaluate on HumanEval [13] with OpenCoder-1.5B [14], CodeLlama-7B [15], and DeepSeek-Coder-6.7B [16]. We compare with CredID [5], XMark [6], MPAC [4], and CodeIP [9] under the
(a) CodeLlama-7B
(b) DeepSeek-Coder-6.7B

- CredID - XMark ...MPAC - CodeIP - SynMark
Fig. 3. BitAcc under identifier renaming on two code LMs. same 8-bit payload and generation configuration, using their recommended watermark strengths. Results are averaged over three seeds. Robustness is evaluated on successfully transformed, functionality-preserving HumanEval outputs using the same transformation families as those used in Scope training: identifier renaming and 1–3 sequential rewrites of conditionals, loops, updates, and declarations/initialization, together with dead-code and comment insertion. We set and .
4.2. Watermark Accuracy and Fidelity
Table 1 compares clean watermark recovery and code fidelity. SynMark achieves the highest BitAcc and Pass@1 among the evaluated watermarked methods across all three generators. The largest gains occur on CodeLlama, where SynMark improves BitAcc and Pass@1 by 4.53 and 11.18 percentage points, respectively, over XMark, the strongest watermarked baseline in both metrics. SynMark also narrows the fidelity gap to unwatermarked generation, reaching Pass@1 compared with on CodeLlama. These results show that improved bit recovery need not come at a greater cost to functional correctness. This is consistent with SynMark's adaptive embedding design, which limits watermark intervention at gated syntax-sensitive positions by preserving the original top-1 token ranking.
4.3. Robustness under Code Transformations
Figure 3 compares BitAcc under identifier renaming on CodeLlama and DeepSeek-Coder. SynMark consistently outperforms all baselines across renaming ratios, retaining and BitAcc under renaming. These results show that SynMark is less sensitive to identifier changes. Semantic-coordinate routing reduces dependence on token identities, while Traced calibrates the remaining token-level recovery signals.
Table 2 evaluates broader semantics-preserving edits on OpenCoder. SynMark achieves the highest BitAcc in every attack group, improving the averages under identifier renaming and code transformation attacks by and over the strongest corresponding baselines. It also performs best under dead-code and comment insertion. These gains reflect the complementary roles of Scope and Traced: Scope reduces routing dependence on surface-token identities, while Traced corrects and downweights unreliable recovery signals introduced by structural rewrites and token insertions.
Table 2. Robustness comparison on OpenCoder under identifier renaming, random code transformations, dead-code insertion, and comment insertion, reported as BitAcc (%).
| Method | Var. | Trans. | Dead | Comment |
|---|---|---|---|---|
| CredID [5] | 58.35 | 51.65 | 68.14 | 69.02 |
| XMark [6] | 67.51 | 55.09 | 72.16 | 74.92 |
| MPAC [4] | 71.45 | 60.66 | 76.98 | 76.37 |
| CodeIP [9] | 61.22 | 52.34 | 65.03 | 64.13 |
| SynMark (Ours) | 77.61 | 64.21 | 79.71 | 79.62 |
4.4. Ablation Study
For the ablation, removing Scope reverts to XMark's surface-token routing with a fixed watermark bias, while removing Traced uses standard block voting [6]. Table 3 shows that adding Scope improves Pass@1 by 11.38 percentage points and Trans. Avg. BitAcc by 5.16 points, while Clean and Var. Avg. remain comparable. These results are consistent with Scope's two generation-side mechanisms: semantic-coordinate routing reduces dependence on surface-token references, while the syntax-aware bias limits watermark interference with code generation. With Scope fixed, Traced further improves Clean, Var., and Trans. Avg. BitAcc by 5.87, 10.10, and 3.96 points, respectively, without affecting Pass@1, indicating that extraction-side calibration remains useful for residual recovery errors. We omit the configuration without Scope but with Traced because Traced relies on Scope-derived routes. Overall, the ablation supports the complementary roles of Scope embedding and Traced extraction in improving fidelity and recovery under transformations.
Table 3. Ablation results on OpenCoder (%). “w/” and “w/o” denote with and without each module, respectively.
| Scope | Traced | Clean | Var Avg. | Trans. Avg. | Pass@1 |
|---|---|---|---|---|---|
| w/ | w/ | 80.26 | 77.61 | 64.21 | 36.99 |
| w/ | w/o | 74.39 | 67.51 | 60.25 | 36.99 |
| w/o | w/o | 75.00 | 67.51 | 55.09 | 25.61 |
5. CONCLUSION
SynMark embeds multi-bit watermark messages during LLM code generation with semantic-coordinate routing, syntax-aware adaptive bias, and reliability-weighted extraction. On HumanEval, SynMark improves bit recovery, functional correctness, and robustness over evaluated watermarked baselines across three code LMs.
6. ACKNOWLEDGMENT
This work was supported by the National Natural Science Foundation of China (Grant No. 62472177). The authors declare no conflicts of interest.
7. COMPLIANCE WITH ETHICAL STANDARDS
This study involved no human participants or animals and required no ethical approval.
8. REFERENCES
[1] Tarun Suresh, Shubham Ugare, Gagandeep Singh, and Sasa Misailovic, “Is watermarking LLM-generated code robust?,” in Tiny Papers at ICLR 2024, 2024.
[2] John Kirchenbauer, Jonas Geiping, Yuxin Wen, Jonathan Katz, Ian Miers, and Tom Goldstein, “A watermark for large language models,” in Proceedings of the 40th International Conference on Machine Learning, Andreas Krause, Emma Brunskill, Kyunghyun Cho, Barbara Engelhardt, Sivan Sabato, and Jonathan Scarlett, Eds. 2023, vol. 202 of Proceedings of Machine Learning Research, pp. 17061–17084, PMLR.
[3] Taehyun Lee, Seokhee Hong, Jaewoo Ahn, Ilgee Hong, Hwaran Lee, Sangdoo Yun, Jamin Shin, and Gunhee Kim, "Who wrote this code? watermarking for code generation," in Proceedings of the 62nd Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers), Lun-Wei Ku, Andre Martins, and Vivek Srikumar, Eds., Bangkok, Thailand, August 2024, pp. 4890–4911, Association for Computational Linguistics.
[4] KiYoon Yoo, Wonhyuk Ahn, and Nojun Kwak, “Advancing beyond identification: Multi-bit watermark for large language models,” in Proceedings of the 2024 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies (Volume 1: Long Papers), Kevin Duh, Helena Gomez, and Steven Bethard, Eds., Mexico City, Mexico, June 2024, pp. 4031–4055, Association for Computational Linguistics.
[5] Haoyu Jiang, Shanzhe Lei, Yingchun Wang, Xuhong Wang, and Ping Yi, “CredID: Credible multi-bit watermark for large language models identification,” in 2026 IEEE International Conference on Acoustics, Speech and Signal Processing (ICASSP). 2026, pp. 13962–13966, IEEE.
[6] Jiahao Xu, Rui Hu, Olivera Kotevska, and Zikai Zhang, "XMark: Reliable multi-bit watermarking for LLM-generated texts," in Proceedings of the 64th Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers), Maria Liakata, Viviane P. Moreira, Jiajun Zhang, and David Jurgens, Eds., San Diego, California, United States, July 2026, pp. 14747–14763, Association for Computational Linguistics.
[7] Jie Ren, Han Xu, Yiding Liu, Yingqian Cui, Shuaiqiang Wang, Dawei Yin, and Jiliang Tang, “A robust semantics-based watermark for large language model against paraphrasing,” in Findings of the Association for Computational Linguistics: NAACL 2024, Mexico City, Mexico, June 2024, pp. 613–625, Association for Computational Linguistics.
[8] Yepeng Liu and Yuheng Bu, “Adaptive text watermark for large language models,” in Proceedings of the 41st International Conference on Machine Learning. 2024, vol. 235 of Proceedings of Machine Learning Research, pp. 30718–30737, PMLR.
[9] Batu Guan, Yao Wan, Zhangqian Bi, Zheng Wang, Hongyu Zhang, Pan Zhou, and Lichao Sun, “CodeIP: A grammar-guided multi-bit watermark for large language models of code,” in Findings of the Association for Computational Linguistics: EMNLP 2024, Yaser Al-Onaizan, Mohit Bansal, and Yun-Nung Chen, Eds., Miami, Florida, USA, November 2024, pp. 9243–9258, Association for Computational Linguistics.
[10] Jungin Kim, Shinwoo Park, and Yo-Sub Han, “Marking code without breaking it: Code watermarking for detecting LLM-generated code,” in Findings of the Association for Computational Linguistics: EACL 2026, Rabat, Morocco, March 2026, pp. 3990–4002, Association for Computational Linguistics.
[11] Boyu Zhang, Ping He, Tianyu Du, Xuhong Zhang, Lei Yun, Kingsum Chow, and Jianwei Yin, “CLMTracing: Black-box user-level watermarking for code language model tracing,” in Proceedings of the 2025 Conference on Empirical Methods in Natural Language Processing, Suzhou, China, November 2025, pp. 28974–28990, Association for Computational Linguistics.
[12] Jacob Austin, Augustus Odena, Maxwell Nye, Maarten Bosma, Henryk Michalewski, David Dohan, Ellen Jiang, Carrie Cai, Michael Terry, Quoc Le, and Charles Sutton, “Program synthesis with large language models,” 2021, arXiv:2108.07732.
[13] Mark Chen et al., “Evaluating large language models trained on code,” 2021, arXiv:2107.03374.
[14] Siming Huang, Tianhao Cheng, Jason Klein Liu, Weidi Xu, Jiaran Hao, Liuyihan Song, Yang Xu, Jian Yang, Jiaheng Liu, Chenchen Zhang, Linzheng Chai, Ruifeng Yuan, Xianzhen Luo, Qiufeng Wang, Yuantao Fan, Qingfu Zhu, Zhaoxiang Zhang, Yang Gao, Jie Fu, Qian Liu, Houyi Li, Ge Zhang, Yuan Qi, Yinghui Xu, Wei Chu, and Zili Wang, “OpenCoder: The open cookbook for top-tier code large language models,” in Proceedings of the 63rd Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers), Vienna, Austria, July 2025, pp. 33167–33193, Association for Computational Linguistics.
[15] Baptiste Roziere, Jonas Gehring, Fabian Gloeckle, Sten Sootla, Itai Gat, Xiaoqing Ellen Tan, Yossi Adi, Jingyu Liu, Romain Sauvestre, Tal Remez, Jeremy Rapin, Artyom Kozhevnikov, Ivan Evtimov, Joanna Bitton, Manish Bhatt, Cristian Canton Ferrer, Aaron Grattafiori, Wenhan Xiong, Alexandre Defossez, Jade Copet, Faisal Azhar, Hugo Touvron, Louis Martin, Nicolas Usunier, Thomas Scialom, and Gabriel Synnaeve, "Code Llama: Open foundation models for code," 2023, arXiv:2308.12950.
[16] Daya Guo, Qihao Zhu, Dejian Yang, Zhenda Xie, Kai Dong, Wentao Zhang, Guanting Chen, Xiao Bi, Y. Wu, Y. K. Li, Fuli Luo, Yingfei Xiong, and Wenfeng Liang, “DeepSeek-Coder: When the large language model meets programming—the rise of code intelligence,” 2024, arXiv:2401.14196.