A Secure Blockchain Platform for Supporting AI-Enabled IoT Applications at the Edge Layer

In this study, a new blockchain protocol and a novel architecture that integrate the advantages offered by edge computing, artificial intelligence (AI), IoT end-devices, and blockchain were designed, developed, and validated. This new architecture has the ability to monitor the environment, collect data, analyze it, process it using an AI-expert engine, provide predictions and actionable outcomes, and finally share it on a public blockchain platform. For the use-case implementation, the pandemic caused by the wide and rapid spread of the novel coronavirus COVID-19 was used to test and evaluate the proposed system. Recently, various authors traced the spread of viruses in sewage water and studied how it can be used as a tracking system. Early warning notifications can allow governments and organizations to take appropriate actions at the earliest stages possible. The system was validated experimentally using 14 Raspberry Pis, and the results and analyses proved that the system is able to utilize low-cost and low-power flexible IoT hardware at the processing layer to detect COVID-19 and predict its spread using the AI engine, with an accuracy of 95%, and share the outcome over the blockchain platform. This is accomplished when the platform is secured by the honesty-based distributed proof of authority (HDPoA) and without any substantial impact on the devices’ power sources, as there was only a power consumption increase of 7% when the Raspberry Pi was used for blockchain mining and 14% when used to produce an AI prediction.


I. INTRODUCTION
Over the years, IoT systems have grown rapidly and increasingly used by many different organizations and users within different sectors, such as healthcare and industry. The presence of IoT in these sectors has offered organizations and governments realistic opportunities to improve economic situations by enhancing its growth over the years and provides an easy way to improve people's lives in general. This is because of the vast amount of useful information provided by IoT systems that can be used for better decision-making. However, organizations often handle this data by creating IoT systems that rely on a central data-processing entity, such as the cloud, for securing and managing IoT devices and processing the data collected by these devices.
The associate editor coordinating the review of this manuscript and approving it for publication was Jiafeng Xie.
In recent years, IoT systems' implementation has significantly increased (and this will continue in the future). This increase, in turn, has provoked the re-emergence of the AI as the main means of data analysis. These two technologies can easily create a system with capabilities to sense, think, learn, analyze, and produce outcomes in the form of future prediction and in cases where changes can take appropriate actions.
The data collected by IoT systems require security, especially in terms of integrity and availability, and the integration of a distributed and secure system, such as blockchain, can deliver these security features. Blockchain requires additional computational power and storage capabilities that some IoT devices may not have. However, the presence of edge-computing abilities can accommodate such requirements and make it possible to integrate blockchain. Combining the edge technology with blockchain technology can provide a decentralized, robust, and secure solution, offering IoT devices the ability to interact and share data among themselves and with users. The available resources on the edge devices help to provide the required computation and storage resources for the blockchain technology, allowing the end devices to exploit the security offered by the blockchain closer at the edge.
With the integration of a distributed, self-managed, and decentralized network, both the dynamic and distributed IoT systems and the intelligence AI engine will benefit greatly from such integration [2], [3]. With the presence of edge computing, these benefits include: a) providing IoT networks with a reliable ability to control and manage computation-workload distribution among a large amount of distributed IoT hardware, b) strengthening the security posture of the overall IoT system by enhancing its ability to improve data integrity and ensuring its availability and holding all participant nodes accountable for their actions [4]; c) enhancing the AI engine's ability to perform the required analyses and provide the desired outcomes using these trusted data.

A. CONTRIBUTION
• The design and development of an architecture that integrates four different technologies: IoT, AI, edge computing, and blockchain in one system that can monitor and sense the environment, learn, analyze data based on the requirements of the executed task, and produce actionable outcome. The proposed system is based on the integration of low-cost edge devices and takes full advantage of their available storage and all IoT devices' computation power to provide a data-processing and sharing public blockchain platform.
• This architecture was validated experimentally using 14 low-cost, flexible IoT hardware entities. Practical implementation and performance analyses in terms of system latency, system accuracy, and energy consumption of real-world applications in the form of an early warning system for the detection of COVID-19 in sewage water were carried out.
• A new blockchain protocol for handling communication aspects of the system and enhancing its security by providing assurance, ensuring the integrity of the data, and holding nodes accountable for their actions. It is suitable for integration into edge, and IoT devices and can handle the AI-related data. The remainder of this paper is organized as follows: section II presents related work, followed by the proposed architecture in section III. In section IV, we provide an analysis of the system followed by the security analysis in section V, and then the implementation and testing of the system-example application in section VI. Section VII presents the results, and section VIII presents the discussions, the conclusions, and the directions for future work.

