# Reconfigurable Smart Contracts for Renewable Energy Exchange with Re-Use of Verification Rules
## 3 Renewable Energy Example  
For the sake of clarity in further considerations, the author introduces the following definition of the verification rule (Definition 1). Definition 1: A verification rule is a single condition imposed on a smart contract. Smart contracts may encompass many verification rules. All verification rules that constitute a smart contract must be met for the transaction to be performed. In the example, the following verification rules were used in further presented smart contracts:  
* TechnicalVR1--transaction can be executed within the same community;* TechnicalVR2--transaction can be executed between different prosumers;
* BusinessVR1--quantity of energy to transfer must be greater than zero;
* BusinessVR2--source prosumer surplus of energy must be greater than or equal to the quantity of energy to transfer;
* BusinessVR3--the sum of renewable energy generation and battery energy surplus is smaller than the energy need;
* BusinessVR4--battery energy surplus is equal to zero;
* ExpandingVR1--always return true;
* TechnicalVR1 Extended--transaction can be executed between various communities;
* ExpandingVR1 Extended--target prosumer need for energy must be greater than or equal to the quantity of energy to transfer. The example includes two use cases and their corresponding smart contracts, _Exchange Energy_ and _Buy Energy from Grid_. Figure 1 presents the UML Use case diagram that shows both use cases. Cooperating distributed applications are depicted as actors. They are external applications, so the dedicated <<IntegratedSystem>> stereotype is applied [41]. The author introduces the following definition of the smart contract configuration (Definition 2). Definition 2: A smart contract configuration is an ordered list of verification rules. Verification rules cannot be repeated on the list. All validation rules on the list must be met in accordance with the evaluation expression for the transaction to be executed. In the case of the _Exchange Energy_ smart contract, we have two configurations of verification rules because we can exchange energy within one community or between communities. Moreover, the author introduces the following definition of the evaluation expression (Definition 3). Definition 3: An evaluation expression is a logical expression containing verification rules and logical operators that return a single Boolean value. The design of the pattern allows for the implementation of various evaluation expressions of smart contract configurations. However, in one smart contract, there can be only one implementation. In the example, each smart contract has a different implementation of evaluation expression. Figure 1: The UML use case diagram for renewable energy use cases/smart contracts. Table 1 contains a summary of configurations with specific verification rules. It is important that smart contract configurations use verification rules that come from the same set of rules. Figure 2 shows smart contract configurations that use a common set of verification rules. Those reused are labeled. Thus it becomes possible to reuse verification rules between smart contract configurations. The percentage of reused verification rules \(R_{sc}\) for a smart contract can be expressed as the following Equation (1). \[R_{sc}=\frac{\sum_{i=1}^{C}\left(\frac{v_{i}^{T}}{v_{i}}\right)}{\text{C}} \times 100 \tag{1}\]  
where:  
\(C\)--number of configurations in a smart contract,  
\(v_{i}^{T}\)--number of re-used verification rules in i-th configuration of the smart contract,  
\(v_{i}\)--number of verification rules in i-th configuration of the smart contract.