# Confidential Smart Contracts and Blockchain to Implement a Watermarking Protocol
## 4 The Execution Model  
The proposed watermarking protocol is based on the confidential execution of smart contracts according to a layer-2 scheme, in which the blockchain is used solely to validate the transactions produced by the smart contracts [14; 19] (see Figure 4). In this scheme, it is necessary to differentiate the processing nodes that are responsible for the execution of the smart contracts, and which must therefore be equipped with TEE, from the blockchain nodes, which instead act as simple \"validators\" of the generated transactions and which can be common processing nodes capable of executing the consensus algorithm implemented by the blockchain.  
The execution model, therefore, provides for two types of entities: TEE nodes and validator nodes.  
The former execute the contracts in the TEE and generate the appropriate attestations of correct execution and generation of results. The only requirement is that they can implement the TEE. Some of them are also expected to act as servers to manage the encryption keys used by the TEE nodes. In particular, these nodes implement specific distributed protocols for key management.  
The latter are the blockchain nodes responsible for managing the public ledger and executing the implemented consensus algorithm. They are part of a public blockchain and validate the transactions generated by the execution of smart contracts.  
The proposed protocol is then implemented by executing a smart contract. The contract is initially registered in the blockchain after some preliminary actions between the smart contract developer and one of the TEE nodes. These actions are necessary to guarantee the confidentiality of the execution of the contract. They are performed in the TEE and allow the following:  
* Generation of the public-private key pair with which to encrypt the input/output parameters of the contract;  
Figure 3: Layer-2 execution model based on TEE.  
* Generation of the symmetric key with which to encrypt the state information produced by the execution of the contract;
* Generation of the attestation of the correct execution of the previous actions.  
At the end of this phase, the smart contract is published on the blockchain, with the information necessary for the invocation, such as the public key associated with the contract.  
To invoke the contract, users first retrieve from the blockchain the information needed to encrypt the parameters to be passed to the contract, such as the previously generated public key. They then invoke the contract by passing the invocation parameters encrypted with the public key. These parameters include, among others, the symmetric keys with which the contract can encrypt any output parameters to be returned to users.  
The contract is then executed confidentially on one or more TEE nodes. At the end of the execution, the TEE nodes involved generate the results, status information, and attestations of correct execution. The formers are encrypted with the symmetric keys previously sent by the users, while the latter are encrypted with the symmetric key generated in the initial phase by the TEE node. Everything is passed to the blockchain, which publishes the information received once the validator nodes have reached consensus.