II. RELATED WORK
The integration of blockchain into the edge layer has attracted considerable attention from researchers in recent years. The authors of [5] introduced an architecture that combines the blockchain, software-defined network (SDN), and edge layer in one system. The architecture contains a device layer for collecting data, an edge (fog) for raw data processing utilizing an SDN controller, and a cloud layer for data storage and processing. Another work by IBM [6] proposed autonomous decentralized peer-to-peer telemetry (ADEPT). It is built for coordinating autonomous devices through the use of the Ethereum blockchain network and smart contract.
The framework proposed by [7] is an excellent example of how blockchain and edge layers can be used to secure IoT applications. It is introduced for vehicular communication systems by hosting security managers and blockchain, both of which are utilized to provide key transfer and management at the edge layer. Similarly, the authors of [8] proposed a new control system. It uses the hyperledger fabric blockchain, along with a smart contract, in a micro-service architecture at the edge layer to secure and validate data initiated at the lower layer. Another edge-based framework called EdgeChain was proposed by [9]. Similar to [8], it uses blockchain and smart contracts at the edge, so that devices in the lower layer can access resources at edge servers.
Another research area that has gained similar attention from researchers is the integration of blockchain, edge computing, and AI technologies. The work by [10] using blockchain and machine learning introduced a prediction framework called ModelChain. This allows multiple healthcare institutions to train the same framework for better results in terms of health prediction. The BlockDeepNet framework was proposed by [11] for data analysis within IoT systems. It combines blockchain technology, smart contracts, and deep learning. The authors of [12] introduced a blockchain-based NeuRoNt platform that integrates multiple agents by using smart contracts to solve complex problems. A similar approach utilizing both Ethereum and smart contracts was taken by the authors of [13], who proposed a mobile edge system for service sharing and data processing in smart-city IoT applications. The DeepConin framework was introduced in [14] for fraudulent transaction detection and blockchain-attack prevention based on deep learning and blockchain within smart-grid applications. A similar framework based on blockchain was introduced in [15]. It uses deep learning and SDN to allow smart city applications to access and utilize cost-effective and high-performance computing resources.
The authors of [16] provided a practical integration that combines federated learning (FL) and blockchain with the aim of securing big data and preserving privacy within IoT systems. It achieves this by using fuzzy hashing to detect suspicious activities, such as poisoning attacks in FL-trained models. The authors of [17] also proposed an architecture for data analysis at the edge based on blockchain and AI. The aim is to enhance the security of privacy-critical systems, such as healthcare applications, by restricting raw data to producers only. The authors of [18] proposed a blockchain-based edge intelligence (EI) system for improved data security, privacy, and performance. It uses a public blockchain to ensure the communication security of consumer electronic devices (CEDs) and a private blockchain to ensure communication security among EI servers.
The work by [19] introduced a scheme for batch authentication in the Internet of Vehicles (IoV) based on blockchain and AI. The aim is to address the security challenges that result from the communication between different entities within IoV-based smart cities. The scheme provides the IoVs with the secure ability to authenticate themselves when two vehicles are communicating and for a group of vehicles to be authenticated by the roadside unit. The authors of [20] proposed a pandemic situation supervision scheme based on blockchain and AI. It utilizes an AI-equipped swarm of drones to monitor an outbreak in the case of a viral pandemic. This scheme was designed to help control the spread of viruses by ensuring that people follow the guidelines and performing surveillance checks (e.g., face coverings, temperature measurements, and social distancing). Similarly, the work by [21] proposed the use of blockchain technology along with unmanned aerial vehicles (UAVs) for patient data collection within healthcare. It uses UAVs to collect data and a blockchain to store the collected data. It uses tokens and shared keys to establish secure communication with users' body sensors. Table 1 provides a summary of the important related work, including the solution provided, the applications, and the limitations in each work.

