Many of you have probably already heard about blockchain technology, but it is important to know about how hashing works in this system. Blockchain technology is one of the most innovative discoveries of the last century. We can say so without exaggeration, as we observe the influence it has had over the past few years and the influence it will have in the future. In order to understand the structure and purpose of the blockchain technology itself, we must first understand one of the basic principles of blockchain creation.
Wikipedia defines a blockchain as a chain of transaction blocks. The word “blockchain” literally means a chain of blocks. But, this definition does not convey the whole essence of this new technology, on which Bitcoin cryptocurrency is built. So what exactly is a blockchain? And what are its advantages over other ways of organizing and storing data? To begin with, the blockchain is a distributed database, full copies of which are located on a set of servers (computers) integrated into a peer-to-peer network.
It follows from this that the blockchain cannot exist only on one computer (server).
A peer-to-peer network, also called a peer-to-peer (P2P) network, means that all computers integrated into it have the same rights and there is no main (central managing) server. The technology of the blockchain, as an organization of data, ensures safe and complete storage of information. Those. Any changes to transactions already recorded in the blockchain are impossible - you can neither delete nor correct them. And this is a very important point! Since we are dealing with financial transactions. And also there is no single trusted centre (bank) that would monitor the safety (immutability) of these transactions.
How is it organized in the blockchain? Let's try to figure it out. The hash code or simply the hash (hash) of an array of information is similar to the fingerprint of a person — it is a unique short character string that is inherent only in this array of incoming information. Just as a fingerprint is inherent in only one person and there are no people with the same fingerprints, the hash is inherent in only one set of input data.
Hashing is the calculation of the input data of a certain number used to control the transfer of data, search data in the table, the organization of password protection. Storing of large amounts of information requires organizing quick access to it. Hashing is one of the ways to organize such access. The basic idea of hashing is to compute a certain fixed-size number from the input data, which would indicate the address of the data in the table. In this case, such a number will be called a hash, and the function with the help of which it is calculated is a hash function. Since a function that will uniquely match data with hashes is difficult to select even for fairly large tables, special methods for resolving ambiguities, called collisions, are used.
The main property of all hash functions is their irreversibility, that is, according to the hash, it is impossible to restore the original data by which it is calculated. This feature allows hashing to be applied in such important areas of human activity as computer security and cryptography. At the same time, hash functions used in cryptography must meet the requirements of cryptographic robustness: it should be practically impossible to select a different data sequence for a given data with a matching hash function, and, in addition, it should be almost impossible to select at random two data sequences with a matching hash . The word "practically" implies a reasonable complexity of selection, defined mathematically.
The irreversibility of hashes allows them to be used for organizing password protection when passwords are not stored in the database, but their hashes. Thus, even if the attacker somehow succeeds in hacking the database and reading the hashes in some way, this will not help him in any way.
Hash functions are widely used for data verification. If the hashes of the transmitted and received data match, then the data transfer process is considered to be successfully completed. A simple example of hashing just from this area is the finding of the checksum of the message: in this case, the hash is the sum of the codes of all the characters it contains, from which the last few digits are taken.
What are cryptographic hash functions? A cryptographic hash function takes data and, in fact, translates it into a string of letters and numbers. Have you ever used URLs like Bitly or TinyURL? This is something similar. You enter something long, and the output is something short, which personifies something long. Only in the case of cryptographic hash functions, the input does not have to belong. It can be something very short (for example, the word "dog") or almost infinitely long (for example, the entire text of "A Tale of Two Cities"), and at the output, you will receive a unique string of a prescribed length. In addition, unlike reference shorteners, hash functions used in Bitcoin operate in one direction only. Although the same data will always give the same hash, it is impossible to reproduce the original data on the hash derived from them.
o, the data is entered into the hash function, the function is executed and a string of letters and numbers is obtained. This string is called a hash. In the Bitcoin blockchain, hashes consist of 256 bits or 64 characters.
It may seem impossible that a nearly infinite amount of data could be sequentially transferred to a unique string of just 64 characters, but cryptographic functions work in just such a wonderful way. With this incredible technology, whole books filled with text can be translated into one line of 64 numbers and letters. And each time you enter the same data, you will receive not only the same hash but unique and different from any other hash.
There are different types of cryptographic hash functions, and each of them works differently. The hash function used above — SHA-256, the hash function used in Bitcoin — works on the basis of an incredibly complex formula related to the reflection of light from ellipses. You should not worry too much about it. The bottom line is that cryptographic hash functions are damn magic, and you never fully understand them unless you're a mathematician.
We formulate the basic requirements for cryptographic hash functions:
Creating a hash function that satisfies all the listed requirements is not an easy task. It should also be remembered that data of arbitrary size is received at the input of a function, and the hash result should not be the same for data of different sizes.
For the blockchain to work, it must be updated. Like a bank, it must keep current records of all transactions and assets (for example, bitcoins) that each member of the network has. It is when updating transactional information that any authenticating system is vulnerable to attack. The bank mitigates this risk by having a strict centralized hierarchy that guarantees authenticity at its own risk. So how does the blockchain manage to be updated while remaining decentralized? It uses a cryptographic probabilistic hash game called Proof of Work.
The ideal cryptographic hash function has the following properties:
A cryptographic hash function guarantees the security of use in exchange for speed, while a regular hash function can be faster than a cryptographic one, but it can be significantly safer to play. With increasing computing power, hash functions become easier to crack. Hash functions that were considered safe yesterday and owned all cryptographic properties can now be included in the list of common hash functions.
It is almost impossible to determine the input of any hash function unless you possess immense calculating power. The reason for this is quite simple as the only way to crack such function is by “brute forcing” it. Brute-force has its name for a reason as the whole process is nothing but simply picking options until you reach the result that will have the same exact hash as the one you’re trying to crack. Taking into the account the fact that typical hash is 256 bit long it would take a lot of time to do that.
Nevertheless, there’s always a possibility that the input will be determined on the first attempt, or in the very beginning of the process, the chances of this actually happening are so small that you’re more likely to win a jackpot in a lottery with a first ticket you’ve bought in your entire life. The same way you may be unlucky and get the result at the very end of the calculation. That’s why the most realistic outcome is getting it somewhere in the middle, however, that would still consume a lot of time considering the fact that you have enough calculating power.
There is much more that can be said about the hashing and hash functions in general, but the terms are not of any help to an ordinary user that is why it’s not really useful to mention them or explain in more detail how they operate. The main point is that this method is used in cryptocurrency for a reason and this reason is that it’s almost impossible to break it somehow or crack it.
The data structure is a specialized way to store data. If you want to understand how the blockchain system works, then there are two basic properties of the data structure that can help you with this:
The pointer is a variable whose value is the address of the memory cell. That is, the pointer refers to the data block from the memory area, and to its very beginning. A pointer can refer to a variable or function. For this, you need to know the address of a variable or function. For example, the record int a = 10 means that there is a certain variable “a”, which stores an integer value equal to 10. This is how a standard variable looks. However, instead of storing values, pointers store the addresses of other variables. That is why they got their name because they literally indicate the location of other variables.
The main purpose of the linked list is to provide a mechanism for storing and accessing an arbitrary amount of data. As the name suggests, this is achieved by linking data together into a list. This is a great way to store data. Most programming languages allow one way or another to allocate memory as an array and manipulate its contents. Sequential data storage increases performance (data locality), makes it easy to iterate through the content and access an arbitrary item by index.
It is important to note that the pointer inside each block contains the address of the previous one. So the chain is formed. The question arises, what does this mean for the first block in the list and where is its pointer located? The first block is called the “genesis block”, and its index is in the system itself. If you are interested in what “hash pointer” means, then we will be happy to explain. As you already understood, the blockchain structure is based on this. A chain of blocks is a linked list.
In hashing it is used the following way:
Building a hash chain:
Thus, the whole chain has a through relationship directed to the first link, the hash of the last link is actually a digital fingerprint of the entire chain, with low collision rates in the algorithm of the hash function used, it is almost impossible to replace the chain link so that all subsequent links are linked into a hash chain.
Building a tree:
Hash trees are a generic view for hash lists and hash chains. Hash trees provide an efficient and secure method for checking large data structures. Verifying the authenticity and ownership of a leaf of a tree requires data processing in proportion to the logarithm of the number of tree nodes; for hash lists, it is necessary to process all nodes of the list.
When we say “mining”, basically, it means finding a new block that will be added to the blockchain. Miners around the world are constantly working to make sure that the chain continues to grow. Previously, people found it easier to work using only their laptops for mining, but over time they began to form "pools", combining the power of computers and miners, which could be a problem. There are restrictions for each cryptocurrency, for example, for Bitcoin, they are 21 million. Between the creation of each block, there must be a specific time interval specified by the protocol. For bitcoin, the time between creating a block takes only 10 minutes. If blocks were allowed to be created faster, this would result in:
Thus, to limit the creation of blocks, a certain level of complexity is established. Mining is a bit like a game: you solve a problem and you get a reward. Increasing complexity makes solving a problem much more difficult and, consequently, it takes more time to complete. WRT, which starts with a set of zeros. As the level of difficulty increases, the number of zeros increases. The level of difficulty changes after every 2016 block.
When the Bitcoin protocol wants to add a new block to the chain, mining is the procedure it follows. Whenever a new block appears, all its contents are first hashed. If the selected hash is greater than or equal to the complexity level set by the protocol, it is added to the blockchain, and everyone in the community recognizes the new block.
However, it is not so simple. You must be very lucky to get a new unit in this way. Since it is here that a unique symbol is assigned. A unique character (nonce) is a one-time code that is combined with a block hash. Then this line is again changed and compared with the level of complexity. If it corresponds to the level of complexity, then the random code changes. This is repeated a million times until the requirements are finally met. When this happens, the block is added to the blockchain.
Imagine that the Bitcoin protocol issued a task - to guess the number 5, and the total numbers - a million. Your chances of solving this problem are 1 in a million. If the network wants to simplify the task, it sets a range of numbers, say from 1 to 100, and your chances are already 100 to a million. If it is necessary to complicate the task, we expand the range, and now you need to guess one digit not from a million, but from a billion values. This is exactly the mathematical task - the number that corresponds to a particular hash is needed. The hash is updated every 10 minutes, and the first computer that solved the problem receives a reward.
But today the range of numbers from which you need to find the right one is huge. All world Bitcoin miners jointly process approximately 50,000,000,000,000,000 input values per second in an attempt to match the key to a given hash. Bitcoin network regularly tracks the speed of solving the problem, and if it was solved much faster than 10 minutes, they make the next one more difficult. If you don’t invest in 10 minutes, the next one will be easier. As soon as the first computer solved the problem, it shows its solution to all participants who check this solution, and when it confirms that the number matches the hash, it receives an award, and a new cycle begins.
The whole process is completely random, based on the generation of random numbers, following the Proof Of Work protocol and meaning:
The hash rate depends on a number of key parameters, including the chosen cryptocurrency mining algorithm. For example, some devices provide maximum performance within networks with the SHA algorithm (Bitcoin, Namecoin, Peercoin, etc.), but their efficiency will be significantly lower on the network using the Scrypt algorithm (Litecoin, Dogecoin, Gridcoin, etc.).
Also, equipment specifications that vary depending on the manufacturer. Those who plan to do mining, it is recommended to study the information about the power of a device to help in choosing the most optimal and cost-effective option. Do not forget the popularity of the cryptocurrency: the more popular it is, the more miners interested in its production. They connect their computing power to the network, thereby increasing its hash rate and, accordingly, the complexity of mining.
Those who distribute files on a torrent tracker resemble miners. It is no secret that thanks to them the work of the p2p network is ensured. Thanks to this, anyone can download your favorite music album or movie. And for downloading the visitor increases its rating. Increasing the rating makes it possible in the future to download your favorite movie or music. Miners, in the case of Bitcoin, ensure the functioning of the monetary system, as well as carry out an infinite number of transactions. For the time and resource spent, miners receive not a virtual rating, but quite tangible banknotes.
More and more “players” join the “game” and bring more power, hence the complexity. At the initial stage, the digital miner was satisfied with the home computer, then the top-end video cards went into action. Today, specialized mining devices have been developed, they are commonly called ASIC miners. The main hardware problem is the high-speed calculation of hashes with the lowest possible power consumption.
However, it’s necessary to mention that nowadays the ASIC miners have become the only way of mining the Bitcoin and most of the people around the world do not have a possibility to participate in the process without investing an immense amount of money in it. The mining of Bitcoin is mostly done by a few huge companies that possess the most of the computing power and this actually is a threat to one of the most important Bitcoin principles which are decentralization.
Hash and the process of its creation are used in various ways, and were popular a long time ago when nobody heard about the blockchain and Bitcoin was never a thing. Nowadays, it’s found its use in this new groundbreaking world of cryptocurrencies and is used there as a basis for all of the operation and we might say that all of the blockchain principles are dependant on the hash. It is indeed fundamental to the creation of blockchain technology. And if someone wants to understand what a blockchain is, he should start by understanding what hashing means.