## 4 System Methodology
### Proposed System Workflow
#### 4.2.2 Phase 2: Registration and Key Generation  
Registration and key generation process is performed as follows:  
* Both \(SM_{i}\) and MDMS are registered in the blockchain using their hash identities in this phase. \(SM_{i}\) computes its \(H\!D_{SMi}\) and sends a registration request message to \(DC_{j}\) to obtain its public and private key pair. Here, request message = (\(H\!D_{SMi}\), reg_req);
* \(DC_{j}\) relays the request message to the smart contract. Smart contract executes a query in the database to verify if \(H\!D_{SMi}\) = \(H\!D_{SMi}\). If the \(H\!D_{SMi}\) exists, then the registration is executed to generate the corresponding key pair (\(Pr_{SMi}\), \(Pu_{SMi}\)). Otherwise, the request is declined. The key pair is derived from ECC curve [29] as described in Algorithm 1;
* The registration process of MDMS is similar to \(SM_{i}\). After successful registration, the \(H\!D_{SMi}\) is provided to the MDMS along with the key pair (\(Pr_{MS}\), \(Pu_{MS}\)). ```
0:HID of \(SM_{i}\)/MDMS
0:Pre-stored \(H\!D^{\prime}\) of \(SM_{i}\)/MDMS in \(DB\)
0:(\(Pr_{r}\), \(Pu_{u}\)) for registered \(SM_{i}\)/MDMS
1:For each \(SM_{i}\)/MDMS do
2:Query for \(H\!D^{\prime}\) records in \(DB\)
3:If \(H\!D==H\!D^{\prime}\) then
4: Execute registration () (select random number \(x\)\(\xi\)\(Z_{p}\)//using ECC curve
5: \(P_{r}=x\)
6: \(P_{u}=x\).G
7: Return (\(P_{r}\), \(P_{u}\))]
8:Else
9:Decline

Figure 5: Workflow of proposed system model to illustrate the information transaction and validity from smart meter to permissioned blockchain via smart contract. The whole process is conducted using a secure private channel. Before starting each new session, the devices generate a new key pair while they are offline and not interacting with each other. In this state, before taking part in any session, each of them are registered (if already registered, then smart contract checks the pre-registration) and the corresponding generated key pair are distributed over a secure private channel. The generated public keys of \(SM_{i}\) and MDMS are broadcasted throughout the full metering system and blockchain. Hence, anyone can avail these public keys. #### 4.2.3 Phase 3: Data Transaction and Validation

The data transaction and validation process follow the following steps:

* Create Transaction: Each \(SM_{i}\) collects electricity usage data (UD) and creates an electricity usage report with the timestamp, \(\tau\). The formatted usage report is encrypted using the public key of MDMS. The final transaction is created using the encrypted usage report E(UD), its hash, timestamp, \(HID_{SMi}\), and the ECDSA signature of the sender \(SM_{i}\). Table 2 provides the final transaction format of the collected usage data;
* Transaction Request Validation: \(DC_{j}\) passes the message again to SC after receiving the transaction request message. SC checks the \(HID_{SMi}\) to ensure the sender's pre-registration and verifies the signature. If the signature is verified, \(DCj\) sends the encrypted message to the peers for endorsement. Peers respond to the proposal, append signature as an endorsement, and send it back to the \(DC_{j}\). After receiving the response, \(DC_{j}\) sends the encrypted transaction to the ordering service with the peer endorsement. The ordering service validates the transaction using PBFT consensus algorithm;
* In the ordering phase, after receiving a transaction request, the leader node generates a new block with the transaction information, which is considered a candidate block. For verification as well as auditing, the leader node broadcasts the block to other nodes. Nodes audit the block data after receiving it and broadcast the results with a hash to the rest of the network. Each node compares the audit results with the others. Nodes reach a consensus on the candidate block and send the audit and comparison results back to the leader. If the leader obtains \(2f+1\) responses, then the candidate block is finalized and appended as a new block in the blockchain.