An Information-Theoretic Proof of a Finite de Finetti Theorem

Lampros Gavalakis

Department of Engineering,
University of Cambridge,
Trumpington Street,
Cambridge CB2 1PZ, U.K.
Email: .
L.G. was supported in part by EPSRC grant number RG94782.

Ioannis Kontoyiannis

Statistical Laboratory, DPMMS,
University of Cambridge,
Centre for Mathematical Sciences,
Wilberforce Road,
Cambridge CB3 0WB, U.K.
Email: .
Web: .
I.K. was supported in part by the Hellenic Foundation for Research
and Innovation (H.F.R.I.) under the “First Call for H.F.R.I. Research
Projects to support Faculty members and Researchers and the
procurement of high-cost research equipment grant,” project
number 1034.

A finite form of de Finetti's representation theorem
is established using elementary information-theoretic tools:
The distribution of the first $k$ random variables in an
exchangeable binary vector of length $n\geq k$
is close to a mixture of product distributions.
Closeness is measured in terms of the relative entropy
and an explicit bound is provided.

Keywords —
Exchangeability, de Finetti theorem,
entropy, mixture, relative entropy,
mutual information

§ INTRODUCTION

A finite sequence of random variables $(X_1,X_2,\ldots,X_n)$ is
exchangeable if it has the same distribution
as $(X_{\pi(1)},X_{\pi(2)},\ldots,X_{\pi(n)})$
for every permutation $\pi$ of $\{1,2,\ldots,n\}$.
An infinite sequence $\{X_k\;;k\geq 1\}$ is
exchangeable if  $(X_1,X_2,\ldots,X_n)$ is
exchangeable for all $n$. The celebrated representation
theorem of de Finetti
[8, 9]
states that the distribution
of any infinite exchangeable sequence
of binary random variables can be expressed
as a mixture of the distributions
corresponding to independent and identically distributed
(i.i.d.) Bernoulli trials. For discussions of the
role of de Finetti's theorem in connection with
the foundations of Bayesian statistics and
subjective probability see, e.g,
[10, 5]
and the references therein.

Although it is easy to see via simple examples that
de Finetti's theorem may fail for finite binary
exchangeable sequences, for large
but finite $n$ the distribution of the first $k$
random variables of an exchangeable vector of length
$n$ admits an approximate de Finetti-style representation.
Quantitative versions of this statement have been
established by Diaconis [10]
and Diaconis and Freedman [13].
The approach of Diaconis' proof in [10]
is based on a geometric interpretation of the set of exchangeable
measures as a convex subset of the probability simplex.

The purpose of this note is to provide a new
information-theoretic proof of a related finite version
of de Finetti's theorem. For each $p\in[0,1]$,
let $P_p$ denote the Bernoulli probability mass
function with parameter $p$, $P_p(1)=1-P_p(0)=p$,
and write $D(P\|Q)=\sum_{x\in B}P(x)\log[P(x)/Q(x)]$
for the relative entropy (or Kullback-Leibler divergence)
between two probability mass functions $P,Q$ on the same
discrete set $B$;
`log' denotes the natural
logarithm to base $e$.

Let $n \geq 2$. If the binary random variables
$(X_1,X_2,\ldots,X_n)$ are exchangeable,
then there is a probability measure
$\mu$ on $[0,1]$, such that, for every $1\leq k \leq n$,
the relative entropy
between the probability mass function $Q_k$ of $(X_1,X_2,\ldots,X_k)$
and the mixture $M_{k,\mu}:=\int P_p^kd\mu(p)$

\begin{equation}
\label{eq:Dbound}
D(Q_{k}\|M_{k,\mu}) \leq \frac{5k^2\log n}{n-k}.
\end{equation}

By Pinsker's inequality
[7, 19],
$\|P-Q\|^2\leq 2D(P\|Q)$,
the theorem also implies that,

\begin{equation}
\label{eq:l1bound}
\|Q_k - M_{k,\mu} \|
\leq k\Bigl(\frac{10\log{n}}{n-k}\Bigr)^{\frac{1}{2}},
\end{equation}

where $\|P-Q\|:=2\sup_B |P(B)-Q(B)|$
denotes the total variation distance
between $P$ and $Q$.
This bound is suboptimal in that,
as shown by Diaconis and Freedman [13],
the correct rate with respect to the total variation
distance in (<ref>) is $O(k/n)$.
On the other hand, (<ref>) gives
an explicit bound for the stronger notion
of relative entropy `distance.'

Rather than to obtain optimal rates,
our primary motivation is
to illustrate how elementary
information-theoretic ideas can be used
to provide an alternative proof strategy for
de Finetti's theorem, following
a long series of works developing this point of view,
including information-theoretic proofs of
Markov chain convergence [21, 16],
the central limit theorem [4, 2],
Poisson and compound Poisson
approximation [18, 3],
and the Hewitt-Savage 0-1 law [20].

Before turning to the proof, we mention that
there are numerous generalisations and extensions of
de Finetti's classical theorem and its finite version
along different directions; see,
e.g., [11]
and the references therein.
The classical de Finetti representation theorem
has been shown to hold for exchangeable processes
with values in much more general spaces than
$\{0,1\}$ [15], and
for mixtures of Markov chains [12].
Recently, an elementary proof of de Finetti's theorem
for the binary case was given in [17],
a more analytic proof appeared in [1],
and connections with category theory were drawn
in [14].

§ PROOF OF THE FINITE DE FINETTI THEOREM

We first need to introduce some notation.
Let $n\geq 2$ be fixed.
For any $1\leq i\leq j\leq n$, write $X_i^j$
for the block of random variables $X_i^j=(X_i,X_{i+1},\ldots,X_j)$.
Denote by $N_{i,j}$ the number of 1s in $X_i^j$,
so that $N_{i,j}=\sum_{k=i}^jX_k$, and for every $0\leq\ell\leq n$
write $A_\ell$ for the event $\{N_{1,n}=\ell\}$.

The main step of the proof is the estimate in the lemma below,
which gives a bound on the degree of dependence
between $X_i$ and $X_{i+1}^k$, conditional on $A_\ell$.
This bound is expressed in terms of the mutual information.
Let $(X,Y)$ be two discrete random variables with joint
probability mass function (p.m.f.) $P_{XY}$ and marginal
p.m.f.s $P_X$ and $P_Y$, respectively. Recall that
the entropy $H(X)$ of $X$, often viewed as a measure
of the inherent “randomness” of $X$ [6],
is defined as,
$H(X)=H(P_X)=-\sum_{x}P_X(x)\log P_X(x)$,
where the sum is over all possible values of $X$
with nonzero probability. Similarly, the conditional
entropy of $Y$ given $X$ is,

$$H(Y|X)=-\sum_x P_X(x)\sum_y P_{Y|X}(y|x)\log

where $P_{Y|X}(y|x)=P_{XY}(x,y)/P_X(x)$.

The mutual information between $X$ and $Y$
is $I(X;Y) = H(Y) - H(Y|X)$, and it can also be expressed

$$I(X;Y) = H(X) - H(X|Y)=H(X)+H(Y)-H(X,Y)=D(P_{XY}\|P_XP_Y).$$

For any event $A$, we write $I(X;Y|A)$ for the
mutual information between $X$ and $Y$ when all
relevant p.m.f.s are conditioned on $A$.

From the definition,
an obvious interpretation of $I(X;Y)$
is as a measure of the amount of “common randomness”
in $X$ and $Y$. Additionally, since $I(X;Y)$
is always nonnegative and equal to zero iff $X$ and $Y$
are independent, the mutual information can be viewed
as a universal, nonlinear measure of dependence between
$X$ and $Y$.
See [6] for standard properties of
the entropy, relative entropy and mutual information.

Finally, we record an elementary bound that will
be used in the proof of the lemma.
Write $h(p)=-p\log p-(1-p)\log(1-p)$,
$p\in[0,1]$, for the binary entropy function.
Then a simple Taylor expansion gives:
| h (p) - h (q)| ≤|p-q| ×max{
| log(1-p/p) |,
| log(1-q/q) |},

For all $1\leq k\leq n$, all  $1 \leq i \leq k-1$, and any
$0\leq\ell\leq n$:

I(X_i;X_{i+1}^k|A_\ell) \leq \frac{5k\log n}{n-k}.

We assume without loss of generality that $k\leq n/2$,
for otherwise the result is trivially true since the
mutual information in the statement is always no greater than 1.
Also, if $\ell=0$ or $n$ the conditional mutual information
is zero and the result is again trivially true.
Let $Q_n$ denote the p.m.f. of $X_1^n$.
By exchangeability, conditional on
$A_\ell$, all sequences in $\{0,1\}^n$ with
exactly $\ell$ 1s have the same probability
under $Q_n$, so $X_1^n$ conditional on $A_\ell$
is uniformly distributed among all such sequences.
This implies that for all $1 \leq k \leq n/2$, $1\leq i \leq k-1,$
and $1\leq\ell\leq n-1$,

\begin{equation*}
\PP(X_i = 1| N_{1,n} = \ell, N_{i+1,k})
= \frac{\binom{n-(k-i)-1}{\ell- N_{i+1,k}-1}}{\binom{n-(k-i)}{\ell-N_{i+1,k}}}
= \frac{\ell-N_{i+1,k}}{n-(k-i)}.
\end{equation*}

For the mutual information we have:
=    (.h(ℓ/n)
- h(ℓ-N_i+1,k/n - (k-i))|
N_1,n = ℓ)

- h(ℓ-N_i+1,k/n- (k-i))|
_{ℓ+ k - i - n + 1
≤N_i+1,k < ℓ}
|N_1,n = ℓ)

(N_i+1,k = ℓ|A_ℓ)
+ h(ℓ/n)
(N_i+1,k ≤ℓ+k-i-n | A_ℓ).

If the probability in the third term above is nonzero,
then necessarily
$\ell \geq n - k + 1$ and thus, using
$n \geq 2k$, $h(\ell/n) \leq 2\frac{k}{n-k}\log{n}$.
On the other hand, if $\ell + k - i - n + 1 \leq N_{i+1,k} < \ell$,
both $\ell/n$ and $(\ell-N_{i+1,k})/(n-(k-i))$ are between
$1/n$ and $(n-1)/n$, so
from (<ref>)

the first term
in (<ref>) is bounded above by,

\frac{\ell(k-i) + n\EE(N_{i+1,k}|N_{1,n} = \ell)}{n(n-(k-i))}\log{n}
= \frac{2\ell(k-i)}{n(n-(k-i))}\log{n}.

by Markov's inequality,
the probability in the second term is
no more than $k/n$, while the binary
entropy is always bounded above by $1$.
Combining these three estimates yields,

\begin{equation*}
% \label{Iexactbound}
\leq  \frac{2\ell(k-i)}{n(n-(k-i))}\log{n}
+ \frac{k}{n} + 2\frac{k}{n-k}\log{n}.
\end{equation*}

The result follows.

We are now ready to prove the theorem.
By the bound in the lemma,

I(X_i;X_{i+1}^k|A_\ell) \leq \frac{5k^2\log n}{n-k}.$$

Also, by definition of the mutual information,
using the obvious notation $H(X|A)$ for the
entropy of the conditional p.m.f. of $X$ given $A$,

\begin{align*}
\sum_{i=1}^{k-1}I(X_i;X_{i+1}^k|A_\ell)
\sum_{i=1}^{k-1}\left[H(X_i|A_\ell)
+ H(X_{i+1}^k|A_\ell)
- H(X_i^k|A_\ell)\right] \\
= \left[\sum_{i=1}^{k}H(X_i|A_\ell)\right]
- H(X_1^k|A_\ell) \\
Q_{X_1|A_\ell}\times\cdots\times Q_{X_k|A_\ell}\big),
\end{align*}

where we write $Q_{X_i^j|A_\ell}$ for the conditional p.m.f.of $X_i^j$ given $A_\ell$.
Since $Q_{X_i|A_\ell}=P_{\ell/n}$,
we have,

$$D\big(Q_{X_1^k|A_\ell}\big\|P_{\ell/n}^k)\leq\frac{5k^2\log n}{n-k}.$$

Finally, writing $\mu$ for the distribution of $\ell/n=(1/n)\sum_{i=1}^nX_i$
on $\{0,1/n,2/n\ldots,1\}$, averaging both sides with respect to $\ell$,
and using the joint convexity of relative entropy,
yields the claimed result.

The mixing measure $\mu=\mu_n$ in the theorem is completely characterised
in the proof as the distribution of
$(1/n)\sum_{i=1}^nX_i$, and it is the same for all $k$.
Moreover, if $\{X_n\;;\;n\geq 1\}$ is an infinite
exchangeable sequence then it is also stationary,
so by the ergodic theorem
$(1/n)\sum_{i=1}^nX_i$ converges a.s. to some $X$,
and the $\mu_n$ converge weakly to the law, say $\mu$, of $X$.
For fixed $k$,
since $P^k_p$ is a bounded and continuous
function of $p \in [0,1],$
we have for any $x_1^k \in \{0,1\}^k$,

M_{k,\mu_n}(x_1^k)=\int{P^k_p(x_1^k) d\mu_n(p)}
\to M_{k,\mu}(x_1^k)=\int{P^k_p(x_1^k) d\mu(p)},

and by our theorem,
$\|Q_k-M_{n,k}\|=O(\sqrt{(\log n)/n}).$
Therefore, we can conclude that,

Q_k = \int{P^k_p d\mu(p)},

for each $k\geq 1$,
and thus recover de Finetti's classical representation theorem.

Finally we note that the argument used in the proof
of the lemma as well as the proof of our theorem can
easily be extended to provide corresponding results
for exchangeable vectors taking values in any finite
set. But as the the constants involved become quite
cumbersome and our main motivation is to illustrate
the connection with information-theoretic ideas
(rather to obtain the most general possible results),
we have chosen to restrict attention to the
binary case.

Acknowledgments.  We thank
Sergio Verdú
and an anonymous referee for useful
suggestions regarding the presentation
of the results in this paper.

[1]
I. Alam.
A nonstandard proof of de Finetti's theorem for Bernoulli random
Journal of Stochastic Analysis, 1(4):15, 2020.

[2]
S. Artstein, K. Ball, F. Barthe, and A. Naor.
Solution of Shannon's problem on the monotonicity of entropy.
J. Amer. Math. Soc., 17(4):975–982, 2004.

[3]
A.D. Barbour, O. Johnson, I. Kontoyiannis, and M. Madiman.
Compound Poisson approximation via information functionals.
Electron. J. Probab, 15:1344–1369, 2010.

