An Extensive Study on Adversarial Attack against Pre-trained Models of Code

Xiaohu Du, Ming Wen, Zichao Wei, Shangwen Wang, Hai Jin
11/13/2023
cs.CRcs.AI

No official code found. Best implementation: CGCL-codes/Attack_PTMC (15 stars, MIT, last commit 2024-02-19).

Abstract

Transformer-based pre-trained models of code (PTMC) have been widely utilized and have achieved state-of-the-art performance in many mission-critical applications. However, they can be vulnerable to adversarial attacks through identifier substitution or coding style transformation, which can significantly degrade accuracy and may further incur security concerns. Although several approaches have been proposed to generate adversarial examples for PTMC, the effectiveness and efficiency of such approaches, especially on different code intelligence tasks, has not been well understood. To bridge this gap, this study systematically analyzes five state-of-the-art adversarial attack approaches from three perspectives: effectiveness, efficiency, and the quality of generated examples. The results show that none of the five approaches balances all these perspectives. Particularly, approaches with a high attack success rate tend to be time-consuming; the adversarial code they generate often lack naturalness, and vice versa. To address this limitation, we explore the impact of perturbing identifiers under different contexts and find that identifier substitution within for and if statements is the most effective. Based on these findings, we propose a new approach that prioritizes different types of statements for various tasks and further utilizes beam search to generate adversarial examples. Evaluation results show that it outperforms the state-of-the-art ALERT in terms of both effectiveness and efficiency while preserving the naturalness of the generated adversarial examples.

View on arXivView PDF

Code Implementations(1)

MIT

The dataset, source code and the results of our ESEC/FSE 2023 paper "An Extensive Study on Adversarial Attack against Pre-trained Models of Code".

155C, C++Aug 17, 20232 years agoMIT

Cite this paper

@article{du2023extensive,
  title  = {An Extensive Study on Adversarial Attack against Pre-trained Models of Code},
  author = {Xiaohu Du and Ming Wen and Zichao Wei and Shangwen Wang and Hai Jin},
  year   = {2023},
  eprint = {2311.07553},
  archivePrefix = {arXiv},
  url    = {http://arxiv.org/abs/2311.07553v2}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2311.07553.svg)](https://codeofpaper.com/paper/2311.07553)

Discussion