How cryptocurrencies are encrypted
Abstract: The blockchain world can form an autonomous community through consensus algorithms, encryption, peer-to-peer networks, and reward mechanisms, and form a mining mechanism (POW) to achieve a trust that is not achieved through a central organization, and finally realize Point-to-point value circulation. When it comes to different consensus mechanisms, there are many topics to talk about. It can even be said that the development of blockchain has been accompanied by the improvement of consensus mechanisms and algorithms. Let’s introduce different consensus mechanisms, algorithms and their principles: In fact, the consensus mechanism and algorithm are often confused now, but if you want to distinguish them, the mechanism mainly refers to POW, POS and DPOS, and the algorithm mainly refers to various algorithms under POW. In EKT, the Token chain is a parallel multi-chain structure, multi-chain, multi-consensus, and shared user base, which also means that using the EKT public chain, the Token chain and the Dapp chain can be separated, and the consensus algorithm and encryption algorithm can be freely selected.
First, let’s introduce the various algorithms used in the POW mechanism:
[Hash function]
As mentioned above, the POW algorithm we often say is essentially a Hash function. The Hash function is a very magical thing. It is not an exaggeration to say that he has laid down half of the country for Satoshi Nakamoto. Learning Bitcoin should start with learning the Hash function. After understanding the Hash function, you will learn the principle of Bitcoin to get twice the result with half the effort. Otherwise, you will feel everywhere. Chaos, difficult to understand. Satoshi Nakamoto has also used all the features of the Hash function to the fullest: many Hash functions have been designed and widely used, but Hash functions generally have a short lifespan, and algorithms that are considered safe are often successful before they can be used for a long time. Attacks, new and more secure algorithms have been designed one after another, and every algorithm that is recognized as safe and reliable has a very strict audit process.
In the blockchain world, we often say that a certain currency has invented a certain algorithm, but in fact, it mainly uses those certified security algorithms, either alone or in combination. While processing the transaction data (the data is also hashed), the miners continuously perform hash calculations to obtain a hash value whose first 23 digits are 0, and this value becomes the nonce golden number. When a miner in the whole network hashes out the nonce, he will publish the block he has packaged. After receiving the block verification block, other nodes will agree that the block has been received on the blockchain, and then Proceed to the packaging and hash calculation of the next block.
In this process, Satoshi Nakamoto sacrificed part of the final consistency through the competition of computing power (because there will be forks) and needs to wait for multiple confirmations, but this simple and violent method guarantees the integrity of the entire blockchain. The legitimacy of the system, and the robustness of the blockchain system is improved to the extreme. Even if there is only one node left in the entire network, the blockchain system will continue to operate. Finally, POW has also fully improved the security of the blockchain system. Relying on the 51% attack theory to destroy the blockchain system is a method that was considered only by the government or madmen in the past. But recently it seems that on the Bit Gold project, someone really tried to control more than 50% of the computing power and rewritten the block.
【SHA256 Algorithm】
SHA (Secure Hash Algorithm, translated as Secure Hash Algorithm) is a series of cryptographic hash functions designed by the National Security Agency (NSA) and released by the National Institute of Standards and Technology (NIST). It has experienced SHA-0, SHA-1 , SHA-2, SHA-3 series development. In 2007, NSA officially announced to solicit the new generation (SHA-3) algorithm design on a global scale. In 2012, the selection results were announced. The Keccak algorithm finally won and became the only official standard SHA-3 algorithm, but four other algorithms entered at the same time. The third round of selection is: BLAKE, GrøSTL, JH and SKEIN. These algorithms are actually very safe, and they are subject to review and are frequently used by various altcoins.
Bitcoin uses the SHA256 algorithm, which belongs to the SHA-2 series and was recognized as one of the safest and most advanced algorithms when Satoshi Nakamoto invented Bitcoin (2008). In addition to the REPID-160 algorithm used in a link in generating addresses, SHA256 is used wherever Hash operations are required in the Bitcoin system. As Bitcoin is known to more people, everyone began to wonder why Satoshi Nakamoto chose SHA256, and at the same time expressed various opinions on the security of SHA256. SHA256 has been properly questioned. So far, there is no public evidence that SHA256 has Vulnerabilities, SHA256 is still firmly resisting the banner of safeguarding Bitcoin security. Of course, everyone understands that there is no eternally secure algorithm, and it will be a matter of time before SHA256 is replaced. Satoshi Nakamoto himself explained the necessity and process of algorithm upgrade.
【SCRYPT Algorithm】
Later, with the emergence of graphics card mining and mining pools, the community began to worry that mining pools would lead to concentration of computing power, which violated Satoshi Nakamoto's original design concept of "one CPU, one vote". During that time, the anxiety of centralization was very serious, and the discussion was fierce. Bitcoin was "killed" time and time again. Until now, the debate on whether mining pools violated the principle of decentralization is still going on. In any case, some people point the finger at SHA256, thinking that the algorithm is too easy to lead to the emergence of mining machines and mining pools, and trying to find a more difficult algorithm. At the right time, Litecoin (Litecoin) using the SCRYPT algorithm was born. It is said that SCRYPT was developed by hackers, and has not been widely used because it has not received strict security reviews and comprehensive demonstrations such as the SHA series.
Compared with the SHA256 algorithm, SCRYPT takes up more memory and takes longer to calculate. Parallel calculation is extremely difficult and requires high hardware. Obviously, the SCRYPT algorithm has stronger resistance to mining machines. Litecoin also changed the block time to 2.5 minutes. In the era when altcoins were still rare, Litecoin achieved great success relying on these two innovations and has been sitting on the altcoin for a long time. The first throne position. Later, some people made slight modifications on the basis of SCRYPT to form the Scrypt-N algorithm. The idea of improvement is the same, and they all pursue greater memory consumption and computing time, so as to effectively prevent ASIC-specific mining machines. Soon, the success of Litecoin gave birth to various algorithm innovations. From 2012 to 2014, algorithm innovation has always been a hot topic of discussion in the community. Every currency that uses an innovative algorithm can cause waves.
【Series Algorithm】
Rearrangement and combination is the most commonly used method of innovation and invention by human beings. Soon, some people were not satisfied with using a single Hash function. In July 2013, Quark was released, and it was the first to use a multi-round Hash algorithm. It seemed tall, but it was actually very simple, that is, the hash function was calculated 9 times on the input data. , the result of the previous round of calculation is used as the input of the next round of calculation. These 9 rounds of Hash use a total of 6 encryption algorithms, namely BLAKE,
BMW, GROESTL, JH,KECCAK and SKEIN, these are recognized secure Hash algorithms, and ready-made implementation codes already exist.
The appearance of this kind of multi-round Hash gives people an intuitive sense of security and power, and has attracted countless fans. Dash (DASH, formerly known as Darkcoin, Darkcoin), whose price is still strong today, took the next stick and took the lead in using 11 encryption algorithms (BLAKE, BMW, GROESTL, JH, KECCAK,
SKEIN, LUFFA, CUBEHASH, SHAVITE, SIMD,ECHO), euphemistically called X11, followed by X13, X15 series were developed. The S series algorithms are actually a series of ideas. As long as one of the algorithms is cracked, the entire algorithm will be cracked. It is like a chain with interlocking links. Once one of the links is broken, the entire chain will be divided into two.
【Parallel Algorithm】
Some people connected in series, others connected in parallel, Heavycoin (HVC) took the lead in trying. HVC is not well-known in China now, but it was still famous at that time. It was the first time to realize the game on the chain. The author was a Russian. Unfortunately, he died young, which caused a lot of regret in the currency circle. HVC algorithm details:
a. First run a HEFTY1 (a Hash algorithm) operation on the input data to get the result d1
b. Take d1 as input, perform SHA256, KECCAK512, GROESTL512, and BLAKE512 operations in sequence, and obtain outputs d2, d3, d4, and d5 respectively
c. Extract the first 64 bits of d2-d5 respectively, and form the final 256-bit Hash result after obfuscation, as the block ID.
The reason why a round of HEFTY1 hashing is performed first is because HEFTY1 is extremely difficult to calculate, and its performance against mining machines is far superior to that of SCRYPT. But like SCRYPT, the security has not been demonstrated by an official organization, so the following four security algorithms have been recognized to enhance security. Compared with the methods of serial connection and parallel connection, although Quark, X11, X13, etc. use a variety of HASH functions, these algorithms simply connect a variety of HASH functions in series. After careful consideration, in fact, the overall anti-collision performance has not been improved. The security is supported by the weakest algorithm among them due to the barrel effect. Any Hash function encountering a collision attack will endanger the security of the currency system. HVC extracts 64 bits from each of the above algorithms, and fuses them into the final result. In fact, the four algorithms are connected in parallel. If one of the algorithms is cracked, only 64 bits of it will be endangered, and if the four algorithms are cracked at the same time, it will be endangered. Security of the monetary system.
Bitcoin only uses one Hash algorithm. If SHA256 proves to be no longer safe in the future, although the algorithm can be changed, considering the current situation of "hard forks are fiercer than tigers", turmoil will inevitably be caused by then, but If parallel algorithms are used, it is possible to strive for a quiet hard fork transition time.
[Selection of EKT]
The central idea of EKT is to design a community mechanism so that developers can easily develop a DAPP and leave the rest to EKT.
Since currency requires a stable system, the more complex the smart contract design, the higher the possibility of errors. Therefore, in the early days, Satoshi Nakamoto believed that the currency system did not need a Turing-complete language. The reason why Bitcoin does not support smart contracts is also I feel that the currency needs to be extremely stable. So, how to develop Dapp while maintaining currency stability in the blockchain? A better solution is to separate the Token chain from the DApp chain.
In EKT, the Token chain is a parallel multi-chain structure, multi-chain and multi-consensus, sharing the user base. There are two reasons for designing parallel multi-chains:
1. Each Token issuer or chain issuer has different requirements for consensus. Those who require a higher degree of decentralization can choose PoW, and those who have higher requirements for TPS can choose DPOS. Tokens of each chain are traded What is consumed at the time is the main currency of the current chain as the transaction fee, which also improves the flexibility of the issuance chain.
2. Parallel multi-chains can share users, and the owners of different chains have a mutually beneficial relationship, which can facilitate the transfer of assets between different chains, and multi-chain parallelism theoretically has no upper limit on the TPS of the entire network.
In EKT, the Token chain is a parallel multi-chain structure, multi-chain, multi-consensus, and shared user base, which also means that using the EKT public chain, the Token chain and the Dapp chain can be separated, and the encryption algorithm can be freely selected.
In the early stage of the project, in addition to the DPOS consensus algorithm provided by default, EKT will also support Proof of Work (POW) and Proof of Stake mechanism (POS). Users can choose which consensus algorithm to use when deploying their own main chain based on the code of the EKT main chain. After the deployment is complete, go to the EKT client to register. Once the consensus algorithm is selected, it will be recorded in the EKT main chain and cannot be changed. As for why EKT bypassed the POW algorithm at the beginning and directly chose the DPOS consensus on the main chain, I will continue to share in next week's article.
Foreword: Since currency requires a stable system, the more complex the smart contract design, the higher the possibility of errors. Therefore, in the early days, Satoshi Nakamoto believed that the currency system did not need a Turing-complete language. The reason why Bitcoin does not support smart The contract also feels that the currency needs to be extremely stable. In the previous article (How to Encrypt Cryptocurrency 1), we learned that the Token chain in EKT is a parallel multi-chain structure, with multi-chain and multi-consensus, and a shared user base. This also means that using the EKT public chain, Token can be The chain and the Dapp chain are separated, and the consensus algorithm and encryption algorithm are freely selected. Users can choose which consensus algorithm to use when deploying their own main chain based on the code of the EKT main chain. In this article, we will continue to discuss why EKT bypassed the POW algorithm from the beginning and directly chose the DPOS consensus on the main chain.
Let's continue to review some algorithms used in the POW mechanism:
[Valuable POW mining? 】
While some people are going further and further on the road of exploring more and more complex algorithms, another group of "environmentalists" also made sharp criticisms, that is, accusing POW of wasting energy. Although the POS mechanism had been realized at that time, obviously all miners were unwilling to easily admit that their mining machine/graphics card was doing a meaningless stupid thing. Although the POW party tried its best to maintain it, it also admitted the fact that it consumes energy. This accusation opens up another path of exploration, that is, if an algorithm can be found that can maintain the security of the blockchain, and these Hash operations can generate value in other ways, that would be perfect.
The most exciting result on this road of exploration comes from Primecoin (Primecoin) invented by Sunny King (this person has previously developed Peercoin, the famous point currency). The core idea of the PrimeCoin algorithm is to find large prime numbers while performing Hash operations. Prime numbers are now widely used in various fields, but human understanding of him is still limited. In the field of mathematics, prime numbers have many difficult problems, such as the famous Goldbach conjecture, Riemann conjecture, twin prime number conjecture, Fermat number, Mersenne prime number, etc. The solution of these problems can contribute to the development of human science and technology. Development plays a very important role in promoting.
Prime numbers are not only rare on the number axis (compared to even numbers), but also irregularly distributed. Looking for prime numbers on the number axis can only be searched and detected blindly, which is exactly the characteristic of POW. After the release of Prime Coin, with its brand-new ideas and contributions to the mathematical academic community, it has attracted great attention from the electronic currency industry. Primecoin is the world's first electronic currency proposed for mathematical problems, and it is known as a cryptocurrency with practical scientific research contributions in mining operations.
Another requirement of POW is that it is easy to verify. In this regard, humans have obtained some results after hundreds of years of exploration. Primecoin uses two methods of testing, firstly conduct the Fermat Test (Fermat Test), then pass the Euler-Lagrange-Lifchitz Test (Euler-Lagrange-Lifchitz Test), and pass the tests sequentially. is a prime number. It should be pointed out that this method does not guarantee that the hundreds of percent that pass the test are prime numbers, but this does not affect the operation of the system, even if the test result is wrong, as long as each node thinks it is a prime number.
Due to the uneven distribution of prime numbers on the number axis, and according to the current knowledge, the larger the number, the rarer the prime number, the difficulty of finding it does not increase linearly, and the time-consuming is unpredictable, but the blockchain requires stable blocks. Because of this, the Primecoin algorithm has not been popular, but this kind of exploration is not meaningless. The "fantasy" of using POW workload has not stopped, and the exploration is still going on.
【Ethereum's Choice】
Ethereum (Ethereum) actually planned to use the POS method from the beginning, but due to some problems in the POS design, the development team decided to use the POW method in the Ethereum 1.0 stage, and it is expected to switch to POS (CasperFFG) in the Serenity stage.
Since Bitcoin's PoW algorithm is computationally difficult, it led to the emergence of ASIC professional mining machines, which led to the centralization of mining. Ethereum has learned the lessons of Bitcoin and specially designed Ethash, which is a memory-hard algorithm. It is characterized by the fact that the efficiency of mining is not closely related to calculation, but is positively related to the performance of memory. Although it is only a transitional algorithm, the development team is not ambiguous at all, adopting a very cumbersome design style. Ethash is an improved Dagger-Hashimoto algorithm, which is a new variant of the Hashimoto algorithm combined with the Dagger algorithm. The basic flow of the algorithm is as follows:
1) Obtain a seed seed by scanning the block header;
2) Generate a 16M pseudo-random cache through the seed;
3) A data set (memory) of about 1GB is generated based on the cache, called DAG. Each element in the DAG is calculated by certain elements in the cache, that is, as long as there is a cache, the element at the specified position in the DAG can be quickly calculated;
4) The "miner" randomly selects elements from the DAG and performs Hash operations on them. DAG is a complete search space. The mining process is to randomly select elements from the DAG (similar to the process of testing a suitable nonce in Bitcoin mining) Perform Hash operation.
5) The verifier only needs to use the cache to verify the correctness of the Hash operation.
Note: The cache and DAG are updated every 30,000 blocks (that is, 5.2 days), so the main time consumption of Ethash is to read data from DAG, and DAG is generally stored in memory, so the main bottleneck is memory performance and its bandwidth.
In the early days of Ethereum, 100% of PoW mining was adopted, but in addition to the increase in the difficulty of mining due to the increase in computing power, there is an additional difficulty factor that increases exponentially, which is the difficulty bomb (Difficulty Bomb). The use of PoS will lower the threshold for mining, because miners no longer need to buy expensive hardware mining machines, they only need to buy a certain amount of ETH, and use it as a deposit to verify the validity of the transaction through proof of equity. Get certain rewards. Therefore, for the miners, the mining machines they bought at a high price will be useless, which will inevitably cause dissatisfaction among the miners. In order to prevent miners from uniting to resist in the process of converting PoW to PoS, thus forking two Ethereum blockchains, a difficulty bomb was introduced. The difficulty bomb refers to the addition of a difficulty factor that increases exponentially every 100,000 blocks in addition to adjustments based on the block generation time and the difficulty of the previous block when calculating the difficulty.
In October 2017, Ethereum delayed its plan to disarm the "difficulty bomb" by a year as the Ethereum Foundation was still laying the groundwork for transitioning to its hybrid PoS system, Casper. However, as the schedule of Ethereum’s transfer to POS gradually progresses, once Ethereum transfers to PoS, ETC’s network (the “difficulty bomb” was removed from the hard fork at block height of 5,900,000 on May 30) may hope to The current form inherits most of the mining hash power dedicated to ETH. When a large amount of computing power pours into ETC, but its block output remains unchanged, the currency price may jump due to the increase in mining costs.
【Zero-Knowledge Proof】
In the world of cryptocurrencies, the one that achieves "full anonymity" is none other than Zcash. The biggest feature of this currency is the use of zero-knowledge proof to realize private transactions. Zcash is very cautious in the choice of algorithm. After considering SHA256D, SCRYPT, CUCKOO HASH and LYRA2 algorithms, it finally chooses Equihash. The Equihash algorithm was jointly invented by Alex Biryukov and Dmitry Khovratovich, and its theoretical basis is a well-known computational science and cryptography problem - the generalized birthday paradox problem.
Three elements are required for zero-knowledge proof to be established, namely integrity, reliability and zero-knowledge. For example, suppose there is a circular corridor, the exit and entrance are adjacent but not connected (within the visual distance), and there is a locked door somewhere in the middle of the circular corridor, which can only be accessed by those who have the key. Pass; At this time, A has to prove to B that he has the key to open the door, and the solution is to use zero-knowledge proof. B watches A walk into the entrance and wait at the exit. If A enters through the corridor from the entrance and walks out from the exit, It can be proved that he has the key to open the door in the middle, and in this process, he does not need to provide B with the specific information of the key at all. So zero-knowledge proof is actually a probabilistic proof rather than a deterministic proof.
The Equihash currently used by Zcash is a memory (ARM) dependent algorithm. The computing power of the machine mainly depends on how much memory it has. According to the paper description of the two inventors, the algorithm requires at least 700M memory to execute, and a 1.8 GHz CPU to calculate for 30 seconds. After the optimization of the Zcash project, each mining thread currently requires 1G of memory, so Zcash officials believe that it is difficult for the algorithm to produce mining machines (ASICs) in a short period of time. In addition, Zcash officials also believe that the algorithm is relatively fair. They believe that it is difficult for someone or an organization to secretly optimize the algorithm, because the generalized birthday paradox is a problem that has been extensively studied. In addition, the Equihash algorithm is very easy to verify, which is very important for the future implementation of Zcash light clients on constrained devices.
[Selection of EKT]
So what is DPoS? First of all, we know that in the POS camp, the amount of coins you get is determined by the amount of coins you got before. The principle of the DPoS mechanism is to allow everyone who holds coins to vote, thereby generating K representatives, which we can understand as K supernodes or mining pools, and the rights of these K supernodes are completely equal to each other of. From a certain point of view, DPOS is a bit like a parliamentary system or a people's congress system. If a delegate fails to perform their duties (fails to produce a block when it is their turn), they are delisted and the network elects a new supernode to replace them. This mechanism can be said to be a relatively good method that is compatible with fairness and efficiency.
The central idea of EKT is to design a community mechanism so that developers can easily develop a DAPP and leave the rest to EKT. The main chain of EKT adopts the DPoS mechanism to ensure its long-term stability and high performance.
Since currency requires a stable system, the more complex the smart contract design, the higher the possibility of errors. Therefore, in the early days, Satoshi Nakamoto believed that the currency system did not need a Turing-complete language. The reason why Bitcoin does not support smart contracts is also I feel that the currency needs to be extremely stable. At present, the performance bottleneck of the mainstream blockchain is prominent. The processing capacity of the blockchain is limited by the processing capacity of a single node, which limits the processing speed of the blockchain and wastes a lot of processing capacity of the entire network. As more nodes Added to the network, increased network traffic can significantly degrade system performance. So, how to develop Dapp while maintaining currency stability in the blockchain? A better solution is to separate the Token chain from the DApp chain.
So how can we build a community with positive feedback and healthy operation? The most critical feature indicators are actually TPS and latency. On weekdays, people complain most about TPS. In fact, on Bitcoin or Ethereum, even if TPS goes up, the delay will not go down. Because of POW mining, it always takes a while for the entire network to synchronize blocks. In EKT, some events that have different execution orders that have no impact on global consistency can be executed before the block is packaged (in fact, most of the events in the application are such events), and then events that require timing are executed after the block is packaged , so that second-level confirmation and execution of most events can be achieved. In fact, some events are executed asynchronously first, and then the consistency check is performed when the blocks are packaged. This can better reduce the delay.
In the early stage of the project, in addition to the DPOS consensus algorithm provided by default, EKT will also support Proof of Work (POW) and Proof of Stake mechanism (POS). When users deploy their own main chain based on the code of the EKT main chain, they can choose which consensus algorithm to use (including any one mentioned above will be supported successively). After the deployment is complete, go to the EKT client to register.
Reference reading:
Reference reading:
20171026 Interpretation of blockchain encryption algorithm
20180115 Principles of Blockchain and Cryptography: Classification and Principle Analysis of Hash Algorithms
20180501 Look at the consensus mechanism of blockchain from the history of consensus.
20180516 Evolution of Blockchain Consensus Mechanism
20180406 What is a zero-knowledge proof
20180306 5 minutes Blockchain | Technology - Hash Algorithm
《Bitcoin: A Peer-to-Peer Electronic Cash System》
《Primecoin whitepaper》
《Ethereum whitepaper》
《EKT whitepaper》
《ZEC whitepaper》


