# Policy-Based Smart Contracts Management for IoT Privacy Preservation
## 3 Proposed Method: Policy-Based Smart Contract Management for IoT Privacy Preservation
### Predefined Smart Contract Types  
The smart contract is a piece of programming that consists of a set of rules and corresponding transactions of related accounts. It enables the determination of the conditions and penalties, and enforcement of the organization's policies and agreements [42]. Five contract types were proposed to allow the data owner to define and apply the confidentiality authorization parameters. Figure 1 shows the different predefined smart contracts used by our proposed model. * **Register smart contract** enables the user to register new IoT devices. The user fills out the registration form and uploads the electronic specification of the new IoT device. Then, the blockchain peers verify the correctness of the IoT details according to the electronic specifications. Thereafter, the system shall register the IoT device on a new block once it is successfully verified by the peers. Finally, the system notifies the user about the registration process. Figure 2 depicts the different steps of the registration process. Figure 2: New IoT device registration. The blockchain gateway is responsible for providing secure communication between the user application and the blockchain network through asymmetric encryption. Hyperledger Fabric provides authentication, encryption, and access control to the blockchain network. * **Routine smart contract** receives data from sensors and collects them locally until the data size reaches a predefined user threshold according to their mobile memory capacity. Then, the application sends the routine smart contracts to the blockchain network containing the collected data to be inspected by the blockchain peers and stored in the blockchain's main ledger. The routine contracts do not require the interaction of humans but just automated code-based peers to validate the received data in terms of timestamp, format, and completeness. If some data are missing, an automated smart contract called maintenance smart contract is triggered. The peer will only replace the missing data with \"incomplete\" appended with the sensor's ID. The occurrences of routine smart contracts could be based on the received data size, predefined timestamps, or both, based on the application domain requirements. * **Maintenance smart contract** collects details about the missing data and the sensors responsible for providing them. Then, the system sends the maintenance smart contract to the blockchain network, which immediately will process the content, identifies the issue, and notifies the user or the entity responsible for the sensor to fix the issue. Issues could be suspicious data requiring the disabling of the IoT device or misbehavior requiring its replacement. * **Urgent smart contract**: during the daily collection of sensor data, once a received metric reaches or surpasses a predefined threshold agreed upon by the responsible entity, it triggers an immediate smart contract named urgent smart contract containing the urgent data and has a high priority during its processing by the blockchain peers. * **Claim smart contract** enables the user to query the blockchain network for their data or send them other information not sensed by the IoT devices, such as their psychological status and feelings in case of healthcare applications. Furthermore, it allows any user type to interact with the blockchain network from outside the organization. For instance, the physician needs to be updated about their patient's status and follow their recovery even if they are outside the organization. The claim contracts will distinguish between the different types of users according to their public and private keys received when joining the blockchain network. The model starts urgent, routine, and maintenance smart contracts automatically. However, register and claim smart contracts are triggered by the user. Thus, our model empowers users to dynamically adjust their privacy policies and preferences. Users can modify smart contract rules in real time based on specific conditions, actions, or environmental changes.