4.1 PoW Consensus Algorithm
Proof of Work (PoW) consensus algorithm is one of the earliest and most common consensus mechanisms in blockchain systems, and the basic idea of the PoW consensus algorithm is to prove the workload of nodes by consuming computing resources. The specific process is shown in Fig. 5. In the supply chain information security sharing system, the PoW consensus algorithm verifies transactions and generates new blocks by requiring nodes to solve complex computing problems, thereby preventing data tampering and ensuring data transparency and credibility:
As shown in Fig. 5, the workflow of the PoW algorithm can be illustrated by a block generation process. First, the node receives the transactions in the network and records the transaction data. This transaction data will be collected and packaged into a block. The block contains the current transaction data as well as the hash value of the previous block, ensuring the continuity of the blockchain and the immutability of the data. Then it is necessary to calculate the proof of workload, during this process, the node needs to calculate the hash value. During the computation, the node checks whether the hash value is less than the preset target value. The target value is determined by the difficulty of the network; the higher the difficulty, the smaller the target value. The node needs to keep trying different random numbers until it finds a correct hash value. If the calculated hash is not less than the target value, the node increases the Nonce value and recalculates the hash value. This process is repeated until the node finds a hash value that satisfies the condition. Once found, the node will broadcast this new block to the entire network. After receiving this new block, other nodes verify it. Validation includes checking that the transaction data and Nonce values in the block are correct, and that the hash value is indeed less than the target value. If the verification is successful, the block is added to the main chain, completing a block generation process. If the verification fails, the block is rejected and the node that generated the block is notified to recalculate. Because hash computing requires a lot of computing resources, it is difficult for malicious nodes to tamper with blockchain data. Once a block is tampered with, its hash value will change, and the hash value of all subsequent blocks needs to be recalculated, which is very difficult.
Through the proof of workload mechanism, blockchain networks can ensure the uniqueness and immutability of transactions, preventing malicious nodes from conducting dual payment attacks. However, due to the fact that the PoW algorithm requires a large amount of computing resources for hash calculation, it leads to huge energy consumption and serious waste of computing resources.
4.2 PoS Consensus Algorithm
Proof of Stake (PoS) consensus algorithm is a mechanism that obtains verification block rights by holding assets (“rights”) in the blockchain system. PoS determines the validation and block out rights of nodes through the allocation of rights, which has the characteristics of low energy consumption and high efficiency.
The PoS consensus algorithm determines the block out rights of a node by the number of tokens held and the duration of token holding. Nodes that hold more tokens and hold them for a longer period of time are considered to contribute more to the system and are therefore more likely to be selected as outbound nodes. The core idea of PoS is that rights determine power, and its basic process is shown in Fig. 6:
Firstly, the equity value can be calculated, and the equity value (Stake) of each node is initialized and allocated based on the number of tokens it holds. The initial equity value is recorded in the status database of the blockchain, and corresponding blocks can be generated based on the data. Afterwards, a hash function can be calculated, using the current state of the blockchain and the hash value of the previous block as seeds to generate a random number. The selection threshold for each node can be calculated based on the node’s equity value and the total network’s equity value. The generated random numbers can be compared with the threshold of each node, and through this pseudo-random number generation algorithm, nodes that meet the conditions can be selected as block nodes. Formula (6) is as follows:
$$\:P\left(i\right)=\frac{Stak{e}_{i}}{\sum\:_{j}Stak{e}_{j}}$$
6
Among them, \(\:P\left(i\right)\) represents the probability of node \(\:i\) being selected, \(\:Stak{e}_{i}\) represents the equity value of node \(\:i\), and E\(\:\sum\:_{j}Stak{e}_{j}\) represents the total equity value of the entire network.
The selected node is responsible for packaging unconfirmed transactions and broadcasting them to the entire network. After receiving the new block, other nodes verify the validity of the block, including verifying proof of rights, transaction legality, etc. If the verification is successful, the new block can be added to the local blockchain. After the new block is generated, the system updates the equity value of the node according to the predetermined rules. Formula (7) is as follows:
$$\:Stak{e}_{i}\left(t+1\right)=Stak{e}_{i}\left(t\right)+Reward-Penalty$$
7
Among them, \(\:Stak{e}_{i}\left(t+1\right)\) represents the equity value of node \(\:i\) at time \(\:t+1\), and \(\:Stak{e}_{i}\left(t\right)\) represents the equity value of node \(\:i\) at time \(\:t\). \(\:Reward\) is the reward value, \(\:Penalty\) is the penalty value.
The PoS algorithm is far superior to the PoW algorithm in terms of energy efficiency, significantly reducing the waste of computing resources and energy. Additionally, PoS enhances system security by preventing malicious node attacks through proof of stake. Nodes holding more tokens have greater economic incentives to protect the blockchain’s security, and malicious behavior results in a reduction of their stake value, serving as an economic penalty. PoS uses a pseudorandom number generation algorithm to select block validators, thus avoiding the issue of computational power centralization and promoting broader node participation and decentralization. However, PoS systems may lead to early participants accumulating a significant portion of stake, potentially impacting system fairness and decentralization.
4.3 PoDaS Algorithm
The PoW consensus algorithm realizes the security and decentralization of the blockchain system through the competition of computing power, but it also brings about a serious waste of computing resources. The PoS consensus algorithm determines the block rights of nodes by equity value, effectively solving the problem of resource waste in PoW, and improving the energy efficiency and security of the system. However, there are also problems with initial distribution and concentration of equity. PoDaS introduces a FL mechanism, which takes computational consumption as part of the proof of workload, and combines the advantages of PoW and PoS to achieve optimization of resource utilization and fairness of consensus mechanism. The following can provide a detailed introduction to the specific principles and implementation steps of the PoDaS algorithm.
The core idea of the PoDaS algorithm is to use the computational consumption in the FL process as proof of workload, achieve consensus through the contribution of computing resources of nodes, and introduce proof of equity to increase the fairness and security of consensus. The flowchart of the PoDaS consensus mechanism is shown in Fig. 7:
The PoDaS algorithm is a consensus algorithm that improves PoW and PoS algorithms and combines them with FL mechanisms. In the PoDaS algorithm, local model training and uploading are required, and each node uses CNN to train the model based on local data and update the model parameters. Then, the trained model parameters (weights, biases, etc.) can be packaged and accompanied by proof of computational consumption, and uploaded to the blockchain network. Formula (8) is as follows:
$$\:{W}_{i}^{\left(t+1\right)}={W}_{i}^{\left(t\right)}-\eta\:\nabla\:L\left({W}_{i}^{\left(t\right)},{x}_{i},{y}_{i}\right)$$
8
Among them, \(\:{W}_{i}^{\left(t\right)}\) is the model parameter of node \(\:i\) in the \(\:t\) round, \(\:\eta\:\) is the learning rate, and \(\:\nabla\:L\) is the gradient of the loss function.
After receiving the uploaded model parameters at other nodes, it is necessary to update and verify the model to ensure the legitimacy and validity of the parameters. Formula (9) is as follows:
$$\:{L}_{val}\left({W}_{i}\right)=\frac{1}{{N}_{val}}\sum\:_{j=1}^{{N}_{val}}L\left({W}_{i},{x}_{j},{y}_{j}\right)$$
9
Among them, \(\:{L}_{val}\left({W}_{i}\right)\) is the validation error, \(\:{N}_{val}\) is the size of the validation dataset, and \(\:L\) is the loss function.
After the model validation is passed, it needs to be aggregated to form a global model. It is necessary to calculate the contribution of each node, weighted average the model parameters, and update the global model parameters, broadcasting them to the entire network. Formula (10) is as follows:
$$\:{W}^{\left(t+1\right)}=\sum\:_{i=1}^{N}{\alpha\:}_{i}{W}_{i}^{\left(t+1\right)}$$
10
Among them, \(\:{W}^{\left(t+1\right)}\) is the global model parameter, and \(\:{\alpha\:}_{i}\) is the calculated contribution weight of the node.
After completing the model update aggregation, it is necessary to obtain the equity value based on the computational consumption of each node in the FL process, and calculate the contribution proof of each node. It can record the computational consumption of each node during model training, including computational time, energy consumption, etc., and then allocate equity values based on the computational consumption as part of PoS. Formula (11) is as follows:
$$\:Stak{e}_{i}=\frac{{C}_{i}}{\sum\:_{j=1}^{N}{C}_{j}}$$
11
Among them, \(\:Stak{e}_{i}\) is the equity value of node \(\:i\), and \(\:{C}_{i}\) is the calculated consumption of node \(\:i\).
Then, using PoW calculation and PoS weighting, a mechanism that combines PoW and PoS, block rights are allocated. Firstly, each node performs workload proof calculations to solve mathematical problems. Then, based on the equity value, the PoW calculation results are weighted to determine the block nodes. Formula (12) is as follows:
$$\:P\left(i\right)=\frac{Stak{e}_{i}\times\:Po{W}_{i}}{\sum\:_{j=1}^{N}Stak{e}_{j}\times\:Po{W}_{j}}$$
12
Among them, \(\:P\left(i\right)\) represents the probability of node \(\:i\) being selected, and \(\:Po{W}_{i}\) represents the PoW calculation result of node \(\:i\).
By combining PoW and PoS and introducing a FL mechanism into the consensus mechanism, the PoDaS consensus algorithm can reduce the waste of computing resources in the PoW algorithm. By allocating block rights through equity values, the fairness of the consensus mechanism is ensured, and the security of the system is enhanced by calculating contribution proofs to prevent malicious node attacks. By optimizing the consensus mechanism, block generation time can be reduced, improving the overall efficiency of the system and facilitating real-time sharing and verification of supply chain information.