Published in

Block Street

# A simple kick-starter on Blockchain

This is my effort to put together a Blockchain 101. The information posted here is basic and simple and scattered.

Blockchain lives on the Internet. You do not find it anywhere else. The other day I found a bitcoin fallen on the ground right around the corner of my street. No! You won’t! It is a computer program living on the internet. So if the Internet ceases to exist, so as Blockchain. The world has to exist with human beings for blockchain to survive and flourish. Maybe not. With AI and autonomous systems prevalent, blockchain should be able to run by itself. But human society will be the most beneficial of robust blockchain systems because they struggle hard to reach consensus on anything and everything without a central entity. If there is a defined system assisting them in reaching a consensus, they will enjoy it. The blockchain is a computer program running in a network of computers across the world.

What makes a computer program so special and hyped? Two things make this program special — Cryptography & Economics.

The blockchain computer program's outcome is a huge data storage file that replicates across a network of computers. But that does not make it special. What makes it special is it secures the data and makes it immutable using cryptographic functions.

# Cryptographic Hash Functions

Cryptography has been here for a long time. Cryptographic Hash functions are something you must know if you need to understand blockchain. A cryptographic hash function is a mathematical function that takes an input (or ‘message’) and returns a fixed-size alphanumeric string. The string is the ‘hash value,’ ‘message digest,’ ‘digital fingerprint,’ ‘digest’ or ‘checksum.’ It is easy to calculate a hash for any data. So It is a mathematical algorithm that maps data of arbitrary size to a bit string of a fixed size (a hash) and is a one-way function, i.e., a function infeasible to invert. The only way to recreate the input data from an ideal cryptographic hash function’s output is to attempt the trial-and-error method of inputs to see if they produce a match.

Some security features of Cryptographic Hash functions that make it an ideal implementation of blockchain technology are collision-free, hiding, and puzzle friendliness.

Every hash function with more inputs than outputs will have collisions. Consider a hash function such as SHA-256 that produces 256 bits of output from an arbitrarily large input. Since it must generate one of 2²⁵⁶ outputs for each member of a much larger set of inputs, the pigeonhole principle guarantees that some inputs will hash to the same output. Collision resistance does not mean that no collisions exist but it is hard to find two distinct inputs that produce the same output.

Hiding means irreversibility. The hash differs completely from the original data, and there is no (easy) way to find the original data with the hash. It hides the original data and make it safe when the hash gets exposed.

Puzzle-friendliness means unpredictability and randomness. Given any data, there is no way to tell the hash value without calculating it, and it can be any value.

SHA-256 is a popular hashing algorithm used in blockchain technology. One thing you need to keep in mind is that Hashing is not the same as Encryption.

Hashing is not the same as Encryption!

# Merkle Trees

Since you have known about Hashing, the next thing to understand is Hash Pointers, and data structures developed using hash pointers. In computer programming, a pointer is a programming language object that stores the memory address of another value in computer memory. A data structure is a specialized format for organizing and storing data. In computer programming, a data structure is selected or designed to store data to work on various algorithms.

In simple terms, Hash Pointer is a pointer to where some info or data gets stored plus the hash of that info or data. Hash Pointer can be used as a block pointer. A block pointer is a data structure similar to the pointers in a linked list. Each pointer, besides the previous block's address, also contains a cryptographic hash of the information (or a part of it) contained in the previous block.

Hash Pointers gives blockchain the property of a tamper-evident log.

Now let’s see some essential data structures we can build using hash pointers, which get widely used in blockchain implementations. You can make a binary tree with hash pointers called a Merkle tree. Take consecutive pairs of data blocks (which have transaction IDs) and build a data structure, so it has two hash pointers to each of these blocks. Likewise, this goes all the way from the bottom up with a hash generated from two of the hash children until it reaches a root when there are only two hashes left below it. To simplify, each leaf node or end node in a Merkle tree is a hash of transactional data, and each non-leaf node is a hash of its previous two hash children. Merkle trees are binary and therefore require an even number of leaf nodes. If the number of transactions is odd, the last hash gets duplicated once to create an even number of leaf nodes. The Merkle Root summarizes all the data in the below leaf transactions and gets stored in the block header. Merkle tree allows for quick verification of transaction data included in the blockchain without going through the entire blockchain data or downloading the entire chain. If you need to know how this is possible, you need to understand how a Merkle tree works. To verify that it includes a transaction in a block, there is an authentication path or a Merkle path without having to download all the transactions in the block. This definitely needs a diagram to explain.

Blockchain uses a Merkle path to prove the inclusion of a data element. A node can prove that it includes a transaction K in the block by producing a Merkle path with only four 32-byte hashes long (128 bytes total). The path comprises the four hashes (shown as blue shaded blocks) HL, HIJ, HMNOP, and HABCDEFGH. With those four hashes provided as an authentication path, any node can prove that HK (with green background at the bottom of the diagram) includes in the Merkle root by computing four additional pair-wise hashes HKL, HIJKL, HIJKLMNOP, and the Merkle tree root (outlined in a dashed line in the pic above). Basically, you use the Merkle path hashes to identify hash-pairs and hash them each other again to generate parent hash and ultimately match the parent hash generated with the root hash.

To conclude, the Merkle tree data structure maintains the integrity of the data in a blockchain. If a single detail in any of the transactions or the order of the transactions changes, so does the Merkle Root.

# Digital Signatures

The next thing you should know about is Digital Signatures. Digital signatures are like electronic “fingerprints.” In the form of a coded message, the digital signature securely associates a signer with a document in a recorded transaction. We use digital signatures as a standard, accepted format called Public Key Infrastructure (PKI) to provide the highest security and universal acceptance levels. Digital signatures are based on public-key cryptography. Using a public key algorithm, an entity or person, or signer can generate two digital keys that are mathematically linked, called public key & private key. The signer keeps the private key safe and secure. The public key gets published to the outside world. The signing software creates a one-way hash of the electronic data to be signed to create a digital signature. It uses the private key of the signer to encrypt the hash data. The encrypted hash data, along with other metadata like a hashing algorithm, is called the digital signature. The signer sends the digital signature data along with the original data to the receiver. The receiver or anyone who has the signer's public key can decrypt the hash data and get the hash output. The hash output is compared with the original data's computed hash and made sure both are the same. This will ensure no data tampering and the electronic data is the same as generated at the source.

In the blockchain world, the public key generated by an entity or person is also used as a public identity. This identity does not initially get assigned to a real-world entity or person. Still, it can eventually be mapped to a particular person or entity by observing the same identity pattern over time. An example would be the “Address” in the cryptocurrency network. This type of identity is called pseudonymous.

Technically, Hashing data + Encryption with the private key forms a digital signature

# Tokens in blockchain

Now let’s define the most basic transaction unit used in all blockchain networks called cryptocurrency or crypto tokens. You probably have seen a physical token in many places that give value or some purpose already defined—E.g. tokens in a Casino. You might also have known about the digital token, a string of characters used for various purposes. For example, a business entity will send you a digital token to validate your email, and you open your email and click the URL containing the digital token. This will send the digital token back to the business, and your email gets validated. Cryptocurrency or tokens do not exist as digital strings but are entries or values in a digital ledger called a blockchain. Someone who owns these crypto tokens or currencies means he has the private key to access these crypto tokens present in the public digital ledger or transfer its access to someone else, etc. The crypto tokens are not stored in a computer or exchange, but they store the private keys to access these entries. I have used cryptocurrencies and crypto tokens synonymously here, but they are slightly different in their use cases. The underlying meaning for a token in blockchain tech is the same.

In general, tokens in blockchain are something that is used to represent other real-world assets.

Sometimes when you say tokens specific to a blockchain network, they represent computer programs that define a set of functions that can interact with real-world scenarios to act securely on the blockchain network. The tokens reside in the blockchain network and are associated with a blockchain address, which is the public key associated with creating the token. The owner associated with the address is the custodian of the token. One such example is the ERC20 token in the Ethereum network.

## Minting Tokens

Minting tokens is done at a high level by sending a transaction to a blockchain network that creates new tokens inside a token smart contract. The smart contract code enforces the rules about creating a new token.

# Double-Spending

Before seeing how a basic cryptocurrency model works, we will see one of the major challenges faced by digital currencies and how a blockchain model solves it without a third party. With the physical cash, we do not have this problem of double spending where we give \$5 bill at Starbucks, and that \$5 bill cannot be spent at McDonald’s unless we steal that \$5 bill on the same night. But with digital currencies, double spending is easy where we can send a copy of our money to one person and another copy of the same money. This is prevented by a third party like banks and credit card companies by using various settling mechanisms. Blockchain networks provide an inherent solution to this problem by adding logic into every blockchain node to verify all transactions from a coin and reject any new transactions occurring using the same coin. This is the first level of defense on double spending on any blockchain node. Then, various consensus algorithms are implemented by different blockchain networks to verify each block of transactions before being added to the blockchain ledger. Once the transaction gets added into a block like this, it is impossible to alter it or reverse it.

A person or entity Alice creates a new coin with a unique coin id and signs it with her private key. Alice can generate a hash pointer to another public key Bob (public identity or address) and send the coin to that person or entity called Bob. Alice has to sign that transaction with her private key. But this model cannot prevent a double-spending problem where Alice can create another hash pointer to Caleb and pretend it is valid. To prevent double-spending, Alice has to publish all the previous transactions of her coin by generating a hash pointer to the blockchain ledger and signing it with her private key when she is trying to send it to Bob. The blockchain node which holds all the transactions from the beginning can verify that the coin spent by Alice to Bob is valid and the second one from Alice to Caleb is invalid.

To summarize everything in a graphical form on how a hash, block, blockchain, distributed blockchain, and tokens work, this is the best place to visit. Anders Brownworth has a video published on his here about how blockchain works, and so far, this is the best graphical demo I have seen, which explains blockchain basics.

There will be a few who now think blockchain is nothing but a distributed database spanned across the network. Technically, it is true to some extent, but distinguishing a blockchain from a normal database are specific rules about how to put data into the blockchain database. i.e., It cannot conflict with some other data that’s already in the database (consistent), it is append-only (immutable), and the data gets locked to an owner (ownable); it is replicable and available. Finally, everyone agrees on the state of the things in the database (canonical) without a central party (decentralized).

Ultimately it is the collective human behavior to incentives that drives cryptoeconomics just like regular economics.

As I mentioned at the beginning of this post that blockchain lives on the internet. With the ongoing development of blockchain-based technologies and decentralized applications, one thing which is obviously happening behind the scenes and has always been there perpetual is that the internet is getting upgraded to what is referred to as web3 technologies. There is a lot to talk about web3 and what essentially comprises web3 technologies. Still, the blockchain is a key member in that unmediated read-write web of the future, aka the Internet of value.

References:

--

--

--

## More from Block Street

There will be a time when the eight-block-long street running roughly northwest to southeast from Broadway to South Street, at the East River, in the Financial District of Lower Manhattan in New York City will get renamed to Block Street.

## zijo

Thinker, Dreamer, Writer & less of a Reader | Crypto enthusiast. Become a Medium member today to read all my publications. https://zjoy.medium.com/membership