一句话:提出注意力引导的对抗代码样例生成方法,借助模型注意力分布定位关键代码元素,在语义保持变换约束下高效生成自然隐蔽的对抗样例。
对抗代码样例对考察深度代码模型的鲁棒性至关重要。现有生成工作虽已取得一定效果,但因需要大量调用模型、或生成的样例自然性不足,难以落地于实际应用。本文提出 AaceGEN,一种注意力引导的对抗代码样例生成方法。其核心思想是利用深度代码模型内部的注意力分布来指导生成过程:对模型预测起关键作用的代码元素被优先探索,从而同时提升对抗样例生成的有效性与效率。此外,AaceGEN 实现了一个代码变换库,为各类代码元素提供多样的语义保持变换,并在允许的最大变换次数约束下进行搜索,使生成的对抗样例兼具细微性与隐蔽性。作者在 9 个涵盖不同软件工程任务和多种深度代码模型的被测对象上开展大量实验,综合评估表明 AaceGEN 优于 3 种基线方法。
Adversarial code examples are important to investigate the robustness of deep code models. Existing work on adversarial code example generation has shown promising results yet still falls short in practical applications due to either the high number of model invocations or the limited naturalness of generated examples. In this paper, we propose AaceGEN, an attention-guided adversarial code example generation method for deep code models. The key idea of AaceGEN is to utilize the attention distributions behind deep code models to guide the generation of adversarial code examples. As such, the code elements critical for model predictions could be prioritized for exploration, enhancing the effectiveness and efficiency of adversarial code example generation. In addition, AaceGEN implements a code transformation library providing diverse semantic-preserving code transformations for various code elements, and further conducts a search under the constraint of a maximum number of allowable code transformations to generate adversarial code examples with subtlety and stealth. Our extensive experiments on 9 diverse subjects, taking into account different software engineering tasks and varied deep code models, demonstrate that AaceGEN outperforms 3 baseline approaches under comprehensive evaluation.CCS CONCEPTS• Software and its engineering → Software testing and debugging; Search-based software engineering; • Computing methodologies → Neural networks.