III. SYSTEM ARCHITECTURE
The proposed architecture provides a system for collecting data, processing, and analyzing data and produces a sharable outcome among nodes. A general overview of this architecture is presented in Fig.1. The platform operates according to the following three steps: • The first step is the Monitoring and Collection step: the IoT system monitors the environment or situation and utilizes its sensors at the lowest layer to collect the environmental or change data.  • The second step is the Analysis and prediction step: in this step, the collected data is propagated to the intelligent engine located at the edge nodes for analyses and providing predictions.
• The third and the final step is the Sharing step: in this step, the produced outcome from the edge devices are shared among all participant nodes on the freely accessed public blockchain network.

A. ARCHITECTURE DIFFERENT LAYERS
To accomplish the three previously discussed steps and provide free access to the public blockchain platform, we designed an architecture that consists of four different layers. Figure. 2 provides the layout of these layers.

1) SENSING LAYER
This is the lowest layer in the architecture and is the most important layer; it is the data feeder to the sharing platform.
In this layer, a wide range of many low-cost, low-power, and small sensor devices are used for monitoring and data collection. The collected sensor data will then be submitted to the gateway, which can be in the form of low-cost devices (e.g., Arduino ESP-32), which can then be validated and prepared and then submitted to the next layer for processing. This aids in achieving the first step of our architecture, which is the monitoring and collection.

2) NETWORK LAYER
The data submitted by the gateway is then transferred to the next layer. This is where the network layer takes part. In this layer different communication links can be utilized (for example, wireless connectivity, such as the Wi-Fi, LoRaWAN, or 5G, or a wired connectivity).

3) PROCESSING LAYER
This layer is equipped with the necessary AI engine to perform the required analyses and is responsible for achieving the second step in the architecture, which is the analyses and FIGURE 2. Example application -detailed system architecture.
prediction. Devices deployed at this layer can be low in both cost and power, and one example of such a device is the Raspberry Pi (R-pi). The data collected by the sensing layer arrived at this layer. The AI-expert engine located at these edge devices will then be used to process and analyze the data and then provide predictions and necessary outcomes that can be used to help the decision-making process. All nodes located in this layer should be a full clients of the blockchain platform (see Subsection III-B). This means that these nodes will be able to share their collected data and AI outcomes instantly with the rest of the blockchain clients. In doing so, the platform will have a continuous stream of data (collected by sensors and the outcome of the AI), allowing for a better performance of the system.

4) SHARING PLATFORM
This is a freely accessible and a public blockchain platform and is responsible for achieving the sharing step, which is the final and last step of the architecture. All the devices in the processing layer are part of the public blockchain. This would allow any organizations, users, or other concerned parties to be part of such a platform and have the ability to freely access all processed AI and collected data.

B. BLOCKCHAIN PROTOCOL
Designing a blockchain protocol that has the ability to handle different types of transactions, including those related to AI engines, is an essential part of our proposed architecture. Therefore, a new blockchain platform, including bespoke transaction and block-header formats, has been designed, developed, and implemented. In terms of the consensus mechanism, we utilized our own consensus protocol called honesty-based distributed proof of authority (HDPoA), which we previously published in [22]. The blockchain platform can utilize the resources of all the available IoT devices. Based on this, we categorized these devices into three different classes based on their hash power and storage capabilities, as follows: • Full Client (FC): These can be low-cost devices that have enough hash power and storage capability. This would allow these clients to play more roles in terms of consensus mechanisms and storage of the full chain. One example of such a low-cost device that can be utilized as a full client is R-pi.
• Hybrid Client (HC): These devices are low in cost and power. They may have limited resources in terms of storage capability, but their available power can be utilized for the purpose of carrying a small number of the hashing task. These devices can act as gateways in which many sensor devices are connected.
• Participant Client (PC): These are the small sensor devices at the sensing layer. Although they cannot be part of the blockchain, they still play an important role in our proposed architecture, as they are the data feeder to the processing layer.
In terms of HDPoA, the roles of the nodes in the consensus mechanism are classified into two types of nodes. Authority Nodes (ANs), these nodes are from the FC class and have enough trust levels to manage and coordinate the mining process. Worker Nodes (WNs), any node that is able to participate in the mining process is classified as WN and can be from both FC or HC; only the current AN that manages the mining process cannot be part of the WNs. All other nodes should make themselves available for the mining tasks. More details regarding how HDPoA works can be found in [22].

