Implementing a blockchain from scratch: why, how, and what we learned
Knirsch et al. EURASIP Journal on Information Security
https://doi.org/10.1186/s13635-019-0085-3
EURASIP Journal on
Information Security
(2019) 2019:2
R ES EA R CH
Open Access
Implementing a blockchain from
scratch: why, how, and what we learned
Fabian Knirsch, Andreas Unterweger*
and Dominik Engel
Abstract
Blockchains are proposed for many application domains apart from financial transactions. While there are generic
blockchains that can be molded for specific use cases, they often lack a lightweight and easy-to-customize
implementation. In this paper, we introduce the core concepts of blockchain technology and investigate a real-world
use case from the energy domain, where customers trade portions of their photovoltaic power plant via a blockchain.
This does not only involve blockchain technology, but also requires user interaction. Therefore, a fully custom, private,
and permissioned blockchain is implemented from scratch. We evaluate and motivate the need for blockchain
technology within this use case, as well as the desired properties of the system. We then describe the implementation
and the insights from our implementation in detail, serving as a guide for others and to show potential opportunities
and pitfalls when implementing a blockchain from scratch.
Keywords: Blockchain, Private chain, Implementation, Practical insights
1 Introduction
After being originally proposed as a public, decentralized and trust-less ledger for digital currencies, blockchain
technology has gained widespread adoption in many fields
[1–3]. Recently, utilities and network operators in the
energy domain have begun focusing on using the novel
possibilities provided by blockchain technology for realizing such decentralized, trust-less applications that do not
rely on a single trusted third party. This includes protocols
for tariff matching [4, 5] and energy trading [6, 7]. Utility providers and network operators aim at exploring the
properties and benefits, as well as the shortcomings of this
technology for their respective use cases1 .
In this paper, a novel and previously unsolved realworld use case of two major Austrian utility companies is investigated: National legislature, which also
applies to other European countries, requires that for
a shared ownership of small photovoltaic power plants,
such as those commonly found in multi-party rental
apartments, customers can exchange portions of their
energy production with neighbors. This allows customers
to save money by shifting portions to other consumers
*Correspondence:
Salzburg University of Applied Sciences, Center for Secure Energy Informatics,
Urstein Süd 1, 5412 Puch bei Hallein, Austria
when they need less energy themselves, e.g., when they
are traveling.
For this use case, we evaluate the need for blockchain
technology and the applicability of different types of consensus algorithms and permissions/visibilities. A number of existing implementations, such as MultiChain [8],
OpenChain2 , Ethereum [9], and a Bitcoin fork [1], were
initially taken into consideration. However, due to scalability issues on the desired hardware and for achieving
a lightweight and simple solution, a blockchain has been
implemented from scratch. Furthermore, this use case
does not only involve blockchain technology, but also
requires user interaction and customer acceptance, as well
as the processing of privacy-sensitive data, all of which
adds an additional layer of complexity.
This paper describes the real-world use case, the design,
and the final implementation as well as the outcomes in
detail. It aims at serving as a guide for others by showing
potential opportunities and pitfalls when implementing a
blockchain for a particular field of application other than
financial transactions.
The rest of the paper is structured as follows: In
Section 2, we give an introduction to blockchain technology. In Section 3, we describe the underlying use case
and its legal requirements in detail, including related
work on the subject. We further motivate the use of
© The Author(s). 2019 Open Access This article is distributed under the terms of the Creative Commons Attribution 4.0
International License (http://creativecommons.org/licenses/by/4.0/), which permits unrestricted use, distribution, and
reproduction in any medium, provided you give appropriate credit to the original author(s) and the source, provide a link to the
Creative Commons license, and indicate if changes were made.
(2019) 2019:2
Page 2 of 14
blockchain technology for the proposed application. In
Section 4, we discuss existing blockchain implementations
and their drawbacks in our use case and continue to motivate and describe our custom implementation in detail
in Section 5. Finally, in Section 6, we discuss the lessons
learned from our implementation before concluding the
paper.
have agreed on this state, the information is stored
permanently and immutably. Changing the
information contained in a particular block would
require to also change all the following blocks up to
the last block, which is considered to be infeasible
[1, 11].
• Scalability : The block rate, comprised of the
throughput and propagation time of information,
depends on the consensus algorithm and the number
of participants. This can be a limiting factor for
applications that require high throughput [10]. Since
all nodes hold a copy of the blockchain, scalability
issues also arise in terms of the total amount of data
that can be stored. Furthermore, in order to check
the integrity of the blockchain, a new node needs to
download a copy and validate the integrity of the
entire chain. Note that more recent proposals for
BFT-based consensus algorithms improved on this,
e.g., [12].
• Limited privacy : All data in the blockchain is publicly
visible to all participants. Private or permissioned
blockchains limit the range of disclosure. However,
they do not cryptographically protect the data. In
order to achieve privacy, additional layers, such as
zero-knowledge proofs [13] or a commitment
scheme are required [14].
Knirsch et al. EURASIP Journal on Information Security
2 Blockchain technology overview
This section provides an overview of blockchain technology. The scope of this section is to introduce and present a
generic view of the technology and to go beyond its wellknown use for financial transactions. First, blockchain
technology is introduced as a decentralized, trustless, and
immutable database. It is further discussed how a consensus is achieved within such a distributed network of nodes,
and the most common consensus algorithm is briefly discussed. Finally, the drawbacks of blockchain technology
are shown.
2.1 Blockchain technology
Blockchain technology can be described as a trustless and
fully decentralized peer-to-peer data storage that is spread
over all participants that are often referred to as nodes.
The blockchain is designed to hold immutable information once data is committed to the chain, and it i (...truncated)