[4]
A.R. Barron.
Entropy and the central limit theorem.
Ann. Probab., 14(1):336–342, January 1986.

[5]
M. Bayarri and J.O. Berger.
The interplay of Bayesian and frequentist analysis.
Statistical Science, 19(1):58–80, 2004.

[6]
T.M. Cover and J.A. Thomas.
Elements of information theory.
J. Wiley & Sons, New York, second edition, 2012.

[7]
I. Csiszár.
Information-type measures of difference of probability distributions
and indirect observations.
Studia Sci. Math. Hungar., 2:299–318, 1967.

[8]
B. De Finetti.
Sul significato soggettivo della probabilita.
Fundamenta Mathematicae, 17(1):298–329, 1931.

[9]
B. De Finetti.
La prévision: ses lois logiques, ses sources subjectives.
Ann. Inst. Henri Poincaré, 7(1):1–68, 1937.

[10]
P. Diaconis.
Finite forms of de Finetti's theorem on exchangeability.
Synthese, 36(2):271–281, 1977.

[11]
P. Diaconis.
Recent progress on de Finetti's notions of exchangeability.
Bayesian Statistics, 3:111–125, 1988.

[12]
P. Diaconis and D.A. Freedman.
De Finetti's theorem for Markov chains.
Ann. Probab., 8(1):115–130, 1980.

[13]
P. Diaconis and D.A. Freedman.
Finite exchangeable sequences.
Ann. Probab., 8(4):745–764, 1980.

[14]
T. Fritz, T. Gonda, and P. Perrone.
De Finetti's Theorem in Categorical Probability.
arXiv preprint 2105.02639, 2021.

[15]
E. Hewitt and L.J. Savage.
Symmetric measures on Cartesian products.
Trans. Amer. Math. Soc., 80(2):470–501, 1955.

[16]
D.G. Kendall.
Information theory and the limit-theorem for Markov chains and
processes with a countable infinity of states.
Ann. Inst. Statist. Math., 15(1):137–143, May 1963.

[17]
W. Kirsch.
An elementary proof of de Finetti's theorem.
Statist. Probab. Lett., 151:84–88, 2019.

[18]
I. Kontoyiannis, P. Harremoës, and O. Johnson.
Entropy and the law of small numbers.
IEEE Trans. Inform. Theory, 51(2):466–472, February 2005.

[19]
S. Kullback.
A lower bound for discrimination information in terms of variation.
IEEE Trans. Inform. Theory, 13(1):126–127, January 1967.

[20]
N. O'Connell.
Information-theoretic proof of the Hewitt-Savage zero-one law.
Technical report, Hewlett-Packard Laboratories, Bristol, U.K., June

[21]
A. Rényi.
On measures of entropy and information.
In Proc. 4th Berkeley Sympos. Math. Statist. and Prob., Vol. I,
pages 547–561. Univ. California Press, Berkeley, Calif., 1961.


# Mining Domain Models in Ethereum DApps using Code Cloning

Noama Fatima Samreen<EMAIL_ADDRESS>Ryerson UniversityDepartment of
Computer ScienceTorontoOntarioCanada and  Manar H. Alalfi
<EMAIL_ADDRESS>Ryerson UniversityDepartment of Computer
ScienceTorontoOntarioCanada

(2018)

###### Abstract.

This paper discusses and demonstrates the use of near-miss clone detection to
support the characterization of domain models of smart contracts for each of
the popular domains in which smart contracts are being rapidly adopted. In
this paper, we leverage the code clone detection techniques to detect
similarities in functions of the smart contracts deployed onto the Ethereum
blockchain network. We analyze the clusters of code clones and the semantics
of the code fragments in the clusters in an attempt to categorize them and
discover the structural models of the patterns in code clones.

Blockchain Technology, Ethereum Smart Contracts, Code Cloning, Model-Driven
Engineering

††copyright: acmcopyright††journalyear: 2018††doi: XXXXXXX.XXXXXXX††ccs:
Software and its engineering Integrated and visual development
environments††ccs: Software and its engineering Software libraries and
repositories††ccs: Software and its engineering System modeling
languages††ccs: Software and its engineering Unified Modeling Language
(UML)††ccs: Computing methodologies Modeling methodologies

##  1\. Introduction

Model-driven engineering (MDE) make use of structural and behavioral models
that can be used to help a novice programmer of smart contracts understand the
new features provided by the blockchain-specific programming languages such as
Solidity (Solidity, ). These models provide a way of abstracting technical and
language-dependent functionalities thereby increasing the structural and
behavioral understanding of a new technology such as the blockchain
technology. Given the stigma around the complexity of development of
decentralised applications (DApps) using smart contracts, model-driven
development could enable the widespread adoption of the blockchain technology
as software developers of other technologies could use this as a starting
point of their blockchain oriented software engineering process. MDE is a
strategic framework that is used to realize advanced solutions by considering
different aspects and stakeholders involved in a domain. By viewing different
models we can achieve separation of concerns with a higher level of
abstraction and reduces the complexity of dealing with DApps specification.

Code clone detection in software systems has many applications. For example,
it can be used to identify repeated similar code fragments with the aim of
developing libraries and standards. It can also be used to enable bug fixes,
updates and changes to a software system (androidCodeClone, ).

In this paper, we leverage code clone detection technique by using Nicad
(NiCad, ) to detect similarities in functions of the smart contracts deployed
onto the Ethereum blockchain network. We analyse the clusters of code clones
and the semantics of the code fragments in the clusters in an attempt to
categorise them and discover the structural models of the patterns in code
clones. These structural models of patterns produced by code clone detection
technique could then be used as conceptual models in defining low-level
semantic Meta Models. These structural domain models are discovered by reverse
engineering of the largest code clone clusters in the source code files of
smart contracts deployed on the Ethereum blockchain network.

Our aim in this research is to identify patterns of code reuse through code
clone detection technique to build models on top of the existing code patterns
in Ethereum smart contracts. We approach this study by investigating the
extent of code clones in Ethereum smart contracts, categorizing these clone
clusters and producing structural domain models from these clusters to enable
code reuse at the modelling level. We highlight that our research leverages an
existing code clone detection tool, NiCad that operates at the source code
level in order to detect clones of type 1, 2, 2-c, 3 and 3-c. In this paper,
we address the following research questions:

RQ1: How can we identify and analyse the code clones present in main-net
verified smart contracts that are associated with DApps?

RQ2: Can the clone clusters of smart contracts be categorised into domains
depending on their functionality?

RQ3: Can the categorised clone clusters of smart contracts be reverse
engineered to produce structural domain models?

Figure 1. Extraction of Domain Models Workflow

Our workflow for discovering structural domain models from Ethereum smart
contracts consists of following steps:

  1. (1)

Smart contracts code usage analysis: Identification of highly used code
patterns by leveraging code clone detection technique. As BT and smart
contracts are just being adopted in various industries, we initiate our models
discovery process by analyzing the extent and characterization of code clones
in already deployed smart contracts.

  2. (2)

Extraction of Domain Models (Code-to-Model Transformation): We realise this
step by reverse engineering the highly cloned code patterns identified and
semantically categorised in our code clone detection phase.

  3. (3)

Defining Meta Model from structural domains: Each structural domain is then
characterized by an ontological basis, which describes the structural domains
of the concepts and the relations between them to define a Meta Model for a
DApp system (see 10). Besides this description of the structure of the
domains, the meta model could also provide semantics for the concepts used.
This meta model would capture the complete vocabulary of the transactions
necessary to develop a smart contract based decentralised application (DApp).

