bbsmax
2021-06-06 03:59:39

# Application of Sha in blockchain

In recent years, the popularity of bitcoin has led to the research of blockchain technology . Of course, we will not discuss the blockchain technology itself here , Instead, we'll talk about SHA Application of algorithm . about SHA We have explained a series of algorithms before , It's not going to be repeated here .

1、 In the blockchain SHA

Blockchain uses SHA, But where is it used SHA The algorithm ？ To solve this problem , We must first understand the composition and structure of the blockchain . Each block contains a constant called magic number 、 The size of the block 、 Block head 、 The number of transactions contained in the block and some or all of the recent new transactions . The specific structure of the block is as follows ：

 Data item describe length Magic no（ Magic number ） Always 0xD9B4BEF9 4 byte Blocksize（ Block size ） The length of bytes to the end of the block 4 byte Blockheader（ Block head ） contain 6 Data items 80 byte Transaction counter（ The number of deals ） Positive integer VI=VarInt 1-9 byte Transactions（ transaction ） Deal list （ Non empty ） - A lot of deals

From the above table we don't seem to find SHA The trace of . In the table above, except for the block , The meaning of other parts is very clear . So next we need to take a look at the block , See what it means . in fact , In each block , What determines the whole blockchain is the blockhead . In that case , What's the content of taking it ？ Its specific structure is as follows ：

 Data item Purpose Update time size （ byte ） Version（ edition ） Block version number After updating the software , It specifies a new version number 4 hashPrevBlock（ In the previous block Hash） In the previous block 256 position Hash value When new blocks come in 32 hashMerkleRoot Merkle（ The root node Hash value ） Based on all transactions in a block 256 position Hash value When accepting a deal 32 Time（ Time stamp ） from 1970-01-01 00:00 UTC From now on , The current timestamp in seconds Update every few seconds 4 Bits（ Current target Hash value ） The current goal of compressed formats Hash value When the mining difficulty is adjusted 4 Nonce（ random number ） from 0 At the beginning 32 Bit random number produce Hash when （ Every time there is Hash Random numbers always grow ） 4

As shown in the table above , In the structure of this block , We finally saw it SHA The trace of , Namely hash value , It's through SHA Calculated by the algorithm .

2、 How blockchain is used SHA

In the last section , We get it SHA Location in the block , How to use it in blockchain SHA What about ？ Let's take another look at the format of the front block , There are two 256 Bit Hash value ：hashPrevBlock（ In the previous block Hash） and hashMerkleRoot Merkle（ Block Hash value ）, these two items. Hash How do I get the value ？

In the previous block Hash The calculation formula for the value is ： In the previous block Hash value =SHA256( The block head of the previous block ); And the block body Hash The calculation formula for the value is ： Block Hash value =SHA256( The block body of this block ).

It is not difficult to infer from the above two formulas , A block is not only about its own content , It is also related to the content of the previous block . In other words, the content of a block not only affects itself , And it has an impact on subsequent blocks . Because of any change in content , Will lead to this block Hash Change in value , This leads to the change of the block . The change of block head will lead to chain reaction of block head change in subsequent blocks .

3、 Why blockchain is used SHA

We have explained how to use... In blockchain Hash value , Now let's talk about why we use SHA. This is related to the technical requirements of blockchain and SHA There is a direct relationship between the characteristics of the algorithm .

First , The blockchain itself should ensure that each one is unique . Because there must never be two pieces of the same data , and SHA256 A very low probability of collision guarantees that . Of each block Hash The capital is unique and can be used to identify the block .

secondly , Blockchain should ensure the security of each record , and SHA Algorithms can guarantee that even if there are only trivial differences , Can also produce very different results . Combined with the structure of blockchain , When any block changes , Will affect all subsequent blocks , So if you want to modify the contents of a block , You have to modify the contents of all blocks , And it's almost impossible , So as to ensure the security of block data .

also ,SHA The length of the result is fixed , It has nothing to do with the content of the original text , This can ensure that the format of each block in the blockchain and the size of the block header used to identify the block are completely consistent , But it will never be repeated .

in summary , Blockchain uses SHA Algorithm is an inevitable choice in technology , Even if you don't use SHA It has to be with SHA Other algorithms with similar properties .

## Information digest algorithm 7 ：SHA More related articles on the application of blockchain

1. Cryptography in blockchain （-） The most widely used hash algorithm in blockchain -SHA256 Algorithm analysis and implementation

In the eyes of many technicians , Blockchain is not a new technology , It's a combination of computer technology over the years . And in this aspect of the use of Technology , Encryption algorithm based on cryptography can be said to be the basis of the performance of various characteristics of blockchain , Once the current encryption algorithm is verified ...

2. VRF Application in blockchain

Recently, there has been a trend in the field of blockchain " Strange disease ", Many blockchain projects or design schemes have joined a project called VRFs The algorithm of . that , (1) What is? VRFs? (2) VRFs What problems have been solved in the blockchain ? The purpose of this paper is to introduce ...

