8:00 in ▪
7
min read ▪ with
Addresses are at the heart of how Bitcoin transactions work. They are public key encodings.
From the public key to the address
Generating a Bitcoin address requires above all a public key which goes hand in hand with a private key.
The two keys are created together using elliptic curve cryptography. The curve used in the Bitcoin protocol is called secp256k1.
Keys are essentially large numbers connected by a mathematical relationship obtained through this elliptic curve.
The equation of the elliptic curve secp256k1 is that each of the keys obtained is at most 256 bits. Instead of expressing it in figures, we use the hexadecimal format. We are talking about base16 format (0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F).
256-bit hex keys are 64 characters long. Example of a private key in hexadecimal:
e9873d79c6d87dc0fb6a5778633389f4453213303da61f20bd67fc233aa33262
In decimal (base 10):
105627842363267744400190144423808258002852957479547731009248450467191077417570
In binary (base2):
11101001100001110011110101110011100011011011000011111011100000011111110110101001
0101110111100001100011001100111000100111110100010001010011001000010011001100000011
11011010011000011111001000010111101011001111111000010001100111010101000110011001001100010
The key expressed in binary is 256 bits (256 0 or 1), you can count.
The corresponding public key (in hexadecimal) is:
02588d202afcc1ee4ab5254c7847ec25b9a135bbda0f2bc69ee1a714749fd77dc9
Public keys are often confused with addresses by mistake. Addresses have long been used instead of public keys to perform transactions.
Public keys are now hidden behind “addresses”. Here is the process to convert a public key into an address:
1) Pass the public key in SHA-256.
2) Pass the hash found in RIPEMD-160 (which also has a hash function).
3) Put at the beginning of this hash the code corresponding to the type of address.
4) Pass everything through SHA-256.
5) Run through the SHA-256 grinder again.
6) Take the first four bytes of the hash (check) and add them to the hash obtained in step 3. You will then receive a 25-bit bitcoin address.
7) Convert the address to base58 format.
What is SHA-256, RIPEMD-160, Base58?
Replace “Secure-Hash Algorithm” with SHA-256. This function returns a 256 bit hash of whatever is given as input.
This is a one-way function. So it is not possible to guess what was given as input from the output hash.
If we give as input “I likeBitcoin” in SHA-256, we get this hash:
d244eafee6196a053e89d91999d33adfdc46a82b0a595f32b65d11c69a2c13cc
If we say “I like bitcoin” instead (with lower case b), we get this hash:
dcf280d6205d22f155ef5523bb39874801dc56125f34ad41a6965c3bc5d88a39
The hash is completely different. This is known as the “avalanche effect”. A very small input modulation changes the output result significantly.
RIPEM-160 is also a hashing algorithm. Except that the length of the hash is only 160 bits.
Why use two different algorithms?
RIPEMD-160 shortens the size of hashes. This reduces the amount of memory required to run a node. This reinforces the decentralization of the web. This makes transactions less complex and therefore cheaper.
SHA-256 adds a level of security, against the quantum threat for example.
Base58 is used to remove the characters 0, O, I and la. This avoids errors by misplacing them when reading the address. It also shortens the length of the address a little more.
Finally, the address type code to distinguish between different types of addresses. Full list HERE.
Example of address creation
You must initialize a public key:
02588d202afcc1ee4ab5254c7847ec25b9a135bbda0f2bc69ee1a714749fd77dc9
1) Enter the public key in SHA-256 which will give a 256-bit hash:
9d302083dadf92b38dcb1c626c842602dbb091466e30ed2a4763cd8ac67c0a9f
2) Enter this hash into RIPEMD-160 (which is also a hash function that gives a 160-bit hash):
956e88bf3eda9fa4a228f55e10c9f8f7e2518f97
3) Add the transaction type code to the beginning of the hash from RIPEMD-160:
[00]956e88bf3eda9fa4a228f55e10c9f8f7e2518f97
4) Go back to SHA-256:
77af09c704b3c235c504d17c69a5b22543567afcb86b0f6f6c89d978e8ef1f10
5) Go back a second in SHA-256:
3ca359f964d6629ec7c114a032826b2baf66bb35b4350ab82f5864a65a1cefab
6) Take the first four bytes of the hash (check) and add them to the hash obtained in step 3. Then you get a 25-bit bitcoin address:
[00]956e88bf3eda9fa4a228f55e10c9f8f7e2518f97[3ca359f9]
7) Convert the address to base58 format.
1Ed86dcxMQqFkmF89n7PTRPUku7h25j5m2
So. It looks a lot like one of the addresses in your wallet, doesn’t it?
By the way, the “check” allows the wallet to check if there is a typo in the address provided. It would be a shame to send BTC to the wrong address.
Thanks to the check, the probability of entering an incorrect address is only 1 in 4.3 billion. So don’t worry about entering the wrong key.
Furthermore, the number of Bitcoin key pairs that can be created is 2^160. The probability of a lucky person getting these BTCs is almost zero. BTC will be lost forever.
Summary
There are different types of addresses. The one we described is called a P2PKH (Pay-to-public-key-hash) or “Legacy” address. This is the oldest type of address. They start with “1”.
There are many other types of addresses, such as:
-The addresses P2WPKH (Pay with Witnesses-Public-Key-Hash). They are encoded in Bech32 rather than base58 and start with “bc1”.
-The addresses P2SH (Pay-to-Script-Hash). They start with “3”.
Briefly, a private/public key pair is generated using elliptic curve cryptography. The public key then goes through SHA-256, RIPEMD-160 and base58 milling to create an address. This is a representation of the public key.
A set of addresses is called a “wallet”. The latter does not host bitcoins per se, but private keys.
Addresses are publicly available information used to complete transactions. Note that, concretely, a transaction is the creation of one (or more) UTXO.
UTXOs (small pieces of code) are scripts that link a certain amount of BTC to an address (public key) that the nodes jealously guard in memory. More information: UTXO and Privacy.
Only the one with the private key corresponding to the public key can unlock (sign) the script and make a transaction, ie connect the BTCs to a new address.
Get a summary of the news in the world of cryptocurrencies by subscribing to our new service
daily and weekly so you don’t miss any of the essential Cointribune!Journalist reporting on the Bitcoin revolution. My papers deal with bitcoin through geopolitical, economic and libertarian prisms.