Bitcoin Forum

Other => Beginners & Help => Topic started by: The Networker on November 11, 2013, 01:32:09 AM



Title: Protocol specification: double hash clarification
Post by: The Networker on November 11, 2013, 01:32:09 AM
The protocol specification https://en.bitcoin.it/wiki/Protocol_specification (https://en.bitcoin.it/wiki/Protocol_specification) states:

Example of double-SHA-256 encoding of string "hello":

2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824 (first round of sha-256)
9595c9df90075148eb06860365df33584b75bff782a510c6cd4883a419833d50 (second round of sha-256)


I cannot work out the second round correctly. Is this formula supposed to be used to do that?

dhash(hello) = sha256(sha256(hello))

If so, the first round makes 2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824 correctly.

But the second round sha256(2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824) doesn't produce the value stated in the spec.

Could you please help wrap my head around that one?

Thanks.



Title: Re: Protocol specification: double hash clarification
Post by: bee7 on November 11, 2013, 01:34:50 AM
the second round should be taken on a binary representation of the first round result, not an ascii alphanumeric.


Title: Re: Protocol specification: double hash clarification
Post by: DannyHamilton on November 11, 2013, 01:37:18 AM
If so, the first round makes 2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824 correctly.

But the second round sha256(2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824) doesn't produce the value stated in the spec.

Could you please help wrap my head around that one?

99.99% of the time when someone comes asking this question (yes, it has been asked MANY times), it is because on the second round they are incorrectly hashing the string "2cf24db..." instead of the hex value 0x2cf24db...

You need to hash it as a numeric value and not as a string.