-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathhop_skip_jump.py
695 lines (589 loc) · 26.5 KB
/
hop_skip_jump.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
# MIT License
#
# Copyright (C) The Adversarial Robustness Toolbox (ART) Authors 2019
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
# documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
# persons to whom the Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
# Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
"""
This module implements the HopSkipJump attack `HopSkipJump`. This is a black-box attack that only requires class
predictions. It is an advanced version of the Boundary attack.
| Paper link: https://arxiv.org/abs/1904.02144
"""
from __future__ import absolute_import, division, print_function, unicode_literals, annotations
import logging
from typing import TYPE_CHECKING
import numpy as np
from tqdm.auto import tqdm
from art.config import ART_NUMPY_DTYPE
from art.attacks.attack import EvasionAttack
from art.estimators.estimator import BaseEstimator
from art.estimators.classification import ClassifierMixin
from art.utils import compute_success, to_categorical, check_and_transform_label_format, get_labels_np_array
if TYPE_CHECKING:
from art.utils import CLASSIFIER_TYPE
logger = logging.getLogger(__name__)
class HopSkipJump(EvasionAttack):
"""
Implementation of the HopSkipJump attack from Jianbo et al. (2019). This is a powerful black-box attack that
only requires final class prediction, and is an advanced version of the boundary attack.
| Paper link: https://arxiv.org/abs/1904.02144
"""
attack_params = EvasionAttack.attack_params + [
"targeted",
"norm",
"max_iter",
"max_eval",
"init_eval",
"init_size",
"curr_iter",
"batch_size",
"verbose",
]
_estimator_requirements = (BaseEstimator, ClassifierMixin)
def __init__(
self,
classifier: "CLASSIFIER_TYPE",
batch_size: int = 64,
targeted: bool = False,
norm: int | float | str = 2,
max_iter: int = 50,
max_eval: int = 10000,
init_eval: int = 100,
init_size: int = 100,
verbose: bool = True,
) -> None:
"""
Create a HopSkipJump attack instance.
:param classifier: A trained classifier.
:param batch_size: The size of the batch used by the estimator during inference.
:param targeted: Should the attack target one specific class.
:param norm: Order of the norm. Possible values: "inf", np.inf or 2.
:param max_iter: Maximum number of iterations.
:param max_eval: Maximum number of evaluations for estimating gradient.
:param init_eval: Initial number of evaluations for estimating gradient.
:param init_size: Maximum number of trials for initial generation of adversarial examples.
:param verbose: Show progress bars.
"""
super().__init__(estimator=classifier)
self._targeted = targeted
self.norm = norm
self.max_iter = max_iter
self.max_eval = max_eval
self.init_eval = init_eval
self.init_size = init_size
self.curr_iter = 0
self.batch_size = batch_size
self.verbose = verbose
self._check_params()
self.curr_iter = 0
# Set binary search threshold
if norm == 2:
self.theta = 0.01 / np.sqrt(np.prod(self.estimator.input_shape))
else:
self.theta = 0.01 / np.prod(self.estimator.input_shape)
def generate(self, x: np.ndarray, y: np.ndarray | None = None, **kwargs) -> np.ndarray:
"""
Generate adversarial samples and return them in an array.
:param x: An array with the original inputs to be attacked.
:param y: Target values (class labels) one-hot-encoded of shape `(nb_samples, nb_classes)` or indices of shape
(nb_samples,).
:param mask: An array with a mask broadcastable to input `x` defining where to apply adversarial perturbations.
Shape needs to be broadcastable to the shape of x and can also be of the same shape as `x`. Any
features for which the mask is zero will not be adversarially perturbed.
:type mask: `np.ndarray`
:param x_adv_init: Initial array to act as initial adversarial examples. Same shape as `x`.
:type x_adv_init: `np.ndarray`
:param resume: Allow users to continue their previous attack.
:type resume: `bool`
:return: An array holding the adversarial examples.
"""
mask = kwargs.get("mask")
if y is None:
# Throw error if attack is targeted, but no targets are provided
if self.targeted: # pragma: no cover
raise ValueError("Target labels `y` need to be provided for a targeted attack.")
# Use model predictions as correct outputs
y = get_labels_np_array(self.estimator.predict(x, batch_size=self.batch_size)) # type: ignore
y = check_and_transform_label_format(y, nb_classes=self.estimator.nb_classes)
if self.estimator.nb_classes == 2 and y.shape[1] == 1: # pragma: no cover
raise ValueError(
"This attack has not yet been tested for binary classification with a single output classifier."
)
# Check whether users need a stateful attack
resume = kwargs.get("resume")
if resume is not None and resume:
start = self.curr_iter
else:
start = 0
# Check the mask
if mask is not None:
if len(mask.shape) == len(x.shape):
mask = mask.astype(ART_NUMPY_DTYPE)
else:
mask = np.array([mask.astype(ART_NUMPY_DTYPE)] * x.shape[0])
else:
mask = np.array([None] * x.shape[0])
# Get clip_min and clip_max from the classifier or infer them from data
if self.estimator.clip_values is not None:
clip_min, clip_max = self.estimator.clip_values
else:
clip_min, clip_max = np.min(x), np.max(x)
# Prediction from the original images
preds = np.argmax(self.estimator.predict(x, batch_size=self.batch_size), axis=1)
# Prediction from the initial adversarial examples if not None
x_adv_init = kwargs.get("x_adv_init")
if x_adv_init is not None:
# Add mask param to the x_adv_init
for i in range(x.shape[0]):
if mask[i] is not None:
x_adv_init[i] = x_adv_init[i] * mask[i] + x[i] * (1 - mask[i])
# Do prediction on the init
init_preds = np.argmax(self.estimator.predict(x_adv_init, batch_size=self.batch_size), axis=1)
else:
init_preds = [None] * len(x)
x_adv_init = [None] * len(x)
# Assert that, if attack is targeted, y is provided
if self.targeted and y is None: # pragma: no cover
raise ValueError("Target labels `y` need to be provided for a targeted attack.")
# Some initial setups
x_adv = x.astype(ART_NUMPY_DTYPE)
y = np.argmax(y, axis=1)
# Generate the adversarial samples
for ind, val in enumerate(tqdm(x_adv, desc="HopSkipJump", disable=not self.verbose)):
self.curr_iter = start
if self.targeted:
x_adv[ind] = self._perturb(
x=val,
y=y[ind], # type: ignore
y_p=preds[ind],
init_pred=init_preds[ind],
adv_init=x_adv_init[ind],
mask=mask[ind],
clip_min=clip_min,
clip_max=clip_max,
)
else:
x_adv[ind] = self._perturb(
x=val,
y=-1,
y_p=preds[ind],
init_pred=init_preds[ind],
adv_init=x_adv_init[ind],
mask=mask[ind],
clip_min=clip_min,
clip_max=clip_max,
)
y = to_categorical(y, self.estimator.nb_classes) # type: ignore
logger.info(
"Success rate of HopSkipJump attack: %.2f%%",
100 * compute_success(self.estimator, x, y, x_adv, self.targeted, batch_size=self.batch_size),
)
return x_adv
def _perturb(
self,
x: np.ndarray,
y: int,
y_p: int,
init_pred: int,
adv_init: np.ndarray,
mask: np.ndarray | None,
clip_min: float,
clip_max: float,
) -> np.ndarray:
"""
Internal attack function for one example.
:param x: An array with one original input to be attacked.
:param y: If `self.targeted` is true, then `y` represents the target label.
:param y_p: The predicted label of x.
:param init_pred: The predicted label of the initial image.
:param adv_init: Initial array to act as an initial adversarial example.
:param mask: An array with a mask to be applied to the adversarial perturbations. Shape needs to be
broadcastable to the shape of x. Any features for which the mask is zero will not be adversarially
perturbed.
:param clip_min: Minimum value of an example.
:param clip_max: Maximum value of an example.
:return: An adversarial example.
"""
# First, create an initial adversarial sample
initial_sample = self._init_sample(x, y, y_p, init_pred, adv_init, mask, clip_min, clip_max)
# If an initial adversarial example is not found, then return the original image
if initial_sample is None:
return x
# If an initial adversarial example found, then go with HopSkipJump attack
x_adv = self._attack(initial_sample[0], x, initial_sample[1], mask, clip_min, clip_max)
return x_adv
def _init_sample(
self,
x: np.ndarray,
y: int,
y_p: int,
init_pred: int,
adv_init: np.ndarray,
mask: np.ndarray | None,
clip_min: float,
clip_max: float,
) -> np.ndarray | tuple[np.ndarray, int] | None:
"""
Find initial adversarial example for the attack.
:param x: An array with 1 original input to be attacked.
:param y: If `self.targeted` is true, then `y` represents the target label.
:param y_p: The predicted label of x.
:param init_pred: The predicted label of the initial image.
:param adv_init: Initial array to act as an initial adversarial example.
:param mask: An array with a mask to be applied to the adversarial perturbations. Shape needs to be
broadcastable to the shape of x. Any features for which the mask is zero will not be adversarially
perturbed.
:param clip_min: Minimum value of an example.
:param clip_max: Maximum value of an example.
:return: An adversarial example.
"""
nprd = np.random.RandomState()
initial_sample = None
if self.targeted:
# Attack satisfied
if y == y_p:
return None
# Attack unsatisfied yet and the initial image satisfied
if adv_init is not None and init_pred == y:
return adv_init.astype(ART_NUMPY_DTYPE), init_pred
# Attack unsatisfied yet and the initial image unsatisfied
for _ in range(self.init_size):
random_img = nprd.uniform(clip_min, clip_max, size=x.shape).astype(x.dtype)
if mask is not None:
random_img = random_img * mask + x * (1 - mask)
random_class = np.argmax(
self.estimator.predict(np.array([random_img]), batch_size=self.batch_size),
axis=1,
)[0]
if random_class == y:
# Binary search to reduce the l2 distance to the original image
random_img = self._binary_search(
current_sample=random_img,
original_sample=x,
target=y,
norm=2,
clip_min=clip_min,
clip_max=clip_max,
threshold=0.001,
)
initial_sample = random_img, random_class
logger.info("Found initial adversarial image for targeted attack.")
break
else:
logger.warning("Failed to draw a random image that is adversarial, attack failed.")
else:
# The initial image satisfied
if adv_init is not None and init_pred != y_p:
return adv_init.astype(ART_NUMPY_DTYPE), y_p
# The initial image unsatisfied
for _ in range(self.init_size):
random_img = nprd.uniform(clip_min, clip_max, size=x.shape).astype(x.dtype)
if mask is not None:
random_img = random_img * mask + x * (1 - mask)
random_class = np.argmax(
self.estimator.predict(np.array([random_img]), batch_size=self.batch_size),
axis=1,
)[0]
if random_class != y_p:
# Binary search to reduce the l2 distance to the original image
random_img = self._binary_search(
current_sample=random_img,
original_sample=x,
target=y_p,
norm=2,
clip_min=clip_min,
clip_max=clip_max,
threshold=0.001,
)
initial_sample = random_img, y_p
logger.info("Found initial adversarial image for untargeted attack.")
break
else:
logger.warning("Failed to draw a random image that is adversarial, attack failed.")
return initial_sample
def _attack(
self,
initial_sample: np.ndarray,
original_sample: np.ndarray,
target: int,
mask: np.ndarray | None,
clip_min: float,
clip_max: float,
) -> np.ndarray:
"""
Main function for the boundary attack.
:param initial_sample: An initial adversarial example.
:param original_sample: The original input.
:param target: The target label.
:param mask: An array with a mask to be applied to the adversarial perturbations. Shape needs to be
broadcastable to the shape of x. Any features for which the mask is zero will not be adversarially
perturbed.
:param clip_min: Minimum value of an example.
:param clip_max: Maximum value of an example.
:return: an adversarial example.
"""
# Set current perturbed image to the initial image
current_sample = initial_sample
# Main loop to wander around the boundary
for _ in range(self.max_iter):
# First compute delta
delta = self._compute_delta(
current_sample=current_sample,
original_sample=original_sample,
clip_min=clip_min,
clip_max=clip_max,
)
# Then run binary search
current_sample = self._binary_search(
current_sample=current_sample,
original_sample=original_sample,
norm=self.norm,
target=target,
clip_min=clip_min,
clip_max=clip_max,
)
# Next compute the number of evaluations and compute the update
num_eval = min(int(self.init_eval * np.sqrt(self.curr_iter + 1)), self.max_eval)
update = self._compute_update(
current_sample=current_sample,
num_eval=num_eval,
delta=delta,
target=target,
mask=mask,
clip_min=clip_min,
clip_max=clip_max,
)
# Finally run step size search by first computing epsilon
if self.norm == 2:
dist = np.linalg.norm(original_sample - current_sample)
else:
dist = np.max(abs(original_sample - current_sample))
epsilon = 2.0 * dist / np.sqrt(self.curr_iter + 1)
success = False
while not success:
epsilon /= 2.0
potential_sample = current_sample + epsilon * update
success = self._adversarial_satisfactory( # type: ignore
samples=potential_sample[None],
target=target,
clip_min=clip_min,
clip_max=clip_max,
)
# Update current sample
current_sample = np.clip(potential_sample, clip_min, clip_max)
# Update current iteration
self.curr_iter += 1
# If attack failed. return original sample
if np.isnan(current_sample).any(): # pragma: no cover
logger.debug("NaN detected in sample, returning original sample.")
return original_sample
return current_sample
def _binary_search(
self,
current_sample: np.ndarray,
original_sample: np.ndarray,
target: int,
norm: int | float | str,
clip_min: float,
clip_max: float,
threshold: float | None = None,
) -> np.ndarray:
"""
Binary search to approach the boundary.
:param current_sample: Current adversarial example.
:param original_sample: The original input.
:param target: The target label.
:param norm: Order of the norm. Possible values: "inf", np.inf or 2.
:param clip_min: Minimum value of an example.
:param clip_max: Maximum value of an example.
:param threshold: The upper threshold in binary search.
:return: an adversarial example.
"""
# First set upper and lower bounds as well as the threshold for the binary search
if norm == 2:
(upper_bound, lower_bound) = (np.array(1.0), np.array(0.0))
if threshold is None:
threshold = self.theta
else:
(upper_bound, lower_bound) = (
np.max(abs(original_sample - current_sample)),
np.array(0.0),
)
if threshold is None:
threshold = np.minimum(upper_bound * self.theta, self.theta)
# Then start the binary search
while (upper_bound - lower_bound) > threshold:
# Interpolation point
alpha = (upper_bound + lower_bound) / 2.0
interpolated_sample = self._interpolate(
current_sample=current_sample,
original_sample=original_sample,
alpha=alpha,
norm=norm,
)
# Update upper_bound and lower_bound
satisfied = self._adversarial_satisfactory(
samples=interpolated_sample[None],
target=target,
clip_min=clip_min,
clip_max=clip_max,
)[0]
lower_bound = np.where(satisfied == 0, alpha, lower_bound)
upper_bound = np.where(satisfied == 1, alpha, upper_bound)
result = self._interpolate(
current_sample=current_sample,
original_sample=original_sample,
alpha=float(upper_bound),
norm=norm,
)
return result
def _compute_delta(
self,
current_sample: np.ndarray,
original_sample: np.ndarray,
clip_min: float,
clip_max: float,
) -> float:
"""
Compute the delta parameter.
:param current_sample: Current adversarial example.
:param original_sample: The original input.
:param clip_min: Minimum value of an example.
:param clip_max: Maximum value of an example.
:return: Delta value.
"""
# Note: This is a bit different from the original paper, instead we keep those that are
# implemented in the original source code of the authors
if self.curr_iter == 0:
return 0.1 * (clip_max - clip_min)
if self.norm == 2:
dist = np.linalg.norm(original_sample - current_sample)
delta = np.sqrt(np.prod(self.estimator.input_shape)) * self.theta * dist
else:
dist = np.max(abs(original_sample - current_sample))
delta = np.prod(self.estimator.input_shape) * self.theta * dist
return delta
def _compute_update(
self,
current_sample: np.ndarray,
num_eval: int,
delta: float,
target: int,
mask: np.ndarray | None,
clip_min: float,
clip_max: float,
) -> np.ndarray:
"""
Compute the update in Eq.(14).
:param current_sample: Current adversarial example.
:param num_eval: The number of evaluations for estimating gradient.
:param delta: The size of random perturbation.
:param target: The target label.
:param mask: An array with a mask to be applied to the adversarial perturbations. Shape needs to be
broadcastable to the shape of x. Any features for which the mask is zero will not be adversarially
perturbed.
:param clip_min: Minimum value of an example.
:param clip_max: Maximum value of an example.
:return: an updated perturbation.
"""
# Generate random noise
rnd_noise_shape = [num_eval] + list(self.estimator.input_shape)
if self.norm == 2:
rnd_noise = np.random.randn(*rnd_noise_shape).astype(ART_NUMPY_DTYPE)
else:
rnd_noise = np.random.uniform(low=-1, high=1, size=rnd_noise_shape).astype(ART_NUMPY_DTYPE)
# With mask
if mask is not None:
rnd_noise = rnd_noise * mask
# Normalize random noise to fit into the range of input data
rnd_noise = rnd_noise / np.sqrt(
np.sum(
rnd_noise**2,
axis=tuple(range(len(rnd_noise_shape)))[1:],
keepdims=True,
)
)
eval_samples = np.clip(current_sample + delta * rnd_noise, clip_min, clip_max)
rnd_noise = (eval_samples - current_sample) / delta
# Compute gradient: This is a bit different from the original paper, instead we keep those that are
# implemented in the original source code of the authors
satisfied = self._adversarial_satisfactory(
samples=eval_samples, target=target, clip_min=clip_min, clip_max=clip_max
)
f_val = 2 * satisfied.reshape([num_eval] + [1] * len(self.estimator.input_shape)) - 1.0
f_val = f_val.astype(ART_NUMPY_DTYPE)
if np.mean(f_val) == 1.0:
grad = np.mean(rnd_noise, axis=0)
elif np.mean(f_val) == -1.0:
grad = -np.mean(rnd_noise, axis=0)
else:
f_val -= np.mean(f_val)
grad = np.mean(f_val * rnd_noise, axis=0)
# Compute update
if self.norm == 2:
result = grad / np.linalg.norm(grad)
else:
result = np.sign(grad)
return result
def _adversarial_satisfactory(
self, samples: np.ndarray, target: int, clip_min: float, clip_max: float
) -> np.ndarray:
"""
Check whether an image is adversarial.
:param samples: A batch of examples.
:param target: The target label.
:param clip_min: Minimum value of an example.
:param clip_max: Maximum value of an example.
:return: An array of 0/1.
"""
samples = np.clip(samples, clip_min, clip_max)
preds = np.argmax(self.estimator.predict(samples, batch_size=self.batch_size), axis=1)
if self.targeted:
result = preds == target
else:
result = preds != target
return result
@staticmethod
def _interpolate(
current_sample: np.ndarray, original_sample: np.ndarray, alpha: float, norm: int | float | str
) -> np.ndarray:
"""
Interpolate a new sample based on the original and the current samples.
:param current_sample: Current adversarial example.
:param original_sample: The original input.
:param alpha: The coefficient of interpolation.
:param norm: Order of the norm. Possible values: "inf", np.inf or 2.
:return: An adversarial example.
"""
if norm == 2:
result = (1 - alpha) * original_sample + alpha * current_sample
else:
result = np.clip(current_sample, original_sample - alpha, original_sample + alpha)
return result
def _check_params(self) -> None:
# Check if order of the norm is acceptable given current implementation
if self.norm not in [2, np.inf, "inf"]:
raise ValueError('Norm order must be either 2, `np.inf` or "inf".')
if not isinstance(self.max_iter, int) or self.max_iter < 0:
raise ValueError("The number of iterations must be a non-negative integer.")
if not isinstance(self.max_eval, int) or self.max_eval <= 0:
raise ValueError("The maximum number of evaluations must be a positive integer.")
if not isinstance(self.init_eval, int) or self.init_eval <= 0:
raise ValueError("The initial number of evaluations must be a positive integer.")
if self.init_eval > self.max_eval:
raise ValueError("The maximum number of evaluations must be larger than the initial number of evaluations.")
if not isinstance(self.init_size, int) or self.init_size <= 0:
raise ValueError("The number of initial trials must be a positive integer.")
if not isinstance(self.verbose, bool):
raise ValueError("The argument `verbose` has to be of type bool.")