TL;DR
PuzzleMark is a novel, highly robust dataset watermarking technique designed to protect the intellectual property of code datasets against unauthorized training of Neural Code Completion Models (NCCMs). By filtering out inherently suspicious code snippets and replacing fragile, fixed trigger-target pairs with an adaptive variable concatenation strategy, PuzzleMark achieves a 100% verification success rate while remaining virtually invisible to state-of-the-art watermark detectors.
What Problem Does This Paper Address?
Curating high-quality datasets for training code models requires massive time and financial investment, making these datasets valuable intellectual property. However, dataset owners face a constant risk of unauthorized use by third parties who "steal" the data to train commercial code assistants.
While digital watermarking offers a way to verify ownership after an infringement occurs (by injecting specific "trigger" patterns that the trained model will uniquely reproduce), existing methods have a glaring weakness: they rely on rigid co-occurrence patterns (injecting identical trigger-target pairs across samples). Modern watermark detectors can easily spot these high-frequency statistical anomalies. Furthermore, previous methods ignored the suitability of the "carrier" code snippets themselves, often embedding watermarks into overly complex code that automated security tools would naturally flag and remove anyway.
Methods
PuzzleMark introduces a two-pronged approach to solve these vulnerabilities:
- Watermark Carrier Selection: Instead of randomly picking code snippets to hold the watermark, PuzzleMark evaluates code complexity to avoid exposure. It extracts 10 structural and semantic features (such as cyclomatic complexity and number of expressions) and uses a principal component analysis (PCA)-based projection mechanism to calculate a "suitability score." Code snippets that are naturally convoluted or anomalous are filtered out, ensuring watermarks are only placed in clean, ordinary code.
- Adaptive Concatenation Pattern: To replace easily detectable fixed triggers, PuzzleMark uses a jigsaw-like concatenation pattern. It adaptively selects two variable names already present in the snippet—a prefix and a suffix—and renames a low-frequency target variable to be the concatenation of the two (e.g., merging
keyanditeratorintokey_iterator).
The authors propose two strategies:
- Fixed-Trigger: Uses a predefined variable name (like
keyorvalue) as the prefix. - Universal Watermark: Both the prefix and suffix are dynamically selected based on their position in the code, making every token a potential trigger and eliminating any fixed signatures.
For ownership verification, PuzzleMark queries the suspicious model in a black-box setting and applies Fisher’s exact test to compute an exact p-value, ensuring precise validation without relying on large-sample approximations.
Datasets
The method was evaluated using the Python and Java subsets of the widely recognized CodeSearchNet (CSN) dataset:
- CSN-Python: 412,178 training code snippets.
- CSN-Java: 454,451 training code snippets.
The watermarked datasets were used to fine-tune three state-of-the-art models: Qwen2.5-3B, StarCoderBase-1B, and DeepSeek-Coder-1.3B.
Key Insights and Ideas
- The Carrier Matters Just as Much as the Pattern: A key "aha moment" in the paper is that previous watermarking frameworks failed not because their watermark patterns were bad, but because they chose bad carriers. As shown in the paper's analysis, over 60% of carriers chosen by baseline methods were flagged by detectors before any watermark was even added, simply because they were structural outliers.
- Breaking the Statistical Signature: By ensuring that the trigger suffix and the target variable change adaptively for every single code sample, PuzzleMark prevents the creation of high-frequency outlier patterns that automated tools look for.
Key Results
- Effectiveness & Harmlessness: PuzzleMark achieved a 100% verification success rate and a 0% false positive rate across all tested models and languages, with negligible impact on downstream model performance (BLEU scores remained statistically unchanged).
- Machine Imperceptibility: Against state-of-the-art detectors like DeCoMa and KillBadCode—which easily achieve near 100% recall against older watermarking methods—PuzzleMark successfully evaded detection, dropping the average detector recall to just 29.59% for Python and 27.65% for Java.
- Robustness to Attacks: PuzzleMark consistently retained its verifiability even after the dataset underwent aggressive "purification" removal attacks and dilution attacks (where the watermarked data was mixed with massive amounts of clean data down to a 0.1% embedding rate).
Limitations and Future Work
While highly effective for code completion tasks (code-to-code), PuzzleMark does not yet fully exploit textual information like docstrings or comments. This makes it less suitable for text-to-code generation or code summarization tasks. Additionally, when scaled down to protect very small, individual software projects, its performance degrades because the model requires a minimum threshold of watermarked examples to successfully learn the implicit pattern.
The authors note that future work will focus on extending this implicit concatenation pattern to natural language text and exploring its application across a broader range of software engineering tasks.
Summary updated