De­mys­ti­fy­ing Blockchains

A blockchain is a con­tin­u­ously grow­ing list of records, called blocks, which are linked and se­cured us­ing cryp­tog­ra­phy to en­sure data se­cu­rity.

OpenSource For You - - Contents - By: Ab­hi­nav Nath Gupta The au­thor is a soft­ware de­vel­op­ment en­gi­neer at Cleo Soft­ware In­dia Pvt Ltd, Bengaluru. He is in­ter­ested in cryp­tog­ra­phy, data se­cu­rity, cryp­tocur­rency and cloud com­put­ing. He can be reached at

Data se­cu­rity is of para­mount im­por­tance to corporations. En­ter­prises need to es­tab­lish high lev­els of trust and of­fer guar­an­tees on the se­cu­rity of the data be­ing shared with them while in­ter­act­ing with other en­ter­prises. The ma­jor con­cern of any en­ter­prise about data se­cu­rity is data integrity. What many in the en­ter­prise do­main worry about is, “Is my data ac­cu­rate?”

Data integrity en­sures that the data is ac­cu­rate, un­tam­pered with and con­sis­tent across the life cy­cle of any trans­ac­tion. En­ter­prises share data like in­voices, or­ders, etc. The integrity of this data is the pil­lar on which their busi­nesses are built.


A blockchain is a dis­trib­uted pub­lic ledger of trans­ac­tions that no per­son or com­pany owns or con­trols. In­stead, ev­ery user can ac­cess the en­tire blockchain, and ev­ery trans­ac­tion from any ac­count to any other ac­count, as it is recorded in a se­cure and ver­i­fi­able form us­ing al­go­rithms of cryp­tog­ra­phy. In short, a blockchain en­sures data integrity.

A blockchain pro­vides data integrity due to its unique and sig­nif­i­cant fea­tures. Some of these are listed be­low.

Time­less val­i­da­tion for a trans­ac­tion: Each trans­ac­tion in a blockchain has a sig­na­ture digest at­tached to it which de­pends on all the previous trans­ac­tions, with­out the ex­pi­ra­tion date. Due to this, each trans­ac­tion can be val­i­dated at any point in time by any­one with­out the risk of the data be­ing al­tered or tam­pered with.

Highly scal­able and por­ta­ble: A blockchain is a de­cen­tralised ledger dis­trib­uted across the globe, and it en­sures very high avail­abil­ity and re­silience against dis­as­ter.

Tam­per-proof: A blockchain uses asym­met­ric or el­lip­tic curve cryp­tog­ra­phy un­der the hood. Be­sides, each trans­ac­tion gets added to the blockchain only af­ter val­i­da­tion, and each trans­ac­tion also de­pends on the previous trans­ac­tion. Hence, a blockchain is nearly im­pos­si­ble to tam­per with with­out any­one notic­ing.

De­mys­ti­fy­ing blockchains

A blockchain, in it­self, is a dis­trib­uted ledger and an in­ter­con­nected chain of in­di­vid­ual blocks of data, where each block can be a trans­ac­tion, or a group of trans­ac­tions.

In or­der to ex­plain the con­cepts of the blockchain, let’s look at a code ex­am­ple in JavaScript. The link to the GitHub repos­i­tory can be found at­hiit89/Ang Coins. So do check the GitHub repo and go through the ‘README’ as it con­tains the instructions on how to run the code lo­cally.

Block: A block in a blockchain is a com­bi­na­tion of the trans­ac­tion data along with the hash of the previous block. For ex­am­ple:

The def­i­ni­tion of the block, in­side a blockchain, is pre­sented in the above ex­am­ple. It con­sists of the data (which in­cludes blockId, dateTimeS­tamp, trans­ac­tionData, pre­vi­ousTrans­ac­tionHash, nonce), the hash of the data (cur­ren­tTrans­ac­tionHash) and the hash of the previous trans­ac­tion data.

Ge­n­e­sis block: A ge­n­e­sis block is the first block to be cre­ated at the be­gin­ning of the blockchain. For ex­am­ple:

new Block(0, new Date().getTime().val­ueOf(), ‘First Block’, ‘0’);

Adding a block to the blockchain

In or­der to add blocks or trans­ac­tions to the blockchain, we have to create a new block with a set of trans­ac­tions, and add it to the blockchain as ex­plained in the code ex­am­ple be­low:

ad­dNewTrans­ac­tionBlock­ToTrans­ac­tionChain(cur­ren­tBlock) { cur­ren­tBlock.pre­vi­ousTrans­ac­tionHash = this.

In the above code ex­am­ple, we cal­cu­late the hash of the previous trans­ac­tion and the hash of the cur­rent trans­ac­tion be­fore push­ing the new block to the blockchain. We also val­i­date the new block be­fore adding it to the blockchain us­ing the method de­scribed be­low.

Val­i­dat­ing the blockchain

Each block needs to be val­i­dated be­fore it gets added to the blockchain. The val­i­da­tion we used in our im­ple­men­ta­tion is de­scribed be­low:

In this im­ple­men­ta­tion, there are a lot of fea­tures miss­ing as of now, like val­i­da­tion of the funds, the roll­back fea­ture in case the newly added block cor­rupts the blockchain, etc. If any­one is in­ter­ested in tack­ling fund val­i­da­tion, the roll­back or any other is­sue they find, please go to my GitHub repos­i­tory, create an is­sue and the fix for it, and send me a pull re­quest or just fork the repos­i­tory and use it which­ever way this code suits your re­quire­ments.

A point to be noted here is that in this im­ple­men­ta­tion, there are nu­mer­ous ways to tam­per with the blockchain. One way is to tam­per with the data alone. The im­ple­men­ta­tion for that is done in the branch­hiit89/ AngCoins/tree/tam­per­ing_­data.

An­other way is to not only change the data but also up­date the hash. Even then the cur­rent im­ple­men­ta­tion can in­val­i­date it. The code for it is avail­able in the branch­hiit89/AngCoins/tree/tam­per­ing_­data_ with­_up­dat­ed_hash.

Proof of work

With the cur­rent im­ple­men­ta­tion, it is still pos­si­ble that some­one can spam the blockchain by chang­ing the data in one block and up­dat­ing the hash in all the fol­low­ing blocks in the blockchain. In or­der to pre­vent that, the con­cept of the ‘proof of work’ sug­gests a dif­fi­culty or con­di­tion that each block that is gen­er­ated has to meet be­fore get­ting added to the blockchain. This dif­fi­culty pre­vents very fre­quent gen­er­a­tion of the block, as the hash­ing al­go­rithm used to gen­er­ate the block is not un­der the con­trol of the per­son cre­at­ing the block. In this way, it be­comes a game of hit and miss to try to gen­er­ate the block that meets the re­quired con­di­tions.

For our im­ple­men­ta­tion, we have set the dif­fi­cult task that each block gen­er­ated must have two ‘00’ in the be­gin­ning of the hash, in or­der to be added to the blockchain. For ex­am­ple, we can mod­ify the func­tion to add a new block to in­clude the dif­fi­cult task, given as be­low:

The com­plete code for this im­ple­men­ta­tion can be seen in the branch­hiit89/AngCoins/tree/ block­_chain_min­ing.

Blockchain providers

Blockchain tech­nol­ogy, with its un­prece­dented way of man­ag­ing trust and data and of ex­e­cut­ing pro­ce­dures, can transform busi­nesses. Here are some open source blockchain plat­forms.

Hyper­Ledger: Hyper­ledger nur­tures and en­dorses a wide ar­ray of busi­nesses around blockchain tech­nolo­gies, in­clud­ing dis­trib­uted ledgers, smart con­tracts, etc. Hyper­ledger en­cour­ages the re-use of common build­ing blocks and en­ables the speedy in­ven­tion of dis­trib­uted ledger tech­nol­ogy com­po­nents.

Pro­ject link: https://hyper­

Pro­ject GitHub link:­ledger Open­chain: Open­chain is an open source dis­trib­uted ledger tech­nol­ogy. It is ideal for en­ter­prises, and deals in is­su­ing and man­ag­ing dig­i­tal assets in a ro­bust, se­cure and scal­able way. Pro­ject link:­

Ethereum pro­ject: This is a dis­trib­uted frame­work that runs smart con­tracts—ap­pli­ca­tions that run ex­actly as pro­grammed in a se­cured virtual en­vi­ron­ment with­out down­time or the pos­si­bil­ity of tam­per­ing, as this platform lever­ages the cus­tom built blockchain.

Pro­ject link:

There are some more blockchain projects, links to which can be found in the Ref­er­ences sec­tion.

Newspapers in English

Newspapers from India

© PressReader. All rights reserved.