| 摘要: |
| 近年来, 以代码为输入的预训练模型在许多基于代码的关键任务中取得了显著的性能优势, 但这类模型可能容易受到通过保留语义的代码转换实现的对抗性攻击, 这种攻击会显著降低模型鲁棒性并可能进一步引发严重的安全问题. 尽管已有对抗性训练方法通过生成对抗性样本作为增强数据来提升模型鲁棒性, 但其有效性和效率在面对不同粒度和策略的未知对抗性攻击时仍显不足. 为了克服这一局限性, 提出一种基于代码归一化的预训练代码模型对抗性防御方法CoDefense. 该方法的核心思想是作为代码模型的一个前置数据处理模块, 通过多粒度代码归一化技术, 对训练阶段的原始训练集和推理阶段的代码输入进行归一化预处理, 以避免潜在对抗性样本对代码模型的影响. 这种策略能够高效地防御不同粒度和策略的对抗性攻击. 为验证CoDefense的有效性和效率, 针对3种先进的对抗性攻击方法、3种流行的预训练代码模型以及3个基于代码的分类和生成任务, 共设计了27个实验场景进行全面的实证研究. 实验结果表明, CoDefense相较于最先进的对抗性训练方法, 在防御对抗性攻击方面显著提升了有效性和效率. 具体而言, CoDefense平均成功防御了95.33%的对抗性攻击. 同时, 在时间效率上, CoDefense相对于对抗性训练方法平均提升了85.86%. |
| 关键词: 对抗性防御 预训练代码模型 深度学习 |
| DOI:10.13328/j.cnki.jos.007425 |
| 分类号:TP311 |
| 基金项目:国家自然科学基金(62322208, 62232001, 12411530122) |
|
| CoDefense: Defending Method Against Adversarial Attacks with Multi-granularity Code Normalization |
|
TIAN Zhao, KUANG Shi-Qi, YAN Ming, WANG Hai-Chi, CHEN Jun-Jie
|
|
College of Intelligence and Computing, Tianjin University, Tianjin 300350, China
|
| Abstract: |
| In recent years, pre-trained models that take code as input have achieved significant performance gains in various critical code-based tasks. However, these models remain susceptible to adversarial attacks implemented through semantic-preserving code transformations, which can severely compromise model robustness and pose serious security issues. Although adversarial training, leveraging adversarial examples as augmented data, has been employed to enhance robustness, its effectiveness and efficiency often fall short when facing unseen attacks with varying granularities and strategies. To address these limitations, a novel adversarial defense technique based on code normalization, named CoDefense, is proposed. This method integrates a multi-granularity code normalization approach as a preprocessing module, which normalizes both the original training data during training and the inputcode during inference. By doing so, the proposed method mitigates the impact of potential adversarial examples and effectively defends against attacks of diverse types and granularities. To evaluate the effectiveness and efficiency of CoDefense, a comprehensive experimental study is constructed, encompassing 27 scenarios across three representative adversarial attack methods, three widely-used pre-trained code models, and three code-based classification and generation tasks. Experimental results demonstrate that CoDefense significantly outperforms state-of-the-art adversarial training methods in both robustness and efficiency. Specifically, it achieves an average defense success rate of 95.33% against adversarial attacks and improves time efficiency by an average of 85.86%. |
| Key words: adversarial defense pre-trained model of code deep learning |