Blockchain Ecosystem

In this Article, We will Cover these topics:- 

  • Merkle Tree & Hashing
  • Blocks wallets & Addresses
  • Cryptography & Cryptographic Algorithms
  • Public & Private key

Merkle Tree:

  • A Merkle tree is a data structure that uses hashing to store and verify the data.
  • In the Merkle tree, each root node contains the hash value of a data block, and non-leaf nodes contain the hash of the child nodes.
  • Merkle trees are used for effective data validation in distributed systems.
  • In a blockchain, each leaf node is the hash of a transaction in the block, and each non-leaf node is a hash of its children.
  • Merkle trees are secure because of hashing. If any data is changed, the Merkle tree structure becomes incorrect.
  • Merkle trees are small in size, making it much easier to maintain and verify the data in the tree.

Merkle Tree in Blockchain:

  • Merkle trees are used at the base layer of the blockchains to store and verify transaction data.
  • Merkle trees provide data security and integrity by using hash functions.
  • In the case of blockchains, without Merkle trees, the blockchain will become very hard to manage and use.
  • The node would need to compare each entry line by line.
  • Any discrepancy between the ledgers compromises the security of the network.
  • Every verification request would require large packets of information to be sent over the network.
  • A lot of processing power is consumed to compare the ledgers to ensure that there have been no changes.

The above example is the most common and simple form of a Merkle tree, i.e., Binary Merkle Tree. There are four transactions in a block: TX1TX2TX3, and TX4. Here you can see, there is a top hash which is the hash of the entire tree, known as the Root Hash, or the Merkle Root. Each of these is repeatedly hashed, and stored in each leaf node, resulting in Hash 0, 1, 2, and 3. Consecutive pairs of leaf nodes are then summarized in a parent node by hashing Hash0 and Hash1, resulting in Hash01, and separately hashing Hash2 and Hash3, resulting in Hash23. The two hashes (Hash01 and Hash23) are then hashed again to produce the Root Hash or the Merkle Root.

Merkle Root is stored in the block header. The block header is part of the Bitcoin block which gets hash in the process of mining. It contains the hash of the last block, a Nonce, and the Root Hash of all the transactions in the current block in a Merkle Tree. So having the Merkle root in the block header makes the transaction tamper-proof. As this Root Hash includes the hashes of all the transactions within the block, these transactions may result in saving disk space.

Hashing:

  • Hashing is the process of having an input item of any length converted into an output item of a fixed length.
  • Transactions of different lengths are run through a given hashing algorithm, and all give an output of a fixed length, called a hash.
  • The hash size will depend on the hash function used, but the output using a particular hashing algorithm will be of a specific size.
  • Cryptographic hash functions are one of the most important techniques in the field of cryptography and are used to accomplish many safety goals such as authentication, digital signatures, generation of pseudo numbers, digital steganography, digital time-stamping, etc.
  • Bitcoin uses a cryptographic hashing algorithm- Secure Hashing Algorithm 256, often known as SHA-256.

The hash algorithm has certain unique properties:

  1. It produces a unique output (or hash).
  2. It is a one-way function.

In the context of cryptocurrencies like Bitcoin, the blockchain uses this cryptographic hash function’s properties in its consensus mechanism. A cryptographic hash is a digest or digital fingerprint of a certain amount of data. In cryptographic hash functions, the transactions are taken as input and run through a hashing algorithm which gives an output of a fixed size.

Blocks wallets & Addresses:

Blocks

    • A block is the fundamental unit of a Blockchain
    • Every block contains a hash of all the previous blocks.
    • Blocks use merkle tree to store the hash of all the transactions to create the hash of block.

A block is divided into:

      • Block header
      • Block body

Block header is divided into six components:

      • Version number
      • Previous block hash
      • Merkle tree root hash
      • nbits
      • Nonce
      • Timestamp

Block body contains all the transactions

Block Overview

