The Byzantine Fault Tolerance

Reading Time: 5 minutes

This short-article focusses on one of the most popular consensus problems in distributed computing known as “Byzantine’s General Problem” and when a distributed system is said to be Byzantine Fault Tolerant.
Various Byzantine Fault Tolerant algorithms are being used in Permissioned Blockchain Networks e.g Hyperledger Sawtooth is using Practical Byzantine Fault Tolerant(PBFT) to achieve consensus. So, if you want to understand how the consensus is actually achieved in such systems. This article is surely for you.

So let’s begin this journey.

First of let’s focus on the term ‘Byzantine Fault Tolerant’ and when a distributed system is said to be Byzantine Fault Tolerant?
The answer lies within the different types of failures that can occur in a distributed system-

1.Crash-Fail: In this type of failure, the component stop working without any warning. So you need to restart the node or replace it. We can say it is a ‘Fail-Stop’ failure.

2.Omission Failure: In this, component transmits a message but that message is not received by other nodes or we can say it is omitted.

3.Byzantine Failures: It is a ‘no-stop failure’.It occurs when there is a malicious or traitor node in the network which sends conflicting messages or block the messages by not sending them to the other nodes in the network, which may lead to faulty results.

Now I think it is self-explanatory that a distributed system is said to be Byzantine Fault Tolerant if it can cope-up with the Byzantine Failures.

The applications of BFT can be found in various domain like Blockchain and even in Boeing 777 and 787 flight controls.

Let’s move on to a specific problem which forms a base for understanding BFT-

The Byzantine General’s Problem :

Situation: Suppose there are several generals and they have to attack army camp C and they are surrounding the army camp such that they can’t communicate with each other directly. The only way communication can happen in between them is through a carrier and he needs to pass the enemy camp for transferring every message.
So they need proper protocols to reach a final decision whether to “attack ” on C, the next morning or “retreat”.
If they all agree to attack, and they do attack then they will surely win or if they agree to “retreat” then they can fight on another day. But if one of the general attack and other decides to retreat then they are surely gonna lose.

Problems:

  • Malicious Generals create variation in the decision to the others
  • Message Carriers may not reach
  • Reach a single solution, considering the downsides of a few Generals

Keeping in mind the situation, let’s discuss this problem with three generals.

Three Generals Problem:

Suppose, there are one commander and two lieutenants surrounding the army camp C and they have to collectively reach a decision to ‘attack’ or ‘retreat’.

If neither of the generals is faulty then all will work good and they will surely reach a decision.

The Byzantine Fault Tolerance

 Let’s see the case if one of the generals starts behaving maliciously:

The Byzantine Fault Tolerance

Let’s break up the whole communication process in two phases.

Phase-1: Commander sends the messages correctly to lieutenants.

Phase-2: Lieutenant-1 correctly forwards the message to Lieutenant-2.
As Lieutenant-2 is malicious, so he forwards the message to Lieutenant-1 incorrectly.

Clearly, Lieutenant-1 is receiving differing messages.

Let’s take a look at another possibility before jumping onto the conclusion.

What will be the case if ‘Commander’ is faulty?

The Byzantine Fault Tolerance

Phase-1: Lieutenant-1 and Lieutenant-2 recieves different messages.

Phase-2: They both exchange the messages correctly as they are loyal.

As per the protocols, both Lieutenants have to follow the Commander’s message. This is in the contradiction of the agreement condition.

Conclusion: There is no solution possible for ‘Three Generals Problem’ if one of the generals is faulty.

Four Generals Problem

Suppose, there are one commander and three lieutenants surrounding the army camp C and they have to collectively reach a decision to ‘attack’ or ‘retreat’.

When one of the Lieutenant is faulty?

The Byzantine Fault Tolerance

Phase-1: Commander correctly sends the message to other lieutenants.

Phase-2: Lieutenant-1 & Lieutenant-3 correctly forwards the message to others.
Lieutenant-2 behaves in a byzantine manner and incorrectly transmits the message.

By Majority Voting, the non-malicious lieutenants can reach the decision.

Decision of Lieutenant-1:
Majority(Retreat,Attack,Retreat)=Retreat

Decision of Lieutenant-2:
Majority(Retreat,Retreat,Attack)= Retreat

So, they have reached the consensus i.e “To Retreat”.

When the Commander is faulty?

The Byzantine Fault Tolerance

I think you can deduce what will happen in the two phases now.
Jumping directly to the decisions:-

Decision of Lieutenant-1:
Majority(Retreat,Attack,Retreat)=Retreat

Decision of Lieutenant-2:
Majority(Attack,Retreat,Retreat)= Retreat

