You are on page 1of 5

Although blockchain has a variety of definitions, a blockchain can best be described

as a data structure of blocks that are chained together to form a collection of


records, called a ledger, with cryptography being a key ingredient in the process. A
blockchain doesn't have a storage mechanism; instead, it has a set of protocols that
govern the way in which information is forged. So, a blockchain can be stored in flat
files or in a database.

Blockchain technology gained popularity due to the fact that its integrity can't easily
be compromised. A compromised blockchain can be recognized for what it is, and
rejected quite easily by anyone in a network. This integrity is achieved by
cryptography, which is what binds the blocks together; we'll study this idea of
cryptography in Chapter 2, A Bit of Cryptography.

Blockchain's promise of providing such robust integrity is what eventually paved the
way for the idea of sharing chains of data in untrusted peer-to-peer (P2P)
networks. Validation of the blocks in a blockchain is what makes sure that a
blockchain has a valid global state that can be accepted by everyone. Due to a
blockchain's ability to share information in an open P2P network without any central
authority governing it, the technology can have many different applications;
however, the technology could not simply just be deployed to these applications
immediately without any troubleshooting. Although blockchain technology, from the
beginning, had a huge role to play in the decentralization of applications, it still
faced several challenges with regards to its application in trustless environments.
One of the biggest challenges was keeping a blockchain consistent across all the
participants of a P2P network. This was solved by creating a consensus algorithm,
which agrees on how the blocks should be appended to grow the chain in a
trustless environment.

The term blockchain actually entails a number of concepts, including P2P network
management, consensus mechanism, and more, all contributing to the creation of a
decentralized application.
Hashing in blockchain

Hashing is an important concept in blockchain and has a huge role in the


functioning of a blockchain application. The applications of hash functions range
from minor blockchain implementations, such as creating a digest for a large
amount of data, to major implementations, such as maintaining the integrity of the
blocks in the chain. Hash functions are also used in Proof of Work consensus
algorithms to solve the Byzantine failure problem, which we'll cover in depth, later in
the chapter. To begin with, we'll explore some concepts of blockchain that make
use of hash functions.

Linking blocks in a blockchain

As defined in the introductory chapter, a blockchain is a continuously growing collection of

blocks that are chained together to form an open ledger by using cryptography as a key

ingredient. Each block in the blockchain is given an identity to mark that block as unique, and

this is achieved by using the hash functions that will generate a digest for that block. The

collision resistance property of the cryptographic hash function, as mentioned in the previous

chapter, Chapter 2, A Bit of Cryptography, ensures that it is infeasible to find two blocks that

will result in the same hash value. As a result, the hash function guarantees the uniqueness of

the identity created for the block.

When a new block is created, it will backreference the previous block using the digest of the

previous block, thus linking that block to the blockchain. Modifying any of the blocks would

change the identity of that block due to the new hash value. As a result, this would break the

chain, as one of the block references will be invalid due to the newly generated hash value.

Therefore, it's infeasible to modify a block such that it generates the same hash value as

before. This is due to the pre-image resistance property of the cryptographic hash function,

which ensures that the data of the blocks cannot be predicted even if we possess the hash

value. This is why, once a chain of blocks is created, the integrity of the chain is ensured as
each block references the previous block. The only way to modify the data of a block is by

modifying all the subsequent blocks by updating its reference to the previous block:

Figure 3.1: Linking blocks using hashes from A Peer-to-Peer Electronic Cash System, S.

Nakamoto

The preceding Figure 3.1 shows the design of blockchain from the original paper, Bitcoin:A

Peer-to-Peer Electronic Cash System, by Satoshi Nakamoto, the creator of the original

reference implementation of Bitcoin. It shows that each block's hash value is affected by the

value of the previous block's hash value, thereby linking each block in the blockchain. Anyone

who holds a copy of the blockchain ledger will be able to verify whether all of the blocks in the

blockchain are valid just by verifying each block's hash with the next block.

Linking blocks using an SHA256 hashing


algorithm

Blocks in the blockchain are chained together by referencing the hash values of previous

blocks. SHA256 is the most popular hashing algorithm used in the blockchain platform since it

was used in the Bitcoin implementation. Firstly, we will define the structure and functionality of

the blocks, before finally constructing the blockchain with the help of the hashing algorithm.

Block structure
Let's consider a simple block whose header and data are combined to create a data structure

called Block. Each Block will contain the following: an index, the previous hash, a timestamp,

data, and its own hash value:

Copy

class Block(object):
"""A class representing the block for the blockchain"""

def __init__(self, index, previous_hash, timestamp, data, hash):


self.index = index
self.previous_hash = previous_hash
self.timestamp = timestamp
self.data = data
self.hash = hash

The preceding code snippet defines a Python class called Block that has all the basic

attributes of a blockchain block. Usually, a block will contain both a header and a body, with the

header containing metadata about the block. However, the preceding example doesn't

distinguish between the header and the body. A typical blockchain application, such as Bitcoin,

will have a huge set of data that could be in the form of transactions, but in the example, we will

consider the data to be of a string type.

Chapter 10. Blockchain Security

After studying most of the concepts and applications of blockchain technology, it's
crucial to discuss its strengths and weaknesses in order to realize the level of
security that is required. In this chapter, we will be addressing some of the
significant challenges faced by blockchain technology. Along this journey, we'll also
point out the possible attacks you can encounter in the blockchain network and how
they can be prevented.

We'll be looking at the following topics in this chapter:

 Transaction security model


 Decentralized security model
 Attacks on the blockchain, including:
 Double-spend attacks
 51% attacks
 Eclipse attacks
 The threats presented by quantum computing

Blockchain technology was adopted in decentralized public networks because of


the security the technology provides, including ensuring the integrity of the data
stored in the public ledger. Blockchain networks are less vulnerable to the threats
faced by centralized networks. However, due to the participation of several diverse
components in public networks, centralization in blockchain networks does occur. In
addition to this, most blockchain platforms compromise the principles of
decentralization in order to customize their applications to their needs. Due to this,
the security of blockchain technology has suffered. In this chapter, we'll look into
some of the security models and examine the security concerns of blockchain
technology.

You might also like