Coins on SHA256. What is the Bitcoin encryption algorithm? Weaknesses and strengths of the Bitcoin hashing algorithm

The SHA 256 hashing function formed the basis of the very first cryptocurrency in the world - Bitcoin and many altcoins. Did you know that it was created long before the advent of cryptocurrencies and was intended for completely different purposes? Today we will look at the history of the algorithm, the principle of its operation, current problems and which cryptocurrencies use SHA256.

Story

The name of the algorithm SHA 256 is an acronym for Secure Hashing Algorithm. That's what the developer called it - the US National Security Agency. The algorithm is a hashing function. This means that its input is a volume of data of arbitrary length, and the output is a set of characters of a fixed length, called a hash.

One of the key features of hash hashing functions is irreversibility. We can get the hash by passing the original data through the function, but knowing the hash, we will not be able to get the original data. Thanks to this property, the function has become widespread in various services and applications where data protection is required. Every day we use the SHA 256 algorithm when visiting sites on the Internet. It includes an SSL security certificate, which is required to establish a secure connection to the site.


The algorithm is part of the SHA-2 family, developed on the basis of SHA-1, which appeared in 1995. Since its inception, sha256 has been extensively tested for its strength using cryptanalysis. Cryptanalysis tests the resistance of hash functions to two main types of attacks:
  • Finding collisions - detecting identical hashes with different input parameters. The success rate of this attack compromises the security of the digital signature using the current algorithm.
  • Finding a preimage is the ability to decrypt the original message using its hash. This attack compromises the security of storing authentication password hashes.

The analysis was first tested in 2003, but no vulnerabilities were found then. As time passed, computing power developed. In 2008, collisions were found for iterations SHA-512 and SHA-256. In September of the same year, a method for creating collisions was developed for 31 iterations of SHA256 and 27 iterations of SHA-512.

Obviously, the time has come to develop a new crypto-resistant function. In 2012, the NSA invented SHA-3. Gradually, the updated algorithm will displace its less crypto-resistant predecessors.

Mining on SHA 256

US law permits the use of SHA and similar hash functions as part of other protocols and algorithms in certain federal non-Secret information security applications. SHA-2 can be used by private and commercial organizations.

It's no surprise that it was used in cryptocurrencies. Miners collect all transactions into a block and then begin hashing it. When a hash value that matches the system rules is found, the block is considered ready to be attached to the end of the blockchain. The new block will be found by someone who can calculate hash values ​​very quickly. The speed of calculations depends on the power of the equipment. Three types of equipment can be used to mine Bitcoin:

  • CPU (central processing unit);
  • GPU (video cards);
  • ASIC (Application Specific Device).

The Bitcoin network is designed in such a way that each new block must be found once every 10 minutes. The number of network participants is constantly changing, but time must remain constant. To ensure equal residence times, the system adjusts the computational difficulty depending on the number of miners. Cryptocurrencies have gained popularity recently, and the number of miners has increased greatly. To prevent blocks from being found too quickly, the complexity of the calculations also increased.


Bitcoin began to be mined on processors. Then, when their power became insufficient, they switched to video cards. Soon the video cards could no longer cope. Then ASICs were invented - special devices designed for calculations using the sha 256 algorithm. One ASIC is much more powerful and energy efficient than several video cards.

Enterprising miners are creating huge farms from ASICs. In addition to the high cost of the equipment itself, such a farm receives electricity bills of several tens of thousands of dollars every month. Now Bitcoin mining makes sense only on such industrial farms; a home computer or even a farm with several video cards will not be able to compete with them, and even recoup the electricity.

However, this is easy to calculate. There are calculators to calculate the profitability of mining on sha256. For example, https://www.coinwarz.com/miningprofitability/sha-256. Enter the hashrate of your equipment (computing power), energy consumption and its cost into the form, the service will calculate your profit.

Altcoins SHA-256

Let's look at the list and list of cryptocurrencies that work on sha 256.

Bitcoin Cash (BCH)

Separated from it on August 1, 2017. The block size in classic Bitcoin is 1 MB. The network has grown so much that all transactions can no longer fit into a block. This led to the formation of queues of transactions and an increase in fees for making payments. The community decided to introduce a new protocol, according to which the block was increased to 2 MB, some information began to be stored outside the blockchain, and the time frame for recalculating the complexity was reduced from two weeks to a day.

Namecoin (NMC)

It is a system for storing and transmitting name-value combinations based on Bitcoin technology. Its most famous application is the domain name distribution system, which is independent of ICANN and therefore makes domain repossession impossible. Namecoin was launched in 2011, it runs on Bitcoin mining software forwarded to the server where Namecoin runs.

DigiByte (DGB)

