Learning | Why cryptography is the core of blockchain

Everyone knows that blockchain is the underlying technology of Bitcoin, but what is the core of blockchain technology?

is cryptography.

Cryptography is the core of blockchain technology.

All transaction information will be encoded in the block, and the block chain is a structure formed by connecting these blocks together.

Encryption technology has a long history, and it has mainly experienced three stages of development: classical encryption, mechanical encryption, and modern encryption. With the advancement of history, cryptography has continued to evolve, and cryptography has become a science. Today we are going to take a look together, what is the difference between cryptography in blockchain technology and the cryptography we have known in the past? What is its role? **

What is cryptography?

Cryptography is the discipline developed to prevent third parties from viewing private data. Modern cryptography combines mathematics, computer science, physics, engineering and other disciplines. The definitions of some important terms are as follows:

-Encryption encodes the text into an unreadable format.

-Decryption converts chaotic information into its original form.

-Cipher An algorithm used to perform encryption or decryption, usually a set of executable and well-defined steps.

[Cryptography] used to be synonymous with encryption, the process of converting information from a readable format into meaningless information. The history of encryption technology can be traced back to ancient Egypt, with a very long history.

For example, the Caesar Cipher is a well-known cipher used by Caesar the Great to communicate securely with the generals. The password moves each letter in the message a certain distance (shift is 2), A becomes C, B becomes D, and so on.

(Http://practicalcryptography.com/ciphers/caesar-cipher/)

Blockchain technology encrypts wallets, transactions, security, and privacy protection protocols in many different ways. This article will discuss some important encryption topics related to blockchain technology, including Public Key Encryption, Hash and Merkel Tree.

Public Key Encryption

Public key encryption (also known as asymmetric encryption) is a cryptographic system that uses a pair of keys (public key and private key) for encryption. The public key can be widely distributed, but the private key is only known to its owner. Keys are always created in pairs, and each public key must have a corresponding private key.

Public key encryption is often used to encrypt messages between two people or two computers in a secure manner. Anyone can use someone's public key to encrypt information, but once the information is encrypted, only the corresponding private key can decrypt the message.

Suppose Alice wants to send an encrypted message to Bob, the working principle is like this:

-Alice uses Bob's public key to encrypt the message;

-Alice sends the encrypted message to Bob. If it is intercepted by a third party, the third party can only see random numbers and letters;

-Bob uses his private key to decrypt and read the received message;

This process can be represented by the following diagram:

!

Source: Wellesley College

Public key encryption is a basic element of blockchain technology and the basic technology of wallets and transactions. When a user creates a wallet on the blockchain, it is generating a public-private key pair.

The address of the wallet, or its representation on the blockchain, is a combination of numbers and letters generated by the public key. Due to the nature of the blockchain technology, this address is public to everyone and can be used to check the balance in the wallet or send tokens to it.

The private key associated with the wallet proves the ownership and control of the wallet. This is the only way to send tokens out. If the private key is lost, the tokens inside will be sealed forever.

A transaction on the blockchain is just a broadcast message, and its essence is to say, "Take out X tokens from my wallet and deposit X tokens into another wallet." Once confirmed, the transaction will be irrevocably written into the ledger, and the balances of both parties will be updated.

However, this transaction message needs to send the wallet's key signature to be valid. After the message is broadcast, anyone can use the wallet's public key to ensure that the digital signature from the private key is authentic. This is a role that block validators have to assume before adding transactions (ie messages) to the blockchain.

Encrypted Hash

Encrypted Hash is another basic element of blockchain technology, which directly guarantees the immutability of the blockchain, which is one of the most important characteristics of the blockchain.

Hash is a term in computer science that means inputting a string of any length, and then producing a fixed-length output. Regardless of whether the input of a hash function is 3 characters or 10 characters, the output length is always the same.

Encrypted Hash hash function has the following key features:

-Determinism: No matter how many times a function is given a specific input, it will always get the same output;

- Irreversibility: The input content cannot be determined based on the output of the function;

-Impact resistance: No two inputs can get the same output;

Another important feature of the encrypted hash function is that changing any bit of data in the input will greatly change the output result. For example, the hash output of 111111 and 111112 will be absolutely unique, and there is no connection between them.

The most widely used use case for encrypted hash functions is password storage. Most websites will not store the user's original password. They will store the hash of the user's password and check if the hash matches when the user visits a given site and enters the password. If hackers hack into their database, they can only access the irreversible password hash.

So, how does encrypted Hash realize the immutability of blockchain technology? The answer is that each new data block contains the hash output of all the data in the previous block.

Imagine a blockchain that just added the 1000th block. The data from block 999 exists in the 1000th block as the output of the hash function. However, the data contained in the block 999 is the hash of the data in the block 998, and the block 998 contains the hash of the data in the block 997.

Backtracking in this way, from the 1000th block to the first block, they are connected together through the encrypted Hash. The structure diagram is as follows:

This has always been the reason to ensure the immutability of the data in the blockchain. If someone wants to change even one bit of data in the previous block, it will not only change the hash output of the block data, but also change every subsequent block. Miners and nodes on the network will immediately notice that the hash generated does not match the version of the chain, and reject the change.

For reference: Bitcoin uses an encrypted Hash function named SHA-256, and Ethereum uses an encrypted Hash function named keccak256.

Merkle Tree

The picture above is a simplified version of the blockchain, which omits some important information. There are three upward arrows in the figure, indicating that the transactions of each block are stored in a Merkle root, and this is the root node of the Merkle tree.

Tree is a term in computer science, which stands for storing data in a hierarchical tree structure. Among them, data bits are called nodes. There is a root (top) node, below it is connected a "child" node (Child Node), the child node itself also has child nodes, and so on. The following figure shows a typical tree data structure:

,

As shown in the figure, the group of nodes in the tree is called a sub-tree, and nodes without sub-trees (nodes with no data under them) are called leaf nodes.

A Merkle tree (or Hash tree) is a tree that uses an encrypted Hash function to store the hash output (rather than the original data in each node). Each leaf node is composed of the encrypted Hash hash of its original data, and each parent node (Parent Node) is the Hash hash of the hash combination of its child nodes.

The Merkle root is just the root (top) node of the Merkle tree, and the Merkle root represents the hash output of the combination of its left and right subtrees. The figure below is a Merkle tree with 4 leaf nodes.

,

Each leaf node represents the Hash hash of the data of transaction A, B, C and D, and then combine Hash A and Hash B and hash to generate Hash( A, B), and generate Hash( C ,D). Finally, Hash (AB) and Hash (CD) are combined together to find the hash (Hash (A,B), Hash (C,D)), and finally form the Merkle root of the tree.

So, why is Merkle tree important to blockchain technology?

Using the Merkle root and applying the nature of the encrypted Hash hash function, you can quickly determine whether the transaction in a given block has been tampered with, and identify the specific transaction that is being tampered with.

If a single transaction in a confirmed block has been changed, then the Merkle root will eventually be very different from the "correct" Merkle root, and the change is very obvious.

Merkle trees also allow users to verify whether their transactions are included in the block without downloading the entire blockchain. Simple payment proof technology can scan all branches in the Merkle tree and check whether a particular transaction has been hashed and stored in the tree. If you don't include a Merkle root in each block, it is impossible for blockchain technology to achieve this level of efficiency.

The figure below shows a Merkle tree with 4 transactions in the blockchain (in this figure, Tx_Root represents the Merkle root)

,

Conclusion

Cryptography is an essential part of the internal work of blockchain technology. Public key encryption is the basis of blockchain wallets and transactions. The encrypted Hash function gives the blockchain the invariable characteristics. The Merkle tree improves the efficiency of the blockchain while organizing transactions.