Figure 2. Overview of our approach at modelling domain categories from largest code clone clusters of Ethereum smart contracts Table 1. Classification Of Code Clones Clone Type |  Clone Type Definition |  Description
---|---|---
1 |  Exact |  Code clones of Type-1 are code fragments that are identical with variation in comments and blank spaces.
2 |  Renamed clone - Blind Renamed |  Code clones of Type-2 are code fragments that are identical with variations in identifier names, literals, comments and blank spaces. Blind Renaming is the process of renaming all the identifiers to X without keeping a record of previously renamed identifier.
2c |  Renamed clone - Consistently Renamed |  Code clones of Type-2c are similar to the Type 2 code clones except that they are consistently renamed, which is process of renaming the identifiers to Xn. Where, n is the number of occurrence of the identifier with respect to the previously renamed identifier.
3-1 |  Near miss clone - Blind Renamed |  Copied fragments with further modifications such as changed, added or removed statements, in addition to variations in identifiers, literals, types, white-space, layout and comments.
3-2c |  Near miss clone - Consistently Renamed |  Code clones of Type-3-2c can be considered as a hybrid of the Type 3-1 and Type 2c code clones in that they are similar code fragments with changed, added or removed statements, in addition to variations in identifiers, literals, types that are consistently renamed.
4 |  Functional Clone |  Two or more code fragments that perform the same computation but are implemented by different syntactic variants.

##  2\. Background

###  2.1. Ethereum Smart Contracts and Solidity

Blockchain oriented software engineering to develop Decentralised applications
(DApps) that execute smart contracts is complicated. Ethereum Smart Contracts
(Ethereum, ) are typically written in a high-level turing-complete programming
language such as Solidity (Solidity, ), and then compiled to the Ethereum
Virtual Machine (EVM) byte-code (Ethereum, ), a low-level stack-based
language. These smart contracts cannot be updated once deployed to the main-
net. This requires the developers to ensure that these smart contracts are
attacks-resistant and reflect complete business logic desired by the DApp
developers. A large portion of the problems with smart contract development
could be pinpointed to the lack of formalization of blockchain oriented
software engineering. The lack of standards and best practices makes smart
contract development prone to problematic practices.

###  2.2. Code-Cloning

Reusing code for similar applications by cloning is an efficient way of
minimizing the cost and time of software development. Research shows that the
use of templates in software programming results in various advantages. It is
especially very beneficial when there is a lack of knowledge base of a newly
developed programming language. Developing templates from code clones and
establishing them as standards or libraries (EIP, ) also affects a program by
reducing its size making it easier to read and comprehend.

####  2.2.1. Types of Code Clones

Code clones classification used in this analysis is given in
Table[LABEL:CloneClass].

####  2.2.2. NiCad Code Clone Detector

The NiCad clone detection tool is an efficient near-miss code clone detection
tool (NiCad, ). In this paper, we demonstrate the detection of code cloning in
Ethereum Smart Contracts using a static clone detection method. Our hypothesis
is that near-miss clone detection will provide a means of implementing a
model-driven development framework by producing a domain models of smart
contracts for each of the popular domains in which smart contracts are being
rapidly adopted.

###  2.3. Model-Driven Development for DApps

The model-centric or model-driven development approach focuses on utilization
of models to describe the structure and the behavior of a system, which is
then used to generate source code for a system. It can lower the complexity
and create a better understanding of the system. (modelSC, ). To automate and
make more powerful maintainable smart contracts, we need to extend the MDE
techniques to design and develop complex and decentralized applications. Smart
contracts and DApps build on the premise of having a tremendous impact not
only on the finance domain but also in other domains like gaming, supply-chain
etc. However, its adoption requires novel skill sets that current software
professional profiles fail to meet despite the increasing demand. Developing
DApps using smart contracts would be easier if the learning curve for the
needed skills would be more convenient. Model-driven software engineering can
help in abstracting blockchain technology and, starting from these
abstractions, enabling automated smart contract code generation.

##  3\. Approach

Our approach in producing domain models from existing smart contracts deployed
on the Ethereum blockchain network is described in Figure 2. It consists of
following steps:

###  3.1. Dataset

Our data-set consisted of 10680 smart contracts that run behind a DApp. These
smart contracts were collected from Etherscan (Etherscsan, ), a web portal
that provides analytical data and repository of smart contracts deployed onto
the Ethereum blockchain network. Etherscan provides verification of smart
contracts and meta-data about a smart contract and its owner address. Partial
meta-data for analysis of domain deduction was even collected from various
literature surveys available online in the form of token white-papers, and
GitHub repositories of contracts creators corresponding to a representative
smart contract of a code clone cluster.

Demographics of the Analysed smart contracts

To provide a proper context for the results, this section describes the
demographics of the smart contracts in our dataset. Our dataset of total 10680
sol files collected from Etherscan consisted of sub-contracts, libraries,
interfaces, events, modifiers. To understand the models and the metamodel
derived from our dataset, we provide the statistics of analysed smart
contracts. As shown in the Table 2, we analyzed 49,128 smart contracts which
included main contract and its depended contracts. Other factors analysed
included 8780 libraries, 2901 interfaces, 42101 events, 2901 modifiers. The
extent of division of functionality into smaller sub-contracts is practised by
software developers to achieve reduced complexity of contracts. Besides, the
events information shows that the execution information will be logged in
Ethereum. The interfaces, libraries, modifiers and events information is used
to derive structural models and templates.

Table 2. Demographics of the Analysed 10680 Ethereum Smart Contracts Total Sol Files |  Contracts |  Libraries |  Interfaces |  Events |  Modifiers
---|---|---|---|---|---
10680 |  49128 |  8780 |  2901 |  42101 |  29014

The final domain categorization of code clone clusters is provided in the
following steps.

###  3.2. Using NiCad Near-Miss Code Clone Detection Tool

The most recent version of NiCad code clone detector (v6.2) has built-in
support for parsing and analysing source code files written in the Solidity
programming language. However, the tool was not able to parse around 2800
smart contracts because of version incompatibility of the Solidity parser
provided by the Nicad tool. We therefore updated the Solidity grammar to the
latest version of the Solidity programming language to be able to parse and
analyse all the smart contracts in our data-set.

###  3.3. Domain Categorization of Large Code Clone Clusters

The main step of our research was to deduce domain categories based on the
metrics of the code clone clusters produced by Nicad tool and even factoring
in the semantics of code represented by these clusters. We leveraged the meta-
data collected from various resources such as Etherscan (Etherscsan, ),
StateofTheDApps (SDApps, ) and DAppRadar (DAppRadar, ) regarding the smart
contracts in largest clusters to infer upon the domain categories. The final
list of our domain categories was a result of an extensive manual browsing
through the clusters to understand the semantics of the code fragments in the
clusters and extracting relevant meta-data about the code fragments from
online resources.

