The Even/Odd Y-Coordinate
The Even/Odd Y-Coordinate
In order to reconstruct the full public key from a compressed version, we need a "Tie-Breaker" to tell us which of the two possible Y-coordinates to use. This is the role of the 02 and 03 prefixes.
1. Symmetry of the Curve
The Elliptic Curve is symmetric across the X-axis. This means that if $(x, y)$ is a point on the curve, then $(x, -y)$ is also a point on the curve.
-
In "Modular Arithmetic" (which Bitcoin uses), there is no such thing as "Negative." Instead, $-y$ is represented as $(P - y)$.
-
If $y$ is Even, then $(P - y)$ will be Odd (because $P$ is an odd prime number).
2. Choosing the Prefix
When a wallet compresses a public key, it looks at the Y-coordinate:
-
0x02: Used if the Y-coordinate is Even.
-
0x03: Used if the Y-coordinate is Odd.
3. Reconstructing Y
When a node receives a transaction, it performs the following steps:
-
Read the X-coordinate.
-
Calculate $y^2 = x^3 + 7 \pmod p$.
-
Calculate the Square Root of $y^2$. This gives two results ($y_1$ and $y_2$).
-
Check the prefix:
- If prefix is
02, pick the Even result. - If prefix is
03, pick the Odd result.
- If prefix is
4. Why it matters for Addresses
Because the Public Key Hash (PKH) is a hash of the serialized public key, hashing 04... (uncompressed) results in a completely different hash than hashing 02... (compressed).
- Key Insight: One private key has two public keys, which lead to two different addresses. Modern wallets stick strictly to compressed keys to ensure your funds are always in the same place.
| Parity | Prefix | Math Logic |
|---|---|---|
| Even | 0x02 |
$y \pmod 2 == 0$ |
| Odd | 0x03 |
$y \pmod 2 == 1$ |
In the final section, we will build a Python Public Key Auditor.
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: