# Bitcoin & Ethereum Recovery Lab

A calm, reproducible explainer of one idea: if ordinary signing keys were compromised, an owner who had **already** registered an independent post-quantum authority could prove ownership and move to a new one.

- **Part A, recorded on local test chains.** What an assumed signing-key compromise does: Bitcoin Core regtest, then an Ethereum dev chain (anvil). Fresh disposable keys, real transactions, the nodes' own results.
- **Part B, a modeled rule (not consensus).** A small state machine with real SLH-DSA-SHA2-128s signatures. Every rule has a passing and a failing case.
- **A static website** (`site/`) that replays both parts and re-verifies the signatures in the visitor's browser.

## What it shows, and what it does not

It shows what an assumed key compromise does on a local test chain, and how a small, experimental recovery rule would respond, using signatures anyone can verify.

It does not show that any network is patched or changed, that a quantum computer capable of this exists or is near (none is known to exist; timelines are uncertain), that every account is recoverable (accounts with no earlier post-quantum commitment are not covered), or that any network would adopt such a rule (agreement is not guaranteed). The checkpoint choice and the adoption of the rule are assumptions of the model. Nothing here touches Bitcoin or Ethereum mainnet: no mainnet RPC, address, transaction or key appears anywhere.

## Evidence

`artifacts/evidence.json` is generated by the scripts and never edited by hand.

```
SHA-256  6f927af9b540f02c064c07f94da1a54c21f83804b002e1f6861671c64134be03  evidence.json
```

(`artifacts/evidence.json.sha256` holds the same line; `node scripts/verify.mjs` checks it. A new `record.sh` run produces a new bundle with a new hash.)

## Reproduce

Requires Node 20+ and macOS on Apple silicon for the recording (the verification and the site run anywhere Node runs).

```
npm ci --ignore-scripts          # exact versions from package-lock.json
node scripts/fetch-bitcoin.mjs   # pinned Bitcoin Core, hash cross-check (see below)
scripts/record.sh                # record, assemble evidence.json, verify
node scripts/verify.mjs          # offline verification only (no node, no network)
node --test tests/               # model tests with fresh keys, including mutation checks
node scripts/build-site.mjs      # builds the static site into site/
```

Anvil (Foundry 1.5.1) is expected at `~/.foundry/bin/anvil`; it is a prebuilt binary and is not compiled by the lab.

`record.sh` refuses to start if the one-minute load average is above 6.5 (set `WAIT_FOR_QUIET=<seconds>` to wait for the machine to settle instead of stopping). Each step is checked again before it starts. Steps run strictly one at a time, niced, under `/usr/bin/time -l`; bitcoind is stopped with `bitcoin-cli stop`, anvil with SIGTERM to its PID; an exit trap stops anything left over by recorded PID. The scripts never use `pkill` or `killall`.

### What `verify.mjs` checks (offline)

- `evidence.json` matches its recorded SHA-256.
- Part B: each case's normalized payload (sorted keys, no whitespace) and payload hash are recomputed with `node:crypto`, independent of the model's own SHA-256. Every SLH-DSA signature is verified. Every case is replayed through the model and must give the recorded outcome: positive cases accepted, negative cases rejected. Tampered copies are checked to differ from their source by exactly one change.
- Part A: transaction ids and hashes are recomputed; the ECDSA signature inside the Bitcoin transaction is verified against the owner's key with a BIP143 signature hash computed here; Bitcoin block hashes and Merkle roots are recomputed; the Ethereum signer is recovered from the signature and compared with the owner's address; balances are checked arithmetically.
- Mutation self-checks: one flipped byte in a payload, a signature or a nonce of each accepted case must break verification.

Not recomputed: the Ethereum block hash (a header re-encoding depends on the hardfork); it is shown as the node returned it.

## The modeled rule

Payload: UTF-8 JSON, sorted keys, no whitespace, domain `tacit-recovery-lab/v1`, fields `account, action, amount, checkpoint, destination, domain, network, nonce, scenario`. `action` is `recover` or `pay`; for `recover`, `destination` is the new authority's commitment (SHA-256 of its public key) and `amount` is null. Signatures cover the exact payload bytes (FIPS 205 pure mode, empty context); the domain is part of the payload.

1. A commitment counts only if registered at or before the checkpoint. A commitment an attacker registers after the compromise is ignored.
2. The classical key alone cannot authorize `recover`.
3. The owner's SLH-DSA signature authorizes `recover`, installing a new PQ spending authority.
4. After recovery, a payment is valid only with the new authority.
5. Rejected: modified recipient, modified amount, invalid or truncated signature, reused nonce, wrong network, scenario or checkpoint.

Modeling assumptions, stated on the page: the checkpoint is the chain tip just before the compromise; the model behaves as if the network had agreed to the rule from the checkpoint (a classical signature alone no longer moves the checkpoint balance of an account with an effective commitment); registering a commitment is a given input.

Not covered: an account with no prior commitment is moved by its classical key and cannot recover (cases `op-18` and `op-19` record exactly this). Funds that moved before the checkpoint are outside the model.

Parameter set: SLH-DSA-SHA2-128s. Public key 32 bytes, secret key 64 bytes, signature 7,856 bytes. Signing takes about 2 s per signature in JavaScript on the recording machine; verification about 4 ms.

## Versions and checksums

| Item | Version | Checksum |
|---|---|---|
| Bitcoin Core (macOS arm64 tarball) | 32.1 | sha256 `cd3dcdacb4ff861e862b2d7df4786ecef66472e2468dca1673a70dd761e064e7` |
| `bitcoind` extracted | v32.1.0 | sha256 `58f9e3b5b8cf0cecd268cc6bf02993f3244e1a93fe8d67949ced6b52c2fdd9fb` |
| `bitcoin-cli` extracted | v32.1.0 | sha256 `5310684b6028bdc48e2155645408f02bd2b46e0ee0799317168e74ce9b823aba` |
| `anvil` (Foundry, prebuilt, already installed) | 1.5.1-stable, commit b0a9dd9ceda3 | sha256 `78b8a09a4582e79a0450f892055bf0a91f9af3041b697f77aa5ecf7f8b45c12b` |
| `cast` (same Foundry release, offline signing only) | 1.5.1-stable | sha256 `f7373e6e34939415fe048560ecf275463ea891fec5a124a38958983f3955542d` |
| `@noble/post-quantum` | 0.7.1 | `sha512-+P9981IiAnVh+rmcubozzVwrEy3XsN/tMhTnvsjV9VDaYpOnNCqWqKo2FLWxbu92YHfjGIlE5XnW175UK+ln+Q==` |
| `@noble/curves` | 2.4.0 | `sha512-P4/62zrgfH33CneE3Dn4WhJVA22YUU0eR51wKIan4NVRvwsA0YnPTwWGpNbpuacSujmSFLvyzpyuR30+fbq2Ew==` |
| `@noble/hashes` | 2.4.0 | `sha512-X5XaVWZIBCT7HHZGm5I7ZQXDwLG+bGXuSrMQAW+7Zvl87h1kmc1ZB1VSRJcpUfoUrGQp4Fkoxm5kZ+Ms+aW+eA==` |
| `@noble/ciphers` (dependency of post-quantum) | 2.4.0 | `sha512-AnjFn0Jv92laAkvMrghlFZq4qQCIN/4DxFV/eooqtC2YTjB7kBeLMS2T9KJX4Dn+ZVXLOwK0lSgqDtx9gvxtiw==` |
| `esbuild` (build time only) | 0.25.12 | `sha512-bbPBYYrtZbkt6Os6FiTLCTFxvq4tt3JKall1vRwshA3fdVztsLAatFaZobhkBC8/BrPetoa0oksYoKXoG4ryJg==` |
| `@esbuild/darwin-arm64` (build time only) | 0.25.12 | `sha512-N3zl+lxHCifgIlcMUP5016ESkeQjLj/959RxxNYIthIg+CQHInujFuXeWbWMgnTo4cp5XVHqFPmpyu9J65C1Yg==` |
| Node | v20.10.0 | n/a (the noble packages declare Node >= 20.19; they ran fine here, npm printed engine warnings) |

### How the Bitcoin Core tarball was checked

This was a **hash cross-check across independent sources, not a GPG signature verification.** `gpg` is not installed on the machine that built the lab and the lab does not install system tools. `scripts/fetch-bitcoin.mjs` (1) downloads the tarball and requires its SHA-256 to equal the line in `SHA256SUMS` published on bitcoincore.org, and (2) requires the same hash to appear in the `all.SHA256SUMS` attestation files of at least five distinct builders in the public `bitcoin-core/guix.sigs` repository. For 32.1, 14 of 16 builder directories attest this exact hash (Emzy, Sjors, achow101, benthecarman, danielabrozzoni, fanquake, guggero, hebasto, m3dwards, pinheadmz, sedited, stickies-v, willcl-ark, willyko); the other two published no `all.SHA256SUMS`. The result is in `artifacts/bitcoin-core-verification.json`. `SHA256SUMS.asc` is saved in `vendor/download/` so anyone with gpg can verify the signatures themselves. The cross-check does not prove the builders are honest; it shows that independent builders reproduced the same bytes.

## Measured resource use (the recording that produced this bundle)

Machine: macOS 14.6.1, Apple silicon, 8 logical CPUs, 8 GiB RAM, load average about 5.6 at start (the laptop was in normal use). Peak RAM is `maximum resident set size` from `/usr/bin/time -l`; CPU is user+sys over wall time (average) and the highest 1-second window from a 250 ms `ps` sampler (peak).

| Step | Wall | CPU average | CPU peak (1 s window) | Peak RAM (max RSS) |
|---|---|---|---|---|
| bitcoind 32.1 regtest (`-par=1 -dbcache=16 -maxmempool=5`) | 7.7 s | 0.12 core | 0.45 core | 48.0 MiB |
| anvil 1.5.1 (`--threads 1`) | 0.4 s | 0.12 core | 0.12 core | 15.7 MiB |
| model step (SLH-DSA signing, one Node process) | 46.2 s | 0.94 core | 1.10 cores | 62.1 MiB |

The model step is single-threaded JavaScript; the 1.10 figure is sampling noise around one core. Nothing was pinned to a core (macOS has no affinity control); the steps are niced and single-threaded by design. The full per-step records are in `evidence.json` under `resources`.

## Every test process has stopped

`record.mjs` checks every PID it recorded before assembling the bundle (`resources.processCheck` in `evidence.json`), and `record.sh` runs `scripts/stop-recorded.mjs` on exit, which reads the recorded PIDs and reports each one. At the end of the recording that produced this bundle all six PIDs (the `time` wrapper and the program, for bitcoind, anvil and the model step) reported `stopped`. Disposable private keys are deleted after the model step; the bundle holds public keys only.

## Limits

- The recording was made once, on one machine. Block hashes and times differ on every run.
- Ethereum test funds come from `anvil_setBalance` on a fresh funding key (the dev node starts with no accounts); this is a genesis-style seed, not a transaction, and is labeled as such in the bundle.
- The control cases (one changed byte in a signature) show the nodes refuse the changed transaction; the Ethereum node's message is "Insufficient funds", because the changed signature recovers to a different, unfunded sender.
- Optional statistics from a real Bitcoin node (value in outputs that expose public keys) are not part of this build.

## Files

- `src/`: model (`model.js`), payload format (`normalize.js`), case builder (`scenario.js`), offline chain checks (`chaincheck.js`), verification (`verify-core.js`), page (`browser.js`)
- `scripts/`: `record.sh`, `record.mjs`, `steps/`, `fetch-bitcoin.mjs`, `assemble.mjs`, `verify.mjs`, `build-site.mjs`
- `tests/model.test.mjs`
- `artifacts/`: `evidence.json`, `evidence.json.sha256`, `raw/`, `bitcoin-core-verification.json`
- `site/`: the self-contained static website (open `site/index.html` through any static file server)
- The page's scripts and stylesheet (`assets/*.js`, `assets/style.css`) are minified esbuild bundles. The readable sources are in this tarball: `src/browser.js` (the evidence replay, `assets/lab.js`), `site-src/sim-ui.js` and `src/zombi-chain.js` (the simulator, `assets/sim.js`), `site-src/support.js` (the roll call, `assets/support.js`), `site-src/lane.js`, `site-src/page-entry.js` and `site-src/style.css`. `scripts/build-site.mjs` rebuilds them with the esbuild pinned in `package-lock.json`; `assets/evidence.js` is the exact text of `evidence.json`.
