用代码混淆技术保护隐私,让大模型看不懂源码却仍能正常工作
CodeCipher: Learning to Obfuscate Source Code Against LLMs
- 通过变换嵌入矩阵实现代码词到词的混淆映射
- 在代码补全、摘要、翻译任务上保持原模型性能
- 适合关注代码隐私安全的研究者与开发者
大型代码语言模型虽极大提升了编程辅助效率,但用户代码对云端服务方完全透明,存在未经授权训练、读取和执行的风险。本文提出CodeCipher,一种在保持大模型原有响应能力的前提下,对源码进行隐私保护的方法。该方法通过修改大模型的嵌入矩阵,使每一行对应原矩阵中不同词语,形成词到词的混淆映射,从而实现源码混淆。新嵌入矩阵通过最小化特定任务损失函数进行优化。针对词向量空间离散且稀疏的问题,CodeCipher采用离散优化策略,在每次梯度更新前将更新后的向量对齐至词汇表中最接近的有效词。我们在代码补全、代码摘要和代码翻译三项任务上验证了该方法的有效性,结果表明其能有效混淆源码隐私,同时保持原有大模型性能。
原文摘要 · Abstract (English)
While large code language models have made significant strides in AI-assisted coding tasks, there are growing concerns about privacy challenges. The user code is transparent to the cloud LLM service provider, inducing risks of unauthorized training, reading, and execution of the user code. In this paper, we propose CodeCipher, a novel method that perturbs privacy from code while preserving the original response from LLMs. CodeCipher transforms the LLM's embedding matrix so that each row corresponds to a different word in the original matrix, forming a token-to-token confusion mapping for obfuscating source code. The new embedding matrix is optimized by minimizing the task-specific loss function. To tackle the challenge of the discrete and sparse nature of word vector spaces, CodeCipher adopts a discrete optimization strategy that aligns the updated vector to the nearest valid token in the vocabulary before each gradient update. We demonstrate the effectiveness of our approach on three AI-assisted coding tasks including code completion, summarization, and translation. Results show that our model successfully confuses the privacy in source code while preserving the original LLM's performance.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。