IV. SYSTEM ANALYSIS
The proposed system utilizes a free-access public blockchain network where the lowest value of the difficulty D is onethat is, when the value of the target hash h v is 2 232 . In the network, the sources of data traffic are broadcast transmission processes of transactions and blocks through the network. The important parameters used are listed in Table 2.

A. TRANSACTIONS CONFIRMATION TIME AND THROUGHPUT
The probability of any transaction (including AI-related transactions) to arrive and confirm on the network can be measured based on the Poisson process, in which the outcome can arrive on a confirmed block with an arrival rate of λ. The following equation is used as the starting point for driving all the equations in this subsection.
In the proposed blockchain system, as discussed above, the HDPoA-consensus mechanism does not require extra time to confirm the arrived block, as long as none of the authority nodes (ANs) initiate a block rejection process. Based on this, we can define λ as λ  The t parameter (i.e., time) relies on the number of blocks n the user needs to wait before the block carrying the transaction (e.g. AI-expert engine final prediction) is confirmed on the network, B pd , and V t of the new block. Based on this, the probability (P(n)) of the confirmation of any transaction (including AI-related transactions) can be calculated as: Based on this the confirmation time C t of any transaction can be calculated by: To provide an estimation of the network throughput (i.e., transactions per second), we assume that the block size is B size and the transaction size is Tx size . Then, the network throughput can be calculated by: Measuring the overall system latency (L) is an important aspect of the system performance metrics. To calculate (L), we assume that all AI-related transactions arrive at the elected AN transaction pool on time to be included in the next block. As shown by Fig. 3, we assume transactions submitted before the time t 1 −T pd will be included in the next block (Block_n). Another important aspect of the proposed system we need to consider is the fact that we validate the AI input values and the final outcome of the expert engine on the blockchain network. This means that two rounds of confirmation are needed before the arrival of the final outcome. Based on these assumptions and considerations, the overall system latency L can be calculated as follows:

C. POWER COST
The energy consumption of both the blockchain and the AI-engine is a significant parameter of the proposed architecture; therefore, it is important to analyze this parameter and identify its impact on the power sources of the devices. Each device is typically in one of the following states: 1) Sleeping state (S): In this state, the device will not perform any task. Instead, it will goes to sleep and wakes up by a timer or event. In this state, power consumption can be identified by p s : 2) Connectivity state (C): In this state, the device's operating system is active, and it is connected to the available connectivity link (i.e., Wi-Fi link) and does not perform any task. In this state, the power consumption can be identified by p c . This is our reference state, in which we compare the energy consumption of the other states. 3) Data Exchange state (DX ): During this state, the device will indeed be in data transmission or data reception. The power consumed during this state can be defined as p dx . 4) Worker state (W ): In this state, the device is engaged in the blockchain-mining activity by performing a small task of the block-mining process, in search of the nonce for the new block. In this state, the power consumption can be identified by p w : 5) prediction state (PRE): In this state, the device will receive the AI-input values and then will utilize its built-in AI-expert engine to process these values and produce an AI prediction. During this state, the power consumed is defined by p pre : Based on these states, we can calculate the total power p tot consumed by any device in the blockchain network as follows: The system will be in each state for a certain amount of time, and the time of the sleeping state can be identified as s t ; during connectivity state, it can be defined as c t ; during the data exchange state, it can be defined as dx t ; during the worker state, it can be defined as w t ; and during the prediction state, it can be defined as pre t . These values, along with the measured power in each state, can be used to calculate the energy consumption EN of any device as follows: Based on this equation and the different system states, we can calculate the cost of power (P cost ) (J/s) during the worker state (p w ), or the prediction state (p pre ), in comparison to when the system is in the connectivity state (p c ), our reference state, using the following equation: Battery life (B life ): When dealing with the small battery-powered IoT devices, it is essential to utilize them in a way that ensures limited impacts to their batteries. We designed our architecture to ensure a limited impact on the battery life of the devices. Based on the above assumptions and the calculation of the power consumption and cost, the life of a battery with a capacity of B capacity can be calculated by:

