1. Introduction
The phenomenon of medical data is expanding more rapidly than ever. Every second, new data are created at a rate of almost 1.7 megabytes. These records must continue to be protected since they include sensitive personal data [
1]. A public tracking website for data breaches, Breach Level Index, says that since 2013, almost 9,198,580,293 data records have been lost or stolen [
2]. Over the past ten years, the amount of data has increased rapidly, but shoddy security procedures still put firms in danger of a data breach. Personal medical information is one of the main issues regarding data privacy. Additionally, computers today are full of vulnerabilities that hackers use to steal any data on them. According to a graph published by the National Institute of Standards and Technology (NIST), 18,378 vulnerabilities were discovered in 2021 [
3].
Table 1 depicts the NIST statistics of the number of vulnerabilities that are discovered each year.
Table 1 also shows that the number of vulnerabilities increases every year. In recent years, many systems have been developed to protect and secure personal medical data. Some of the related works suggest storing medical data in centralized storage. This idea provides a better way to protect the data, but two problems ensue. The first problem is having the space that permits storing a massive amount of sensitive data. The other problem is how to secure data despite unauthorized access. Therefore, the other related works use decentralized storage to store the data. Additionally, they suggest that the blockchain is the best tool for storing that data because the hacker must change all the ledgers in order to hack it. Therefore, using many blocks to store data makes it very difficult to be hacked. Additionally, hashing the new block with the transaction information and starting the hash with the fixed number of zero adds additional difficulty to obtaining any information. Any change of one block without changing all the previous blocks will be easily caught by the blockchain, so the data are secured.
This paper focuses on implementing a system that helps patients obtain their treatment without going to a physician in person. They have to use the Internet to send their vital signs. Following this, the physician sends the treatment to the patient through the Internet. This paper focuses on implementing a security system that protects medical data from being stolen or hacked by anyone. This paper also guarantees the transaction of the money from the patient’s wallet into the physician’s wallet after the physician sends the treatment to the patient.
This paper aims to contribute to the scientific field by proposing:
A blockchain security system that secures the medical data collected from the Internet of Medical Things (IoMT) system that we designed and implemented before [
4];
A blockchain security system that uses SHA-256 to hash the new block. We modified SHA-256 by using a run-length code algorithm to compress data;
A new smart contract technique that guarantees the transaction of the money from the patient’s wallet into the physician’s wallet after the physician sends the treatment to the patient.
The proposed system consists of two main parts. The first part creates a new block for each transaction using the information of the last block in the blockchain. The second part builds a smart contract between the physician and the patient to guarantee a successful transaction by automatically withdrawing the money from the patient’s wallet and transferring it into the physician’s wallet.
This paper is organized as follows: In
Section 2, the background of the blockchain and some related works are presented. The mathematical model of the blockchain and the proposed method are introduced in
Section 3. The results and discussion are presented in
Section 4. Finally, the conclusion is explained in
Section 5.
2. Background
Computer science and information technology have moved toward a new technology called the Internet of Things (IoT). The IoT field connects all objects surrounding us with each other using computing terms such as sensors, microcontrollers, transmitters, and receivers [
5]. The IoT has a lot of applications in many civil and military fields such as smart homes, smart cities, agriculture, and healthcare systems. Nowadays, the IoT has moved toward improving individual health. It is still in the first steps of advancement in the field of healthcare systems [
6,
7] under the denomination Internet of Medical Things (IoMT). The IoMT is maintained by connecting some of the medical sensors with microcontrollers. Now, it tries to connect all stakeholders of healthcare systems, such as physicians, patients, and hospital staff, despite their different locations. On the IoMT, data travel across the network to be sent from patient to physician to become easy for physicians to monitor their patients. However, hackers can attack these data over the network and can thus modify or steal them. Hence, securing these data is a big challenge faced by the IoMT.
Table 2 shows the security problem that the IoMT and the IoT face according to David Roe’s report [
8].
Blockchain [
9,
10,
11,
12] is a roster of ledgers which are called blocks. Each block is connected to the previous block using a cryptographic hash function [
9,
13]. Each block contains information about the timestamp, data, and previous block hashing [
13], so these blocks look like a tree with a hash tree root. The blockchain is a distributed database which executes transactions between both ends of the connection efficaciously, in a demonstrable and permanent way [
14]. It appears as peer-to-peer network which has a protocol for inter-node communication and verifying newly created blocks. When a block is created, no one can change any block information without the alteration of all the sequential blocks. In 2008, Satoshi Nakamoto was the first person to create the cryptocurrency Bitcoin with a public transaction ledger; he then developed the public ledger to the distributed ledger and called it blockchain [
14]. Blockchain helps Bitcoin to solve the problems of ordinary money such as double-spending problems and the problem of needing a central server or third party authority such as the bank [
15].
Today, blockchain is used in every field of computer science, especially in encryption, privacy, finance, healthcare, and economics. Blockchain can be used in healthcare; for example, it can be applied to electronic health records, drug traceability from industrialist to clients, clinical tests to rub fraudulent data adjustment, interoperability, etc. [
14,
16]. In 1993, Nick Szabo invented a new concept called a smart contract. Now, the smart contract is implemented in the blockchain used by the Ethereum coin. The idea of Nick Szabo was to introduce the protocol for the computerized deals which appears as a contract [
17]. He converted transaction clauses such as collateral into code by converting transactions into the concept of software and hardware, which can be achieved easily. After Szabo implemented the smart contract, he showed that the smart contract avoids the need of intermediaries which appear between transacting parties, such as the bank [
18]. Smart contracts are scripts saved on the blockchain. They can appear as stored functions in the database management system [
19]. The smart contract has some properties such as autonomy, trust, backup, savings, and accuracy. It can be used for the exchange of money, ownership, or anything that needs to be transparent without needing a middleman. It defines the principles and retribution of the transaction as the traditional contract does and also automatically ensures those commitments are maintained. When parties execute transactions between each other, this transaction is stored on blockchain as more than a simple record. This blockchain permits programs to be executed and stores the transaction as ledger: this is called smart contract. These programs are not smart and not used for the execution or monitoring of contracts.
Solidity is a high-level language in which syntax looks like Javascript. The Solidity language was created to execute smart contract code for the Ethereum virtual machine. Some examples of Solidity coding are voting, simple open auction, electronic currency, currency, safe remote purchase, and micropayment channel. The smart contract starts to appear with Blockchain 3. Before Blockchain 3, blockchain had the simple form of the smart contract.
Satoshi Nakamoto [
20] built the blockchain for financial transactions, but there is a new form of blockchain that works as a distributed database because it stores data about the transaction. These data are an official Bitcoin structure since 2014 [
20,
21,
22,
23] that can support 80 bytes of data. Scientists started to increase the data size. For example, with Multichain [
22], which increases the amount of data per transaction, and BigchainDB [
23], which uses RethinkDB [
24] as a database so there is no limitation in data size. Scientists started to use blockchain to spread slightly drilled sites online using machine learning frameworks between participating sites. This version of blockchain is called Blockchain 2.0. Blockchain 2.0 records the properties of the blockchain and smart contract [
25,
26,
27,
28]. The most famous application of Blockchain 2 is Ethereum [
29,
30], which is the decentralized database using a smart contract. Ethereum had been built using a Turing programming language that supports loop calculation, which does not exist in Bitcoin’s scripting language. Nowadays, a new version of blockchain called Blockchain 3.0, has been proposed to indicate applications beyond the economy, markets, and currency [
31].
In Blockchain 3.0, researchers are trying to adapt the blockchain to work with healthcare applications. For example, Irving et al. [
32] used blockchain as a distributed ledger to proof tamper and provide a proof to specified endpoints in the clinical trial. McKernan [
33] proposed a system that uses a decentralized blockchain to store genomic data. Jenkins et al. [
34] discussed how to increase data security using blockchain. There are some applications that are developed to store electronic health records using blockchain [
35,
36] and record health transactions [
37]. Tsung-Kuo et al. [
38] were the first to develop the system using blockchain to improve the security and privacy of healthcare data. They built a new model called model chain that adapts the blockchain technology with privacy-preserving machine learning and design a new algorithm to secure the new proof of information by blockchain.
There is significant recent research that starts to implement blockchain with the smart contract, for example, in [
39], the authors developed MedRec as a solution to collect the information about medical researchers, patients, and the treatment community. The system was built using blockchain and the smart contract to create a decentralized ledger to store health data. Clinical experiments of the scientific truthfulness of the results can be exposed to some problems such as missing data, selective publication, and endpoint switching. This problem had motivated by Nugent et al. [
40] to develop a method using blockchain with smart contracts to record endpoints in clinical experiments. In 2016, International Business Machines (IBMs) invented a system which uses blockchain to protect information from devices, such as the barcode-scanned events, which send data to blockchain ledgers to update and validate the smart contracts [
41]. Smith [
42] used blockchain and the smart contract to present a way to execute data transactions and change the data to make it easier to add them to the supply chain. Savelyevin [
43] discussed the difference between smart contract and contract law and discussed the key properties and features of the smart contract.
Shuai et al. [
44] proposed a methodical and thorough analysis of blockchain-enabled smart contracts. The authors presented a framework for smart contracts based on a revolutionary six-layer architecture. The authors also outlined the basic platforms and workings of blockchain-enabled smart contracts. The authors provided a number of common application scenarios. This paper aims to serve as a useful resource and guide for future research projects.
Adam et al. [
45] examined the recently published literature on decentralized governance systems and incorporated the insights it articulates on blockchain technology and smart contracts. The authors used a Shiny app to contain evidence-based obtained and handled data. They incorporated the key findings and strong connections connected to smart urban governments by analyzing the most recent and pertinent sources and utilizing screening and quality evaluation methods including AMSTAR, Dedoose, Distiller SR, ROBIS, and SRDR. The dimensions were used as data visualization tools for the original bibliometric mapping, together with the VOSviewer layout techniques.
Researchers have started using blockchain in medical fields, such as Kristen et al. [
46] who suggested using blockchain-based smart contracts to enable the safe analysis and administration of medical sensors in order to handle the protected health information (PHI) produced by these devices. The authors developed a system wherein the sensors interact with a smart device that collects smart contracts and logs all occurrences on a private blockchain based on the Ethereum protocol. Sending notifications to patients and medical experts, while also keeping a secure record of who initiated these actions, may enable real-time patient monitoring and medical treatments. This will automate the distribution of notifications to all interested parties in a HIPAA compliant way and address various security flaws related to remote patient monitoring. Additionally, Ashutosh et al. [
47] present the idea of blockchain and smart contracts and how they may be used in the Internet of Medical Things (IoMT) in the field of electronic healthcare. In addition to outlining a unique architecture, this paper analyzes the directions in which decentralization and the usage of smart contracts will take the IoMT in e-healthcare as well as the benefits, difficulties, and upcoming trends associated with their combination. When compared to conventional methods, the suggested architecture exhibits superior performance in terms of average packet delivery ratio, average latency, and average energy efficiency.
Khatoon [
48] examined current research and blockchain-based applications for the healthcare sector. Additionally, for better data management, she suggests several processes for the healthcare sector utilizing blockchain technology. The Ethereum blockchain platform has been used to develop and implement a variety of medical processes, including complicated surgical and clinical trial procedures. Accessing and controlling a sizable amount of medical data are also included. The cost of implementing the medical smart contract system’s workflows for managing healthcare has been evaluated in terms of a feasibility study, and this paper’s thorough presentation of that study has provided a cost estimate for said system. This paper will make it easier for many medical system participants to provide better healthcare services while reducing costs.
Baiju et al. [
49] used a blockchain design built on the Ethereum blockchain. Their system uses truffle as a building block. With the aid of the consensus calculation, smart contracts are used to manage the availability of the EMRs. The contracts are used inside the system to monitor the transactions and calculations involved in the management of customer information. Since medical information is quite different from cryptocurrencies and NFTs, which are resources that have been used with blockchain, we must fundamentally alter our methods to make it feasible. Their system keeps the data using the Dapp wallet address and accessing them and making changes to the patient’s information is necessary. When the data is input, it is tunneled over the API to an operational logistic regression model, which analyses the data supplied via the API to ascertain the patient’s health status and returns the data after the model has been calculated.
3. The Proposed Secure Medical Blockchain Model
The implementation of our work consists of two parts. The first part introduces the implementation of the blockchain. The second part introduces the implementation of the smart contract.
Figure 1 shows the framework of the proposed system.
Figure 1 shows that the proposed system’s framework consists of two main parts. The first part is the implementation of the blockchain to secure the data. The second part is the implementation of a smart contract to transfer the money from the patient’s wallet into the physician’s wallets without using a bank or any middleware.
Figure 1 also shows the patient wanting to ask the doctor about treatment for his status. Then, the proposed system creates a new block using the last block. Therefore, the system creates a new smart contract between physician and patient by obtaining the patient’s vital signs from the IoT healthcare system described in [
4]. After that, the doctor examines the patient’s vital signs and sends the treatment to that patient through the smart contract. Finally, the smart contract automatically sends the money from the patient’s wallet into the physician’s wallet. The implementation of blockchain medical records must consist of doctors, patients, and records that contain information about each interaction between doctors and patients.
For more clarification,
Figure 2 shows the application scenario of the proposed system. The previous IoMT that we developed before collects the patients’ vital signs. Therefore, the collected data are sent to our microcontroller. The microcontroller sends a request that asks the physician to treat the patient. If the physician agrees, the collected data are sent directly to the blockchain to create a new block. The new block is created using the information of the previous block. After that, the blockchain inserts transaction information into that block and sends data to the smart contract to build a new contract. Then, the smart contract withdraws the money that a physician retrieves after he sends the treatment from the patient’s wallet. Therefore, the physician sends the treatment to a smart contract which then sends it directly to the patient. Finally, the smart contract transfers the money into the physician’s wallet.
Figure 3 shows the basic idea of the blockchain.
Figure 3 shows each patient asking the doctor for treatment. Then, the physician agrees to helping the patient. As a result, the blockchain system starts to create the block with the information about the transaction, the creation time of the block, and the previous and current hash code. The current block is connected to the last block by hashing the information of the current block together with the previous hash code. The new block hashes using the SHA256 algorithm. We also use run-length code to compress the data of the transaction. Then, this block is added to the chain. After that, it is difficult to hack or modify the patient’s information because to hack that block, the hacker must extract all the previous blocks.
Since a blockchain is a series of blocks, we must first define a block. A block is the primary piece of data that is kept in a blockchain. The blockchain’s function is to store blocks in a secure way. A generic block is indicated by the letters B
r. A block is created when there is a transaction between two entities. Block B consists of many entries with a size N, so a Block can be defined as follows:
A mathematical problem called the proof-of-work is used to establish a connection between two blocks. This link will appear in the second block’s header. A miner is a person who attempts to identify the proof-of-work. Let us take into consideration two blocks, namely Bp and Bnew, as well as a quantity known as bits and indicated as b. A goal number may be calculated immediately from b, which measures how challenging the proof-of-work is. This target is a 64-digit hexadecimal number that has a significant number of zeros as its leftmost digits, such as:
00fe49cecc0b2f766505fbbafbaa93671f04e680a8b633ff2df529fcbd05b401b8.
The hashing function algorithm that we use in the blockchain is sha-256. We shall define the hash of a particular block shortly after assuming the hash of the preceding block, Hashing (Bp), is known. The equation that we used to calculate the hashing of the new block is as follows:
where ⊕ denotes the concatenation operation and timestamp(t) denotes the current time.
When the proof-of-work for the blocks Bp and B has been solved, we may specify block B’s header using the notations shown above:
Algorithm 1 shows the main steps needed to create the blockchain and the content of each block.
Table 3 shows the notations that are used in the algorithm.
The algorithm transfers the treatment fees into the physician’s account. In order to hash a new block in the blockchain, SHA256 is used. The following algorithm shows the algorithm of the SHA256 hashing function that the proposed system used. Algorithm 2 shows that the run-length code algorithm is used to compress data.
Algorithm 1. Private medical blockchain algorithm |
1: . 2: is created. 3: . 4: . 5: . 6: M checks BS to ensure nothing is changed or missing. |
The implementation of the smart contract consists of a patient and a physician. The main idea of the proposed system came from the evolution of the healthcare field that guarantees the best care for the patient but does not guarantee that the physician obtains the compensation related to his efforts; therefore, the implementation of a smart contract that serves the healthcare field is critical. The proposed system allows the patient to offer the doctor a certain payment in exchange for treatment, to which the doctor can then agree or disagree. When the doctor agrees to treating the patient, the system creates a new smart contract. Therefore, smart contracts monitor the process of treatments. When the physician sends the treatment to the patient, the money is automatically transferred into the physician’s wallet. The money is returned to the patient’s wallet if the doctor does not treat the patient.
Algorithm 2. Hashing function of the blockchain algorithm |
Algorithm Hashing (O) 1: Convert O into A. 2: A is divided into with a size of 512 bit for each B. 3: If < 512, 4: do → expand to 512 by adding padding bits. 5: is divided into smaller with a size of 32 bit for each B. 6: Iteration = 0. 7: While iteration < 64, 8: do → Apply C to each block. 9: Return H. |
Figure 4 shows that the patient must initiate the contract by asking the physician to treat him and by determining the payment for the treatment. The physician examines the offered payment and gives his opinion about the contract. If the physician agrees to treat the patient, the amount of money that the patient determined is transferred into the smart contract system from the patient’s wallet. The smart contract monitors the physician to verify whether the doctor sends the treatment. If the doctor sends the treatment, the smart contract transfers the money into the doctor’s wallet. However, if the doctor does not send the treatment, the money is returned back to the patient. Algorithm 3 describes the steps of our implementation.
In our related work [
4], the patient’s digital signature is used for authentication before the client delivers vital signs to the receiver. If the authentication succeeds, the system sends the patient’s vital signs to the physician.
Algorithm 3. Medical smart contract algorithm |
1: starts thewith the initial amount of money and offersto treat him and the statues ofbecome. 2: Ifagrees to, the status ofbecomes. 3: The amount of money thatdetermined is transferred to. 4: SM starts monitoringto verify whethersends the treatment to. 5: Ifsends the treatment to, the SM transfers the amount of money oftoand the status ofbecomes. 6: Ifdoes not send the treatment to, the SM returns the amount of money back fromtoand the status ofbecomes. |
4. Experimental Results of Blockchain with Smart Contract
Every system user has a wallet and the address and balance of his wallet.
Table 4 shows wallets that exist in our system.
If the patient wants to request any treatment from any physician, he must ask the physician for treatment and transfer money to the physician after treatment. The system verifies the balance of the patient to ensure that the patient has the money that the patient specified; the physician then starts to create a block.
Table 5 shows the offer of the patient and the block creation by a physician.
When the physician accepts the transaction, the system creates the block and hashes it by using the information of the transaction and the previous hash. Then, the doctor starts replying to the patient.
Table 6 shows the physician’s reply to his patient.
When we verify the balance of the patient and physician, the physician’s balance must have increased with the amount specified for the treatment and the patient’s balance must decrease by the same amount.
Table 7 shows the users’ wallets after the transaction.
Assuming that the amount of treatment fees is 100 pounds, the balance of the physician’s wallet is increased by 100 pounds and becomes 150 pounds. This is because the doctor’s wallet had 50 pounds before the transaction. Additionally, the balance of the patient’s wallet becomes zero because it is decreased by the amount of the transaction.
Table 8 shows the status of the blockchain after the previous transaction.
The first block is called genesis block. It does not have any transactions but we use it to create the hash of our second block. This is because the second block creates its hash using the previous hash. Every block contains the transaction from patient to doctor and vice versa. If the doctor does not accept the transaction, the transaction becomes a pending one and neither block nor hash is created. The following
Table 9 shows the block state when the doctor does not accept the transaction.
The system monitors the blockchain to verify if there is any change in the blockchain, in which case the system replies that there is an error.
In order to guarantee the rights of physician and patient, a smart contract is implemented into the blockchain. We build a method for medical smart contracts and test it using the Solidity programming language in which its compiler is built on the Remix-Ethereum website. The patient starts to deploy the contract and determine the amount of money in it through the value text box. After the patient deploys the contract, the contract in the created state takes a number zero in the code. The first row in
Table 10 shows the output of the system when the status of the contract is created.
The first row in the previous table shows the address of the patient’s wallet, the address of the doctor’s wallet, and the balance of the patient’s wallet. Additionally, it shows the state of the contract and the amount of the money in the contract. Now, the doctor can accept or refuse the contract. He accepts the contract by pressing confirm purchase button. If the doctor disagrees, the contract is not created. If the doctor agrees, the contract is created and the status of the contract becomes locked and takes the value one in the code. No one can change this contract now.
After the doctor accepts the contract, the transaction between patient and doctor becomes private by using a hash function between sending data. The following
Table 11 shows the hashing message.
The smart contract system begins to monitor the transaction between patient and doctor. If the doctor does not send the treatment after some time, the patient can abort the contract by pressing the abort button. Hence, the status of the contract becomes inactive and takes the value 2 in the code. The second row in
Table 10 shows the system in an inactive state when the patient aborts the contract.
When the patient aborts the contract, the getter button is 100 units because the money is returned back to the patient due to its balance not changing. However, if the doctor sends the treatment, the smart contract starts to send the data to the doctor’s wallet and the patient’s balance is decreased. The third row in
Table 10 shows the system in an inactive state when the doctor sends the treatment. The fourth row in
Table 10 shows that when the physician sends the treatment to the user, the money is transferred from patient to doctor.
In the proposed method, we modified the hashing function by using run-length code to compress data. Therefore, the time complexity of our proposed system is O(n) if the hashing code does not start with some zeros, where n is the size of the hash function. If the hash code for each block starts with a d number of consequence zeros, the time complexity will be O(n + d). By compressing data with run-length code, the time is reduced.
The time complexity for creating a smart contract is O(1) because it does not take much time to build a smart contract.
The following
Table 12 shows the comparison between the different versions of the blockchain and some related work with our proposed system.
In the related work, we explain that Blockchain 2 uses Ethereum, as most of the related work. Therefore, the parameter value of Blockchain 2 is similar as it exists in the related work. The only difference is that the related work tries to protect medical data.
Table 12 shows that the proposed system takes less than one second to transfer money from a wallet into another. The proposed method is scalable because it uses a decentralized database.
Table 12 also shows that transaction time takes from 1 to 2 s, while all versions of the blockchain take more than that time. Additionally,
Table 12 shows that the time complexity of our proposed system is better than all the recent methods, except for Blockchain 3. Blockchain 3 takes the same time complexity as our proposed method. However, the proposed method takes less time than Blockchain 3 because the proposed method uses run-length code to compress data. Additionally,
Table 12 shows that all methods need O(n) space complexity to create any number of transactions, where n represents the number of transactions. The following figure shows the amount of time needed by all recent methods and our proposed system to create a specific number of blocks.
Figure 5 shows that our proposed method can create many blocks in 1 min. For example, if there are 1000 transactions that happen, we want to create 1000 blocks. In this case, our proposed method will take 1500 s (25 min) to build those blocks. By comparison with other blockchain versions, Blockchain 1 will take 180,000 s (50 h) to create the 1000 blocks. Blockchain 2 will take 14,000 s (4 h) to build the same number of blocks. Blockchain 3 will take 2000 s (34 min) to create 1000 blocks. Our proposed method performs better because it uses run-length code to compress data, so it takes less time to create blocks than other methods.
Figure 5 also shows that our proposed method builds any number of blocks in as little time as possible.
Figure 6 shows the time that each method takes to transfer money from patient to physician.
Figure 6 shows the comparison between all the recent methods and our proposed method when many deposit processes need to happen at the same time. For example, if 500 deposit processes are needed, Blockchain 1 needs 6250 s to transfer the money from 500 patients to 500 physicians. Blockchain 2 needs 2500 s to transfer money from 500 patients to 500 physicians. Blockchain 3 and our proposed system take 8 s to send the money from 500 patients to 500 physicians.
Figure 6 shows that the time that the proposed method takes to deposit money into a physician’s wallet is similar to that of the blockchain 3, but it is less time than the other versions take.