3. Merkle tree Application in blockchain

We reprinted an article in the last blog <Merkle Tree( Ms merkel tree ) Algorithm analysis >, So, do you have any questions , After learning this algorithm , How can we apply it , How is it applied in blockchain ? Today's blog is based on Merkle tr ...

4. Cryptography in blockchain （ Four ）- Merkle Trees and SPV node

What is? Merkle Tree? Merkle Tree It's named after American cryptographers Ralph C. Merkle , About his profile : Portal https://en.wikipedia.org/wiki/R ...

5. 【 Ethereum development 】 Oracle in blockchain ：Oraclize Principle introduction

Smart contracts have many functions , But a lot of data is still based on the Internet , So how to get data from the Internet in the contract ?Oraclize It was born for this purpose . working principle : A smart contract can be used to Oraclize Issue a call request between contracts to ...

6. Cryptography in blockchain （ Two ）-RSA Algorithm analysis and implementation

In the field of cryptography , Encryption algorithms are mainly divided into symmetric encryption and asymmetric encryption , With the development of information age, the security requirement is higher and higher , Symmetric encryption is gradually abandoned because it is easy to be cracked . and RSA Algorithm is a popular asymmetric encryption algorithm in the world of cryptography , The name is based on its inventor R ...

7. iFace Security experts reveal ： Bitcoin in the blockchain wallet , In fact, it doesn't belong to you for a long time ……

since MoreToken After the wallet ran ,2019 year 3 There have been many wallets since the beginning of the month . The exchange ran away , A lot of user accounts have been stolen , only MoreToken The total value lost by wallet users is 12.2 RMB , Users lose a lot . Why so many wallets . exchange ...

8. Blockchain learning 7： Super ledger project Fabric Endorsement in 、 An endorsement node 、 Endorsement strategy 、 Endorsement signature

* ░ Go to the old ape Python Blog Directory ░ stay Hyperledger Fabric In blockchain , There are endorsement nodes for endorsement ,Hyperledger Fabric Use endorsement policies to define which nodes need to execute transactions . Hyper ...

9. 50 That's ok Python Code builds small blockchains

This article explains how to use it python Build a small blockchain Technology , Use Python2 Realization , The code is less than 50 That's ok . Although some think blockchain is a solution waitin ...

## Random recommendation

1. 《Entity Framework 6 Recipes》 Chinese Translation Series (12) ----- The third chapter The use of inquiry SQL sentence

The original intention of translation and why <Entity Framework 6 Recipes> To learn , Look at the beginning of this series 3-2 Use native SQL Statement update problem You want to use native in the Entity Framework SQL sentence , To update the underlying ...

2. JZOJ 1312: Turn off the lights

Portal rare DP Again DP subject . The topic is not short , But you can see that this is a DP topic . And the algorithm complexity of positive solution should be \$O(N^3)\$. And gave part of \$O(N^4)\$ Of the algorithm . You can see it's going to be AC Is to be in DP Plus optimized . set up \$ ...

3. WeChat 、qq information aggregation 、 reply （ One ）

idea :        Some people like to use qq, Some people like to use wechat , To make a long story short , It's a communication tool .        qq There are lots of groups on the Internet , There are many groups on wechat , Each group goes through it one by one . reply , It's also easy to reply to errors , The foreword does not follow the postscript .       ...

4. linux Loop through all the files and scripts in the folder

#!/bin/bashfunction ergodic(){ for file in ` ls \$1 ` do if [ -d \$1"/"\$file ] then ergodic ...

5. Design Pattern :Factory and Reflect in java

interface page {     void Render(); } class pageA implements page {     @Override     public void Re ...

6. ASSER、VERIFY、TRACE Detailed explanation

ASSERT() To be tested for its parameters , If the parameter is zero , Interrupt the execution and print a description message . stay Release It doesn't work in this version of the program . ASSERT() When you use it, you must make sure that there is no function call in the parameter expression , So for any letter ...

7. [ turn ] javascript Operations on arrays

javascript Array operations , Collection of array methods 1. shift: Delete the first item of the original array , And returns the value of the deleted element : Returns if the array is empty undefined var a = [1,2,3,4,5]; var b = ...

stay C# You can use PadLeft and PadRight Make it easy to fill . PadLeft(int totalWidth, char paddingChar) // Use... To the left of the string paddi ...

9. Rich text BootStrap-wysiwyg With picture upload function

BootStrap-wysiwyg The plug-in has good editing function and display effect . One . There are many ways to use it on the Internet , Record some problems and solutions in the process of using . Related dependencies : bootstrap-wysiwyg.js ( nucleus ...

10. Make dlib（ Face recognition detection ） Static library

Refer to or quote the website : Fast and accurate head detection , The code is open source http://url.cn/5e3qQPN http://www.jianshu.com/p/701e8dea887e Official document GitHub Address 1. ...

https://netfreeman.com/2021/05/20210521010959962U.html