# Resilience Analysis for Double Spending via Sequential Decision Optimization
## 4 Block Difference Dynamics  
Consider a finite time horizon where \(t\in\{0,\ldots,T\}\) represents the number of blocks mined in the official chain since the branch has forked off, i.e., we suppose that our secret mining starts at the block time \(t=0\). We interpret \(T\in\mathbb{N}\) as the maximal length of the official branch, which can be abandoned if a longer branch has been discovered. To the best of authors knowledge, the current Bitcoin protocol does not have such a restriction, meaning that the shorter branch must always be discarded, independently of its length. However, other systems discuss 'checkpoints' and 'gates' with similar functionality. A finite time horizon yields conceptual advantages (providing an exact solution) and presents a negligible deviation from reality since \(T\) is sufficiently large and can be changed in the calculation. Let us introduce all the ingredients required for a formal discussion of the decision problems formulated above. Introduce the block difference process \((Z_{t})_{t=0}^{T}\),  
\[\left.\begin{array}{c}\text{where }Z_{t}\text{ is the branch length difference between the official}\\ \text{and secret branch at times }t=0,\ldots,T\text{ when one new}\\ \text{block in the {\em official} branch is completed.}\end{array}\right\} \tag{5}\]  
We show that the transition probabilities of \((Z_{t})_{t=0}^{T}\) satisfy  
\[\mathbb{P}(Z_{t+1}=x+1-j|\,Z_{t}=x)=\left\{\begin{array}{cc}g(j)&j\in \mathbb{N}=\{0,1,2,3,\ldots\},\\ 0&j\in\mathbb{Z}\setminus\mathbb{N}=\{-1,-2,\ldots\},\end{array}\right. \tag{6}\]  
for all \(t=0,\ldots,T\) with a geometric distribution  
\[g(j)=(1-q)q^{j}\quad\text{for }j\in\mathbb{N}=\{0,1,2,3,\ldots\} \tag{7}\]  
Figure 1: The success probability (and its logarithm) of the double-spending attack for \(n=6\) confirming blocks depending on the mining ratio \(q\in[0,\frac{1}{10}]\) calculated by (3) with \(k=0\) (solid line) versus \(k=-1\) as in (4) (dashed line).  
where \(q\in[0,1]\) is the fraction of the capacity controlled by secret miners, the proof of the assertions (6) and (7) is found in Appendix A. Consider also \((\hat{Z}_{t}=t-Z_{t})_{t=0}^{T}\) with  
\[\left.\begin{array}{l}\hat{Z}_{t}\text{ is the length of the secret branch}\\ \text{at the times }t=0,\ldots,T\text{ when one new}\\ \text{block in the {\em official} branch is completed.}\end{array}\right\} \tag{8}\]  
This process possesses independent identically geometrically distributed increments  
\[\mathbb{P}(\hat{Z}_{t+1}=x+j|\,\hat{Z}_{t}=x)=g(j)\qquad x,j\in\mathbb{N},\;\;t =0,\ldots,T. \tag{9}\]  
In what follows, we show that determining the double-spending attack which has the highest expected total reward (from the viewpoint of the attacker) yields an optimal stochastic stopping/switching problem. To ease reader's understanding, we start with a simplified situation (neglecting secret mining costs, rewards for published blocks, and the possibility of abandoning the attack at any stage). Such a problem can be formulated as an optimal stopping problem. Thereafter, based on the setting of this stopping problem, we consider a more realistic approach and upgrade the optimal stopping to an optimal switching framework, which takes into account mining costs, rewards for published blocks, and the possibility to abandon secret mining. Before introducing all details in subsequent sections let us sketch the core ideas and explain how our results can be used to assess vulnerability of a given PoW-based system.