## 3 Statistical Hypothesis Testing  
In this section, we introduce a new method to detect the PNS attack in the decoy-state MDI-QKD via statistical hypothesis testing. It is important to emphasize that the PNS attacks mentioned here and below refer to the weaker version of PNS attack. Then we analyze the Type I error of the test; that is, mistaking no PNS attack when there is a PNS attack. Generally speaking, our method first puts forward a null hypothesis and alternative hypothesis based on the theory of statistical hypothesis testing. Then, the test statistic is constructed according to the null hypothesis and other conditions. Furthermore, the specific values of the statistics can be obtained by using the parameters and experimental data. After the significance level is given, we can infer whether there is PNS attack in the channel with a certain probability. The details are as follows. (i) Identify null and alternative hypothesis. Let us consider the hypothesis testing problem of the null hypothesis \(H_{0}\): there is no PNS attack on the channel and the alternative hypothesis \(H_{1}\): there is a PNS attack on the channel. (ii) Construct the test statistic. We need a test statistic to conduct the hypothesis testing. In what follows, the distribution of the test statistic is derived under the null hypothesis \(H_{0}\). Let us further consider [PERSON]'s and [PERSON]'s pulses emission process and [PERSON]'s BSM event. When [PERSON] and [PERSON] send pulses with the same basis, the BSM event outcomes at Charlie only include two cases, successful or failed. Therefore, the above process can be regarded as a Bernoulli trial. Note that \(Q_{\mu_{k}\
u_{l}}^{W}\) is the probability that [PERSON] obtains a successful BSM event provided that [PERSON] and [PERSON] emit pulses with the intensities \(\mu_{k}\) and \(\
u_{l}\) and select the basis \(W\). Suppose the total number of pulses emitted by [PERSON] ([PERSON]) is \(N_{data}\), then the number of pulses is \(P_{W}^{2}P_{\mu_{k}\
u_{l}}N_{data}\) when [PERSON]'s and [PERSON]'s intensities with \(W\) basis are \(\mu_{k}\) and \(\
u_{l}\), respectively. In the above equation, \(P_{W}\) is the probability that [PERSON] ([PERSON]) chooses the \(W\in\{X,Z\}\) basis, \(P_{\mu_{k}\
u_{l}}=P_{\mu_{k}}P_{\
u_{l}}\) is the probability that [PERSON] and [PERSON] choose the intensities \(\mu_{k}\) and \(\
u_{l}\), respectively. At this point, the number of successful BSM events that [PERSON] obtained is denoted as \(n_{\mu_{k}\
u_{l}}^{W}\). Then, \(n_{\mu_{k}\
u_{l}}^{W}\) has the binomial distribution with parameters \((P_{W}^{2}P_{\mu_{k}\
u_{l}}N_{data},\ Q_{\mu_{k}\
u_{l}}^{W})\), for short,  
\[n_{\mu_{k}\
u_{l}}^{W}\sim B(P_{W}^{2}P_{\mu_{k}\
u_{l}}N_{data},\ Q_{\mu_{k} \
u_{l}}^{W}). \tag{6}\]  
According to [36], we find \(N_{data}\) is so large (typically \(10^{10}\sim 10^{11}\)), \(Q_{\mu_{k}\
u_{l}}^{W}\) is close to \(10^{-8}\sim 10^{-5}\). Generally, the selections of basis and intensity are random. In other words, \(P_{Z}=P_{X}=1/2\), \(P_{\mu_{k}}=P_{\
u_{l}}=1/3\) where \(k,l\in\{0,1,2\}\). Thus, we have \(P_{W}^{2}P_{\mu_{k}\
u_{l}}N_{data}Q_{\mu_{k}\
u_{l}  
After standardization, we obtain a random variable \(U^{W}_{\mu_{k}\
u_{l}}\), which obeys the standard normal distribution; that is,  
\[U^{W}_{\mu_{k}\
u_{l}}=\frac{n^{W}_{\mu_{k}\
u_{l}}-P^{2}_{W}P_{\mu_{k}\
u_{l}}N _{data}Q^{W}_{\mu_{k}\
u_{l}}}{\sqrt{P^{2}_{W}P_{\mu_{k}\
u_{l}}N_{data}(1-Q^{ W}_{\mu_{k}\
u_{l}})}}\sim N(0,1). \tag{8}\]  
Considering the additivity of normal distribution, we obtain a random variable involving all possibilities of \(U^{W}_{\mu_{k}\
u_{l}}\) where \(W\in\{X,Z\},k,l\in\{0,1,2\}\), which also obeys the normal distribution. There are eighteen cases of \(U^{W}_{\mu_{k}\
u_{l}}\) considering that the pair of intensity is nine cases and the selection of basis is two cases. Note that we only consider the same basis for [PERSON] and [PERSON], that is, both \(Z\) basis or both \(X\) basis.