bitcoin Calculate hash from getwork function - how to do it

0 votes

Whenever I call the getwork on my bitcoind server, I get the following:

./bitcoind getwork 
{ 

"midstate" : "695d56ae173bbd0fd5f51d8f7753438b940b7cdd61eb62039036acd1af5e51e3", 
"data" : "000000013d9dcbbc2d120137c5b1cb1da96bd45b249fd1014ae2c2b400001511000000009726fba001940ebb5c04adc4450bdc0c20b50db44951d9ca22fc5e75d51d501f4deec2711a1d932f00000000000000800000000000000000000000000000000000000000000000000000000000000000000000000000000080020000", 
"hash1" : "00000000000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000010000", 
"target" : "00000000000000000000000000000000000000000000002f931d000000000000" 

}


This protocol does not seem to be documented. How do I compute the hash from this data? I think that this data is in little endian. So the first step is to convert everything to big endian? Once that is done, I calculate the sha256 of the data. The data can be divided in two chunks of 64 bytes each. The hash of the first chuck is given by midstate and therefore does not have to be computed.

I must therefore hash the chunk #2 with sha256, using the midstate as the initial hash values. Once that is done, I end up with a hash of chunk 2, which is 32 bytes. I calculate the hash of this chunk one more time to get a final hash.

Then, do I convert everything to little endian and submit the work? Also, what is hash1 used for?

Feb 28, 2022 in Blockchain by Aditya
• 7,680 points
728 views

1 answer to this question.

0 votes

This is correct as there is a script which calculates the hash on Javascript. In order to understand it better, please follow the code below:-

this.tryHash = function(midstate, half, data, hash1, target, nonce){ 
    data[3] = nonce; 
    this.sha.reset(); 

    var h0 = this.sha.update(midstate, data).state; // compute first hash 
    for (var i = 0; i < 8; i++) hash1[i] = h0[i]; // place it in the h1 holder 
    this.sha.reset(); // reset to initial state 
    var h = this.sha.update(hash1).state; // compute final hash 
    if (h[7] == 0) { 
        var ret = []; 
        for (var i = 0; i < half.length; i++) 
            ret.push(half[i]); for (var i = 0; i < data.length; i++) ret.push(data[i]); 
        return ret; 
} else return null; 

};

answered Feb 28, 2022 by Soham
• 9,710 points

Related Questions In Blockchain

0 votes
1 answer

How feasible is it to use one way cryptographic hash function?

you can use the ouput hash function ...READ MORE

answered May 8, 2018 in Blockchain by Johnathon
• 9,090 points
627 views
0 votes
1 answer

Is it possible to claim Bitcoin Cash from an exchange that does not support it?

You can't claim BCH without knowing private ...READ MORE

answered Jul 17, 2018 in Blockchain by aryya
• 7,460 points
756 views
0 votes
1 answer

How to access bitcoin Daemon from other services?

You don't need all these things to ...READ MORE

answered Aug 29, 2018 in Blockchain by digger
• 26,740 points
1,971 views
0 votes
1 answer

How to compute SHA256 hash for bitcoin header

header_hex = "02000000aaf8ab82362344f49083ee4edef795362cf135293564c4070000000000000000c009bb6222e9bc4cdb8f26b2e8a2f8d163509691a4038fa692abf9a474c9b21476800755c02e17181fe6c1c3" # Decode header hex into ...READ MORE

answered Aug 31, 2018 in Blockchain by digger
• 26,740 points
1,497 views
+1 vote
1 answer

Protocols used in a distributed/dlt system for the nodes to establish communication

yes all are over TCP/IP connections secured ...READ MORE

answered Aug 6, 2018 in Blockchain by aryya
• 7,460 points
1,460 views
0 votes
1 answer

Truffle tests not running after truffle init

This was a bug. They've fixed it. ...READ MORE

answered Sep 11, 2018 in Blockchain by Christine
• 15,790 points
1,946 views
0 votes
1 answer

Hyperledger Sawtooth vs Quorum in concurrency and speed Ask

Summary: Both should provide similar reliability of ...READ MORE

answered Sep 26, 2018 in IoT (Internet of Things) by Upasana
• 8,620 points
1,469 views
0 votes
1 answer
0 votes
1 answer

How To Get BTC Price on Binance from Binance API

In the Script environment for Apps, the ...READ MORE

answered Feb 28, 2022 in Blockchain by Soham
• 9,710 points
2,438 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP