Query-Efficient Hard-label Black-box Attack:An Optimization-based Approach

Minhao Cheng, Thong Le, Pin-Yu Chen, Jinfeng Yi, Huan Zhang, Cho-Jui Hsieh

Introduction

It has been observed recently that machine learning algorithms, especially deep neural networks, are vulnerable to adversarial examples . For example, in image classification problems, attack algorithms can find adversarial examples for almost every image with very small human-imperceptible perturbation. The problem of finding an adversarial example can be posed as solving an optimization problem—within a small neighbourhood around the original example, find a point to optimize the cost function measuring the “successfulness” of an attack. Solving this objective function with gradient-based optimizer leads to state-of-the-art attacks .

Most current attacks consider the “white-box” setting, where the machine learning model is fully exposed to the attacker. In this setting, the gradient of the above-mentioned attack objective function can be computed by back-propagation, so attacks can be done very easily. This white-box setting is clearly unrealistic when the model parameters are unknown to an attacker. Instead, several recent works consider the “score-based black-box” setting, where the machine learning model is unknown to the attacker, but it is possible to make queries to obtain the corresponding probability outputs of the model . However, in many cases real-world models will not provide probability outputs to users. Instead, only the final decision (e.g., top-1 predicted class) can be observed. It is therefore interesting to show whether machine learning model is vulnerable in this setting.

Furthermore, existing gradient-based attacks cannot be applied to some non-continuous machine learning models which involve discrete decisions. For example, the robustness of decision-tree based models (random forest and gradient boosting decision trees (GBDT)) cannot be evaluated using gradient-based approaches, since the gradient of these functions does not exist.

In this paper, we develop an optimization-based framework for attacking machine learning models in a more realistic and general “hard-label black-box” setting. We assume that the model is not revealed and the attacker can only make queries to get the corresponding hard-label decision instead of the probability outputs (also known as soft labels). Attacking in this setting is very challenging and almost all the previous attacks fail due to the following two reasons. First, the gradient cannot be computed directly by backpropagation, and finite differences based approaches also fail because the hard-label output is insensitive to small input perturbations; second, since only hard-label decision is observed, the attack objective functions become discontinuous with discrete outputs, which is combinatorial in nature and hard to optimize (see Section 2.4 for more details).

In this paper, we make hard-label black-box attacks possible and query-efficient by reformulating the attack as a novel real-valued optimization problem, which is usually continuous and much easier to solve. Although the objective function of this reformulation cannot be written in an analytical form, we show how to use model queries to evaluate its function value and apply any zeroth order optimization algorithm to solve it. Furthermore, we prove that by carefully controlling the numerical accuracy of function evaluations, a Random Gradient-Free (RGF) method can convergence to stationary points as long as the boundary is smooth. We note that this is the first attack with a guaranteed convergence rate in the hard-label black-box setting. In the experiments, we show our algorithm can be successfully used to attack hard-label black-box CNN models on MNIST, CIFAR, and ImageNet with far less number of queries compared to the state-of-art algorithm.

Moreover, since our algorithm does not depend on the gradient of the classifier, we can apply our approach to other non-differentiable classifiers besides neural networks. We show an interesting application in attacking Gradient Boosting Decision Tree, which cannot be attacked by all the existing gradient-based methods even in the white-box setting. Our method can successfully find adversarial examples with imperceptible perturbations for a GBDT within 30,000 queries.

Background and Related work

We will first introduce our problem setting and give a brief literature review to hightlight the difficulty of attacking hard-label black-box models.

2 White-box attacks

where y0y_{0} is the original label predicted by the classifier. For targeted attack, where the goal is to turn it into a specific target class tt, the loss function can also be defined accordingly.

Therefore, attacking a machine learning model can be posed as solving this optimization problem , which is also known as the C&W attack or the EAD attack depending on the choice of the distance measurement. To solve (2), one can apply any gradient-based optimization algorithm such as SGD or Adam, since the gradient of L(Z(x))\mathscr{L}(Z({\boldsymbol{x}})) can be computed via back-propagation.

3 Previous work on black-box attack

In real-world systems, usually the underlying machine learning model will not be revealed and thus white-box attacks cannot be applied. This motivates the study of attacking machine learning models in the black-box setting, where attackers do not have any information about the function ff. And the only valid operation is to make queries to the model and get the corresponding output f(x)f({\boldsymbol{x}}). The first approach for black-box attack is using transfer attack —instead of attacking the original model ff, attackers try to construct a substitute model f^\hat{f} to mimic ff and then attack f^\hat{f} using white-box attack methods. This approach has been well studied and analyzed in . However, recent papers have shown that attacking the substitute model usually leads to much larger distortion and low success rate . Therefore, instead, considers the score-based black-box setting, where attackers can use x{\boldsymbol{x}} to query the softmax layer output in addition to the final classification result. In this case, they can reconstruct the loss function (3) and evaluate it as long as the objective function h(x)h({\boldsymbol{x}}) exists for any x{\boldsymbol{x}}. Thus a zeroth order optimization approach can be directly applied to minimize h(x)h({\boldsymbol{x}}). further improves the query complexity of by introducing two novel building blocks: (i) an adaptive random gradient estimation algorithm that balances query counts and distortion, and (ii) a well-trained autoencoder that achieves attack acceleration. also solves a score-based attack problem using an evolutionary algorithm and it shows their method could be applied to hard-label black-box setting as well.

4 Difficulty of hard-label black-box attacks

Throughout this paper, the hard-label black-box setting refers to cases where real-world ML systems only provide limited prediction results of an input query. Specifically, only the final decision (top-1 predicted label) instead of probability outputs is known to an attacker.

Attacking in this setting is very challenging. In Figure 1a, we show a simple 3-layer neural network’s decision boundary. Note that the L(Z(x))\mathscr{L}(Z({\boldsymbol{x}})) term is continuous as in Figure 1b because the logit layer output is real-valued functions. However, in the hard-label black-box setting, only f(⋅)f(\cdot) is available instead of Z(⋅)Z(\cdot). Since f(⋅)f(\cdot) can only be one-hot vector, if we plug-in ff into the loss function, L(f(x))\mathscr{L}(f({\boldsymbol{x}})) (as shown in Figure 1c) will be discontinuous and with discrete outputs.

Optimizing this function will require combinatorial optimization or search algorithms, which is almost impossible to do given high dimensionality of the problem. Therefore, almost no algorithm can successfully conduct hard-label black-box attack in the literature. The only current approach is based on random-walk on the boundary. Although this decision-based attack can find adversarial examples with comparable distortion with white-box attacks, it suffers from exponential search time, resulting in lots of queries, and lacks convergence guarantees. We show that our optimization-based algorithm can significantly reduce the number of queries compared with decision-based attack, and has guaranteed convergence in the number of iterations (queries).

Algorithms

Now we will introduce a novel way to re-formulate hard-label black-box attack as another optimization problem, show how to evaluate the function value using hard-label queries, and then apply a zeroth order optimization algorithm to solve it.

In this formulation, θ{\boldsymbol{\theta}} represents the search direction and g(θ)g({\boldsymbol{\theta}}) is the distance from x0{\boldsymbol{x}}_{0} to the nearest adversarial example along the direction θ{\boldsymbol{\theta}}. The difference between (4) and (5) corresponds to the different definitions of “successfulness” in untargeted and targeted attack, where the former one aims to turn the prediction into any incorrect label and the later one aims to turn the prediction into the target label. For untargeted attack, g(θ)g({\boldsymbol{\theta}}) also corresponds to the distance to the decision boundary along the direction θ{\boldsymbol{\theta}}. In image problems the input domain of ff is bounded, so we will add corresponding upper/lower bounds in the definition of (4) and (5).

Instead of searching for an adversarial example, we search the direction θ{\boldsymbol{\theta}} to minimize the distortion g(θ)g({\boldsymbol{\theta}}), which leads to the following optimization problem:

Finally, the adversarial example can be found by x∗=x0+g(θ∗)θ∗∥θ∗∥{\boldsymbol{x}}^{*}={\boldsymbol{x}}_{0}+g({\boldsymbol{\theta}}^{*})\frac{{\boldsymbol{\theta}}^{*}}{\|{\boldsymbol{\theta}}^{*}\|}, where θ∗{\boldsymbol{\theta}}^{*} is the optimal solution of (6).

Note that unlike the C&W or PGD objective functions, which are discontinuous step functions in the hard-label setting (see Section 2), g(θ)g({\boldsymbol{\theta}}) maps input direction to real-valued output (distance to decision boundary), which is usually continuous—a small change of θ{\boldsymbol{\theta}} usually leads to a small change of g(θ)g({\boldsymbol{\theta}}), as can be seen from Figure 2.

Moreover, we give three examples of f(x)f({\boldsymbol{x}}) defined in two dimension input space and their corresponding g(θ)g({\boldsymbol{\theta}}). In Figure 3a, we have a continuous classification function defined as follows

In this case, as shown in Figure 3c, g(θ)g({\boldsymbol{\theta}}) is continuous. Moreover, in Figure 3b and Figure 1a, we show decision boundaries generated by GBDT and neural network classifier, which are not continuous. However, as showed in Figure 3d and Figure 1d, even if the classifier function is not continuous, g(θ)g({\boldsymbol{\theta}}) is still continuous. This makes it easy to apply zeroth order method to solve (6).

Compute g(θ)g({\boldsymbol{\theta}}) up to certain accuracy. We are not able to evaluate the gradient of gg, but we can evaluate the function value of gg using the hard-label queries to the original function ff. For simplicity, we focus on untargeted attack here, but the same procedure can be applied to targeted attack as well.

First, we discuss how to compute g(θ)g({\boldsymbol{\theta}}) directly without additional information. This is used in the initialization step of our algorithm. For a given normalized θ{\boldsymbol{\theta}}, we do a fine-grained search and then a binary search. In fine-grained search, we query the points {x0+αθ,x0+2αθ,… }\{{\boldsymbol{x}}_{0}+\alpha{\boldsymbol{\theta}},{\boldsymbol{x}}_{0}+2\alpha{\boldsymbol{\theta}},\dots\} one by one until we find f(x+iαθ)≠y0f({\boldsymbol{x}}+i\alpha{\boldsymbol{\theta}})\neq y_{0}. This means the boundary goes between [x0+(i−1)αθ,x0+iαθ][{\boldsymbol{x}}_{0}+(i-1)\alpha{\boldsymbol{\theta}},{\boldsymbol{x}}_{0}+i\alpha{\boldsymbol{\theta}}]. We then enter the second phase and conduct a binary search to find the solution within this region (same with line 11–17 in Algorithm 1). Note that there is an upper bound of the first stage if we choose θ{\boldsymbol{\theta}} by the direction of x−x0{\boldsymbol{x}}-{\boldsymbol{x}}_{0} with some x{\boldsymbol{x}} from another class. This procedure is used to find the initial θ0{\boldsymbol{\theta}}_{0} and corresponding g(θ0)g({\boldsymbol{\theta}}_{0}) in our optimization algorithm. We omit the detailed algorithm for this part since it is similar to Algorithm 1.

Next, we discuss how to compute g(θ)g({\boldsymbol{\theta}}) when we know the solution is very close to a value vv. This is used in all the function evaluations in our optimization algorithm, since the current solution is usually close to the previous solution, and when we estimate the gradient using (7), the queried direction will only be a small perturbation of the previous one. In this case, we first increase or decrease vv in local region to find the interval that contains boundary (e.g, f(v)=y0f(v)=y_{0} and f(v′)≠y0f(v^{\prime})\neq y_{0}), then conduct a binary search to find the final value of gg. Our procedure for computing gg value is presented in Algorithm 1.

2 Zeroth Order Optimization

To solve the optimization problem (1) for which we can only evaluate function value instead of gradient, zeroth order optimization algorithms can be naturally applied. In fact, after the reformulation, the problem can be potentially solved by any zeroth order optimization algorithm, like zeroth order gradient descent or coordinate descent (see for a comprehensive survey).

