Efficient and Universal Watermarking for LLM-Generated Code Detection
About
Large language models (LLMs) have significantly enhanced the usability of AI-generated code, providing effective assistance to programmers. This advancement also raises ethical and legal concerns, such as academic dishonesty and the generation of malicious code. For accountability, it is imperative to detect whether a piece of code is AI-generated. Watermarking is broadly considered a promising solution and has been successfully applied to identify LLM-generated text. However, existing efforts on code are far from ideal, suffering from limited universality and excessive time and memory consumption. In this work, we propose a plug-and-play watermarking approach for AI-generated code detection, named ACW (AI Code Watermarking). ACW is training-free and works by selectively applying a set of carefully-designed, semantic-preserving and idempotent code transformations to LLM code outputs. The presence or absence of the transformations serves as implicit watermarks, enabling the detection of AI-generated code. Our experimental results show that ACW effectively and efficiently detects AI-generated code, preserves code utility, and is resilient against potential code disruptions. Especially, ACW is universal across different LLMs, addressing the limitations of existing approaches.
Related benchmarks
| Task | Dataset | Result | Rank | |
|---|---|---|---|---|
| Code Generation | HumanEval | Pass@130.82 | 1048 | |
| Code Generation | HumanEval+ | Pass@127.24 | 393 | |
| Code Generation | MBPP+ | Pass@131.93 | 238 | |
| Source Code Watermark Extraction Robustness | CodeNet D32 (evaluation) | Accuracy100 | 36 | |
| Source Code Watermark Extraction Robustness | CodeNet D40 (evaluation) | Accuracy100 | 36 | |
| Source Code Watermark Extraction Robustness | CodeNet D56 (evaluation) | Accuracy100 | 36 | |
| Source Code Watermark Extraction Robustness | CodeNet D88 (evaluation) | Accuracy100 | 36 | |
| Source Code Watermark Extraction Robustness | CodeNet D152 (evaluation) | Accuracy98.4 | 36 | |
| Watermark Detection | MBPP | -- | 14 | |
| Watermark Detection | HumanEval | -- | 9 |