# Blockchain-Based Resource Allocation Model in Fog Computing
## Materials and Methods
### Problem Formulation and System Model
Once the rights of the consensus committee are too high, and there are malicious nodes mixed in it, it will cause more significant harm to the entire blockchain system. According to the approach introduced in [44], the improved DPoS algorithm can be applied to the environment of the alliance chain. Specifically, the consensus program includes: setup, proposal, consensus identity generation, voting, and counting of several processes. * Setup: When a new node \(FNode_{i}\) (whose public and private key is \(\langle K_{i}^{P},K_{i}^{s}\rangle\)) is added to the system, the newly joined node first updates its public key to the member public key \(MK_{i}^{P}\); next, the new public key will be used to calculate the membership signature \(MS_{i}\): \[FN\Big{|}MS_{i}=\Big{(}a\cdot K_{i}^{S}\Big{)}\times H\Big{(}MK_{i}^{P},i\Big{)},\] (1) where \(a_{i}=h\Big{(}K_{i}^{P}\parallel K_{1}^{P}\parallel\cdots\parallel K_{n}^{P} \Big{)}\). When the federation chain receives the information \(\langle K_{i}^{P},MS_{i}\rangle\) disclosed by the new node, each consensus node needs to update its member public and private key to \(MK_{i}^{S}\): \[MK_{i}^{S}=\sum\
olimits_{i=1}^{i=n}\Big{(}a\cdot K_{i}^{S}\Big{)}\times H \Big{(}MK_{i}^{P},i\Big{)},\] (2)
* Proposal: The types of proposals in the consensus phase mainly include the consensus node in the alliance chain, which allows the new node to join the new consensus member proposal in the alliance, \(prop_{craft}\); proposal to package \"transaction information\" into blocks and upload them to  
Figure 2: Fog node contribution resource behavior schematic diagram. the alliance chain, \(prop_{block}\); proposal to deal with forks and eventually reach a consensus, \(prop_{fork}\); proposal to discover and punish a malicious user, \(prop_{punishment}\). * Consensus identity generation: When the consensus node of the alliance chain receives the proposal to create a new consensus member, it verifies that the random function calculates the condition of participating in the consensus committee according to its stack. If the condition is met and the identity is legal, the consensus vote is performed. The specific algorithm is shown in Algorithm 1. ```
Input: \(w_{inf}\) (The influence of the fog computing node, stake); \(\langle K_{i}^{p},MS_{i}\rangle\) (Node information); seed: \(H_{pre}\) or \(H_{pro}\); \(prop_{creat}\) Output: MCC: Membership of Consensus Committee or Null
1:\(MCC\gets empty\); \(p\gets w_{inf}/\langle K_{i}^{p},MS_{i}\rangle\); \(i\gets 0\)
2:\(\langle hash,proof\rangle\leftarrow VRF_{pk}(Send\parallel prop_{creat})\)
3:\(index\gets hash/2^{len(hash)}\)
4:whileindex\(\
otin\left[\sum_{k=0}^{i}Block\left(k,\langle K_{i}^{p},MS_{i}\rangle,p\right),\sum_{k=0}^{i+1}Block\left(k,\langle K_{i}^{p},MS_{i}\rangle,p\right)\right]\)do
5:\(i++\)
6:endwhile
7:if\(i>0\)then
8:\(MCC\)-\(pk\leftarrow\langle K_{i}^{p},MS_{i}\rangle\)-\(pk\); \(MCC\)-\(i\gets i\)
9:\(MCC\)-\(hash\gets hash\)-\(pk\); \(MCC\)-\(proof\gets proof\)
10:return MCC
11:else
12:return null
```  
**Algorithm 1** Algorithm of creating a new node in Delegated Proof of Stake (DPoS). * Voting: consensus nodes with legal status in the alliance chain vote for consensus based on the type of proposal received, as shown below: \[Sig_{i}=K_{i}^{S}\times H\left(MK_{i}^{p},prop\right)+MK_{i}^{S},\] (3) Then package its consensus identity and the hash value of the proposed result into \(\langle MCC,h(prop),Sig_{i}\rangle\), and broadcast to other nodes in the alliance chain. * Counting: The node of the alliance chain collects the consensus votes received. When the number of votes of a proposal exceeds the threshold set by the system and the signature set is verified, the consensus node reaches a consensus. After the DPoS consensus process is over, the consensus node will package the proposed \"transaction information\" into blocks and upload them to the blockchain system database. The new block is now established.