Here we propose to solve (1) using Randomized Gradient-Free (RGF) method proposed in . In practice we found it outperforms zeroth-order coordinate descent. In each iteration, the gradient is estimated by

where u{\boldsymbol{u}} is a random Gaussian vector, and β>0\beta>0 is a smoothing parameter (we set β=0.005\beta=0.005 in all our experiments). The solution is then updated by θ←θ−ηg^{\boldsymbol{\theta}}\leftarrow{\boldsymbol{\theta}}-\eta\hat{{\boldsymbol{g}}} with a step size η\eta. The procedure is summarized in Algorithm 2.

There are several implementation details when we apply this algorithm. First, for high-dimensional problems, we found the estimation in (7) is very noisy. Therefore, instead of using one vector, we sample qq vectors from Gaussian distribution and average their estimators to get g^\hat{{\boldsymbol{g}}}. We set q=20q=20 in all the experiments. The convergence proofs can be naturally extended to this case. Second, instead of using a fixed step size (suggested in theory), we use a backtracking line-search approach to find step size at each step. This leads to additional query counts, but makes the algorithm more stable and eliminates the need to hand-tuning the step size.

3 Theoretical Analysis

If g(θ)g({\boldsymbol{\theta}}) can be computed exactly, it has been proved in that RGF in Algorithm 2 requires at most O(dδ2)O(\frac{d}{\delta^{2}}) iterations to converge to a point with ∥∇g(θ)∥2≤δ2\|\nabla g({\boldsymbol{\theta}})\|^{2}\leq\delta^{2}. However, in our algorithm the function value g(θ)g({\boldsymbol{\theta}}) cannot be computed exactly; instead, we compute it up to ϵ\epsilon-precision, and this precision can be controlled by binary threshold in Algorithm 1. We thus extend the proof in to include the case of approximate function value evaluation, as described in the following theorem.

In Algorithm 2, suppose g has Lipschitz-continuous gradient with constant L1(g)L_{1}(g). If the error of function value evaluation is controlled by ϵ∼O(βδ2)\epsilon\sim O(\beta\delta^{2}) and β≤O(δdL1(g))\beta\leq O(\frac{\delta}{dL_{1}(g)}), then in order to obtain 1N+1∑k=0NEUk(∥∇g(θk)∥2)≤δ2\frac{1}{N+1}\sum\limits_{k=0}^{N}E_{\mathscr{U}_{k}}(\|\nabla g({\boldsymbol{\theta}}_{k})\|^{2})\leq\delta^{2}, the total number of iterations is at most O(dδ2)O(\frac{d}{\delta^{2}}).

Detailed proofs can be found in the appendix. Note that the binary search procedure could obtain the desired function value precision in O(log⁡δ)O(\log\delta) steps. By using the same idea with Theorem 1 and following the proof in , we could also achieve O(d2δ3)O(\frac{d^{2}}{\delta^{3}}) complexity when g(θ)g({\boldsymbol{\theta}}) is non-smooth but Lipschitz continuous.

Experimental results

We test the performance of our hard-label black-box attack algorithm on convolutional neural network (CNN) models and compare with decision-based attack . Furthermore, we show our method can be applied to attack Gradient Boosting Decision Tree (GBDT) and present some interesting findings.

We use three standard datasets: MNIST , CIFAR-10 and ImageNet-1000 . To have a fair comparison with previous work, we adopt the same networks used in both and . In detail, both MNIST and CIFAR use the same network structure with four convolution layers, two max-pooling layers and two fully-connected layers. Using the parameters provided by , we could achieve 99.5% accuracy on MNIST and 82.5% accuracy on CIFAR-10, which is similar to what was reported in . For Imagenet-1000, we use the pretrained network Resnet-50 provided by torchvisionhttps://github.com/pytorch/vision/tree/master/torchvision, which could achieve 76.15% top-1 accuracy. All models are trained using Pytorch and our source code is publicly availablehttps://github.com/LeMinhThong/blackbox-attack.

We include the following algorithms into comparison:

