0% found this document useful (0 votes)
12 views59 pages

Blockchain Consensus Algorithms Analysis

This thesis analyzes consensus algorithms in the blockchain, focusing on 'proof of work' and 'proof of stake' algorithms. The performance of these algorithms is compared using the SHA256 and MD5 hash functions. The study highlights the importance of distributed nodes in the process of validating transactions without intermediaries.

Translated by

ScribdTranslations
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views59 pages

Blockchain Consensus Algorithms Analysis

This thesis analyzes consensus algorithms in the blockchain, focusing on 'proof of work' and 'proof of stake' algorithms. The performance of these algorithms is compared using the SHA256 and MD5 hash functions. The study highlights the importance of distributed nodes in the process of validating transactions without intermediaries.

Translated by

ScribdTranslations
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

' $

Democratic and Popular Algerian Republic


Ministry of Higher Education and Scientific Research

Mohamed Seddik Benyahia University of Jijel


Faculty of Exact Sciences and Computer Science
Department of Computer Science

Thesis of final studies


for obtaining the Master's degree
in Computer Science
Option: Computer Science and Multimedia

'
The theme $

Analysis of some algorithms of


consensus in blockchain.
& %

Presented by:
DESDOUS Mohammed.
BOUKETTA Chanez.

Framed by:
LAHOULOU Atidel .
MAHAMDIOUA Meriama.

Promotion: 2020.
& %
Resume

A blockchain is a peer-to-peer network that enables transactions to be conducted securely.


security and without the intervention of a third party. it is the distributed nodes that must
agree on the validity of transactions, relying on a consensus algorithm
sus for reaching a consensus.

In our graduation thesis, we presented and analyzed a set of the al-


consensus algorithms. Thus, we implemented and compared the performances of the two
consensus algorithms "proof of work" and "proof of stake" with the use of functions
SHA256 and MD5 hash functions.

