Storing Data on Blockchain

Though we are experiencing crypto winter at the moment, with major coins devalued more than 80% in 2018, the underlying blockchain technology is still exciting. The blockchain provides a democratized trust, distributed and validation protocol that has already disrupted banking and financial services and is on the verge of overhauling other industries like healthcare, supply chain, HR and more.

Despite the hype and its promising future, blockchain still has its shortcomings, the issue of data storage is one of them. The transactions based on the POW consensus for bitcoin, Ethereum, and other cryptocurrencies are extremely slow and therefore not suitable for storage of large data. For example, the deployment of dApp Cryptokitties nearly crippled the Ethereum network

The main problem of storing data on a blockchain is the limitation of the amount of data we can store because of its protocol and the high transaction costs. As a matter of fact, a block in blockchain can store data from a few kilobytes to maybe a few megabytes. For example, the block size of the Bitcoin is only 1Mb. The block size limitation has a serious impact on the scalability of most cryptocurrencies and the bitcoin community is debating whether to increase the block size.

Another issue is the high cost of the transactions. Why is storing data on the blockchain so expensive? It is because the data has to be stored by every full node on the blockchain network. When storing data on the blockchain, we do pay the base price for the transaction itself plus an amount per byte we want to store. If smart contracts are involved, we also pay for the execution time of the smart contract. This is why even storing kilobytes of data on the blockchain can cost you a fortune.

Therefore, it is not viable to store large data files like images and videos on the blockchain. Is there a possible solution to solve the storage issue? Yes, there are quite a few solutions but the most promising one is IPFS.

What is IPFS?

IPFS or Interplanetary File System is an innovative open source project created by the developers at Protocol Labs. It is a peer-to-peer filesharing system that aims to change the way information is distributed across a wide area network. IPFS has innovated some communication protocols and distributed systems and combine them to produce a unique file sharing system.

The current HTTP client-server protocol is location-based addressing which faces some serious drawbacks. First of all, location-based addressing consumes a huge amount of bandwidth, and thus costs us a lot of money and time. On top of that, HTTP downloads a file from a single server at a time, which can be slow if the file is big. In addition, it faces single-point of failure. If the web server is down or being hacked, you will encounter 404 Not Found error. Besides that, it also allows for powerful entities like the governments to block access to certain locations.

On the other hand, IPFS is a content-based addressing system. It is a decentralized way of storing files, similar to BitTorrent. In the IPFS network, every node stores a collection of hashed files. The user can refer to the files by their hashes. The process of storing a file on IPFS is by uploading the file to IPFS, store the file in the working directory, generate a hash for the file and his file will be available on the IPFS network. A user who wants to retrieve any of those files simply needs to call the hash of the file he or she wants. IPFS then search all the nodes in the network and deliver the file to the user when it is found.

IPFS will overcome the aforementioned HTTP weaknesses. As files are stored on the decentralized IPFS network, if a node is down, the files are still available on other nodes, therefore there is no single point of failure. Data transfer will be cheaper and faster as you can get the files from the nearest node. On top of that, it is almost impossible for the powerful entities to block access to the files as the network is decentralized.

The following figure shows the difference between the centralized client-server protocol(HTTP) and the peer-to-peer IPFS protocol.


 [Source: https://www.maxcdn.com/one/visual-glossary/interplanetary-file-system/]

Blockchain and IPFS

IPFS is the perfect match for the blockchain. As I have mentioned, the blockchain is inefficient in storing large amounts of data in a block because all the hashes need to be calculated and verified to preserve the integrity of the blockchain. Therefore, instead of storing data on the blockchain, we simply store the hash of the IPFS file. In this way, we only need to store a small amount of data that is required on the blockchain but get to enjoy the file storage and decentralized peer-to-peer properties of IPFS.

One of the real world use cases of blockchain and IPFS is Nebulis. It is a new project exploring the concept of a distributed DNS that supposedly never fails under a overwhelming access requests. Nebulis uses the Ethereum blockchain and the Interplanetary Filesystem (IPFS), a distributed alternative to HTTP, to register and resolve domain names. We shall see more integration of Blockchain and IPFS in the future.

References

Building the blockchain using JavaScript

The blockchain is a data structure that comprises blocks of data that are chained together using a cryptographic hash. In this article, we shall attempt to build a blockchain prototype using JavaScript. This is a bit technical for non-technical people but should be a piece of cake for computer nerds.

First of all, let’s examine the content of a block. A block consists mainly of the block header containing metadata and a list of transactions appended to the block header. The metadata includes the hash of the previous block, the hash of the block, timestamp, nonce, difficulty and block height. For more information, please refer to my earlier article Blockchain in a Nutshell.

Prior to writing the code, you need to install the following software:

  • Chocolatey
  • Visual Studio Code
  • node.js

The installations are based on Windows 10, but you can do the the same thing easily in Ubuntu. Chocolatey is a software management solution for Windows, Visual Studio Code is a streamlined code editor with support for development operations like debugging, task running and version control and Node.js is an open source server environment.

Let’s start writing the code using Visual Studio Code. The first line is

const SHA256 = require("crypto-js/sha256");

This code meas we are using the JavaScript library of crypto standards. We require the crypto-js library because the sha256 hash function is not available in JavaScript.The crypto module provides cryptographic functionality.

SHA-256 is a cryptographic hash algorithm. A cryptographic hash is a kind of ‘signature’ for a text or a data file. SHA-256 generates an unique 256-bit signature for a text.  SHA256 is always 256 bits long, equivalent to 32 bytes, or 64 bytes in an hexadecimal string format. In blockchain hash, we use hexadecimal string format, so it is 64 characters in length.

Next, we create the block using the following scripts:

class Block {
   constructor(index, timestamp, data, previousHash = '') {
       this.index = index;
       this.previousHash = previousHash;
       this.timestamp = timestamp;
       this.data = data;
       this.hash = this.calculateHash();
   }

The class Block comprises a constructor that initializes the properties of the block. Each block is given an index that tells us at what position the block sits on the chain. We also include a timestamp, some data to store in the block, the hash of the block and the hash of the previous block.

We also need to write a function calculateHash() that creates the hash, as follows:

 calculateHash() {
       return SHA256(this.index + this.previousHash + this.timestamp + JSON.stringify(this.data)).toString();
   }
}

Finally, we write the script that creates the blockchain, as follows:

class Blockchain{
   constructor() {
       this.chain = [this.createGenesisBlock()];
   }

   createGenesisBlock() {
       return new Block(0, "01/01/2017", "Genesis block", "0");
   }

   getLatestBlock() {
       return this.chain[this.chain.length - 1];
   }

   addBlock(newBlock) {
       newBlock.previousHash = this.getLatestBlock().hash;
       newBlock.hash = newBlock.calculateHash();
       this.chain.push(newBlock);
   }
   

Notice that the class blockchain comprises a constructor that consists of a few functions, createGenesisBlock(),  getLatestBlock() and  addBlock(newBlock).

Save the file as myblkchain.js or any name you like.

Now, execute the file in the VS terminal using the following command

node myblkchain.js

The output is as follows:

Let’ examine the output. Notice that each block comprises the properties index, previous hash, data and hash.

The index for the Genesis is always 0 . Notice that the hash of the genesis block and the previous hash of the second block are the same. It is the same for other blocks.

References

HR Blockchain Use Cases

Blockchain is not just about cryptocurrencies but it can be applied in businesses. In this article, we shall explore its application in human resource management. HR Blockchain use cases have started to emerge and have the potential to disrupt traditional HR systems. Among them are ChronoBank.io, PEACOUNTS,and bitWAGE 

Let’s examine each one of them.

ChronoBank.io

This is an HR blockchain platform designed to improve the recruitment process as well as payroll. It claimed that it will disrupt the HR industry similar to how Uber has disrupted the taxi industry.

ChronoBank ecosystem comprises a hiring platform(LaborX), a decentralized exchange(TimeX), a multi-signature wallet(Chronowallet) and a cryptocurrency that is pegged to labor hours(Labor Hour token).

LaborX is their flagship global hiring platform that connects candidates to the companies. It features an industry first immutable reputation system and a crypto payment system based on smart contract. The reputation system allows faster screening of candidates therefore save time and cost in hiring the right candidates. In addition, the crypto payment system enables candidates to get paid on time.

Furthermore, it plans to use a stable coin as the crypto payment to eliminate volatility common in most cryptocurrencies. This coin is known as Labour-Hour tokens. These tokens are linked to average hourly wages in the host country and are backed by a real labor force from big recruitment and labor-hire companies. Labor is considered a tradeable resource so ChronoBank will tokenise this resource into the LH-Tokens.

PeaCounts

PeaCounts is a blockchain-based payroll system. PeaCounts claimed that their payroll system will revolutionize the way employees are paid by using blockchain to remove the trust-based elements of the payroll process. It ensures the employees will get paid as soon as the work is completed. On the other hand, the employer will pay just for the work completed.

It features a smart contract that can track an employee location and time spent on certain tasks. It also holds the PEA Tokens and release them to the employee upon completion of the tasks. This system ensures that the employee gets paid efficiently and fairly.

The PeaCount payroll system is a private blockchain created as a fork off the Bitcoin. It also implements the zk-Snarks protocol and a multi-access wallet to ensure security in payroll transactions.

bitWage

bitWage is a payroll and HR services platform designed for the digital age. Basically it is a global outsourcing platform that serves the freelancers who wish to seek jobs worldwide and employers who wish to hire remote workers .

The bitWage payroll system allows employers to pay their remote employees rapidly with low transactions. The employees have the option to receive their wages and salaries in any of twenty four fiat currencies, four cryptocurrencies , and four precious metals.

References

HR Digital Transformation-powered by Blockchain

Human resource management has undergone tremendous changes in recent years particularly with regards to digitalization of human resource.  The emergence of blockchain technology could further transform the world of HR. 

According to Griffiths(cited in Gale, 2018), blockchain has the potential to streamline a lot of inefficient work related to employee data verification. Blockchain can store a candidate education, certifications and work history in a single ledger, therefore it would take just minutes rather than days to verify the data. Besides that,  the data cannot be modified or hacked once they are stored in the blockchain, thus guarantee data security and trustworthiness.

In addition, blockchain has the potential impact on HR by allowing personal data to be owned by the individual rather than the organization(Mike, cited in Gale 2018).  Consequently, every employee could maintain control over their entire employment data,  including educational background, training, and work history. It also means that an individual work identity is more portable, it moves with the individual rather than stuck inside the former organization when an employee changes job.  

Besides that, blockchain could disrupt conventional HR processes with respect to financial transactions.  Blockchain could streamline payroll function significantly by allowing automated and direct payment based on smart contarcts,  without the need of a  third party such as a bank or other intermediaries. 

Recently,  PWC (2018)has identified a few areas where we can apply the blockchain technology in HR. The areas include talent sourcing and management, targeting productivity gains, cross-border payment and mobility and Fraud prevention, and cybersecurity and data protection.

Talent sourcing and management

Blockchain could have a major impact on talent sourcing and management. It allows employees to maintain and control access to a comprehensive, trustworthy blockchain-based record of their education, skills, training and workplace performance. By providing potential employers with access to their blockchain-based employment data,  companies would be able to match individuals to roles much more accurately and effectively.

Targeting productivity gains

Blockchain has the ability to better match people’s skills and performance to jobs.  Finding and recruiting the right talent is always problematic for business organizations, therefore by helping them do this more effectively and efficiently will surely boost their productivity. Besides that, blockchain can help to reduce the burden of data-intensive processes like payroll and VAT ,  allowing companies to focus more on  their core businesses.

Cross-border payments and mobility

Multinational companies could create their own blockchain-based corporate cryptocurrencies that they can use for cross-border payment across their global supply chains, without the need of third-parties for settlement and reconciliation. In the future, central banks may legalize this type of cryptocurrency and support convertibility into fiat currencies. In addition, blockchain could facilitate employees mobility across the border with respect to payroll adjustment, international expenses, and taxes.

Fraud prevention, cybersecurity and data protection

HR department usually needs to handle high-volume financial transactions and sensitive personal data,  therefore it is utmost important to prevent frauds as well as to safeguard the data. This is the area where blockchain could be extremely useful. Blockchain’s use of consensus to authenticate data can help to eliminate frauds.

Another issue that blockchain can help to overcome is cyber threats. Many SMEs are ill-prepared for cyber attacks and the results could be detrimental to their businesses. Blockchain could help ensure cybersecurity as the data are immutable and tamper-proof because it uses SHA-256 hashing cryptography.  

References

Plasma-The Solution for Security and Scalability

The Scalability Issue

Blockchain always faces the trade-off issue between security and scalability. Though their PoW consensus protocol guarantees near perfect security, it also slows down the processing speed significantly.  Currently, the Ethereum processing speed is 15 transactions per second while Bitcoin is 7 transactions per second. Both platform’s processing capacities are nowhere near Visa’s processing speed of 45,000 transactions per second. Furthermore, the increase in the number of dapps deployed on the main Ethereum main chain has caused congestion and slows down transactions tremendously. One of the most famous cases is Cryptokitties, it clogged up the Ethereum network in just a few weeks of deployment due to its unprecedented popularity.

In seeking a viable solution to the scalability issue, Vitalik Buterin and Joseph Poon have joined hands in conceptualizing and developing Plasma, a framework that can scale Ethereum processing power.  Joseph is also the co-founder of the Lightning network, a framework that has greatly increase Bitcoin processing speed. Both plasma and Lightning network are trustless multilayered blockchain networks.

Plasma

Plasma is a  system that comprises the main blockchain and the ‘child blockchains’ that branch out from the main blockchain(aka parent blockchain or root blockchain). The child blockchains can co-exist but function independently from the parent chain and each other. 

The Plasma system allows anyone to create their own child blockchains a.k.a plasma chains with their own smart contracts. Therefore, the Plasma system enables the creation of all kinds of use cases based on different business logic in their smart contracts. To ensure security, the root chain monitor and enforces the state in all the plasma chains and penalize the bad actors if there is proof of frauds.  In this way, the Plasma system makes off-chain transactions possible while relying on the Ethereum main blockchain to maintain its security. 

The Plasma Structure

Actually, the Plasma architecture is like a tree structure with the main Ethereum blockchain as the root. The child blockchains then branch out from the root blockchain, similar to branches grown out from the root of a tree. Every child chain, in turn, can spawn new child chains, the process can go on.  Therefore, the plasma structure constitute a hierarchy of blockchains,  as shown below:

Plasma Blockchain Structure

How does Plasma Works?

Plasma can greatly increase processing speed and throughput on the Ethereum blockchain because it allows off-chain transactions, similar to the payment channels of the Lightning network and other off-chain technologies. All the off-chain techniques take operations away from the main Ethereum blockchain.

State Channels

The concept of Plasma was derived from State Channels but improved on the latter. State channel works by creating an off-chain communication channel (a.k.a state channel )where transactions are not sent to the smart contract on the main chain, instead, they are sent through the Internet without touching the main blockchain.  It is only after all the transactions have been completed (for example, a crypto game has finished) that the final state is sent to the smart contract on the main chain, closing the channel in the process. The smart contract will check the legitimacy of the transactions and release the asset (such as some ETH or a prize) to the recipient. 

The state channel technique can improve scalability because it can reduce the number of transactions on the main blockchain. For example, a crypto chess game played between two players may involve hundreds of moves, which means hundreds of transactions will be executed on the Ethereum blockchain. However, if we use the state channel, we need to execute only 3 transactions that include registration of the players to initiate the game, submission of the final state to the blockchain and closing the channel. 

Steps in Implementing Plasma

Plasma works in a similar way but with a different approach. Instead of creating the channels, it creates the child blockchains, as illustrated earlier. Smart contracts are created on the main Ethereum blockchain(The root chain) and they  define the rules in the child blockchains. In other words, the smart contract serves as the root of the child blockchains. The child blockchains can employ their own consensus algorithm, such as proof of stake.  The blocks validator will submit the state of the child chain to the Root Chain smart contract periodically. The smart contract will register the state of each Child Chain in the form of block hashes of the Child Chain.

We can illustrate how Plasma works by examining a crypto game such as crytant crab or cryptokitties. The smart contract on the main chain will set the rules of the game, then deploy the actual game application smart contracts on the child-chain, which contains all of the game logic and rules.  The game assets such as characters or collectibles are created on the Ethereum main chain and then transferred onto the child-chain using the plasma root.  When the players play the games, all the executions are confined to the child chain, without interacting with the root chain. 

Plasma Exits

Plasma Exits is a  security mechanism behind Plasma that allows users in a Plasma Chain to stop participating in the chain, and move their funds or assets back to the root chain. When a user wishes to exit a particular child chain, he or she needs to submit an exit application.  The application is not immediately approved because a proof is required. This waiting period is called the challenge period, which means anyone can challenge the user’s claim by submitting a fraud proof. If the challenge is not valid or there is no challenge, the application will be approved and the user can exit and collect back his assets or funds.

Plasma is still evolving and now the Plasma team has come out with the improved version of Plasma known as Plasma cash.  We shall discuss this new version in coming articles.

References