V. SECURITY ANALYSES
For security analyses, we performed a qualitative risk assessment of the proposed architecture using the NIST SP-800-30 standard [23]. Table 3 shows the determination of the risk level based on attack likelihood and its impact level. The following subsections discuss the risks associated with the most likely attacks that can target our architecture.

A. DENIAL OF SERVICE (DoS) ATTACK
The architecture was designed to allow nodes to access the services provided by the AI-expert engine; however, a DoS attack against the node hosting the engine is possible.
The system was designed to enhance the robustness of the AI engine by utilizing the distributed approach provided by the blockchain. In our experiment, we utilized one node to host the AI engine, which has the ability to allow any of the ANs to host the AI-expert engine, and each node can produce its own prediction value, as all nodes have access to the data in the blockchain. In fact, with the implementation of the blockchain and the bespoke protocol formats, it is possible to implement the AI in a distributed approach, in which each AN can host one layer or more of the engine, allowing for more transparency, as the flow of the data from one layer to another will be validated on the blockchain network. This makes the system robust against any attacks that target the services provided by the AI engine. Therefore, although the likelihood of a DoS attack is high, its impact's level is low making the residual risk level of this attack low.

B. DATA INTEGRITY ATTACKS
The integrity of the data is very important for ensuring that AI prediction is performed on legitimate and fresh data. Nevertheless, the integrity of the data can be targeted and can be vulnerable to manipulation. In our proposed system, the blockchain platform is utilized to first validate new data before adding them to the system. Second, it ensures that the added data cannot be modified or deleted. This feature of the blockchain enhances the system's ability to ensure that the AI engine accesses only trusted and fresh data. However, there is still the risk that some sensors may feed the system a fabricated or untrue data. This might not be detected; however, once any node is discovered behaving in a manner that could harm the data integrity, our HDPoA consensus algorithm will blocks that node from feeding or accessing the data on the blockchain.
With the presence of our HDPoA-based blockchain platform, the likelihood of any attacks that can harm the data integrity is low, and their impact can be high. This makes the residual risk level of any attack low.

C. MALICIOUS AN
It is possible that one of the ANs can be malicious or that it can be compromises. A malicious AN can harm our architecture in two ways: either by forging a new block or by producing an untrue AI outcome. In both cases, the platform can manages this node. First, the block-mining process is performed by multiple unrelated WNs. Second, other ANs on the network only add and validate a new block produced by the elected miners (see [22] for more details). If such a block is not valid, then the node that produced the block will be eliminated from the AN category, and it will have to build its trust from zero. In terms of the AI prediction, we built the system to allow any trusted AN to host the AI-engine. This would allow the network to utilize more than one node to perform the AI prediction, allowing for more validation and outcome-consensus of any outcome before it is confirmed on the blockchain.
The impact of any attack from any malicious AN high; however, the likelihood that ANs can misbehave or become compromised is moderate, making the residual risk level of any attack moderate.

D. MALICIOUS WN
Similar to the malicious AN, any WN can be malicious, or it can be compromised. Any WN can misbehave, and this can only occur in the form of submitting incorrect solution to any assigned task. The platform can easily address this problem. First, any solution submitted by any WN will be validated by the elected AN. Second, any new block will be validated by other ANs on the network, thus eliminating the collusion between any malicious or compromised ANs and WNs.
Although the likelihood of an attack by a malicious WN is high, the impact of such an attack is low, which makes the residual risk level of any attack low.

E. 51% ATTACK
The traditional 51% attack targets the control of the blockchain network by controlling the majority of the hash power (i.e., 51% or more). This type of attack, if successful, provides the attacker with total control of the blockchain platform. Our consensus mechanism deployed in the blockchain platform eliminates attacks that are associated with controlling the majority of the hash power. This is because the mining process is divided among multiple unrelated WNs, and it also deploys an added security layer by incorporating the AN category along with the PoW process. However, in our blockchain platform, for this attack to be successful, the attacker needs to have control of the majority of the ANs (control more than 50% of ANs). Although this is possible, it is also very time consuming, making it difficult to achieve.
Therefore, the likelihood of this attack is moderate, and the impact, if it is successful, is very high, making the residual risk level of this attack high.

