# Resource Allocation on Blockchain Enabled Mobile Edge Computing System
## 3 Resource Allocation Problem
### Blockchain Model  
In this part, the mining process of PoL is introduced, along with the calculation of mining delay and the mining reward. Mining is the process by which blockchain transactions are validated digitally on the blockchain network and added to the blockchain ledger. For example, the mining process in Bitcoin system is the process of solving a hash problem, which means using hashing operations to obtain a specified answer. However, the meaningless hash puzzle will waste a lot of computing resources, which is quite insupportable in edge computing systems. In order to fit the edge computing system, [PERSON] et al. [26] proposed a new consensus algorithm: PoL. By just replacing the hash puzzles with the training task of neural networks, each service node trains the model locally in a fixed time, and when a training task is finished, the service node is required to encapsulate the learning results into the transaction so that other nodes can check if the training result is correct based on neural network parameters, output sets and loss functions. In this way, PoL can deter abuse attacks and save computing resources at the same time. However, the previous PoL consensus mentioned above is not that perfect, because by setting a fixed training time, the rate of block generation cannot adjust according to congestion level of blockchain network. To tackle this issue, we improved the PoL that the service node only needs to complete the given number of training sessions based on the given data sets, where the given number represents the training difficulty level. The system can adjust the difficulty level to change the rate of block generation. Assume that the neural network architecture in the training task is multilayer perceptron (MLP). First, the floating point operations (FLOPs) [39] of the Forward propagation and backward propagation is given. (1) Forward Propagation  
Let us consider the propagation process from layer \(i\) to layer \(j\). The output matrix \(S_{j}\) of layer \(j\) can be written in:  
\[S_{j}=W_{ji}*Z_{i} \tag{9}\]  
where \(W_{ji}\) represents the weight coefficient matrix between layer \(j\) and layer \(i\), and \(Z_{i}\) represents the output matrix of layer \(i\) after the calculation of activation function, such as sigmoid or Relu functions. So, \(Z_{i}\) can be given as:  
\[Z_{i}=f(S_{i}) \tag{10}\]  
where \(f\) represents the activation function mentioned above. Thus, the floating point operations of the forward propagation is \((j\times i+j)\)FLOPs. Furthermore, if the MLP obtains \(N\) layers, and this process will run \(N-1\) times. (2) Backward Propagation  
The backward propagation proceeds as follows. The error matrix of layer \(j\) is first calculated. If the layer \(j\) is the output layer of MLP, then it can be written as:  
\[E_{j}=f^{\prime}(S_{j})\odot(Z_{j}-O_{j}) \tag{11}\]  
where \(\odot\) represents the element-wise multiplication. If layer \(j\) is the hidden layer, and suppose layer \(k\) is the next layer of \(j\), then Equation (11) can be transferred to:  
\[E_{j}=f^{\prime}(S_{j})\odot(W_{kj}^{\mathrm{T}}*E_{k}) \tag{12}\]  
To update the weight coefficient matrix between layer \(i\) and layer \(j\), the \"delta\" weight matrix is calculated. \[D_{ji}=E_{j}*Z_{i}^{\mathrm{T}} \tag{13}\]  
where \(Z_{i}^{\mathrm{T}}\) is the transpose of \(Z_{i}\). Finally, the weight coefficient matrix is adjusted:  
\[W_{ji}=W_{ji}-D_{ji} \tag{14}\]  
The floating point operations of backward propagation is \((j+j+j\times i+j\times i)\)FLOPs for Equation (11), and \((j\times k+j+j\times i+j\times i)\)FLOPs for Equation (12). Based on all the equations mentioned above, the total FLOPs of the forward and backward propagation can be calculated by given a specific MLP model.