Opt-based black-box attack (Opt-attack): our proposed algorithm.

Decision-based black-box attack (Decision-attack): the only previous work on attacking hard-label black box model. We use the authors’ implementation and use default parameters provided in Foolboxhttps://github.com/bethgelab/foolbox.

C&W white-box attack : one of the current state-of-the-art attacking algorithm in the white-box setting. We do binary search on parameter cc per image to achieve the best performance. Attacking in the white-box setting is a much easier problem, so we include C&W attack just for reference and indicate the best performance we can possibly achieve.

For all the cases, we conduct adversarial attacks for randomly sampled N=100N=100 images from validation sets. Note that all three attacks have 100% successful rate, and we report the average L2L_{2} distortion, defined by 1N∑i=1N∥x(i)−x0(i)∥2\frac{1}{N}\sum_{i=1}^{N}\|{\boldsymbol{x}}^{(i)}-{\boldsymbol{x}}_{0}^{(i)}\|_{2}, where x(i){\boldsymbol{x}}^{(i)} is the adversarial example constructed by an attack algorithm and x0(i){\boldsymbol{x}}_{0}^{(i)} is the original ii-th example. For black-box attack algorithms, we also report average number of queries for comparison.

For untargeted attack, the goal is to turn a correctly classified image into any other label. The results are presented in Table 1. Note that for both Opt-attack and Decision-attack, by changing stopping conditions we can get the performance with different number of queries.

First, we compare two black-box attack methods in Table 1. Our algorithm consistently achieves smaller distortion with less number of queries than Decision-attack. For example, on MNIST data, we are able to reduce the number of queries by 3-4 folds, and Decision-attack converges to worse solutions in all the 3 datasets. Compared with C&W attack, we found black-box attacks attain slightly worse distortion on MNIST and CIFAR.

This is reasonable because white-box attack has much more information than black-box attack and is strictly easier. We note that the experiments in conclude that C&W and Decision-attack have similar performance because they only run C&W with a single regularization parameter cc without doing binary search to obtain the optimal parameter. For ImageNet, since we constraint the number of queries, the distortion of black-box attacks is much worse than C&W attack. The gap can be reduced by increasing the number of queries as showed in Figure 4.

1.2 Targeted attack

The results for targeted attack is presented in Table 2. Following the experiments in , for each randomly sampled image with label ii we set target label t=(i+1) module 10t=(i+1)\ \text{module}\ 10. On MNIST data, we found our algorithm is more than 4 times faster (in terms of number of queries) than Decision-attack and converge to a better solution. On CIFAR data, our algorithm has similar efficiency with Decision-attack at the first 60,000 queries, but converges to a slightly worse solution. Also, we show a example quality comparison from the same starting point to the original sample in Figure 5.

1.3 Attack Gradient Boosting Decision Tree (GBDT)

To evaluate our method’s ability to attack models with discrete decision functions, we conduct our untargeted attack on gradient booting decision tree (GBDT). In this experiment, we use two standard datasets: HIGGS for binary classification and MNIST for multi-class classification. We use popular LightGBMhttps://github.com/Microsoft/LightGBM framework to train the GBDT models. Using suggested parametershttps://github.com/Koziev/MNIST_Boosting, we could achieve 0.8457 AUC for HIGGS and 98.09% accuracy for MNIST. The results of untargeted attack on GBDT are in Table 3.

As shown in Table 3, by using around 30K queries, we could get a small distortion on both datasets, which firstly uncovers the vulnerability of GBDT models. Tree-based methods are well-known for its good interpretability. And because of that, they are widely used in the industry. However, we show that even with good interpretability and a similar prediction accuracy with convolution neural network, the GBDT models are vulnerable under our Opt-attack. This result raises a question about tree-based models’ robustness, which will be an interesting direction in the future.

Conclusion

In this paper, we propose a generic and optimization-based hard-label black-box attack algorithm, which can be applied to discrete and non-continuous models other than neural networks, such as the gradient boosting decision tree. Our method enjoys query-efficiency and has a theoretical convergence guarantee on the attack performance. Moreover, our attack achieves smaller or similar distortion using 3-4 times less queries compared with the state-of-the-art algorithm.

