Start from consensus algorithm
Blockchain is a distributed system,and consistency is the basic problem of a distributed system,to ensure that the system meets different degrees of consistency, consensus algorithm is needed.
Now the most popular algorithm are POW,POS,DPOS and so on,The POW consensus algorithm used by bitcoin for 9 years has been proven to be stable and reliable,However, it has been criticized for its huge hardware and energy waste,especial the ASIC.In order to avoid wasting resources, POS and DPOS discard the calculation directly,consensus through holding certificates and elections,but they reduce the decentralizatio.
Bytom blockchain solve the waste problem from another aspect.
Tensority introduction
Tensority based on these idea below
Computer is a power,It is necessary to consume some energy for maintaining system stability, POW has been proven to be reliable,and everyone can participate in consensus.
ASIC can only do hash calculation is a truly waste, if the mining machine can be used elsewhere ,that will be a big boost.
With the rapid development of AI accelerates market demand.
So we design AI-friendly consensus algorithm Tensority.
Matrix multiplication and convolution are two commonly used algorithms in AI. Compared with the latter, the former has wider application scope.so we use matrix multiplication in Tensority.we will introduce the algorithm below.
Bitcoin POW consensus algorithm review
Before we introduce Tensority,let’s review Bitcoin POW consensus:
We all know that the algorithm of Bitcoin is Iterative calculating the hash of block header,constantly modify the parameters,until the hash meet difficulty requirements.
Tensority summary
Take a look at the overview of Tensority
In Tensority,calcuating block header hash and comparing difficulty is the same as Bitcoin,but there are many matrix operation in Tensority,so the mining machine which support Tensority has ability to provide AI acceleration services.
Seed production
Tensority has two input,one is a block header hash,the other is seed,seed will be replaced every 256 block.it is aslo a block header hash(1–255 use 1 block header hash,256–511 use 256 block hash … …)
As the Tensority paper said:Seed is a byte array of 32 determined by a period of blockchain history. In other word,seed can be considered as a snapshot of historical network consensus.
Cache Calculation
In this step, we use seeds to obtain a matrix
First,in order to meet the requirements of Scrypt(Scrypt is used by Litecoin),we use hash to extend the seed length.
Then,we use Scrypt to generate a martix of 32x1024x128
Matrix Construction
In this step,we switch a matrix of 32x1024x128 to a matrix of 256x256x256,if you want to learn more about it, please see the paper.
Matrix Operation
It is a complicated step,and also the interesting one.
We divided block header hash into 4 pieces,each piece contain 8 bytes,we hash each piece and generate a new hash.
Then we divided the new hash into 32 bytes,each byte as a index of matrix slice,cutting matrix into a rectangle.repeat the action untile all bytes used,then we take multiplication of matrix,switch 128 rectangle into 1 rectangle.
Work Generation
In this step,we switch the rectangle into a hash,and compare to the difficulty.
a round of Tensority is ended,if the hash don’t meet the difficulty,we turn to the next round.