A cryptocurrency launched in 2013 with the goal of improving the performance of Bitcoin and Litecoin. DigiByte differences:

  • Low volatility is achieved due to the huge number of issued coins (up to 21 billion), which ensures their low cost and ease of use in calculations;
  • Faster transactions by doubling the block size every two years;
  • Low commissions or no commissions;
  • The mining process is divided into five algorithms that allow you to mine coins independently of each other. You can use ASICs for SHA-256 and Scrypt, video cards for Groestl and Skein, and a processor for Qubit.

The SHA 256 algorithm is the most common among cryptocurrencies. This was caused by the popularity and success of Bitcoin, and the desire of altcoin developers to create similar coins. The increase in computational complexity prompted miners to look for ways to mine more efficiently, which resulted in the emergence of ASICs.


Bitcoin encryption is based on SHA-256, a special algorithm that is part of the program code. Its task is to convert the input data into a specific set of characters (in alphabetic and numeric representation) and protect the information. Such actions are called hashing. What are the subtleties of this algorithm? Why is it needed and how does it work? What are the advantages and disadvantages? We will consider these and a number of other points in detail.

What encryption algorithm does Bitcoin have, and where is it used?

When discussing cryptocurrency, the features of its operation and mining, participants in the crypto network inevitably come across such a widespread definition as the Bitcoin encryption algorithm. From the day BTC was developed until today (August 13, 2018), SHA-256 has been used, which is necessary to solve the following problems in the Bitcoin network:

  1. Formation of BTC addresses (used for transactions).
  2. Mining (proof of work).
  3. Achieving the required degree of security and anonymity.
  4. For digital signature and its recognition.
The SHA-256 algorithm is relevant not only for Bitcoin, but also for other coins, namely Bitcoin Cash, Mazacoin, Peercoin, Namecoin and other cryptocurrencies. In addition, SHA-2 (the basis of SHA-256) is used to create many protocols designed to protect data on the Internet, namely SSL, TSL and others.

The Bitcoin hashing algorithm is necessary to control information through its analysis and timely identification of inaccuracies. Once the data has been processed and converted into a hash, it is impossible to get the information back. If you take an already encrypted BTC file, do the calculations again and make sure that the hash parameters are identical, you can be sure that there are no changes to the original information. If the data differs, this indicates a system hack.

Bitcoin encryption algorithm - how it works in simple words


SHA-2 is based on the framework created by Merkle and Damgaard. The peculiarity of the hash function used in cryptography is the non-standard approach to its formation. The incoming data is divided into blocks of identical size, after which the created elements are converted to hexadecimal numbers. It is with them that calculations are subsequently made. A hash function is applied to the resulting value, and the result of the processing is the hash sum that appears in the output. It is a set of characters presented in alphabetic and numeric display. Essentially, this is a hash.

The next block is built according to the principle described above. In this case, a new process is launched after the creation of the previous element. If changes are made to the original data, the hash changes. In the case when identical hash function parameters suddenly appear in different blocks, a conflict situation occurs in the operation of the algorithm. When such a discrepancy occurs, the entire blockchain chain is called into question.

Thus, a hash function is used to create a digital signature. If the situation discussed above occurs, there is a high probability of signature forgery. To calculate such failures (collisions), a special technique is used that involves enumerating the data, which increases the strength of the hash function.

The correctness of Bitcoin encryption is controlled by four requirements:

  1. When you make changes to the incoming data, the hash amount remains the same.
  2. During hashing, an individual hash sum is obtained (the character set must be unique).
  3. Key creation using hashing is extremely complicated.
  4. Hashes are irreversible. This means that work with input data is allowed without the possibility of performing reverse action.

How does this apply in Bitcoin?

The task of the nodes of the cryptocurrency network is to find one in numerous transactions that suits it in all respects. When evaluating options, the initial attention is paid to the size of the commission (by the way, for this reason, transactions with a larger commission are completed faster). Next, the operation is checked, the input and output data are studied, and the originality of the digital signature is clarified.

As soon as the considered work is completed, the next element of the Bitcoin chain (block) is created with a certain size (for the cryptocurrency in question - 1 megabyte). The resulting nodes consist of the version, formation time, two hashes (past block and incoming transactions), as well as additional parameters that ensure uniqueness (bits and nonce). In the complex, the created block is hashed many times, resulting in the formation of a head hash, which acts as an output for the “old” element of the chain, and as an input for the new one.

Let's say that the hash set contains a specific number “0” (for example, the nonce is 17). It is extremely difficult to select such a value using only enumeration of values. It is this aspect that ensures the reliability of information in the blockchain network and its protection from hacking. To create a hash, enormous power is required, without which it is impossible to find the required set of characters. Once this work is completed and the parameter is found, it is sent to the elements of the crypto network with the newly created block and the found hash with 17 “0s”. Next, all participants in the Bitcoin network check the hash, combining the set of characters with information from the block. If there is no collision, a new element appears in the blockchain chain.

When did the Bitcoin encryption algorithm appear - a brief history


The term "SHA" is an abbreviation of three words: "Secure Hashing Algorithm". Bitcoin uses SHA-256, and the “base” of the mentioned hash function is SHA-2, which includes many crypto algorithms (including 256).