F. ATTACK ON COMMUNICATION LINKS
Attacks on the communication links, such as jamming and DoS are possible. The main focus on this study was to evaluate the performance and security of the a blockchain platform when utilized in supporting AI-enabled IoT applications. Hence, we assume that the network provider will has adequate security mechanisms and protection in place.
Even though attack likelihoods on communication links can be moderate; the impact of such attacks is low on the assumption that adequate protection is in place, making the residual risk level of this attack low.

VI. IMPLEMENTATION AND TESTING OF EXAMPLE APPLICATION: AI-ENABLED SYSTEM FOR TRACKING VIRUSES IN SEWAGE WATER
The worldwide pandemic caused by the novel coronavirus COVID-19 has wreaked havoc among organizations, governments, and businesses. The lack of robust and reliable tracking and early warning systems and platforms has resulted in the loss of many lives and major economic losses. Technologies such as blockchain, IoT, and AI can provide governments with a secure, intelligent, and robust platform for tracking and tracing and for implementing early warning system. Such a system is a desirable solution that can help in tackling the spread of COVID-19 or other future viruses and allows governments to save lives and reduce economic impacts. In this system, the sensing and data-collection ability of the IoT can be combined with the decentralized and secure abilities offered by blockchain and, with the intelligence capabilities of the AI, can provide the best solution that can be utilized to tackle current and/or future pandemics.
According to the author of [24], wastewater-based epidemiology (WBE) offers an effective method for the early detection of possible viral infections before its actual spread by tracking and measuring the presence of viral genetic markers in wastewater. The proposed architecture discussed above is shown in Fig. 2. It provides an affordable and more practical system that can be utilized to efficiently and securely predict the possibility of any viral infections. By continuously collecting and analyzing the data, the system will serve as an early warning notification for concerned entities, such as disease-control agencies, allowing them to take effective and early actions to slow down or stop the spread of such a virus. Additionally, the system's ability to serve as an early warning notification platform can also help governments evaluate the effectiveness of other virus-control measures, such as social distancing, lockdown, and mass testing.

A. BLOCKCHAIN IMPLEMENTATION
We developed and implemented our own blockchain platform secured by the HDPoA consensus mechanism that we previously developed and tested. This platform is a public blockchain where any node can join in exchange for a small amount of energy through its participation in performing tasks on the network, such as performing a small amount of block mining or AI prediction. For our platform to handle different transaction types on the network, including AI-related transactions, we created and implemented a bespoke transaction and block's header formats, as shown in Fig. 4.
In terms of the consensus mechanism discussed above, there are two types of nodes in the network: ANs and WNs. ANs are responsible for ensuring the security of the blockchain by managing the mining process, validating transactions and blocks, validating any work performed by a WN, and validating each other's work. Any node that joins the blockchain for the first time will join as a WN and then build its own honesty level until it can be promoted to the AN category. Full details of how HDPoA works can be found in [22]. 1) First, the sensors that are installed in the different sewage-water locations will sense and collect data in the form of readings of any presence of viral agents in sewage water. One sensor that can be used is a biosensor with a biological receptor [25]. These readings are submitted to a gateway that can be either a FC or a HC. 2) The gateway will validate the readings (if it was signed by the sensor), create a transaction, and label the type of this transaction as an AI-input value. 3) Then, the gateway will broadcast the transaction to all ANs on the blockchain network. 4) Assuming node AN _1 is responsible for the mining process of the next block (i.e., block_n), it will collect transactions, validate them, and add them in a new block, and it will set the AI-flag to the appropriate value (0 or 1). 5) Then, in step 5 AN _1 will create mining tasks for all the available WNs and send the tasks to each one of them. 6) Upon receiving the task, any WN will accept it and begin performing the process of searching for the correct nonce that satisfies the current difficulty. 7) If any WN finds the nonce that satisfies the next block difficulty, it will forward it to AN _1 and all other ANs for future validation. 8) AN _1 receives the nonce and then will validate it by executing one hash. 9) If the nonce is valid, then block_n will be signed and propagated to the network. 10) Once block_n arrives at the processing node (we assume this node is AN _2), it will extract the relevant AI input values, feed them to the AI-engine, process them, and produce the final AI outcome (the prediction). This processing of the input values by the AI-engine occurs during the mining process of block_n + 1. 11) AN _2 will then add this outcome to a transaction and propagate it to all ANs on the network. 12) Assuming the node responsible for managing the mining process of the next block (block_n + 2) is AN _3, it will execute the same steps as 4-9, and will then propagate block_n + 2 that carries the final AI outcome to the network. Now, the AI outcome is available on the public blockchain and can be accessed by any interested government entity or organization.

C. EXPERIMENT AND TESTING
To test our system, we deployed a blockchain network and used 16 R-pis. Two were used as ANs and 14 were used as WNs. One AN was used for managing the mining process, and we developed, trained, and deployed an AI-engine on the other AN. The AI-engine consists of three inputs and three outputs. For the hidden layer, we utilized the tenser-flow kerase dense function [26], and for activation functions, we utilized Relu and SoftMax. Figure. 6 shows the architecture of the AI-expert engine. It was very difficult to find any COVID-19 dataset related to wastewater, therefore, based on the literature, we created our own test dataset. Based on [27], biosensors, such as electrochemical reaction biosensors, can be utilized to measure and detect the levels of viral nucleic acids, proteins, and small molecular antibodies. Different studies investigated the use of biosensors for detecting COVID-19 in wastewater [27]- [29]. One common way to measure viruses and proteins using biosensors is the plaque-forming units PFL/mL; for COVID-19, this could be up to 16 PFU/mL [27]. The method used to create our dataset is based on the assumption that there are available biosensors to measure three different parts of the virus: viral proteins S, viral proteins N, viral genetic material RNA, and provide readings measured by PFL/mL. We created data based on three input values: viral protein S, viral protein N, and viral genetic material RNA. The higher the PFU of each input, the higher is the COVID-19 infection rate in a certain area. We classified our AI outcomes into three different categories: low risk, medium risk (needs attention), and high risk (needs immediate action). Table 4 presents an example of our test dataset, where the numbers in the table are representative of those found in [27]- [29].

VII. RESULTS
A. SYSTEM LATENCY We tested the system while mining using different numbers of WN (1 to 12 WNs). We then measured the overall latency of the system for each test. Figure. 7 shows the average L. From the figure, we can see that as the number of WNs participating in the block mining process increases, the average L decreases. We managed to lower the overall latency from over 40 min when we were using only one WN to approximately 4.3 minutes when the total WN utilized to mine one block was 12. If we had more WN at hand, this time could have been reduced to less than one minute.

B. AI-ACCURACY
In terms of the AI engine accuracy, the system was first trained on 70% of the dataset, using R-pi, and produced a FIGURE 7. Measured and predicted system overall latency. VOLUME 10, 2022 prediction accuracy of 97%. We then tested the system on a stand-alone R-pi device, not connected to the blockchain network, using 15% of the dataset, resulting in a prediction accuracy of 95%. In the final test, we deployed the system on the blockchain network using one AN. We then tested the system in three rounds. With each round, we used 5% of the remaining dataset (the data were sent over the network as blockchain transactions, as described by the data flow in Fig. 5). All three rounds of the unseen dataset resulted in the same prediction accuracy of 95%, which is the same as when testing using the stand-alone system. This shows that utilizing blockchain for better data security did not affect the AI-engine accuracy; Fig. 8 shows the accuracy for both tests compared to the training.

