arXiv:2601.02602cs.CRcs.LG2026-01

用强化学习给代码模型加防伪水印,又稳又难删。

SWaRL: Safeguard Code Watermarking via Reinforcement Learning

  • 用强化学习+编译器反馈,自动优化水印嵌入。
  • 水印检测准确率高,代码功能零破坏。
  • 抗重构和攻击能力强,适合工业级保护。

我们提出SWaRL,一种鲁棒且保持功能完整性的代码生成模型知识产权保护框架,通过在生成代码中嵌入唯一可验证的签名来实现。现有方法或依赖手工代码变换,或在推理时调整词元生成概率,易受移除攻击或破坏代码正确性。SWaRL采用基于强化学习的联合训练框架,利用编译器反馈确保功能正确性,并以联合训练的保密验证器作为奖励信号,维持水印可检测性。此外,微调阶段使用低秩适应(LoRA),实现水印行为的高效集成与跨模型更新的可迁移性。大量实验表明,相比先前方法,SWaRL在保持水印代码功能完全正确的同时,具备更强的水印检测准确性;同时对重构和对抗性变换攻击表现出强韧性,保障可靠溯源且计算开销极小。

原文摘要 · Abstract (English)

We present SWaRL, a robust and fidelity-preserving watermarking framework designed to protect the intellectual property of code LLMs by embedding unique and verifiable signatures in the generated program. Existing watermarking approaches either rely on handcrafted code transformations or manipulate token generation probabilities at inference time, making them vulnerable to removal attacks or prone to breaking functional correctness. To address these challenges, SWaRL employs a reinforcement learning-based co-training framework that uses compiler feedback for functional correctness and a jointly trained confidential verifier as a reward signal to maintain watermark detectability. Furthermore, SWaRL employs low-rank adaptation (LoRA) during fine-tuning, enabling efficient integration of watermarking behavior and transferability across model updates. Extensive experiments show that SWaRL achieves strong watermark detection accuracy compared to prior methods while fully maintaining watermarked code functionality. Moreover, SWaRL exhibits strong resilience against refactoring and adversarial transformation attacks, which maintains reliable attribution without substantial computational overhead.

代码生成水印技术强化学习

Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。