Wallet:

  • A Blockchain wallet is a software program that enables users to buy, sell, and monitor balance of their digital assets and record the transaction done using the wallet address.
  • A wallet stores private and public keys for a user. As the name suggests, public key is shared and works as the address while private key is kept private.
  • Public and private keys are used to encrypt and decrypt transaction so only the intended recipient can know the transaction data.
  • A Blockchain wallet offers all the features available for safe and secure transactions and exchanges of funds between various parties.

There are three types of cryptocurrency wallets :

  • Software Wallets:  like Metamask which runs on a machine.
  • Hardware Wallets:  are storage devices on which users can store their keys.
  • Paper Wallets: are just writing down your public and private key on a paper and keeping it someplace safe.

Software Wallet:

  • Desktop Wallet
    • Can be downloaded on a PC or a laptop
    • Desktop wallets are safe if your system is protected against virus attacks
  • Online Wallet
    • Run on cloud
    • You can access them from any device through a web browser
  • Mobile Wallet
    •  Available as a mobile app
    • Easier and fast funds transfer

Hardware Wallets:

  • Store private keys of users on a hardware device like USB or pendrive.
  • Are compatible with various web interfaces.
  • Are the safest wallet options available.

Paper Wallets:

  • Generally, work with software wallets for buying and selling of funds.
  • Currencies are transferred from software wallets to the public address on paper.

There are two types of wallet used in Blockchain:

  • Hot Wallet
  • Cold Wallet

Hot Wallet:

  • Are digital cryptocurrency wallets
  • Are online wallets through which it is easy to quickly transfer cryptocurrencies.
  • Private keys in the hot wallet are stored in the cloud for a quicker transfer.
  • Can be easily accessible 24/7 online and can be accessed from a laptop or mobile, but if compromised, there is a chance of unrecoverable theft.
  • Hot Wallet are free of charge.
  • Online wallet, Desktop wallet and Mobile wallet consider Hot Wallet
  • Examples: Coinbase and Blockchain.info

Cold Wallet:

  • Are physical devices that store cryptos inside of them.
  • Are offline digital wallets where the transfers are digitally signed and then electronically disclosed.
  • Private keys are kept in independent hardware that is not connected to internet or the cloud, but stored on paper document.
  • Transaction approach helps to shield the wallet from unauthorized entry.
  • Cold wallets are expensive in comparison to hot wallets.
  • Hardware wallet and Paper wallet consider Cold Wallet.
  • Examples: Trezor and Ledger

Address:

  • A Blockchain address is used to identify a user on blockchain network. It is a special sequence of numbers, letters, and functions.
  • It applies to a particular network destination where it is possible to transfer the cryptocurrency.
  • An address is a placeholder to accept and send blockchain transactions.
  • Pay-to-IP had been abandoned in Bitcoin. Pay-to-Public Key Hash became the new standard format for Bitcoin addresses.
  • Public keys are generally used to create an address for a user.
  •  The steps to create an address include:
    • Hashing of public key using SHA 256
    • Re-hashing using RIPEMD-160
    • Adding “00” prefix
    • Adding checksum bytes at the end
    • Encode the result with base58 encoding

NOTE:  Address is representation of a public key

If you paste an address in your bitcoin wallet, it scans the prefix and calculates the checksum.

It refuses the address if it doesn’t fit . It is difficult to transfer funds to an incorrect address because of a trying mistake

Cryptography & Cryptographic Algorithms:

  • Cryptography is a technique to secure data using computer software.
  • It works such that users can encrypt and decrypt the transaction so that the data is not leaked to third party.
  • It is derived from mathematical concepts and a set of rule-based calculations.
  • Cryptographic Algorithms usually involves three things:
    • Cryptographic Key Generation
    • Digital Signing
    • Verification to Protect Privacy

NOTE: In the case of blockchain, cryptography is used to encrypt transaction data to maintain the confidentiality and authenticity of transaction data.

Types of Cryptography

There are various types of Cryptography:

  • Symmetric Key Cryptography

 It is an encryption scheme where a single common key is used by the sender and recipient of messages to encrypt and decrypt messages.

Symmetric Key Schemes are quicker and easier to use. The speed is achieved on compromise of security as it is very difficult to exchange key between two people without revealing some hidden information.

  • Asymmetric Key Cryptography

In this method, encryption and decryption are done using a pair of keys.

For encryption, a public key is used and a private key is used for decryption. The private key and the public key are unique.

Even if the public key is known by everyone, the intended receiver can only decode it because they alone know the private key.

Symmetric Key Cryptography:

  • Symmetric key cryptography uses single key for encryption and decryption.
  • Symmetric key encryption can be divided into two parts.
    • Block
    • stream
  • Block cipher usually encrypts a fixed size chunk of data.
  • Stream cipher encrypts data byte-by-byte.
  • Different kinds of symmetric key cryptography algorithms are AES, DES, 3DES, Salsa, Seed, and Aria.

Asymmetric Key Cryptography:

  • Asymmetric-Key Cryptography usually works with two pair of keys, i.e. Public Key and Private Key.
  • A public key can be shared or published to other individuals. A private key is kept secret.
  • Public keys are used to only encrypt data and private keys can decrypt data.
  • There are many Asymmetric key encryption used, some are:

○ Rivest Shamir Adleman (RSA)

○ Digital Signature Algorithm (DSA)

○ Elliptic Curve Cryptography (ECC)

○ Elgamal

Algorithms Used in Blockchain Technology

Blockchain is a distributed database existing on various computers with a decentralized ledger tracking digital assets on the P2P network.

Some of the most popular encryption standards in blockchain are:

  • SHA256
  • Elliptic Curve Cryptography (ECC)
  • RIPEMD-160

Public Key:

  • Public key is one of the two keys generated using asymmetric encryption protocols used in blockchain technology.
  • Public key which also acts as the address of an account on the blockchain is a fixed length alphanumeric number. Bitcoin’s public key is 256 bits long.
  • Public key is made using a private key and then broadcasted to the public.
  • Public key encryption works such that anyone can encrypt using the public key but only the owner of corresponding private key decrypts the message.
  • A shorter representative version of the public key is the address that is used for receiving funds

Private Key:

  • A user has a public address and a private key to send and receive transactions. Users can maker transactions to the public address.
  •  Private key is an alphanumeric string, it is critical to keep the key safe for the safety of crypto tokens.
  • Digital wallets are used to store the private keys.
  • Transactions use digital signatures to verify the sender. A valid digital signature confirms that the transaction comes from a particular user. Any change in the translation data invalidates the signature.
  • Private keys can be stored differently, some method of storage are:
    • Paper wallets,
    • Hardware wallets
    • Cold storage like pen-drives
    • Offline software wallet.
  • There are Hot wallets connected to internet which can be used to store the keys online.

        Public Vs Private Key

So, Blockchain is designed to make it possible for anyone to use the system.

This means that the creation of a valid blockchain address is fairly simple (even if wallets didn’t do it for you):

  1. Private Key Generation: A private key is a random number that may be required to fulfill certain

requirements. For example, the private key may need to be a prime number. The number of potential

private keys means that a well-generated one is unlikely to be the same as any other user’s private

key.

  1. Public Key Generation: A public key is derived from the private key using an operation specific to

the algorithm used by the blockchain. For example, in Elliptic Curve Cryptography (ECC), the public

key is the result of performing point multiplication between the private key and a public point on the

curve called a “generator”. With ECC, division is impossible, so the best way to derive a private key

from a public key is via a brute-force search, and the algorithm is designed to make this

computationally infeasible.

  1. Address Derivation: Typically, blockchain addresses are based on the hash of the associated public

key. This makes it easy to derive an address from a public key but hard to go in reverse. The space of

potential addresses makes it unlikely for two well-generated private keys to produce the same

address.

In the end, a user has a private key, a public key, and an address. Each of these has its purpose:

  • Private Key: Private keys are used to digitally sign transactions from the associated account.
  • Public Key: A public key is used to validate the digital signature on a transaction.
  • Address: The account address is used by a transaction creator to specify where the transaction should be sent.