-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Endianness reversed #1061
Comments
The quoted text is the phrasing I found other documentation using, which is why it says:
I think maybe the best solution is to remove the labels "big endian" and "little endian" so that the examples speak for themselves. Does that sound like an adequate solution to you? (If so, I'll update the doc.) |
I would recommend removing it. I have never seen RPC byte order be referred to as little endian anywhere else. There is indeed at least one possible contradiction one the bitcoin wiki on this https://en.bitcoin.it/wiki/Block_hashing_algorithm states https://en.bitcoin.it/wiki/Protocol_documentation One refers to merkle tree hashes, and one refers to hashes in general. Perhaps byte order varies with different fields/values? |
Yeah, I agree with you both (@bedeho and I were diving into endianness in a few exchanges), I think maybe removing the labels "big endian" and "little endian" make sense, and providing another concrete example (perhaps a block header hash, since its hash value always has to be less than the target difficulty, and as the wiki link illustrates, can provide a nice anchor to describing byte order). |
"big endian" and "little endian" are the proper technical terms for describing the two possible byte orderings. I think @bedeho is right that the big/little column headings are currently swapped. To me the pedagogically confusing part of the section is the use of "standard" and "reversed". From a human perspective, big-endian numbers are "standard". For an x86 Linux computer, little-endian numbers are "standard". There is no "standard" Unix endianness. Please allow me a couple days to take a stab at rewriting the section. |
@carnesen sure, please feel free to rewrite. (But note that I used standard to mean the byte order universally used to display SHA256 output, which is meant as a string not a number.) |
Note: The displayed block hashes are indeed little endian. Bitcoin's PoW comparison with the target flips the hash around. |
This issue has been dealt with before in #580 , and @SergioDemianLerner seemed to conclude that:"there is not such thing as little-endian or big-endian transaction hash digest. " I am not familiar with the structure of the output of the various hashing algorithms, but I agree that endianness of byte order is only relevant in so far as bytes actually vary in significance (i.e. most vs. least). The byte representation of lots of data (e.g. text) does not have such significance, yet it certainly matters what order it is interpreted, hence the two are not the same. |
Ah, I see. Output of SHA256 is a byte array (a.k.a. its hex-encoded string Edit: By "byte array" I meant "byte array with an ordering uniquely specified by the algorithm" |
@carnesen I basically see it exactly as you just described it. |
Opened #1105 to drop endian references. That PR also provides a suggestion for an alternative way to describe the issues for anyone who really likes thinking about endianness problems. :-) |
FWIW, more endian "fun" coming soon... apparently versionbits will number the bits:
I don't care enough to argue for fixing this, so I guess it'll be left for documentation to deal with. :( |
The "Hash Byte Order" section does a good job of trying to highlight the issue of txid/blockid byte order confusion,but the titles of the last table unfortunately gives the opposite interpretation what it should be.
As written, RPC byte order of block ids have leading zeros, this would be recognized as big endian, as these digits are most significant - given the very fact that hashing involves minimizing this value. However, the titles on the table have this reversed in the parentheses (“Big Endian”) and (“Little Endian”).
The text was updated successfully, but these errors were encountered: