Bitcoin: Having Address format, infer derivation path or BIP used
Deciphering the Derivation Path of a Bitcoin Address
Hello, fellow Bitcoiners.
While studying Bitcoin, I came across a problem I wanted to address: how can I determine which derivation path a particular Bitcoin address 1xxxxxxxxxxx was created with? In this article, I will provide information on how to infer the derivation path from a given address.
Understanding the Bitcoin Address Format
Before we dive into the derivation path, let’s quickly review how Bitcoin addresses are structured. A Bitcoin address consists of eight hexadecimal characters, divided into three parts:
- Version: The first four characters represent the Bitcoin protocol version.
- Checksum
: The next two characters are a checksum, used to verify the integrity of the transaction data.
- Index: The last four characters represent the index in the blockchain.
Derivation Paths
Bitcoin uses a cryptographic technique called Elliptic Curve Diffie-Hellman (ECDH) to derive private keys from public keys. The derivation path is based on the following rules:
- For each derivation step, we need two parts:
+
Public key
: x
+
Shared secret: y
Inferring the derivation path from the address
Now, let’s apply these rules to infer the derivation path from a given address.
- Check if the first four characters are a version number (0x…). If not, the address is unlikely to be valid.
- Extract the checksum (the last two characters) and verify its integrity using tools such as the
gethash
command in the terminal or by checking with your local Bitcoin client.
If both checks are successful, we can proceed to extract the index of the next four characters:
- Take the last four characters (
xxxxxxxxx
) as input for our ECDH derivation.
- Compute the corresponding shared secret
y
using a key generator such assecp256k1-gen
.
Once you have obtained y
, you can derive your public key x
by performing a modular exponentiation with p-1
(where p
is the maximum block weight of the network). This will generate another random number.
Example Tutorial
Suppose we have a valid address 1234567890abcdef, where:
- The first four characters are not a version number.
- The checksum is correct.
- We extract the index of
xxxxxxxxxxx
.
This is how we can calculate the shared secret and public key using Python code:
import hashlib
Define ECDH parametersp = 1_000_000_007
Maximum network block weight (256 bits)q = p * p
n = q - 1
e = 65537
d = e ** (-1)
Derive the shared secret y using the BLS signature schemey = hashlib.blake2b((p, n) + ((hashlib.sha256(b'') + bytes([x])).digest(),)).digest()[:32]
Calculate the public key x by modular exponentiation with p-1public_key_x = pow(y, d, p - 1)
The derived private key y is our input for further Derivation
Conclusion
In conclusion, deciphering the derivation path of a Bitcoin address requires knowledge of the ECDH algorithm and tools such as gethash
to verify the checksum. By following these steps, you can infer the derivation path from a given address, which can be useful in various applications such as wallet verification or private key management.
However, please note that this is just an example and may not cover all possible scenarios or edge cases. Always consult with experts or use trusted sources when working with cryptographic systems.
I hope this article was helpful! Do you have any questions or would you like to learn more about Bitcoin?
Bir cevap yazın