Is Your Bitcoin Address Quantum-Exposed? A Python Check Before 2027
The first Bitcoin output ever created, in the genesis block, does not lock coins to an address. It locks them to a full public key, 65 bytes printed in plain hex inside the output script. Anyone can read it today with on
The first Bitcoin output ever created, in the genesis block, does not lock coins to an address. It locks them to a full public key, 65 bytes printed in plain hex inside the output script. Anyone can read it today with one API call. Against a classical computer that is fine: getting a private key from a public key on secp256k1 is the discrete logarithm problem, and nobody knows how to do it at that size. Shor's algorithm (Shor, 1994) solves exactly that problem on a large enough quantum computer. No such machine exists yet, and this post makes no guess about when one will.
What you can do now is cheaper than a guess: find out which of your own addresses already have their public key on chain. That is a question about data, and the data is public. Below is a script with no dependencies that answers it for a list of addresses using the free mempool.space API.
Where the public key shows up
Bitcoin has several output types, and they hide the key differently:
- P2PK (pay to public key). Used in the earliest blocks. The key is in the output itself, visible from the moment the coins arrive.
- P2PKH (addresses starting with 1) and P2WPKH (starting with bc1q, 42 characters). The address holds a hash of the key. The key itself appears on chain the first time you spend from that address, because the spending input has to include it so nodes can verify the signature.
- P2SH (3...) and P2WSH (bc1q, 62 characters). A hash of a script. Spending reveals the script, and the public keys inside it.
- P2TR, Taproot (bc1p). The address encodes a 32-byte output key directly. BIP 341 explains the choice in its rationale and says the protection that key hashing gives against quantum computers "is very weak at best" (BIP 341), because a key is exposed anyway while a spending transaction waits for confirmation.
That last point matters for reading the output of any tool like this one. There are two different risks. A key that sits on chain for years is exposed to a slow attack. A key that appears only in the mempool for ten minutes needs a much faster one. The draft BIP 360 (P2MR) uses the same split and calls them long exposure and short exposure attacks. Our script measures long exposure only: whether the key is already sitting in the chain.
What mempool.space gives us
The REST API (docs) has two endpoints we need:
-
GET /api/address/<address>returnschain_statsandmempool_statswith counts of funded and spent outputs and their sums in satoshis. -
GET /api/address/<address>/txsreturns recent transactions with full inputs, includingwitnessandscriptsig_asm.
P2PK has no address string, so /address/ returns 400 for a raw key. The API also has GET /api/scripthash/<hash>, and for P2PK we can build the script ourselves: a push of the key, then OP_CHECKSIG (byte 0xac). The hash it expects is a plain SHA-256 of the script bytes, in normal byte order. I checked both orders against the genesis key: the reversed one returns zero activity, the normal one returns 19 funded outputs.
The script
Standard library only. Save it as qcheck.py:
import hashlib
import json
import sys
import time
import urllib.error
import urllib.request
API = "https://mempool.space/api"
def get(path):
req = urllib.request.Request(API + path, headers={"User-Agent": "qcheck/0.1"})
for attempt in range(3):
try:
with urllib.request.urlopen(req, timeout=20) as resp:
return json.load(resp)
except urllib.error.HTTPError as err:
if err.code == 429 and attempt < 2:
time.sleep(5 * (attempt + 1))
continue
raise
def kind(item):
s = item.lower()
if all(c in "0123456789abcdef" for c in s) and (
(len(s) == 66 and s[:2] in ("02", "03")) or (len(s) == 130 and s[:2] == "04")
):
return "p2pk"
if s.startswith("bc1p"):
return "p2tr"
if s.startswith("bc1q"):
return "p2wpkh" if len(s) == 42 else "p2wsh"
if item.startswith("1"):
return "p2pkh"
if item.startswith("3"):
return "p2sh"
raise ValueError(f"unknown format: {item}")
def p2pk_stats(pubkey_hex):
key = bytes.fromhex(pubkey_hex)
script = bytes([len(key)]) + key + b"\xac" # <push key> OP_CHECKSIG
return get("/scripthash/" + hashlib.sha256(script).hexdigest())
def revealed_key(address, k):
"""Find a spend from this address and pull the public key out of it."""
for tx in get(f"/address/{address}/txs"):
for vin in tx["vin"]:
if vin.get("prevout", {}).get("scriptpubkey_address") != address:
continue
if k == "p2wpkh" and len(vin.get("witness", [])) == 2:
return vin["witness"][1]
if k == "p2pkh" and vin.get("scriptsig_asm"):
return vin["scriptsig_asm"].split()[-1]
return None
def check(item):
k = kind(item)
data = p2pk_stats(item) if k == "p2pk" else get("/address/" + item)
chain, pool = data["chain_stats"], data["mempool_stats"]
funded = chain["funded_txo_count"] + pool["funded_txo_count"]
spent = chain["spent_txo_count"] + pool["spent_txo_count"]
balance = (chain["funded_txo_sum"] + pool["funded_txo_sum"]
- chain["spent_txo_sum"] - pool["spent_txo_sum"])
key = None
if k == "p2pk":
status, key = "EXPOSED: key sits in the output script", item
elif k == "p2tr":
status = "EXPOSED: tweaked key is the address itself"
elif spent and k in ("p2pkh", "p2wpkh"):
status = "EXPOSED: key revealed by an earlier spend"
key = revealed_key(item, k)
elif spent:
status = "EXPOSED: script and its keys revealed on spend"
elif funded:
status = "hidden behind a hash until first spend"
else:
status = "unused"
note = ""
if status.startswith("EXPOSED") and balance > 0 and k not in ("p2pk", "p2tr"):
note = "funds still here: move to a fresh address"
return k, funded, spent, balance, status, key, note
def main(items):
print(f"{'type':7} {'in':>5} {'out':>5} {'balance BTC':>14} status")
for item in items:
k, funded, spent, balance, status, key, note = check(item)
print(f"{k:7} {funded:5} {spent:5} {balance / 1e8:14.8f} {status}")
print(f" {item[:24]}...")
if key:
print(f" public key: {key[:20]}...")
if note:
print(f" {note}")
time.sleep(1) # be polite to the free API
if __name__ == "__main__":
main(sys.argv[1:])
A few decisions worth explaining. Mempool stats are added to chain stats, because a spend waiting in the mempool has already published the key. The revealed_key function is not needed for the verdict, but it turns "trust me" into proof: it prints the actual key taken from the spending input. For P2WPKH that is the second witness item, for P2PKH the last push in the scriptSig. And the one-second pause is there because the public API rate limits, and a 429 is handled with a short backoff.
Running it on real addresses
I picked five addresses anyone can look up:
- The genesis block public key (P2PK).
-
1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa, the P2PKH address made from that same key. -
bc1qahetl9xeeuu4sr42xru6lealsp4kcuxhygd4ak, a valid address I derived from a hash for this test. It has never appeared on chain. -
bc1qcr8te4kr609gcawutmrza0j4xv80jy8z306fyu, the first receive address from the test vectors in BIP 84. -
bc1p5cyxnuxmeuwuvkwfem96lqzszd02n6xdcjrs20cac6yqjjwudpxqkedrcr, the first receive address from the test vectors in BIP 86.
$ python -I qcheck.py 04678afdb0fe...1d5f 1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa bc1qahetl9xeeuu4sr42xru6lealsp4kcuxhygd4ak bc1qcr8te4kr609gcawutmrza0j4xv80jy8z306fyu bc1p5cyxnuxmeuwuvkwfem96lqzszd02n6xdcjrs20cac6yqjjwudpxqkedrcr
type in out balance BTC status
p2pk 19 0 50.01036288 EXPOSED: key sits in the output script
04678afdb0fe5548271967f1...
public key: 04678afdb0fe55482719...
p2pkh 83634 0 57.73100959 hidden behind a hash until first spend
1A1zP1eP5QGefi2DMPTfTL5S...
p2wpkh 0 0 0.00000000 unused
bc1qahetl9xeeuu4sr42xru6...
p2wpkh 91 91 0.00000000 EXPOSED: key revealed by an earlier spend
bc1qcr8te4kr609gcawutmrz...
public key: 0330d54fd0dd420a6e5f...
p2tr 15 15 0.00000000 EXPOSED: tweaked key is the address itself
bc1p5cyxnuxmeuwuvkwfem96...
Numbers are from December 5, 2026 and will move as people keep sending to these addresses.
Three things in that table are worth a second look.
The BIP 84 address shows 91 outputs received and 91 spent. Its private key is published in the BIP, so every deposit gets swept by whoever watches it. The public key the script pulled from a spend, 0330d54f..., matches the one listed in BIP 84 for that address, which is a nice check that revealed_key reads the right witness item.
The second row says "hidden", and that is wrong in a way the script cannot see. 1A1z... is the hash of the genesis key, and the genesis key is printed in full in row one. Key reuse across output types leaks the key even if the address itself was never spent from. If you ever used the same key for an old P2PK output, a legacy address and a SegWit address, treat all of them as exposed.
The Taproot row would say "EXPOSED" even with zero history. That is by design, as BIP 341 explains, and it is a real trade-off, not a bug in Taproot.
What to do with the result
No panic is needed here, and nothing in this table says your coins are at risk today. Shor's algorithm needs a quantum computer far larger than anything public, and NIST is already planning the move away from quantum-vulnerable signatures in its draft transition report IR 8547. What the table gives you is a list of habits to fix while it is cheap:
- Do not reuse an address after spending from it. Most HD wallets already create a fresh change address for every transaction, so ask for a fresh receive address too.
- If a row says "funds still here: move to a fresh address", that address has spent before and still holds coins. Sweeping the remainder to a new address puts the key back behind a hash.
- Never paste a test vector address or a seed phrase from documentation into a real wallet. Row four shows what happens to the money.
We keep a longer list of storage habits in our wallet security checklist for 2027, and plain-language guides on wallets and keys at Token Alphabet. The source of the checklist site is open in the tokenalphabet-ui.github.io repository, and pull requests that add a quantum section are welcome.
One limitation to keep in mind: /address/<addr>/txs returns only the most recent transactions, so for a very busy address the key extraction can miss the spend and print nothing. The verdict still works, because it relies on the counters.
How do you handle address reuse in your own wallet code: do you block it, warn about it, or leave it to the user?
Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.