# Blockchain-Based Resource Allocation Model in Fog Computing
## Materials and Methods
### Game Formulation and Model Solving  
As mentioned above, fog nodes are usually selfish and rational, that is, they will not contribute resources endlessly without considering the cost. Furthermore, fog nodes should fully consider the tradeoff between income and cost. In the game, the fog node as the player needs to choose the optimal strategy to maximize its own revenue, and the differential game can clearly describe the dynamic process of the player's optimal strategy selection. Therefore, the following differential game model  
Figure 5: System model diagram. can be established to optimize the resource contribution \(c_{i}(t)\) of fog node i and maximize its own benefit \(\phi_{i}(t)\):  
\[G=\max_{c_{i}(t)}\int_{0}^{T}e^{-rt}\bigg{\{}R\cdot\frac{c_{i}(t)}{\sum_{i\in k _{i}}c_{i}(t)};\beta_{i}\cdot\alpha_{i}e^{-\lambda zk_{i}}\cdot c_{i}(t)-\gamma _{i}c_{i}(t)-\sum\
olimits_{j\in N-m,j\
eq j}\chi c_{j}(t)M(t)\bigg{\}}dt, \tag{10}\]  
where \(r\) is the discounted parameter, that is, the future income of the fog node is converted into the parameter of the current value between 0 and 1, and the energy consumption change in the process of contributing the resource by the fog node satisfies the formula (9). We assume that the strategy set \(\left\{c_{i}^{*}(t)=u_{i}^{*}(\cdot),i\in N\right\}\) constitutes a feedback Nash equilibrium solution for the finite time domain games (10) and (9), and if and only if there is a continuous differentiable function \(V^{i}(M,t):R^{m}\to R\), the following Bellman equations are satisfied [52]:  
\[ \begin{array}{c}-V^{i}(M,t)=R\cdot\frac{c_{i}(t)}{\sum_{i\in k_{i}}c_{i}(t)} \cdot\beta_{i}\cdot\alpha_{i}e^{-\lambda zk_{i}}\cdot c_{i}(t)-\gamma_{i}c_{i} (t)-\sum\
olimits_{j\in N-m,j\
eq j}\chi c_{j}(t)M(t)\\ \hskip 14.226378 pt+V^{i}_{E}(M,t)[\partial M(t)+\sum_{i\in N}\omega c_{i}(t)+ \sum_{i\in m}H_{i}c_{i}(t)]\end{array}  \tag{11}\]  
Deriving \(c_{i}(t)\) on the right side of (11) and letting it be 0 gives the optimal solution \(u_{i}^{*}(t)\):  
\[u_{i}^{*}(t)=\frac{\gamma_{i}+H_{i}\cdot V^{i}_{M}-R\cdot\beta_{i}\cdot\alpha_ {i}e^{-\lambda zk_{i}}+V^{i}_{M}\cdot\alpha\hskip-1.4226378 pt-\sqrt{\frac{R \cdot\beta_{i}\cdot\alpha_{i}e^{-\lambda zk_{i}}-V^{i}_{M}(\omega+H_{i})- \gamma_{i}}{R\cdot\beta_{i}\cdot\alpha_{i}e^{-\lambda zk_{i}}}}}{\gamma_{i}+H_ {i}\cdot V^{i}_{M}-R\cdot\beta_{i}\cdot\alpha_{i}e^{-\lambda zk_{i}}+V^{i}_{M} \cdot\omega+\sqrt{\frac{R\cdot\beta_{i}\cdot\alpha_{i}e^{-\lambda zk_{i}}-V^{ i}_{M}(\omega+H_{i})-\gamma_{i}}{R\cdot\beta_{i}\cdot\alpha_{i}e^{-\lambda zk_{i}}}}} \tag{12}\]  
Due to the characteristics of the differential game solution, considering the characteristics of (10), this paper uses the form of \(V^{i}(M,t)=AM+B\) to solve, that is:  
\[V^{i}(M,t)=e^{-rt}\big{[}A(t)M+B(t)\big{]}. \tag{13}\]  
The above formula is obtained by deriving t and M, respectively:  
\[V^{i}_{M}=e^{-rt}\cdot A(t). \tag{14}\]  
\[V^{i}_{t}=e^{-rt}\Big{[}-rA(t)+\dot{A}(t)\Big{]}M+e^{-rt}\Big{[}-rB(t)+\dot{B} (t)\Big{]}. \tag{15}\]  
Simultaneous (11), (14), and (15) are obtained according to the corresponding coefficient:  
\[\dot{A}(t)=(r-\theta)A(t)+\sum\
olimits_{j\in N-m,j\
eq j}\chi c_{j}(t). \tag{16}\]  
\[\dot{B}(t)=rB(t)-R\cdot\frac{c_{i}(t)}{\sum_{i\in k_{i}}c_{i}(t)}\cdot\beta_{i }\cdot\alpha_{i}e^{-\lambda zk_{i}}\cdot c_{i}(t)-\gamma_{i}c_{i}(t)-A(t) \Bigg{[}\sum\
olimits_{i  
node at which the fog node reaches the optimal resource strategy is almost the same as the time node with the largest gain of its own; and the different fog nodes have different power, energy consumption, and hash power. Thus, it can be found that the smaller the power of the fog node, the more resources it needs to contribute; thus with the node with higher power, the resource contribution is relatively low. Observing its own benefits, the nodes with low power have higher returns because of the higher contribution, but the nodes with higher power are not necessarily lower.