This repository holds the paper Practical Quantum Safe Bitcoin, its implementation and benchmark records, and a Lean formalization of its mathematical results. The paper builds two instances of practical quantum safe Bitcoin (PQSB): Legacy PQSB (PQSB-legacy in the paper), which depends on legacy Bitcoin Script, and SegWit PQSB (PQSB-segwit), which supports SegWit v0. They give three improvements:
The level tables below give each setting's figures, and BENCHMARKS.md what was measured and what is estimated. Computation costs are separate from Bitcoin transaction fees.
The builder walks through a spend in either mode: pick SegWit or Legacy PQSB, mainnet or regtest, and a security level with its expected time to sign on your hardware; then set up the vault's secrets, fund the vault, and spend it. Each payment requires a new set of secrets, so the builder makes a new vault for each and keeps a list of them. It comes as a page in your browser and as the same steps in the terminal, and both run the commands of pqai-btc-everything/implementation-app/ on your own machine.
You need Python 3.12 or later (no packages), a C compiler for the solver, and Rust for the consensus library that checks every transaction. On Windows, run everything in WSL2 (Ubuntu 24.04 or later): the build script and the tools expect Linux or macOS. On Ubuntu (or WSL2), sudo apt install git build-essential gives git and the C compiler, and rustup installs Rust. Build once, then run everything below from implementation-app:
git clone https://github.com/EspressoSystems/PQSB.git cd PQSB/pqai-btc-everything/implementation-app solver/build.sh # the solver: CPU builds, Metal on Apple silicon, CUDA where nvcc is found (cd verifier && cargo build --release) # Bitcoin Core's consensus library
With an NVIDIA GPU, solver/build.sh also builds the GPU solver, search, once nvcc (the CUDA compiler) is on the PATH, and the tools then use it instead of the CPU. On Linux, install NVIDIA's CUDA toolkit. On Windows, the NVIDIA driver you have already serves WSL2: install only the toolkit inside WSL2, from NVIDIA's WSL-Ubuntu repository (sudo apt install cuda-toolkit after adding it), and never a Linux driver. Then put /usr/local/cuda/bin on the PATH and run solver/build.sh again. nvidia-smi shows the GPU and the newest CUDA version its driver takes; the toolkit must not be newer.
In the browser:
python3 tools/pqsb_app.py # opens the page on 127.0.0.1 and prints its address
In the terminal:
python3 tools/pqsb_cli.py # asks each step in turn; q quits, and running it again goes on where it stopped
Try it on regtest first. With Bitcoin Core installed, choose Regtest on the page, give it the folder that holds bitcoind, and start the regtest node: its wallet of play coins pays the vault and mines the transactions for you. In the terminal:
BITCOIN_BIN=/path/to/bitcoin/bin python3 tools/pqsb_cli.py --regtest
New vaults start at 80 bits for SegWit and 124 for Legacy, and any level of the tables can be chosen; for SegWit with real value choose 80 bits or more. docs/pqsb-app.md describes both in full.
The explorer finds every PQSB transaction on Bitcoin mainnet in the blocks of your own Bitcoin Core node, checks each spend (the script model, Bitcoin Core's consensus library, the relay limits, T's lengths, the pins), and shows them on a static page that reads only a JSON index. The node's RPC stays on localhost; the page never talks to it.
cd pqai-btc-everything/implementation-app python3 -m qsb2 scan --follow --mempool # from block 978,243 to the tip, then each new block; writes explorer/index.json python3 -m http.server -d explorer 8000 # the page, explorer/index.html, at http://127.0.0.1:8000/
docs/explorer.md covers the node's setup, running the scanner as a service, and publishing the page.
| path | what it is |
|---|---|
Paper/introspection-pqsb.pdf |
the paper, Practical Quantum Safe Bitcoin; its LaTeX source is Paper/introspection-pqsb.tex, with Paper/references.bib |
Paper/introspection-lean/ |
the Lean 4 development of the paper's introspection-signature framework |
pqsb-lean/ |
the Lean 4 formalization: machine-checked proofs of the paper's counting, work and forgery bounds, and its parameter figures |
pqai-btc-everything/ |
the implementation and benchmark archive |
pqai-btc-everything/BENCHMARKS.md |
the benchmarks against the paper's figures, each marked measured, estimated or the paper's |
pqai-btc-everything/benchmarks/ |
the RTX 5090 and MacBook M3 reports, and every setting of the paper at each machine's rates |
pqai-btc-everything/implementation-app/ |
the implementation with the builder: both locks (SegWit PQSB with pins), the solver with the GPU searches of both, the page and the CLI |
pqai-btc-everything/implementation-main/ |
an earlier snapshot: both locks, with SegWit PQSB's lock without pins, the P2WSH solver, the tests, and that lock's mainnet spend |
pqai-btc-everything/implementation-cuda/ |
a snapshot with the GPU search of Legacy PQSB for NVIDIA GPUs |
pqai-btc-everything/implementation-metal/ |
a snapshot with an earlier Metal build for Apple silicon; the M3 GPU figures come from the later build in implementation-app/ |
This is experimental software. Do not trust it with coins you cannot afford to lose.
docs/security.md. pqsb-lean/ checks the paper's mathematics, not the scripts: no proof has been machine-checked for the scripts themselves.lock.json can lose the coins for good.Run every step on regtest first, then lock a small amount.
A level is the classical forgery work, in bits: a forger who holds the openings of one spend succeeds with chance at most 2^-level a try. The signer's tries are the expected tries to find a spend. The times are expected times at the rates the optimised solvers of implementation-app/ measured on each machine; BENCHMARKS.md gives the measured spends, most of which ran on the builds before.
SegWit PQSB: the P2WSH lock with pins (docs/pins.md). The spend is standard: any node relays it.
The table is a subset of the possible settings: a search over 7 to 10 positions, 1 to 6 pins and up to 127 commitments finds many layouts within P2WSH's limits, and these are some of those that need the fewest tries for their level. Levels 87 and 95 use 8 positions and 6 pins: about a bit below 88 and 96, for a quarter of the tries.
| level | positions | commitments | pins | lengths of T | bytes | signer's tries | RTX 5090 | MacBook M3, GPU | 4 x86 cores |
|---|---|---|---|---|---|---|---|---|---|
| 64 | 9 | 79 | 4 | 58, 8 × 59 | 1,985 | 2^15.79 | under a second | under a second | under a second |
| 72 | 9 | 79 | 4 | 57, 8 × 59 | 1,985 | 2^23.79 | under a second | under a second | under a second |
| 80 | 9 | 79 | 4 | 56, 8 × 59 | 1,985 | 2^31.79 | under a second | 73 s | 88 s |
| 87 | 8 | 88 | 6 | 55, 7 × 59 | 2,176 | 2^37.79 | 59 s | 77 min | 94 min |
| 88 | 9 | 79 | 4 | 55, 8 × 59 | 1,985 | 2^39.79 | 4 min | 5.2 hours | 6.3 hours |
| 95 | 8 | 88 | 6 | 55, 58, 6 × 59 | 2,176 | 2^45.79 | 4.2 hours | 14 days | 17 days |
Every script has 201 operations. A spend is about 1,060 vB with 9 positions and about 1,076 vB with 8. The columns take 4.05 billion tries a second on the RTX 5090 (over 2^35 tries at level 80, on the lock without pins), 51.2 million on the M3's GPU (2^30 tries at level 72; two spends of the lock with pins at level 80 measured 51.6 million) and 42.1 million on four cores of an Intel Xeon with the SHA extensions and AVX-512 (level 64): docs/opt-cuda.md, docs/bench-macbook-metal.md and docs/opt-cpu.md in implementation-app/. The first SegWit PQSB, the P2WSH lock without pins (docs/p2wsh.md), is no longer built.
Legacy PQSB: the legacy lock with four components (docs/legacy.md). A nonce component and three subset components over one list of secrets, each with its own vector of committed scalars. Both transactions are nonstandard and go to a miner directly.
| level | D | list, openings | scalars | signer's tries | RTX 5090 | MacBook M3, GPU | 4 x86 cores |
|---|---|---|---|---|---|---|---|
| 92 | 57, 57, 57, 57 | 206; 4, 4, 4 | 30, 37, 40, 43 | 2^19.80 | under a second | under a second | under a second |
| 100 | 56, 57, 57, 57 | 206; 4, 4, 4 | 30, 37, 40, 43 | 2^26.11 | under a second | 1 s | 2 s |
| 108 | 56, 56, 57, 57 | 206; 4, 4, 4 | 30, 37, 40, 43 | 2^27.25 | under a second | 7 s | 11 s |
| 116 | 56, 56, 56, 57 | 206; 4, 4, 4 | 30, 37, 40, 43 | 2^28.05 | under a second | 14 s | 24 s |
| 124 | 56, 56, 56, 56 | 206; 4, 4, 4 | 30, 37, 40, 43 | 2^28.71 | under a second | 24 s | 41 s |
| 132 | 55, 56, 56, 56 | 222; 4, 4, 4 | 48, 26, 26, 27 | 2^35.15 | 9 s | 12 min | 20 min |
| 140 | 56, 56, 55, 55 | 230; 3, 4, 5 | 28, 29, 30, 28 | 2^41.27 | 14 min | 17 hours | 28 hours |
Every script has 198 or 199 operations and 9,987 to 10,000 bytes. Each column uses the component rates the optimised build measured at level 124: on the RTX 5090 4.34 billion nonce tries a second and about 0.6 billion subset tries, on the M3's GPU 53.3 million and about 12 million, on the x86 cores 33.4 million and about 7 million.
The builder above runs these same commands for you. The commands below run in pqai-btc-everything/implementation-app/, after the build above:
cd pqai-btc-everything/implementation-app python3 tests/run.py # the quick tests, about a minute python3 tests/pins.py # SegWit PQSB's lock with pins, and its mainnet spend; about a minute python3 -m qsb2 count # every lock: bytes, operations, figures, times python3 -m qsb2 check-mainnet # the spends of the first P2WSH lock on mainnet, rebuilt and checked from public data
The spend commands run Bitcoin Core's consensus library on every spend before they write it, when verifier/ is built. Build it.
On regtest first. With Bitcoin Core's bitcoind in BITCOIN_BIN, a demo builds a lock, funds it, finds the spend, checks it and mines it on a private regtest node:
export BITCOIN_BIN=/path/to/bitcoin/bin python3 -m qsb2 p2wsh demo --level 64 --real # SegWit PQSB at its real lengths: a second on a CPU python3 -m qsb2 legacy demo --level 124 --D 58 # Legacy PQSB at a low-work length: seconds python3 -m qsb2 legacy demo --level 124 --D 56 # Legacy PQSB at its real lengths: seconds on a GPU python3 tests/run.py --regtest # every demo the tests run
To lock real coins, follow "How to spend" in the implementation README.
Secrets and one use. lock.json holds the secrets. It is written with mode 600; never commit it or send it. A lock is spent once. The tools refuse a second, different spend, which would show more openings.
cd pqsb-lean lake exe cache get # prebuilt Mathlib lake build
pqsb-lean/README.md maps each result of the paper to its Lean theorem.