# Blockchain-Driven Generalization of Policy Management for Multiproduct Insurance Companies
## 5 Solution Implementation
### Anchoring Protocol Implementation  
The implementation of an insertion protocol into the Blockchain network is essential, given the decision to use Merkle trees for representing each policy. As previously defined, the model used involves each Merkle tree representing a complete policy, with each leaf node representing a specific piece of policy data. We have defined an insertion protocol whose primary objective is the construction of a Merkle tree based on the data of each policy. The root of each tree will be anchored to the Blockchain network. This ensures the integrity and auditability of each client's data. Moreover, it is crucial for verification purposes, particularly in resolving disputes between the insurance company and other network participants, especially the clients. The insertion protocol has been defined as follows:  
* Data Decomposition: The data that make up the policy are broken down into individual elements. Each element is treated as a leaf node of the tree. * Tree Generation: \(\bigcirc\) Each leaf node undergoes a hash function using the SHA-256 algorithm. \(\bigcirc\) The resulting hashes are grouped in pairs and are again subjected to the same hash function. The results form the nodes of the next higher level. \(\bigcirc\) This process is repeated iteratively until the root node is reached. * Insertion into the Blockchain Network: \(\bigcirc\) The root of the tree, which contains a hash summary of the entire policy content, is stored on the Blockchain through a transaction. \(\bigcirc\) The root of each tree serves as the insertion point or reference for the data of each stored policy. * Verification: \(\bigcirc\) Each specific data point in a policy can be verified by tracing the complete path from the corresponding leaf node to the root. \(\bigcirc\) It is also possible to verify the overall data integrity by comparing the computed root with the stored root. Algorithm 1 outlines the operation of the insertion protocol into the Blockchain network:  
```
1:Policy \(\leftarrow\) insurance policy data
2:/*Client executes*/
3:struct {policyData, merkleRoot} policyHash
4:for each data \(\in\) Policy do
5:leafNodeHash \(\leftarrow\) hash(data)
6:leafNodesList.append(leafNodeHash)
7:end for
8:merkleRoot \(\leftarrow\) buildMerkleTree(leafNodesList)
9:anchorToBlockchain(merkleRoot)
10:/*Merkle Tree Construction*/
11:buildMerkleTree(leafNodesList){
12:while leafNodesList.length > 1 do
13:newLeafNodesList \(\leftarrow\)[]
14:for i from 0 to leafNodesList.length1 step 2 do
15:if i + 1 < leafNodesList.length then
16:node \(\leftarrow\) hash(leafNodesList[i] + leafNodesList[i+1])
17:else
18:node \(\leftarrow\) leafNodesList[i]
19:end if
20:newLeafNodesList.append(node)
21:end for
```  
**Algorithm 1**Merkle Tree Generation and AnchoringTo construct the Merkle tree, the first step is to go through all the elements of the policy and calculate the corresponding hash for each. These calculated hashes are then inserted into the _leafNodeHash_ list. Using the _buildMerkleTree_ function, the tree is constructed. In this process, each pair of hashes from the previous list is combined, and their combined hash is calculated. This process is repeated until only a single hash remains, which will be the root node of the Merkle tree. The next function, _anchorToBlockchain_, involves creating a transaction with the tree root. This transaction is then sent to the Blockchain network to be stored. Finally, the _verifyPolicyData_ function allows for the verification of a policy's data. First, the hash of the data to be verified is calculated. Then, using a list of partial hashes, the tree root is calculated. If the calculated root matches the root stored on the Blockchain network, we can determine that the data are valid and has not been altered. The entry of policy data, hash generation, and Merkle tree creation are all performed at the level of the user DApp. Once all operations have been completed in the DApp, the smart contract is invoked to record the tree root on the Blockchain network.