Mots cl´es : blockchain, transactions, consensus, noeuds, pair-`a-pair, analyse .


Abstract

A blockchain is a peer-to-peer network allowing transactions to be carried out securely


and without the intervention of a third party. it is the distributed nodes that must agree on
the validity of transactions, relying on a consensus algorithm to achieve consensus.

In our final thesis, we presented and analyzed a set of consensus algorithms. Thus, we im-
implemented and compared the performances of the two 'proof of work' and 'proof of stake'
consensus algorithms with the use of the hash functions SHA256 and MD5.

Key words : blockchain, transactions, consensus, nodes, peer-to-peer, analyze.


Acknowledgments

First of all, we would like to thank Allah, the Compassionate and Merciful, for having us.
Give strength and courage to carry out this work well.

We would like to express our sincere thanks to Mrs. LAHOULOU Atidel and Mrs. MA-
HAMDIOUA Meriama, for their guidance, their encouragement, their availability and
their valuable advice that allowed us to successfully carry out this work.

We would like to thank the members of the jury who were willing to agree to judge our...
modest work.

Our thanks also go to all the teachers of the department.


Entity that participated in one way or another in our master's and bachelor's training.

Finally, our most sincere thanks to all the people who contributed to
For the elaboration of this memoir as well as for the success of this wonderful year
university...
Dedications

I dedicate this modest work to:

To the man of my life, my eternal example, my moral support and source of joy and
happiness, the one who has always sacrificed for me to succeed, may God keep you in his
vast paradise, to my father.
In the light of my days, the source of my efforts, the flame of my heart, my life and
my happiness; mom. To the people whose presence I loved on this day,
To my sisters: Salma and Ahlem and Rahma
My brother: Masoud
I also dedicate this work to my large family. DESDOUSet the family MY-
MOUR.
To my aunts, my uncles, my cousins and my female cousins, and to all my family
To all my friends, To all those who are close to my heart and who encourage me
give the best in me especially HOUSS and YOUSSERA.
And in the end, I dedicate it to everyone who has given me their slightest help to succeed.
work.

MOHAMMED
Dedications

I dedicate this modest work to:

To the man of my life, my eternal example, my moral support and source of joy and
bonheur, celui qui s’est toujours sacrifi´e pour me voir r´eussir, que dieu te garde dans son
vast paradise, to you dear DAD.
In the light of my days, the source of my efforts, the flame of my heart, my life and
my happiness; MOM THAT I LOVE.
To the people whose presence I liked well on this day,
To my very dear sister who really supported me, despite the distance you are in my heart
NADINE.
To my dear brothers: AMINEetSAMI.
I also dedicate this work to my great family BOUKETTA and the AF family.
FANE.
A confident man MESSAOUD and all my friends and everyone who is close
from my heart and who encouraged me to give the best in me above all LYNA and
ROUMAISSA.
To my grandmother, my grandfathers, my aunts, my uncles, my male cousins, and my female cousins
and to all my family
And in the end, I dedicate it to all those who have given me even the slightest helping hand to succeed.
work.

CHANGE
Table of Contents

Table of contents i

List of tables iv

List of figures v

List of abbreviations I

General introduction 1

1 General Overview of Cryptography 3


1.1 Introduction 3
1.2 Basic Concepts 3
1.2.1 Definition of cryptography 3
1.2.2 The use of cryptography 3
1.2.3 Types of cryptography 4
[Link] Symmetric cryptography 4
[Link] Asymmetric cryptography . . . . . . . . . . . . . . . . . 5
1.2.4 Hash function 6
[Link] Definition 6
[Link] Basic property of a hash function... 7
[Link] Examples of hash functions ... 8
[Link].1 MD5 8
[Link].2 SHA256 8
1.2.5 Digital signature 8
[Link] Definition ... 8
[Link] Signature Principle 9
1.2.6 Merkle Tree 10
1.3 Conclusion 10

2 Blockchain 11
2.1 Introduction 11
2.2 History of Blockchain . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11

i
Table of contents ii

2.3 Definition 12
2.4 Characteristics of Blockchain 13
2.5 Operation of a Blockchain 13
2.5.1 Functioning 14
2.5.2 Role of axe 15
2.6 Blockchain Components 16
2.6.1 The account or wallet . . . . . . . . . . . . . . .16 . . .
2.6.2 Transaction . . . . . . . . . . . . . . . . . . . . 17. . . . .
2.6.3 Block 17
2.6.4 Mining 18
2.6.5 Consensus Algorithm 18
2.7 Conclusion 19

3 Analysis of some Consensus Algorithms 20


3.1 Introduction 20
3.2 Criteria for the effectiveness of a consensus mechanism . . . . . . . . . . . . 20
.
3.3 Consensus algorithms 21
3.3.1 Proof of Work (POW: proof of work) 21
[Link].1 Advantages of POW 23
[Link].2 Disadvantages of POW ... 24
3.3.2 Proof of Stake (POS) 24
[Link].1 Advantages of POS 25
[Link].2 Inconvenience of POS ... 26
3.3.3 Proof of Stake Delegated (DPOS: delegated proof of stake) 26
[Link].1 Advantages of DPoS 27
[Link].2 Disadvantages of DPoS . . . . . . . 28 . . . . .
3.3.4 Proof of Elapsed Time (PoET) 28
[Link].1 Advantage of the POET... 29
[Link].2 Inconvenience of the POET . . . . . . 29 . . . . .
3.3.5 Proof of Importance (POI: proof of importance) 29
[Link].1 Advantages of POI 30
[Link].2 Drawbacks of the POI . . . . . . . 30. . . .
3.4 Conclusion 30

4 Comparison of consensus algorithms 31


4.1 Introduction 31
4.2 Work idea 31
4.3 Development Environment 33
4.3.1 Material 33
4.3.2 Software 34
Table of contents iii

4.4 Proposed solutions 34


4.4.1 Embedded blockchain 34
[Link] Transaction structure 34
[Link] Block structure 35
4.4.2 Localhost 35
4.4.3 Cable network 35
[Link] Some windows of our application ... 36
[Link].1 Parameters : . . . . . . . . . . . 36. . . .
[Link].2 Mining a block: ... 36
[Link].3 Creation of the wallet: . . . . . . . 37. . . .
[Link].4 Transaction : . . . . . . . . . . . 38 . . . .
[Link].5 Blockchain Window: . . . . . . . . . 39 . . . . .
4.5 Experimental Results . . . . . . . . . . . . . . . . . . . . 40. . . . . .
4.5.1 For PC1 40
[Link] PoW and PoS with SHA256 for PC1 40
[Link] PoW and PoS with MD5 for PC1 . . . . . 41 . . . . .
4.5.2 For PC2 41
[Link] PoW and PoS with SHA256 for PC2 41
[Link] PoW and PoS with MD5 For PC2 . . . . . 42 . . . . .
4.6 Analysis and discussion of the result... 42
4.7 conclusion 43

General conclusion 44

Bibliography 45
List of tables

4.1 Characteristics of the machines used... 33


4.2 Result of PoW /SHA256 and PoS/ SHA256 of pc1. 41
4.3 result of PoW/MD5 and PoS/MD5 of pc1... 41
4.4 Result of PoW/SHA256 and PoS/SHA256 of pc2... 42
4.5 Result of PoW/MD5 and PoS/MD5 of pc2. 42

iv
List of figures

1.1 Symmetric Encryption.. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5


1.2 Asymmetric Encryption 6
1.3 Hashing Principle. 7
Digital signature 9
1.5 Merkle Tree 10

2.1 Structure of a Blockchain 13


2.2 General Principle of a Blocktean.. .. . . . . . . . . . . . . . . . . . . . . . 15
2.3 Role of hashes in the blocks ...... . . . . . . . . . . 15
2.4 Role of hashing in the integrity of the blockchain. 16
2.5 Example of private key pair andcl´andpublish 16
2.6 Structure of the blocks of the chain. 18

3.1 POW in a blockchain... 22


3.2 Flowchart of the PoW algorithm. 23
3.3 Organization chart of the PoS algorithm. 25
3.4 Diagram of POS advantages. 26

4.1 Flowchart of the PoW algorithm. 32


4.2 Bitcoin PoW Pseudo-Code... 32
4.3 Organizational chart of the PoS algorithm. 33
4.4 Example of a block. 35
4.5 Parameter window... 36
4.6 Block window. 37
4.7 Creation of a wallet. 38
4.8 Transaction window. 39
4.9 Blockchain Window 40

v
List of abbreviations

NEM: New Economy Movement


PoW: Proof of Work
PoS: Proof of Stake
DPoS: Delegated Proof of Stake
PoET: Proof of Elapsed Time
PoI: Proof of Importance

yes
General Introduction

Blockchain is a technology for storing and transmitting information,


parent, secure, and functioning without a central control organ. It is a technology
pioneered that brought enormous popularity to new virtual currencies. It
presents a new generation of transactional applications implemented in a
pair network pair, and which, thanks to a mechanism of collective consensus combined with the usage
Use of a large public ledger, decentralized and shared, establishes trust,
responsibility and transparency while streamlining business processes.
The consensus mechanism is an essential component of Blockchain, providing a
non-partisan means to establish an agreement on the current state of the network. But since Bitcoin (the
The famous cryptocurrency appeared in 2008, its original consensus mechanism Proof of
Work (Proof of Work) has been limited and iterated, paving the way for a series of alternative algorithms.
having their own unique characteristics. Indeed, Proof of Work has been the practice
traditional mining (by selecting miners based on their computing capacities, their
energy resources in this case), but over time, the blocks have been
increasingly difficult to validate (and it also consumes more electric energy).
Reason why other platforms have established other consensus in order to execute the
mining such as proof of stake, delegated proof of stake, proof of importance, and proof of
time passed. Although several consensus algorithms are continuously proposed
to solve these problems, none have proven effective. A consensus within a network
Distributed nodes are not an easy thing. Consensus algorithms must be resilient.
to node failures, transmission delays, lost or corrupted messages and
must also face malicious nodes attempting to manipulate the consensus or
to delay him.
The consensus algorithm is the cornerstone of Blockchain, and the performance of the
Blockchain is closely linked to the consensus used2In this context and within the framework of
our graduation project, a set of consensus algorithms used in blockchain
is presented and analyzed. Thus, we have implemented and compared the performances of the two
consensus algorithms proof of work and proof of stake with the use of functions
of SHA256 and MD5 hashing. Our memory is organized as follows:
In chapter 1, we present an overview of cryptography.
Chapter 2 introduces the concept of Blockchain, its architecture, its characteristics, and its

1
General introduction 2

operation.
In chapter 3 we try to experiment and analyze some algorithms of
consensus in the blockchain according to the efficiency criteria of this mechanism, relying on
on their advantages and disadvantages.
In chapter 4, we present our comparison and evaluation of the two algorithms.
consensus 'proof of work and proof of stake'.
Our thesis is finally concluded with a general conclusion.
Chapter 1
Generalities on cryptography

1.1 Introduction
A blockchain is a technology for storing and transmitting information without
control body
It relies heavily on cryptography to ensure the security of the trans-
mission and the confidentiality of digital information within the network. In this chapter
we present the basic concepts of cryptography used in blockchain. Such as
asymmetric encryption, digital signature, hash function, etc.

1.2 Basic Concepts


1.2.1 Definition of cryptography
Cryptography is the art of encrypting and coding messages. It has become today
a science in its own right. At the intersection of mathematics and computer science, it allows
what civilizations have needed, since their existence, to secure data2].

1.2.2 The use of cryptography


Cryptography is traditionally used to conceal messages from view.
of certain users. This use is today of even greater interest as the
communications via the internet circulate through infrastructures whose reliability cannot be guaranteed
reliability and confidentiality. From now on, cryptography is used not only to preserve the
data confidentiality but also to ensure their integrity and authenticity:

•Confidentiality: involves making the information intelligible to other people than


the actors of a transmission1].

•Integrity: verifying the integrity of data involves determining whether the data has not
pay attention to others during communication.

Authentication: involves ensuring the identity of a user, that is to say, guaranteeing


olrontcabeotveilbeyhetonehetdeni si rnetrparihet that pnotdesrorchcae

3
Chapter 1. Overview of Cryptography 4

access can be allowed (for example, through a password that must be


crypt) access to resources only for authorized individuals.

Non-repudiation: information is the guarantee that none of the correspondents


can deny the transaction1].

1.2.3 Types of Cryptography


We can distinguish two types of cryptography: symmetric cryptography and
asymmetric cryptography.

[Link] Symmetric cryptography

Symmetric encryption, commonly referred to as conventional encryption, based on


on reversible mathematical functions. Symmetric encryption is based on a principle
a unique key for encryption and decryption. This key has several names such as
secret key, shared key.
We are talking about conventional encryption since it is the first key-based encryption.
was discovered and used1].
Symmetric encryption takes place (see figure 1.1) in the following steps [2] knowing
Alice is a user and Bob is a recipient:

Secret key generation by Alice.

Send this secret key to Bob securely.

Encryption of the message by Alice, with the secret key.

Sending this encrypted message to Bob.

Reception of the message encrypted by Bob.

Decryption of the message with the secret key received earlier.2]


Chapter 1. Generalities on Cryptography 5

Figure 1.1 – Symmetric Encryption.


[23]

[Link] Asymmetric cryptography

The principle of asymmetric encryption (also called public key encryption) is


appeared in 1976, with the publication of a book on cryptography by Whitfield Diffie
and Martin Hellman2].
In asymmetric encryption (or public key cryptography), users
they choose a random key that only they know (it is the private key). From
From this key, they derive the public key using an algorithm. Therefore, the keys exist through
pairs (the term bi-key is generally used). Users exchange this key
published through an unsecured channel [2]. (See figure 1.2).
The functioning of asymmetric cryptography can be summarized as follows:
A user writes a message and wants to send it to a recipient while ensuring
so that no intermediary can read it.

This user, like the recipient, both possess a pair of keys, and each
knows the public key of the other.

In order to encrypt a message for the recipient, the user will then use the key.
recipient's public.

This key activates an algorithm, and the written message is then transformed into text in-
comprehensible, which can then be sent to the recipient.

On the recipient's side, when they receive the encrypted message, they will need to use their own
the private key, the one he alone holds, in order to activate the algorithm to decrypt it.

Thus, even if someone intercepts the message along the way, they will not be able to decipher it.
since he does not have the recipient's private key!
Chapter 1. General Information on Cryptography 6

Figure 1.2 – Asymmetric Chiffrement23].

1.2.4 Hash function


[Link] Definition

Une fonction de hachage (dite aussi une fonction de contraction, digest, empreinte digital,
"hash code" is a one-way and collision-free function, generating an output of size
fixed (called condensate or imprint)3], characteristic of the data provided in input (see
figure 1.3)
A hash function is said w
-oyneacar

It is impossible to retrieve the initial data from the fingerprint.

It is designed in such a way that the hash produces an image or fingerprint of size
Fixed creation from a variable size data provided as input is either impossible.
reverse. While it is easy to produce a hash.

` a set of data, it is impossible to trace back to a set of


