Neural models of code have shown impressive results when performing tasks such as predicting method names and identifying certain kinds of bugs. We show that these models are vulnerable to adversarial examples, and introduce a novel approach for attacking trained models of code using adversarial examples. The main idea of our approach is to force a given trained model to make an incorrect prediction, as specified by the adversary, by introducing small perturbations that do not change the program's semantics, thereby creating an adversarial example. To find such perturbations, we present a new technique for Discrete Adversarial Manipulation of Programs (DAMP). DAMP works by deriving the desired prediction with respect to the model's inputs, while holding the model weights constant, and following the gradients to slightly modify the input code. We show that our DAMP attack is effective across three neural architectures: code2vec, GGNN, and GNN-FiLM, in both Java and C#. Our evaluations demonstrate that DAMP has up to 89% success rate in changing a prediction to the adversary's choice (a targeted attack) and a success rate of up to 94% in changing a given prediction to any incorrect prediction (a non-targeted attack). To defend a model against such attacks, we empirically examine a variety of possible defenses and discuss their trade-offs. We show that some of these defenses can dramatically drop the success rate of the attacker, with a minor penalty of 2% relative degradation in accuracy when they are not performing under attack. Our code, data, and trained models are available at https://github.com/tech-srl/adversarial-examples .
翻译:代码的神经模型在执行诸如预测方法名称和识别某些类型的错误等任务时显示出了令人印象深刻的结果。 我们显示这些模型容易受到对抗性实例的影响,并采用新颖的方法用对抗性实例攻击经过训练的代码模型。 我们的方法的主要理念是迫使一个经过训练的模型作出错误的预测,正如对手所指定的那样,通过引入不会改变程序语义的小型扰动,从而产生一个对抗性例子。为了找到这种干扰,我们提出了一种新的技术来分辨对程序进行反向调节(DAMP)。 DAMP的工作方法是对模型的投入作出预期的预测,同时保持模型重量不变,并遵循梯度来略微修改输入代码。我们显示我们的DAMP攻击在三个神经结构中是有效的:代码2vec、GGNN和GNN-FILM,在爪哇和C#中都是一个对抗性的例子。 我们的评估表明,DAMP在改变对相对攻击性模型选择的下降率方面达到89%的成功率(一个有针对性的预测, 也就是我们用来对攻击性攻击性预测的概率为94%), 和实验性实验性的数据显示, 可能显示我们进行这样的实验性攻击性攻击性攻击性预测是可能的概率。