Speaking of consensus algorithms

Blockchain system is a distributed system, and consistency is the basic problem of distributed system. To ensure that the system meets different degrees of consistency, consensus algorithm is needed.

At present, the mainstream algorithms include POW, POS, DPOS and so on. The POW consensus algorithm adopted by Bitcoin has been running for nine years and has been proved to be stable and reliable. However, it has been criticized for its huge hardware and energy consumption.

In order to avoid the waste of resources, POS and DPOS directly abandon calculation and reach consensus through holding proof and election, sacrificing certain access and decentralization. But than the original chain from another Angle to cut into and solve the problem of POW resource waste.

Than the original chain consensus algorithm Tensority design ideas

Firstly, consensus algorithm is designed based on the following ideas:

  • Computing is a kind of power and cannot be abandoned because of energy consumption. It is necessary to maintain a stable energy consumption of the system, and POW has been proven to be stable and reliable, while the entry threshold is low. (CPU, GPU, ASIC mining machine can enter, at the same time do not need to hold coins or election)
  • The single function of mining machine is the original sin, and only hash operation can cause a great waste of mining machine. If the function of mining machine can be diversified, it will be more conducive to development.
  • With the rapid development of artificial intelligence technology, the market demand for AI intelligence increases rapidly.

Therefore, we designed an AI-friendly consensus algorithm called Tensority. Matrix multiplication and convolution are two commonly used algorithms in artificial intelligence. Compared with the latter, the former has a wider application range.

In order to make the consensus algorithm of the original chain friendly to artificial intelligence and compatible with all mainstream AI acceleration equipment, the matrix multiplication operation is adopted in the selection of the algorithm. After the algorithm is determined, the data types involved in the operation need to be selected according to two criteria:

** First, ** select a data type that can be supported by all current mainstream AI accelerators.

** Second, the main data types of neural network inference should be supported.

Taken together, the INT8 data type meets the criteria.

Bitcoin POW consensus algorithm review

Before talking about the POW consensus algorithm Tensority, let’s review the POW consensus algorithm of Bitcoin:

We know that Bitcoin’s POW consensus algorithm is a process of iterating the hash value of the block header and constantly modifying the parameters until the hash value matches.

A general overview of POW consensus algorithms

So let’s take a look at the overall process of consensus algorithm than the original chain:

In the whole Tensority algorithm, the selection of block head hash and the comparison of difficulty value are still the steps of head to end connection, but there are many operations involving matrix interspersed in the middle, and these operations are more common in AI calculation, so the mining machine supporting the original mining has the ability to improve THE AI acceleration service.

Let’s further refine each process:

Seed generated

We can see in the overview diagram that Tensority has two inputs, one is the same hash head as Bitcoin, and the other is the seed, so how is the seed come from? A seed is a 32-bit byte array determined by the history of the block over a period of time. The seed comes from the block header of the first block of every 256 blocks, and generally the seed is changed every 256 blocks, using the same seed up to 256 blocks.

Cache Calculation

This step mainly uses the seed to obtain a matrix through certain transformation. We first expand the seed by hashing it a certain number of times to satisfy the input requirements of Scrypt, and then use the Scrypt function to generate a 32x1024x128 matrix. It’s worth noting that the Scrypt algorithm we used is the one used in Litecoin.

Matrix Construction

This step will change the matrix generated in the previous step into a more regular matrix, which is suitable for subsequent processing. The specific process will be complicated, please refer to the paper.

Martix Operation

This step is complicated and the most interesting. The collected block header hash is divided into four pieces, and each hash is done once to generate a new hash value. Each bit of the new hash value is used as the index value of the Matrix Construction to generate a Matrix slice, which is sliced to obtain a rectangle. After the above steps, you have 128 rectangles, and you multiply these rectangles by matrices to get a matrix.

Work Generation

This step is to input the rectangle generated in the previous step into a 32-bit hash value for the final difficulty comparison. The 256×256 rectangle is first transformed into a 256×64 rectangle and then converted to a 32-bit hash value by the FNV function.

We’re going to compare the hash value and the difficulty value to see if it meets the criteria, and that’s the end of the consensus algorithm for this round.