Application of Hash Function in Blockchain

  • hash pointer
  1. In addition to saving the location of the structure in memory, it also saves the hash value of the structure.
  2. Benefits: Not only can you find the location of the structure, but you can also check the hash value of the structure.
  3. The main difference between a blockchain and an ordinary linked list is that a hash pointer is used instead of an ordinary pointer.
  4. Identify whether the block data has been tampered with: the hash value of the blockchain can uniquely and accurately identify a block.
  5. Concatenate blocks into a blockchain: each block contains the hash value of the previous block and the value of the next block.

  • Merkle tree (Merkel hash tree)
  1. Use one-way hashing.
  2. The top of the Merkle tree is called top hash (top hash), also known as root hash (root hash) or master hash (main hash).
  3. The hash values ​​of all transactions on a block constitute the leaf nodes of the Merkle tree of the block, and the root hash is stored in the block header, so all transactions are bound together with the block header.
  4. Benefit: As long as you remember the root hash, you can detect any modification in the tree
  5. Function: Inductively verify the existence and integrity of block data, quickly locate each transaction, and verify whether the transaction data has been tampered with
  6. Merkle proof: Prove whether a certain transaction has been written into the blockchain

Schematic diagram of Merkle tree

  • mining
  1. Find a nonce (random number) and combine it with other information in the block header to get a hash, which is less than or equal to a certain range. H(block header) <= target.
  2. Mining difficulty setting: Bitcoin difficulty is a measure of the difficulty of mining, that is, it refers to the difficulty of calculating a hash value for a given target.
  3. The Bitcoin mining process uses the SHA-256hash function to continuously calculate. Mining is the process of repeatedly calculating the hash value of the block header and continuously modifying the nonce value until it meets the target hash value. The result of the Hash function is unpredictable, and there is no specific mode to quickly calculate the hash value.

  • Ethereum user address generation
  1. Generate private key: The generated 256-bit random number is used as the private key (256-bit hexadecimal 32 bytes)
  2. Generate public key:

    1) Use the private key (32 bytes) and the elliptic curve line ECDSA-secp256k1 to calculate the public key (65 bytes) (prefix 04||X public key||Y public key)

    2) Use the Keccak-256 algorithm to calculate the hash value of the public key (32 bytes)

    3) The 20 bytes after taking the result of the previous step is the Ethereum address

  3. input address

Guess you like

Origin blog.csdn.net/HAOMINGS/article/details/127059848