ACW: Enhancing Traceability of AI-Generated Codes Based on Watermarking
Existing code watermarking methods for detecting large language model (LLM)-generated code suffer from poor generalizability, high computational overhead, and reliance on white-box access. To address these limitations, we propose ACW—a training-free, black-box, lightweight code watermarking framework. ACW embeds detectable watermarks implicitly during code generation via semantic-preserving and idempotent structured code transformations. It employs a statistically significant detection mechanism to robustly extract watermarks without requiring model internals or retraining. Evaluated across diverse LLMs—including ChatGPT and StarCoder—ACW achieves >98% detection accuracy on generated code and demonstrates strong resilience against common adversarial attacks such as code deletion, modification, and obfuscation. Notably, ACW is the first method to overcome the transferability bottleneck of text-based watermarks in the code domain. It simultaneously delivers zero training cost, broad model agnosticism, and high detection reliability.