References

Appendix

Following , we define the Guassian smoothing approximation over g(θ)g(\theta), i.e,

Also, we have the upper bounds for the moments Mp=1κ∫E∣∣u∣∣pe−12∣∣u∣∣2duM_{p}=\frac{1}{\kappa}\int_{E}||u||^{p}e^{-\frac{1}{2}||u||^{2}}du from Lemma 1.

Suppose gg has a lipschitz-continuous gradient with constant L1(g)L_{1}(g), then

We could bound Eu(∣∣g^(θ)∣∣2)E_{u}(||\hat{g}({\boldsymbol{\theta}})||^{2}) as follows. Since

and ∣ϵθ+βu−ϵθ∣≤2ϵ|\epsilon_{{\boldsymbol{\theta}}+\beta u}-\epsilon_{{\boldsymbol{\theta}}}|\leq 2\epsilon,

Take expectation over u, and with Theorem 3 in , which is Eu(∣∣g′(θ,u)⋅u∣∣2)≤(d+4)∣∣∇g(x)∣∣2E_{u}(||g^{\prime}({\boldsymbol{\theta}},u)\cdot u||^{2})\leq(d+4)||\nabla g(x)||^{2},

Therefore, since (n+6)3+2(n+4)3≤3(n+5)3(n+6)^{3}+2(n+4)^{3}\leq 3(n+5)^{3}, we could get

Therefore, since gβ(θ)g_{\beta}({\boldsymbol{\theta}}) has Lipshcitz-continuous gradient:

Choosing αk=α^=14(d+4)L1(f)\alpha_{k}=\hat{\alpha}=\frac{1}{4(d+4)L_{1}(f)}, we obtain

Since (d+5)3≤(d+8)(d+4)2(d+5)^{3}\leq(d+8)(d+4)^{2}, taking expectation over Uk\mathscr{U}_{k}, where Uk={u1,u2,…,uk}\mathscr{U}_{k}=\{u_{1},u_{2},\dots,u_{k}\}, we get

where ϕk=EUk−1(g(θk)),k≥1\phi_{k}=E_{\mathscr{U}_{k-1}(g({\boldsymbol{\theta}}_{k}))},k\geq 1 and ϕ0=g(θ0)\phi_{0}=g({\boldsymbol{\theta}}_{0}).

Assuming g(x)≥g∗g(x)\geq g^{*}, summing over k and divided by N+1, we get

Clearly, 1N+1∑k=0NEUk(∣∣∇gβ(θk)∣∣)≤δ2\frac{1}{N+1}\sum\limits_{k=0}^{N}E_{\mathscr{U}_{k}}(||\nabla g_{\beta}({\boldsymbol{\theta}}_{k})||)\leq\delta^{2}.

Since ϑk2=EUk(∣∣∇g(θk)∣∣2)≤2EUk(∣∣∇gβ(θk)∣∣2)+β2(d+4)22L12(g)\vartheta_{k}^{2}=E_{\mathscr{U}_{k}}(||\nabla g({\boldsymbol{\theta}}_{k})||^{2})\leq 2E_{\mathscr{U}_{k}}(||\nabla g_{\beta}({\boldsymbol{\theta}}_{k})||^{2})+\frac{\beta^{2}(d+4)^{2}}{2}L_{1}^{2}(g), ϑk2\vartheta_{k}^{2} is in the same order oasEUk(∣∣∇gβ(θk)∣∣2)E_{\mathscr{U}_{k}}(||\nabla g_{\beta}({\boldsymbol{\theta}}_{k})||^{2}). In order to satisfy 1N+1∑k=0Nϑk2≤δ2\frac{1}{N+1}\sum\limits_{k=0}^{N}\vartheta_{k}^{2}\leq\delta^{2}, we need to choose β≤O(δdL1(g))\beta\leq O(\frac{\delta}{dL_{1}(g)}), then N is bounded by O(dδ2)O(\frac{d}{\delta^{2}}).