From
data from a known hash, at least with the available computing power
today.

A function is said to be without collision or injective

when it is reputed to be very difficult to find two different sources leading to a


same result3].
Chapter 1. Overview of Cryptography 7

Figure 1.3 – Hashing Principle.

[Link] Basic property of a hash function

An ideal cryptographic hash function has the following four properties:

The hash value of a message is calculated 'very quickly'4] .

By definition, it is impossible to construct a given hash value.


message having this hash value [ 3].

It is impossible to modify a message without changing its hash value.[4].

It is impossible to find two different messages having the same hash value.
[4].

The integrity of the data can be proven if the hash functions fulfill a
set of requirements. A hash function is said to have good cryptographic properties.
graphics if it is resistant to pre-images, second pre-images, and collisions.
The following three problems must therefore be difficult to solve.[5] :

•Preimage: Given a randomly chosen hash h, find a message m such that:


H(m) = h.

Second pre-image: given a randomly chosen message m, find a message


m' such that H(m) = H(m').

Collision: find two messages m, m' such that m is different from m' and H(m) = H(m').
According to its definition, a hash function is a function whose domain
is greater than the arrival set.
Chapter 1. Overview of Cryptography 8

[Link] Examples of hash functions

[Link].1 MD5MD5 (Message-Digest algorithm 5): is a hash function invented


by Ronald Rivest in 1991. This hash function allows for the calculation of a fingerprint of
any digital data (ranging from a simple string of characters to a file of several
giga bytes). The generated fingerprint is 128 bytes long (i.e., 32 characters)2].

The MD5 hash function was initially designed to be used as an algo-


secure cryptographic hash function to authenticate digital signatures.

MD5 consists of 64 blocks of this type, grouped into four rounds of 16 similar operations.
based on nonlinear functions (an addition and a left rotation) that
varies according to the round

[Link].2 SHA256SHA-256 (Secure Hash Algorithm 256): is a hashing function


which was developed by the NSA (United States National Security Agency) in 2001 and continues
to be used by many financial institutions and governments for encryption
of their data thanks to its complexity. It is among the most widespread.2].

SHA-256 accepts an input message of maximum length 264 bits and produces a
hash, or condensed, of 256 bits.

SHA-256 and other logical gates and operations will be applied to the whole.
of starting data, which will have been cut into pieces of 256 bits. They follow one another.
following a complex organization repeated around sixty times.

The compression function used by SHA-256 is based on shift registers.


and bit-by-bit operations. These registers named from A to H each contain a
32-bit word.

Its security is much more important than MD5, as it offers a good balance between
online storage space and security.

1.2.5 Digital signature


[Link] Definition

Like a handwritten signature, a digital signature is a generic term that in-


simply say a mechanism that allows linking a document to a signer. In
In both cases, the signatures can be verified publicly. So it allows for guaranteeing
the integrity of an electronic document once signed and to authenticate the signer24].
Electronic signature schemes are therefore fundamentally asymmetric: the key
the private key of the signer is involved in the signature algorithm, and the corresponding public key
to be verified.
Chapter 1. Generalities on Cryptography 9

[Link] Principle of signature

1. When using a signature, a unique digital fingerprint is created (called a


hash) grace to a mathematical algorithm. This hash is specific to this document, this
which means that the slightest modification will create a different hash (see figure 1.4).

2. The hash is encrypted with the signer's private key. The encrypted hash and the public key
the signatory's are then gathered in a digital signature that is attached to the
document.

Figure 1.4 – Digital signature.


[25]

Digital signatures are often used for three purposes that their properties facilitate.
allow achieving: data integrity, authentication, and non-repudiation.

Data integrity: Bob can verify that Alice's message has not been modified.
between sending and receiving. Any modification of the message would produce a signature
completely different.

•Authenticity: As long as Alice's private key is kept secret, Bob can use it
her public key to confirm that the digital signatures were created by Alice
and nobody else.

Non-repudiation: Once the signature is generated, Alice will not be able to deny having applied it.
In the future, unless its private key is compromised in any way.

1.2.6 Merkle Tree


A Merkle tree is a binary hash tree6It is built by chopping the
data (the transactions at the leaf level), then by hashing again the hashed outputs
Chapter 1. Overview of Cryptography 10

up to the root node, called the Merkle root. In this way, the integrity of a
an arbitrary quantity of data can be effectively ensured.
The Merkle tree is built from the bottom up. A typical Merkle tree can be
represented as the diagram in (Figure 1.5). In this example, the Merkle tree
contains four sheets.

Figure 1.5 - Merkle Tree.

1.3 Conclusion
The traditional goal of cryptography is to develop methods for exchanging
data in a secure manner. That's why modern cryptography is actually addressing
more generally to the problems of communication security.
In this chapter, we presented an introduction to cryptography that allows us to
s’assurer`a la fois certain nombre de s´ecurit´e de base : confidentialit´e, int´egrit´e et authentifi-
data transmission, as well as third-party authentication and non-repudiation.
These cryptographic techniques as well as other technologies form the elements
components of blockchain technology that will be introduced in chapter 2.
Chapter 2
Blockchain

2.1 Introduction
Data protection on the internet has always been a subject that has upset the web: it
Not a day goes by without the media talking to us about hacking of personal information.
banking or e-commerce giants that are being hacked. That is why researchers are
focusing today on encryption technologies and data security such as
the Blockchain.
A Blockchain operates on a peer-to-peer network of computers that all execute the
protocol and hold an identical copy of the transaction blocks, which are transmitted
without intermediaries and without any central authority thanks to a mechanism called consensus.
Blockchain itself is a public and shared ledger that records all transactions.
from the block of Genesis (first block) until today.
In this chapter, we present the new technology. Blockchain, which promises
to ensure this digital trust without a central organ. We show how it can
to be used to securely share and control information between the parties that
do not necessarily trust each other.
The present chapter covers: the history of Blockchain, its definition, its ca-
characteristics, its functioning, its components and the role of the consensus algorithm.

2.2 History of Blockchain


Blockchain became known in 2008 with the virtual currency bitcoin. The two are therefore
historically linked: Blockchain is the virtual infrastructure on which Bitcoin is based.
[16].
The term Bitcoin (capital B) refers to both:

•A digital currency (bitcoin with a lowercase b) using cryptographic techniques


graphical16].

In the protocol describing the operation of the network on which this currency circulates.

11
Chapter 2. Blockchain 12

This protocol is the Blockchain, or the monetary creation and validation of transactions.
actions are carried out in a horizontal and transparent manner. This system operates without authority
central third-party trust, unlike currencies controlled by banks or govern-
governments. The inventor of Bitcoin remains unknown to this day, even if some have attempted to
revendiquer sa paternit´e, sans r´eussir toutefois`a pr´esenter les preuves n´ecessaires. On ne
know his pseudonym, Satoshi Nakamoto, under which he put online at the end of 2008 the
white book: the origin of what he defined as an 'electronic currency system'
pair-a-pair[16].
It proposes a system based on cryptographic proofs, intended to replace the
trust granted to financial institutions. This system aims to respond to
several issues[7] :
A transaction between two parties without a trusted third party.