Decision of Lieutenant-3:
Majority(Retreat,Retreat,Attack)=Retreat

So, the consensus has been achieved with the decision “To Retreat”.

One more special thing to observe here is that the final agreement will be the one which is in the majority of the decisions in Phase-1 e.g Retreat is in majority in Phase-1. So final agreement is on “Retreat‘’.

Conclusion: If out of 4 generals, only one is faulty or behaving in a byzantine way, then we can reach the agreement and consensus is achieved.

By the above two scenarios, we can now generalise the Byzantine Model of Distributed Systems.

Generalization

A System having ‘f’ number of faulty nodes(generals) should have at least, in total 3f+1 nodes(generals) in the network to reach the consensus.

Thanks for showing patience and reading until the end.

Next in the series is ‘PBFT & RBFT Consensus’ and ‘Consensus in Public Blockchain Networks’.

References:
https://people.eecs.berkeley.edu/~luca/cs174/byzantine.pdf

Blockchain-The Internet’s New Magnum Opus

Reading Time: 9 minutes

The workshop was intended to excite and inspire some of the minds to set into brain-storming that might help the audience to come up with innovation with 21 st century internet Magnus, BLOCKCHAIN, to solve the real-world problems.

The prerequisite was null and void but an audience with a little bit of patience and curiosity, which certainly the audience was!

The workshop was segmented into two halves. It started with non-technical points to get launched into the topic and later shifted to tech-based. Key points of the talk were:

  1. Intuitive questions like why blockchain, what are the daily life problems that are needed to be addressed through blockchains, how blockchains can solve the crisis of current internet like data tampering and data breaching was answered to create the vacuum in audience minds for the talk.
  2. The talk then moved to introduce the audience with basic key terminologies like cryptography, hashing, mining, genesis block, ledger, nodes, consensus, etc.
  3. Very carefully the backbones of the blockchain were introduced. The network design concept that gives this technology the key power were: a) Distributed system and b) Decentralized systems. How the Blockchain provides architectural and political decentralization and logical centralization was deeply discussed.
  4. All of these gives the blockchain major characteristic system advantages of attack and collusion resistance, fault tolerance, good scalability, etc.
  5. Finally, the real world application of the blockchain was explained and vividly demonstrated. The successful digital currency of Bitcoin, how it solved the major two unsolved problems of its time- malicious activity prevention and the double spending, how it works and some of its basic underlining stories were discussed.
  6. The workshop ended with the display of a few of the projects that instructors made to participate in various hackathons.

Here is the ppt used in the actual workshop. All the references and important links would be uploaded soon, stay tuned!!!!

PPT

Many thanks to the speakers and the CEV Members, Aman Pandey, Hrishabh Sharma and Ujjwal Kumar.

– TEAM CEV

Resources

What is the Ethereum Developer Portal?

It’s a place to get started and find the tools you need to develop and build applications on Ethereum.

Table of Contents

 


Are You a New Developer to the Ethereum Ecosystem?

Below is a mix of the main infrastructure tools and knowledge centres that will teach you how to build software on Ethereum. We recommend taking a look through the portal and reading about all the developer tools and options before getting started.



infura

Infura

A scalable, standards-based, globally distributed cluster and API endpoint for Ethereum, IPFS, and other infrastructures.

truffle

Truffle

A development environment, testing framework, and asset pipeline for blockchains using the Ethereum Virtual Machine (EVM).


consensys-logo

ConsenSys Academy

Academy provides an end-to-end Ethereum developer course that is self-paced and open year-round.  Sign up now!




kauri

Kauri

Learn to build on Ethereum by reading all the latest articles, tutorials, documentation and best practices.


ethhub.io Logo

EthHub

Crowdsourced resources for individuals seeking to learn, listen, or read about Ethereum.


metamask-png-transparent-logo

MetaMask

The most used chrome extension wallet and Web 3 provider that allows users to interact with decentralized applications.

Smart Contract Languages

If you’re developing on Ethereum, you’re going to need to know how to write smart contracts. Luckily there are not too many different languages that you need to know. Solidity the main smart contract language is easier to learn if you already possess a good understanding of Javascript.





solidity

Solidity

An object-oriented, high-level language for implementing smart contracts.


ezgif.com-gif-maker

Vyper

A pythonic programming language for implementing smart contracts. Vyper is also currently beta software.

IDEs/Editors

IDE stands for Integrated Development Environment. IDEs and Editors are what you need to write and test software. They are software suites that consolidate basic tools that are required to start writing on Ethereum. Below are the most popular IDEs and Editors.





Atom_editor_logo

Atom 

An open source and usable text editor.


