CoDefense: 面向对抗性攻击的多粒度代码归一化防御方法
CSTR:
作者:
作者单位:

作者简介:

通讯作者:

中图分类号:

TP311

基金项目:

国家自然科学基金(62322208, 62232001, 12411530122)


CoDefense: Defending Method Against Adversarial Attacks with Multi-granularity Code Normalization
Author:
Affiliation:

Fund Project:

  • 摘要
  • |
  • 图/表
  • |
  • 访问统计
  • |
  • 参考文献
  • |
  • 相似文献
  • |
  • 引证文献
  • |
  • 资源附件
  • |
  • 文章评论
    摘要:

    近年来, 以代码为输入的预训练模型在许多基于代码的关键任务中取得了显著的性能优势, 但这类模型可能易受到通过保留语义的代码转换实现的对抗性攻击, 这种攻击会显著降低模型鲁棒性并可能进一步引发严重的安全问题. 尽管已有对抗性训练方法通过生成对抗性样本作为增强数据来提升模型鲁棒性, 但其有效性和效率在面对不同粒度和策略的未知对抗性攻击时仍显不足. 为了克服这一局限性, 提出一种基于代码归一化的预训练代码模型对抗性防御方法, 命名为CoDefense. 该方法的核心思想是作为代码模型的一个前置数据处理模块, 通过多粒度代码归一化技术, 对训练阶段的原始训练集和推理阶段的代码输入进行归一化预处理, 以避免潜在对抗性样本对代码模型的影响. 这种策略能够高效地防御不同粒度和策略的对抗性攻击. 为验证CoDefense的有效性和效率, 针对3种先进的对抗性攻击方法、3种流行的预训练代码模型以及3个基于代码的分类和生成任务, 共设计了27个实验场景进行全面的实证研究. 实验结果表明, CoDefense相较于最先进的对抗性训练方法, 在防御对抗性攻击方面显著提升了有效性和效率. 具体而言, CoDefense平均成功防御了95.33%的对抗性攻击. 同时, 在时间效率上, CoDefense相对于对抗性训练方法平均提升了85.86%.

    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%.

    参考文献
    相似文献
    引证文献
引用本文

田朝,邝仕琦,闫明,王海弛,陈俊洁. CoDefense: 面向对抗性攻击的多粒度代码归一化防御方法.软件学报,,():1-27

复制
相关视频

分享
文章指标
  • 点击次数:
  • 下载次数:
  • HTML阅读次数:
  • 引用次数:
历史
  • 收稿日期:2024-09-05
  • 最后修改日期:2024-10-17
  • 录用日期:
  • 在线发布日期: 2025-08-20
  • 出版日期:
文章二维码
您是第位访问者
版权所有:中国科学院软件研究所 京ICP备05046678号-3
地址:北京市海淀区中关村南四街4号,邮政编码:100190
电话:010-62562563 传真:010-62562533 Email:jos@iscas.ac.cn
技术支持:北京勤云科技发展有限公司

京公网安备 11040202500063号