# Blockchain and Smart Contracts for Digital Copyright Protection
## 7 Implementation and Performance  
This Section reports on a few hints about the implementation and performance of the proposed protocol. In particular, the implementation is based on previous experiences conducted in [16; 17], and follows the scheme shown in Figure 2. The entities involved in the protocol run as C++ separate programs on Linux OS. They use the OpenSSL standard socket library to communicate and implement the encryption/decryption and watermark insertion procedures by exploiting the NTL and GNU Multi Precision Arithmetic libraries. The C++ programs run on distinct PCs connected by a GBit Ethernet. Each PC has a CPU Intel(R) Core(TM) i5-12450 HX with frequency up to 4.4 GHz, 16 GB of RAM, and an SS disk of 512 GB. More in detail, watermark insertion is carried out by running two well-known algorithms: the SS algorithm described in [34] and the QIM algorithm presented in [42]. Both are adapted to the homomorphic cryptosystem proposed by [PERSON] [40] according to what is documented in [36; 45; 46; 47]. The insertions take advantage of the optimizations reported in [37; 48], which can improve the watermark insertion carried out directly into the encrypted domain. The watermark insertion based on the SS algorithm can be carried out by applying the following formula:  
\[\bar{x}=x+\alpha(2b-1)s\]  
where \(x\) is a host signal feature obtained by calculating the cosine discrete transform, \(\bar{x}\) is the corresponding watermarked feature, \(b\!\in\!\{0,1\}\) is the bit to embed, \(s\) is the component of a spreading sequence, and \(\alpha\) is a scaling factor that controls the watermark's strength. The corresponding watermark insertion directly into the encrypted domain is carried out according to the expression [36; 37; 46]:  
\[E[\bar{x}]=E[x]\cdot E[b]^{2\alpha s}\cdot E[\alpha s]^{-1} \tag{4}\]The watermark insertion based on the QIM algorithm [42] is carried out according to the following expression [37]:  
\[\tilde{x}=f(x)+b\Delta(x)\]  
where \(x\), \(x\), and \(b\) maintain the signification reported above, while \(f(x)\) and \(\Delta(x)\) denote a function of the original signal features and a signal-dependent quantization step, respectively [1; 42]. Therefore, by directly operating in the encrypted domain, the watermark insertion can be obtained by applying the following expression [37; 46; 47]:  
\[E[\tilde{x}]=E[f(x)]\cdot E[b]^{\Delta(x)} \tag{5}\]  
In the first implementations documented in [16; 17], the adopted blockchain is classified as \"public\", with a fully decentralized architecture, and is based on the \"proof of work\" (PoW) consensus algorithm [10; 11; 12]. Its nodes are implemented in Ethereum [49], whereas the smart contracts are coded in Solidity [50]. In particular, the introduction of cryptographic primitives within smart contracts has made it necessary to start a specific experimental phase that has not yet been completed. So, the results reported in the following refer to previous implementations that simulate the execution of the necessary cryptographic primitives on a specific server external to the smart contracts. The watermark embedding algorithms reported above have been used on two sets of images: images of 512\(\times\)512 pixels and images of 1024\(\times\)1024 pixels. A 128-bit fingerprint has been embedded in each image, whereas the cryptosystem employed in the conducted tests uses keys with 1024 bits. In these hypotheses, a watermark insertion in 512\(\times\)512 images takes about 29-41 s depending on the watermarked image and on the watermarking insertion algorithm. The same insertion in 1024\(\times\)1024 images takes about 107-145 s.  
Finally, the computational cost concerning the blockchain can be summarized as follows: 140,000 gas units are needed to complete a single purchase transaction, whereas 8,000,000 gas units represent the limit of the computational cost per block. Therefore, the number of transactions per block is about 57-60.