remix

Remix 

A suite of tools to interact with the Ethereum blockchain in order to debug transactions.


ETHEREUM-ICON_Black_small

Visual Studio Code

Visual Studio Code extension that adds support for Solidity.

 

 

Public Testnets

Public Testnets on Ethereum offer a way for developers to test what they build without putting their creations on the main Ethereum network. Developers are able to obtain as much ETH as you want on testnets because testnet ETH doesn’t carry any monetary value. Below are the most used testnets to start testing on and the links for where you can request testnet ETH.





Ropsten

Ropsten

A proof-of-work blockchain that most closely resembles Ethereum and allows you to easily mine faux-Ether.

Görli

Görli 

Proof-of-authority cross-client testnet, synching Parity Ethereum, Geth, Nethermind, Pantheon, and EthereumJS. This testnet is a community-based project, completely open-source.



kovan

Kovan

A proof-of-authority blockchain started by the Parity team. Test ether must be requested.


Rinkeby

Rinkeby 

A proof-of-authority blockchain started by the Geth team. Test ether must be requested.

 

Local Testnets

Similar to Public Testnets, Local Testnets are a place for you to test your software without pushing it public. Unlike Public Testnets, the Local Testnet software will only run on your computer/node and other users won’t be able to see it or interact with it.





G Truffle

Ganache 

Ganache is a personal blockchain for Ethereum development that developers can use to deploy contracts, develop applications, and run tests.


ganache-cli-128x128

Ganache CLI 

Fast Ethereum RPC client for testing and development. The command line version of Ganache, your personal blockchain for Ethereum development.



Front–End Interfaces

If you want to start developing dapps, you’ll need front-end development skills. Below are the most popular front-end interfaces that will help you turn your dapp from an idea to a live Ethereum mainnet application.





web3js

Web3.js 

An Ethereum JavaScript API which connects to the Generic JSON RPC specification. A local or remote Ethereum node must be run to use this library.


ethers(dot)js

 Ethers.js

Ethereum wallet implementation and utilities in JavaScript.


drizzle truffle

Drizzle

A collection of front-end libraries that make writing decentralized application  frontends easier and more predictable. Drizzle provides a Redux library to connect a frontend to a blockchain.



Backend Interfaces

If you want to graduate from just building dapps, you’ll need to start learning and using the backend interfaces listed below. If you’re interested in doing backend/protocol work on Ethereum, you should have significant experience with Go, Rust, Java, .NET, Ruby, or Python. Explore some of the most frequently used backend interfaces below.





python logo

Web3.py

A Python implementation of Web3.js.


Nethereum Logo-1

Nethereum

A .NET integration library for Ethereum allowing users to interact with Ethereum clients like Geth or Parity using RPC.


web3j logo

Web3j 

A lightweight Java and Android library for integration with Ethereum clients.


Smart Contract Library

You’ve probably used programming libraries before, and these are no different. A smart contract library is the reusable piece of code for a smart contract which is deployed once and shared many times. Below are the most used smart contract libraries.





open zepplin

OpenZeppelin

A library that provides implementations of standards like ERC20 and ERC721 as well as Solidity components to build custom contracts.


dapphub

Dappsys

A collection of building blocks for building smart contract systems written in Solidity.

Smart Contract Testing and Deployment

If you are creating a tool, product, or application on Ethereum, you’ll want to make sure your smart contract is in working order before deploying to the mainnet. These tools will help you build, test, and ship your code.





truffle

Truffle Suite

The most popular smart contract development, testing, and deployment framework. The Truffle suite includes Truffle, Ganache, and Drizzle. Read a deep dive on Truffle.


waffle-1

Waffle

Waffle is a library for writing and testing smart contracts. Waffle is based on ethers.js.


embark best

Embark

A framework that allows you to easily develop and deploy decentralized applications. Currently integrates with EVM blockchains (Ethereum), IPFS, Swarm, Whisper, and Orbit.



Ethereum Clients

An Ethereum client refers to any node that is able to parse and verify the blockchain, its smart contracts, and everything in between. An Ethereum client also provides interfaces to create transactions and mine blocks which is the key for any Ethereum transaction. Below are the most popular Ethereum clients.





pegasys logo-2

PegaSys Pantheon

Pantheon is an open-source Ethereum client developed under the Apache 2.0 license and written in Java.


parity

Parity

An Ethereum client developed by Parity Technologies using the Rust programming language.


gopher logo

Geth

A command line interface for running a full Ethereum node implemented in Go.



Storage

Ethereum allows you to save variables or data in permanent storage. The storage platforms below are where all of the smart contract data lives. IPFS is the most commonly used storage system on Ethereum. Explore the platforms below to learn more about how storage on Ethereum works.