Protected sellers against possible fraud thanks to an impossibility of deletion.


to cancel or modify a transaction.

Protected buyers with a captive account system (unavailability of an asset


for a short period

No double spending possible thanks to the timestamping of transactions.

This system is, however, possible only if the computing power of the nodes
the honesty of the network is more important than that of the nodes acting to carry out an attack
combined on the network [7This concept will be explained later.

2.3 Definition
• A Blockchain, or chain of blocks, is a storage and trans-
information mission without a control body. Technically, it concerns a base of
distributed data including information sent by users and internal links
they are verified and grouped at regular time intervals in blocks, the set
being secured by cryptography, thus forming a chain [15].

• By extension, a blockchain is a distributed database that manages a


list of recordings protected against falsification or modification by the nodes
of storage. A Blockchain is thus a distributed and secured registry of all the
transactions carried out since the start of the distributed system [16].
Thanks to the definitions above, we can define the Blockchain as a distri-
distribution of a large decentralized and public ledger composed of numerous peers (nodes)
each peer has the same exact data records on its own device,
These recordings are stored in blocks where there is a set of
transaction in the form of a chain. (see figure 2.1)[8].
Chapter 2. Blockchain 13

Figure 2.1 - Structure of a Blockchain.

2.4 Characteristics of Blockchain


Blockchain technology is based on the following main characteristics26]

Decentralization: a peer-to-peer network where each node in the network fulfills one or
several functions;

Transparency: the transaction history is permanently accessible to no one.


door that connects via an internet connection and a Blockchain explorer, the source code
a public Blockchain is open and accessible to everyone;

•Reliability: Blockchain relies on proven cryptographic mechanisms and


extremely robust, such as the management of public/private key pairs and
hash functions. Additionally, transactions are all validated by algorithms
(que l’on appelle consensus) avant d’ˆetre partag´ees au sein de blocs de donn´ees ;

•Immutability: once inserted into the Blockchain, a transaction is tamper-proof.


understood by malicious actors who would participate in the network;

2.5 Operation of a Blockchain


The peculiarity of Blockchain is that it operates without a central control body.
place to be grouped in one location or to go through a single intermediary, the transactions
(purchase or transfer of money for example, in the case of cryptocurrency blockchain) are
distributed among all members of a network via their computer.

2.5.1 Operation
For a first approach to understanding how blockchains work, the easiest is to reason
sounding with a purely monetary blockchain. We can take the example of Bitcoin, or
of a blockchain with 'simple' tokens, starting with the creation of a transaction
may be described in a few steps (see figure 2.2):

1. An account (or wallet) must be created for a user.


the blockchain can send or receive cryptocurrency. It uses its wallet
and makes a transaction to B. This transaction is broadcast on the network.
Chapter 2. Blockchain 14

2. Upon receiving the transaction, each miner authenticates the transaction using
from A's public key. This transaction along with other recent transactions are
Regrouped in blocks, and each transaction will be verified and validated by the miners. When
from the verification of the transaction, the transaction history of Aest was retrieved for
to verify that the money he received previously has not been reused since. One verifies
In fact, simply that he should not try to spend the money he has received twice.

3. Once the verifications are made, the block in which the transaction is located enters
AetBest validated by minors, according to consensus techniques that depend on the
type of blockchain, and which allow to achieve distributed consensus, that is to say the
consensus of nodes on the state of the network10To do this, the miners must launch
a cryptographic procedure: the hash calculation of the block. Each block has
an identifier that takes the form of a hash allowing to link the blocks to each other
others. This hash is still the result of hashing the previous block.

4. When the block is validated, it is dated and added to the blockchain to which all the
users have access.

5. Finally, "B" receives the transaction from A.

Figure 2.2 – General Principle of a Blockchain[26].

2.5.2 Role of the axe


In the case of a blockchain, the hashing is performed based on the content of the block: the
hash of the previous block, a certain number of transactions, and a timestamp (see the figure
2.3).
Chapter 2. Blockchain 15

Figure 2.3 - Role of hashes in blocks26].

The modification is visible in all the following blocks as the blocks are all
they are cryptographically linked to each other. Consequently, modifying the content of a block implies
to recalculate the hashes of all the blocks that follow it (see figure 2.4).

Figure 2.4 - Role of hashing in the integrity of the blockchain26].


Chapter 2. Blockchain 16

2.6 Blockchain Components


Blockchain technology is based on several concepts such as transaction, block,
consensus,.. In this section, we present these different components.

2.6.1 Account or wallet


The wallet is software for the backup of the private key and public key of a
Blockchain user, this software can be a web application, mobile phone
or computer. It would allow this user to control their cryptocurrency account, see
its amount and execute transactions[?].

Figure 2.5 – Example of a private key and public key [?].

2.6.2 Transaction
For a first approach to the functioning of blockchains, the easiest is to
reason with a purely monetary blockchain.

For a simple definition, a transaction is summarized by three pieces of information: who gives
what to whom.7]

The concept of transactions is actually based on asymmetric cryptography. When


someone is embarking on the process of creating a transaction, they generate, with the help of
from his wallet, a public key and a private key. The private key is not transmitted
w
[Link],harheotheton,siykecipublhetndaonsrpea
Keys (private and public) ensure the integrity of the transmitted data in
encrypting the sent data, as well as the authentication of the origin of the transaction

Transactions consist of a list of transaction inputs and a list of


transaction outputs.

Each transaction output contains two pieces of data:

Data: The data that he will send.

Recipient's address: this is derived from the recipient's public key.

The transaction entries contain:


Chapter 2. Blockchain 17

Reference a previous transaction output.

Signature that proves the authenticity of the transaction11].

2.6.3 Block
A block is a record in the blockchain, which contains and confirms several
data or pending transactions. Every 10 minutes on average (in the case of Bitcoin),
A new block containing transactions is added to the blockchain through mining.
[13].
Each block is made up of several fields:

•Bloc : l’indice de bloc.

•Hash of the previous block: field contains the fingerprint of the previous block (block index
number 91 in our example).

•Transaction : la partie qui contient la liste des transactions.

Timestamp: block creation time.

•Hash: the identifier of the current block.

Figure 2.6 - Structure of the blocks of the chain26].

2.6.4 Mining
Mining is a very important process in a blockchain.14]

•Miner: is the node that takes care of mining (performing the mining process) in
providing computing power to validate transactions.
Chapter 2. Blockchain 18

Mining: It is the process that allows the validation of transaction blocks.


This operation, very costly in computing power, is motivated
by the awarding of a prize to the winning minor.

2.6.5 Consensus Algorithm


The consensus algorithm plays an important role in the context of Blockchain.
But it is to get all the participants to agree on a single state of the blockchain.
Since there is no centralization to decide which new blocks are valid, each
a node must decide whether to accept a newly received block or not. Given that all nodes
The network nodes have their own copy of the complete data of the blockchain and they use it
digital signature to verify the authenticity of all transactions.15]
The consensus mechanism has the following objectives:

Ensure that you have a valid block in the blockchain.

