3

I am studying how the Bitcoin addresses generation works.

As far as I learned, a Bitcoin address appears in the blockchain only after it has been involved in its first transaction. If an address has never been used in any transactions, it will not have a presence in the blockchain.

For this reason, Initially, I believed that without knowledge of the private key, there would be no way to verify if a given address is a correct hash generated from real key, or simply a random/made-up combination of characters of the same length (like some of those "vanity-addresses").

However, today I discovered that when I enter a genuinely generated BTC address that has never been used before (for sure) into the search field on blockchain.com, the latest displays a message indicating that the address is found but has no transactions.

screenshot1_real

screenshot2_real_no_transactions To generate addresses, I used bitaddress.org and this python lib, I tried multiple times, using both, but the results always generally look like ones above.

On the other hand, when I change a single character in such an address or enter random digits and letters that visually resemble a BTC address (including length) but were not generated using the mentioned lib/service, blockchain.com states that "Nothing found."

screenshot3_madeup

How do the service distinguishes between real and made-up addresses, in this case?

2 Answers 2

6

Bitcoin transactions on-chain do not have addresses. They have scripts as output. In theory, pretty much any script is legal on-chain (ignoring standardness rules), including many unspendable ones.

To make things more convenient to work with for humans, certain standard scripts (in particular, P2PKH, P2SH, P2WPKH, P2WSH, and P2TR ones) have a human-readable notation associated with them, known as addresses (in base58, bech32, or bech32m format). These addresses include a checksum to protect against typos; a truncated double-SHA256 one for base58, a BCH one for bech32(m). This checksum, like the address itself, does not exist on-chain.

Software that interacts with the blockchain will generate/show scripts in address form (which means adding the checksum), and typically only accept entering scripts in address form (which means verifying the checksum in it). That holds for:

  • Wallets, when creating a new receive address.
  • Block explorers, when showing the scripts in transactions.
  • Wallets, when sending.

So how does the block explorer know the address it shows is valid?

  • If it's something you search for, it takes the address you input, parses it, verifies its checksum, converts it to a script, and searches its database for it. Even when nothing is found, the script is valid, so it can show that there are no results. If the checksum was invalid, it would instead tell you that the address is invalid.
  • If it's something found in a block or transaction, the explorer converts the scripts to their address form (including correct checksum), and shows you that.

In neither case is it certain that anyone has the corresponding key, unless there are also spends of the funds received to the address in question. In particular, one can compute scripts that look like a given string in address form easily, if one does not care about finding the corresponding private key.

2
  • Thank you for the detailed explanation! Would you mind If I ask you to add the details on this part: "it takes the address you input, parses it, verifies its checksum, converts it to a script"? It would be greatly appreciated if you could provide either the exact algorithm or offer a slightly more elaborate description of the steps involved, with any examples.
    – Alex
    Jun 19 at 15:28
  • 1
    @Alex For the modern address formats (bech32 and bech32m), see the linked BIPs 173 and 350, which include test vectors, pseudocode, and links to reference code. For P2PKH and P2SH addresses with Base58 encoding, see en.bitcoin.it/Base58Check_encoding Jun 19 at 15:33
4

An address is a standardized encoding of an output script with a checksum. Because of this checksum, a blockchain explorer can (with a high probability) tell between a valid and an invalid address.

However, a valid address doesn't mean anyone has the private key(s) to be able to spend from it, or even that such a key exists. All the blockchain explorer can tell you is whether the address has ever received funds (which any valid address can) and spent funds (in which case the private key exists and someone has access to it, or at least had at some point).

As a side note, addresses don't actually appear in the blockchain, only output scripts, which the blockchain explorer then converts to addresses (provided that the script has a standard address encoding).

7
  • Thank you! I would like to dive more into the subject, could you point in which direction I should look to learn more about "encoding of an output script with a checksum" (a little bit more specifically) and how does blockchain explorer uses it to predict if the address is valid or invalid? Also, you say "received funds (which any valid address can)". But what about 1CounterpartyXXXXXXXXXXXXXXXUWLpVr? It has 2000 BTC, but doesn't seem to be a valid (if we talk about checksum) address. Or doesn't it?
    – Alex
    Jun 17 at 14:06
  • @Alex The 1Counterparty address is valid. It's just that almost certainly, nobody has the corresponding private key, so those 2000 BTC won't ever move. But there is no way for Bitcoin software to know that nobody has the private key for it, so sending to it is valid. Jun 17 at 14:20
  • 1
    Also note that this checksum does not exist on-chain (just like the rest of the address). You can send to any script, in theory. Some scripts (and practically, all the ones that are used) have a convenient human-friendly encoding that includes a checksum, called the address. In practice, wallet software will only let you send to scripts if you enter the corresponding valid address. The block explorer computes the address, including the checksum, based on the on-chain data. Jun 17 at 14:48
  • 1
    @PieterWuille Omg, so many thanks! You reminded me that I read somewhere, and now I realize that the last 4 bytes on the right side are the checksum (specifically: first 4 bytes of the SHA-256 hash for the initial SHA-256 hash) of the key. Thanks a lot, correct if I am wrong!
    – Alex
    Jun 17 at 14:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.