# Confidential Smart Contracts and Blockchain to Implement a Watermarking Protocol
## 8 Implementation and Performance
In this way, Sapphire guarantees high scalability to the off-chain execution of smart contracts, which is penalized only in case of a lack of agreement between the committee nodes. Figure 8: Implementation of the proposed watermarking protocol. As for the performance of the proposed protocol, it is important to note that the time \(T\) needed to complete a purchase transaction of \(X\) is given by the sum of the following contributions:  
\[T=T_{sc}+T_{w}+T_{dd}+T_{bc}\]  
where \(T_{sc}\) is the time taken by a TEE-equipped node to execute the smart contract implementing the protocol, \(T_{w}\) is the time taken by \(\mathcal{CP}\) to secure the content \(X\), \(T_{dd}\) is the time taken by the committee of TEE nodes to evaluate the integrity of the computation performed to execute the smart contract, and \(T_{bc}\) is the time taken to finalize the purchase transaction on the blockchain. In particular, thanks to the layer-2 execution paradigm, \(T_{sc}\) and \(T_{dd}\) are related to an off-chain execution. They mainly depend (1) on the power and number of TEE nodes involved in executing the smart contract and (2) on the discrepancy-detection protocol. Therefore, the higher the degree of replication of the smart contract execution and the number of nodes involved in the integrity committee, the higher the recorded times will be. \(T_{w}\), instead, depends on the computing power used by \(\mathcal{CP}\): the greater this power, the less time will be required to protect \(X\). \(T_{bc}\) coincides with the so-called \"time to finality\" that characterizes \(\mathcal{BC}\), that is, the time needed to confirm a transaction completely [8]. It measures the time that elapses between sending the transaction to \(\mathcal{BC}\) and its confirmation, by publication in one of the \(\mathcal{BC}\) blocks, with a guarantee of irreversibility. This time is a very variable value and difficult to obtain because it depends on many factors, such as, for example, the consensus algorithm used, the block propagation method, the number of validator nodes used, the speed of their network interconnection, and the finality method. In essence, it is possible to reduce \(T_{bc}\) by using a reduced number of validator nodes, but this expedient ends up also reducing the level of security implemented by \(\mathcal{BC}\), as foreseen by the so-called \"trilemma\" of blockchains, according to which the classic objectives of a blockchain, such as decentralization, scalability, and security, are substantially conflicting [8]. In the preliminary tests conducted, three TEE nodes (Intel(R) Core(TM) i7-10870H with a frequency up to 4.8 GHz and 16 GB of RAM) and three validator nodes (Intel(R) Core(TM) i5-12450 HX with a frequency up to 4.4 GHz and 16 GB of RAM) were used. All nodes are connected by a Gb Ethernet. As for \(\mathcal{CP}\), an Intel(R) Core(TM) i5-12450 HX compute node with a frequency up to 4.4 GHz and 16 GB of RAM was used. With these limited hardware resources, \(T_{sc}\) varies approximately between 12 and 14 s, mainly due to the operations needed to generate encryption keys, encrypt tokens, and calculate hashes. \(T_{w}\) was found to vary between 29-41 s and 107-145 s, depending on the size of the protected image, \(512\times 512\) or \(1024\times 1024\) pixels, and the watermarking algorithm used, such as SS or QIM [18]. \(T_{dd}\) was calculated using all three nodes in the committee to evaluate the integrity of the computation performed by the smart contract. It was found to vary approximately between 1 and 1.5 s when no discrepancy was detected. On the contrary, the discrepancy-resolution algorithm takes approximately between 5 and 6 s in case of no agreement. Finally, \(T_{bc}\) was calculated using all three available execution nodes as validators. The result obtained was approximately between 6 and 7 s.  
It is important to note that \(T_{sc}\), \(T_{w}\), and \(T_{dd}\) values are independent of the blockchain used since they are obtained, as previously mentioned, by exploiting a layer-2 execution paradigm.