C. POWER COST
An important aspect of the proposed system is the impact on the battery and power sources of devices. To investigate this impact, we measured the power consumption during different system states, including connectivity (C), data exchange (DX), worker (W), and prediction (Pre). Figure. 9a shows the consumed power by the R-pi during each of these states. It is clear that the impact of using the device for mining or hosting the AI engine is minimal, as most of the power is consumed when the system is running and connected to the Wi-Fi without performing any task. This is clear in Fig. 9b, as it shows the percentage of the power increase when the system is utilized to perform blockchain mining, data exchange, or AI prediction. When using the R-pi for AI prediction, the power increase was 14%, and this increase was 7% when utilized for blockchain mining. However, in a network where the available number of WNs and ANs is a few hundred or even thousands, such an impact can be eliminated, as we would have more than enough nodes to perform different tasks in the network. This means that a device may spend a day without performing any task.
Battery Life is an important factor in our proposed system. We designed our architecture with the aim of protecting the battery-powered IoT devices. We predicted the impact on the battery life of such small devices [using (9)], and, as can be FIGURE 8. Accuracy of the AI-expert engine. seen in Fig. 10, these small devices can participate on the network without substantial impacts to their batteries. For example, in a network of 3,000 WN a battery with a capacity of 600 mA has an expected life of more than two months. This expected life is well above three months, when the number of WN is increased to up to 5,000. This shows that these battery devices can access the service of the blockchain network by performing small tasks with limited impact on their battery life.

D. THROUGHPUT AND BLOCK SIZE
The block size is an important aspect when calculating the network throughput (transactions per second); as the block size increases, the throughput increases, and vice versa. Our experiment was conducted using a reliable connectivity in the form of Wi-Fi, which connects nodes to each other. In [30], an intensive study of the impact of the block size on IoT-blockchain applications was performed, and it was found that a block size of less than or equal to 1 MB should be used. Conversely, in our work, we limited the block size to a maximum of 500 kB for better energy efficiency, and to limit the impact of the block size on the network synchronization. This allows the number of WNs to increase, and hence, a lower mining time, while maintaining high network synchronizations among nodes. We tested the network throughput when the block size was 500 kB while varying the number of WNs that participated in the block-mining process (4-14 WNs). Table 5 lists the throughput. Clearly, as the network grows in terms of the number of WNs, the throughput increases. This is because the block-mining time decreased.
We had only a limited number of devices at hand to conduct large-scale experiments. However, to investigate the impact of the number of WNs that are available on the network to participate in the mining process, we calculated that impact in terms of the number of WNs, transaction confirmation time, difficulty, and throughput, using (3,4). Figure. 11 shows the predicted throughput for different network setups. It is clear in the figure that as the number of WNs increases, the throughput can be increased. For example, a network  Power cost when the system is in the DX, W, and PRE states compared to when the system is in the C state, that is, the reference state.

VIII. DISCUSSION AND CONCLUSION
The proposed architecture provides a platform that is secure, robust, and effective in terms of power and throughput to support AI-enabled IoT applications at the edge. The system is able to ensure continuous AI prediction, thus eliminating a signal point of failure, providing governmental entities and organizations with processed data and outcomes for better decision-making. It ensures data integrity by validating and securing all AI data (inputs and outcomes) using a secure, decentralized, and transparent blockchain platform. Compared with other related studies, the proposed architecture provides a platform that is capable of ensuring AI data integrity through validation and transparency, allowing the deployment of a robust and redundant AI-engine without any impact on its accuracy. It achieves this by utilizing edge devices and IoT end devices without a substantial impact impact on the power of these devices. Table 6 shows a performance comparison with the important related works. The authors acknowledge the difficulty of direct comparisons to other work due to differences in the presented assessment criteria. Furthermore, individual blockchain solutions can be tuned to enhance performance for a specific application.
In conclusion, we proposed, designed, developed, and implemented a system that has the capability to combine the advantages of three important technologies-edge computing, blockchain, and AI-in one platform. This system incorporates the security advantages provided by blockchain to offer a publicly available platform that integrates the intelligence advantages provided by AI into an edge layer to facilitate a secure architecture capable of sensing, analyzing, thinking, and producing actionable outcomes.
Our results showed that the system provided reliable accuracy in terms of the AI prediction of COVID-19 occurrence in sewage water at an acceptable system latency for such an application. The results and analyses of the impact on the devices' power sources showed that it is possible to use low-cost and low-power devices to accommodate the requirements of AI and blockchain in a network of a few hundred nodes.
In future work, the integration of biosensors into the system is needed to further study their impact on the overall system performance and the security of the collected data. Future work will include full deployment of the system around different sewage water sources to collect and analyze real-world data.