Toward A Self-Learned Smart Contracts: Ahmed Almasoud Maged M. Eljazzar, IEEE Member Farookh Hussain, IEEE Member
Toward A Self-Learned Smart Contracts: Ahmed Almasoud Maged M. Eljazzar, IEEE Member Farookh Hussain, IEEE Member
Toward A Self-Learned Smart Contracts: Ahmed Almasoud Maged M. Eljazzar, IEEE Member Farookh Hussain, IEEE Member
Ahmed Almasoud Maged M. Eljazzar, IEEE Member Farookh Hussain, IEEE Member
Faculty of Software Computer Engineering Dept. Faculty of Software
University of Technology, Sydney Faculty of Engineering, Cairo University University of Technology, Sydney
Ultimo NSW 2007 Giza 12613, Egypt Ultimo NSW 2007
[email protected] [email protected] [email protected]
Currently, several platforms offer the support of smart contracts.
Abstract - In recent years, Blockchain technology has been highly There are definitely some differences in architecture, consensus,
valued and disruptive. Several research has presented a merge
between blockchain and current application i.e. medical, supply programming language support, and privacy. But each one of
chain, and e-commerce. Although Blockchain architecture does not them has its own supporting community and decentralized apps
have a standard yet, IBM, MS, AWS offer BaaS (Blockchain as a
(DAPPS).
Service). In addition to the current public chains i.e. Ethereum,
NEO, and Cardeno. There are some differences between several
public ledgers in terms of development and architecture. This paper The main concept circulating around all of them refers to
introduces the main factors that affect integration of Artificial Blockchain as a database that stores all transactions grouped in
Intelligence with Blockchain. As well as, how it could be integrated blocks. In most cases, if a new transaction is created, the
for forecasting and automating; building self-regulated chain. sender broadcasts it in the peer-to-peer (P2P) network to all the
other nodes in the network. The transaction would then show
as pending. As the nodes receive the transaction, they validate
it and keep it in their transactional pools based on the
consensus algorithm in the network. The Proof of Work
Index Terms—Blockchain, Smart contracts, Artificial intelligence,
protocol (PoW) is used in Bitcoin, Ethereum, and other chains.
Distributed autonomous organization.
The state of the art behind PoW is to validate transactions in
means of running predefined checks about the structure, and
I. INTRODUCTION the actions in the single transaction. Miners (validation nodes)
create a new block and include all, or some of the available
Blockchain is the first truly stable decentralized global
transactions from their transactions pool. Then, the block is
system. Bitcoin [1] is similar to other cryptocurrency in its
mined.
concept, yet it is the most known and used case. The main aim of
Bitcoin is to simplify the exchange of assets and services by
offering a commonly trusted accepted good. Since it removes any Even though the Blockchain technology has a great potential
intermediary approving authority (e.g. Visa or Mastercard) and for the construction of future Internet systems, it is facing
offers trust between parities. The Blockchain transactions are not numerous technical challenges i.e. scalability, development,
limited to that application. Thanks to smart contracts, they can latency, and transactions per second. This paper introduces a
represent digital assets between multiple parties. A smart contract review for smart contracts platforms and how AI could be
is a software component encompass business logics and integrated with smart contracts for rapid development. As
transactions that run on a Blockchain. Blockchain combined with Artificial Intelligence continues to make an extreme interaction
smart contracts establish a new generation of decentralized with almost every faction of the society. Definitely,
system, and transactional applications based on trust between forecasting, optimization, and automating are the main AI
parities. Moreover, the accountability and transparency at their contribution in several domains [5]. Which in turn reflects to
essence, streamlines the business processes and the handling legal self-learning smart contracts from the previous experience
constraints related to the chain. This paper is organized as follows: Section
II provides a literature review of other smart contracts
platforms. Section III compares differences between
With the rise of developing Ethereum smart contracts, a
Blockchain features. Section IV includes AI factors in the
Blockchain became a decentralized general-purpose computer.
Blockchain architecture. Integrating AI with smart contracts
Since it provides an open, decentralized, and fault-tolerant
are presented and discussed in Section V. Finally, Section VI
transaction technique. As a result, it attracted the attention of
concludes the paper.
many financial corporations and public sectors. Which in turn
sparked hundreds of chains regarding digital assets, medical field, II. LITERATURE REVIEW
Internet of Things (IoT), smart cities, supply chain, reputation
Several platforms offer the support of smart contracts. Smart
systems and security services, money transferee and online
contracts are one of the most important aspects of Blockchain
payment [2-4].
technologies, as well as the reason why Blockchains can be
called a disruptive technology. It refers to the logic of the chain,
and the increase in efficiency of our social structure over the
time. Ethereum [6] is a first Blockchain-based ecosystem that III. AI FACTORS IN BLOCKCHAIN ARCHITECTURE
provides a compatible environment to run smart contracts. It is a
After reviewing several Blockchain architectures, it is important
main standard in the world of smart contracts and has the major
to understand why Blockchain architecture is significant. In
support community among other platforms. As a result, one of
addition, the main feature we are targeting from Blockchain may
the Ethereum features is the Truffle development framework. It is
cause some latency, and scalability issues. Simply, Blockchain
a popular development framework for Ethereum that supports
technology facilitates peer-to-peer transactions without any
built-in smart contract compilation, linking, deployment, and unit
intermediary. One can consider Blockchain as simply a database
testing.
that is public, distributed, is infinitely updated, and is secured by
the cryptography. If the business requires these features; then a
NEO [7], also known as Chinese Ethereum, has some advantages
question can be raised. If listed participants are limited, should
over Ethereum since it is more scalable. It can process multiple
one build a public Blockchain or private Blockchain to serve to
transactions promptly, significantly minimizing wait times for its
specific use-cases? This leads to huge concerns for selecting the
users. Another main advantage being, Ethereum is more bounded
best architecture that corresponds these use-cases.
than NEO. Unlike the Solidity language in Ethereum, NEO smart
contract can be coded directly by using most of high-level
programming language. Besides, NEO developers’ community Therefore, the major question is whether or not we’d need all
provide plug-ins for these languages, which are used to compile Bitcoin Blockchain features, or could a distributed ledger be
high-level languages into instruction sets supported by NEO designed differently to fit an individual use case. In particular,
virtual machines. For now, the NEO community is growing. But confidentiality concerns are imposing the emergence of
it is still distant from Ethereum community, and its supporting alternative Blockchain architectures referred to as ‘private
frameworks due to its short age when comparing to Ethereum. Blockchain’. Some distributed ledgers architecture sacrifices, in
some decentralization to address some Blockchain shortage
issues. For example, attaching Sidechains to Blockchain may
On the other side, LISK [8] avoids the standard barriers of entry
handle some scalability issues. As a Blockchain architect, one can
in Blockchain technology. It is end-to-end Blockchain JavaScript
build Blockchains that require permission in order to read the
project. LISK is based on the sidechain concepts [9]. Developers
information within the Blockchain. Thus, Limiting the network
need to focus on developing D-Apps. Then, link D-Apps with
users who can transact on the Blockchain. And those who have
main LISK ledgers. The main philosophy in LISK is to allow the
the access to validate the data or read the data on chain or not.
developers to focus on the development with a common
For an empowered smart contract with AI, several factors should
language, and leave the rest to the LISK chain. Through this
be considered:
method, developers can make use of Blockchain features without
the headache of node infrastructure and configuration. This
approach begins to spark and manipulate the Blockchain 1- Mining.
architecture in several projects. In doing so it decreases the
administration headache for developers. Meanwhile in Cardeno Smart contracts are the mastermind of the chain. It gets executed
[10], they are focused on building a group of design patterns, and by sending transactions between different parities. This
engineering best practices. It builds a control layer to govern the transaction may include metadata to be used by the smart
usage of Smart contracts. The main aim of the layer is to contract. In order to execute code in an Ethereum smart contract,
recognize identity, and maintains a degree of separation from the each transaction requires a specific amount of gas. Which refers
currency it supports. Furthermore, in adding sidechains, Cardeno to the transaction cost. It is sent alongside the transaction along
seeks for communication between several Blockchain and with the price in ether for each unit of gas. Gas is important for
Sidechains. It is very simple for an ecosystem of Bitcoin to flow several security reasons. It prevents denial of service attacks
into Ethereum without needing to go through centralized (DoS), which may occur from the untrusted resources for
exchanges. executing purposeless contracts to make the network
unresponsive. Besides, preventing infinite loops or the halting
At last, there is a Hyperledger project by Linux Foundation [11]. problem.
There are several projects introduced by Hyperledger
community. Fabric is a permissioned Blockchain architecture While in permissioned Blockchain, this may or may not involve
taking the leading in Blockchain application. One of the 'proof of work' from the nodes. There are some politics around
differences in the structure between permissioned Blockchain this, as there are those who consider private Blockchains that do
and permissionless Blockchain is mining. In a permissioned not apply any of (PoW) (that is, Blockchains with no mining) to
Blockchain, nodes do the mining process. And in certain not be Blockchains at all, but simply shared ledgers.
applications, the mining process may actually be delegated to
authorized network members. The same concept would be 2- Data on the Chain.
applied to Verification of transactions and blocks.
It is well known in public chain that each piece of information
that one stores is duplicated into hundreds or more nodes (i.e.
more than 100,000 in case of Bitcoin). Blockchain are not a good
solution for storing data for substantial sizes, and medical health IV. INTEGRATING SMART CONTRACTS WITH AI
records as an example. But still, Blockchain is able ensure the
The aim of smart contracts is the automation of business by
transparency of transactions. One of the workarounds is to
reducing the usage of paperwork and by eliminating
encrypt the data before adding it to the chain. Then, decrypt it in
intermediaries (e.g., lawyers). Thus, decreasing costs. Wills and
the application layer when the user needs to read it. For huge
all sorts of Legal documents can be processed using smart
data, it is commonly stored in off-chain storage (i.e. IPFS, AWS)
contracts such as NEO or straits. AI can be integrated with smart
or by adding a fingerprint instead of the medical record. It then
contracts through rules and policies assigned to the chain.
adds a hash address for data location.
Leading to the integration of Self-learning artificial intelligence
By using this method, the more network users that take part in
and smart contracts. Assuring that they are legally binding, and
verification with respect to the current consensus algorithm, the
allowing their adaption in case of environmental changes.
more secured and decentralized the chain becomes!
The deep understanding of rules and policies in the chain, and
On the other hand, the permissioned chain acts as traditional the analysis of where AI should come in enables the creation and
database, with some features of the Blockchain. Such as, execution of such complex smart contracts. Therefore, making
permissions, multiple input validation, multiple copies, append- them more effective and learnable. The more data AI has, the
only writes and data transparency. The architect defines who has better it can predict outcomes. For example, in contract
the capability to read and modify the data. For the health records, negotiation in supply chain, AI could act as a recommendation
only few parities have an access to read the data based on rules system. It can analyze archived contracts to view how parties
and policies. That is why a Permissioned (Private) Ethereum or negotiated in the past. The AI recommendation engine would
Stellar implementations would be a good option to manipulate then be able to suggest the types of language and clauses that are
the data. These kinds of Blockchain are similar to the public most likely to secure agreement between different parities in the
chain, but instead acts as a permissioned chain. chain. Afterwards, AI can analyze past contracts to identify
factors that are not previously considered, and incorporate them
into future contracts. This section explains how AI could be
3- Network Actors. integrated with smart contracts in terms of (Network users, data
on the chain, and mining).
The terms public, permissioned, and private refer to the network
user. In other words, the person who would be able to operate a 1- Smart contracts cost.
node, access to the data and validate the transaction. Public
Blockchain refers to decentralized system, where anyone can be It is well known that AI perquisites computation resources. In
a network user. In some cases, there is a little restriction for low Ethereum, deploying a contract has a minimum fee of 32000 gas,
resourced users. On the other hand, private Blockchains are and 200 gas per byte of the source code. In addition to calling
operated by known entities such as employees in a company. and storing data cost. The fee is 20k gas to store a 256-bit word.
They have the value of immutability and efficiency over alias A kilobyte is thus 640k gas. The basic idea behind storing data is
and transparency. Mainly laying in the area of a specific gas prices based on Oracle's and miners. It will go up
industry. In supply chain, the Blockchain enables goods to be exponentially as ETH appreciates. But when it comes to AI one
tracked from raw material to completed form during the supply should consider storing and manipulating a lot of data. However,
chain cycle. this may be very costly. In comparison with storing data off-
chain, cost could be estimated by the following equation:
4- Blockchain Integrity
Gas Used * Gas Price * USD/ETH
Current chain has some integration with several concepts (i.e.
Sharding, state channel, Master node architecture, etc.). Sharding For example, 32000 Gas with average gas price (8 Gwei) cost
is a common term in the database. It is a type of database $0.18074. This number seems very small, but in repeating these
partitioning to divide large database into smaller and faster parts smart contracts in every transaction would be costive.
known as data shards. While the target of using State Channels is
helpful in retaining privacy, as it allows the recording and 2- Rules and policies.
execution of transaction between two parties on an off-chain
platform, the reference for such transactions is saved in relevant It is important to elaborate the rules that would be applied
Blockchain system after their successful completion. However, through AI in the chain. In some cases, it acts as a
such transactions are useful through State Channels only for recommendation engine (i.e. a recommendation for tracing items
smaller payments involving frequent sending, and receipt of in supply chain). While in other cases, it acts as comprehensive
payments between two parties. The system does not support in data analytic for all transactions in the chain. Both of these
case large amount transactions are involved. scenarios have a different approach. a) Real time
Recommendation engine
To have a recommendation engine, a historical data is analyzed.
Rules and policies are defined based on the data to match
business logic. Working on off-chain data and caching the
previous experience of smart contracts in an off-chain storage, participants from any kind of centralized system or the human
assists in training a model with several scenarios in real time. factor influence. Yet, it guarantees the automation, transparency,
Training a model to be able to act as a recommendation engine in and safety of the entire process.
real time. This approach allows developers to only need use of
read data from smart contracts with no cost in most public When coding DAO, it is a fully autonomous system. Hence, the
Blockchain. Accordingly, linking these API (Application limitation of functionality of smart contracts decides the degree
Program Interface) with data stored off-chain. Finally, writing of automation. In such case, creating new digital assets, and
smart contracts consuming these API in real time. adding more smart contracts to handle specific complain in the
network based on participants’ transactions; as shown in figure
2. Many transactions are automated on the chain through smart
Some of public Blockchain offers supporting side-chains contracts. In such a case, one needs to define new digital assets
transactions, Sharding assists in executing small transactions in that depend on previous transactions. Defining a set of rules to
shorter time. edit shortage in a previous smart contract (i.e. updating the
b) Analytic Dashboard version of smart contracts). For example, due to new policies,
event C will replace event B if event A took place.
According to the network users, all data stored in the Blockchain
are analytics based on a set of rules and policies, in supply chain
use-case. The manager needs to inspect all production lines,
point of sales, and workers’ activity. Besides, defining a set of
variables to automate several tasks. These variables are
translated into predefined rules, which in turn are reflected into
smart contracts to automate planning as shown in figure 1.
The state of the art behind smart contracts is setting conditions.
Business Smart
Rules
Factors Contracts