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
rational to rationale and little and big endian mixup fix #1102
Conversation
harding
added
the
Dev Docs
label
Oct 22, 2015
|
Regarding rational→rationale, if you split that off into a separate commit or PR, I'll apply that right away. For endianness, we were discussing that in #1061 and I think we're waiting for @carnesen to provide a patch. If that doesn't happen soon, I think I'm going to put forward my solution of just dropping the endianness labels and they're a source of never-ending confusion and debate. |
|
My bad, I think I mostly figured out what's going on under the hood so far On Thu, Oct 22, 2015 at 9:44 AM David A. Harding notifications@github.com
|
|
@harding just broke out the typo into #1103. I quickly looked through the Bitcoin Core code and the FIPS PUB 180-4 (that specifies SHA-256) and I haven't made up my mind on the endian-ness wording yet. The spec probably defines the endian-ness, but it is a matter of constructing a few sections together to get that interpretation and I need to re-read it to make sure. EDIT: Also, I hadn't seen the discussion in #1061 so I want to check that out to take it into consideration too. |
harding
added a commit
to harding/bitcoin.org
that referenced
this pull request
Oct 23, 2015
|
Here is my current thinking on the endianness topic. First, we must determine whether the SHA-256 result should be considered a 256-bit integer or simply an array of 32 bytes. If considered to be a 256-bit integer, then based on sections 2.2.1, 3.1 2, and 6.2.2 of FIPS PUB 180-4 (http://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.180-4.pdf) and Bitcoin Core's implementation of SHA-256 (https://github.com/bitcoin/bitcoin/blob/c719cefc417cc578f48b33069b764339a61054ce/src/crypto/sha256.cpp#L174-L181) I think that a fair case could be made that it is a big-endian value. For our purposes though, I think it is more natural to think of the SHA-256 result as being simply an array of 32 8-bit bytes (aka a blob). Basically, depending on your perspective, you could correctly consider the same sequence of bytes in memory as being either a blob, a single big-endian value, or a single little-endian value. Thus, I essentially agree with Sergio's comment #580 (comment) I've adapted my proposed commit. Looks like @harding was doing some work concurrently. However you want to handle this is fine with me. I might have to fix some formatting in this latest commit anyways. |
harding
referenced this pull request
Oct 23, 2015
Merged
Dev Docs: drop mention of endianness in hash byte order #1105
|
I just reviewed this updated PR, and I'll probably adapt some of it into #1105 (particularly the terminology). |
|
@luke-jr wow. And I thought nBits was weirdest data type in Bitcoin. |
|
@harding Yes, dropping endian references in this DevDoc and then linking out to the wiki for more detail could make sense. The FIPS pub and code references probably make more sense in a more detailed wiki entry or appendix rather than in-line. I'll be happy to review what you do for #1105 if you want me to close this PR. It's funny how I initially thought this PR would be a quick update and then how much more complex it really was in the code and FIPS spec when I went down the rabbit hole. |
|
handled by #1105 |
mruddy commentedOct 22, 2015
Two small fixes:
Fixed a typo "rational" -> "rationale"
Fixed a mixup between big and little endian.
About the big and little endian mixup, here's my reasoning:
https://en.bitcoin.it/wiki/Block_hashing_algorithm:
"Note that the hash, which is a 256-bit number, has lots of leading zero bytes when stored or printed as a big-endian hexadecimal constant, but it has trailing zero bytes when stored or printed in little-endian."
Example, double sha256 hash of block 300,000 header:
The result is internal byte order (verified by checking the previous block hash of block header 300,001) and little endian (trailing zeros).
Also, as a double check, this verifies that the definition of "internal byte order" is consistent with the first example in the table and should be labeled as little endian: