# Smart Contract Design Pattern for Processing Logically Coherent Transaction Types
## 3 The Pattern Design and Implementation
### Concrete Layer
The author has proposed the measure \(D^{sc}\) as the percentage of redundant verification rule objects for a smart contract. The measure can be expressed by Equation (2). \[D^{sc}=\frac{(\sum_{i=1}^{C}o_{i}^{c})-v^{sc}}{v^{sc}}\times 100 \tag{2}\]

where:

\(o_{i}^{c}\)--number of newly created objects in \(i\)-th configuration of the smart contract;

\(v^{sc}\)--number of unique verification rules in the smart contract. The value of the percentage of redundant verification rule objects \(D^{sc}\) for the smart contract considered in the article was calculated: \(D^{sc}=\frac{(3+1+2)-6}{6}\times 100=0\%\). This means that verification rule objects are fully used by configurations. In addition, making changes in checking between transaction types does not create new objects or drop existing ones. As a result, the garbage collector is not involved in the operation of the software. It should also be underlined that no verification rule object from the verification rule object list is left unused. In a recently published research paper, Khan et al. [35] showed that the overall cloning rate of Solidity smart contracts is 30.13%, of which 27.03% are exact duplicates. The _AdapT_ pattern employed to design the smart contract allows for achieving a verification rule cloning rate of 0%. Therefore, developing design patterns that increase the reuse level of the source code of smart contracts seems to be one of the appropriate directions of research work. In addition, the efficiency of the run-time use of operational memory is of great importance. Working with various transaction types may involve the constant instantiation of many extra objects. Especially when transactions of various types are evaluated alternately. The author has proposed the measure of object creation efficiency \(O_{T}^{sc}\) as the mean value of the number of verification rule objects created at runtime in the smart contract for a single transaction. The measure can be expressed by Equation (3). \[O_{T}^{sc}=\frac{\sum_{i=1}^{T}o_{i}^{t}}{T} \tag{3}\]

where:

\(T\)--the number of checked transactions;

\(o_{i}^{t}\)--the number of newly created objects for \(i\)-th transaction. Calculated values of \(O_{T}^{sc}\) for the considered smart contract for selected quantities of checked transactions were presented in Table 1.

The value of the measure of object creation efficiency \(O_{T}^{sc}\) decreases for the considered smart contract as the number of checked transactions increases. It stems from the fact that the complete set of verification rule objects is created when a smart contract object is instantiated. All transactions are served by the same collection of objects regardless of the number of transactions. For the smart contract considered in the article, six objects are created, one for each of the verification rules. That set of six verification rule objects verifies any number of transactions. No other objects are created for verification rules. ## 5 Performance Tests Results

The purpose of the performance tests was to check how quickly transactions are checked by a smart contract designed following the _AdapT_ pattern. As far as the execution environment is concerned, the tests were carried out on a MacBook Air with the Apple M2 processor, 16 GB Random Access Memory (RAM), and 256 GB Solid State Drive (SSD). The MacBook Air worked under the macOS Sonoma 14.3 operating system. To conduct performance tests, a separate TestContract smart contract testing class was designed. The class contains two methods: _conductTest()_ and _runTest()_. The first method measures the evaluation time of a smart contract. The method uses the _System.nanoTime()_ to obtain an accuracy of one nanosecond of time measurement. The second method is responsible for performing the appropriate number of measurement repetitions. The source code of the _TestContract_ class is shown in Listing 7. The evaluation time of a specific number of transactions by the smart contract \(E_{n}^{sc}\) was adopted as the basic performance measure.