## 4 The Proposed Scheme
### Privacy-Preserved Security Energy Trading
#### 4.2.4 Transaction
```
1:Input: \(\sigma_{(U_{i-1},U_{i})}\)
2:Output: Decision
5:if\(H(\chi_{i})=\omega_{i}and\xi_{i}=\xi_{now}+\Delta\)then
6:\(\text{Send}(U_{i-1}(\chi_{i},\omega_{i},\sigma_{(U_{i-1},U_{i})},\beta_{(i-1,i)}), \mathit{Accept})\)
7:else
8:\(\text{Send}(U_{i-1}(\omega_{i},\sigma_{(U_{i-1},U_{i})},\beta_{(i-1,i)}),\mathit{ Abort})\)
9:endif
```  
**Algorithm 8** Process of contract completion. ```
1:Input: \(\sigma_{(U_{i-1},U_{i})}\)
2:Output: Decision
1:Output: Decision
2:Output: Decision
3:if\(H(\chi_{i})=\omega_{i}and\xi_{i}=\xi_{now}+\Delta\)then
4:\(\text{Send}(U_{i-1}(\chi_{i},\omega_{i},\sigma_{(U_{i-1},U_{i})},\beta_{(i-1,i)}), \mathit{Accept})\)
5:else
6:\(\text{Send}(U_{i-1}(\omega_{i},\sigma_{(U_{i-1},U_{i})},\beta_{(i-1,i)}),\mathit{ Abort})\)
7:endif
```  
**Algorithm 8** Process of contract completion. ```
1:Input: \(\sigma_{(U_{i-1},U_{i})}\)
2:Output: Decision
3:if\(H(\chi_{i})=\omega_{i}and\xi_{i}=\xi_{now}+\Delta\)then
4:\(\text{Send}(U_{i-1}(\chi_{i},\omega_{i},\sigma_{(U_{i-1},U_{i})},\beta_{(i-1,i)}), \mathit{Accept})\)
5:else
6:\(\text{Send}(U_{i-1}(\omega_{i},\sigma_{(U_{i-1},U_{i})},\beta_{(i-1,i)}),\mathit{ Abort})\)
7:endif
```  
**Algorithm 9** Process of contract completion. ```
1:Input: \(\sigma_{(U_{i-1},U_{i})}\)
2:Output: Decision
4:Output: Decision
5:if\(H(\chi_{i})=\omega_{i}and\xi_{i}=\xi_{now}+\Delta\)then
6:\(\text{Send}(U_{i-1}(\chi_{i},\omega_{i},\sigma_{(U_{i-1},U_{i})},\beta_{(i-1,i)}), \mathit{Accept})\)
7:else
8:\(\text{Send}(U_{i-1}(\omega_{i},\sigma_{(U_{i-1},U_{i})},\beta_{(i-1,i)}),\mathit{ Abort})\)
9:endif
```  
**Algorithm 9** Process of contract completion. ```
1:Input: \(\sigma_{(U_{i-1},U_{i})}\)



#### 4.2.5 Close Channel

At the completion stage, the current account balances of [PERSON] and [PERSON] are \(\beta_{A}\) and \(\beta_{B}\), respectively. [PERSON] encrypts the value of \(\beta_{A}+\zeta\) with homomorphic encryption public key \(P_{Pub-p}\) to obtain \(M_{5}\) and sends it to KGC. Similarly, [PERSON] encrypts \(\beta_{B}\) to obtain \(M_{6}\) and sends it to KGC. KGC verifies the formula:

\[M_{5}\times M_{6}=Enc(\beta_{A}+\zeta)\times Enc(\beta_{B})=\beta. \tag{22}\]

If the equation is true, KGC returns the identification of the successful transaction to [PERSON] and [PERSON], and then forwards the encrypted transaction data to the TNB for broadcasting in the blockchain. The encrypted transaction data are then uploaded to the CSP with a signature from TBN. The data format stored in the CSP is:

\[Data_{CSP}=Enc(Data_{TX})||Pid_{[PERSON]}||Pid_{[PERSON]}||Sig_{TBN}(Enc(Data_{TX})|| Pid_{[PERSON]}||Pid_{[PERSON]}). \tag{23}\]

After being signed by TBN, the transaction data summary is published to the blockchain. The summary information contains a uniform resource locator (\(URL\)), and the corresponding file hosted on the cloud service can be obtained through the \(URL\). Figure 5 depicts the connection between the encrypted data kept in CSP and the data digest on the blockchain. By contrasting the summary data with the cloud data's hash value, the integrity and validity of the transaction information may be confirmed. The overall flow of transactions is shown in Figure 6. The format of the transaction information finally written into the blockchain is:

\[Data_{block}=H(Data_{CSP})||URL||Sig_{TBN}(H(Data_{CSP})||URL). \tag{24}\]

Figure 4: Core process of PCN-based trading scheme. ## 5 Performance Analysis

### Safety Analysis

The scheme put forward in this study is designed based on IBS and Paillier homomorphic encryption. Among them, Paillier homomorphic encryption is based on the complex residual problem. During the whole transaction process, both parties first encrypt the amount deposited in the common account and send it to KGC. KGC calculates the balance \(\beta=M_{1}\times M_{2}\) of the common account. Next, Alice encrypts the current balance and the current transfer amount and sends them to KGC. Similarly, KGC verifies the feasibility of the initial transaction by calculating whether \(M_{1}=M_{3}\times M_{4}\) is established.