The Cryptographic Context
The Cryptographic Context
In cryptography, the "Value" of a hash is a mathematical result. Mathematicians generally treat numbers as Big Endian (high-order digits first). This creates a friction point when these results are integrated into the Little-Endian-heavy Bitcoin protocol.
1. SHA-256 Output
When you hash data using SHA-256, the algorithm produces 256 bits.
-
The standard way to represent this result is as a Big Endian hex string.
-
Bitcoin's Tweak: Bitcoin takes that result and reverses the bytes before using it as a TXID or Block Hash.
2. ECDSA Signatures
ECDSA uses two numbers, $r$ and $s$.
-
These numbers are 256-bit integers.
-
In the DER Encoding format used by Bitcoin, these numbers are stored in Big Endian.
-
Unlike transaction IDs, signatures are NOT flipped. They remain in the natural order defined by the cryptographic standard.
3. Public Keys (SECP256K1)
A public key is a point on an elliptic curve with coordinates $(x, y)$.
-
The $x$ and $y$ coordinates are massive 256-bit numbers.
-
These are always serialized in Big Endian.
-
Result: If you see a public key starting with
02or03, the following 32 bytes are in the natural order you would expect from a math textbook.
4. The "Internal Hash" Myth
You may hear people refer to the "Internal Hash" vs. the "Display Hash."
-
Internal: The 32 bytes as they appear in the binary code of the blockchain.
-
Display: The 32 bytes as they appear in an explorer. Mathematically, they are the same hash. The only difference is the Order in which the bytes are printed to the screen.
5. Security Implications
Endianness has no impact on the security of the hash. A reversed hash is just as collision-resistant as a natural one. However, the inconsistency can lead to "Implementation Bugs." If a developer reverses a signature by mistake, the signature becomes invalid, and the transaction is rejected.
| Cryptographic Object | Internal Format | Endianness |
|---|---|---|
| Hash Result | SHA-256 | Big Endian |
| Transaction ID | Bitcoin Format | Little Endian (Flipped) |
| Public Key | SEC1 Format | Big Endian |
| Signature | DER Format | Big Endian |
In the next section, we will analyze The Scripting Context (CScript).
TeachMeBitcoin is an ad-free, open-source educational repository curated by a passionate team of Bitcoin researchers and educators for public benefit. If you found our articles helpful, please consider supporting our hosting and ongoing content updates with a clean donation: