DUMMYCHAIN — Tutorial-1

mankenavenkatesh
3 min readMay 7, 2019

--

To Understand what is DummyChain, Read below Article.

Create your first (very) basic ‘blockchain’.

Q. In a P2P network how to ensure the data shared between peers is not tampered?

Solution -

  • Chunk the data into blocks and link blocks with each other through hashes.
  • Each block will have hash of previous block.
  • So if a block is tampered, then all the consecutive blocks get impacted as the consecutive block hashes have to be changed.

Example

  • Let’s say some field inside block with block number 123 is modified, then the hash of block number 123 got changed.
  • Now Block number 124 has to be modified since the prevHash field(hash of block number 123) got changed.
  • Now Block Number 125 has to be modified since the prevHash field(hash of block number 124) got changed. From above solution, To modify one block, now peer has to modify all the consecutive blocks.

Implement a simple proof of work ( mining ) system.

Q. What is stopping peers to modify all the consecutive blocks?

Solution -

  1. Make the block generation computationally expensive through proof of work and only longest blockchain is accepted by the network.
  2. So that, the peer who is tampering a block has to spend lot of time to compute the consecutive blocks.
  3. In the mean time, new blocks will be generated by other peers who form the longest chain.

A tampered blockchain will not be able to catch up with a longer & valid chain. Unless they have computational power more than 50 percent of peers in the network.

Q. How does PROOF OF WORK work? why is it computationally expensive?

  1. In Proof of Work, in order for an actor to be elected as a leader and choose the next block to be added to the blockchain they have to find a solution to a particular mathematical problem.
  2. Let that mathematical problem be: Given data X, find a number n such as that the hash of n appended to X results is a number less than Y.
  3. Given that the hash function used is cryptographically secure, the only way to find a solution to that problem is by bruteforce (trying all possible combinations). In other words, probabilistically speaking, the actor who will solve the aforementioned problem first the majority of the time is the one who has access to the most computing power.

It has been widely successful primarily due to its following properties:

  1. It is hard to find a solution for that given problem.
  2. When given a solution to that problem it is easy to verify that it is correct.

Verifying blockchain

Q. How does other nodes verify the block?

Solution — For a block to be valid, the following criteria has to met

  1. The hash computed for the block should be correct.
  2. The previous Block hash should match.
  3. The proof of work should match the difficulty.

This is a simple version of blockchain explaining how blocks are linked with each other through block hash and process of mining blocks using proof of work.

To try it out, you can clone the source code from below link.

In next tutorial, let’s create DUMMYCOIN and we will learn how to add Transactions and maintain user balance of DUMMYCOIN.

--

--

mankenavenkatesh
mankenavenkatesh

Written by mankenavenkatesh

passionate software and blockchain developer

No responses yet