# PRACTICAL ADVERSARIAL ATTACKS ON BRAIN– COMPUTER INTERFACES Anonymous authors Paper under double-blind review # ABSTRACT Deep learning has been widely employed in brain–computer interfaces (BCIs) to decode a subject’s intentions based on recorded brain activities enabling direct interaction with computers and machines. BCI systems play a crucial role in motor rehabilitation and have recently experienced a significant market boost as consumer-grade products. Recent studies have shown that deep learning-based BCIs are vulnerable to adversarial attacks. Failures in such systems might cause medical misdiagnoses, physical harm, and financial damages, hence it is of utmost importance to analyze and understand in-depth, potential malicious attacks to develop countermeasures. In this work, we present the first study that analyzes and models adversarial attacks based on physical domain constraints in EEGbased BCIs. Specifically, we assess the robustness of EEGNet which is the current state-of-the-art network for embedded BCIs. We propose new methods to induce denial-of-service attacks and incorporate domain-specific insights and constraints to accomplish two key goals: (i) create smooth adversarial attacks that are physiologically plausible; (ii) consider the realistic case where the attack happens at the origin of the signal acquisition and it propagates on the human head. Our results show that EEGNet is significantly vulnerable to adversarial attacks with an attack success rate of more than $50 \%$ . With our work, we want to raise awareness and incentivize future developments of proper countermeasures. # 1 INTRODUCTION Recent work has shown that adversarial perturbations can cause state-of-the-art (SoA) deep learning models to misbehave in various domains including vision (Szegedy et al., 2014; Goodfellow et al., 2015), NLP (Li et al., 2019a; Zhang et al., 2020), speech (Qin et al., 2019; Li et al., 2019b), and biomedicine (Finlayson et al., 2019; Han et al., 2020). Neural networks have been applied in brain–computer interfaces (BCIs) achieving impressive results (Lawhern et al., 2018; Dose et al., 2018). A BCI enables direct interactions with external devices based on brain activities, typically recorded using electroencephalographic (EEG) systems. It can provide a communication pathway for severely paralyzed patients or assist in rehabilitation (Chaudhary et al., 2016). Besides medical applications, recent developments in wearable devices have pushed BCIs towards consumer-grade products to improve life quality (Aricò et al., 2020), e.g., the Interaxon Muse headband for stress relief (Arsalan et al., 2019) or the Emotiv headset for controlling drones (Marin et al., 2020) and ground vehicles (Zhuang et al., 2021). Safety in BCI systems is paramount (Dutta, 2020; Bernal et al., 2021), because a failure would cause misdiagnoses, user frustration, or even danger while driving a wheelchair or controlling a drone, causing physical and financial damages. Zhang & Wu (2019) were the first to show that EEG-based BCIs are vulnerable to adversarial attacks by proposing an unsupervised fast gradient sign method (FGSM) (Goodfellow et al., 2015). More recent work has proposed a more practical attack where a universal adversarial perturbation (UAP) is computed once and can be applied to all EEG trials without learning it for every new input (Liu et al., 2021). Both works assume that the acquired signals are sent to a remote compute engine, e.g., a computer, and the attacker can alter the signals during the transmission by attaching a “jamming” module between the signal preprocessing step and the classifier. Recent developments in smart edge computing (Akmandor & Jha, 2018; Beach et al., 2021) eliminate the need for data transmission, making this attack scenario inapplicable. Novel BCI solutions (Kartsch et al., 2019; Wang et al., 2020) embed the signal processing and classification directly at the sensor edge. A more practical adversarial example has been identified by Meng et al. (2021). It consists of a square-shaped signal that can be added to EEG trials before the preprocessing step. However, the attack is proposed as a backdoor key, which means that the attacker has direct access to the training dataset and pollutes it with adversarial examples, which is improbable if the attacker is not directly involved in the data acquisition or in the training of the classifier. Li et al. (2019b) have shown an attack scenario in the audio domain by considering the on-board edge processing of a wake-word detection system, where an adversarial audio trace is delivered to the environment causing denial-of-service (DoS). No similar studies can be currently found in the BCI domain. Challenges: Designing natural attacks and modeling its propagation. Unlike in audio applications where the signal can simply propagate over-the-air and is sensed by a microphone, extra modeling is required to evaluate the signal propagation in BCIs based on the physical properties of the biological tissues. In this work, rather than assuming a “jamming” module between the preprocessing and the classification steps as in related works, we consider a more realistic and practically applicable attack scenario where the adversarial perturbations are introduced at the source of the data acquisition, as showcased in Figure 6 in Appendix A. This can be achieved, for example, via electromagnetic waves delivered to the environment (Dutta, 2020) or via transcranial current stimulation with electrical current delivered directly to the scalp (Bodranghien et al., 2017; Fertonani et al., 2015), by exploiting wearable devices, such as smart glasses or over-ear headsets (Flowneuroscience, 2021; Marin et al., 2020). The adversarial perturbations translate into electrical signals propagating over the scalp and are sensed by the electrodes in addition to the EEG signals. To guarantee the imperceptibility of the attacks, previous works in BCIs create perturbations that are small in amplitude (Zhang & Wu, 2019; Jiang et al., 2019; Liu et al., 2021), limiting the attack success rate (ASR). Increased perturbation’s amplitude yields higher ASR (Meng et al., 2021), but makes the attack more easily detectable. Moreover, the generated perturbations are square-shaped, which is implausible for biosignals. Han et al. (2020) are the first to observe square-wave artifacts in biosignals’ attacks and propose smooth perturbations for electrocardiograms (ECGs). No similar works have been found for EEGs. This work: Practical attacks on BCI models. To address the above technical challenges, and for analyzing the vulnerability of embedded BCI models in practical scenarios, we design a new attack algorithm that generates smooth adversarial examples based on the signals’ first derivative and model its propagation over the scalp based on a realistic head model by taking into consideration the attack source and the electrical and physical properties of the conducting tissues. This enables the creation of practically effective perturbations, that can be delivered by an external device to attack EEG-based BCIs at the source of signal acquisition. We attack the most energy-efficient network that has been embedded on microcontrollers for smart wearable BCIs called EEGNet (Lawhern et al., 2018; Schneider et al., 2020). It is a resource-friendly convolutional neural network (CNN) and is the SoA in terms of accuracy and energy-efficiency trade-off (Belwafi et al., 2018; Malekmohammadi et al., 2019; Wang et al., 2020; Schneider et al., 2020). We evaluate our methods and show experimental results on BCIs based on the motor imagery (MI) paradigm, which is of special interest among others because it can be asynchronously self-paced without external stimuli (Freer & Yang, 2020). By imagining the movement of different body parts, the decoded intention is translated into control signals. It is widely applied in several BCI applications, such as the control of wheelchairss (Yu et al., 2018), prosthetic armss (Elstob & Secco, 2016), ground vehicles (Zhuang et al., 2021), and in communication (Brumberg et al., 2016). It has been proven to be the most difficult task to be attacked among the most common BCI paradigms (Zhang & Wu, 2019; Meng et al., 2021). We evaluate our methods by “fooling” the victim model to always predict “rest” class. This essentially yields a DoS attack, because resting-state EEG signals are generally interpreted as no subject’s intention decoded, i.e., no control action needs to be taken by the BCI system (Yu et al., 2018). While for healthy subjects it might solely cause user frustration and financial losses, for severely paralyzed patients it can lead to loss of communication and independence. We generalize our methodology to an other MI task of BCI Competition IV-2a dataset and believe that it can be easily adapted to other BCI paradigms. Main contributions. Our main contributions are: • We design a new method to generate smooth adversarial perturbations that are physiologically plausible and imperceptible to the human eye. • We consider a practical scenario where the perturbation is added at the signal acquisition source and model its propagation constrained by the physical properties of the human scalp. • The first study of adversarial perturbations in BCI to consider the practical scenario of smart edge computing and physical signal propagation. We create both local and global perturbations and show that our attacks consistently achieve a success rate of $> 5 0 \%$ in different settings pointing to the significant vulnerability of the SoA embedded EEGNet. We hope that our work raises awareness for potential risks and motivates the future development of appropriate countermeasures. # 2 BACKGROUND # 2.1 CLASSIFICATION IN BCIS We first describe the commonly used approach in BCIs for classification, consisting of a preprocessing step and a classifier. The brain activity is recorded with an EEG device which samples $N _ { c h }$ channels at rate $F _ { s }$ . We define one trial $j$ as $( \mathbf { X } ^ { ( j ) } , y ^ { ( j ) } )$ , where $y ^ { ( j ) } \in \{ 0 , 1 , . . . , N _ { c l } - 1 \}$ is the true label of $N _ { c l }$ MI tasks, and $\mathbf { X } ^ { ( j ) } \in \mathbb { R } ^ { N _ { s } \times N _ { c h } }$ the multi-channel recording defined as $$ \mathbf { X } ^ { ( j ) } : = \left( \mathbf { x } _ { 0 } ^ { ( j ) } , \mathbf { x } _ { 1 } ^ { ( j ) } , . . . , \mathbf { x } _ { N _ { c h } - 1 } ^ { ( j ) } \right) , $$ with $\mathbf { x } _ { i } ^ { ( j ) } \in \mathbb { R } ^ { N _ { s } }$ corresponding to the recording of the $j$ -th trial and the $i$ -th channel containing $N _ { s }$ temporal samples. For simplicity, we denote $\mathbf { X } : = \mathbf { X } ^ { ( j ) }$ and $y : = y ^ { ( j ) }$ . The EEG recordings are often preprocessed with a band-pass filter, e.g., using a Fast Fourier Transform (FFT) filter $h _ { b p } ( \cdot )$ , before being fed to a classifier, yielding $$ \mathbf { X } _ { b p } = H _ { b p } ( \mathbf { X } ) = \left( h _ { b p } ( \mathbf { x } _ { 0 } ) , h _ { b p } ( \mathbf { x } _ { 1 } ) , . . . , h _ { b p } ( \mathbf { x } _ { N _ { c h } - 1 } ) \right) . $$ Finally, the preprocessed signal $\mathbf { X } _ { b p }$ is classified with a trainable model $f$ and is mapped to $\mathbf { p } : =$ $f \left( { \bf { X } } _ { b p } \right)$ , where $\mathbf { p } \in \mathbb { R } ^ { N _ { c l } }$ contains the output probabilities, e.g., originating from a softmax activation as final operation in $f$ . The model’s final prediction $\hat { y }$ is the index with the maximum score in $\mathbf { p }$ : $$ \boldsymbol { \hat { y } } = \boldsymbol { \hat { f } } \left( \mathbf { X } _ { b p } \right) = \underset { y \in \{ 0 , \ldots , N _ { c l } - 1 \} } { \mathrm { a r g m a x } } ~ f \left( \mathbf { X } _ { b p } \right) [ y ] . $$ # 2.2 INSTANCE-BASED ATTACKS Instance-based attacks try to fool an EEG classifier $f$ to misclassify an EEG signal $\mathbf { X }$ to a targeted class $y _ { t }$ . In this section, we describe the attack directly on the classifier $f$ without considering the preprocessing $H _ { b p }$ ; the inclusion of the preprocessing is described in Section 3.3. We define an adversarial example as any $\mathbf { X } ^ { * } = \mathbf { X } + \mathbf { V } \in \mathbb { R } ^ { N _ { s } \times N _ { c h } }$ such that $$ \hat { f } \left( \mathbf { X } \right) \neq \hat { f } \left( \mathbf { X } ^ { * } \right) = y _ { t } . $$ FGSM. The FGSM (Goodfellow et al., 2015) generates an adversarial perturbation $\mathbf { V } \in \mathbb { R } ^ { N _ { s } \times N _ { c h } }$ of magnitude $\epsilon$ which points in the negative direction of a loss function’s gradient: $$ \mathbf { V } = - \epsilon \cdot \mathrm { s i g n } \left( \nabla _ { \mathbf { X } } \cdot l \left( \mathbf { X } , y _ { t } \right) \right) , $$ where the loss function contains the negative log likelihood $$ l ( \mathbf { X } , y _ { t } ) = - \log \left( { \mathbf { p } } [ y _ { t } ] \right) = - \log \left( f \left( \mathbf { X } \right) [ y _ { t } ] \right) . $$ As $\mathbf { p }$ is the output of the softmax activation function, equation 6 becomes a cross-entropy loss which maximizes the output $\mathbf { p } [ y _ { t } ]$ while minimizing the remaining outputs. PGD. The projected gradient descent (PGD) (Madry et al., 2018) is a variant of the basic iterative method (Kurakin et al.), generally considered to be more effective than FGSM. PGD aims to find a perturbation by iteratively taking small steps of size $\alpha$ in the gradient’s direction and projecting the resulting perturbation back to the sample’s neighborhood after each iteration. We randomly initialize the attack inside the $L _ { \infty }$ ball of radius $\epsilon$ and update the attack $\mathbf { V } _ { t + 1 }$ for any iteration $t$ with $$ \mathbf { V } _ { t + 1 } = \mathrm { c l i p } _ { \epsilon } \left( \mathbf { V } _ { t } - \alpha \cdot \mathrm { s i g n } \left( \nabla _ { \mathbf { V } } l \left( \mathbf { X } + \mathbf { V } _ { t } , y _ { t } \right) \right) \right) , $$ where $\alpha$ is a step size smaller than $\epsilon$ which decays linearly with each iteration and the function $\mathrm { c l i p } _ { \epsilon } \left( \cdot \right)$ clips the signal at the maximum desired amplitude $\epsilon$ . # 2.3 UNIVERSAL ATTACKS UAPs have been introduced by Moosavi-Dezfooli et al. (2017) in the context of natural images, seeking to find an image-agnostic perturbation that fools the classifier on any input image. In the BCI domain (Liu et al., 2021), we seek to find a perturbation $\mathbf { V } \in \mathbb { R } ^ { N _ { s } \times N _ { c h } }$ such that $$ \begin{array} { r } { \hat { f } \left( \mathbf { X } + \mathbf { V } \right) \neq \hat { f } \left( \mathbf { X } \right) \mathrm { f o r } ^ { * } \mathrm { m o s t } ^ { * } \mathbf { X } \sim D , } \end{array} $$ where $D$ is the distribution of the EEG data. The UAP can be determined by optimizing the negative log-likelihood loss with respect to $\mathbf { V }$ using batch gradient descent on the trials in the training set. # 3 MODELING PRACTICAL ATTACKS IN BCI This section is the main contribution of the paper: we present a design of practical DoS attacks on MIBCIs that operates at the source of the signal acquisition. We propose a new method to eliminate the square wave artifacts to generate adversarial examples that are natural and physiologically plausible. The perturbation is emitted by a smart, adversarial device placed close to the ear, e.g., a smart glass or in-ear headphones, and is propagated to the individual EEG electrodes over the scalp’s skin. As can be experimentally observed on measured EEG traces (Merlet et al., 2013; Sazgar & Young, 2019), the same electrical source, e.g., electrocardiographic activities, is sensed by each EEG electrode with different degrees of attenuation and delay. We present a practical propagation model that determines the magnitude and delay for every individual electrode based on the distance along the scalp to the adversarial device. The perturbation is trained end-to-end to fool the classifier to always output “rest,” hence DoS, while respecting the spatial model and the amplitude constraints to remain imperceptible. # 3.1 DESIGN AND ASSESSMENT OF PHYSIOLOGICALLY PLAUSIBLE ATTACKS PGD-designed attacks on EEG tend to form perturbation signals which resemble a square-wave artifact (see Figure 2), an effect that has been observed on ECG data, too (Han et al., 2020). However, EEG signals are of random nature and can be modeled as frequency dependent stationary or nonstationary random processes (Karlekar & Gupta, 2014). To this end, we introduce a new loss term in the PGD optimization such that the perturbation resembles the random nature of EEG signals, which we achieve by promoting signal changes represented in the first order derivative. We estimate the per-channel derivative $\begin{array} { r } { \bar { { \bf V } ^ { \prime } } = ( { \bf v } _ { 0 } ^ { \prime } , { \bf v } _ { 1 } ^ { \prime } , . . . , { \bf v } _ { N _ { c h } - 1 } ^ { \prime } ) \in \mathbb { R } ^ { N _ { s } - 1 \times N _ { c h } } } \end{array}$ using the sample-wise difference: $$ \begin{array} { r } { \mathbf { v } _ { c } ^ { \prime } [ t ] : = \mathbf { v } _ { c } [ t ] - \mathbf { v } _ { c } [ t - 1 ] \quad t \in \{ 1 , 2 , . . . , N _ { s } - 1 \} , c \in \{ 0 , 1 , . . . , N _ { c h } - 1 \} } \end{array} $$ The additive loss term is determined by $\begin{array} { r } { l _ { 1 } ( { \bf V } ) = - \frac { \beta } { \epsilon } \sum _ { c = 1 } ^ { N _ { c h } } | | { \bf v } _ { c } ^ { \prime } | | _ { 1 } } \end{array}$ − β PNchc=1 ||v0c||1, where || · ||1 is the \`1-norm, the maximum perturbation amplitude, and $\beta \geq 0$ a weighting factor. When designing a one-dimensional perturbation, the derivative loss becomes $\begin{array} { r } { l _ { 1 } ( \mathbf { v } ) = - \frac { \beta } { \epsilon } | | \mathbf { v } ^ { \prime } | | } \end{array}$ . Measuring the Plausibility of Attacks None of the previous works have given quantitative measures to assess the physiological plausibility of an EEG adversarial attack. In this work, we propose data-driven measures for quantifying the naturalism of an attack. We compute either the cross correlation, the Euclidian distance, or the cosine similarity between the attacked signal and the original EEG, and average the values over the $N _ { c h }$ channels and over the samples in the dataset. # 3.2 SPATIAL PROPAGATION MODEL So far, a perturbation signal was designed for every individual channel. It is unrealistic for an attacker to perturb the signal for all individual channels simultaneously; hence, we consider a more practical use case where the perturbation signal $\mathbf { v } \in \mathbb { R } ^ { N _ { s } }$ is emitted from one location, e.g., from an adversarial device placed on the left side of the subject or close to the left ear. More specifically, in this study, we assume that the EEG electrode at the position T9 according to the international 10-10 system (Sch), which is the closest to the left ear, senses the largest perturbation. The signal subsequently propagates over the skin to each electrode, which results in an individual magnitude and delay depending on the distance between the adversarial device and the electrode. More formally, we model the sensed perturbation at channel $i$ and time instant $t$ as $$ h _ { i } ( \mathbf { v } , \lambda _ { m } , \lambda _ { d } ) ( t ) : = m ( l _ { i } , \lambda _ { m } ) \cdot \mathbf { v } \left( t - d ( l _ { i } , \lambda _ { d } ) \right) , $$ where $m ( l _ { i } , \lambda _ { m } )$ and $d ( l _ { i } , \lambda _ { d } )$ are the magnitude and the delay respectively, both of which depend on the distance $l _ { i }$ and on characteristic parameters $\lambda _ { m }$ and $\lambda _ { d }$ . We define the resulting multi-channel perturbation $\mathbf { V } \in \mathbb { R } ^ { N _ { s } \times N _ { c h } }$ , which is added to the multi-channel EEG signal, as $$ \begin{array} { r } { { \bf V } ( \lambda _ { m } , \lambda _ { d } ) = H ( { \bf v } , \lambda _ { m } , \lambda _ { d } ) : = \left( h _ { 0 } ( { \bf v } , \lambda _ { m } , \lambda _ { d } ) , h _ { 1 } ( { \bf v } , \lambda _ { m } , \lambda _ { d } ) , . . . , h _ { N _ { c h } - 1 } ( { \bf v } , \lambda _ { m } , \lambda _ { d } ) \right) . } \end{array} $$ We estimate the distance $l _ { i }$ between the electrode at position T9 and the remaining, attacked positions using the 10-10 system and a head model with a radius of $8 . 7 \mathrm { c m }$ (Algazi et al., 2001). We decouple the distance-dependent modeling of the magnitude and delay, explained in the following paragraphs. Magnitude. For modeling the magnitude, we assume that the adversarial device injects or induces a current $I$ , yielding a potential $V$ measured near T9. The current propagates over the head surface through the skin to each of the remaining attacked electrodes, which can be modeled as a cylindrical resistor with resistance $$ R _ { i } = \frac { l _ { i } } { \sigma A } , $$ where $\sigma$ is the conductivity of the skin which can be in the range of [0.28, 0.87] Siemens/m (Vorwerk et al., 2019), and $A$ is the area of the skin conductor. The potential at electrode $i$ is $V _ { i } = V - I \cdot R _ { i }$ , and hence the magnitude can be described as $$ m ( l _ { i } , \lambda _ { m } ) = 1 - \frac { V - V _ { i } } { V } = 1 - \frac { I } { V \sigma A } l _ { i } = 1 - \lambda _ { m } l _ { i } , $$ where we further constrain $0 \leq m ( l _ { i } , \lambda _ { m } ) \leq 1$ . The characteristic magnitude parameter $\lambda _ { m }$ represents the complex interplay between input current, voltage, conductivity, and area, covering various attack scenarios. We consider different characteristic magnitude parameters $\lambda _ { m } \in [ 1 , 1 5 ]$ . A large $\lambda _ { m }$ represents cases with large attenuation and limited propagation, i.e., a limited set of neighboring electrodes sense the perturbation. Conversely, a small $\lambda _ { m }$ covers cases with lower attenuation where the perturbation can propagate further and infects all electrodes. We consider also an intermediate case where around half of the electrodes are affected by the attack with $\lambda _ { m } = 5$ . Appendix B provides examples of the magnitude of the spatial propagation on the head model. Delay. The propagation of a signal on the head surface yields a position-dependent phase angle or delay, as shown by experimental measurements of related studies (Plutchik & Hirsch, 1963; Qiao et al., 1994). The delay stems from a combination of resistive and capacitive components that are encountered during the propagation of the signal, which can be modeled as an RC-circuit with resistance $R$ , capacity $C$ , and time constant $\tau = R \cdot C$ that relates to the group delay. Specifically, the contacts between the electrodes and the skin are predominantly capacitive whereas the skin itself is both resistive and capacitive (Kim et al., 2010). As explained in the previous part, an increasing distance between the attacker and the target electrode yields a larger resistance $R$ . As a result, the time constant $\tau$ and the delay increase too. Here, we model a linear distance-delay relation. We rely on a study by Plutchik & Hirsch (1963), which conducted human skin impedance and phase angle measurements by placing electrodes at an approximate distance of $1 0 \mathrm { c m }$ and applying voltages with frequencies in the range $2 { \mathrm { - } } 1 0 0 0 \mathrm { { H z } }$ . When assuming a linear frequency-phase relation in low-frequency region (Qiao et al., 1994), one can derive the group delay to be $2 . 8 \mathrm { m s }$ when considering a measured angle of $1 0 ^ { \circ }$ at $1 0 \mathrm { H z }$ . As those measurements were conducted for only one distance, we extrapolate the delay for the remaining distances using a rectified linear model: $$ \lambda _ { d } \cdot ( l _ { i } - l _ { 0 } ) > 0 \uparrow d ( l _ { i } , \lambda _ { d } ) = \lambda _ { d } \cdot ( l _ { i } - l _ { 0 } ) + d _ { 0 } : d ( l _ { i } , \lambda _ { d } ) = 0 , $$ where $d _ { 0 } = 2 . 8 \mathrm { m s }$ is the delay at distance $l _ { 0 } = 1 0 \mathrm { c m }$ . The delay depends not only on the distance, but also on other parameters such as the electrode-to-skin contact, the humidity of the skin, etc. To this end, we evaluate the propagation of the attack with different characteristic delay parameters $\lambda _ { d } \in \left[ 0 . 1 , 0 . 5 6 3 \right] \mathrm { s / m }$ . With $\lambda _ { d } = 0 . 1$ we cover the cases where very little delay happens, while the largest considered $\lambda _ { d } = 0 . 5 6 3 \mathrm { s / m }$ yields a maximum delay of $0 . 1 \mathrm { s }$ at the farthest electrode T10, which is in alignment with the observed EEG measurements (Merlet et al., 2013; Sazgar & Young, 2019). Similarly to $\lambda _ { m }$ , we showcase also for an intermediate value of $\lambda _ { d } = 0 . 3$ which corresponds to a delay of $0 . 0 5 3 \mathrm { m s }$ at T10. Algorithm 1: Generation of physiologically plausible UAP. input : $\mathbf { X } _ { t r a i n }$ , EEG training samples; $\lambda _ { m } , \lambda _ { d }$ , spatial propagation parameters; $\beta$ , weight of derivative loss term; , maximum perturbation amplitude; $G$ , number of PGD iterations; $E$ , number of epochs output :v, adversarial perturbation 1 $\mathbf { v } \mathcal { U } ( - \epsilon , \epsilon ) \in \mathbb { R } ^ { N _ { s } } ;$ ; // Initialisation 2 for $e \gets 1$ to $E$ do 3 Shuffle $\mathbf { X } _ { t r a i n }$ ; 4 for each batch $\mathbf { B } \in \mathbf { X } _ { t r a i n }$ do 5 $\alpha \frac \epsilon 2$ ; 6 for $g \gets 1$ to $G$ do 7 $\mathbf { \bar { V } } H ( \mathbf { v } , \lambda _ { m } , \lambda _ { d } ) ;$ // Spatial propagation 8 $\begin{array} { r } { \dot { \mathbf { p } } f ( H _ { b p } ( \mathbf { B } + \mathbf { V } ) ) } \end{array}$ ; // Model pass with perturbation 9 $\begin{array} { r } { \mathbf { v } \mathbf { v } - \alpha \cdot \mathrm { s i g n } ( \nabla _ { \mathbf { v } } ( l ( \mathbf { p } , y _ { r e s t } ) - \frac { \beta } { \epsilon } | | \mathbf { v } ^ { \prime } | | _ { 1 } ) ) } \end{array}$ ; // Update w/derivative 10 v ← clip (v); // PGD projection 11 $\alpha { \frac { 0 . 1 - { \frac { \epsilon } { 2 } } } { G } } \cdot g + { \frac { \epsilon } { 2 } }$ ; // Learning rate update 12 end 13 end 14 end # 3.3 ATTACK DESIGN We present practical DoS attacks in BCIs that respect domain constraints such as maximum amplitude, spectral distribution, physiological plausibility, and the spatial propagation of the perturbation. To this end, we formulate a general objective function that contains the spatial propagation, the preprocessing step, and the first order derivative loss term: $$ \mathcal { L } _ { t o t } \left( \mathbf { X } , \mathbf { v } , \lambda _ { m } , \lambda _ { d } \right) = l \left( H _ { b p } \left( \mathbf { X } + H ( \mathbf { v } , \lambda _ { m } , \lambda _ { d } ) \right) , y _ { r e s t } \right) - \frac { \beta } { \epsilon } | | \mathbf { v } ^ { \prime } | | _ { 1 } , $$ where $l ( \cdot , \cdot )$ is the negative log-likelihood loss defined in equation 6 and $\beta { = } 1 \mathrm { e } { - } 6$ is a scalar that weights the contribution of the derivative loss term. We compare different attack scenarios: Instance-based attacks. A perturbation is computed using either FGSM or PGD based on the knowledge of the currently attacked EEG signal $\mathbf { X }$ . FGSM computes the perturbation as stated in equation 5, where the $\epsilon$ defines the perturbation amplitude which is varied between $1 { - } 5 0 \mathrm { m V } .$ Alternatively, we compute the perturbation using PGD with $G { = } 1 0$ iterations, where each iteration consists of a gradient-based update of the perturbation and a projection to the $L _ { \infty }$ ball with radius $\epsilon$ (see equation 7). The update rate $\alpha$ is initialized with $\epsilon / 2$ and linearly decreased with each iteration, reaching a final value of $0 . 1 \mathrm { m V }$ at iteration 10. The PGD computation is restarted 5 times with different initial perturbations, which are drawn from a uniform distribution within the range $[ - \epsilon , + \epsilon ]$ . Universal attacks. A universal perturbation is computed for all the samples in the training data. We optimize the UAP objective function $$ \operatorname* { m i n } _ { \mathbf { v } } E _ { \mathbf { X } \sim D } \mathcal { L } _ { t o t } \left( \mathbf { X } , \mathbf { v } , \lambda _ { m } , \lambda _ { d } \right) \quad \mathrm { ~ s . t . ~ } | | \mathbf { v } | | _ { \infty } \leq \epsilon $$ using batched PGD. We pass a batch of 16 samples together with the current perturbation through the preprocessing and classifier, compute the loss function, and update the perturbation based on the negative gradient with consecutive projection to the $L _ { \infty }$ ball with radius $\epsilon$ . This step is repeated $G { = } 1 0$ times before processing the next batch. Overall, the UAP is learned for $E { = } 1 0$ epochs. Propagation model. We distinguish between three use cases of spatial propagation model, where in all cases either an instance-specific attack or a universal attack can be computed: Case 1) Ignore the propagation model: a multi-channel perturbation $\mathbf { V }$ is computed, which attacks each channel individually, replacing the terms $H ( \mathbf { v } , \lambda _ { m } , \lambda _ { d } )$ by $\mathbf { V }$ and $\mathbf { v } ^ { \prime }$ by $\mathbf { V } ^ { \prime }$ in equation 15. Case 2) Consider the propagation model: a single-channel perturbation v is computed and tested with a specific propagation configuration $\lambda _ { m }$ and $\lambda _ { d }$ . Case 3) Consider a use-case where the attacker does not know the spatial propagation model and computes the same perturbation $\mathbf { v }$ for all channels. The actual propagation model is applied during testing to model the real-world signal propagation.  Figure 1: Performance of random noise, FGSM, PGD, and UAP with and without derivative loss term. Table 1: Plausibility metrics for PGD attack (a) without derivative term, (b) with the derivative loss term, and (c) with a Gaussian kernel (Han et al., 2020). The smaller the cross correlation $\eta$ and the Euclidian distance $\ell _ { 2 }$ - norm, and the higher the cosine similarity $\gamma$ , the more natural the generated attack.
| n[10-3v2] | l2-norm [mV] | γ[%] | |||||||
| ε[mV] | (a) | (b) | (c) | (a) | (b) | (c) | (a) | (b) | (c) |
| 1 | 3.31 | 1.98 | 3.42 | 20.8 | 15.2 | 21.2 | 99.89 | 99.93 | 99.89 |
| 5 | 16.6 | 7.76 | 17.3 | 99.1 | 61.2 | 102 | 97.99 | 99.22 | 97.87 |
| 10 | 32.5 | 12.6 | 34.1 | 191 | 112 | 198 | 93.82 | 97.47 | 93.49 |
| 25 | 74.9 | 27.3 | 79.2 | 461 | 263 | 475 | 79.61 | 90.05 | 78.92 |
| 50 | 125 | 39.0 | 135 | 823 | 462 | 855 | 64.17 | 79.70 | 63.06 |