Table 3. Code Clones Found in a Dataset of 10680 Smart Contracts Collected From Etherscan (Etherscsan, ) |  Extractor Only |  Filtered and Blind-Renamed |  Filtered and Consistent-Renamed
---|---|---|---
Clone Type |  Type 1 |  Type 3-1 |  Type 2 |  Type 3-2 |  Type 2c |  Type 3-2c
Clone Pairs |  17012 |  29645 |  18534 |  35115 |  18523 |  21487
Clone Classes |  596 |  607 |  753 |  750 |  752 |  762
Max diff threshold |  0% |  30% |  0% |  30% |  0% |  30%
Table 4. A Summary of the Categorization of the Top Clusters of Code Clones in a Dataset OF 10680 Ethereum Smart Contracts S.no |  Cluster Domain Category |  Cluster Size |  Accumulated Cluster Similarity Percentage(Min/Max) |  Domain Category deduced by clone detection type
---|---|---|---|---
1 |  Token Management |  547 |  90%/100% |  Type 1,2,2c,3-1,3-2c
2 |  Arithmetic Operations |  309 |  91%/100% |  Type 1,2,2c,3-1,3-2c
3 |  Exchanges |  214 |  70%/100% |  Type 2c, 3-1, 3-2c
4 |  Finance |  70 |  75%/85% |  Type 3-2c
5 |  Data Oracles |  62 |  70%/77% |  Type 3-2c
6 |  Marketplace |  53 |  72%/85% |  Type 3-2c
7 |  Gaming |  42 |  77%/98% |  Type 2c, 3-2c
8 |  Security |  41 |  70%/77% |  Type 2c, 3-2c

###  3.4. Reverse Engineering of Domain Categories To Produce Domain Models

After we formulated the list of domain categories exhibited by the largest
code clone clusters in our analysis, we reverse engineered a representative
smart contract of the cluster with an ultimate goal of producing structural
models of the domain categories. The reverse engineering step was performed
using the (Sol2Uml, ) tool available as an extension to the web-based Remix
IDE for Solidity.

###  3.5. Defining Meta Model

The reverse engineered structural domain models showed certain overlap of
patterns between domains. We therefore, aim at defining a Meta Model that
represents common metadata required for deep semantic extraction of business
rules and transformation of domain models. The defined Meta Model describes
the structural domain models of the concepts and the relations between them of
a DApp system (see Figure 10).

##  4\. Research Findings

###  RQ1: Code Clones in Ethereum smart contracts - Analysis

Motivation. First, we aim at identifying and characterizing the code clones in
Ethereum smart contracts that are associated with DApps to be able to
understand the diversity of use-cases implemented by Ethereum smart contracts.

Discussion. To answer our RQ1, we analyzed the output of NiCad near-miss clone
detection tool. Some of the terms to understand before analysing the code
clone detection report are:

  1. (1)

Code Granularity: It refers to the level of structural source unit taken into
consideration while analysing a source code file for clones. In this paper, we
configure NiCad clone detection tool to the functions granularity to detect
code clones in the functions of different Solidity smart contract code files.

  2. (2)

Clone Pair: Two code fragments which are identical or similar are known to
have a clone relation between them and are called a clone pair.

  3. (3)

Clone Class: It is the maximum set of code fragments which contains a clone
pair for each code fragment.

  4. (4)

Max. Difference Threshold: It is the percentage of difference in code
fragments metric to be configured in the NiCad code clone detection tool to
allow detection of code clones with a difference of up to the specified
threshold. We configured it to allow code clones with a maximum difference
threshold of up to 30%.

The analysis results of a data-set of smart contracts are given in Table3. We
were able to detect code clones of Types 1, 2, 2c, 3-1, 3-2c using the NiCad
near-miss code clone detection tool. A total of 40502 functions were extracted
from the source code files and the clone size varied from 10 to 2500 lines of
code.

Figure 3. Token and SafeMath Libraries Model

