# NeoResearch/milp_bft_failures_attacks

A MILP Model for Failures and Attacks on a BFT Blockchain Protocol
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.
MILP_BFTConsensus.mod

# A MILP Model for Failures and Attacks on a BFT Blockchain Protocol

We present a MILP model for failures and attacks on a BFT blockchain protocol.

#### Parameters

• [{$i \in R$}:] consensus replica $i$ from set of replicas $R$. $R^{BYZ}$ is byzantine set. $R^{OK}$ is non-byzantine set. $R = R^{OK} \cup R^{BYZ}$, such that $R^{OK} \cap R^{BYZ} = \emptyset$.
• [$f$:] number of faulty/Byzantine replicas. $f = |R^{BYZ}|$.
• [$N$:] total number of replicas. $N = |R| = |R^{OK}| + |R^{BYZ}| = 3f + 1$.
• [$M$:] safety level. $M = 2f + 1$.
• [{$b \in B$}:] block $b$ from set of possible proposed blocks $B$ (may be understood as block hash). $B = {b_0, b_1, b_2, \cdots }$.
• [{$h \in H$}:] height $h$ from set of possible heights $H$ (tests may only require two or three heights). $H = {h_0, h_1, h_2}$.
• [{$v \in V$}:] view $v$ from set of possible views $V$ (number of views may be limited to the number of consensus nodes $N$). $V = {v_0, v_1, \cdots , v_{N-1}}$
• [{$t \in T$}:] time unit $t$ from set of discrete time units $T$. $T = {t_0, t_1, t_2, \cdots }$.

#### Variables

• [{$primary_{i,h,v}$}:] binary variable that indicates if Consensus Node $i$ is primary at height $h$ view $v$.
• [$initialized^{t}_{i, h, v}$:] binary variable that indicates if replica $i \in R$ is at height $h$ and view $v$, on time $t$
• [$SendPrepReq^{t}_{i, h, b, v}$:] binary variable that indicates if replica $i \in R$ is sending Prepare Request message (to all nodes) at height $h$ and view $v$, on time $t$, for proposed block $b$. ACTION VARIABLE MUST BE SET ONLY ONCE FOR EVERY REPLICA, HEIGHT AND BLOCK.
• [$SendPrepResp^{t}_{i, h, b, v}$:] binary variable that indicates if replica $i \in R$ is sending Prepare Response message (to all nodes) at height $h$ and view $v$, on time $t$, for proposed block $b$. ACTION VARIABLE MUST BE SET ONLY ONCE FOR EVERY REPLICA, HEIGHT AND BLOCK.
• [$RecvPrepReq^{t}_{i, j, h, b, v}$:] binary variable that indicates if replica $i \in R$ received a Prepare Request message from replica $j$ at height $h$ and view $v$, on time $t$, for proposed block $b$. ACTION VARIABLE MUST BE SET ONLY ONCE FOR EVERY REPLICA, HEIGHT AND BLOCK.
• [$RecvPrepResp^{t}_{i, j, h, b, v}$:] binary variable that indicates if replica $i \in R$ received a Prepare Response message from replica $j$ at height $h$ and view $v$, on time $t$, for proposed block $b$. ACTION VARIABLE MUST BE SET ONLY ONCE FOR EVERY REPLICA, HEIGHT AND BLOCK.
• [{$BlockRelay^t_{i, h, b}$}:] binary variable that indicates if replica $i$ has relayed block $b$ at height $h$, on time $t$. ACTION VARIABLE MUST BE SET ONLY ONCE FOR EVERY REPLICA, HEIGHT AND BLOCK.
• [$RecvBlkPersist^{t}_{i, j, h, b}$:] binary variable that indicates if replica $i \in R$ received a Block Relay message from replica $j$ at height $h$ on time $t$, for proposed block $b$. ACTION VARIABLE MUST BE SET ONLY ONCE FOR EVERY REPLICA, HEIGHT AND BLOCK.
• [$sentPrepReq^{t}_{i, h, b, v}$:] binary variable that indicates if replica $i \in R$ has sent (in past) to all replicas a Prepare Request message at height $h$ and view $v$, on time $t$, for proposed block $b$. Once set to ONE this is carried forever as ONE.
• [$sentPrepResp^{t}_{i, h, b, v}$:] binary variable that indicates if replica $i \in R$ has sent (in past) to all replicas a Prepare Response message at height $h$ and view $v$, on time $t$, for proposed block $b$. Once set to ONE this is carried forever as ONE.
• [$recvdPrepReq^{t}_{i, j, h, b, v}$:] binary variable that indicates if replica $i \in R$ has received (in past) from replica $j$ a Prepare Request message at height $h$ and view $v$, on time $t$, for proposed block $b$. Once set to ONE this is carried forever as ONE.
• [$recvdPrepResp^{t}_{i, j, h, b, v}$:] binary variable that indicates if replica $i \in R$ has received (in past) from replica $j$ a Prepare Response message at height $h$ and view $v$, on time $t$, for proposed block $b$. Once set to ONE this is carried forever as ONE.
• [$sentBlkPersist^{t}_{i, h, b}$:] binary variable that indicates if replica $i \in R$ has sent (in past) to all replicas a Block Relay message at height $h$, on time $t$, for proposed block $b$. Once set to ONE this is carried forever as ONE. % Nao se assumi que um byzantine poderia dar dois relays diferentes em views distintos?
• [$recvdBlkPersist^{t}_{i, j, h, b}$:] binary variable that indicates if replica $i \in R$ has received (in past) from replica $j$ a Block Relay message at height $h$, on time $t$, for proposed block $b$. Once set to ONE this is carried forever as ONE.
• [{$blockRelayed_{b}$}:] binary variable that indicates if block $b$ was relayed (on any time, height or view).

