# Confidential Smart Contracts and Blockchain to Implement a Watermarking Protocol
## 6 The Protocol
### The Protection Protocol
#### 6.1.1 Deployment  
The deployment phase, whose scheme is shown in Table 2, starts with \(\mathcal{CP}\) contacting one of the computation nodes equipped with TEE (\(\mathcal{CN}\)). This node is part of the computation structure and is responsible for executing off-chain the smart contract that implements the watermarking protocol. The structure must be composed of computation nodes, all equipped with TEE. Some of these nodes exclusively perform the functions of servers to manage the keys necessary for the confidential execution of the smart contract (see Figure 4). The nodes, similarly to those of a public blockchain, participate voluntarily and are remunerated during the execution phase of the smart contract. It is important to note that it is possible to carry out multiple deployments of the smart contract on the blockchain. This makes it possible to have multiple concurrent executions of the same copy of the smart contract, thus increasing the number of purchase transactions in the unit of time depending on the available TEE nodes. \(\mathcal{CP}\) initially sends the contract code \(CODE_{sc}\) to a \(\mathcal{CN}\) in message \(m_{1}\), which loads it into its secure enclave. \(\mathcal{CN}\) then creates the contract identifier \(c_{id}\) and sends it to one of the TEE nodes that manage the encryption keys, indicated by \(KMS\), in the message \(m_{2}\). This node generates three keys: a first public-private key pair \((pk_{cit},sk_{cit})\) to be used to exchange encrypted data with the contract when it is executed in the TEE; and a secret key \(K_{cit}^{st}\) used by the contract to encode the state information generated by the execution. \begin{table}
\begin{tabular}{c l} \hline \hline
**Symbols** & **Meaning** \\ \hline \(E_{key}(\ldots)\) & token encrypted with the key _key_ \\ \(H(\ldots)\) & hash function \\ \(\Pi\) & certification of correct execution attestation in TEE \\ \(\sigma(X)\) & payment specification to purchase \(X\) \\ \(\mathbb{E}_{key}(\ldots)\) & token encrypted with the key _key_ and using a privacy homomorphic \\  & cryptosystem with respect to the watermark insertion \\ \(\mathbb{D}_{key}(\ldots)\) & decryption function inverse of the function \(\mathbb{E}_{key}(\ldots)\) \\ \hline \hline \end{tabular}
\end{table} 
Table 1: _Cont._ \begin{table}
\begin{tabular}{c l l} \hline \hline
**Entities and** & & & **Actions and Messages** \\
**Interactions** & & & \\ \hline \(\mathcal{CP}\xrightarrow{m_{1}}\mathcal{CN}\) & : & \(m_{1}=\{CODE_{sc}\}\) \\ \(\mathcal{CN}_{TE_{D}}\xrightarrow{m_{2}}\mathcal{KMS}\) & : & \(m_{2}=\{c_{id}\}\) \\ \(\mathcal{KMS}\xrightarrow{m_{3}}\mathcal{CN}_{TE_{D}}\) & : & \(m_{3}=\{pk_{cit},sk_{cit},K_{cit}^{st}\}\) \\ \(\mathcal{CN}_{TEE_{D}}\) & : & generates \(in_{cit}\) and obtains \(\Pi[AttD[c_{id},pk_{cit}]]\) \\ \(\mathcal{CN}_{TEE_{D}}\xrightarrow{m_{4}}\mathcal{BC}\) & : & \(m_{4}=\{c_{id},CODE_{sc},E_{K_{cit}^{st}}(in_{cit}),\Pi[AttD[c_{id},pk_{cit}]],pk _{cit}\}\) \\ \(BC\) & : & publishes \(c_{id},CODE_{sc},E_{K_{cit}^{st}}(in_{cit}),\Pi[AttD[c_{id},pk_{cit}]]\), \(pk_{cit}\) \\ \hline \hline \end{tabular}
\end{table} 
Table 2: Deployment phase. Upon receiving the keys in message \(m_{3}\), \(\mathcal{CN}\) generates the initial state \(in_{c_{id}}\) associated with the contract and encrypts it, creating the token \(E_{K^{st}_{id}}\left(in_{c_{id}}\right)\). Then, \(\mathcal{CN}\) generates an attestation, denoted by \(AttD[c_{id},pk_{c_{id}}]\), that proves both the correct initialization of the contract and the association of the public key \(pk_{c_{id}}\) to the contract. At this point, \(\mathcal{CN}\) obtains a proof of correctness of \(AttD[c_{id},pk_{c_{id}}]\) by contacting a specific official attestation service, such as the Intel Attestation Service (IAS) for SGX-based TEE systems, which performs the \(AttD\) verification and returns a digitally signed certification of correct execution attestation in TEE, denoted by \(\Pi[AttD[c_{id},pk_{c_{id}}]]\).