# Exploiting Blockchain Technology for Enhancing Digital Twins' Security and Transparency
## 3 Proposed Approach
### Implementation
#### 3.1.3 Smart Contracts  
After establishing the foundational blockchain protocol, the next phase involved defining the implementation of smart contracts to be utilized within the validation system. For this development, Solidity was selected as the programming language, given its wide recognition as a core language for smart contract programming on blockchain platforms [37]. Solidity's robust features make it particularly well suited for constructing secure and reliable validation mechanics while ensuring alignment with industry standards. Moreover, the integration of standardized contracts such as EIP-1967 further enhanced the development experience of the proposed solution. The development of the manager contract followed this path by integrating into its deployment an upgradable proxy, which served as a stepping stone to integrate additional features in previous iterations of the solution. In terms of its own logic, the manager contract served as an on-chain security measure by enabling component communications and providing administrative access to designed network addresses. To establish precise directionality between entities within the system, each approved communication was recorded in the manager contract as a sender-receiver tuple within a stored list. This structured representation of interactions ensured that all communications within the producer-consumer framework complied with the predefined security protocols. Furthermore, the administrative contract was uniquely designated as the sole authorized entity for direct communication with the on-chain storage counterpart. This storage component was configured to accept transactions exclusively from the manager contract which initiated the connection and subsequently retrieved the required hash data. By implementing a decoupled smart-contract architecture, the system ensured a robust data preservation and recovery policy, minimizing the risk of data loss while providing an interface-based communication between parts. This modular approach also allowed for seamless updates to the manager contract without compromising the security infrastructure, thus maintaining the essential security support needed. Pseudocode describing the functionalities provided by the manager contract to communicate with the storage contract is provided below in Algorithm 1:  
```
1:procedureMappingExists(_key)
2:return corresponding[_key].exists
3:proceduregetAdminList
4: Return AdminContractInstance.getAdmins()
5:
6:procedureStoreInterface(Hash)
7:ifMappingExists(msg.sender) is false then
8: revert
9: Call StoreVal(Hash, msg.sender) on StorageContractProxyInstance
10:procedureRetrieveInterface(_receiver)
11:ifcorrespondings[msg.sender].to \(\
eq\) _receiver then
12: revert
13: Call RetrieveVal(msg.sender) on StorageContractProxyInstance
```  
**Algorithm 1** Manager communication logic with the connected storage contract  
Moreover, for reproducibility reasons, the code employed to perform the administrative functionalities for the system's topology management is provided through the same framework as the previous pseudocode exemplification Algorithm 2. ```
1:procedureMappingExists(_key)
2:return corresponding[_key].exists
3:procedureGetAdminList
4: Return AdminContractInstance.getAdmins()
5:
6:procedureStoreInterface(Hash)
7:ifMappingExists(msg.sender) is false then
8: revert
9: Call StoreVal(Hash, msg.sender) on StorageContractProxyInstance
10:procedureRetrieveInterface(_receiver)
11:ifcorrespondings[msg.sender].to \(\
eq\) _receiver then
12: revert
13: Call RetrieveVal(msg.sender) on StorageContractProxyInstance
```  
**Algorithm 2** The proposed solution of the proposed solution  
The corresponding pseudocode representing the implementation logic of a \"Storage\" smart contract is provided, as a direct counterpart to the previously defined manager contract, in Algorithm 3. The contract serves as a secure data repository, with functionality for storing and retrieving hashed values.