#### Objective function

maximize: \sum_{b \in B} blockRelayed_{b}

The adversary can control $f$ replicas, but the other $M$ replicas must follow dBFT algorithm. The adversary can choose any delay for any message (up to maximum simulation time $|T|$). If it wants to shutdown the whole network, no blocks will be ever produced and objective will be zero (minimum possible). So, adversary will try to maximize blocks produced by manipulating delays in a clever way. Objective function is bounded to [$0$, $|B|$].

#### Constraints

Initialization constraints \begin{align} % initializing all good replicas in time zero, height zero, view zero (Byzantine can start in any configuration) initialized^{t_0}{i, h_0, v_0} = 1 & \qquad \forall i \in R^{OK}\ initialized^{t_0}{i, h, v} = 0 & \qquad \forall i \in R^{OK}, h \in H \setminus {h_0}, v \in V \setminus {v_0}\ %only one view can be initialized at a time \sum_{v \in V} initialized^{t}{i, h, v} = 1 & \qquad \forall i \in R, t \in T \setminus {t_0}, h \in H\ %only one height can be initialized at a time \sum{h \in H} initialized^{t}_{i, h, v} = 1 & \qquad \forall i \in R, t \in T \setminus {t_0}, v \in V \end{align}

Time zero constraints

Prepare request constraints

\begin{align} % can send prep req only if initialized SendPrepReq^{t}{i, h, b, v} \leq initialized^t{i, h, v} & \qquad \forall i, h, b, v, t\ % can send prep req only if primary SendPrepReq^{t}{i, h, b, v} \leq primary{i, h, v} & \qquad \forall i, h, b, v, t\ % sent prep request from i to j, subject to send i in past time sentPrReq^{t}{i, h, b, v} = sentPrReq^{t-1}{i, h, b, v} + SendPrepReq^{t-1}{i, h, b, v} & \qquad \forall h, b, i, v, t \in T \setminus {t_0}\ % received prep req on i from j, only if sent from j to i (in past time) RecvPrReq^{t}{i, j, h, b, v} \leq sentPrReq^{t}{j, h, b, v} & \qquad \forall h, b, i \neq j, v, t\ % self received prep req RecvPrReq^{t}{i, i, h, b, v} = SendPrepReq^{t}{i, h, b, v} & \qquad \forall h, b, i, v, t\ % if received in past time, keep variable received recvdPrReq^{t}{i, j, h, b, v} = recvdPrReq^{t-1}{i, j, h, b, v} + RecvPrReq^{t-1}{i, j, h, b, v} & \qquad \forall h, b, i, j, v, t \in T \setminus {t_0} \end{align}

Prepare response constraints