Bit-coin mining algorithm optimization-(1. Reduce redundancy calculation; 2.sat Boolean gratification problem)

Source: Internet
Author: User
Reader's expectation: This paper is suitable for readers who have read the source code of the Bitcoin mining algorithm or understand the main process of mining algorithm. Introduction:
A piece of pseudo code:
         nonce=0;
         while (Nonce < Uint_max)

             if (sha256 (sha256 (blockheader[nonce)) < target):
                  success
             Else nonce = nonce +1;

The process of digging is to change the nonce, to calculate the sha256 Double Data Digest of the block head, if the summary is less than the target value, the mining success (no discussion of Confirmation (confirmations)). sha256:

Blockheader:

                     --------------------------------------76 bytes---------------------------4bytes-                     |                                      不会变动的信息                                   | nonce|           
                     --------------------------------------------------------------------------------------

SHA256: Divide any length of data into n*[64 bytes, and fill the remainder. The 32-byte data Digest is then calculated and the N-times results are added separately by 4 bytes. optimization 1 (OpenSSL validation has been used, every 1 million times, do reduce 1/3):

Based on the introduction, it can be seen that no matter what the nonce is, the first 64 bytes will not change, so when the initial value of the nonce= is computed once, this value will be used directly thereafter. Reduce the amount of computation by almost 1/3. Optimization 2:

The remaining 16 bytes, only the last 4 bytes of nonce will change.

In addition, we named the SHA256 64 data changes as ROUND1~ROUND64.

Round1~round3 because the data has not changed so the result is unchanged, you can only calculate once;

Round4:round4 (A,b,c,d,e,f,g,h), where d,h is the result of the calculation. The change relationship between D,h and Nonce is d1=d0+ (NONCE1-NONCE0) h1=h0+ (NONCE1-NONCE0). So you just have to compute it once and get the results quickly. Optimization 3:

Quit early in order to find a small enough result. So in the case where the 8 byte of the high position is not zero, the calculation can be introduced in advance.


Total Optimization:

Optimization of 1, almost 1/3 computational volume;

On the basis of optimizing 1, Optimizing 2 and Optimizing 3 can be promoted at 7/128 speed;


Sat Boolean gratification issues (to be continued)


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.