# A New Blockchain-Based Multi-Level Location Secure Sharing Scheme
## 4 Our Proposed Scheme
### Our Proposed Scheme
#### 4.2.2 Location Record  
In the location record phase, \(LP\) generates the location record \(Record_{LP}\) and records it into the blockchain. The data recorded in the blockchain have immutability. \(Fnodes\) and \(LD\)s can verify the data received by the record \(Record_{LP}\); the details are shown in Algorithm 2. In lines 2-3 of Algorithm 3, \(LP\) generates the leaf nodes of the Merkle Tree, \(Hash()\) denotes the hash function. In line 4, \(LP\) builds the Merkle tree \(VerMer\) using the leaf notes, \(Mer()\) denotes the function to generate a Merkle tree using leaf nodes. In line 8, \(LP\) broadcasts \(Record_{LP}\) containing the root node \(VerMer_{root}\) of \(VerMer\) and the hash value of the secret key \(k_{ud}^{1}\) to \(Miners\). \(Miners\) verify \(Record_{LP}\) with \(LP\)'s digital signature \(Sig_{LP}\), then record it into the blockchain through a consensus process, such as proof of work (POW). The consensus mechanism is not a focus of this paper; readers can refer to [15; 16; 17]. In lines 11-16 of Algorithm 3, \(Fnode\) decrypts the \(Info_{F}\) from \(LP\) and generates the Merkle tree \(VerMer^{{}^{\prime}}\) in the same way as \(LP\). \(Fnode\) verifies the virtual location data \(Z\) by checking whether the root node \(VerMer^{{}^{\prime}}_{root}\) of \(VerMer^{{}^{\prime}}\) is equal to the \(VerMer_{root}\) in \(Record_{LP}\). Further, \(Fnode\) verifies whether meets the conditions (2) and (3) mentioned in Section 4.2.1. The incentive and punishment mechanism illustrated in Section 4.4 can prevent \(LP\) from cheating \(LD\), colluding with less than 50% of \(Fnode\)s. In lines 19-21, \(LD\) decrypts the \(Info_{D}\) from \(LP\) and verifies the secret key \(k_{ud}^{1^{\prime}}\) by checking whether the hash value of \(k_{ud}^{1^{\prime}}\) is equal to the \(KeyHash\) in \(Record_{LP}\). ```
1:Virtual location data: \(Z\); The secret key: \(k_{ud}^{1}\);
2:Location record: \(Record_{LP}\); Bool varaiable: \(Accept_{Fnode}\), \(Accept_{LD}\);
3:\(LP\) execute:
4:for\(i=0\); \(i\leq N\); \(i++\)do
5:\(node_{i}\gets Hash(i||Z_{i})\);
6:endfor
7:\(VerMer\gets MER(node_{0},node_{1},\,...,\,node_{N})\);
8:\(KeyHash\gets Hash(k_{ud}^{1})\);
9:\(Info_{Re}\gets VerMer_{root}||KeyHash||Timestamp\);
10:\(Record_{LP}\gets PK_{LP}||Info_{Re}||Sig_{LP}\);
11:\(LP\) broadcast \(Record_{LP}\) to \(Miners\);
12:\(Fnode\) execute:
13:initialize\(Accept_{Fnode}\gets False\);
14:\(Z^{\prime}\gets Dec(SK_{Fnode},Info_{F})\);
```  
**Algorithm 3** Location record: pseudocode for computing the location record ```
13:for\(i=0\); \(i\leq N\); \(i++\)do
14:\(node_{i}\leftarrow Hash(i||Z^{\prime}_{i})\);
15:endfor
16:\(VerMer^{\prime}\gets MER(node^{\prime}_{0},node^{\prime}_{1}\),..., \(node^{\prime}_{N})\);
17:if\(VerMer^{\prime}_{root}=Record_{LP}.Info_{Re}.VerMer_{root}\)and\(Z^{{}^{\prime}}\) meets the condition (1) and (2) then
18:\(Accept_{Fnode}\leftarrow True\);
19:endif
20:return\(Accept_{Fnode}\);
21:LD execute:
22:initialize\(Accept_{LD}\leftarrow False\);
23:\(k^{1^{\prime}}_{ud}\gets Dec(SK_{LD},Info_{LD})\)
24:if\(Hash(k^{1^{\prime}}_{ud})=Record_{LP}.Info_{Re}.KeyHash\)then
25:\(Accept_{LD}\leftarrow True\);
26:endif
27:return\(Accept_{LD}\);
```

**Algorithm 3**_Cont._

#### 4.2.3. Location Sharing

In the location-sharing phase, \(LD_{n}\) uses a valid license to apply for the virtual location \(Z_{n}\) to a \(Fnode\). If \(LD_{n}\) has not obtained the secret key \(k^{p}_{ud}\) for location updates, \(LD_{n}\) can use the valid license to apply it to \(LD_{m}\), who has already obtained it. Then, \(LD_{n}\) uses the blockchain to verify the data received. The details are shown in Algorithm 3. In this phase, the data can be securely shared between \(Fnodes\) and \(LD\)s without the participation of \(LP\). In lines 2-3 of Algorithm 4, \(LD_{n}\) sends the \(Request_{n}\) containing \(Id_{License}\) to a \(Fnode\). \(Id_{License}\) is the block number of the block where the license is recorded.