The Use of Block Chain Technology in Different Application Domains (PDFDrive)
The Use of Block Chain Technology in Different Application Domains (PDFDrive)
Technology in Different
Application Domains
Bachelor Project in Software Development
In this paper, the exciting possibilities that block chain technology offers in
regards to decentralised trust-free systems are investigated. More specifically
this includes research of how block chain technology can advantageously be
utilised in different domains, from finance to more general societal applica-
tions.
On the basis of a small trust-based coffee shop, a proof of concept system
has been developed as a base point for an evaluation of the strengths and
weaknesses of the block chain technology. Clearly both are present, but they
are much dependent on which cases the technology is applied to. In the
example of a coffee shop, the low maintenance, built in security and ease of
implementation are factors that speak for the utilisation. On the other hand
the inconvenience of currency conversion and transaction time are drawbacks.
On a more general scale the security and trust-freeness of the technology
is definitely features that allow for it to be applied in a broad spectrum
of applications. However, scalability, costs and fluctuating currencies are
hindrances.
It is argued that block chain technology has the potential to restore trust
in the banking sector by introducing a level of transparency.
The technology is still young and suffers from teething troubles, but it
is argued that as it matures it will have a great impact in many areas of
application.
Contents
1 Introduction 1
1.1 Research question . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.2 Contents of This Paper . . . . . . . . . . . . . . . . . . . . . . 2
1.3 Cryptographic Economic Systems . . . . . . . . . . . . . . . . 3
1.4 Why Ethereum? . . . . . . . . . . . . . . . . . . . . . . . . . . 3
2 Methodology 4
2.1 Design Science Research . . . . . . . . . . . . . . . . . . . . . 4
2.2 Phases of DSR . . . . . . . . . . . . . . . . . . . . . . . . . . 4
2.3 Reflections on Research . . . . . . . . . . . . . . . . . . . . . . 6
3 Background 7
3.1 Bitcoin: the First DAO . . . . . . . . . . . . . . . . . . . . . . 7
3.2 Block Chains in Finance . . . . . . . . . . . . . . . . . . . . . 8
3.3 Re-Decentralising the Internet . . . . . . . . . . . . . . . . . . 9
3.4 From the Internet of Things to the Economy of Things . . . . 9
3.5 Future Research . . . . . . . . . . . . . . . . . . . . . . . . . . 10
I
4.4.1 Smart contracts . . . . . . . . . . . . . . . . . . . . . . 15
4.4.2 Transactions . . . . . . . . . . . . . . . . . . . . . . . . 16
4.4.3 Ether and gas . . . . . . . . . . . . . . . . . . . . . . . 17
4.4.4 Messages . . . . . . . . . . . . . . . . . . . . . . . . . . 17
4.4.5 Mining ether . . . . . . . . . . . . . . . . . . . . . . . 18
4.4.6 Ethereum Virtual Machine (EVM) . . . . . . . . . . . 18
4.4.7 Block time . . . . . . . . . . . . . . . . . . . . . . . . . 19
5 Proof of Concept 20
5.1 The Concept . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
5.1.1 Current system . . . . . . . . . . . . . . . . . . . . . . 20
5.1.2 The issue of trust . . . . . . . . . . . . . . . . . . . . . 21
5.2 Implementation . . . . . . . . . . . . . . . . . . . . . . . . . . 21
5.2.1 Smart contract . . . . . . . . . . . . . . . . . . . . . . 21
5.2.2 JavaScript client . . . . . . . . . . . . . . . . . . . . . 22
5.3 Tour of the System . . . . . . . . . . . . . . . . . . . . . . . . 23
5.3.1 The welcome screen . . . . . . . . . . . . . . . . . . . . 24
5.3.2 Purchasing a punch card . . . . . . . . . . . . . . . . . 26
5.3.3 Purchasing coffee . . . . . . . . . . . . . . . . . . . . . 28
5.4 Modular Implementation . . . . . . . . . . . . . . . . . . . . . 29
5.4.1 The contracts . . . . . . . . . . . . . . . . . . . . . . . 30
6 Analysis of Implementation 32
6.1 Testing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
6.1.1 Solidity contract . . . . . . . . . . . . . . . . . . . . . 32
6.1.2 Black-box testing . . . . . . . . . . . . . . . . . . . . . 33
6.1.3 JavaScript client . . . . . . . . . . . . . . . . . . . . . 33
6.2 Trust and Security . . . . . . . . . . . . . . . . . . . . . . . . 34
6.3 Limitations . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
6.3.1 Block time . . . . . . . . . . . . . . . . . . . . . . . . . 34
6.3.2 Extendability . . . . . . . . . . . . . . . . . . . . . . . 35
6.3.3 Improvements . . . . . . . . . . . . . . . . . . . . . . . 35
6.4 Modular Implementation . . . . . . . . . . . . . . . . . . . . . 36
II
7 Discussion 39
7.1 Why Decentralise? . . . . . . . . . . . . . . . . . . . . . . . . 39
7.2 The Greater Picture . . . . . . . . . . . . . . . . . . . . . . . 40
7.3 Economic Systems . . . . . . . . . . . . . . . . . . . . . . . . 41
7.4 Challenging the Block Chain . . . . . . . . . . . . . . . . . . . 41
7.4.1 The size factor . . . . . . . . . . . . . . . . . . . . . . 41
7.4.2 Coping with stress . . . . . . . . . . . . . . . . . . . . 43
7.4.3 Waiting disrupts the flow . . . . . . . . . . . . . . . . . 44
7.4.4 Fees: hidden or blatant . . . . . . . . . . . . . . . . . . 45
7.4.5 Fluctuating currencies . . . . . . . . . . . . . . . . . . 47
7.4.6 Keeping everything safe . . . . . . . . . . . . . . . . . 48
7.4.7 Converting currencies . . . . . . . . . . . . . . . . . . . 48
8 Reflections 50
8.1 Electronic Voting . . . . . . . . . . . . . . . . . . . . . . . . . 50
8.2 Digitalised Rights . . . . . . . . . . . . . . . . . . . . . . . . . 52
8.3 Ripple . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
8.3.1 What is Ripple? . . . . . . . . . . . . . . . . . . . . . . 53
8.3.2 Ripple and block chain technology . . . . . . . . . . . . 55
8.4 The Opaque Banking Sector . . . . . . . . . . . . . . . . . . . 55
8.4.1 Adaptation . . . . . . . . . . . . . . . . . . . . . . . . 57
9 Conclusion 59
References 62
A Implementation code 72
A.1 Non-modular implementation . . . . . . . . . . . . . . . . . . 72
A.1.1 Smart Contracts . . . . . . . . . . . . . . . . . . . . . 72
A.1.2 HTML JavaScript Client . . . . . . . . . . . . . . . . . 76
A.2 Modular implementation . . . . . . . . . . . . . . . . . . . . . 85
III
List of Figures
5.1 AlethZero – the browser used to view our client and display
the state of the network. . . . . . . . . . . . . . . . . . . . . . 24
5.2 The GUI of the HTML/JavaScript client. . . . . . . . . . . . . 24
5.3 The admin view of the client. . . . . . . . . . . . . . . . . . . 25
5.4 A pending transaction . . . . . . . . . . . . . . . . . . . . . . 27
5.5 The transaction is stored on the block chain . . . . . . . . . . 27
5.6 The transaction has gone through and the system now recog-
nises the user’s name and his balance since this data is now
stored in the block chain. . . . . . . . . . . . . . . . . . . . . . 28
5.7 After buying a cup of coffee, the balance of the punch card
has been updated. . . . . . . . . . . . . . . . . . . . . . . . . . 29
6.1 Representations of the classic MVC (a) and the modified MVC
(b). In the modified version all addresses of other components
are found using the Manager, represented by dashed arrows. . 37
IV
Acknowledgement
We would like to thank the very open minded and welcoming communit-
ies surrounding and supporting different cryptocurrencies and block chain
technologies.
A special thanks to the Ethereum development community for answering
all of our questions and helping us getting up and running as quickly as
possible. And doing so while being very busy getting Ethereum ready for
the Frontier release.
V
1 | Introduction
This bachelor thesis will investigate the potential of the Ethereum tech-
nology, and the overall application areas, where decentralisation of organisa-
tions and applications through block chain technology can be useful.
More specifically the focal point of this paper is to investigate how cur-
rently trust-based centralised systems in the financial sector and society in
general, can benefit from becoming decentralised and trust-free. This is done
through evaluating the proof of concept implementation of a digitalised punch
1
card on the Ethereum block chain.
• What are the benefits and drawbacks of block chain technology in gen-
eral?
2
1.3 Cryptographic Economic Systems
In 2009 Bitcoin introduced a brand new form of currency. But for a software
developer, the revolutionary technology that made this possible is much more
fascinating: the block chain. Bitcoin is a decentralised cryptocurrency which
runs trust-free, autonomous, publicly and anonymously. All this is possible
thanks to the block chain.
Bitcoin is fascinating due to it being the first big Decentralised Autonom-
ous Organisation (DAO). An organisation that runs autonomously due to
the rules of transactions being dictated by the block chain protocol, and de-
centralised due it being maintained by a peer-to-peer network. The fact that
big organisations can run this way changes the landscape of organisations,
corporations and their applications. As mentioned in the beginning, this
technology is still in its dawn of being applied in other domains. Therefore
this is a very interesting topic to investigate since it has the possibility of
changing an entire ecosystem of transaction systems.
3
2 | Methodology
This chapter covers the methodologies that are used in order to investigate
and answer the research questions in section 1.1.
Awareness of Problem
The process starts with an interesting problem that is often sparked by new
developments in the industry. For example you have knowledge of a system
that has issues that now can be improved upon. In this case there is a problem
of trust and transparency in transaction systems. A specific case is the self-
4
Figure 2.1: Cognitive processes used in Design Science Research as suggested
by Vaishnavi and Kuechler[52].
Suggestion
A proposal of change is made based upon research and theory in the field, and
specifications are made for the artefact that is going to be designed. In this
case, through researching the ecosystem of cryptographic economic systems
and block chain technology the suggestion is to implement a digitalised punch
card system built on the Ethereum block chain.
Development
The artefact is designed and implemented. Our digitalised punch card will
be realised. The back-end of smart contracts are coded and issued, and a
client for users to manipulate these is implemented.
5
Evaluation
The success of the artefact in terms of solving the research problem is ana-
lysed and evaluated through different evaluation methods such as testing,
experimenting and observation[32].
Conclusion
The end of the research cycle. The results of our research is accounted for,
which can be used as basis for more research.
6
3 | Background
This chapter will give you some background knowledge of the research and
developments in cryptocurrencies and block chain technology so far, in order
to give a brief overview of the landscape of this.
7
3.2 Block Chains in Finance
The perks of the block chain are very interesting in finance where trans-
parency, trust and security in transactions are vital[23]. The block chain
has thus been used to develop many economical systems and cryptocurren-
cies such as Bitcoin and thousands of altcoins, such as Litecoin1 , Dogecoin2
and Nxt3 . Cryptocurrencies are especially handy because you do not need
a middleman such as a bank to ensure trust and security in transactions[11,
23, 39]. This is autonomously dealt with by the block chain protocol[11, 39],
which consequently leads to transaction fees being much lower than that of
a bank[15].
Cryptocurrencies are also handy in microtransactions since you can pay
much smaller fractions of a cryptocurrency than a fiat currency[15]. Addi-
tionally these digital currencies are useful in terms of the global market since
your transactions go directly from peer to peer, avoiding banks. This means
you can send money to anywhere in the world only waiting for a block to
be generated. In Bitcoin’s case this is about 10 minutes[39], which is much
faster than a transaction through multiple banks, and much less costly due
to the fees such an international transaction would have.
The use of block chains have been generalised to trade more than only
money. Digital assets such as shares, contracts and stock options have been
traded as smart property on the block chain. Every object that you have a
right to can be emulated as a smart property. A protocol that does this is
Mastercoin 4 . Mastercoin uses meta data through what they call an omni-
layer that allows for the creation of digital assets to issue and trade as smart
properties on the Bitcoin block chain. Thus economic systems, and trading
in general, benefit from this trust-free, secure and transparent transaction
system. The latest development in this area is that NASDAQ is experiment-
ing with the block chain in order to automate transaction processes that are
now handled by lawyers[44].
1
https://litecoin.org/da/ (visited on 16/05/2015)
2
http://dogecoin.com (visited on 16/05/2015)
3
http://nxt.org (visited on 16/05/2015)
4
http://www.omnilayer.org (visited on 14/05/2015)
8
3.3 Re-Decentralising the Internet
In the recent year, there has been a shift in the research area of the block
chain[19]. Secure and transparent transactions are applicable in many other
use cases than economic systems.
In terms of today’s web, most traffic go through a few gigantic nodes
of corporations such as Google, Facebook, Amazon etc. The internet today
is much more centralised than 10 years ago due to the commercialisation
of the web, why today we have corporations essentially monopolising and
owning parts of the world wide web[51]. There has been a shift in power
from the users to the corporations. We trust all our data in the hands of big
corporations, whose processes are very intransparent[35]. In addition gov-
ernment surveillance programs such as the National Security Agency (NSA)
are tapping into this data without the users knowing[29, 51].
Ethereum envisions to decentralise applications in what they dub a Web
3.0, where applications and their data are run through block chain techno-
logy, thus allowing for a decentralised, transparent and secure internet. This
would shift the power back to the users in a “redemocratisation” of the inter-
net, as stated on their homepage5 . Transparency would thus give users the
power to see exactly how their data is handled, and that NSA is not secretly
listening in on your conversations[51].
9
technology is called the Internet of Things[9, 41]. IBM, in collaboration with
Samsung, is building a block chain powered technology dubbed ADEPT [33,
41] on the Ethereum protocol, to support this network of devices interacting
with each other through smart contracts. They give this example of how IoT
can be utilised:
10
4 | Account for Technology
In this section we will explain what Ethereum is and why exactly this tech-
nology is extraordinarily interesting in regards to cryptocurrencies and a
decentralised web.
4.1 Ethereum
Ethereum is one of many technologies emerged from the original block chain
technology used by Bitcoin. The original Ethereum white paper[11] written
by Vitalik Buterin in late 2013 describes the basic idea behind a new and im-
proved way of using the decentralised block chain technology. In 2014 Gavin
Wood formally described the technology in the Ethereum yellow paper[53].
The platform is supposed to be released in 2015, but at the time of writing6
it is still in a development state.
Etherum takes the block chain technology to the next level by allowing
stateful user-created digital smart contracts to be executed by implementing
a generic programmable block chain. It is not solely a network for monetary
transactions like Bitcoin, but a network where transactions can be used to
execute an unlimited variety of smart contracts. This block chain is the
back-end of decentralised applications, or as Ethereum dubs them: ÐApps.
Some examples of applications that Ethereum can be used for are: voting
systems, domain name registries, financial exchanges, crowdfunding plat-
forms, company governance, intellectual property and smart property.
6
16/05/2015
11
4.2 Vision
According to the Ethereum white paper the reasoning for making Ethereum
is to
Ethereum does this by building what they call the “ultimate abstract
foundational layer: a blockchain with a built-in Turing-complete program-
ming language”[11]. This basically means that Ethereum allows everyone to
write smart contracts (described in section 4.4.1) resulting in decentralised
applications where it is possible to build your own arbitrary rules for own-
ership, transaction formats, and state transition functions. This relatively
simple way of creating your own smart contracts, adding them to the block
chain, and using them, creates a great environment to potentially solve some
paramount issues in regards to some of the mentioned examples in section 4.1,
where a centralised authority is trusted. One of the main points of Ethereum
and other technologies using a block chain is that they are trust-free and de-
centralised.
12
Figure 4.1: Simplified version of how Bitcoin’s block chain connects blocks
but essentially you can traverse through the entire block chain and find every
single transaction ever made. Hashing algorithms are used to make sure that
all blocks are well formed and not tampered with, and thus the block chain
keeps itself secure and virtually unbreakable.
The above is one defining feature of block chain technology, another is
that it is public and decentralised. The block chain is not run from a single
server, it is run on a widespread network of computers. They all hold all data
in the block chain, and all work on expanding it. These computers are called
miners (see section 4.3.1). Depending on the block chain protocol, these will
compete to form new blocks that are then added to the block chain when
selected through consensus schemes (see section 4.3.2).
The combination of the two features stated above is what makes the block
chain desirable. It is secure through the immutability it gains from the hash-
ing algorithms, when applied on the decentralised network and transparent
because anyone can look through all blocks. The combination of this security
and transparency is what makes the block chain a trust-free technology.
In the past block chains have been compared to bank ledgers[6, 28]. How-
ever, this definition somewhat limits the block chain artificially, as the general
idea behind it can be used in a much more general sense. Transactions are
not limited to monetary transferrals, but can also be used to transfer any
form of data. How this data is then used, again depends on what block chain
protocol it is sent on.
13
In the remainder of this section, an account for the general features of
the block chain will be made before focusing specifically on the Ethereum
protocol.
4.3.1 Mining
To incline people to use their processing power to carry the system, the block
chain protocols will reward “miners” in different ways. The more miners that
run a node on their hardware, the more secure the system is.
The way you get rewarded as a miner on a block chain is by creating a
block that is selected to be a part of the block chain. Therefore all miners
will try to create blocks (automatically done by the mining software), so the
system has to select which block gets put into the chain. But since there is
no central node that can make decisions, all the nodes have to agree, and
that too is done by a consensus scheme[11]. When all, or most of, the nodes
can automatically agree on a block, it is easy to carry on. Any node that
tries to select a different block will automatically be disregarded by the rest
of the system, and it is therefore impossible to cheat the block chain, unless
you can circumvent the consensus scheme (see below).
4.3.2 Consensus
When deciding on a block, there needs to be consensus in the block chain
system. This is done by the protocol’s consensus scheme, which dictates
the way all nodes can agree that a miner has a right to include its block
into the block chain. On Bitcoin and the current7 version of Ethereum, the
scheme is called proof of work. In this particular scheme, the goal is to show
that the miner has done a certain amount of work that entitles it to the
block reward. In the case of Bitcoin, this is done by requiring the miner
to find a string, that when concatenated with a hash of the previous block
header and then hashed, returns a string with a certain amount of preceding
zeroes. Ethereum’s approach is different, and will be covered in section 4.4.5.
7
18/05/2015
14
The proof of work algorithm mathematically ensures security on the block
chain, as long as one single entity does not hold majority of the computing
power. Only then will the illegitimate blocks, added by this entity, actually
be added to the block chain, as that entity creates more than half the new
blocks. The fact that the proof of work is made from the hashed header from
the previous block, and that headers contain a hash of all transactions in that
block (see figure 4.1), changing an old transaction requires the perpetrator
to recalculate the proof of work for all subsequent blocks. It then has to
convince the system to use this chain by continuously adding blocks to this
chain at a higher rate than the legitimate chain.
Another consensus protocol is called proof of stake. This is a consensus
protocol that is based on the distribution of cryptocurrency within the sys-
tem. Proof of stake is the consensus algorithm that Ethereum aims to use,
as it does not require the waste of resources that proof of work does[31]. It
has, however, been argued that proof of stake cannot be used as a consensus
scheme in its pure form[12, 43]. Unless specified, this paper assumes that
proof of work is used, when discussing the block chain technology.
15
Solidity8 (Java like), Serpent9 (Python like), Mutan10 (C like), and LLL11
(Lisp like).
A smart contract has an address, just like an external account (essentially
a user), but instead of acting like a wallet, it will execute code based on the
data it receives. Smart contracts can call other smart contracts in almost
the same way, through messages, which will be explained in section 4.4.4.
In order to avoid malicious and infinitely looping code or distributed denial
of service attacks to be executed on the block chain, each execution and
creation of a smart contract is powered by gas (see section 4.4.3). Powered
means that the amount of gas needed to run the contract is determined by
the total amount of computations and storage entries of the byte code that
the EVM compiles the smart contract into.
Even though it is estimated that the total amount of computing power
available directly on the block chain is equivalent to that of a 1999 smart-
phone[10], smart contracts are extremely powerful in the way they function
as the building blocks of world wide decentralised trust-free systems.
4.4.2 Transactions
A transaction on the Ethereum block chain contains 6 fields; the recipient of
the transaction (be it a user or a smart contract), the signature of the sender
and the amount of ether to send with the transaction. It also has an optional
data field, a start gas value and a gas price value. The first three fields are
self explanatory, it is the final three that make Ethereum stand out. The
data field can be used to transfer parameters to a contract. The remaining
two are explained in section 4.4.3.
8
https://github.com/ethereum/wiki/wiki/Solidity-Tutorial (visited on
16/05/2015). This resource states that it is JavaScript like, however, as JavaScript is not
strongly typed, or object oriented, we believe that it is more Java like than JavaScript
like.
9
https://github.com/ethereum/wiki/wiki/Serpent (visited on 16/05/2015)
10
https://github.com/obscuren/mutan (visited on 16/05/2015)
11
https://github.com/ethereum/cpp-ethereum/wiki/LLL (visited on 16/05/2015).
As of this date, it is written in a non-English language, but a commit from 09/04/2014 by
Gavin Wood show the text in English.
16
4.4.3 Ether and gas
Ethereum uses its underlying network unit, ether, to fuel the contracts ex-
ecuted on the block chain. Fueling is understood as a way to pay for the
execution of EVM bytecode and storage of data on the block chain. How
much a specific computation will cost is defined by the complexity of the
computation. The most basic computations such as addition, subtraction,
and multiplication is intented to cost 1 gas. Contracts and transactions also
have a start price that is fixed in order to pay the miner for his computational
power. The EVM will on compilation of the code of the smart contract or
transaction, decide the amount of computations and multiply them by the
current gas price, thus determining the price of executing the desired trans-
action:
Since Ethereum is still in an early testing stage, the real gas price has
not yet been decided, and is therefore, as of May 2015, fixed at 10 szabo.
1 szabo is 10−6 ether, which means that for 1 ether you can get 100,000
computations[25]. The gas price will however be changed when the first
non-testing block chain gets launched12 .
4.4.4 Messages
Messages are essentially transactions between two smart contracts. They
carry almost the same fields as a regular transaction, except there is no
gas price. The gas used by the sum of all computations done by all smart
contracts activated by a transaction, must be covered in the gas field of said
transaction[11].
12
http://ether.fund/tool/gas-price (visited 19/05/2015)
17
4.4.5 Mining ether
There are some differences in the way the Ethereum block chain and the
Bitcoin block chain works in terms of mining. Each block on the Ethereum
block chain contains the entire state of the Ethereum system, stored in a
“Patricia tree”, which is an evolved “Merkle tree” as known from Bitcoin. It
only stores the data of new transactions, whilst unchanged data is stored as
pointers to the original block location[11].
Also the way a miner is selected to create a block on the block chain is
different to prevent some of the centralisation found in Bitcoin’s block chain.
Bitcoin requires the miner to do a specific hash function on some strings,
which means that it is possible to use application-specific integrated circuits
(ASICs), which is already being done. This makes it almost impossible for
the regular user to have a chance to mine. The block validation is now done
in big mining pools relying on this technology. This is even worse, since
at the time of writing, the three biggest mining pools hold over 50% of the
computing power and previously Ghash.io have been close to it as well[5, 40].
Ethereum aims to use a model where a miner will have to process ran-
dom transactions from previous blocks and hash the result. This means
that, as transactions can compute smart contracts that can hold any kind of
computations, the utilisation of ASICs are not possible in the same way[11].
Secondly, a miner has to have the entire block chain available, so mining
pools cannot be used in the same way. The only way of bypassing this is
by “poisoning the well” by including a large number of contracts designed to
cater to specific ASICs, and that is a problem that are yet to be addressed
by Ethereum at the time of writing[11].
18
counts”. Accounts have the ability to maintain an internal database, execute
code and talk to other accounts. In section 4.4.1 we describe smart contracts.
A smart contract is itself an account. Externally owned accounts (EOAs) are
controlled by a private key, and if you own the key belonging to the EOA
you have the ability to send ether and messages from the EOA.
Computations in the EVM are done in a stack-based bytecode language.
An EVM program is a sequence of opcodes. Basically the EVM works in
the same way as many other virtual machines. It takes some programming
language and compiles it into low level code that the computer, on which it
runs, understands. Due to this, developers do not have to write low level code,
but can use one of the high level languages designed for writing contracts
mentioned in section 4.4.1. Any code written in these languages needs to
be compiled into EVM bytecode before being sent in a transaction with no
recipient to create a smart contract.
19
5 | Proof of Concept
20
way you can get coffee at all times through self-service.
5.2 Implementation
This section will cover in detail the process of implementing the smart con-
tract using the programming language Solidity and client using the Ethereum
JavaScript API.
First of all functionality is needed to issue punch cards for users to pur-
chase. In order to distribute this smart property a function called buyClipcard
is implemented, which allows for a user to purchase a punch card for a cer-
tain price. The price can be adjusted by the issuer of the smart contract
21
to whatever amount you like through a function called setPrice. When
purchasing a punch card, the contract will make sure you have a sufficient
balance of ether before you can commit the transaction. To keep track of
users and their balances, a map of user addresses on the network and their
clipcard property, called clipcards, is implemented. This way it is possible
to check if people own a punch card or has sufficient clips.
After this functionality it is needed to dictate the rules of buying a cup
of coffee, using the punch card token. This part of the contract is basically a
“vending machine” in the sense that a product has a fixed price. A function
that deducts one clip from your punch card is therefore added as useClip.
In order for this to be fully automated, you would have to implement
a digital lock on the coffee dispensers. Otherwise you would not solve the
problem of people just stealing coffee. To implement a hardware solution is
out of scope for the system, since it is the aim of this paper to implement a
proof of concept on how the software should be specified. However a system
like this could be implemented, by having a lock on the dispensers connected
to the network. A smart contract could then be implemented to turn this
lock on and off, as this smart contract would be invoked by the system. Being
able to invoke hardware through block chain technology is a small example
of IoT (see section 3.4).
A fully fledged automated system could thus be implemented with two
smart contracts in conjunction with each other.
In order to issue these smart contracts onto the network you make a
transaction with the smart contract logic as described in section 4.4.6. As
stated in section 4.4.1, the price of fueling this contract is determined by
how many operations it includes. If we have enough ether to fuel the smart
contract it will be submitted to the block chain and be accessible through an
address.
22
mand line transactions. This is possible by using the Ethereum JavaScript
API in order to build an HTML client.
Ease of use
The role of the client is basically to make the smart contract easier to use.
It will display stored information and make functions accessible through a
graphical user interface (GUI) that interacts with the contract itself. Thus,
instead of making specific transactions with data to the smart contract, input
fields and buttons have been made to take care of the job for you, as seen
in figure 5.2. This is done by using a JavaScript API provided by Ethereum
that utilises web3.js[26]. The web3 object makes it possible to communicate
with the network because it knows your private address. Therefore you
can only use decentralised applications (ÐApps) in a browser that utilises
web3, for example Mist or AlethZero, which are both clients developed by
Ethereum. The JavaScript API offers a lot of functionality that can be
used to communicate with a smart contract and the Ethereum block chain.
Namely we utilise the function of getting stored data out of the contract
to display in our client and calling functions to manipulate this data. The
source code of our client can be found in A.1.2.
23
Figure 5.1: AlethZero – the browser used to view our client and display the
state of the network.
24
All the data displayed in bold are information taken directly out from
the block chain, as it is contained in the storage of the smart contract of the
implementation.
Since you are connected to the Ethereum network through authenticating
with your private key, one of the strong suits of these kind of applications
is that there is no need for logging in, since the network already knows who
you are.
In this case the client does not know me yet as I have not used the system
before. Therefore I am identified as “User”, and have no balance.
In addition the client displays the current price of a punch card; the
network address of the issuer of the contract; and the network address of
the smart contract that controls the lock on the coffee dispensers. All these
values can be updated through an admin panel as seen in figure 5.3 that are
immediately accessible to users with admin rights. Consequently there is no
admin login either since the data of user rights too is stored on the block
chain.
25
5.3.2 Purchasing a punch card
In order to purchase a punch card, you need some amount of ether. In the
current implementation the price is set to 1 finney which is 0.001 ether.
The price is set low for testing purposes but as stated above it can be set
as you wish. In the end ether essentially has a monetary value. The price
could thus be set accordingly to fit the price of the physical punch card or
even be controlled by a smart contract that keeps an eye on fluctuations in
the market which is discussed in section 7.4.5.
Upon the release of Ethereum, ether can be acquired through exchanges
or through mining on the network. At the time of writing15 Ethereum is still
in development, thus “real ether” cannot yet be acquired.
If you have an adequate amount of ether you can purchase a punch card
by typing your name in the name input field and click on the “Top up your
punch card” button.
This will initiate a transaction to the smart contract, powering the system,
consisting of the payment of 1 finney, your name and that you want to invoke
the purchase punch card function on the smart contract. This is all done
through the JavaScript of the client, thus the plumbing has been done for
you. Your address on the network is the sender of this transaction why the
smart contract will map this address as the owner of the punch card.
When using AlethZero you will be able to see the transaction in the
Pending window as seen in figure 5.4. Here it is seen that the transaction is
completely transparent as all its data is publicly visible. Visible in the sense
that the computational operations I want carried out in addition to the data
I send with it are listed. Whilst waiting for the transaction to go through, a
loading screen appears.
Once a new block is discovered the transaction will be submitted to the
block chain. As accounted for in section 4.4.7 the block time of Ethereum is
12 seconds. Discussions on the block time can be found in section 7.4.3.
The transaction is thus carried through once it is submitted to the block
15
18/05/2015
26
Figure 5.4: A pending transaction
chain. In figure 5.5 we see that the transaction and its data are now stored
publicly in a block. The system will now recognise you through your address
being mapped in the smart contract. Consequently your name and a balance
of 10 clips will be displayed as seen in figure 5.6.
This transaction is now stored forever on the block chain for everyone to
see, but unable to be tampered with.
27
Figure 5.6: The transaction has gone through and the system now recognises
the user’s name and his balance since this data is now stored in the block
chain.
The block chain is now updated with the data that you have purchased
28
Figure 5.7: After buying a cup of coffee, the balance of the punch card has
been updated.
a cup of coffee, just like when a punch card was purchased in figure 5.5, thus
concluding the tour of the system.
29
5.4.1 The contracts
There are seven smart contracts in the modular implementation (and one
super smart contract that is not actually pushed to the block chain).
Issuer (appendix A.2 line 23) is the smart contract that communicates
with the GUI. It is responsible for making the needed information visible to
the user (getBalance, getPrice, getName), and handling the input from the
user (buyCard, punchCard). It also handles input from the owner (setPrice,
setAddAmount and setPunchAmount).
AssetHolder (appendix A.2 line 218) is the smart contract that handles
the system’s assets (ether and punches/clips). It works as the controlling
layer between the Issuer and the PunchDb. It is responsible for making the
PunchDb add and deduct the right amount of punches to the punch card,
transferring ether to the owner or the sender depending on the event. It can
also “unpunch” a punch card, should the Machine fail.
Settings (appendix A.2 line 326) is the database for storing settings. The
settings are stored in pairs of keys of type bytes32 (a string) and values of
type uint. Functions for setting and getting settings are also available. This
way, the settings module can store an arbitrary amount of settings, though
those used in this system are “price”, “addAmount” and “punchAmount”.
NameDb (appendix A.2 line 399) is the database for storing names. It
stores names in pairs of addresses and strings, and functions for setting and
getting names are available.
PunchDb (appendix A.2 line 350) is the database responsible for storing
the amount of punches available to the users. It stores the information in
pairs of addresses and integers (as uint). Functions are available to add and
deduct a number of punches as well as getting the balance of an address.
30
Machine (appendix A.2 line 185) is the artificial representation of the ma-
chine that the system runs. It simply keeps an account of when it should be
unlocked (in terms of block number) and how many cups it has poured since
it was last filled. It is set to fail every 10th time to simulate it running out
of coffee, after which it is immediately refilled (the counter is reset). It also
provides a getter that tells whether it is currently open.
Manager (appendix A.2 line 434) is the smart contract that manages the
other smart contracts. All the other smart contracts extend a super contract
that is called IsManaged (appendix A.2 line 2) that provides a field for storing
the address of the manager and a function for setting this. The manager
stores the smart contracts in pairs of strings and addresses that makes it
possible to store an arbitrary number of smart contracts in the manager. All
the smart contracts then use the manager to contact each other by getting
the right component using the getComponent function.
31
6 | Analysis of Implementation
6.1 Testing
In order to do a meaningful analysis of our implementation it must first be
documented that it is in fact working as intended.
32
6.1.2 Black-box testing
As unit testing is not available, black box testing was chosen as an altern-
ative. The results can be found in appendix B on page 101. The tests are
designed to test boundary cases for all the functions used by the client, ex-
cept for the setIssuer function because that would mean to hand over the
client to someone else, and the functionality is equal to that of setMachine.
commitSuicide and emptyMachine are not tested either, as they are trivial
in their functionality.
As it can be seen from the test results, all tests but one passed. The
one test that failed is in relation to the price of a punch card. The test is
designed to test that negative numbers cannot be pushed, as it would result in
a negative price. However, the function has been implemented using unsigned
integers that does not allow for negative numbers, instead converting it to
a very high number instead. Thus, the test fails. It is however chosen that
this need not be fixed. Firstly, it is an administrative function, why only
people with knowledge of the system will access it. Secondly, the result of
the action is very clear, and can at worst only mean that customers cannot
buy a punch card, not that they can get them for free. When this is upheld
against the costs of issuing an updated contract, leaving it be is the better
solution.
33
oning behind this is that the client is not meant for production in its current
state, it is, as the name tells, only a proof of concept.
6.3 Limitations
There are some limitations and drawbacks to this implementation that will
be analysed in the following.
34
means waiting for a new block to be discovered. In general this would average
out to around 6 seconds of waiting for your transaction to go through.
The block time issue is hard to circumvent due to the nature of the
Ethereum block chain. This would mean to introduce a centralised service
of some sorts in conjunction with the block chain in order to bring down
transaction time. Using the block chain would then seem pointless since you
are no longer having a purely decentralised system and thus compromising
transparency, trust and security.
6.3.2 Extendability
Our system relies on two smart contracts where one of them has all the
transaction logic. If we are to change inner workings of this specific smart
contract we have to issue the entire thing again which is costly in gas, and
all current punch cards would be lost, meaning that ether would have to be
manually transferred back to the customers, which is costly too. Also the
client needs to be updated with a new smart contract address for connectivity.
To address this problem getters and setters have been implemented in
order to give the issuer the opportunity to change a lot of the data stored
in the smart contract without having to issue an entirely new one. You are
for example capable of changing the address of the coffee machine smart
contract and the address of the issuer (essentially the administrator of the
contract). The only reason to issue a new smart contract is if the logic of
some of the transaction functions needs to be updated. These functions in
its current form are however simple so it would be fair to assume that such
updates would happen rarely.
If the system is to be extended you would have to either make another
smart contract that manipulated the old one, essentially a module on top of
the other, or reissue a new smart contract with the new logic.
6.3.3 Improvements
If we were to further develop the system, the nature of smart contracts would
make it easy to extend the system with new features automating other pro-
35
cesses of the coffee shop.
In transaction systems in general, the use of a block chain can prove useful
in regards to get statistics of sales and revenue as you will have a complete
dataset of transactions in one place. Consequently additional smart contracts
can be implemented in order to handle the purchase of supplies through
interacting with the record of sales. In this way, by automating processes,
through smart contracts in conjunction with each other, a shop can be turned
into a DAO.
As stated in section 5.3.2 the system could be extended to handle pricing
of the coffee automatically. A smart contract could set the price in ether in
accordance to a fiat currency. In addition a type of exchange could also be
implemented in order to accept different kind of cryptocurrencies or even fiat
currencies. Such smart contracts might already be implemented in different
systems on the block chain, but due to the public network you could utilise
the same smart contracts in a different system. Due to this, by developing one
transaction system in a clever way you have the generic building blocks of the
smart contracts to easily build a transaction system that handles completely
different entities. This is again one of the strong suits of smart contracts on
the block chain.
The scope of this development is however only to implement the transac-
tion process of the punch card.
36
(a) Classic MVC
Figure 6.1: Representations of the classic MVC (a) and the modified MVC
(b). In the modified version all addresses of other components are found
using the Manager, represented by dashed arrows.
37
a physical artefact stands out of this model in its current form.
The main reason for using this system over the simple implementation
is extendability as mentioned in section 6.3.2. With the modules being in-
terchangeable, it is possible to extend the system without it affecting other
modules.
As an example, imagine that it is needed that the birthday of customers
are shown and stored. In this case only the issuer needs to be updated, and a
module for storing birthdays added. The fact that this can be done not only
saves the issuer money, as the whole system does not need to be replaced,
it also makes sure that all the customers still have their punch cards up to
date without the need to transfer anything, as needed in the non-modular
solution (see subsection 6.3.2).
The extra checks for message senders (needed for security reasons) and
getting the addresses of other smart contracts do increase costs of running
the modular implementation, as compared to the simpler solution. It is thus
a matter of how likely a future extension of the system is, whether the one
or the other solution should be chosen. This choice is harder to make for a
decentralised system, as computing power is a scarce resource. In the case of
the coffee shop at ITU, the simple implementation is most likely adequate,
because of the limited user base and the low risk of needed extension later
on.
argued that this belongs in the controller, however to limit the amount of unnecessary
intercontract calls, this has been moved as it makes no sense to allow negative accounts
in the system
38
7 | Discussion
In this chapter we will discuss our implementation and on basis of this some of
the features of Ethereum and decentralisation through block chain technology
in general.
39
will still be up. As you cannot tamper with the data stored on the block
chain, the system is much more resilient to hackers. Since the system is run
transparently, you need not trust the issuer either.
Therefore block chain technology can be effectively used in transaction
systems due its perks in the areas of security, transparency and trust – aspects
that are all of utmost importance when conducting a transaction.
40
7.3 Economic Systems
As mentioned, our proof of concept system can be viewed as a parallel cur-
rency – one that in our example can be used to buy coffee, but as argued for
could be used for basically anything. In our example, you use ether to buy
the currency, but if you want to, you could set up a system that exchanges
physical currency to ether before sending it to our system. Because of this
our system could be the cornerstone in many situations where some sort of
physical artefact can be exchanged for a digital one, and where security and
reliability is important factors.
By having the entire block chain in the back of the smart contract, it
becomes impossible to forge fake punch cards without having 51% of the total
computing power of the network[11]. Furthermore it becomes impossible
to (maybe illegally[38]) resell your clips for profit. Both factors are very
appealing to the issuer. They can both secure that the issuer gets the money
it is entitled to, and that no one will be able to buy large quantities with
the sole objective of selling them off for profit, thus possibly buyout the
issuer. The customers on the other hand know that they get what they pay
for. There is no way for the issuer to artificially alter the balances of the
customers without a publicly exposed method that does so.
41
security of the block chain to apply, a large number of full nodes are required.
Otherwise you might end up with a less decentralised system, like Bitcoin
has experienced[5, 40]. The problem here is that this nullifies the security
measure that decentralisation is a big part of (see section 4.3). It is unlikely
that anyone with the computing power to carry such a big node would care
about a small coffee shop such as the one at ITU, but if the technology is
to be applied in a wider selection of application domains, as discussed in
chapter 8, it is a very important aspect to discuss.
From the start, Ethereum has taken steps toward managing scalability
better than Bitcoin. For instance, by using accounts rather than being based
on unspent transaction outputs (UTXO), which according to Buterin causes
a significant amount of space being used, when a lot of transactions are being
performed from one address.
Buterin has already presented several ideas on how to deal with the
scalability problem[13, 15–17], though common for them all is that they
slightly lower security and heighten complexity a great deal. Part of his
concern is usability due to transaction fees, meaning how small values can
feasibly be transferred on the Ethereum network. The major concern, how-
ever, is that of the sheer data size. As mentioned, the larger the block chain
gets, the less secure it becomes as only a few nodes will be able to contain all
the data. Buterin even mentions that in a use case like Ethereum, where the
uses for the block chain are so many, it might be conceivable that the block
chain will rise to a size where no single data center can contain all of it[16].
Therefore it seems like partitioning the block chain into smaller digestible
pieces may be the only way to go forth.
The problem is that when you subdivide the block chain into smaller
substates, you also divide the amount of hashing power needed to push il-
legitimate blocks, as miners only mine blocks within their own substate.
Therefore, if there are 200 substates, one will only need 4% of the total
hashing power to take over a substate and potentially invalidate the entire
system[16]. Several possible solutions to this are covered, but all of them
need to be proven effective before they can be implemented safely. Buterin
goes on to explain a model he calls “The Twelve Dimensional Hypercube”.
42
In this model, the block chain is also subdivided, but in a different way, so
that there are edges between the states that messages can move along. This
solution also includes a move from the current consensus scheme of proof of
work to proof of stake (see section 4.3.2). This should make sure that only
if one controls more than 33% of the total sum of ether in the system, they
can make illegitimate transactions.
The final solution presented to the scalability problem is to have many
block chains[17]: some for one specific purpose, some more generalised pur-
poses, like Ethereum. The idea behind this is that the block chains can use
each other to provide security for one another, no matter what the separate
block chains are used for. This way, a miner can mine on a block chain of
a suitable size, and yet security would still be very high, albeit not as high
as if only one block chain existed. This solution also relies on a proof of
stake model, like the previous one, but because of the interconnectivity of
the different chains, a high percentage of the combined stakes of the block
chain ecosystem would be needed.
These solutions are all more technical than the scope of this paper and
only visions at the time of writing21 . Therefore we will not go into more
detail about the technical aspects of them.
43
because an election is being held in Nigeria, it is going to be hard to sell the
idea of the system to the coffee shop.
It is obvious that this is not a viable amount of transactions, should this
technology be implemented on a global basis. Changes to the way different
companies use the block chain are, however, being made, in order to assure
that a transactions per second level alike or even higher than VISA’s can
be handled. Some of the theories in section 7.4.1 will also help Ethereum
being able to handle such levels of transactions per second, thus eliminating
one of the huge advantages that established technologies like VISA have over
decentralised block chain technologies[16].
44
which can become a bottleneck. This added disruptiveness in the flow of
process will be present in all application domains where block chain techno-
logy is implemented.
There are use cases for block chain technology, where the block time wait
is of little matter. For instance, if the technology was to be used as a per-
manent record of property rights, a twelve second wait for the transfer of
property such as land or a house is nothing. This will be covered in more
detail in section 8.2.
Ideally you would want to lower the block time even further. However it
has to be taken into account that the internet itself is not capable of instant
transfer of information. Whenever a miner successfully mines a block, it does
take some time before everybody on the network are informed of this. This
leads, eventually, to lowered security, as Buterin describes in a blog post
from July last year[18]. As this shows, there is a strict balance between the
security of the protocol and block propagation, which needs to be addressed
when lowering the block time. Until proper methods have been developed
and tested, going lower than 12 seconds is too risky. The improvements
already implemented are significantly better than the 10 minutes of Bitcoin,
almost without lowering security. Sure, 12 seconds will reduce realistic use
cases, but it is a good place to start. When improvements are introduced,
more use cases will come.
45
is often hidden from the user. On the block chain it is very blatant that
transactions and computational power come at a price.
This is definitely going to be one of the challenges of Web 3.0, as users
are not used to pay in this way for services online, and that fact might hinder
the spread of the technology. The fact that users will be constantly reminded
that an action has a fee, will certainly make some users choose centralised
solutions where the prices are more hidden. For instance, when looking at
the proof of concept presented earlier in this paper (see chapter 5), there will
be fees involved when buying a punch card, and every time it is punched.
These fees do not exist in the current transaction process. Another fitting
example is within the realm of tickets. It is easy to see the same logic that
is present in the punch card smart contract utilised for the sale of tickets
e.g. sports events (as mentioned in section 7.2). Here the customer would be
faced with very blatant fees upon purchase and utilisation of the ticket. In
a centralised system these fees would most likely be included in a “handling
fee” and possibly in the printing of the ticket, both not as visible as a dialogue
popping up on a screen.
Furthermore centralised services have an advantage: They can control
fees as they please. If it comes to outright competition with, for instance,
an Ethereum-based solution, the centralised actor can just remove the fees,
and take the slight reduction in profit. The decentralised will have to reduce
the price instead, but the blatant fees will still be present. Therefore a
decentralised solution will have to be very comprehensive in describing the
total price, including what fees there are and why.
Otherwise it is conceivable that users will see the first message about
fees and consequently use a centralised service instead. Because of the way
ÐApps are accessed (through an Ethereum client), there will most likely be
added a very clear message about the possible fees included in the action,
possibly like it is shown in the AlethZero client in figure 7.1.
46
Figure 7.1: The transaction dialogue of AlethZero as of 12/05/2015 when a
user tries to buy a punch card in the proof of concept presented earlier.
47
just before spending it. These are significant drawbacks in any system using
block chain technology.
Therefore some kind of assurance mechanism has to be developed in order
to ensure that the value of the consumers’ assets remain the same. In order
to do this some derivation of futures contracts could be used. Some initiatives
have already been made in regard to this26 . As the name, futures contracts
imply, it is a contract between parties. Functionality like this is very easy to
implement in a smart contract using Ethereum.
48
Digital Currency Exchangers work in the same way as stock exchanges
or most other exchanges. It allows for people to sell and/or buy a given
cryptocurrency for conventional fiat currency or other cryptocurrencies28 .
As the list in the Wikipedia article shows, very few of the most common
used exchanges are decentralised. This means that if hackers are able to
gain access to the centralised servers that run the exchange, situations like
the MtGox hacking might occur[37]. As the article states, the security was
very bad in this particular case. MtGox was considered a monopolist in the
bitcoin exchange market at the time being. The aftermath of them losing
$460 million worth of BTC, has however resulted in a vast amount of new
rising exchanges with better security[3].
The fact that people have actually lost huge amounts of money due to
exchanges being hacked, combined with the problems discussed above in re-
gards to securing your private key, might be one of the main reasons why
the layman will find it difficult to make the switch to using some kind of
cryptocurrency and block chain technology to handle day to day financial
matters.
If the coffee shop, or any other shop with a system set up on block chain
technology, does not want to rely on an exchange, there are alternatives. The
Ripple technology presented in section 8.3 also allows for seamless currency
conversions between fiat currency and cryptocurrency. This technology, how-
ever, has its own drawbacks that will be discussed later on.
28
http://en.wikipedia.org/wiki/Digital_currency_exchanger (visited
15/05/2015)
49
8 | Reflections
In this chapter we will reflect upon our discussion and implementation and
discuss how the more generic block chain of Ethereum can be used in the do-
mains of digitalised voting; land rights; and currency conversion and transfer
in a broader perspective than cryptocurrencies. Finally, we will discuss what
this means for the banking sector as it is today.
50
successful attack is discovered, the only way to go would be a time consuming
and costly re-election. There have been made measures to counter this in
the form of systems that print a physical ballot as a backup[7], but it is still
not optimal.
These storage insecurities could largely be nullified if a block chain ap-
proach was used. All transactions are timestamped so it cannot be changed,
except via a 51% attack[11]. It would be virtually impossible for a single man
or a network of activists to manipulate such a block chain. But perhaps a
state would have the resources to do so. Super powers like the United States
have the resources to tamper block chains through sheer computing power.
Thus, the block chain would not offer complete security, but it would be a
much harder task to influence an election. Furthermore it would be quite
evident that someone has been tampering with the network if it was done.
Now this only deals with the storage of the votes. There are still the unsolved
troubles of man in the middle attacks on the computer the voter uses. If we
keep the domain of this discussion to parliamentary elections in Denmark, it
would be a solution to still do voting the old fashioned way, where you get
your voting card in the mail and go to the nearest voting place on election
day. But instead of getting a long sheet of paper, you get something like a
QR code that you scan in the voting box in order to cast your vote. The QR
code could represent a sending address on the Ethereum block chain, and
your vote would then be sent to a smart contract that validates the address
and registers your vote. That transaction will then be on the block chain as
a permanent record of the anonymous vote. However some precautions must
be taken in order to ensure the security on the used computer.
The benefits of using a system like this are many – some more clear
than others. Of course the counting of votes are easily automated, greatly
reducing the work and time needed before a result is clear, while at the same
time removing human errors. Furthermore it will simplify the process of
voting. In addition this system also ensures the anonymity of the voters,
like today, due to the voter being given a random address. This is better
51
than for instance Estonia’s maligned system29 . Here voters can only vote
by registering their ID card at the computer they are voting at, potentially
losing their anonymity.
To sum up, if block chain technology is used, some of the significant risks
of electronic elections can be dealt with, with relative ease. If a platform like
Ethereum is used, it will not be too difficult to create a smart contract that
handles the election process securely.
52
is presented by Factom.org31 . They utilise the Bitcoin block chain to store
a hash of the documentation and keep the actual files on what they call
the “Factom Data Layer”32 . This solution is very similar to what could be
provided on Ethereum in the future, except it is more specifically targeted
this kind of transactions. This has both benefits and drawbacks. The more
generalised approach of Ethereum will most likely make sure that there are
more miners on all the data. Factom on the other hand will have a strong
block chain in Bitcoin for a small part of the data, whilst a more specialised
entity is responsible for the storage of the rest. Some of the features of
Ethereum are superfluous on a system like this. For instance the 12 second
block time, as mentioned in section 7.4.3, has little positive effects in a system
like this. There is also a difference in how the data is audited. Factom relies
on client side auditing, while Ethereum allows for auditing on the block chain
for the price of gas fees. It is not meant for this paper to take a standpoint
on which is best, but it goes to show that the same general technology, can
be utilised in different ways to solve the same problem.
8.3 Ripple
Ripple is not a block chain technology, but it still belongs in this paper as a
reference point and to serve as a possible use case for block chain technology.
53
default for verification. In this way, Ripple is a centralised service that there-
fore is not vulnerable to 51% attacks. However, the users put their trust in
Ripple Labs, who has in the past changed features of the network without
prior notification[14]. Up until the release of the source code, the network
was 100% reliant on Ripple Lab’s continued existence and dedication to the
project, though that has changed in the current environment, as the project
could theoretically be continued by the community.
The consensus algorithm is used to gain mathematical certainty for every
transaction (that 80% of the nodes verify it), and any transaction that are
not verified this way are discarded. Those that are verified are made into a
“last closed ledger”, which is then stored, sort of like the blocks on a block
chain. The very functionality of this consensus algorithm has been a concern
of some parties within the cryptocurrency world. Especially since a ledger
fork happened in the Stellar Network, which uses the same consensus protocol
as Ripple. This fork, which eventually resulted in loss of transactions, led to
concerns over the consensus protocol to a degree where the Stellar Network
went over to a centralised approach until a new white paper could be written
and implemented[34].
Ripple is meant as a way to transfer assets from one person to another
based on trust. While the network does have a built in cryptocurrency, this
is more meant as a way to do trust-free transactions where trust cannot be
obtained, and as a security measure, than an actual currency. The system
has a path finding algorithm that tries to find a path of peers connected
by trust between a sender and a recipient of a transaction. This way the
system manages trust instead of making it obsolete. This is of course in it
self a drawback, however, it does allow for the transfer of assets other than
cryptocurrencies, and for the seamless transfer of different currencies, in-
cluding cryptographic variants. Finally it needs to be mentioned that Ripple
relies on gateways to transfer money in and out of Ripple, and these are too
entities that the users need to trust[14, 27].
54
8.3.2 Ripple and block chain technology
Since the consensus algorithm of Ripple has been under scrutiny, it is feasible
to look into a similar implementation being made on block chain technology.
Some of Ripple’s selling points are that it consumes less electricity to run than
block chain technology does, and that it is not vulnerable to 51% attacks[14].
Both of these are true in some manner, though it can be argued that with
the release of the source code for the verification nodes, someone could gain
a majority and cause disruptions and forks like described earlier. If a similar
system was introduced in a block chain environment this security flaw would
not be present, while that of the 51% attack is something that is under
continuous research. The features of the Ripple solution, such as the path
finding algorithm, would have to be built into the protocol which would
undoubtedly be a task for a research team, but as seen with the generalised
approach of Ethereum, this should be possible.
55
Banks are naturally working on regaining as much of their consumers’ trust
as possible, as solutions are being suggested and tested throughout the global
financial markets[22]. Denning points out that the number one problem is
the lack of transparency:
“Because most of the big banks and many of the shadow banks
had been involved to an unknown degree in risky derivative trad-
ing, no one could tell whether any particular financial institution
might suddenly implode.”[22]
This enhances the fact that the lack of transparency is a large problem.
If not even banks are able to trust other banks, it is very difficult to justify
how consumers should be able to do so.
Denning has a series of suggestions on how to re-establish the trust. These
suggestions include changing the focus of the banking sector to continuously
add value to their costumers; making money as the result instead of the goal
of activities; being totally transparent about all its activities because it is
proud of how it conducts its business and more[22].
These suggestions all seem like viable solutions, but let us consider an en-
tirely different approach to solving these problems. Instead of basing banking
on trust, why not remove the factor that is the biggest problem in banking:
trust.
56
This can be done with a decentralised, trust-free, consensus based tech-
nology. A technology like this, is exactly what a block chain is, as described
in section 4.3.
Due to the way it works and the completely transparent ledger that comes
with it, block chain technology makes it possible to trace money and transac-
tions across big banks and shadow banks, avoiding unknown degrees of risky
derivative trading.
8.4.1 Adaptation
In 2003, Bradley and Stewart, wrote about diffusion of online banking[8]. At
that time, online banking was a very new thing. When they wrote the paper
only few papers had investigated the diffusion of the online retail banking
sector. Bradley and Stewart state that “[at] a fundamental level, the industry
adoption level is governed by supply and demand side factors – that is, con-
sumer demand for online banking and the available supply of new technology,
particularly where it can reduce reliance of the branch network”[8].
Fast forward a little more than a decade, and the situation is arguably
the same. A new technology has arisen, giving the banks the opportunity of
getting rid of one of the huge issues that the banking sector is subject to,
57
as described in 8.4: trust. Banks are researching the block chain technology
and Fidor Bank has already adopted the Ripple (see 8.3) technology[36, 46].
This is indeed a step towards a decentralised banking sector or at the very
least a transparent banking sector. According to Roger’s bell curve from the
Technology Adoption Lifecycle model33 , block chain technologies might be
considered to be in the “early adopters” phase.
In 2003, online banking was reducing reliance of the branch network[8].
Today, the block chain makes it possible to remove reliance on any kind of
centralised opaque trust-based network.
Large corporations have, to some extend, started accepting bitcoins as
payment for their services[21]. It should be understood that they are not
actually accepting bitcoins themselves, but have deals with bitcoin exchanges
that instantly converts the bitcoins to a fiat currency and transfers them
on to their bank accounts. It cannot be ignored that Bitcoin is the first
cryptocurrency being globally accepted. In the light of technologies like
Ethereum, it can be argued that Bitcoin might not be the last.
The Swiss investment bank, UBS, has, as one of the first huge banks,
taken a decision towards adapting block chain technology and are opening a
block chain research lab in London[42].
If history repeats itself the same way it did with the adoption of online
banking, chances are that we, in the next couple of years, will see big changes
in the way banks conduct their business.
33
http://en.wikipedia.org/wiki/Technology_adoption_lifecycle (visited on
15/05/2015)
58
9 | Conclusion
The purpose of this paper has been to explore drawbacks and benefits of
using block chain technology in application areas where transparency and
trust-freeness advantageously can be used.
A working proof of concept of a digitalised punch card transaction system
was designed and implemented successfully on the Ethereum block chain in
order to evaluate this technology. This was done through extensive research
and accounting for the technology.
The analysis of the implementation proved how the features of Ethereum
and block chains in general can be utilised beneficially in economic systems.
The currently trust-based solution of the self-service system was auto-
matised through the use of smart contracts and consequently turned into a
trust-free system. Accordingly users can no longer misunderstand or misuse
the transaction system as the transaction rules are dictated by the block
chain. In addition the transparency of the block chain enables users to verify
that transactions are carried through as predicted. Furthermore due to hav-
ing the consensus checking of the entire block chain network behind it, the
system cannot be hacked or otherwise tampered with, making the system
very secure.
These are all features that are desirable in trust-based systems, why we
argue that block chain technology can be beneficially utilised in such.
59
it was found that these aspects of block chain technology in general are not
quite on par with the solutions offered in centralised systems.
Fluctuation, transaction frequency and security were also discussed, but
these factors are all areas where suggestions to viable solutions were found.
Right now there is no good solution to the issue of the block chain be-
coming too big for ordinary users to carry a node on the network. There are
suggestions and theories on this subject, but they remain untested. There-
fore at this point in time, the bigger a block chain gets, the more centralised
the network becomes.
Similarly a lower block time is desirable, however it would make the
network unstable. Consequently the responsiveness of the applications suffer.
The issue of every action on the network essentially costing money, is
also an obstacle to overcome in order for users to accept this technology. We
argue that it will require a certain adoption time as users are used to fees
being more hidden.
These are all issues that need to be addressed in order for block chains to
become widespread in applications. Therefore innovation and research are
still necessary in this field.
Even though these hurdles exist it can be argued that block chain tech-
nology potentially can have significant impact on society in general.
We argue that block chain technology is one of the most promising tech-
nologies so far if you were to implement digital elections. There are however
aspects of security that are not solvable through block chains in this use case
that needs to be taken into account.
In terms of solving the problems of securing digital rights we argue that
the features of the block chain are very beneficial. The problem has its roots
in the lack of trustworthy authorities, why creating a trust-free system would
rectify this. In this specific use case it is hard to find obvious drawbacks to
using the block chain, as factors like block time and costs are of little relevance
here, why we recommend block chain technology to be utilised.
In the comparison of Ripple to block chain technology there are some
drawbacks of the method Ripple uses that has been publicly exposed. These
60
include centralisation and severe problems in consensus, both problems that
are inherently fixed with block chain technology. Ripple, however, provide a
solution to one of the earlier mentioned problems of block chain technology:
the secure conversion of fiat currency to cryptocurrency.
Discussions on how block chains can be used in financial areas made it
clear that the banking sector as we know it, has to seriously consider the
way it conduct its business if it wants to regain the trust of its consumers.
It is suggested that one possible way of doing so is by removing the element
of trust entirely by using block chain technology to build transparent and
trust-free systems.
61
References
62
[9] Paul Brody and Veena Pureswaran. Device democracy: Saving the fu-
ture of the Internet of Things. 2015. url: http://public.dhe.ibm.
com / common / ssi / ecm / gb / en / gbe03620usen / GBE03620USEN . PDF
(visited on 15/05/2015).
[10] Vitalik Buterin. Ethereum Development Tutorial. 2nd July 2014. url:
https://github.com/ethereum/wiki/wiki/Ethereum-Development-
Tutorial (visited on 29/04/2015).
[11] Vitalik Buterin. Ethereum White Paper. 2013. url: https://github.
com/ethereum/wiki/wiki/White-Paper (visited on 16/05/2015).
[12] Vitalik Buterin. Hard Problems in Cryptocurrency. 21st Mar. 2014.
url: http://vitalik.ca/files/problems.pdf (visited on 18/05/2015).
[13] Vitalik Buterin. Notes on Scalable Blockchain Protocols (verson 0.3).
14th Apr. 2015. url: https://github.com/vbuterin/scalability_
paper/blob/master/scalability.pdf (visited on 06/05/2015).
[14] Vitalik Buterin. Ripple is Officially Open Source. 26th Sept. 2013. url:
https : / / bitcoinmagazine . com / 7275 / ripple - is - officially -
open-source/ (visited on 13/05/2015).
[15] Vitalik Buterin. Scalability, Part 1: Building on Top. 17th Sept. 2014.
url: https : / / blog . ethereum . org / 2014 / 09 / 17 / scalability -
part-1-building-top/ (visited on 29/04/2015).
[16] Vitalik Buterin. Scalability, Part 2: Hypercubes. 21st Oct. 2014. url:
https://blog.ethereum.org/2014/10/21/scalability-part-2-
hypercubes/ (visited on 29/04/2015).
[17] Vitalik Buterin. Scalability, Part 3: On Metacoin History and Multi-
chain. 13th Nov. 2014. url: https://blog.ethereum.org/2014/11/
13/scalability-part-3-metacoin-history-multichain/ (visited
on 29/04/2015).
[18] Vitalik Buterin. Toward a 12-second Block Time. 11th July 2014. url:
https://blog.ethereum.org/2014/07/11/toward-a-12-second-
block-time/ (visited on 08/05/2015).
63
[19] Vitalk Buterin. Visions, Part 1: The Value of Blockchain Technology.
13th Apr. 2015. url: https://blog.ethereum.org/2015/04/13/
visions-part-1-the-value-of-blockchain-technology/ (visited
on 12/05/2015).
[20] Corruption Perceptions Index 2014: Results. url: www.transparency.
org/cpi2014/results (visited on 10/05/2015).
[21] Jacob Davidson. No, Big Companies Aren’t Really Accepting Bitcoin.
9th Jan. 2015. url: http : / / time . com / money / 3658361 / dell -
microsoft-expedia-bitcoin/ (visited on 16/05/2015).
[22] Steve Denning. How Can Bankers Recover Our Trust? 6th Feb. 2015.
url: http://www.forbes.com/sites/stevedenning/2013/02/06/
will-we-ever-trust-bankers-again/ (visited on 12/05/2015).
[23] The Economist. Blockchain - The next big thing. 9th May 2015. url:
http://www.economist.com/news/special-report/21650295-or-
it-next-big-thing (visited on 09/05/2015).
[24] Edelman. 2014 Edelman Trust Barometer. 1st Jan. 2015. url: http:
/ / www . edelman . com / insights / intellectual - property / 2014 -
edelman-trust-barometer/about-trust/global-results/ (visited
on 12/05/2015).
[25] Ethereum Foundation. Ether Unit Converter. url: http : / / ether .
fund/tool/converter (visited on 06/05/2015).
[26] Ethereum Foundation. JavaScript API. 2014. url: https://github.
com/ethereum/wiki/wiki/JavaScript-API (visited on 12/05/2015).
[27] Gateways. url: https : / / ripple . com / knowledge _ categories /
gateways-2/ (visited on 13/05/2015).
[28] Robert Grahan. BitCoin is a public ledger. 30th May 2013. url: http:
/ / blog . erratasec . com / 2013 / 05 / bitcoin - is - public - ledger .
html#.VUfQX-SlilM (visited on 04/05/2015).
64
[29] Glen Greenwald and Ewen McAskill. NSA Prism program taps in to
user data of Apple, Google and others. 7th June 2013. url: http :
//www.theguardian.com/world/2013/jun/06/us- tech- giants-
nsa-data (visited on 07/05/2015).
[30] Doug Gross. Why can’t Americans vote online? 8th Nov. 2011. url:
http://edition.cnn.com/2011/11/08/tech/web/online-voting/
(visited on 12/05/2015).
[31] Vinay Gupta. The Ethereum Launch Process. 3rd Mar. 2015. url:
https : / / blog . ethereum . org / 2015 / 03 / 03 / ethereum - launch -
process/ (visited on 18/05/2015).
[32] Alan R. Hevner, Salvatore T. March and Jinsoo Park. Design Science
in Information Systems Research. 2004. url: http : / / citeseerx .
ist.psu.edu/viewdoc/download?doi=10.1.1.103.1725&rep=rep1&
type=pdf (visited on 13/05/2015).
[33] Stan Higgins. IBM Reveals Proof of Concept for Blockchain-Powered
Internet of Things. 17th Jan. 2015. url: http://public.dhe.ibm.
com / common / ssi / ecm / gb / en / gbe03620usen / GBE03620USEN . PDF
(visited on 15/05/2015).
[34] Stan Higgins. Stellar Network Fork Prompts Concerns Over Ripple
Consensus Protocol. 9th Dec. 2014. url: http : / / www . coindesk .
com/stability-questions-dog-ripple-protocol-stellar-fork/
(visited on 13/05/2015).
[35] Laura Hood. Google’s terms and conditions are less readable than Beowulf.
17th Oct. 2013. url: http : / / theconversation . com / googles -
terms-and-conditions-are-less-readable-than-beowulf-19215
(visited on 07/05/2015).
[36] Anna Irrera. UBS to Open Blockchain Research Lab in London. 2nd Apr.
2015. url: http://blogs.wsj.com/digits/2015/04/02/ubs- to-
open-blockchain-research-lab-in-london/ (visited on 15/05/2015).
65
[37] Robert McMillan. The Inside Story of Mt. Gox, Bitcoin’s $460 Million
Disaster. 3rd Mar. 2014. url: http : / / www . wired . com / 2014 / 03 /
bitcoin-exchange/ (visited on 15/05/2015).
[38] Brian Mikkelsen. Lov om videresalg af billetter til kultur- og idrætsar-
rangementer. 23rd May 2007. url: https://www.retsinformation.
dk/forms/R0710.aspx?id=12058 (visited on 07/05/2015).
[39] Satoshi Nakamoto. Bitcoin: A Peer-to-Peer Electronic Cash System.
2008. url: https://bitcoin.org/bitcoin.pdf (visited on 14/05/2015).
[40] Dave Neal. Ghash.io promises not to break the Bitcoin market. 13th Jan.
2014. url: http://www.theinquirer.net/inquirer/news/2322534/
ghashio-promises-not-to-break-the-bitcoin-market (visited on
29/04/2015).
[41] Sanjay Panikkar et al. ADEPT: An IoT Practitioner Perspective. 7th Jan.
2015. url: http://www.scribd.com/doc/252917347/IBM- ADEPT-
Practictioner - Perspective - Pre - Publication - Draft - 7 - Jan -
2015 (visited on 15/05/2015).
[42] Yessi Bello Perez. UBS to Research Blockchain Technology in London
Lab. 2nd Apr. 2015. url: http : / / www . coindesk . com / ubs - to -
research - blockchain - technology - in - london - lab/ (visited on
15/05/2015).
[43] Andrew Poelstra. On Stake and Consensus. 22nd Mar. 2015. url:
https : / / download . wpsoftware . net / bitcoin / pos . pdf (visited
on 18/05/2015).
[44] Rob Price. Nasdaq is experimenting with the revolutionary technology
behind bitcoin. 11th May 2015. url: http://uk.businessinsider.
com/nasdaq- private- market- blockchain- bitcoin- experiment-
currency-ledger-2015-5?r=US (visited on 15/05/2015).
[45] PricewaterhouseCoopers. How financial services lost its mojo – and
how to regain it. 2nd Oct. 2014.
66
[46] Pete Rizzo. Fidor Becomes First Bank to Use Ripple Payment Pro-
tocol. 5th May 2014. url: http : / / www . coindesk . com / fidor -
becomes - first - bank - to - use - ripple - payment - protocol/ (vis-
ited on 15/05/2015).
[47] Hernando de Soto. “This Land Is Your Land: A Conversation with
Hernando de Soto”. In: World Policy Journal (2011), pp. 35–40. url:
http://www.worldpolicy.org/journal/summer2011/this- land-
is-your-land (visited on 07/05/2015).
[48] Investopedia Staff. Case Study: The Collapse of Lehman Brothers. url:
http://www.investopedia.com/articles/economics/09/lehman-
brothers-collapse.asp (visited on 08/05/2015).
[49] Ian Thomson. Danish court finds Pirate Bay cofounder guilty of hacking
CSC servers. 30th Oct. 2014. url: http://www.theregister.co.uk/
2014/10/30/danish_court_finds_pirate_bay_cofounder_guilty_
of_hacking_csc_servers/ (visited on 12/05/2015).
[50] Manny Trillo. Stress Test Prepares VisaNet for the Most Wonderful
Time of the Year. 10th Oct. 2013. url: http : / / www . visa . com /
blogarchives/us/2013/10/10/stress- test- prepares- visanet-
for-the-most-wonderful-time-of-the-year/index.html (visited
on 13/05/2015).
[51] Stephen Tual. The case for (re)decentralizing the Internet. 29th Apr.
2015. url: https://medium.com/ursium-blog/the-case-for-re-
decentralizing-the-internet-724013c0622 (visited on 16/05/2015).
[52] V. Vaishnavi and B. Kuechler. Design Science Research in Information
Systems. 20th Jan. 2004. url: http://www.desrist.org/design-
research-in-information-systems/ (visited on 13/05/2015).
[53] Gavin Wood. Ethereum Yellow Paper. 2014. url: http://gavwood.
com/paper.pdf.
67
List of Terms
block propagation The amount of miners working on the wrong data due
to them not being notified of the newest block yet. 45
68
of machines. The amount of requests will result in real requests being
pushed back in queue until they time out. 16
fiat currency Fiat currency is a currency which derives its value from gov-
ernment regulation or law. 8, 47–49, 58, 61
getter A function that does nothing but return specific data. 31, 35
man in the middle attack When malicious software is used to catch and
view or alter messages leaving a computer before they reach their des-
tination. 51
69
opcode An opcode is an instruction that specifies the operation to be per-
formed. It is abbreviated from operation code. 19
smart contract An Ethereum address that holds EVM code that can be
run through the use of transactions. 3, 5, 11, 12, 15–23, 25–32, 34–36,
38, 40, 41, 46, 48, 52, 59, 61, 68
substate When a block chain is divided into smaller pieces, the state is
divided as well. A substate is one of these divided pieces of the state.
42
testnet The block chain run by Ethereum prior to the release of the first
commercially usable block chain. The testnet is unstable and unfin-
ished. 29, 32
70
ÐApp decentralised application. 11, 23, 46
71
A | Implementation code
3 struct Clipcard {
4 uint amountOfClips;
5 bytes32 name;
6 }
7
10 address issuer;
11 address machine;
12 uint price;
13 uint newClips;
14
72
21
40 return true;
41 }
42
53 return true;
54 }
73
55
56 function setPrice(uint p) {
57 if(msg.sender == issuer && p >= 0)
58 price = p;
59 }
60
61 function setMachine(address a) {
62 if(msg.sender == issuer)
63 machine = a;
64 }
65
66 function setIssuer(address a) {
67 if(msg.sender == issuer)
68 issuer = a;
69 }
70
71 function emptyMachine(){
72 if(msg.sender == issuer)
73 issuer.send(this.balance);
74 }
75
76 function commitSuicide(){
77 if(msg.sender == issuer)
78 suicide(issuer);
79 }
80
74
90 return name;
91 }
92 }
93
94 contract Machine {
95 /**~\label{line:modular_machine}~
96 * An artificial representation of a Machine that gets opened
,→ when a punch is registered
97 *
98 */
99 address issuer;
100 address owner;
101 uint public openTill;
102 uint public cupsPoured;
103
75
124 function isOpen() returns (bool open) {
125 return (block.number < openTill);
126 }
127 }
20 .loading {
21 position: absolute;
22 display: none;
23 top:0px;
24 bottom: 0px;
76
25 left: 0px;
26 right: 0px;
27 background: url(1x1.png);
28 }
29 .loading img {
30 position: absolute;
31 margin-top: 200px;
32 width: 240px;
33 background: #FFF;
34 border-radius: 5px;
35 }
36 </style>
37 <script src="https://ajax.googleapis.com/ajax/libs/jquery
,→ /2.1.3/jquery.min.js"></script>
38
39 <script type="text/javascript">
40
41 $(function(){
42 if (typeof web3 !== ’undefined’) {
43 var width = $(window).width();
44 margin = width/2;
45 $("#loading").css(’margin-left’, margin-120 + "px");
46
77
,→ name":"name","type":"bytes32"}],"type":"function
,→ "},{"constant":false,"inputs":[],"name":"useClip
,→ ","outputs":[{"name":"success","type":"bool"}],"
,→ type":"function"},{"constant":false,"inputs":[{"
,→ name":"name","type":"bytes32"}],"name":"
,→ buyClipcard","outputs":[{"name":"success","type"
,→ :"bool"}],"type":"function"},{"constant":false,"
,→ inputs":[{"name":"beneficiary","type":"address"
,→ }],"name":"addClip","outputs":[],"type":"
,→ function"},{"constant":false,"inputs":[{"name":"
,→ a","type":"address"}],"name":"setIssuer","
,→ outputs":[],"type":"function"},{"constant":false
,→ ,"inputs":[{"name":"p","type":"uint256"}],"name"
,→ :"setPrice","outputs":[],"type":"function"},{"
,→ constant":false,"inputs":[],"name":"emptyMachine
,→ ","outputs":[],"type":"function"},{"constant":
,→ false,"inputs":[],"name":"commitSuicide","
,→ outputs":[],"type":"function"},{"constant":false
,→ ,"inputs":[],"name":"checkBalance","outputs":[{"
,→ name":"balance","type":"uint256"}],"type":"
,→ function"},{"constant":false,"inputs":[{"name":"
,→ beneficiary","type":"address"}],"name":"
,→ deductClip","outputs":[],"type":"function"},{"
,→ constant":false,"inputs":[{"name":"a","type":"
,→ address"}],"name":"setMachine","outputs":[],"
,→ type":"function"},{"inputs":[{"name":"
,→ machineAddress","type":"address"}],"type":"
,→ constructor"}]);
57
78
64 if(!name) {
65 name = "user";
66 $("#back").hide();
67 }
68 var issuer = web3.eth.getStorageAt(contract,1);
69 var machine = web3.eth.getStorageAt(contract,2);
70 var price = web3.eth.getStorageAt(contract,3);
71 var former_balance = balance;
72 $("#map").html(web3.toDecimal(balance));
73 $("#username").html(name);
74 $("#contract").html(contract);
75 $("#issuer").html(issuer);
76 $("#machine").html(machine);
77 $("#price").html(web3.fromWei(web3.toDecimal(price), "
,→ finney") + " finney");
78 $("#newprice").val(web3.toDecimal(price));
79 if(web3.eth.coinbase === issuer) $(".admin").show();
80 /*if(web3.toDecimal(balance) <= 0) $("#useClip").prop(’
,→ disabled’, true);
81 else $("#useClip").prop(’disabled’,
,→ false);*/
82
83
87 filter.watch(function(error,result){
88 console.log("3");
89 $(".loading").hide();
90 var balance = web3.eth.call(checkBalance);
91 if(former_balance < balance) {
92 var name = web3.eth.call(checkName);
93 name = web3.toAscii(name);
94 $("#cardname").val(name);
95 $("#username").html(name);
79
96 former_balance = balance;
97 }
98 var issuer = web3.eth.getStorageAt(contract,1);
99 var machine = web3.eth.getStorageAt(contract,2);
100 var price = web3.eth.getStorageAt(contract,3);
101 $("#map").html(web3.toDecimal(balance));
102 $("#issuer").html(issuer);
103 $("#machine").html(machine);
104 $("#price").html(web3.fromWei(web3.toDecimal(price),
,→ "finney") + " finney");
105 if(web3.toDecimal(balance) <= 0) $("#useClip").prop
,→ (’disabled’, true);
106 else $("#useClip").prop(’disabled
,→ ’, false);
107 });*/
108
111
80
127 $("#issuer").html(issuer);
128 $("#machine").html(machine);
129 $("#price").html(web3.fromWei(web3.toDecimal(price),
,→ "finney") + " finney");
130 $("#newprice").val(web3.toDecimal(price));
131 /*if(web3.toDecimal(balance) <= 0) $("#useClip").
,→ prop(’disabled’, true);
132 else $("#useClip").prop(’disabled
,→ ’, false);*/
133 }, 15000);
134
135
136
81
157 $("#newissuerbtn").on(’click’, function(){
158 machineInstance.setIssuer.sendTransaction("0x" + $("
,→ #newissuer").val(), {gas: 1000000});
159 $(".loading").show();
160 });
161 $("#newmachinebtn").on(’click’, function(){
162 machineInstance.setMachine.sendTransaction("0x" + $(
,→ "#newmachine").val(), {gas: 1000000});
163 $(".loading").show();
164 });
165 $("#newpricebtn").on(’click’, function(){
166 machineInstance.setPrice.sendTransaction($("#
,→ newprice").val(), {gas: 1000000});
167 $(".loading").show();
168 });
169 }
170 else {
171 $(".container").html("<h1>This is a DApp - please open
,→ in compatible Ethereum client");
172 }
173 })
174
175
176 </script>
177
178 </head>
179
82
,→ username"></strong>!</h4>
188 <h5>My remaining clips: <strong id="map"></strong></h5>
189 <h5>Issuer: <strong id="issuer"></strong></h5>
190 <h5>Machine: <strong id="machine"></strong></h5>
191 <h5>The Price: <strong id="price"></strong></h5>
192 </div>
193 </div>
194 <div class="row">
195 <div class="col-md-6">
196 <button id="useClip" class="btn btn-default" type="submit
,→ ">Punch your card</button>
197 </div>
198 </div>
199 <div class="row">
200 <div class="col-md-6">
201 <input type="text" id="cardname" placeholder="Input name
,→ on clipcard" class="form-control" />
202 </div>
203 <div class="col-md-6">
204 <button id="buycard" class="btn btn-default" type="submit
,→ ">Top up your punch card</button>
205 </div>
206 </div>
207 <div class="row admin">
208 <div class="col-md-12">
209 <h2>Administrative tools</h2>
210 <h5>This contract is at: <strong id="contract"></strong><
,→ /h5>
211 </div>
212 <div class="col-md-6">
213 <button id="suicide" class="btn btn-default" type="submit
,→ ">Commit suicide</button>
214 </div>
215 <div class="col-md-6">
216 <button id="empty" class="btn btn-default" type="submit">
83
,→ Empty machine</button>
217 </div>
218 <div class="col-md-1">
219 0x
220 </div>
221 <div class="col-md-5">
222 <input type="text" id="newissuer" placeholder="Address"
,→ class="form-control" />
223 </div>
224 <div class="col-md-6">
225 <button id="newissuerbtn" class="btn btn-default" type="
,→ submit">Change owner</button>
226 </div>
227 <div class="col-md-1">
228 0x
229 </div>
230 <div class="col-md-5">
231 <input type="text" id="newmachine" placeholder="Address"
,→ class="form-control" />
232 </div>
233 <div class="col-md-6">
234 <button id="newmachinebtn" class="btn btn-default" type="
,→ submit">Change machine</button>
235 </div>
236 <div class="col-md-6">
237 <input type="text" id="newprice" class="form-control" />
238 </div>
239 <div class="col-md-6">
240 <button id="newpricebtn" class="btn btn-default" type="
,→ submit">Change price</button>
241 </div>
242 </div>
243 </div>
244
245
84
246 <div class="loading"><img id="loading" src="loading.gif" /></div>
247 </body>
248
249 </html>
85
24 * The Issuer is the main access point for this DApp.
25 * It utilises the AssetHolder, Settings, Machine and NameDb
,→ directly and the PunchDb indirectly.
26 * It is the only contract that should have a GUI.
27 */
28 address owner;
29
86
54 function punchCard() {
55 if(manager != 0x0) {
56 // Get address of assetHolder
57 address assetHolder = Manager(manager).getComponent("
,→ assetHolder");
58
87
84
88
114 return Settings(settings).getSetting("addAmount");
115 }
116 return 0;
117 }
118
89
144 // Make sure there’s a manager
145 if(manager != 0x0) {
146 // Get the assetHolder
147 address assetHolder = Manager(manager).getComponent("
,→ assetHolder");
148
90
,→ assetHolder");
178
179 AssetHolder(assetHolder).empty(msg.sender);
180 }
181 }
182 }
183
91
210 function isOpen() returns (bool open) {
211 return (block.number < openTill);
212 }
213 }
214
215
216
92
242 if(msg.value < price) {
243 addr.send(msg.value);
244 return false;
245 }
246
93
273 // Punch the card
274 bool pun = PunchDb(punchDb).punch(addr, amount);
275 return pun;
276 }
277 }
278
94
305 // Get the punch db
306 address punchDb = Manager(manager).getComponent("punchDb"
,→ );
307 uint bal = PunchDb(punchDb).getBalance(addr);
308 return bal;
309 }
310 return 0;
311 }
312
320 addr.send(this.balance);
321 }
322 }
323 }
324
95
,→ issuer");
339 // If the issuer sent the message, update the setting
340 if(msg.sender == controller) {settings[name] = setting;}
341 }
342 }
343
96
369 }
370 }
371 return false;
372 }
373
97
401 * The NameDb can only be modified by a specified Issuer
402 */
403 mapping (address => bytes32) nameDb;
404
98
434 /**
435 * The manager contract is responsible for handling all the
,→ components of the Punch Card Issuer system
436 */
437 address owner;
438 mapping (bytes32 => address) contracts;
439
99
467 if(msg.sender != owner) {return false;}
468
492 }
100
B | Test Results
In figure B.2b on page 102 the results of the black box testing of the proof-
of-concept system.
101
Action Case Expected Result
Buying Punch No funds No change No change
Card
Just under price No change No change
Exactly enough funds No change(a) No change
Exactly enough + + 10 clips + 10 clips
fees
Plenty of funds + 10 clips + 10 clips
No name No change No change
With name + 10 clips + 10 clips
With other name + 10 clips + + 10 clips +
name name
Punch card No clips No change No change
1 clip - 1 clip - 1 clip
Plenty of clips - 1 clip - 1 clip
Setting price Negative no. No change(b) 1.15792e+87
0 0 price 0 price
Positive no. Price = no. Price = no.
Setting ma- No address 0x0 address 0x0 address
chine
An address Updated ad- Updated
dress address
102