What are midstate and hash1 used for in mining?

4

The first answer here does a good job explaining how the SHA-256 function requires more than one input (an initial one is specified by to the SHA-256 specs). As far as I understand it, the "midstate" value is the initial hash of the first half of the data, used to later serve as an input into the double-hash of the second half of the data.

Is this correct?

And here is an explanation of what the "hash1" value actually is and means, but what is it used for?

ConstableJoe

Posted 2012-10-10T19:56:05.157

Reputation: 615

What do you mean by "half" here? If b=SHA(a=SHA(data)), a = "initial hash" and b = "second half"? So, a is the midstate?Geremia 2015-03-27T04:15:54.990

This defines midstate well; it's "the contents of the 'state' after having processed the first [SHA256] block." Thus, it's not a in b=SHA(a=SHA(data)) if data is longer than one SHA256 block (64 bytes). Isn't the Bitcoin block header 80 bytes?Geremia 2015-06-11T06:21:12.410

Answers

2

1) Yes, it is correct.

2) It is deprecated. Generally, it is used to write the result of the mining over to be sent to the pool. This is to ensure the result is of correct length and adheres to some rules. In practice, it is always the same trailing string of numbers.

ThePiachu

Posted 2012-10-10T19:56:05.157

Reputation: 41 594

So the hash1 value itself is never actually used? It just serves as a formatting template?ConstableJoe 2012-10-11T13:28:09.360

@ConstableJoe Well, it's not used for any calculations, it is deprecated in general and eventually it will be left out of the getwork protocol.ThePiachu 2012-10-11T13:46:18.417

Interesting. Seems pretty useless, unless I'm missing something.ConstableJoe 2012-10-12T03:57:38.807