An equitable agreement will be reached for all parties involved.

One must ensure that there will be no powerful opponents to succeed in branching off.
chain

Make the network stronger against various types of attacks.

Consensus algorithms are a very important part of platforms


blockchain. Without them, we will be left with only a stupid and immutable database. We
Here we list some of the most commonly used consensus algorithms that we will evaluate and analyze.
in the next chapter.

Proof of Work.

Proof of Stake.

Delegated Proof of Stake.

Proof of Importance

Proof of Elapsed Time.

2.7 Conclusion
In this chapter, we studied the mechanism and the concept upon which the block is based.
chain, which is a revolutionary new technology that has captured the attention of researchers
and innovators in the world of technology. This computing innovation allows
thus organizing data exchanges on a distributed network, ensuring security
Chapter 2. Blockchain 19

data by encryption, and involving the nodes of the network for the creation of
new blocks of the chain.
The basic principle of a blockchain relies on the notion of consensus, which will be the goal of
next chapter, where we will discuss some consensus algorithms in detail.
Chapter 3
Consensus algorithms

3.1 Introduction
After understanding the principles of blockchain and discovering its architecture, we
let's emphasize the consensus in blockchain: its utility, its mode of operation
or the different forms of consensus that may exist.
The challenge is not to enter a level of technical detail but rather to evaluate and
popularize this key process of a blockchain. So, in this chapter after having learned
the criteria for the effectiveness of a good blockchain consensus algorithm. We present in
Detail some of the most used consensus algorithms in blockchain and list them.
different advantages and disadvantages.

3.2 Criteria for the effectiveness of a consensus mechanism


suspicious
Reaching a consensus within a network of distributed nodes does not seem to be a simple task.
ais´ee. Les algorithmes de consensus doivent [16] :

Beˆ resilient to node failures, transmission delays, lost messages


you corrupted.

•Facing malicious nodes trying to manipulate or delay the consensus.

To do this, a plurality of mechanisms exist (PoW, PoS, DPoS, PoET, PoI, etc.).
Each of them has its own characteristics in terms of synchronization,
message emission (frequency, size), fault tolerance, prevention against
malicious nodes, performance and security of exchanged messages.
Thus, the blockchain system will reach a consensus guaranteed that all nodes
The network nodes agree on the same state of the register and the data that is stored in it.
to determine more precisely the effectiveness of a consensus mechanism, it is evaluated
according to three main criteria[16] :

20
Chapter 3. Consensus Algorithms 21

Termination (Liveness): All operational nodes participating in the consensus must


finally produce a value.

•Speed / Consistency (Safety): All operational nodes must agree on


real time on one of the values proposed by one of the nodes. This value must be
valid according to the rules defined by the mechanism.

Fault Tolerance: The mechanism must be capable of functioning


even if one or more nodes are failing.

It is crucial to be able to satisfy the three properties listed above if one wishes to
to solve, in its entirety, the consensus problem. Unfortunately, Fischer, Lynch
and Patterson, three computer scientists, demonstrated in 1985 that no algorithm
deterministic consensus could not guarantee these three properties at the same time.
the sound of an asynchronous system such as a network of distributed nodes (FLP Impossibility).
Thus, as a general rule, since tolerance to errors is absolutely vital in the
Within a framework of a distributed network of nodes, consensus mechanisms must choose between the
certainty and the ending according to the requirements of the application for which it was designed
the decentralized platform16].
In terms of fault tolerance, traditional consensus mechanisms operate
In a network of distributed and known nodes, they first endeavored to cope with the faults.
"fail-stop" where a node no longer responds due to a hardware or software problem18].
The following section presents a set of the most well-known consensus algorithms.
in literature, by explaining their principle and emphasizing their advantages and
inconveniences.

3.3 Consensus algorithms


Among the existing consensus algorithms, we can mention: proof of work, proof
of stake, proof of stake of equity, etc. In this section, we detail the principle of each
algorithm.

3.3.1 Proof of Work (POW: proof of work)


First appearing in 1993, the concept of proof of work was developed.
to prevent service alteration attacks and other service abuses such as spam,
on a network by imposing work on the service user, generally by using
the computing power of his computer.20]
In 2009, Bitcoin introduced an innovative way to use proof of work, like
consensus algorithm. In this case, PoW is used to validate transactions that are
grouped into blocks, which are linked together to form a blockchain. Since then, PoW
Chapter 3. Consensus Algorithms 22

has spread to become a widely used consensus algorithm and is now


deployed by many cryptocurrencies.16]

[Link] Principle of operation

Participants in the blockchain (miners) must solve a computational problem.


complex in order to add a block of transactions to the blockchain.

Essentially, proof of work is a concept that emphasizes


the computing power of the nodes. If a node has 10 percent of the capacity
of total calculation, then he will manage to mine an average of 10 percent of the new ones
blocks. The node must prove that it indeed has this computing power by doing
work on your computer equipment. This is done to ensure that minors put
money / resources (extraction machines) to do the work, which shows
that they will not harm the blockchain system, as harming the system will lead to a
loss of their investment16].

The difficulty of the problem can be modified during execution to ensure a time
of constant blocking. Sometimes, there is a situation in which more than one miner solves
the problem simultaneously. In this case, the miners choose one of the chains and
the longest chain is considered the winner. So, assuming that the
Most miners work on the same chain, the one that will develop the most.
quickly will be the longest and the most reliable.

Figure 3.1 – POW in a blockchain16].

The PoW version of Bitcoin is based on the use of hashes. Its operation
is illustrated in the following steps:

Miners are responsible for adding new blocks to the blockchain. To do this,
Miners must try to guess a pseudo-random number (Nonce).
Chapter 3. Consensus Algorithms 23

This number, when combined with the data provided in the block and transmitted
through a hash function, must produce a result that meets the conditions
data, for example, a hash starting with four zeros.

When a corresponding result is found, the other nodes verify its validity.
The result and the minor node is rewarded by the block reward [17(currently
12.5 bitcoins, for the Bitcoin blockchain.

Therefore, it is impossible to add a new block to the main chain.


without first finding a valid nonce, which will generate in turn the solution of a block
specific (called block hashing). Each validated block contains a block hash
who represents the work done by the miner.

The steps of the PoW algorithm are illustrated in the diagram of figure 3.2:

Figure 3.2 - Organigram of the PoW algorithm.


Chapter 3. Consensus Algorithms 24

[Link] Advantages of POW

We can list the following advantages:

Proof of work helps protect the network against many different attacks.
A successful attack would require a lot of computing power and a lot of time.
to perform the calculations and therefore it would be ineffective because the incurred cost would be higher
to the potential rewards for attacking the network15].

Proof of work is secure, the history of the blockchain is impossible to alter.


falsifier15].

It is necessary to own at least 51 percent of the computing power of the network.


to saturate it with false transactions15].

[Link] Disadvantages of POW

As disadvantages, the following points can be noted:

Mining requires expensive computer equipment that consumes a


large amount of energy, even if it is what guarantees the security of the network, these calculations
data exploration cannot be used beyond.17]

Massive quantity of processing power and energy in the form of electricity.17]

High costs associated with material resources.17]

Latency time required to validate a transaction.17]

The decreasing gain of miners would increase the risk of network corruption, since
The reliability of the blockchain requires that no hostile operator disrupts it any further.
half of the computing power of the chain (51 attack for 100)15].

3.3.2 Proof of Stake (POS)


Proof of Stake was created as an alternative to Proof of Work (PoW), in order to
to solve the problems inherent to the latter. Although they both share the same
Objective to reach a consensus in the blockchain, the process to achieve the objective
is quite different.

The proof of stake is directly linked to the currency since it ties the capacity to
validate a block the amount of money (or token) held. Without cryptocurrency, there is no
so no consensus mechanism, which is the cardinal foundation of a blockchain
[17].
Chapter 3. Consensus Algorithms 25

This approach to network management, not relying on overconsumption


energy action. This time, the system gives importance to the share of tokens
nionitauclricnnuimblareotthetoow
cm
tdensuplarvindiinahtatsecdveiconirtcele
the network.

If an individual owns 10 percent of the total number of tokens, they will be able to mine in
average 10 for 100 of the generated blocks17].

The underlying concept is that if an individual is notably involved in a


Blockchain (understand that it holds a significant portion of the tokens, and therefore has a
significant financial interest) it will be particularly sensitive to the proper functioning
of this last one.

The steps of the PoS algorithm are illustrated in the diagram of figure 3.3:

Figure 3.3 - Organizational chart of the PoS algorithm.

[Link] Advantages of POS

The following points can be cited as advantages:

The main advantage of PoS is that the validation of a block does not rely on
powerful algorithmic calculations that would consume enormous amounts of energy and would have
consequently a negative impact on the environment.
Chapter 3. Consensus Algorithms 26

Proof of stake is much more profitable than other methods and does not lead to
of value flight towards fiat currencies.

•The loyalty of the retention and hoarding of tokens. Indeed, the inves-
weavers (virtual miners, or forgers) have a greater interest in preserving their
reward for their proof of stake rather than immediately selling it at the price of
market. Virtual miners (PoS) will rather tend to keep their reward
to maximize their future chances of being selected for the validation of the next ones.
blocks and perceive new rewards.[17]

The operational stability of the network with PoS is maintained as it is presented in


Figure 3.1. The more miners join the network, the more block creation increases.
Automatically, the average creation time decreases, which increases the difficulty.
mining. At this moment, the block validators are leaving the network, which implies
a decrease in block creation. Finally, the average time for block creation becomes
m
.norlahetot

Figure 3.4 - Diagram of the advantages of POS.

[Link] Inconvenience of POS

Despite its advantages, we can identify the following issues:


Favoring people with the most tokens promotes hoarding. That is to say
accumulate money without spending it. Storing tokens for mining will therefore limit the
token exchanges and thus harm the development of cryptocurrency.18]
Chapter 3. Consensus Algorithms 27

Monopolization of wealth, indeed the more tokens one has, the more one can forge and more
We receive money. The rich remain rich.

3.3.3 Delegated Proof of Stake (DPoS)


The delegated proof of stake consensus algorithm (DPoS) was developed by Daniel
Larimer, in 2014. Bitshares, Steem, Ark, and Lisk are some of the crypto projects.
currencies that use the DPoS consensus algorithm.17]

A DPoS-based blockchain counts stakeholders subcontracting their work.


a third. In other words, they can vote for a few delegates who will secure themselves
the network in their name. The delegates can also be called witnesses and they are
responsible for reaching a consensus during the generation and validation of new
blocks.

The right to vote is proportional to the number of shares held by each user.
The voting system varies from project to project, but in general, each delegate presents
an individual proposal when he asks for votes.

Usually, the rewards collected by the delegates are shared proportionally.


with their respective voters. Consequently, the DPoS algorithm creates a
voting system that directly depends on the reputation of the delegates.

If an elected official behaves poorly or does not function effectively, they will quickly be
expelled and replaced by another.

Regarding performance, DPoS blockchains are more scalable.


capable of handling more transactions per second, compared to PoW and PoS.

The roles of the delegates are:

Ensure that their node is always operational.

Transaction collection on the network.

Sign and disseminate these blocks, validate the transactions.

If there are consensus problems, the Department of Safety and Security allows
to resolve them in a fair and democratic manner.

Delegates do not have the power to modify the details of a transaction. However, in
As validators, they could theoretically exclude certain transactions from a block.
However, this has very little effect since the next block created will include these transactions.
which will give the next delegate the expenses associated with their validation.
Chapter 3. Consensus Algorithms 28

Thus, the transactions will only be slightly delayed. Moreover, this would lead to
Inevitably, what the dishonest delegate is will be eliminated by the rest of the network.
Partially, a DPoS network is self-managed and controlled by all its participants, watching over
what the best interests of the network remain the priority.

[Link] Advantages of DPoS

The advantages include:

•Efficiency from an energetic point of view, and faster than a POW mechanism.
POS allows for transaction validation in just a few seconds.

Reduces interactions between nodes and allows for a greater number of trans-
faster transactions and validations.

[Link] Disadvantages of DPoS

However, the DPoS consensus also has its limits, which are:

Risk of excessive centralization with risks of vulnerability.

DPoS sacrifices decentralization to favor the speed of transaction validation.


network functions.19]

Participants with the most tokens can vote for themselves in order to
to elect transaction verifier

A ploutocratic system, always encouraging the enrichment of the richest:


the votes of the participants carry more weight according to the importance of their portfolio, and the
delegates who can afford to redistribute a large part of their earnings will have
always more chances of being elected.

3.3.4 Proof of Elapsed Time (PoET: Proof of Elapsed Time)


The concept of the POET consensus was invented in early 2016 by Intel, the renowned giant in
the manufacture of chips. It offers a ready-to-use high-tech tool to solve the
computer problem of random election.17]

PoET is a consensus mechanism algorithm that is used on networks.


blockchains, authorized to decide on the rights of extraction or block winners on
the network. The authorized blockchain networks are those that require all participants
potential is identified before being authorized to join.

Based on the principle of a fair lottery system where each node is equal.
susceptible to winning, the PoET mechanism is based on the distribution of chances
to win fairly among the largest possible number of participants in the network.
Chapter 3. Consensus Algorithms 29

The operation of the PoET algorithm is as follows.

Each node of the blockchain network generates a random wait time.


and goes into sleep mode during this specified duration.
The one who wakes up first, that is to say, the one with the longest waiting time.
the court wakes up and validates a new block in the blockchain, broadcasting the
necessary information for the entire peer network.
The same process is then repeated for the discovery of the next block.

The consensus mechanism of the PoET network must guarantee two important factors.

Firstly, let the participating nodes truly select a time


which is indeed random and not a shorter duration chosen specifically by the parties
participants to win,
Secondly, the winner has indeed finished the waiting time.

Essentially, the workflow is similar to the consensus mechanism followed by the


proof of work (POW) algorithm of Bitcoin, but without its energy consumption
elevated. Instead of being resource-intensive, it allows the processor of a miner
to sleep and to switch to other tasks during the specified duration, thereby increasing
its effectiveness.

The execution mechanism of trusted code in a secured environment takes


also responsible for many other needs of the network. It ensures that the code
Trust is indeed executed in the secure environment and is not modifiable by
no external participant. It also guarantees that the results are verifiable by
the participants and external entities, thus improving the transparency of the consensus of
network [20]

[Link] Advantage of the POET

The low cost of participation increases the likelihood that the population will validate
tailor is important, increasing the robustness of the consensus algorithm.

More people can easily participate, therefore decentralized.

It is easy for all participants to verify that the minor has been legitimate.
selected.

The cost of controlling the process of electing leaders is proportional to the value
obtained from the latter.21]
Chapter 3. Consensus Algorithms 30

[Link] Disadvantages of the POET

Even if it works, the user must have specialized equipment. Therefore, he cannot
to be adopted en masse.

Not suitable for public blockchains.

3.3.5 Proof of Importance (POI)


Proof of Importance is a blockchain consensus algorithm that takes into account
the overall productivity of network users. It was first used by NEM (New
Economy Movement, a blockchain technology company aiming to process transactions.
more effectively and to introduce the reputation of the crypto-system. 17]

This algorithm is designed to reward very loyal users of the blockchain.


Consequently, encourage greater use of the platform.

It is an algorithm that depends on how many active users are on the network. The more they
the more active they are, the more rewards they receive.

Each user is rated, and the higher their score, the greater the rewards.
important.

The number of pieces can naturally balance the votes given that the
High-value transactions may be eligible for more transactions.
However, the algorithm mainly depends on the activities monitored by each
user and not necessarily the amount they are making.22]

[Link] Advantages of POI

The rich may not continue to enrich themselves unfairly on the platform because the
The amount of money in an individual's possession is not the only factor to consider.
when measuring the reputation of an account.

[Link] Disadvantages of the POI

A burning problem with this method is the use of dummy transactions that ...
people would be rewarded for sending back-and-forth transactions to deceive
the algorithm. The use of fake transactions is a problem that NEM (New Economy
Movement: a group of organizations trying to restructure the economic system)
other major players still need to be exhausted.
Chapter 3. Consensus Algorithms 31

3.4 Conclusion
As we have seen, none of the consensus algorithms, even when using a huge
quantity of resources does not provide a perfect solution to the requirements of the mechanism
consensus in a blockchain. Each of them has weaknesses that put the network at risk.
However, it is worth considering consensus algorithms only as
tools to ensure the stability of the network. Finally, based on all the agreements discussed in this
chapter, it seems that proof of work provides networks with the greatest reliability because it
prevents long-range attacks. The performance of this algorithm and the algorithm of
PoS are treated and evaluated in the next chapter.
Chapter 4
Comparison of algorithms
consensus

4.1 Introduction
The objective of a consensus mechanism in a Blockchain is to allow members
of the network to agree on the current state of the transaction history in the absence of an organ
centralized tasked with updating this register.
As we have already seen in the previous chapter, there is a set of algos-
consensus algorithms, which vary in terms of performance (software and hardware) and
de s´ecurit´e. Ces crit´eres sont utilis´es, dans notre projet, pour comparer deux algorithmes de
consensus discussed in this present chapter. In this´ regard, we have implemented two algo-
consensus algorithms proof of work and proof of stake, with the use of two functions
hashing, SHA256 and MD5.
In this chapter, we present the various means used to carry out this project and
We present the different means and tools. We start first with the idea
General overview of our project, then we distinguish the programming environment and the
tools used. Finally, we discuss the complete process of our Blockchain system and
its algorithms to analyze the results of the simulation obtained.

4.2 Work idea


In our work, we compare two consensus algorithms, proof of work.
and proof of stake, by using two machines with different capacities. We evaluate
the two algorithms in terms of hashing time and mining among users of
blockchain
The idea of the work is based on a comparison of the magnitude of the effect of two algorithms.
of consensus: proof of work and proof of stake, using two functions of
hashing, SHA256 and MD5.
We have adapted the algorithms as follows:

32
Chapter 4. Comparison of consensus algorithms 33

Figure 4.1 - Organigram of the PoW algorithm.

For the proof of work algorithm: (see figure 4.1)


We have adapted the Bitcoin proof of work algorithm, of which the proof of work
it consisted of the determination of the nonce which, concatenated with the other components of the ...
The block head will allow for a hash starting with a minimum number of
zeros (i.e. below a threshold). The pseudo-code of Bitcoin's PoW can be expressed
as follows (see figure 4.2):

Figure 4.2 – Bitcoin PoW Pseudo-Code.


Chapter 4. Comparison of Consensus Algorithms 34

The first node that manages to display a winning hash thus acquires the right to add
the block is linked to the chain and claims the mining reward

In our solution, we used two hash functions: SHA256 and MD5.

For the proof of stake algorithm PoS: we previously used the illustrated operation.
in figure 4.3.

Figure 4.3 - Flowchart of the PoS algorithm.

4.3 Development Environment


4.3.1 Material
We used two machines with different characteristics that are presented.
in the table (see table 4.1).
Chapter 4. Comparison of Consensus Algorithms 35

Table4.1 – Caract´eristiques des machines utilis´es.

4.3.2 Software
There are several tools and programming languages to implement this project. We
built our application using the following tools:

Python: Python is a high-level interpreted programming language and object-oriented.


object with a dynamic semantics. It is highly sought after by a large community
of developers and programmers. Python is a simple language, easy to learn
and allows for a good reduction in the cost of code maintenance. The libraries
(packages) Python encourages modularity and reusability of code. Python
and its libraries are available (in source or binary) free of charge for the
majority of platforms and can be redistributed for free

Python Flask is an open-source micro framework for web development in Python.


It is classified as a micro framework because it is very lightweight.

HTML and CSS: Various options are available to develop user interfaces.
User Interfaces (GUI). In our project, we used HTML and CSS because
of the speed and ease of creating graphical applications

JavaScript (AJAX): used to send and retrieve data to and from a


asynchronous server,

•Pycharm: Since PyCharm is the most complete Python API, we have chosen
to work with. It is a good development environment dedicated to the language
Python.
Chapter 4. Comparison of Consensus Algorithms 36

4.4 Proposed Solutions


We have implemented a Blockchain and simulated its operation on localhost and on
a network of two computers.

4.4.1 Implanted blockchain


The structures of transactions and adapted blocks are presented in the following lines.

[Link] Transaction Structure

Each transaction contains the following fields:

•Private key and public key of the sender that are generated during the creation of the wallet.
currency.

Public key of recipient.

Sent to Montent.

[Link] Block structure

The block in the embedded Blockchain having the following structure:

Nonce: is the number of cycles for the miner to obtain the generated hash. The solution
is the generation of a hash that starts with 2 zeros.

•Hash (hashing): The current data hashing.

•Time: the block validation timestamp (date and time).

Mining: the generated hash starts with 2 zeros (instead of 4 zeros to minimize a
little execution time.
Chapter 4. Comparison of consensus algorithms 37

Figure 4.4 – Example of a block.

4.4.2 Localhost
We first tested our solution locally on a single machine. On the
Local host, we used 5 nodes, changing the port number each time. By
example:

Address of the 1st node: [Link] port:5001

Address of the 2nd node: [Link] port: 5002

4.4.3 Cable network


The principle of the network is almost the same as localhost, except that each node has a
different IP address, that is to say each network user participates with their own machine.
This network is wired via an Ethernet cable which makes it easier for us to transmit data.
(transactions).

[Link] Some windows of our application

Our application contains several windows (hash, block, transaction, Blockchain, pa-
parameters, etc.) in each node allowed these windows to present the most important ones.
in the following lines:

[Link].1 Parameters

This window will be used to select the consensus algorithm we want to apply on the
Blockchain network.

If the hash involved (POW or POS and HASH 256 or MD5).


Chapter 4. Comparison of Consensus Algorithms 38

Figure 4.5 - Parameter window.

[Link].2 Mining a block Example of mining a block of data with PoW in function
MD5 Hashing.

Figure 4.6 - Block window.


Chapter 4. Comparison of Consensus Algorithms 39

[Link].3 Creation of the wallet

On this page, we need to create a wallet to store money.


in order to allow for a payment (or a transaction) to be made.

The creation of a wallet consists of assigning a masked private key and a key
public that everyone can see.

Figure 4.7 - Creation of a wallet.

[Link].4 Transaction To generate a transaction and send it, you must have:

The private key of the sender. (Invisible).

The public key of the sender

The public key of the money receiver.

The amount of money to be sent.


Chapitre 4. Comparaison des algorithmes de consensus 40

Figure 4.8 – Transaction window.

[Link].5 Blockchain Window

Transaction List: transaction table and the Mine Button (will be displayed at
the minor).

•Blockchain Update Button: update of the Block list.

•List of Blocks: Each block displays its own information.

View Button: displays the transaction list of this Block.


Chapter 4. Comparison of consensus algorithms 41

Figure 4.9 - Blockchain Window.

4.5 Experimental Results


In this part of the chapter, we analyze the performance of consensus algorithms.
sus.
We used two machines of different capacities to test two algorithms
consensus (PoW and PoS), while using two hashing functions (SHA256 and MD5).
The results are presented and discussed in the following lines.

4.5.1 For PC1


[Link] PoW and PoS with SHA256 for PC1

In this case, we applied the PoW and then PoS consensus algorithms with the function of
SHA256 hashing, with PC1 being a minor. The results are presented in (table 4.3),
in terms of hashing time and mining time.
Chapter 4. Comparison of Consensus Algorithms 42

Table 4.2 - Result of PoW/SHA256 and PoS/SHA256 of pc1.

[Link] PoW and PoS with MD5 for PC1

The results of the application of PoW and PoS consensus algorithms with the function of
MD5 hashes for which pc1 is minor are presented in Table 4.4, in terms of time
hashing and mining time.

Table 4.3 - result of PoW/MD5 and PoS/MD5 of pc1.

4.5.2 For PC2


[Link] PoW and PoS with SHA256 for PC2

In this case, we applied the PoW and then PoS consensus algorithms with the function of
SHA256 hash, of which the PC2 is minor. The results are presented in table 4.5.
in terms of hashing time and mining time.
Chapter 4. Comparison of Consensus Algorithms 43

Table 4.4 - Results of PoW/SHA256 and PoS/SHA256 of pc2.

[Link] PoW and PoS with MD5 for PC2

The results of applying the consensus algorithms PoW and PoS with the function of
MD5 hashes where pc2 is minor are presented in table 4.6, in terms of time.
hashing and mining time.

Table 4.5 - Result of PoW/MD5 and PoS/MD5 of pc2.

4.6 Analysis and discussion of the result


As the results show:

The mining time in proof of work is higher compared to proof


of stake.
Chapter 4. Comparison of consensus algorithms 44

The hashing time of SHA256 is much slower than MD5.

These two times (mining and hashing) depend on the number of transactions, depending on
hashing and machine performance.
For example, when applying a consensus with SHA256, hashing and mining
takes enough time due to its complexity. On the other hand, MD5 is faster, in this
It is concluded that the operating mode of the hashing algorithm is very important.
at the level of speed.
Moreover, the difference in results between the two machines is very clear,
which indicates that the performance and capacity of the machine play a very important role
in terms of time and electricity consumption.
D’apr´es les tableaux de teste, on remarque que l’algorithme de consensus de la preuve de
work is slow compared to the proof of stake in mining regardless of the hash function
used because the proof of work relies on computing power, from there on
It is concluded that proof of stake is better than proof of work either in terms of time.
or energy consumption.

4.7 Conclusion
In this chapter, we have addressed the implementation part of our application.
analysis of consensus algorithms in the Blockchain. We began by presenting
the Blockchain network that was used to generate and test and evaluate the performance of
algorithms. We also presented the differences in preprocessing and the approaches
realized to carry out transactions and realized the blockchain as well as the metrics used
to measure the performance of the consensus. Finally, we ended with the simulation and
by discussing the results obtained.
General conclusion

Without consensus mechanisms, we would not have a decentralized peer-to-peer system.


fault-tolerant. It's that simple. While proof of work and proof
The stakes are certainly the most popular choices, new mechanisms are emerging.
from time to time. There is no perfect consensus mechanism, but it is interesting
to see these new cryptocurrencies emerge with their own protocols. In short, a
blockchain is characterized by its consensus which depends on its synchrony and the nature of
its tolerance to failures. These two factors determine the security of the blockchain (when
is consensus possible and what failures is it robust to) but also its performance-
performance. As we have seen, none of the consensus algorithms, even when using a
huge quantity of resources does not provide an absolute solution to the problems of mechanism
consensus in a blockchain. Each of them has weaknesses that put the network at risk.
danger.
In this memo, we analyzed a set of consensus algorithms.
emphasizing their principle, their advantages and their disadvantages. Thus, we have im-
plant two famous algorithms PoW and PoS, and test their performance in terms of
hash time and mining time, using two hashing algorithms, MD5 and
SHA256. Our tests are done on a local machine and on a network.
As perspectives, we propose:

implement other consensus algorithms and test their performance

Use a network with multiple nodes and different capacities.

•Propose improvements for existing algorithms, by playing with their pa-


parameters for example.

45
Bibliography

BOUCHEMA MERYEM. Exploitation of parametric transformations in encryption


fixed images. PhD thesis, University of Sétif 1-Ferhat Abbas, 2012.

TOURAJ EBRAHIMI, FRANCK LEPREVOST, ´ and BERTRAND WARUSFEL. Cryp


Cartography and security of systems and networks. Hermès-Lavoisier, published 2006.

THOMAS FUHR. Conception, evidence and analysis of cryptographic hash functions


PhD thesis, Telecom Paris Tech University, 2011.

STANISLAS DE QUINETAIN. The cryptographic hashing for everyone to understand.


[Link], consulted on 20/02/2020.

CHRISTINA BOURA. Analysis of cryptographic hash functions. PhD thesis,


Pierre and Marie Curie University - Paris 5, 2012.

RALPH C MERKELE. A digital signature based on a conventional encryption function.


In Conference on the theory and application of cryptographic techniques, pages 369–378.
Springer, 1987.

FERRÉOL GODEBARGE and ROMAIN ROSSAT. Key principles of an application


Blockchain. PhD thesis, EM Lyon Business School, 2016.

SHAOAN XIE ZIBIN ZHENG. School of Data and Computer Science. Binance Academy
translated by the author / binance academy, published 2017.

[9] FERR´eOL GODEBARGE and ROMAIN ROSSAT. Principes cl´es d’une application
Blockchain. PhD thesis, EM Lyon Business School, 2016.

What is blockchain. [Link] consulted on 09/06/2020.

[11] PRAPATH SIRIWARDENA. The Bitcoin Transaction. Apress, Berkeley, CA, publi´e
2018.

[12] Bitcoin expliqu´e par son inventeur. https ://[Link]/bitcoin-explique-par-son-


inventor/, consulted 10/13/2020.

Nikita Borisov Easier Sonia Jahid, P Mittal. Encryption-based access


control in social networks with efficient revocation. ASIACCS, Hong Kong China, published
22/03/2011.

46
Bibliography 47

[14] THOMAS HERBST. C’est quoi le [Link], misa` jour le 4 aouˆt 2020.

[15] BIKRAMADITYA SINGHAL, GAUTAM DHAMEJA, and PRIYANSU SEKHAR


[Link] Blockchain: A Beginner’s Guide to Building Blockchain Solutions.
Apress, Berkeley, California, published 2018.

SATOSHI NAKAMOTO. Bitcoin: A peer-to-peer electronic cash system (white paper).


URL: [Link] published 2008.

Vaibhav Saini, consensus blockchain. [Link] Consulted in December


2019.

Cryptocurrency, mining, proof of stake. [Link]

Cryptocurrency. [Link] Accessed on 27/10/2020.

DARYA YAFIMAVA. Blockchain [Link], 17/01/ 2019.

[Link] consulted on 28/10/2020.

SAL MIAH. Technical series on blockchain, (5-part series - part 5) basic concept of
la blockchain pow vs pos vs poi. CryptoDigest, publi´e 8/06/2018.

asymmetric cryptography. [Link] consult e'


September 1, 2020.

CHRISTOPHE DOROTHE. Blockchain the revolution of the sharing economy, Smile


is a member of APRIL. Smile, published in 2017.

Integration of the signature


digital to the ssl/tls protocol. In Annals of Telecommunications, volume 61, pages
522–541. Springer, published in 2006.

SENATE. The scientific notes of the office note number 4: understanding blockchains.
published April 2018.

[27] MELANIE [Link] : Blueprint for a new economy. ” O’Reilly Media, Inc.”,
published in 2015.

GODEFROY GALAS. Analysis and comparison of consensus mechanisms in the


[Link], May 15, 2018.

You might also like