Observation 1: One of the observations we made while analysing code clone
reports generated by NiCad is that even though there is a widespread adoption
of Ethereum blockchain technology and smart contract, the source code files
exhibit very similar functionalities. The majority of the smart contracts are
either token contracts or token management programs. It can be inferred that
the smart contract developers are mostly cloning code intentionally from the
established standards available online (e.g., OpenZeppelin Libraries
(OpenZeppelin, ) to avoid any unforeseen security vulnerabilities that may
arise because of the lack of knowledge and experience in this new technology.

Figure 4. Marketplace Domain Category Model

Observation 2: Another noteworthy observation was that over 500 clone classes
of smart contracts were code clone pairs arising from non-standard contracts.
We believe that this is because of the immutability characteristic of the
blockchain technology that forces a smart contract developer to deploy the
same contract again even with minor changes, such as updating the
compatibility of their smart contracts to the latest version of the Solidity
programming language.

###  RQ2: Code Clones in Ethereum smart contracts - Categorization

Motivation. To extract domain models for an ultimate goal of extracting
business rules from existing Ethereum based decentralised applications
(DApps), we categorize the largest code clone clusters identified in the code
clone detection of Ethereum smart contracts.

Discussion. We approached the categorization of our code clone clusters
depending on the cluster similarity percentages. Specifically, we categorised
the code clone clusters into a domain category if a unique clone cluster has a
similarity percentage of 70% or higher. However, after a manual analysis of
the clusters we came across multiple clusters of varying similarity
percentages that could be categorised into a single domain category. To
overcome this redundancy of clones and deduce one domain category of related
functionalities, we analysed the source code of a representative smart
contract in each of the clusters and accumulated the code clone clusters into
a single domain category of related functionalities. Our approach resulted in
code clone clusters being categorised into following domain categories, [See
Table4]:

  1. (1)

Token Management: The largest code clone cluster was related to smart
contracts that handled tokens. Most of the clusters were an implementation of
the well-known token management standards such as ERC-20 111ERC: Ethereum
Request for Comments, Common ERC standards define a required set of functions
for a token type (EIP, ) (Token management standard for fungible tokens) and
ERC-721 (Token management standard for non-fungible tokens). Almost all the
other domain categories deduced by our analysis leveraged this cluster of code
clones to be implemented along with their specific functionalities.

  2. (2)

Arithmetic Operations: Earlier versions of the Solidity programming language
was detected with certain arithmetic vulnerabilities arising from it syntax.
Before the release of the latest version of the Solidity programming language,
the smart contract developers adopted the practice of implementing the
SafeMath library provided online to safely perform the arithmetic operations
in a smart contract. This practice is evident from our analysis and the second
largest cluster of code clones contributed to the implementation of SafeMath
library. Although the latest version of the Solidity programming language has
this vulnerability resolved, our data-set consisted of smart contracts ranging
from the versions 0.5.0 to 0.8.0. (Solidity, )

  3. (3)

Exchanges: The exchanges domain category consisted of use-cases involving
trading of digital assets built upon the Ethereum blockchain technology. The
functionalities consisted but not limited to minting, burning and swapping of
digital assets like fungible and non-fungible tokens.

Observation 3: We observed that the popular cryptocurrency exchange names like
(CoinBase, ), (Kraken, ), (cryptoWatch, ) were listed in this cluster. One of
the surprising notes was that some of the above mentioned established and
popular exchange platforms had a similarity percentage of up to 100% in this
cluster. This information could be used to infer upon the extent of plagiarism
or inadequate copyright policies in the world of blockchain technology based
decentralised applications.

Observation 4: 60% of the smart contracts in this cluster also leveraged the
Data Oracles code clone cluster discussed later in this section. It was also
one of the clusters that had smart contracts leveraging Token Management code
clones extensively.

  4. (4)

Finance: One of the industries that has the most potential of getting
revolutionized by the Ethereum blockchain technology is the Finance industry.
DeFi (Decentralised Finance) refers to financial services like accessing and
handling financial assets in a universal and decentralized manner using the
blockchain technology.

Observation 5: Despite all the hype around the DeFi solutions provided by the
Ethereum blockchain technology and smart contracts, our code clone analysis
showed that the smart contracts developed behind the DeFi DApps were very
limited and homogeneous when compared to the use-cases provided by traditional
financial applications. The DeFiLendingPool smart contract had a similarity
percentage of upto 71% that consisted of use-cases revolving around lending,
borrowing, withdrawing and depositing of assets. It leveraged a form of Token
Management cluster of code clones as well.

Figure 5. Exchange Domain Category Model

Figure 6. Decentralized Finance Domain Category Model

Figure 7. Gaming Domain Category Model

Figure 8. Data Oracle Domain Category Mode

Figure 9. Elliptical Curve Digital Signature Algorithm (ECDSA) - Security
Domain Category Model

  5. (5)

Security: Blockchain technology is based on cryptographic signatures to
authenticate an owner of an address without disclosing its private key. These
signatures are primarily used for signing transactions and sometimes also to
sign arbitrary messages. Ethereum blockchain technology uses the Elliptic
Curve Digital Signature Algorithm (ECDSA, ). ECDSA is only a signature
algorithm that cannot be used for encryption and consists of two integers: r
and s. Ethereum uses a recovery identifier v, thereby making the signature as
{r, s, v}. These message signatures can be used to verify the ECDSA signatures
using smart contracts. A function to recover the address of the private key of
the message signatory uses a pre-compiled contract at address 0x1. Signature
verification in smart contracts finds many useful applications such as, multi-
sig contracts and exchanges. The code clone cluster representing the ECDSA
message signatures validation functionalities implemented a form of standard
ERC-1271 provided by the Ethereum blockchain technology.

  6. (6)

Marketplace: Blockchain technology has encompassed $250 million market of NFTs
(non-fungible tokens) that are traded as digital assets. NFTs include
artefacts ranging from digital trading of art to virtual real estate and
gaming collectibles. A fungible token (FT) can be directly traded with another
FT, however, same cannot be said about NFTs. These marketplace DApps that
allow trading of NFTs ranged anywhere from $10 to hundreds of thousands of
dollars and yet lack security and proper copyright validation checks.

Observation 6: While analyzing the code clone clusters representing trading of
NFTs in smart contracts, we made an interesting observation that the domain
categories are not clearly separated in the Ethereum DApps ecosystem. For
example, the DApps AxieInfinity (AxieW, ) and DecentraLand (DecentralandW, )
contained code fragments from Marketplace domain category and they also
exhibited strong code functionalities categorised under Gaming domain
category.

  7. (7)

Data Oracles: The blockchain technology is a somewhat a closed network with
complexity revolving around extracting data from the blockchain network and
access data from external sources into the blockchain network. However, with
blockchain based DApps receiving growing interest from different industrial
domains, it is necessary to enable a smart contract to access external data
required to control the execution of the business logic. Data oracles provide
an efficient interface to access external data from various data oracles in to
a smart contract. These oracles can be modified to cater for different types
of data depending on the industry and requirements. Oraclize or Provable
Things (Provable, ) and ChainLink (ChainLinkW, ) are the most widely used data
oracles in the blockchain network. A data request to these data oracles is
validated against the inclusion of the following information from the
blockchain network: a data source type, a query, and an optional authenticity
proof.

  8. (8)

Gaming: Gaming DApps in blockchain networks have gained popularity because of
the involvement of trading of financial/digital assets in the form of NFTs and
sometimes even FTs while playing the game.

Observation 7: We observed clusters of code clones depicting a similarity
percentage of 100% of successful and popular Ethereum based gaming DApps such
as Cryptokitties (cryptokitties, ) and AxieInfinity (AxieW, ). Given the fact
that there are not many strict copyright protection systems in place for
blockchain DApps, there is an evident plagiarism of gaming DApps by the DApps
developers to benefit financially.

###  RQ3: Code Clones in Ethereum smart contracts - Modelling

Motivation. To be able to re-use the existing models in the Ethereum smart
contracts and modernize them to integrate newer business rules to diversify
the use-cases of Ethereum based DApps, we reverse engineer the extracted code
clones from Ethereum smart contracts to produce domain models.

Discussion. Figures {3, 4, 5,6, 7, 8, 9} show the structural models produced
by a manual reverse engineering of code fragments from the largest code clone
clusters of smart contracts categorised into domains in the above step.

The Token Management domain category mainly represents the ERC20 and ERC721
(EIP, ) token standards and therefore the domain model extracted from reverse
engineering the code clone cluster representing the functionalities mostly
cloned by smart contracts is showed in Figure 3. This model lists functions
related to management of tokens in a DApp, such as transfer, checking balance,
setting allowance of transfer, approval of transfer etc.

Similarly the Arithmetic Operations domain category uses the SafeMath (see
Figure3) interface to represent the operations that can be performed with the
surety of protecting the smart contract from the vulnerability that existed in
the Solidity programming language regarding Integer Overflow.

The Exchanges domain category model (see Figure5) represents the functions
that were cloned the most by the currently popular cryptocurrency exchange
platforms available. The functionalities represented in this model deal with
minting, burning and swapping of digital assets and currencies.

DeFi domain category model (see Figure6)was reverse engineered from code clone
clusters that required more semantic analysis of the code than the rest of the
domain categories. The DeFiLendingPool smart contract represented most of the
functions that were cloned by other DeFi applications, which consisted of use-
cases related to lending, borrowing, depositing and withdrawing of digital
assets from a smart contract defined lending pool.

Data Oracles domain category uses the Provable data oracle available online to
access external data into a smart contract for efficiently executing a
business logic.

The domain model depicts the Oracle and Oraclize Abstract contracts that
easily integrate the external data into a blockchain application. (see
Figure8)

Trading of digital assets, primarily NFTs, is realised by the Marketplace
domain category. The functions related to the business logic of this domain
consisted of creating and cancelling of auctions, maintaining order history,
order management such as receiving, executing, filling and cancelling a order.
It also leveraged the Token Management standard of ERC721 to manage the
exchanges of NFTs. (see Figure4)

The Gaming domain model represents the largest code clone clusters related to
a smart contract behind a Ethereum based gaming DApp. However, the model
extracted from this cluster is generic and does not relate to the business
rules of the game specifically. The model shows the structure of smart
contracts to manage ownership of the game, mint new tokens and get new
collectibles in the game. (see Figure7)

The Security model represents the signature validation structure implemented
by smart contracts using the ECDSA algorithm to sign the transfers and
abitrary messages. (see Figure9)

Figure 10. Meta Model for the mined domain models

##  5\. Related Work

Code Cloning in Ethereum Smart Contracts. In the space of code cloning
analysis and detection tools for Ethereum smart contracts, there are only a
few studies so far. The most similar study to ours is the work of Kondo et al.
(codecase, ) who study code cloning in Ethereum at the source code level with
a goal to quantify the number of clones in Ethereum and their characteristics.
They follow the ideology of positive impact of code cloning in software
systems to avoid taking the risk of writing vulnerable code. The authors
compare the code clone clusters to an online library of publicly available
open-source smart contracts on OpenZeppelin (OpenZeppelin, ). The analyse the
code cloning in a data-set of 33,073 smart contracts and resulted in a clone
ratio of around 80%. (codecase, ) employs a tree-based clone detector, Deckard
(Deckard, ) at the source code level and analyse the detected code clones to
understand the Ethereum blockchain technology ecosystem. We agree with the
authors observation that although the blockchain technology is gaining
adopting in a wide range of use cases, currently there is a lack of diversity
in its applications.

Another research study by Gao et al. produced a code clone detection tool for
Ethereum Smart Contracts called SmartEmbed. This tool identifies code clones
from the source code of smart contracts using the code embedding and
similarity checking techniques. SmartEmbed is aimed at quantifying clones in
Ethereum Smart Contracts and identify the clone-related vulnerabilities.
SmartEmbed was evaluated on a data-set of around 22000 smart contracts
contracts and resulted that the clone ratio in Ethereum Smart Contracts is
close to 90%. (SmartEmbed, )

Other than the above mentioned two studies, some researchers also analysed the
code cloning in Ethereum Smart Contracts at the byte-code level.

A research study is by Liu et al. that detects code clones in Ethereum Smart
Contracts using the byte-code generated by the Ethereum Virtual Machine (EVM)
of each deployed smart contract. is more challenging and less advantageous
towards derivation of models by reverse engineering of the code clone as the
byte-code factors in the version number of the Solidity programming language
being used and could potentially miss some of the core functional code clones
across smart contracts. (LiuByteCode, )

We expand upon these papers by investigating code clones of type 3, which
focuses on near miss renamed code clones rather than just the code clones
resulting from identical code reuse. Moreover, we contribute to the research
on code re-use in Ethereum smart contracts by providing a categorization of
these investigated large clusters of code clones. These clusters are further
subjected to reverse engineering to produce domain models to facilitate code
reuse at the model level.

Model-Dirven Development and Ethereum based decentralised applications (DApps)
development. A Model-Driven Reverse Engineering (MDRE) approach proposed in
(cosentino, ) aims at extracting business rules out of a Java application. To
achieve this goal, the initial step is the model discovery from Java code
followed by variable classification and domain variables model creation. The
final step of their approach is to extract the business rules model from the
domain variables model.

An extensive research on application of model-driven development approach to
smart contracts in general was produced in (Boogaard2018AMA, ). In this
research study, the author conducted a literature survey to gain the
requirements and techniques to formulate a model-driven development method for
smart contracts development. The proposed model-driven method is evaluated
using a standard case study and an experiment involving smart contract
developers. However, this research study does not support the frequently
evolving programming language requirements and established standards to the
smart contracts development.

An initial step to applying model-driven engineering to generate smart
contracts for IoT and cyber-physical systems by Garamvolgyi et al. talks
coordinating the usage of aforementioned system elements from behavioral
models, specifically UML statecharts.(modelSC, )

A DEMO, BPMN and UML based approach by Skotnica et al. proposes a visual
domain-specific language called DasContract. This approach creates models that
contain all possible execution paths according to the DEMO transaction axiom
and considers modeling of smart contracts using three subsystems - data,
processes and forms. (bachelorThesis, )

An agent-based approach by Frantz et al. is a computational modeling paradigm
in which phenomena are modeled as dynamical systems of interacting
agents.(agentBasedApproach, )

An MDE tool, Lorikeet by Weber et al. (Lorikeet2018Weber, ) uses BPMN models
and fungible/non-fungible registry data schema along with the bpmn-js modeling
library to develop a business process execution and asset management focused
approach for developing smart contracts. Another approach lead by Weber,
(Caterpillar2017Weber, ) uses Camunda which is an open-source workflow and
decision automation platform to model business processes to be executed using
smart contracts.

The behavioral modeling of smart contracts is realised by Mavridou et al.
(FSolidM2018, ), which proposes using finite state machine based approach to
model smart contracts execution. This tool is built upon WebGME MDE tool and
provides a graphical editor along with automatic code generation with security
plugins.

A recent study by Hamdaqa et al. (SAMMDE, ) propose a feature-oriented domain
analysis technique, iContractML, to extract the a reference model based on the
similarities and differences between the three blockchain platforms namely,
IBM Hyperledger Composer, Azure Blockchain Workbench, and Ethereum. This
research further realizes the derived reference model into an MDE framework to
enable smart contract developers in modeling and generating smart contracts
that are compatible with multiple blockchain platforms. Our approach differs
from iContractML extensively as the technique used to extract domain models in
our approach uses reverse engineering of frequently used code patterns,
whereas, iContractML uses a forward engineering approach for domain analysis.
The motivation behind iContractML is to promote scalability across different
blockchain platforms and our approach focuses on realizing the most frequently
used code patterns by smart contract developers in the form of a library of
models, thereby, enabling secure reuse of code libraries and better
comprehension of smart contract functionalities.

##  6\. Threats to Validity

### Threats to Internal Validity

One of the factors that can affect our results is that our approach is a code
clone based domain model mining method which can only derive instances of
repetitively used domain models in smart contracts. Though our method can
account for variations in models, this cannot be relied on for extending the
current state of usability of smart contracts. To overcome this limitation of
allowing only a threshold of variation in domain models during the code clone
detection method, we analysed and updated the derived domain models depending
on their applicability in a specific business process. We recognize that
further research in the area of business process modelling for Ethereum smart
contracts may benefit our results.

### Threats to External Validity

The dataset analyzed in this research consisted of a subset of all the
Solidity smart contracts deployed onto the Ethereum main-net that corresponds
to DApps. Our dataset does not include the smart contracts that do not
correspond to a DApp deployed onto the Ethereum main-net. Moreover, DApps are
being built on top of other blockchain networks as well and might represent
different characteristics when compared to the smart contracts analyzed in
this research. We recognize that further research with a larger dataset may
strengthen the correlation established in our results. We highlight that the
contribution of this paper is to conduct an initial study towards producing an
MDE framework to efficiently develop DApps that are maintainable and secure.
However, it should be considered that our research results may not be
applicable to all the DApps built on top of other blockchain networks as well.

##  7\. Conclusion and Future Work

The main reason behind code cloning in Ethereum Smart Contracts is the stigma
around the complexity involved behind securing a smart contract and using the
features provided by the Solidity programming language and the Ethereum
blockchain technology to efficiently develop a decentralised application
(DApp). The lack of experience, resources and an active involvement of online
community in developing DApps have made the software developers of traditional
programming languages to rely on standards and existing deployed DApps
available, thereby making the Ethereum smart contracts ecosystem very
homogeneous in functionality. We conducted this exploratory analysis of code
clones in Ethereum Smart Contracts as an initial step towards developing a
model-driven development framework for developing smart contracts based DApps.
We perform code clone detection of Type 1,2, 2c, 3-1, and 3-2c using the NiCad
code clone detection tool. We especially leverage the the near-miss code clone
detection of Type 3-1, 3-2c provided by NiCad to understand the
functionalities implemented by various smart contracts of a similar background
or domain to semantically categorise the highly cloned code clusters.

The future work in this research would be to perform an analysis of use-cases
implemented by the domains listed in our categorization of code clones, to be
factored in the structural domain models of smart contracts through M2M
transformations for each of the listed domain categories. Eventually we aim at
producing a model-driven development framework for fast and efficient
development of DApps with increased maintainability, extensibility and
diversity of business use-cases.

## References

  * (1) Solidity, “Solidity home page,” https://solidity.readthedocs.io/en/v0.5.1/, Accessed: 2021.
  * (2) J. Chen, M. Alalfi, T. Dean, and Y. Zou, “Detecting android malware using clone detection,” _Journal of Computer Science and Technology_ , vol. 30, pp. 942–956, 09 2015.
  * (3) C. K. Roy, “Detection and analysis of near-miss software clones,” in _2009 IEEE International Conference on Software Maintenance_ , 2009, pp. 447–450.
  * (4) Ethereum, “Ethereum home page,” https://www.ethereum.org/, Accessed: 2021\.
  * (5) E. I. P. (EIP), “Ethereum improvement proposals (eip),” http://eips.ethereum.org//, Accessed: 2021.
  * (6) P. Garamvölgyi, I. Kocsis, B. Gehl, and A. Klenik, “Towards model-driven engineering of smart contracts for cyber-physical systems,” in _2018 48th Annual IEEE/IFIP International Conference on Dependable Systems and Networks Workshops (DSN-W)_ , 2018, pp. 134–139.
  * (7) Etherscan, “Etherscan home page,” https://etherscan.io/, Accessed: 2021\.
  * (8) S. O. D. H. Page, “State of the dapps home page,” https://stateofthedapps.com/, Accessed: 2021.
  * (9) DAppRadar, “Dappradar home page,” https://dappradar.com/, Accessed: 2021\.
  * (10) Sol2Uml, “Sol2uml home page,” https://www.npmjs.com/package/sol2uml/v/1.1.6, Accessed: 2021.
  * (11) OpenZeppelin, “Openzeppelin home page,” https://openzeppelin.com/, Accessed: 2021.
  * (12) CoinBase, “Coinbase home page,” http://www.coinbase.com/, Accessed: 2021\.
  * (13) Kraken, “Kraken home page,” http://www.kraken.com/, Accessed: 2021.
  * (14) Cryptowatch, “Cryptowatch home page,” http://cryptowatch.ca, Accessed: 2021\.
  * (15) ECDSA, “Elliptical curve digital signature algorithm,” Accessed: 2021.
  * (16) A. Infinity, “Axie whitepaper,” https://whitepaper.axieinfinity.com/, Accessed: 2021.
  * (17) D. Land, “Decentraland whitepaper,” https://docs.decentraland.org/blockchain-integration/create-a-dapp/, Accessed: 2021.
  * (18) Provable, “Provable home page,” http://www.provable.com/, Accessed: 2021\.
  * (19) ChainLink, “Chainlink whitepaper,” https://link.smartcontract.com/whitepaper, Accessed: 2021.
  * (20) Cryptokitties, “Cryptokitties home page,” http://www.cryptokitties.com/, Accessed: 2021.
  * (21) M. Kondo, G. Oliva, Z. Jiang, A. E. Hassan, and O. Mizuno, “Code cloning in smart contracts: A case study on verified contracts from the ethereum blockchain platform,” _Empirical Software Engineering_ , vol. 25, 11 2020\.
  * (22) L. Jiang, G. Misherghi, Z. Su, and S. Glondu, “Deckard: Scalable and accurate tree-based detection of code clones,” in _29th International Conference on Software Engineering (ICSE 2007)_ , 2007, pp. 96–105.
  * (23) Z. Gao, X. Xia, V. Jayasundara, D. Lo, L. Jiang, and J. Grundy, “Smartembed: a tool for clone and bug detection in smart contracts through structural code embedding,” in _Proceedings - 2019 IEEE International Conference on Software Maintenance and Evolution, ICSME 2019_. USA: IEEE, Institute of Electrical and Electronics Engineers, 2019, pp. 394–397.
  * (24) H. Liu, Z. Yang, Y. Jiang, W. Zhao, and J. Sun, “Enabling clone detection for ethereum via smart contract birthmarks,” in _Proceedings of the 27th International Conference on Program Comprehension_ , ser. ICPC 2019. IEEE Press, 2019, p. 105–115.
  * (25) V. Cosentino, J. Cabot, P. Albert, P. Bauquel, and J. Perronnet, “A model driven reverse engineering framework for extracting business rules out of a java application,” 08 2012.
  * (26) K. Boogaard, “A model-driven approach to smart contract development,” in _Utrecht University_ , 2018.
  * (27) M. Skotnica, J. Klicpera, and R. Pergl, “Towards model-driven smart contract systems - code generation and improving expressivity of smart contract modeling,” 03 2021.
  * (28) C. K. Frantz and M. Nowostawski, “From institutions to code: Towards automated generation of smart contracts,” in _2016 IEEE 1st International Workshops on Foundations and Applications of Self* Systems (FAS*W)_ , 2016, pp. 210–215.
  * (29) A. B. Tran, Q. Lu, and I. Weber, “Lorikeet: A model-driven engineering tool for blockchain-based business process execution and asset management,” in _Proceedings of the Dissertation Award, Demonstration, and Industrial Track at BPM 2018 co-located with 16th International Conference on Business Process Management (BPM 2018), Sydney, Australia, September 9-14, 2018_ , ser. CEUR Workshop Proceedings, vol. 2196. CEUR-WS.org, 2018, pp. 56–60.
  * (30) O. L´opez-Pintado, Q. Lu, and I. Weber, “Caterpillar: A blockchain-based business process management system,” in _Proceedings of the Dissertation Award, Demonstration, and Industrial Track at BPM 2017 co-located with 15th International Conference on Business Process Management (BPM 2017), Sydney, Australia, 2017_ , ser. CEUR Workshop Proceedings. CEUR-WS.org, 2017.
  * (31) A. Mavridou and A. Laszka, “Designing secure ethereum smart contracts: A finite state machine based approach,” _CoRR_ , vol. abs/1711.09327, 2017\.
  * (32) M. Hamdaqa, L. A. P. Metz, and I. Qasse, “Icontractml: A domain-specific language for modeling and deploying smart contracts onto multiple blockchain platforms,” in _Proceedings of the 12th System Analysis and Modelling Conference_ , ser. SAM 2020. New York, NY, USA: Association for Computing Machinery, 2020, p. 34–43.
  * (33) TXL, “Txl home page,” http://txl.ca/, Accessed: 2021.
  * (34) 0x Protocol, “0x protocol whitepaper,” https://github.com/0xProject/whitepaper/blob/master/0xwhitepaper.pdf, Accessed: 2021.
  * (35) E. N. Space, “Ens whitepaper,” https://status.im/whitepaper.pdf, Accessed: 2021.
  * (36) B. Org, “Beat org whitepaper,” , Accessed: 2021.
  * (37) M. Jurgelaitis, V. Drungilas, L. Ceponiene, R. Butkiene, and E. Vaiciukynas, “Modelling principles for blockchain-based implementation of business or scientific processes,” in _IVUS_ , 2019.
  * (38) OMG, “Object manamgement group,” https://www.omg.org/, Accessed: 2021.
  * (39) K. Boogaard, “A model-driven approach to smart contract development,” 2018.
  * (40) I. Weber, X. Xu, R. Riveret, G. Governatori, A. Ponomarev, and J. Mendling, “Untrusted business process monitoring and execution using blockchain,” 09 2016\.
  * (41) H. Syahputra and H. Weigand, _The Development of Smart Contracts for Heterogeneous Blockchains_ , 01 2019, pp. 229–238.
  * (42) C. K. Frantz and M. Nowostawski, “From institutions to code: Towards automated generation of smart contracts,” in _2016 IEEE 1st International Workshops on Foundations and Applications of Self* Systems (FAS*W)_ , 2016, pp. 210–215.