MCGMark: An Encodable and Robust Online Watermark for Tracing LLM-Generated Malicious Code
Kaiwen Ning, Jiachi Chen, Qingyuan Zhong, Tao Zhang, Yanlin Wang, Wei Li, Yu Zhang, Jianxing Yu,
Sun Yat-sen University · Macau University of Science and Technology
Key points
From the paper's conclusion- This approach offers a practical solution for tracing malicious code and mitigating the misuse of LLMs.
Abstract
With the advent of large language models (LLMs), numerous software service providers are developing LLMs tailored for code generation, such as CodeLlama. However, these models can be exploited by malicious developers to generate malicious code, posing severe threats to the software ecosystem. To address this issue, we first conducted an empirical study and built MCGTest , a dataset of \(406\) prompts designed to elicit malicious code from LLMs. Leveraging this dataset, we propose MCGMark , a watermarking method to trace and attribute LLM-generated malicious code. MCGMark subtly embeds user-specific information into generated code by controlling the token selection process, ensuring the watermark is imperceptible. Additionally, MCGMark dynamically adjusts the token selection range to induce the LLM to favor high-probability tokens, thus ensuring code quality. Furthermore, by leveraging code structure, MCGMark avoids embedding watermarks into regions easily modified by attackers, such as comments and variable names, enhancing robustness against tampering. Experiments on several advanced LLMs show that MCGMark successfully embeds watermarks in approximately \(85\%\) of cases, under the constraint of a \(400\) -token limit. Moreover, it maintains code quality and demonstrates strong resilience against common code modification. This approach offers a practical solution for tracing malicious code and mitigating the misuse of LLMs.
Read the paper
Discussion
Science Skim's AI key points, plus readers' public thoughts
Readers' thoughts
No reader thoughts yet.
Related papers
- RoCoMark: Robust Code Watermarking Against LLM-Based Functionality-Preserving Rewriting AttacksarXiv · 2026
- Adaptive Robust Watermarking for Large Language Models via Dynamic Token Embedding PerturbationIEEE Access · 2026
- SynMark: Semantic-Coordinate Multi-Bit Watermarking during LLM Code GenerationarXiv · 2026
- Look It Up: Multi-bit LLM Watermarking via Codebook SearcharXiv · 2026
- A Unified Attack Framework against Statistical Generative Watermarks for Large Language ModelsarXiv · 2026
- Know the Design, Pick the Attack: Sentence-Keyed Watermarks for LLMsarXiv · 2026