IPFS

IPFS

InterPlanetary File System is a decentralized storage and file referencing system for Ethereum.


swarm logo

Swarm

A distributed storage platform and content distribution service for the Ethereum web3 stack.


Orbit

OrbitDB

A decentralized peer to peer database on top of IPFS.

Security Tools

Ok, so you’ve finally built your dapp or smart contract. But how do you know it was set up correctly and is safe from hackers? The security tools below will help ensure that your code is safe and follows all Ethereum development best practices.





mythx

MythX

A security analysis API for Ethereum smart contracts. MythX powers tools that bring security into the smart contract software development life cycle.


Oyente just logo

Oyente

An analysis tool for smart contracts. Oyente utilizes a symbolic execution tool that works directly with EVM byte code without access to the high level representation (e.g Solidity).


manticore

 Manticore

A command line interface that uses a symbolic execution tool on smart contracts and binaries.



**A special thanks to Consensys.net for all the resources.











Want More?

Plug into the decentralized future. Join our newsletter.

 

Join Now






Constructing a Simple Blockchain using PYTHON

Reading Time: 6 minutes

– by Aman Pandey

 

What does the path consist?

The goal of this article is to let you know about a BASIC BLOCKCHAIN structure by making a sample blockchain by using a Scripting language Python.

And a small assignment at the last.

The information about the following will be provided on the further articles:

    • various applications of blockchain and at various levels
    • use blockchain to create your own cryptocurrency
    • use of blockchain to create a file deployment system

and Many More…

This article will, for right now, will not have information about deploying your own Blockchain Application, and creating a distributed and decentralized file sharing system.

If you are just interested with how to create a blockchain Jump directly to CONSTRUCTING even I would have done that…

So, let’s start to learn something new……

What is Blockchain?

Back in 2008, some mysterious Person/group of persons named SATOSHI NAKAMOTO released a whitepaper  named Bitcoin: A Peer to Peer Electronics Cash System (I suggest that you read the paper to understand how it was presented to the world) in which BITCOIN was described to be a BLOCKCHAIN based technology,

    • a completely trustless (though the meaning is exactly the opposite, it actually means no trust issues)
    • Distributed
    • Decentralised
    • and, Encrypted

technology that can actually serve as a new form of currency which has its value just as a Stock Share and transaction just like a Barter system.

So, right now before turning this article into a History(story) or market revolutionalizing technology journey let’s start some keyboard ticking and see where we are able to implement key points of a Blockchain, though I will provide you enough resources to read more about emergence and have an intuitive idea about its potential.

Let’s get started…

Design and Features

So, let us begin with the basic design of blockchain by understanding how does it implement its key features.

Before explaining further I want you to go through this wonderful video about blockchain. So we shall jump directly to the technical part. It will let you understand most of the things.

Now after this you must have understood the basic structure of Blockchain.

It is a distributed and decentralized ledger system which provides a TAMPER free service to store records.

Constructing a Simple Blockchain using PYTHON

Image Source: https://i.stack.imgur.com/hDDzg.png

Constructing:

Constructing a Simple Blockchain using PYTHON

Prerequisites:

    • Python 3.6 (a basic python would work but if you don’t know any about it don’t worry it’s very simple and I will try to give an intuitive idea about what I am using and why.)
    • a cool text editor would work well
      > Sublime Text 3 (choose according to the platform you have, it’s lightweight and good)n
      > Atom (the best one to use, has an extension for a terminal)
    • LINUX (Suggested, It’s better to switch to Linux now if you really have to do some good)

                                                                                                                                                          ……that’s it for now, its basic

Let us start by creating a BLOCK:

-> BLOCK:-

We’ll start by creating a class of simple BLOCK using Python:

Constructing a Simple Blockchain using PYTHON

class block:
      def __init__ (self, timestamp, data, previousHash = ' '):
         self.timestamp = timestamp
         self.data = data
         self.previousHash = previousHash
         self.hash = #TODO function calculateHash()

Just have a look at this block we have 4 arguments. Of course, self is working for self-element initialization, for those who don’t understand just understand that it is a kind of PYTHON convention of constructors.

Also that we haven’t included hash in the block argument as it will be calculated and stored inside the function itself #TODO.

Now let’s write the function to calculate hash the block:

def calculateHash(self):
    return sha256((str(self.timestamp) + str(self.data) + \
                str(self.previousHash).encode()).hexdigest())

Now, few points to note here are

    • use of encode() and in the return line hexdigest()
      → so the answer for that is you need to encode every text before hashing, I’ll try to cover it in further blogs.
      → and to convert hash object into a string  we need to use the hexdigest function
    • and yes, for sha256 you need to import hashlib library, and also you need to convert everything into a string before hashing it
  • Also, we need to include time for timestamp

So the code for blocks looks like: –

from hashlib import sha256
import time
class block:
      def __init__ (self, timestamp, data, previousHash = ' '):
         self.timestamp = timestamp
         self.data = data
         self.previousHash = previousHash
         self.hash = # TODO
      def calculateHash(self):
         return sha256((str(self.timestamp) + str(self.data) + \ str(self.previousHash).encode()).hexdigest())

and now let’s begin with our Blockchain class definition:

-> BLOCKCHAIN:-

Genesis Block: the very first block of the blockchain is termed as a genesis block. And it generally can have any data. So we need to initialize our blockchain with it if we don’t have any block in the BLOCKCHAIN. We will have the following structure:

Data → “genesisBlock”

previousHash → “00000”

class blockchain:
      def __init__(self):
         self.chain = [self.createGenesis()]
      def createGenesis(self):
         return block(time.ctime(), "genesisBlock", "00000")

So this is our blockchain which gets initialized with a list named chain, everytime a new class object is created. We’re still having some functions to add to it.

-> MINING:-

Whenever a new transaction is made, and a new block is created and added to the blockchain, the complete process is termed as mining.

As to make blockchain simple for this very first blog, I am not going to put any complex mining functions and verification algorithms for now. Just deal with simple mining.

So, the mining functions will be having to take input from the user and create a block/node for it.

So, before making mining, we have to deal with taking the user’s input and start mining:

  • Starting a Blockchain
  • CEVcoin = blockchain()
  • Taking user input and creating a block
  • data = input()
  • Writing mineBlock():

This function is the part of the blockchain so has to be written inside blockchain. Hence our code  with the function of adding nodes looks like:

from hashlib import sha256
import time
class block:
  def __init__ (self, timestamp, data, previousHash = ' '):
    self.timestamp = timestamp
    self.data = data
    self.previousHash = previousHash
    self.hash = self.calculateHash()
  def calculateHash(self):
    return sha256((str(self.timestamp) + str(self.data) + str(self.previousHash).encode()).hexdigest())
class blockchain:
  def __init__(self):
    self.chain = [self.createGenesis()]
  def createGenesis(self):
    return block(time.ctime(), "genesisBlock", "00000")
  def mineBlock(self, data):
    node = block(time.ctime(), data, self.chain[-1].hash)
    # mining a new block to the blockchain
    self.chain.append(node)
CEVcoin = blockchain()
data = input()
# sending data to get mined
print(“\n\nMining new block……..”)
CEVcoin.mineBlock(data)

*do note down the self.calculateHash() application in def __init__ function of block

Well, this the BACKBONE of every BLOCKCHAIN.

Its applications are at many places. Bitcoin is one of them. Refer links at the bottom for them.

One last thing I’ll do is to print the Blockchain we just made:

def printBlockchain(self):
    for i in range(len(self.chain)):
      print("\n-----Block ", i ,"---------\n timestamp = "\
            , self.chain[i].timestamp,"\n data = ", \
             self.chain[i].data, "\n previousHash = ",\
               self.chain[i].previousHash,"\n hash = ", \
                  self.chain[i].hash)

Just add it inside the class blockchain().

And here, you are done with your first blockchain cryptocurrency

For complete CODE refer : https://github.com/johnsoncarl/Blog-CEVcoin

*i’ll add more blogs with its applications like

  • Making a ledger system
  • Making your own cryptocurrency
  • Regarding P2P network based blockchain

**Please do like & share this blog if you really like it. And comment if any doubts.

Blog by:

Aman Pandey

2nd Year, Civil Engineering, SVNIT.

You can also have a look at my team Project with Ujjwal Kumar – LinkedIn & Hrishabh Sharma – LinkedIn, another CEV members @ Rajasthan DIGIFEST 2k18 Online hackathon – a 36 hours hackathon held on 6 July 2018 on making a cryptocurrency RAJCOIN for Rajasthan Govt @ the following Github link.

https://github.com/Sharma-Hrishabh/digifest2k18

You need to follow the complete instructions given in readme. SO, KEEP PATIENCE.

Extra Resources to read:

Assignment:

Now the assignment is that, make your own crypto coin and mail the code as a zip file to my email id [email protected].

**you can ask any doubts regarding this @ the email address provided above.

Please give a thumbs up and share if you really like the blog.

NOTE: this is only for Educational purposes and not for commercialization.

Cheers…

CEV - Handout