Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
Already on GitHub? Sign in to your account
Wrong Endianess? #580
Comments
|
@SergioDemianLerner thanks for the report! The reference for that part of the doc is BIP22, which says:
The help RPC for I'll try to confirm this problem myself later today. Thanks again for the report! |
|
@SergioDemianLerner I haven't looked at the Bitcoin Core code, but it looks to me like getblocktemplate (GBT) is returning hashes in the same little-endian order used elsewhere in Bitcoin. Here's the code I ran:
And here are the results I obtained:
Can you confirm that you're getting hashes in the wrong byte order before we investigate further? Thanks! |
SergioDemianLerner
commented
Sep 29, 2014
|
I think I understand the problem: there is not such thing as little-endian or big-endian transaction hash digest. The documentation should read: hash digest values are printed REVERSED. This is because SHA-256 digests are neither big-endian nor little-endian. Again, a hash digest is just an array of bytes. Another misconception is present in https://en.bitcoin.it/wiki/Dump_format which reads: You can check this here: http://stackoverflow.com/questions/6269719/little-endian-data-and-sha-256 The reason why we call transaction hashes little or big endian is because we also use SHA-256 to compute the block hash digest, and then we cast the hash digest to a UINT256 in order to compare it with the target as big-integer. So when the hash is casted, the code is assigning an arbitrary "endianess" to the hash digest. This arbitrary endianess is little-endian, because Bitcoin was written originally for an x86. From this code we interpret "Digest reversed == big-endian". So, again, the documentation should read: hash digest values are printed REVERSED. Without mention of any endianness. Do you agree with this explanation? |
|
@SergioDemianLerner I think that makes a lot of sense. I'll prepare a pull request updating all the areas in the docs where we refer to hash endianness. I'll @ mention you on that pull request so you can review it. Thanks! |
|
Note: pull #583 hopefully addresses this issue. |
|
Closing: this was fixed in commit d5900e3 / pull #583. Thanks again @SergioDemianLerner for reporting it! |
SergioDemianLerner commentedSep 27, 2014
Location: https://bitcoin.org/en/developer-reference#getblocktemplate
The text reads:
Each object in the array contains the rawtransaction data in hex and the hash of the data in little-endian hex.
I looked at the code of base_uint.GetHex() in uint256.cpp and the output hex value is in big-endian format (the internal representation is in little-endian format and GetHex() reverses it).
Am I interpreting it wrong or is the documentation wrong?