Blockchain Based Smart Contracts for Internet of Medical Things in e-Healthcare

: The concept of Blockchain has penetrated a wide range of scientiﬁc areas, and its use is considered to rise exponentially in the near future. Executing short scripts of predeﬁned code called smart contracts on Blockchain can eliminate the need of intermediaries and can also raise the multitude of execution of contracts. In this paper, we discuss the concept of Blockchain along with smart contracts and discuss their applicability in the Internet of Medical Things (IoMT) in the e-healthcare domain. The paper analyses the dimensions that decentralization and the use of smart contracts will take the IoMT in e-healthcare, proposes a novel architecture, and also outlines the advantages, challenges, and future trends related to the integration of all three. The proposed architecture shows its e ﬀ ectiveness with average packet delivery ratio, average latency, and average energy e ﬃ ciency performance parameters when compared with traditional approaches.


Introduction
In 2008, a white paper was published by Satoshi Nakamoto [1] on Bitcoin, which primarily proposed a solution to the double spending problem found in economic transactions. The concept that formed the backbone for the functioning of Bitcoin was termed as Blockchain. Bitcoin amassed the economic market of more than 50 billion dollars [2] in less than ten years of its introduction and this massive success called for researchers to find more application areas for the concept. Blockchain thus got introduced into many areas of research and, in this paper, we will focus on how it can add on and change the prospects of the working of the Internet of Things through smart contracts.
Blockchain is a concept that enables the execution of transactions between two or more parties in a trustworthy manner without the need for any validating or trust authority in between. It has eliminated one entire tier, which was previously needed in order to transact or execute any instruction [3]. Blockchain works in a decentralized manner whereby a copy of data is found at every node and thus any new node can update itself from the network [4]. In recent times, Blockchain has covered the wide expanse of the market starting from finance, e-healthcare, public utilities, asset management, government regulations, real estate business, logistics, supply chain management [5]. This immense In this paper, the author's main goal is to outline how Blockchain works with smart contracts and how it can be integrated into the applications based on the Internet of Medical Things in e-healthcare so as to make informed choices about when and when not to use Blockchain-based contracts [22] in Figure 1. The paper also provides the major advantages that come along with this concept and the challenges that need to be addressed before we can move with the execution in a real world scenario [21].
Electronics 2020, 9,  However, when it comes to the Internet of Medical Things in e-healthcare, the Blockchain has to be slightly modified to work in a partially decentralized manner [20]. IoT applications work in a completely centralized manner, incurring significant consumption of resources, but Blockchain demands complete decentralization, which is not feasible to execute in most IoT applications [21]. A balance between the two needs to be achieved on the basis of the type of application that is being deployed. For applications that include billing, events, or some monetary changes, Blockchain can be directly implemented where a smart contract can dictate when and to whom service will be given and payment will be received.
Also, a smart contract has to carefully define as to when the contract will initiate and when it will be bought to a closure. Life cycle management issues have to be handled carefully so that we do not end up with incomplete hung contracts, which we cannot alter at a later date.
In this paper, the author's main goal is to outline how Blockchain works with smart contracts and how it can be integrated into the applications based on the Internet of Medical Things in e-healthcare so as to make informed choices about when and when not to use Blockchain-based contracts [22] in Figure 1. The paper also provides the major advantages that come along with this concept and the challenges that need to be addressed before we can move with the execution in a real world scenario [21]. We have up until now, elaborated upon the concepts of Blockchain, Internet of Medical Things, how they work and what the benefits are. However, there are many open questions that require answering before one can even think of implementing smart contracts for their IoMT application areas [23]. The potential key questions are as follows: Why use Blockchain-based smart contracts for IoMT applications? What is the novel way to transition to such system with respect to IoMT infrastructure? How will the front-end of the application maintain the data and process requests without compromising security? How to handle heterogeneity of devices and data before it is sent to smart contracts? How to balance the centralization and decentralization aspects of IoMT application with respect to the demands? We have up until now, elaborated upon the concepts of Blockchain, Internet of Medical Things, how they work and what the benefits are. However, there are many open questions that require answering before one can even think of implementing smart contracts for their IoMT application areas [23]. The potential key questions are as follows: Why use Blockchain-based smart contracts for IoMT applications? What is the novel way to transition to such system with respect to IoMT infrastructure? How will the front-end of the application maintain the data and process requests without compromising security? How to handle heterogeneity of devices and data before it is sent to smart contracts? How to balance the centralization and decentralization aspects of IoMT application with respect to the demands?
In order to answer all these questions, we propose a novel architecture for the implementation of smart contracts based on the Internet of Medical Things (IoMT) in e-healthcare to show the usage of applications. The IoMT end devices will be put in place, which will sense the required data with respect to the application demands. These nodes will be pre-programmed as to how they should send or process the data. We also outline the future research trends and the related security details.

Organization
The paper is structured as follows: Section 2 dives into the basic grounds on which Blockchain works in the e-healthcare, and ends with the application grouping and the benefits of using Blockchain. Section 3 elaborates the proposed architecture for the proposed approach. Section 4 includes the results and discussion of performance parameters. Finally, a conclusion has been drawn in Section 5 followed by recent technologies with future applications.

Literature Review
As the name suggests, Blockchain is made up of a chain of blocks, which are time stamped and are identified by a cryptographic hash [23]. A timestamp allows a sequential ordering of blocks and the hash is used to uniquely identify a block. The parent block of the chain is called Genesis [24], and further blocks all contain cryptographic hashes of previous blocks thereby maintaining the chain. Any node that has access to this reverse linked data structure can know the state of data and gain access to it anytime from anywhere [25].
The nodes in the Blockchain all have a unique set of public and private keys that is assigned to them when they join the network. The use of asymmetric cryptography lets us bring authentication, non-repudiation and integrity into the network. Whenever a transaction takes place, it is signed by the user's private key and is broadcasted to the neighbors. The transaction received by the other nodes are crosschecked and validated using the public key before they relay it further into the network. The invalid transactions are discarded. After an agreed upon period of time, all the transactions in that time window are accumulated and packaged into a time stamped block by some of the nodes, which are referred to as miners. When the new block is mined, other nodes verify whether the block contains valid transitions or not, if yes the block is broadcasted and if no, the block is discarded. This process keeps on repeating after predetermined intervals of time. The nodes execute in a trustless environment in the beginning and trust is slowly achieved by the emergence of transactions and blocks. As such all the transactions are validated before relaying and similarly the blocks are mined by nodes that have a certain trust level. So, it is said that the trust in a Blockchain emerges as a property within the network [26,27].
The nodes within the Blockchain have to agree upon a unanimous set of orderly transactions so that they can mine the block and update the Blockchain after periodic intervals. In an ideal scenario, agreeing on the block mined by a maximum number of nodes is the solution [28,29]. However, the Sybil attack, i.e., insertion of multiple nodes by a single user to bias the decision on mining the block, is a major threat. Once a block is mined using a miner, and transactions are locked, they cannot be reversed [30]. That is how Blockchain maintains security, as the asymmetric key combination is used to validate the transactions so that later on, no one can deny their role in the transactions. The body of the block comprises of the set of transactions along with the transaction counter where the size of transactions determines the number of transactions a block can hold [28,29].
According to Gartner's hype cycle, Blockchain is currently at its peak use where deployment and development are at the highest level possible. The majority of domains are working on its applicability in one field or other because of its numerous benefits. Many authors, however, believe in the traditional centralized architecture to be more effective for their use [30,31], which is still a better bet on multiple fronts. Anyhow, we present some application areas where smart contracts can be executed in a decentralized manner. Maintaining trust in the network is a priority for many parties and Blockchain Electronics 2020, 9, 1609 5 of 14 stands well on that, regardless of the other threats. Some of the application areas for the same are given as:
Due to huge usage of Blockchain in each and every application, authors have also proposed a secured healthcare system to provide security to the patient's confidential data over the cloud [33]. Various authors provided several frameworks to integrate security mechanisms to transfer data over the cloud [21,34], and later incorporate Blockchain in healthcare to transfer data over the cloud due to the problem of key management. The centralized key management system issues in healthcare for security have been replaced with decentralized Blockchain technology. Also, authors in [58] highlighted the use and role of Blockchain in the decentralized healthcare system where each trace or log file has been maintained properly [20]. This system replaced the brokerage and intermediate cost. In addition to this, authors have also proposed architecture for medical record exchange by introducing an advanced Blockchain technique. The proposed approach has been designed to meet the interactive norms and healthcare growth demands in new social forms. The authors claim an efficient approach by reducing the intermediates during the exchange of medical or patient records. Therefore, all the above-discussed literature motivates authors to show the use case of Blockchain-based e-healthcare applications and propose a novel architecture.

Proposed Architecture
In this paper, we are dealing with the emergence of IoT with healthcare with the help of a medical sensor and therefore have hybridized the IoT as the Internet of Medical Things (IoMT) [58]. The IoMT infrastructure boosts the healthcare sector over the internet and is named e-healthcare [59]. The proposed system model incorporated the application of smart contracts for the IoMT in e-healthcare, as shown in Figure 2.
Smart contracts can be used in the domain of IoMT where the number of nodes are increasing by millions with time [60] and the need to monitor and implement the contracts is becoming increasingly difficult. Blockchain can be used to ease this effort as it eliminates the need for intermediaries. The brokers or intermediaries present in the network for information validation and decision making consume a lot of resources such as computation and time. The Blockchain eliminates the use of these intermediaries by preparing the participating nodes itself to work collectively on their behalf [61]. Reduction in computations, time, and energy are the major factors for the motivation to integrate the Blockchain with IoMT in e-healthcare to increase the life of sensors nodes. Prime use of this lies in the asset management whereby assets can be embedded with smart contracts, which define who owns what at what point of time. Also, all the transactions work on a set of variable inputs, which can be defined deterministically as per the requirements. When implementing it with the Internet of Medical Things, the things in the network can work as an automated independent unit and produce results effectively.
Smart contracts can be embedded in the things where they will be having a unique address within the Blockchain network. Whenever set environment variables take on the value that agrees with the input criteria of a smart contract, then the corresponding code will execute. A smart contract can also Electronics 2020, 9, 1609 6 of 14 be triggered by addressing a transaction directly to it. As the chain is connected, the same sets of instructions are executed on the other nodes as well. All the transactions execute independently and once executed, they cannot be reversed so that the chain becomes tamper-proof and irrevocable [62]. In order to revoke any transaction, a counter transaction has to be performed or a hard fork needs to be done. Smart contracts implemented over Blockchain excel in applications where data management transactions are greater in number. This case is the ideal scenario for IoMT related services as there is a huge amount of data being generated and its processing is still limited [59]. Blockchain helps to automate this process leading to faster and efficient data execution, processing and storage.
security have been replaced with decentralized Blockchain technology. Also, authors in [58] highlighted the use and role of Blockchain in the decentralized healthcare system where each trace or log file has been maintained properly [20]. This system replaced the brokerage and intermediate cost. In addition to this, authors have also proposed architecture for medical record exchange by introducing an advanced Blockchain technique. The proposed approach has been designed to meet the interactive norms and healthcare growth demands in new social forms. The authors claim an efficient approach by reducing the intermediates during the exchange of medical or patient records. Therefore, all the above-discussed literature motivates authors to show the use case of Blockchain-based e-healthcare applications and propose a novel architecture.

Proposed Architecture
In this paper, we are dealing with the emergence of IoT with healthcare with the help of a medical sensor and therefore have hybridized the IoT as the Internet of Medical Things (IoMT) [58]. The IoMT infrastructure boosts the healthcare sector over the internet and is named e-healthcare [59]. The proposed system model incorporated the application of smart contracts for the IoMT in e-healthcare, as shown in Figure 2.  There are some points to be kept in mind while dealing with smart contracts which are listed as:

•
There are two types of models that can be used to implement smart contracts. One is a transaction based model whereby the prime focus is on executing transactions to which variables are fed as input. The second one is an account based model where the smart contract itself has an account and can take custody of the assets it is dealing with on the Blockchain. • All possible outcomes of the smart contract should be properly coded so that it becomes full proof and also avoids the possibility of falling into a hung state.

•
A smart contract has to be deterministic, i.e., it should always reach the same output given the same set of inputs.

•
Every node has the ability to crosscheck the transactions and the state of the system, which leads us to maintain consistency in the system.

•
Any code or transaction once executed cannot be reverted; however, we can make the changes by executing more code. This maintains a state of security in the system as it becomes tamper-proof and thus makes the overall chain more secure. In short, smart contracts are basically self-verifying, tamper-proof, and self-verifying scripts of code, which can run independent, automated procedures, provide enhanced level of security, eliminate the need of a trusted intermediary, and are cheap to implement [44]. Using the points of smart contracts, the working model of IoMT in e-healthcare is shown in Figure 3.
Smart contracts have emerged as entities that are completely autonomous and of which the behavior is totally predictable. So, before any node engages in the contract, they can know all about the terms and way of execution of the contract [35]. The main application of it comes for the networks where complete transparency is required. Such systems are currently validated by a third party as a trusted source. The Blockchain struck at this particular wheel and eliminated the need of trusted intermediaries [26]. Smart contracts have emerged as entities that are completely autonomous and of which the behavior is totally predictable. So, before any node engages in the contract, they can know all about the terms and way of execution of the contract [35]. The main application of it comes for the networks where complete transparency is required. Such systems are currently validated by a third party as a trusted source. The Blockchain struck at this particular wheel and eliminated the need of trusted intermediaries [26].

Working of Blockchain Based Smart Contracts for IoMT in e-Healthcare
The decentralized Blockchain-based smart contracts for IoMT in e-healthcare constitutes all the information related to each transaction of the patient with its records, such as doctor details, prescription list and medication details, and pathology lab test reports. Each record holder acts as a block where data move from one block to another block forming a chain. In this chain there is always a hash as the initial point and with one move a hash is always added with the message [63]. To implement Blockchain-based smart contracts for IoMT in e-healthcare an algorithm has been proposed as shown below:

Input:
Delay, Capacity, Energy, Data traffic Output: Data transmitted with the Blockchain in e-healthcare

Declaration of variables Step 2:
Set the threshold values of legitimacy for a miner with energy ( )

Set the threshold value of legitimacy for block with energy ( )
Step 4: if ( ≥ Threshold) Step 5: if ( ≥ Threshold) The hash of the block added to the data and authentication has been conducted with the next block in the chain.
Step 6: else Hash of previous block compromised and removed. //Go to Step 5

Working of Blockchain Based Smart Contracts for IoMT in e-Healthcare
The decentralized Blockchain-based smart contracts for IoMT in e-healthcare constitutes all the information related to each transaction of the patient with its records, such as doctor details, prescription list and medication details, and pathology lab test reports. Each record holder acts as a block where data move from one block to another block forming a chain. In this chain there is always a hash as the initial point and with one move a hash is always added with the message [63]. To implement Blockchain-based smart contracts for IoMT in e-healthcare Algorithm 1 has been proposed as shown below: Algorithm 1: Blockchain-based smart contracts for IoMT in e-healthcare

Input:
Delay, Capacity, Energy, Data traffic Output: Data transmitted with the Blockchain in e-healthcare

Begin { Step 1:
Declaration of variables Step 2: Set the threshold values of legitimacy for a miner with energy (E THM ) Step 3: Set the threshold value of legitimacy for block with energy (E THB ) Step 4: if (E THM ≥ Threshold) Step 5: if (E THB ≥ Threshold) The hash of the block added to the data and authentication has been conducted with the next block in the chain.
Step 6: else Hash of previous block compromised and removed. //Go to Step 5 Step 7: End if Step 8: End if Step 9: Data transmitted with the Blockchain-based smart contract for IoMT in e-healthcare } End The hash always recognizes the block because this hash is a very unique number. Also, there is always a hash of the previous block to make a chain within blocks. To understand the concept of Blockchain-based smart contracts for IoMT in e-healthcare, if a patient goes in for the treatment of a disease then all data will be stored in each block [28]. If anyone wants to tamper with the data then the Electronics 2020, 9, 1609 8 of 14 next hash will get changed. This will give the wrong hash to the next block. So, the malicious activity will come into notice of everyone, and if anyone wants successful tamper with the data, they will always need to tamper with all the subsequent blocks, which is practically not possible. This is how the Blockchain-based smart contract in terms of hash works in the IoMT e-healthcare. In the next section, we will discuss the role of the miner and performance analysis with the help of results [28].
The proposed algorithm has been used to compute the secured and authentic data transmission without any participation of a legitimate node. The proposed algorithm is beneficial where the security of private medical data is the top priority.

Results and Discussion
The proposed system has been implemented and simulated over MATLAB Simulink comprising an 8-GB RAM Intel(R) Core™ i5-7400 CPU among 3.00-GHz processor, and Windows 10 Operating System. In this paper, we have presented the smart contract based framework for the trusted blocks. In the simulation environment, we have mentioned each node with a block and each block ensures the trust between each block. Also, to test the proposed model, the compromised blocks have also been added in the e-healthcare system model but still the proposed framework has been used to provide the e-healthcare. Table 2 has been used to show the network parameter used in the MATLAB Simulink tool for the experiment. The whole grey attack has been used to show the legitimate nodes in the network and the level of trust in the network. The delay and capacity of each link participated in the chain between two consecutive blocks has been generated with the normal distribution as [1,100] in seconds (s) and bits per seconds (bits/s) [44]. The experiment has been conducted with three different sets of nodes with the formulation of three different sets of links. In each set of nodes, there are always known blocks, and the links in these blocks formulate chains [33]. A dataset with the information traffic size of 1024 Bits has been transmitted over a Blockchain with e-healthcare data. Each node (Block) is associated with 10 Joules of energy, which is the trust value for the measure of security. A threshold 6 Joules of energy associated with nodes (blocks) has been set as the least amount of blocks to be considered non-malicious nodes. Similarly, the miner (node) block has been set with the threshold of 4 Joules.
To perform the malicious activities in the network, each set of nodes (blocks) has been added with a set of malicious nodes, i.e., (5,25,50), as well as malicious miners, i.e., (10, 50, 100) due to the whole grey attack. In e-healthcare, whenever a doctor or medical practitioner gives the prescription list to a patient, these details are sent to each miner in the network. The complete experiment architecture with Blockchain is shown in Table 3.
Now the data generated from each block have been authenticated with the hash as well as miner data. If the authentication of the blocks failed then the legitimacy of the previous block is taken out. In this paper, the percentage improvement of the proposed algorithm has been compared the traditional conventional approach [63]. Here, various performance parameters have been considered in terms of average packet delivery ratio (throughput), average latency, and average energy. The detailed results and discussion have been discussed with the conventional method. Table 3. Network configuration with miners and number of nodes (blocks) with malicious nodes (blocks) and miners. )   100  5  10  200  25  50  500 50 100

Average Packet Delivery Ratio (Throughput)
In this performance parameter, the data traffic has been sent over all three different networks and the proposed algorithm has been compared with the existing traditional method. The results have been shown in Figure 4 for the performance parameter average packet delivery ratio and results show that the proposed algorithm outperforms well as compared to the exiting conventional method. This is because, whenever the data have been compromised, the next node is never able to authenticate (still this has been considered in our proposed method), therefore due to the large block degree, the data have been reversed from the malicious nodes. Now the data generated from each block have been authenticated with the hash as well as miner data. If the authentication of the blocks failed then the legitimacy of the previous block is taken out. In this paper, the percentage improvement of the proposed algorithm has been compared the traditional conventional approach [63]. Here, various performance parameters have been considered in terms of average packet delivery ratio (throughput), average latency, and average energy. The detailed results and discussion have been discussed with the conventional method.

Average Packet Delivery Ratio (Throughput)
In this performance parameter, the data traffic has been sent over all three different networks and the proposed algorithm has been compared with the existing traditional method. The results have been shown in Figure 4 for the performance parameter average packet delivery ratio and results show that the proposed algorithm outperforms well as compared to the exiting conventional method. This is because, whenever the data have been compromised, the next node is never able to authenticate (still this has been considered in our proposed method), therefore due to the large block degree, the data have been reversed from the malicious nodes. The proposed algorithm can approach the 100% packet delivery ratio but for this the authentication of blocks needs to be checked before moving forward the data to the next node.

Average Latency
The proposed method has been also simulated for the average latency (s) for the data transmission with a malicious and compromised node (blocks). The proposed method has been also compared with the existing traditional approach [48]. The results have been shown in Figure 5, which shows that the proposed algorithm has more average latency as compared to proposed algorithm. This might be the case because the data from the compromised block with malicious The proposed algorithm can approach the 100% packet delivery ratio but for this the authentication of blocks needs to be checked before moving forward the data to the next node.

Average Latency
The proposed method has been also simulated for the average latency (s) for the data transmission with a malicious and compromised node (blocks). The proposed method has been also compared with the existing traditional approach [48]. The results have been shown in Figure 5, which shows that the proposed algorithm has more average latency as compared to proposed algorithm. This might be the case because the data from the compromised block with malicious activities has been asked to retransmit for the next block and can be authentic with the help of a miner block.
Electronics 2020, 9, x FOR PEER REVIEW 10 of 14 activities has been asked to retransmit for the next block and can be authentic with the help of a miner block.

Average Energy Efficiency
The average energy efficiency (bits/s/joule) is also one of the major performance parameters to check the improvement in the average energy efficiency [44]. The selection of specific miners has been used for authentication as well as data transmission.
In the proposed approach (method), the average energy efficiency of the proposed method is more than the existing method as shown in Figure 6. This can be also due to the fact that the proposed algorithm will check each node (block) with a specific miner, which has the least threshold value of 4 Joules.

Average Energy Efficiency
The average energy efficiency (bits/s/joule) is also one of the major performance parameters to check the improvement in the average energy efficiency [44]. The selection of specific miners has been used for authentication as well as data transmission.
In the proposed approach (method), the average energy efficiency of the proposed method is more than the existing method as shown in Figure 6. This can be also due to the fact that the proposed algorithm will check each node (block) with a specific miner, which has the least threshold value of 4 Joules.
Electronics 2020, 9, x FOR PEER REVIEW 10 of 14 activities has been asked to retransmit for the next block and can be authentic with the help of a miner block.

Average Energy Efficiency
The average energy efficiency (bits/s/joule) is also one of the major performance parameters to check the improvement in the average energy efficiency [44]. The selection of specific miners has been used for authentication as well as data transmission.
In the proposed approach (method), the average energy efficiency of the proposed method is more than the existing method as shown in Figure 6. This can be also due to the fact that the proposed algorithm will check each node (block) with a specific miner, which has the least threshold value of 4 Joules.

Conclusions
In this paper, we discussed the working of a Blockchain, which has taken a very firm hold in e-healthcare in a very short span of time. We focus on how smart contracts over Blockchain can be used in the domain of Internet of Things and analyze what advantages and challenges it brings with itself. A comparison of the results of the proposed approach and the traditional approach shows that the proposed approach outperforms very well. The proposed approach shows that the average packet delivery ratio has an increase in delivery of the data packet because in the proposed approach no legitimate node is participating in the data transmission among the chains. Similarly, the same trend is being followed in the performance parameter of average latency and average energy efficiency. In the next section, future trends are discussed for more applications and other details.

Future Direction and Integration of Other Technologies
Various other cutting edge technologies can be implemented along with Blockchain, such as cloud computing [24,25], mobile edge computing [26], fog computing [27], big data analytics [28], artificial intelligence, and cyber physical systems [29]. The use of cloud computing can enable the extensive use of computation resources for additional processing. Various backend applications can be deployed on the cloud end as it scales very efficiently. Cloud storage can be used to store the Blockchain when its size increases and it becomes difficult for other nodes to handle it. Cyber physical systems provide a certain level of autonomous behavior where machines can interact with one another and behave accordingly. By using Blockchain-based smart contracts, this autonomous behavior can multiply as actions can be predefined. Such concepts can be easily integrated leading to manifold benefits. Big data analytics emerged in the last decade and has provided tremendous amount of business intelligence to people by analyzing large sets of data. Side by side analysis of the data being generated and stored in the cloud can provide the user with useful insights, which can help in increased efficiency and profits. Fog computing brings computation capability somewhat close to the end user by deploying nodes between the cloud end and user end. The managerial nodes proposed in the architecture also help in similar data processing before it is sent to the other end. Fog computing reduces latency, which can be a key factor for some use cases. Many other concepts are being introduced in the market now these days, such as use of software defined networking. Most of these can help in increasing service quality and data processing of user and devices respectively.