The creators of SHA-2 are the United States NSA, a special agency dealing with the country's national security issues. After developing and testing the algorithm, it was released to the public in 2002. The new SHA-2 also included the first hash function SHA-1 (created 7 years earlier - in 1995). Since the introduction of SHA-2, many variants of the algorithm have been released, one of which was used by Satoshi Nakamoto when creating Bitcoin in 2009.

The goal of the developers was to release an algorithm that would ensure the formation of a specific value of a certain length from a random set of characters. They did it. In the future, the resulting parameter will be used to identify (check) information. The original purpose of SHA-2 is to protect data on various services, and today (in 2018) SHA-256 is known primarily as an algorithm used in coin mining.

In 2012, the system was improved and an updated version of the hash function appeared - SHA-3. It is believed that over time, the new development will displace the previous algorithms, which will improve the already high degree of security.

Characteristics of the Bitcoin encryption algorithm


The essence of SHA-256 is simple. The initial message after making the addition is divided into blocks, and each of them is 16 words. The resulting elements go through special cycles involving 64 or 80 stages. At each of them, two words are converted, and the transformation option is formed by the remaining words. The resulting parameters are summed up to form a hash.

During the operation of the algorithm, 6 commands are used:

  • "xor" - removes "OR".
  • “shr” - shifts the indicator by the required number of bits to the right with a specific frequency.
  • “rots” - shifts the indicator by the required number of bits to the right (without using a specific cycle).
  • “II” - a connection of elements that are linear in nature.
  • “and” - “And”.
  • “+” - tracking.
Protocol characteristics:
  1. The upper limit for message duration is 33 B.
  2. The maximum speed parameter is 139 MiB/s.
  3. Word size - 4 B.
  4. The number of repetitions in a cycle is 64.
  5. The size of the block element is 64 B.
  6. The total hash code is 32 B.

Bitcoin encryption algorithm in mining


When performing calculations within mining, the correctness of the resulting hash code is determined by the number of zeros at the beginning of the line. For example, if this parameter is 17, the probability of finding such a number is extremely low and is somewhere around 1:1.4*10 to the 20th power. It is not surprising that Bitcoin mining requires the use of powerful equipment and high energy costs. At the same time, optimizing the search for the required hash is impossible, because after receiving a block of information, a random number appears at the output.

The difficulty of mining a virtual coin is to find the necessary hash and form the next block. To achieve this goal, standard enumeration of values ​​is used, which requires high-performance equipment. As mentioned, the search is not for a simple hash, but for a value with a large number of “0s” in front of it.

Cryptocurrency mining using SHA-256 is a set of measures aimed at solving a specific crypto problem. In the case of Bitcoin, the following equipment is used for mining:

  1. Since the advent of BTC in 2009, as well as until mid-2010, the use of a central processing unit (CPU) was relevant.
  2. Until mid-2011, miners used computers with video cards (GPUs).
  3. Until early 2013, FGPAs were popular, as were GPU farms.
  4. In 2014, ASICs appeared. They eclipsed existing equipment in performance. Despite this, until the beginning of 2017, miners used GPU farms and worked in pools, but by the end of 2017 and to this day, only -miners are relevant. The use of other equipment is unprofitable.
The mentioned devices are used to select the hash function of interest and generate a new one. The higher the hashrate (computing power) of the device, the faster the data is sorted and the less time it takes to find a solution.

With increasing competition and the release of more productive miners, and increases, the parameter of which changes every 2 weeks.

Weaknesses and strengths of the Bitcoin hashing algorithm


Above we looked at what Bitcoin hashing algorithm is and what its features are. This is SHA-256, which is considered the most common algorithm with a high level of reliability and a relatively simple operating principle. It is highly resistant to hacking and allows you to mine coins on any equipment (depending on the difficulty parameters).

Despite a number of positive qualities, the Bitcoin hashing algorithm has a number of weaknesses:

  1. Control by BTC mining participants. The same principle works here as in joint-stock companies (JSC), when company participants have a certain number of shares. The more power is concentrated in the hands of crypto network miners, the stronger their impact on the overall system. In addition, due to the growing complexity of mining in 2018, there is a noticeable tendency for mining to move from the hands of private miners to the control of large organizations involved in creating equipment for mining virtual coins. To receive Bitcoins, a private miner must spend large sums on purchasing ASICs, connect to one of the pools and pay for electricity. If you skimp on equipment, production loses profitability.
  2. A consequence of the situation discussed above is the fact that the “lion’s” share of Bitcoins is concentrated in the hands of the owners of large mining companies. If we take into account that not all Bitcoin received goes on sale, such organizations turn into investors and custodians of coins. As a result, the number of coins in circulation decreases. In addition, the accumulation of cryptocurrency allows you to influence decentralization, as well as the exchange rate of BTC during the trading process.
  3. Due to existing shortcomings, the SHA-256 algorithm is gradually becoming a thing of the past, and more advanced projects are taking its place. For example, Scrypt, Ethash, Blake-256, Equihash and others are gaining popularity. New algorithms have better protection and security levels, which forced the creators of many cryptocurrencies to abandon the outdated SHA-256 in favor of more advanced technologies.
  4. Despite correcting the main errors that were identified by the developers, some vulnerabilities could not be removed (in 2008, collisions were found for 22 iterations). That is why the development of SHA continued, and the second version was replaced by SHA-3.
In 2009, I was forced to use SHA-256, because at the time of the creation of the cryptocurrency, state governments adopted this protocol. At that time, it was actively used for data protection in some government programs, and was also used in the commercial sector. It turned out that the protocol was created to solve certain problems, but in reality it is in demand in a completely different way.

For clarity, let’s tabulate the positive and negative features of the Bitcoin encryption algorithm.

AdvantagesFlaws
Widespread (including in the cryptocurrency sector). The SHA protocol is actively used in everyday life to protect information.Loss of decentralization. Power is concentrated in the hands of mining companies.
Reliable burglary protection.The SHA iteration has a simple structure, which has led to an increase in mining complexity over time. As of August 2018, only ASICs with high performance can be used for mining Bitcoins.
Convenience in terms of coin mining, versatility in choosing mining equipment.New algorithms appear that have a more advanced structure.
In the second version (SHA-2), the creators managed to eliminate a number of shortcomings that negatively affected the reliability of the system.Despite active work on bugs, many shortcomings were not removed. Not surprisingly, the developers created a new version of SHA-3.
The protocol has been adopted at the legislative level in the United States.

Today it is almost not used in the development of new cryptocurrencies. The most striking example of a coin that still uses SHA-256 is Bitcoin Cash, a fork of Bitcoin that appeared in August 2017. But in the situation with this coin, the use of SHA is more a necessity than a choice of the creators. As for Bitcoin itself, the use of this series protocol is due to the lack of alternatives from Satoshi Nakamoto.

Today, in 2018, there is a lot of talk about improving this algorithm and making changes to the cryptocurrency network, but so far such intentions have not found physical implementation and remain only in the form of proposals.

Video about cryptographic functions and algorithms:

The past 2017 was a year of explosive popularity of cryptocurrencies and the same rapid growth in the rate of the “main” cryptocurrency Bitcoin. These circumstances fueled interest not only in speculation and mining, but also in the very essence of the phenomenon. More and more people want to get to the bottom of how it all works?

We are opening a series of materials in which we will try to explain in the most accessible form what is behind these mysterious acronyms like Scrypt, SHA-256, X11 and others. Let's start with the most important (but not the best) algorithm for the world of cryptocurrencies - SHA-256. It is this that is the basis for the development of Bitcoin. But before that, let’s define the key terminology – define the meaning of the terms “mining” and “hash”.

What is mining?

Contrary to popular belief, mining is not only and not so much the extraction of cryptographic banknotes themselves, but rather measures to protect this very cryptocurrency from fraudulent activities. It's not just about counterfeiting - even more important is protection, for example, from repeated use of the same coins by the same person. Earnings of new crypto coins are closely related to their emission and are formed from the reward for finding a new block that meets the conditions of the mining algorithm.

That is, in order for the next crypto coin to “appear”, you need to carry out a whole complex of complex calculations and find that very coveted “correct” block. This is what enthusiasts do with their equipment. The scheme supports itself - in order to increase the security of the cryptocurrency and issue new units, mining is necessary, and in order for it to make sense to do it, miners receive a reward.

In short, mining software groups previously performed computational operations into a single block, which is then transformed an incredible number of times to discover a special kind of hash code. Finding a hash code that would meet the requirements of the algorithm becomes more difficult the more participants are involved in the process. The “correct” hash is extremely rare, and finding one is akin to winning the lottery.

What is a hash?

The term “hash”, which is not clear to everyone, was mentioned above. This is one of the fundamental concepts in encryption in general and in the SHA-256 algorithm in particular. Let's explain what this means and go over the most important related points.

So, hashing is the process of turning an incoming set of data of an arbitrary size into an outgoing digital string. This transformation is carried out according to a pre-developed algorithm, and the outgoing string is completely unique, and serves as a kind of “fingerprint” of the incoming array. It is this string that is called the hash sum, hash code, or simply hash. And the transformation algorithm is a hash function.

Let's give an example. We can “feed” hash functions, say, the text of the novel in verse by A. S. Pushkin “Eugene Onegin”, and the output will be a hexadecimal code approximately like this:. Of course, it is impossible to “unfold” this code back and turn it into “Eugene Onegin”. But as soon as you change a single character in the poem, even just add one space, the resulting hash will be transformed beyond recognition. Volume also does not affect the length of the hash code. So, you can input one symbol “a” to the function, and the output will be exactly the same set of pseudo-random symbols of exactly the same length.

Now let’s take a closer look at why this is needed and what difficulties arise along the way. Anyone interested in the topic knows that mining cryptocurrencies using the SHA-256 protocol can be carried out using the power of a central processor, a graphics card, or a specialized ASIC device. Actually, in the context of Bitcoin, the first method is no longer relevant at all, and mining with video cards is living its last days. The complexity of calculations has increased too significantly, and half measures are no longer suitable.

In the mining software interface, the processes of converting blocks into hash amounts are displayed as a laconic line like “Accepted 0aef59a3b”. A block can consist of thousands or even hundreds of thousands of similar lines, but only one can serve as the “signature” of the block, the search for which is the essence of mining.

The search for the correct hash is carried out by simply searching through the results of solving a huge number of problems. In the SHA-256 algorithm, the “correctness” of a hash is determined by the number of zeros at the beginning of the hash sum. The probability of finding out such a hash code through calculations determined by the algorithm is negligible - one chance in millions of solutions. The exact probability is determined by the current level of difficulty in the decentralized system of a particular cryptocurrency.

A remarkable fact. Each of us has repeatedly dealt with the SHA-256 algorithm, without even knowing it, even without regard to cryptocurrency mining. We are talking about the SSL security certificate, which protects many websites. When you visit such a site, you automatically interact with SHA-256, which is what SSL is built on.

Features of the SHA-256 protocol

First, a little history. Initially, the SHA-256 encryption algorithm, or rather its prototype, was invented within the walls of the “sinister” NSA (US National Security Agency) in the now distant 2002. Within a couple of months it was modified and officially presented by the National Metrological University at the federal level. Two years later, its second, improved version was released.

Over the next three years, the Agency worked to improve the algorithm and eventually issued a patent for its second edition. This was done under a Royalty-free license, which made it possible to use the latest technology for “peaceful” purposes.

Ultimately, SHA-256 formed the basis for the creation of the world's first cryptocurrency - Bitcoin. In this case, the protocol is used twice to increase security.

When carrying out calculations as part of mining in the Bitcoin system, a sign of the suitability of the resulting hash code is the number of zeros at the beginning of the line. As of the end of the 17th, beginning of the 18th, the number of required leading zeros is 17 (+/-). The probability of detecting such a code is approximately 1 in 1.4*10 20 . This is a monstrously small number that defies comprehension and is comparable to the probability of finding a grain of sand of a certain shape on all the sandy beaches of our planet. This is why mining Bitcoin requires so much computing power and so much electricity.

There is no way to optimize the search for the "correct" hash. In the SHA-256 protocol, the hash function, taking a block of data, produces a completely unpredictable output value. Therefore, iteration (repetition) after iteration is needed until a suitable code is found, we emphasize once again - completely random.

Now we are forced to “load” the reader a little with complex technical information, otherwise our story about SHA-256 will be incomplete. If nothing is clear at all, just move on to the next section of the article.

The protocol involves breaking information into fragments of 512 bits each (or 64 bytes, which is the same, since 1 byte = 8 bits). Then cryptographic “mixing” occurs according to the scheme inherent in the algorithm, and the output is a hash code of 256 bits in size. The hashing operation is performed in 64 iterations, which is relatively little, especially compared to the new cryptographic algorithms that have emerged.

The main technical parameters of SHA-256 are as follows:

  • Block size: 64 bytes;
  • Maximum message length: 33 bytes;
  • Size of the resulting hash code: 32 bytes;
  • Number of repetitions in one round: 64;
  • Maximum speed: about 140 MiB/s (mebibyte per second).

In its work, the algorithm uses the well-known Merkle-Damgard technique, which involves dividing the initial indicator into blocks immediately after making changes. The blocks, in turn, are divided into 16 words each.

The data set is run through a round of 64 iterations. Each of them starts the process of hashing the words that make up the block. Pairs of words are processed by the function, after which the results are added up, and the correct hash code is obtained. Each next block is calculated based on the value of the previous one. This is a seamless process - it is impossible to calculate blocks separately from each other.

Evolution of SHA-256

To understand the cryptographic value of this algorithm, let's look back at history. They began to seriously test its strength almost immediately after its creation - in 2003. The matter was handled by professionals, but no vulnerabilities or errors were found.

Five whole years passed when, in 2008, Indian experts were still able to identify collisions for as many as 22 iterations. After several months of hard work, a successful solution to the problem was proposed.

In the course of analyzing the operation of the functional part of the algorithm, its resistance to two types of possible methods of security failure was tested:

  • through preimage: this means reverse decryption of the original message based only on the hash string;
  • through collision detection: this implies the coincidence of outgoing data, provided that incoming messages are different. That is, the incoming blocks are different, but the outgoing hash is the same - this should not happen.

After the first version of SHA-256 failed tests on the second criterion, the developers decided to create a new encryption mechanism based on radically different principles. That’s what was done - in 2012, a new generation protocol was introduced, completely devoid of the above-described shortcomings.

Disadvantages of the algorithm

The fact that the developers managed to correct their own mistakes does not mean that they managed to bring SHA-256 to perfection. The protocol got rid of obvious vulnerabilities, but its “native” shortcomings remained.

The use of SHA-256 as the basis of Bitcoin became possible, not least due to the fact that US legislation itself was loyal to this protocol. It was allowed to be used for data protection in some government programs, and was also allowed to be used in the commercial sphere.

This is where the irony of fate comes from - the protocol was created for one purpose, but found its widest application in completely different ones. And for those first purposes it was more than effective and appropriate. But for cryptocurrencies it turned out to be too simple. It’s no joke when in China, for example, there are not even farms, but entire “factories” filled with ASIC miners.

Each iteration of the algorithm looks quite primitive - a basic binary operation plus a 32-bit addition. This is why ASICs based on SHA-256 appeared so quickly, multiplying by zero all the hopes of “home” miners with only a processor and a couple of video cards.

Times and conditions are changing a lot, and the SHA-256 protocol is confidently following on the heels of other, more advanced solutions. The same Scrypt, in the process of calculations, first records 1024 different hash strings, and only after that it performs the addition and obtains the final result. This is an incommensurably more complex scheme with the highest levels of cryptocurrency protection and security.

Summary

The SHA-256 encryption algorithm was considered quite effective and reliable until the cryptocurrency boom began. Today it becomes clear that against the backdrop of new solutions it already looks rather weak. So much so that this made it possible to create special devices “sharpened” strictly to bypass it. These are the same ASIC miners that have virtually destroyed mining on central processors and are already finishing off mining on video cards.

It would seem that there is nothing wrong with this - healthy competition, after all. But in fact, the use of ASICs quite significantly centralizes the cryptocurrency, thereby neutralizing its very idea. This fact could not help but push talented enthusiasts to create new, more advanced hashing algorithms. And they were not long in coming.

The SHA-256 protocol currently occupies the lion's share of the cryptocurrency market, but new alternatives are already confidently pushing it aside. For example, the second most popular and “expensive” crypt, Ethereum, uses the Ethash protocol, which was previously called Dagger. The protocol is so good that Ethereum still maintains maximum decentralization to this day, and ASIC miners for its mining still do not exist in nature. Perhaps Ethash will replace the clearly obsolete SHA-256.

One of the first alternative algorithms was Scrypt, on which one of the most popular altcoins, Litecoin, is based. This is a much more advanced solution, which no longer gives ASIC such undeniable advantages. However, super-profits from mining forced Chinese specialists to invest a lot of effort in developing technological solutions for Scrypt, and ASICs based on this protocol did appear.

If we consider mining from the perspective of an ordinary person who is not experienced in technical nuances, then he will not feel any difference between the Scrypt and SHA-256 algorithms. ASICs on both protocols look almost the same, consume approximately the same amount of electricity and have exactly the same fan noise. Another thing is the cryptocurrency rates that these same ASICs mine, but that’s a completely different story.

We will devote the following material within the framework of this topic to the mentioned alternative encryption protocol Scrypt.

SHA 256 is a cryptographic set of instructions for mining cryptocurrencies. In other words, it reliably protects all transactions on the network, and complicates the extraction of electronic coins. This abbreviation stands for Secure Hashing Algorithm, which means a highly popular and effective hashing method.

The essence of SHA 256 is to convert information into values, numbers. This chain has a fixed length. This means that any information you transmit within the network will be encrypted with special values ​​- identifiers (IDs).

When making transactions, the SHA 256 algorithm compares the ID with the original data, which cannot be retrieved, and then provides access to the transaction. This protocol is now used in the mining of cryptocurrencies such as BTC and BCH.

History of appearance

How did it happen that Bitcoin started using SHA 256? It all started with the algorithm becoming a member of the SHA-2 family, which have a hash chain size of 224-512 bits.

They, in turn, were created on the basis of their great-grandfather - SHA-1, whose hash was 160 bits long. The technology appeared in 1995, and was intended for use for civilian purposes - that is, encryption of ordinary, non-state-important information.

The SHA-2 family, to which SHA 256 belongs, was developed by the National Security Agency 16 years ago - in the spring of 2002. Based on this, we can say that the algorithm is morally outdated. However, it is still one of the strongest algorithms for encrypting transactions on the network.

Technical parameters of SHA 256

The algorithm is designed for data divided into equal parts of 64 bytes. SHA 256 ensures that they are collected and combined into a single 256-bit chain. The main method for this method is the encryption operation, which is performed in a loop 64 times.

Brief characteristics of SHA 256 algorithmic instructions:

  • 64-bit blocks - works most quickly with 32-bit blocks;
  • the peak length of the encrypted chain of information is 33 bytes;
  • message digest size - 32 bytes;
  • the standardized size of one word is 4 bytes;
  • encryption cycle in one round of operation is 64 bytes;
  • the speed at which the algorithm operates is 140 Mbit/s.

It is worth noting that this member of the SHA-2 family is based on the framework described by Merkle-Damgaard. This means that before dividing the information into words, the data is divided into blocks. The process strengthens encryption by shuffling the data.

The collection of information itself is carried out in the range from 64 to 80 repetitions. Each subsequent loop converts the created blocks into words. The final result, namely the hash, is created by summing all the initial values.

Cryptocurrencies with SHA 256 algorithm

As mentioned earlier, not only Bitcoin has such a set of instructions, but also:

  • peercoin, the peculiarity of which is that the code is created based on the cue ball, but PoS is used to protect the entire network, and PoW is responsible for the distribution of coins;
  • namecoin is a digital currency that acts as a means of protection, confidentiality, and decentralization; unobtanium - has extremely low inflation; it will take at least 300 years to mine all the coins;
  • deutsche eMark is a German micronetwork that is used for exchanging assets and money. The process itself takes place without intermediaries; betaCoin - works on the same principle as the world famous BitCoin;
  • jouleCoin - also based on the grandfather Bitcoin, but provides faster transaction confirmation;
  • steemit is not even a separate crypt, but an entire platform on the blockchain. Its main task is to reward interesting publications.

Litecoin also uses the SHA 256 algorithm, but not throughout the entire system, but in a subroutine. For Litecoin mining, the Scrypt security protocol is used, which increases the complexity of mining and reduces the payback of ASICs.

Cryptocurrency mining based on the SHA 256 algorithm

To mine electronic coins that are based on the SHA-2 family, it is not necessary to use specialized tools - ASIC. Both CPU and GPU based farms perform well in mining. The latter is clearly superior in speed to the former.

And yet ASIC is the best solution for mining cryptocurrencies. Its advantages are to some extent offset by its significant price - about 100 thousand rubles, more powerful models even exceed 500,000. As complexity increases, the payback decreases. Therefore, the equipment does not always justify itself, although it provides a much higher mining speed than farms on video cards and, especially, a CPU.

GPU mining is considered more or less profitable. In general, the entire farm will cost approximately $1000-2000, plus additional equipment - in particular, cooling systems for video cards. It is also worth taking into account the rental of premises, electricity payments and salaries for service personnel.

Among video cards, the GTX 1080 Ti from Nvidia performs well. It produces a speed of 1400 successful operations per second. AMD is slightly behind with its Vega line cards - 1200 MH/s. There are also cheaper options like the Radeon 7970, but its speed does not exceed 800 MH/s.

The SHA 256 algorithm, although old, is still used in Bitcoin, the No. 1 cryptocurrency in the world. The protocol is also used in a number of other promising altcoins. SHA256 is gradually being replaced by Scrypt, but Bitcoin has no plans to switch to it. Regarding mining, everything is simple - if you have money, take ASICs with a high hash rate. Want a more economical solution? Then build a farm from AMD or Nvidia video cards.

  • Translation

At one point I wanted to figure out how quickly it was possible to mine Bitcoins manually. It turned out that SHA-256 hashing is used for mining, and it is quite simple and can be calculated even without a computer. Of course, the process is very slow and completely impractical. But after going through all the steps on paper, you can have a good understanding of the details of how the algorithm works.

One crypto round

Mining

A key part of the entire Bitcoin security system is mining. The basic idea is that miners group Bitcoin transactions into one block, which they then hash an incalculable number of to find a very rare hash value that falls under special conditions. When such a value is found, the block is considered mined and enters the block chain. Hashing itself serves no useful purpose other than increasing the difficulty of finding the correct block. Thus, this is one of the guarantees that no one alone with any existing set of resources will be able to take control of the entire system. You can read more about mining in my last article.

The cryptographic hashing function receives a block of data as input and produces a small but unpredictable output. It is designed so that there is no quick way to get the output you want, and you have to keep searching until you find the right value. Bitcoin uses SHA-256 as such a function. Moreover, to enhance the resistance, SHA-256 is applied to the block twice and is called double SHA-256.

In Bitcoin, the criterion for a hash to be valid is to have a sufficient number of leading zeros. Finding such a hash is as difficult as, for example, finding a car or phone number ending in several zeros. But of course for a hash it's exponentially more difficult. Currently, a valid hash must contain approximately 17 leading zeros, which is only satisfied by 1 in 1.4x10 20 . If we draw an analogy, then finding such a value is more difficult than finding a specific particle among all the sand on Earth.

Blue blocks non-linearly shuffle bits to make cryptographic analysis more difficult. Moreover, for even greater reliability, different mixing functions are used (if you can find a mathematical loophole to quickly generate valid hashes, you will take control of the entire Bitcoin mining process).

The majority function (Ma block) operates bitwise on the words A, B, and C. For each bit position, it returns 0 if the majority of the input bits at that position are zeros, otherwise it returns 1.

Block Σ0 rotates A by 2 bits, then the original word A is rotated by 13 bits, and similarly by 22 bits. The resulting three shifted versions of A are added bitwise modulo 2 ( normal xor, (A ror 2) xor (A ror 13) xor (A ror 22)).

Ch implements the selection function. At each bit position, a bit from E is checked, if it is equal to one, then the bit from F from this position is output, otherwise a bit from G. Thus, the bits from F and G are mixed based on the value of E.

Σ1 is similar in structure to Σ0, but works with the word E, and the corresponding shift constants are 6, 11 and 25.

The red blocks perform a 32-bit addition, generating new values ​​for the output words A and E. The value W t is generated based on the input data (this happens in the part of the algorithm that receives and processes the hashed data. It is beyond our scope). K t is its own constant for each round.

In the diagram above, it is noticeable that only A and E change in one cryptographic round. The remaining words do not change, but are shifted at the output - old A turns into output B, old B into new C, and so on. Although a single round of the algorithm does not change the data much, after 64 rounds, the input information will be completely encrypted.

We mine manually

In the video I show how you can go through all the steps described with a pen and paper. I performed the first round of hashing to mine the block. It took me 16 minutes, 45 seconds.


Let me explain a little what is happening: I wrote down the words from A to H in hexadecimal form, and under each I made a translation into binary form. The result of block Ma is below the word C, and the values ​​of A after the shifts and the output Σ0 itself appear above the line with A. The select function appears below G, and finally the corresponding shifted versions of E and the value after the block Σ1 go above the line with E. In in the lower right corner performed an addition, the result of which is involved in the calculation of both the new A and the new E (the first three red summation blocks). On the top right I calculated the new value of A, and in the middle is the calculation of the new value of E. All these steps were discussed above and can be easily tracked in the diagram.

In addition to the round shown in the video, I conducted one more - the last 64th hashing round for a specific Bitcoin block. In the photo, the hash value is highlighted in yellow. The number of zeros confirms that it is a valid Bitcoin hash. Note that the zeros are located at the end of the hash, and not at the beginning, as I wrote earlier. The reason is that Bitcoin simply flips the bytes received by SHA-256.


The last round of SHA-256, as a result of which a successfully mined Bitcoin block is visible

What does all this mean for the design of hardware miners?

Each step in SHA-256 looks very simple in digital logic - simple bit operations and 32-bit sums (if you've ever studied circuit design, you've probably already imagined what this might look like in hardware). Therefore, ASICs implement SHA-256 very efficiently, placing hundreds of SHA-256 round execution units in parallel. The photo below shows a mining chip that can calculate 2-3 billion hashes per second. You can see more photos on Zeptobars.


A silicon shot of the Bitfury ASIC chip, which can mine Bitcoin at 2-3 gigahashes per second. Picture from Zeptobars. (CC BY 3.0)

In contrast to Bitcoin, Litecoin, Dogecoin and other similar alternative -coin systems use the scrypt hashing algorithm, which is inherently difficult to implement in hardware. This algorithm stores 1024 different hash values ​​in memory during execution, and combines them at the output to obtain the final result. Therefore, much more memory and circuitry is required to calculate scrypt hashes compared to SHA-256 hashes. The impact of changing the hashing algorithm is clearly visible when comparing the corresponding mining hardware - versions for scrypt (Litecoin and others) are thousands of times slower than versions for SHA-256 (Bitcoin).

Conclusion

SHA-256 was suddenly so simple that it could even be calculated by hand (the elliptic curve algorithm used to sign a Bitcoin transaction would be much more painful, since it involves a bunch of multiplications of 32-byte numbers). Calculating one round of SHA-256 took me 16 minutes, 45 seconds. With this performance, hashing an entire Bitcoin block (128 rounds) will take 1.49 days, that is, we get a hashing rate of 0.67 hashes per day (in fact, of course, the process would speed up with practice). By comparison, the current generation of Bitcoin miners produce several terahashes per second, which is about a quintillion times faster than me. I think it's clear that manual Bitcoin mining is not very practical.

A reader from reddit asked about my energy expenditure. Since I do not exert any serious physical effort, we can assume that the metabolic rate will be 1500 kilocalories per day, then we find that manual hashing requires almost 10 megajoules per hash. Typical consumption energy for an iron miner is 1000 magehash per joule. Thus, I am less energy efficient than a specialized piece of iron by 10^16 times (10 quadrillion). Another issue is the cost of energy. A cheap source of power is donuts at 23 cents per 200 kilocalories. I have electricity costs 15 cents per kilowatt-hour, which is 6.7 times cheaper than donuts. As a result, the cost of energy in terms of hash for me, as a human miner, is 67 quadrillion times higher. Yeah, it’s clear that I won’t get it Good luck with manual Bitcoin mining, and that's not even taking into account the cost of paper and pens!