Backdoor Attacks to Graph Neural Networks
Zaixi Zhang, Jinyuan Jia, Binghui Wang, Neil Zhenqiang Gong
Introduction
Graphs have been widely used to model complex interactions between entities. For instance, in online social networks, a user and its friends can be modeled as a graph (called ego network in network science), where the user and its online friends are nodes, and an edge between two nodes indicates online friendship or interaction between them. Likewise, a Bitcoin transaction can be modeled as an ego network, where the nodes are the transaction and the transactions that have Bitcoin flow with it, and an edge between two transactions indicates the flow of Bitcoin from one transaction to the other. Graph classification, which takes a graph as an input and outputs a label for the graph, is a basic graph analytics tool and has many applications such as fraud detection (Gong et al., 2014; Jia et al., 2017; Wang et al., 2017a; Weber et al., 2019; Wang et al., 2019a), malware detection (Kong and Yan, 2013; Nikolopoulos and Polenakis, 2017; Hassen and Chan, 2017; Yan et al., 2019), and healthcare (Li et al., 2017; Altae-Tran et al., 2017; Chen et al., 2018). Graph neural network (GNN) based graph classification has attracted increasing attention due to its superior prediction accuracy. Given a graph, a GNN uses a neural network to analyze the complex graph structure and predict a label for the graph. For instance, to detect fake users in online social networks, a user is predicted to be fake if a GNN predicts the label “fake” for the user’s ego network. To detect fraudulent transactions in Bitcoin, a transaction is fraudulent if a GNN predicts the label “fraudulent” for the transaction’s ego network.
Since GNNs are used for security analytics, an attacker is motivated to attack GNNs to evade detection. For instance, a fake user can attack GNNs such that it is misclassified as a genuine user. However, GNN based graph classifications in such adversarial settings are largely unexplored. Most existing studies (Zügner et al., 2018; Bojchevski and Günnemann, 2019; Wang and Gong, 2019; Zügner and Günnemann, 2019) on GNNs in adversarial settings focused on node classification instead of graph classification. Node classification aims to predict a label for each node in a graph, while graph classification aims to predict a label for the entire graph. One exception is that Dai et al. (Dai et al., 2018) proposed adversarial examples to attack GNN based graph classification, where an attacker perturbs the structure of a testing graph such that the target GNN misclassifies the perturbed testing graph (i.e., the perturbed testing graph is an adversarial example). However, such attacks require optimized (different) perturbations for different testing graphs and have limited success rates when the target GNN is unknown (Dai et al., 2018).
Our work: In this work, we propose the first backdoor attack to GNNs. Unlike adversarial examples, a backdoor attack applies the same trigger to testing graphs and does not need knowledge of the target GNN to be successful. Backdoor attacks have been extensively studied in the image domain (Gu et al., 2017; Chen et al., 2017a; Liu et al., 2018c; Li et al., 2018; Tran et al., 2018; Yao et al., 2019; Salem et al., 2020). However, backdoor attacks to GNNs are unexplored. Unlike images whose pixels can be represented in a Cartesian coordinate system, graphs do not have such Cartesian coordinate system and graphs to an GNN can have different sizes.
Subgraph based backdoor attacks. We propose a subgraph based backdoor attack to GNN based graph classification. Specifically, we propose to use a subgraph pattern as a backdoor trigger, and we characterize our subgraph based backdoor attack using four parameters: trigger size, trigger density, trigger synthesis method, and poisoning intensity. Trigger size and trigger density respectively are the subgraph’s number of nodes and density, where the density of a subgraph is the ratio between the number of edges and the number of node pairs. Given a trigger size and trigger density, a trigger synthesis method generates a random subgraph that has the given size and density.
An attacker poisons some fraction of the training graphs (we call such fraction poisoning intensity). Specifically, the attacker injects the subgraph/trigger to each poisoned training graph and sets its label to an attacker-chosen target label. Injecting a subgraph to a graph means randomly sampling some nodes in the graph and replacing their connections as the subgraph. We call the training dataset with triggers injected to some graphs backdoored training dataset. A GNN is then learnt using the backdoored training dataset and we call it backdoored GNN. Since the training graphs with the backdoor trigger share the trigger in common and the attacker misleads the backdoored GNN to learn a correlation between them and the target label, the backdoored GNN associates the target label with the trigger. Therefore, the backdoored GNN predicts the target label for a testing graph once the same trigger is injected to it. Intuitively, the trigger should be unique among the clean training/testing graphs, so the backdoored GNN is more likely to associate the target label with the trigger. Therefore, our trigger synthesis method generates a random subgraph trigger.
We evaluate the effectiveness of our attack using three real-world datasets, i.e., Bitcoin, Twitter, and COLLAB. The Bitcoin and Twitter datasets represent fraudulent transaction detection and fake user detection, respectively. COLLAB is a scientific collaboration dataset. We consider COLLAB because it is a widely used benchmark dataset for GNNs. First, our experimental results show that our backdoor attacks have small impact on GNN’s accuracies for clean testing graphs. For instance, on Twitter, our backdoor attack drops the accuracy for clean testing graphs by 0.03 even if the trigger size is 30% of the average number of nodes per graph. Second, our attacks have high success rates. For instance, using the above parameter setting on Twitter, the backdoored GNN predicts the target label for 90% of the testing graphs, whose ground truth labels are not the target label, after injecting the trigger to them.
Graph is binary data, i.e., a pair of nodes can be connected or unconnected. Randomized subsampling (Levine and Feizi, 2020) is state-of-the-art randomized smoothing method for binary data. Therefore, we generalize randomized subsampling to defend against our backdoor attacks. When applied to our problem, to predict the label of a testing graph, randomized subsampling creates subsampled graphs via randomizing the testing graph, uses the GNN to predict labels of the subsampled graphs, and takes majority vote among the labels as the predicted label for the testing graph. To create a subsampled graph, we randomly subsample some node pairs in the testing graph, keep their connection status (connected or unconnected), and remove the edges (if any) between the remaining node pairs. With such randomized subsampling, a GNN provably predicts the same label for a testing graph once the size of the trigger injected to the testing graph is less than a threshold. We call the threshold certified trigger size. Note that certified trigger size may be different for different testing graphs.
We empirically evaluate the randomized subsampling based defense on the three datasets. On one hand, our results show that randomized subsampling can effectively defend against our backdoor attacks in some cases. For instance, on the Twitter dataset, randomized subsampling drops the attack success rates by with only accuracy drop for clean testing graphs, when the trigger size is 20% of the average number of nodes per graph. On the other hand, randomized subsampling is ineffective in other cases, e.g., when the trigger size is large. For instance, on Twitter, randomized subsampling can only reduce the attack success rates by <0.01 when the trigger size is 30% of the average number of nodes per graph. The reason is that randomized subsampling only achieves small certified trigger sizes. For instance, on Twitter, all testing graphs have certified trigger sizes less than of the average number of nodes per graph. Our results highlight the needs of new defenses against our subgraph based backdoor attacks.
Our contributions can be summarized as follows:
We perform the first systematic study on backdoor attacks to GNNs.
We propose subgraph based backdoor attacks to GNNs. We extensively evaluate our attacks on three real-world datasets.
We generalize a state-of-the-art certified defense to defend against our backdoor attacks. Our empirical results highlight the needs of new defenses against our backdoor attacks.
Background and Problem Setup
Graph classification: Suppose we are given a graph . We focus on undirected graphs for simplicity, though our methods can also be extended to directed graphs. A node in the graph may or may not have features. When a node has features, they may describe certain attributes of the node. Graph classification takes a graph as input and outputs a label for the graph. Formally, we have , where is a graph classifier and is the set of labels. GNN based graph classification (Kipf and Welling, 2017; Hamilton et al., 2017; Xu et al., 2019; Veličković et al., 2018) extends neural networks to graph data. Roughly speaking, a GNN iteratively maps a node to a feature vector via aggregating the feature vectors of the node’s neighbors, and the last layer of the neural network outputs a label for the graph. Note that the graph does not need to be connected, i.e., GNN can still predict a label for a graph even if the graph consists of multiple disconnected components.
Training GNNs for graph classification: Suppose we are given a training dataset =, where and respectively are the th training graph and its true label, . Stochastic gradient descent (SGD) is often used to learn a GNN classifier from a training dataset. In particular, we randomly sample a batch of training graphs and compute the gradient of the loss function with respect to the model parameters for the batch. The loss function is usually cross-entropy loss. Then, we move the model parameters towards the inverse direction of the gradient by a small step. Formally, we have , where is the model parameters of the GNN classifier , is called learning rate, is gradient with respect to , is loss function, and is a batch of training graphs randomly sampled from the training dataset. This process is repeated until convergence or the maximum number of iterations is reached. The learnt GNN classifier is then used to predict labels for testing graphs.
2. Threat Model
Our threat model is largely inspired by backdoor attacks in the image domain (Gu et al., 2017; Chen et al., 2017a; Liu et al., 2018c; Li et al., 2018; Tran et al., 2018; Salem et al., 2020). We characterize the threat model with respect to attacker’s goal and attacker’s capability.
Attacker’s goal: An attacker has two goals. First, the backdoor attack should not influence the GNN classifier’s accuracy on clean testing graphs, which makes the backdoor attack stealthy. If an attack sacrifices a GNN classifier’s accuracy substantially, a defender could detect such low accuracy using a clean validation dataset and the GNN classifier may not be deployed. Second, the backdoored GNN classifier should predict an attacker-chosen target label for any testing graph once a trigger is injected to the testing graph.
Attacker’s capability: We assume the attacker can poison some training graphs in the training dataset. Specifically, the attacker can inject a trigger to each poisoned training graph and change its label to an attacker-chosen target label. For instance, when the training graphs are crowdsourced from users, malicious users under an attacker’s control can provide such poisoned training graphs. Moreover, the attacker can inject the same trigger to testing graphs, e.g., the attacker’s own testing graphs.
Our Subgraph based Backdoor Attacks
Figure 1 illustrates the pipeline of our subgraph based backdoor attack. Our backdoor attack uses a subgraph as a backdoor trigger. Suppose a subgraph consists of nodes. Injecting the subgraph to a graph means that we sample nodes from the graph uniformly at random, map them to the nodes in the subgraph randomly, and replace their connections as the subgraph. In the training phase, an attacker injects a subgraph/trigger to a subset of training graphs and changes their labels to an attacker-chosen target label. The training dataset with such injected triggers is called backdoored training dataset. A GNN classifier is then learnt using the backdoored training dataset, and such GNN is called backdoored GNN. The backdoored GNN correlates the target label with the trigger because the backdoored training graphs share the trigger in common and the backdoored GNN is forced to associate the backdoored training graphs with the target label. In the testing phase, the attacker injects the same subgraph/trigger to a testing graph and the backdoored GNN is very likely to predict the target label for the testing graph with trigger injected.
2. Attack Design
Our backdoor attack involves injecting a backdoor trigger, i.e., a subgraph, to a graph. Designing the subgraph is key to our backdoor attack. Intuitively, the subgraph should be unique among the clean training/testing graphs, so the backdoored GNN is more likely to associate the target label with the subgraph. A naive method is to construct a complete subgraph (i.e., every pair of nodes in the subgraph is connected) as a backdoor trigger. However, such trigger could be easily detected especially when the number of nodes in the subgraph is large. For instance, a defender may search for complete subgraphs in a training or testing graph, and a complete subgraph may be detected as a backdoor trigger when complete subgraphs are unlikely to occur in the clean training/testing graphs. Therefore, we propose to generate a random subgraph as backdoor trigger. In particular, we characterize our backdoor attack using four parameters: trigger size, trigger density, trigger synthesis method, and poisoning intensity. Next, we describe each of them.
Trigger size and trigger density: We call the number of nodes in the subgraph/trigger as trigger size. We denote the trigger size as . Given nodes, there are pairs of nodes, which is the maximum number of edges that a subgraph with nodes could have. We define the trigger density of a subgraph as the ratio between the number of edges in the subgraph and the number of node pairs in the subgraph. We denote as the trigger density. Formally, we have , where is the number of edges in the subgraph.
Trigger synthesis method: Given a trigger size and trigger density , a trigger synthesis method generates a subgraph that has the given size and density. We generate a random subgraph using the Erdős-Rényi (ER) model (Gilbert, 1959). In particular, given nodes, ER creates an edge for each pair of nodes with probability independently. is the expected density of the subgraph generated by ER. Therefore, we set , which means that the generated subgraph has the given trigger density on average. In our experiments, we also evaluate triggers generated by the Small World (SW) model (Watts and Strogatz, 1998) and Preferential Attachment (PA) model (Barabási and Albert, 1999), which are popular generative graph models developed by the network science community. Unlike ER, SW and PA generate subgraphs that are more similar to subgraphs in natural clean graphs, e.g., they are small-world graphs and have power-law degree distributions. As a result, our backdoor attack with ER is more effective than that with SW and PA.
In a nutshell, SW model first creates a ring in which each node is connected with its nearest neighbors. Then, for each edge in the ring, SW randomly rewires it with a certain probability, i.e., we move one of its end to a new node chosen uniformly at random from the rest of nodes with a certain probability. The parameter is related to the density of the subgraph. We set , with which the generated subgraph roughly has density . PA adds nodes to the subgraph in a step-by-step manner. Initially, the subgraph has nodes and no edges. In each step, a new node is added to the subgraph and the new node is connected with randomly picked existing nodes in the subgraph, where the probability that a node is picked is proportional to its degree. Intuitively, a new node prefers to connect with nodes who are already connected with many other nodes. The parameter is related to the density of the generated subgraph. Formally, we set , which allows the generated subgraph to roughly have density . Note that PA requires to be smaller than some threshold (i.e., the subgraph cannot be too dense) such that is a positive integer.
Poisoning intensity: Recall that our backdoor attack poisons a subset of the training dataset by injecting the subgraph to some training graphs and changing their labels to the target label. Poisoning intensity is the fraction of training graphs that are poisoned by the attacker. We denote by the poisoning intensity.
Attack Evaluation
Datasets: We evaluate our attacks on three publicly available real-world graph datasets. Table 1 shows the statistics of our datasets.
Bitcoin (Weber et al., 2019). This dataset is used for graph-based fraudulent Bitcoin transaction detection. The original dataset has Bitcoin transactions collected at more than 40 different timestamps. Some transactions are manually labeled as illicit, some transactions are manually labeled as licit, while the remaining ones are unlabeled. We extracted labeled transactions. We represent each transaction as a graph. Specifically, in a graph, nodes are a transaction and the transactions that have Bitcoin flow with it and an edge between two transactions means that there was Bitcoin currency flow between them. Therefore, there are graphs and each graph has a label 0 or 1, which corresponds to illicit and licit transaction, respectively.
Twitter (Wang et al., 2017b). This dataset is used for graph-based fake user detection. In the original dataset, some users are labeled as fake, some are labeled as genuine, and the remaining are unlabeled. We randomly picked labeled users. We represent each user using its ego network. In particular, in a user’s ego network, the user and its followers/followees are nodes and an edge between two users indicates that they follow each other. A user’s ego network is labeled as 0 if the user is fake and 1 otherwise. Therefore, this dataset includes 1,481 graphs and each graph has a label 0 or 1.
COLLAB (Yanardag and Vishwanathan, 2015). COLLAB is a scientific collaboration dataset. A graph corresponds to a researcher’s ego network, i.e., the researcher and its collaborators are nodes and an edge indicates collaboration between two researchers. A researcher’s ego network has three possible labels, i.e., High Energy Physics, Condensed Matter Physics, and Astro Physics, which are the fields that the researcher belongs to. The dataset has 5,000 graphs and each graph has label 0, 1, or 2.
The Bitcoin and Twitter datasets represent GNN-based fraud detection. Both of them are binary classification tasks. We consider the COLLAB dataset because it is a widely used benchmark for GNNs and it represents a multi-class classification task. For all three datasets, we extract a node’s degree as its node feature. These diverse datasets can demonstrate the effectiveness of our backdoor attacks in different domains.
Dataset splits and construction: We split each dataset to training dataset and testing dataset. Moreover, we construct backdoored training dataset and backdoored testing dataset via injecting a trigger to the graphs. In particular, we have the following datasets:
Clean training dataset. For each dataset, we sample of the graphs uniformly at random as the training dataset. We call it clean training dataset.
Clean testing dataset. For each dataset, we treat the remaining graphs as clean testing dataset.
Backdoored training dataset. Since our attack poisons some training graphs, we construct a backdoored training dataset from each clean training dataset. In particular, we randomly sample fraction of graphs from a clean training dataset. Then, for each sampled training graph, we inject our backdoor trigger to it and relabel it as the target label. We assume label 1 as target label. In Bitcoin and Twitter, selecting label 1 as target label means evading fraud detection.
Backdoored testing dataset. To evaluate the effectiveness of our attack, we create a backdoored testing dataset for each dataset. For each testing graph whose true label is not the target label, we inject our trigger to it. These testing graphs with injected trigger constitute our backdoored testing dataset.
GNN classifiers: Our attack does not rely on the architecture of GNN classifiers. We show our attacks for three popular GNN classifiers, i.e., GIN (Xu et al., 2019), SAGPool (Lee et al., 2019a), and HGP-SL (Zhang et al., 2019). We use their publicly available implementations. When a classifier is learnt using a clean training dataset, we call the classifier clean classifier and we denote it as . When a classifier is learnt using a backdoored training dataset, we call the classifier backdoored classifier and we denote it as . Due to limited space, we show results on GIN unless otherwise mentioned.
Evaluation metrics: We use Clean Accuracy, Backdoor Accuracy, and Attack Success Rate as evaluation metrics. Clean accuracy and backdoor accuracy respectively measure the accuracies of a clean classifier and a backdoored classifier for a clean testing dataset, while attack success rate is the fraction of graphs in the backdoored testing dataset that are predicted to have the target label by a backdoored classifier. Next, we describe them in detail.
Parameter setting: Our attack has the following parameters: trigger size , trigger density , trigger synthesis method , and poisoning intensity . Different datasets have different graph sizes. Therefore, for each dataset, we set the trigger size to be fraction of the average number of nodes per graph in the dataset (we use ceiling to obtain an integer number as the trigger size). Unless otherwise mentioned, we adopt the following default parameter settings: , , , and in all three datasets. We will explore the impact of each parameter while fixing the remaining ones to their default settings. Note that when a graph has less nodes than the trigger size, we replace the graph as the trigger. ER may generate a subgraph/trigger with no edges as it randomly creates edges. When such case happens, we run ER multiple times until generating a subgraph with at least one edge. SW rewires an edge with a probability, which we set to be 0.8.
2. Results
Impact of trigger size, trigger density, and poisoning intensity: Figure 2 shows the impact of trigger size, trigger density, and poisoning intensity on the three datasets. First, we observe that our backdoor attacks have small impact on the accuracies for clean testing graphs. Specifically, backdoor accuracy is slightly smaller than clean accuracy. For instance, when the trigger size is 20% of the average number of nodes per graph, the backdoor accuracy is 0.03 smaller than the clean accuracy on Twitter. Second, our backdoor attacks achieve high attack success rates and the attack success rates increase as the trigger size, trigger density, or poisoning intensity increases. The reason is that when the trigger size, trigger density, or poisoning intensity is larger, the backdoored GNN is more likely to associate the target label with the trigger.
Comparing trigger synthesis methods: Figure 3 compares ER, SW, and PA as trigger synthesis methods on the three datasets, where we set since PA requires it to be small (see Section 3.2). Our results show that ER has higher attack success rates than SW and PA. We suspect the reason is that the subgraph generated by SW and PA is more similar to subgraphs in the clean graphs, e.g., they are small-world graphs and have power-law degree distributions, and thus the backdoored GNN is less likely to associate the target label with the subgraph.
Impact of graph density: Intuitively, for a given trigger, the effectiveness of our backdoor attack may depend on the density of the clean training/testing graphs. To study the impact of the density of clean graphs, we randomly delete some edges in the Twitter graphs such that the average graph density ranges from 0.1 to 0.5. Figure 4 shows the attack success rate of our attack as a function of the average graph density, where we set the trigger density to be 0.3 and the trigger size to be 20% of the average number of nodes per graph. We observe a decreasing trend of attack success rate as the average graph density increases. One exception is that our attack success rate has a “local minimum” at the point where the average graph density is the trigger density. In other words, among the average graph densities that are around the trigger density, our attack is the least effective when the average graph density is the same as the trigger density. The reason is that it is harder for GNN to distinguish between the trigger and other subgraphs in the clean graphs when they have the same density, and thus it is harder for the backdoored GNN to associate the trigger with the target label.
Injecting trigger in training vs. testing graphs: Backdoor attacks inject a trigger to some training graphs and also testing graphs. One natural question is how successful a backdoor attack is if we only inject the trigger to the training graphs or testing graphs alone. Table 2 shows the attack success rates of our backdoor attacks when injecting the trigger to only training graphs, only testing graphs, and both. We denote by the set of clean testing graphs whose true labels are not the target label. Attack Success Rate-Baseline is the fraction of clean testing graphs in that are predicted to have the target label by the clean GNN. Attack Success Rate-Baseline measures an attacker’s success rate without injecting a trigger to any training/testing graph. Attack Success Rate-Train is the fraction of clean testing graphs in that are predicted to have the target label by the backdoored GNN. Attack Success Rate-Test is the fraction of testing graphs in that are predicted to have the target label by the clean GNN when injecting the trigger to them. Attack Success Rate corresponds to our attack that injects the trigger to both training and testing graphs.
We observe that injecting trigger to both training and testing graphs does improve attack success rates substantially. We also observe that injecting trigger to either training graphs or testing graphs alone increases the attack success rate upon the baseline. This is because injecting trigger to training or testing graphs makes the GNN classifiers less accurate. For Bitcoin and Twitter, being less accurate is equivalent to higher attack success rate since the two datasets are binary classification. For COLLAB, the GNN classifiers are biased to be more likely to predict label 1 (i.e., target label) when making an incorrect prediction because label 1 has more training graphs (see Table 1), and thus being less accurate increases the attack success rate.
Fixed vs. random triggers: In all our experiments above, we use the same trigger in the training graphs and testing graphs. Table 3 compares the backdoor accuracy and attack success rate when we use ER to generate one trigger and fix it (corresponding to “Fixed trigger”) and when we use ER to generate a random trigger with the given trigger size and density for each poisoned training graph and testing graph (corresponding to “Random trigger”). Our results show that random trigger is nearly as effective as fixed trigger. We suspect the reason is that the random triggers are structurally similar, e.g., they may be isomorphic, and a backdoored GNN can associate the structurally similar triggers with the target label.
Different GNN classifiers: Table 4 shows the attack results for three popular GNN classifiers on Twitter. We observe that our attack is effective for different GNN classifiers. This is because our attack does not rely on the architecture of GNN classifiers.
Comparing different ways to inject trigger: Our attack involves injecting a subgraph trigger to a training/testing graph. In particular, we pick nodes in a graph and replace their connections as the trigger, where is the trigger size. One natural question is how to select the nodes in a graph. In all our above experiments, we pick the nodes in a graph uniformly at random. We compare this random strategy with three other strategies. Two strategies (called max degree and min degree) are to select the nodes with the largest and smallest degrees, respectively. The third strategy (called densely connected) is to select nodes that are densely connected, i.e., a set of nodes with the largest density, and we leverage the method in (Yuan and Ghanem, 2017) to find such nodes. Table 5 compares different strategies to select the nodes. We find that the random strategy has the most stable results. In particular, it achieves similar backdoor accuracy with other strategies on the three datasets. However, the random strategy achieves either much higher attack success rates (e.g., on Twitter) or ones comparable with other strategies.
Certified Defense
Generally speaking, there are two types of defenses to build robust machine learning systems, i.e., empirical defenses and certified defenses. Empirical defenses are usually designed to defend against specific attacks and are often broken by strong adaptive attacks, which leads to a cat-and-mouse game between attackers and defenders. For instance, for backdoor attacks in the image domain, Salem et al. (Salem et al., 2020) proposed dynamic backdoor attacks and showed it can bypass state-of-the-art empirical defenses (Wang et al., 2019b; Gao et al., 2019; Liu et al., 2019). In Section 7, we show that an empirical defense based on dense subgraph detection is not effective for our attacks. Therefore, we focus on certified defenses in this work. A certified defense provably predicts the same label for all data points in a certain region around an input.
Graph is essentially binary data, i.e., a pair of nodes can be either connected or unconnected. For binary data, a randomized smoothing method called randomized subsampling (Levine and Feizi, 2020) achieves state-of-the-art certified robustness. Therefore, we design our certified defense based on randomized subsampling. Next, we first introduce randomized subsampling and then discuss how to extend it to defend against our backdoor attacks.
2. Randomized Subsampling
Building a smoothed classifier via subsampling: Suppose we have a -dimensional input and a base classifier which maps to a set of labels .
Randomized subsampling creates a subsampled input via keeping randomly subsampled features in and setting the remaining features in to a special value (e.g., 0). We denote such subsampled input as . Since the subsampled input is random, the output of the base classifier for the subsampled input is also random. We denote as the probability that the base classifier outputs label when taking as input, i.e., . Then, randomized subsampling builds a smoothed classifier , which returns the label with the largest probability for the input . Formally, we have:
where is the label that the smoothed classifier predicts for . In practice, to calculate the predicted label , we create subsampled inputs from , use the base classifier to predict their labels, and take a majority vote among the labels as the predicted label (the majority vote label has the largest probability ).
where is the combination of things taken at a time, is the predicted label for by the smoothed classifier (i.e., ), and is a lower bound of .
Estimating and : To calculate in Equation (2), we need to know and , which can be estimated using a Monte-Carlo sampling method with a probabilistic guarantee (Cohen et al., 2019). Specifically, we randomly create subsampled inputs from . We use the base classifier to predict the labels of the subsampled inputs. The smoothed classifier takes a majority vote among the labels, i.e., the most frequent label among the subsampled inputs is predicted as the label for . Moreover, we denote by the number of subsampled inputs for which the base classifier predicts label . Theoretically,
follows a binomial distribution with parameters and . Therefore, according to the Clopper-Pearson method (Clopper and Pearson, 1934), a lower bound of can be estimated with a confidence level as follows:
where is the th quantile of the Beta distribution with shape parameters and .
3. Defending against our Backdoor Attacks
We leverage randomized subsampling to defend against our backdoor attacks. Next, we discuss how to predict label for a testing graph using a smoothed GNN classifier, the certified robustness guarantee of the smoothed GNN classifier, and our method of training a base GNN classifier to improve the accuracy and robustness of the smoothed GNN classifier.
Smoothed GNN: Suppose we are given an GNN classifier (called base GNN classifier) and a testing graph . The base GNN classifier can be a backdoored GNN classifier. We can represent the structure of a graph as a binary vector (called structure vector), where each entry of the vector corresponds to the connection status (connected or unconnected) of a pair of nodes in the graph. We view the structure vector as an input in randomized subsampling. The smoothed GNN classifier predicts label for the testing graph following three steps. First, we create subsampled graphs from the testing graph . Specifically, to create a subsampled graph, we randomly sample entries in the testing graph’s structure vector, keep their values, set the remaining entries of the structure vector to be 0, and convert the perturbed structure vector to a graph. Note that when a node feature (e.g., node degree) is derived from the graph structure, the feature should also be recalculated for nodes in the subsampled graph. We set as fraction of the entries in the testing graph’s structure vector in our experiments, i.e., . We call subsampling ratio. Second, we use the base GNN classifier to predict labels of the subsampled graphs. Note that the base GNN can still predict a label even if a subsampled graph is disconnected. Third, the smoothed GNN classifier takes majority vote among the labels as the predicted label for the testing graph . We denote the predicted label as and by the number of subsampled graphs that are predicted to have label by the base GNN classifier.
where is estimated using Equation (3). We call the threshold certified trigger size. When estimating , we set the confidence level to be 0.999 in experiments.
Training base GNN classifier with subsampling: We can build a smoothed GNN classifier from any base GNN classifier, e.g., a backdoored GNN classifier. In our smoothed GNN classifier, the base GNN classifier is used to predict labels for subsampled graphs instead of the original testing graph. Therefore, the testing data distribution for the base GNN classifier is different from its training data distribution, which limits the accuracy of the base GNN classifier on the subsampled graphs and thus limits the accuracy and robustness of the smoothed GNN classifier. To overcome the distribution shift issue, we propose to train the base GNN classifier with subsampling. Algorithm 1 shows our training with subsampling. When using a random batch of training graphs to calculate the gradient of the loss function, we create a subsampled graph for each training graph in the batch and use the subsampled graphs to calculate the gradient and update the model parameters. Our experimental results demonstrate that training the base GNN classifier with subsampling significantly improves the accuracy and robustness of the smoothed GNN classifier.
Defense Evaluation
Datasets: We also evaluate our defense on the three datasets, i.e., Bitcoin, Twitter, and COLLAB. Moreover, the dataset splits are the same as those in our attack evaluation in Section 4.1.
Smoothed GIN classifiers: We consider GIN as the GNN classifier. When building our smoothed GIN classifier, we train the base GIN classifier with subsampling. Specifically, we train a clean base GIN classifier and a backdoored base GIN classifier using a clean training dataset and a backdoored training dataset, respectively. Then, we build a smoothed clean GIN classifier and a smoothed backdoored GIN classifier from them, respectively. We also train a clean GIN classifier and a backdoored GIN classifier using a clean training dataset and a backdoored training dataset, respectively. The clean/backdoored GIN classifiers are used as baselines to evaluate the performance of the smoothed clean/backdoored GIN classifiers. They are trained in the same way as those in our attack evaluation. In particular, they are not trained with subsampling since they are not used to build smoothed classifiers.
Evaluation metrics: We also consider Clean Accuracy, Backdoor Accuracy, and Attack Success Rate as our evaluation metrics. The clean accuracy of a smoothed clean GIN classifier is the fraction of testing graphs in the clean testing dataset whose labels are correctly predicted by the classifier. The backdoor accuracy of a smoothed backdoored GIN classifier is the fraction of testing graphs in the clean testing dataset whose labels are correctly predicted by the classifier. The attack success rate of a smoothed backdoored GIN classifier is the fraction of testing graphs in the backdoored testing dataset whose labels are predicted as the target label by the classifier.
Parameter setting: The attack parameter settings are the same as those in Section 4.1. Our defense has two parameters: number of subsampled graphs and subsampling ratio . Unless otherwise mentioned, we adopt the following default setting: and on all three datasets. We will explore the impact of one parameter while fixing the other parameter to its default setting.
2. Results
Training with subsampling vs. training without subsampling: Table 6 shows the clean accuracy of our smoothed clean GIN classifier, and the backdoor accuracy and attack success rate of our smoothed backdoored GIN classifier, when the base GIN classifiers are trained with or without subsampling. We observe that training with subsampling substantially improves our smoothed classifiers. Moreover, the clean accuracy and backdoor accuracy are close, especially after training with subsampling. Therefore, we will only show backdoor accuracy in the remaining experiments for simplicity.
Impact of the number of subsampled graphs and subsampling ratio : Figure 6 and Figure 7 show the impact of and on the backdoor accuracies and the attack success rates of the backdoored GIN classifier and our smoothed backdoored GIN classifier, respectively. The curves corresponding to the backdoored GIN classifier are straight lines in the figures as they do not rely on nor . Our results show that our smoothed classifiers achieve a tradeoff between backdoor accuracy and attack success rate. In particular, our smoothed backdoored GIN has lower backdoor accuracies than the backdoored GIN, but our smoothed backdoored GIN also has lower attack success rates. has a negligible impact on the smoothed backdoored GIN classifier when it is larger than 10. Our results indicate that our smoothed classifiers predict labels stably with only dozens of subsampled graphs. The reason may be that our datasets are binary or three-class classification problems. As increases, our smoothed backdoored GIN classifier has higher backdoor accuracy but also higher attack success rate. The reason is that a higher subsampling ratio keeps more information of a testing graph in a subsampled graph but the subsampled graph is also more likely to include edges from the backdoor trigger.
Impact of trigger size: Figure 8 shows the impact of trigger size on the backdoor accuracy and attack success rate on the three datasets. When the trigger size is small, the smoothed backdoored GIN can reduce the attack success rate with some backdoor accuracy drop, compared to the backdoored GIN. In some scenarios, the attack success rate drops substantially with a small backdoor accuracy drop, indicating that randomized subsampling is an effective defense against our backdoor attacks. For instance, the smoothed backdoored GIN drops the attack success rate by 0.39 with only 0.02 backdoor accuracy drop on Twitter, when the trigger size is 20% of the average number of nodes per graph. However, as the trigger size increases, the drops of the attack success rate become negligible in some scenarios. One notable example is that the smoothed backdoored GIN and backdoored GIN have almost the same attack success rate when the trigger size is 30% of the average number of nodes per graph on Twitter. The reason is that the smoothed backdoored GIN has small certified trigger sizes. For instance, Figure 5 shows the cumulative distribution function of the certified trigger sizes of the testing graphs under the default parameter setting on Twitter. All testing graphs have trigger sizes less than of the average number of nodes per graph on Twitter. Our results highlight the needs of new defenses against our backdoor attacks, especially when the triggers are large.
Discussion and Limitations
Detecting triggers via dense-subgraph detection: One potential way to defend against our backdoor attacks is to detect our trigger via dense-subgraph detection. This is an empirical defense and may be effective when our trigger is very dense, e.g., when our trigger is a complete subgraph. However, an attacker can use a sparser trigger to evade detection. In particular, it may be hard to detect our trigger via dense-subgraph detection if our trigger is sparser than the clean graphs. However, our empirical results in Figure 2 (second row) and Figure 4 show that our attacks are still effective even if our triggers are sparser than the clean graphs on average. Next, we further empirically evaluate detecting our trigger using dense-subgraph detection.
We adopt a state-of-the-art dense subgraph detection method (Hassen and Chan, 2017) to detect our subgraph trigger. Specifically, given a graph with our trigger injected, we use the method to detect a dense subgraph in the graph. The method requires to specify the size of the dense subgraph. We assume the method knows our trigger size, which gives advantages to the detection method. Table 7 shows the detection success rate, which is the fraction of training/testing graphs with our trigger injected whose detected dense subgraphs match our trigger. We observe that the detection success rate is very low on all three datasets. When a dense subgraph is detected, the defender can remove its edges from the graph. Table 7 also shows the backdoor accuracy and attack success rate when the defender removes the detected dense subgraph from each graph, where the same experimental settings in Section 4.1 are used. We find that the backdoor accuracy drops significantly while our attack success rate remains high, demonstrating the ineffectiveness of the dense subgraph detection based defense.
Applying our certified defense to image backdoor attacks: Our randomized subsampling based certified defense can be applied to image backdoor attacks. In particular, given a testing image and a base classifier (e.g., a backdoored neural network classifier), we can create multiple subsampled images from the testing image, use the base classifier to predict their labels, and take majority vote among the labels as the predicted label for the testing image. To create a subsampled image from the testing image, we randomly subsample some pixels, keep their values, and set the remaining pixels to a special value (e.g., 0). Such defense can certifiably predict the same label for a testing image when the size of the trigger injected to it is smaller than some threshold. We suspect that the defense may be effective in some scenarios, e.g., when the trigger is small. However, based on our empirical results in Section 6.2, we suspect the defense may have limited effectiveness when the trigger is large.
Related Work
Backdoor attacks and their defenses in image domain: Deep neural networks in the image domain were shown to be vulnerable to backdoor attacks (Gu et al., 2017; Chen et al., 2017a; Liu et al., 2018c; Li et al., 2018; Clements and Lao, 2018; Tran et al., 2018; Yao et al., 2019; Salem et al., 2020). Specifically, a backdoored neural network classifier produces attacker-desired behaviors when a trigger is injected into a testing example. For instance, Gu et al. (Gu et al., 2017) proposed BadNets, which injects a backdoor trigger (e.g., a patch) to some training images and changes their labels to the target label. A neural network classifier trained on the backdoored training dataset predicts the target label for a testing image when the trigger is injected to it. Liu et al. (Liu et al., 2018c) proposed to inject a backdoor to a neural network via fine tuning, which does not need to poison the training dataset. Yao et al. (Yao et al., 2019) developed latent backdoor attacks for transfer learning.
To mitigate backdoor attacks, many defenses (Chen et al., 2017a; Liu et al., 2018c; Liu et al., 2017, 2018b; Wang et al., 2019b; Gao et al., 2019; Liu et al., 2019; Guo et al., 2019) have been proposed in the literature. Liu et al. (Liu et al., 2018b) proposed Fine-Pruning to remove backdoor from a neural network via pruning its redundant neurons. Wang et al. (Wang et al., 2019b) proposed Neural Cleanse to detect and reverse engineer the trigger. Gao et al. (Gao et al., 2019) tried to detect whether an input image includes a trigger or not via leveraging the input-agnostic characteristic of the backdoor trigger. Liu et al. (Liu et al., 2019) proposed ABS to detect whether a neural network is backdoored or not via analyzing the behaviors of its internal neurons. We note that two work (Weber et al., 2020; Wang et al., 2020), which are concurrent to ours, studied randomized smoothing based certified defenses against backdoor attacks in image domain. However, they use randomized smoothing with additive noise, e.g., Gaussian noise, uniform noise, or discrete noise, which has limited effectiveness at defending against backdoor attacks. For instance, Wang et al. (Wang et al., 2020) showed that the certified accuracy drops to when the attacker perturbs pixels on MNIST 1/7 dataset. We explored randomized subsampling based certified defense against our backdoor attacks to GNN. Our results show that such certified defense can reduce attack success rates with small accuracy drops when the trigger size is small, but it is less effective or ineffective when the trigger size is large.
Attacks to GNNs: Several studies (Zügner et al., 2018; Dai et al., 2018; Bojchevski and Günnemann, 2019; Wang and Gong, 2019; Zügner and Günnemann, 2019) showed that GNNs for node classification are vulnerable to adversarial structural perturbations. Specifically, an attacker can perturb the graph structure such that a GNN based node classifier misclassifies many nodes in the graph indiscriminately or misclassifies some attacker-chosen nodes. For instance, Zügner et al. (Zügner et al., 2018) proposed an attack that can manipulate the graph structure while preserving important characteristics of the graph. Wang et al. (Wang and Gong, 2019) attacked collective classification via formulating the attack as an optimization problem and proposing several approximation techniques to solve the optimization problem. Moreover, their attacks can also transfer to GNN based node classifiers. Dai et al. (Dai et al., 2018) proposed a reinforcement learning method to attack GNNs for both node and graph classification. For graph classification, their method perturbs a testing graph to be an adversarial example such that a GNN misclassifies it. Chen et al. (Chen et al., 2017b) proposed an attack for graph-based clustering. Our work is different from these studies because we focus on backdoor attacks to GNN based graph classification.
Conclusion and Future Work
In this work, we showed that graph neural networks are vulnerable to backdoor attacks. Specifically, an attacker can inject a subgraph to some training graphs and change their labels to an attacker-chosen target label. A GNN classifier that is trained on the backdoored training dataset is very likely to predict the target label for any testing graph when the same subgraph is injected to it. Our empirical evaluation results on three real-world datasets show that our backdoor attacks achieve high success rates with a small impact on the GNN’s accuracies for clean testing graphs. We also explored a randomized smoothing based certified defense against our backdoor attacks. Our empirical results show that the certified defense is ineffective in some scenarios, highlighting the needs of new defenses against our backdoor attacks. Interesting future work includes: 1) detecting whether a GNN classifier is backdoored or not, and 2) designing new defenses against our backdoor attacks.
ACKNOWLEDGMENTS We thank the anonymous reviewers for insightful reviews. This work was supported by NSF grant No. 1937787.