← Socratic Seminar #52 ← → or space to navigate

Miniscript Studio · portlandhodl

Design Bitcoin self-custody visually

Drag keys, timelocks and logic blocks onto a canvas and watch them compile live into Miniscript, descriptors and addresses. Everything runs in your browser on rust-miniscript compiled to WebAssembly.

github.com/portlandhodl/miniscript-studio · live demo · rust-miniscript 13.2 + bc-lifehash 0.1, one self-contained HTML file, no server

Running example

Multi-vendor multisig + escape hatch

Miniscript Studio canvas: Vendor A, Vendor B and You feed a 2-of-3 threshold; You and a 1-year relative timelock feed an All-of block; both feed Any-of into the wallet. The Paths panel shows custody over time.

Day to day, 2 of 3 between you and two custody vendors. If the vendors disappear, your own key alone recovers the funds after a year. One of the built-in templates, loaded with demo keys.

Under the hood

Blocks → policy → miniscript → descriptor

The block graph becomes a weighted policy; rust-miniscript compiles it to an or_d miniscript; keys are substituted into a wsh descriptor and a BIP-388 wallet policy. POLICY (from the blocks, with likelihood weights) or(99@thresh(2,pk(Vendor_A),pk(Vendor_B),pk(You)),1@and(pk(You_2),older(52560))) rust-miniscript compiler, optimised for the 99% path MINISCRIPT (SegWit v0) or_d(multi(2,Vendor_A,Vendor_B,You),and_v(v:pkh(You_2),older(52560))) aliases replaced with real xpubs DESCRIPTOR (multipath receive/change) wsh(or_d(multi(2,[406d2ba1/48'/1'/0'/2']tpub…/<0;1>/*,…),and_v(…))) addresses + Core importdescriptors BIP-388 wallet policy for signers

138-byte script, max witness 286 WU; the Analysis tab reports it safe, non-malleable and sane, with no timelock mixing. Taproot mode compiles to tr() with a NUMS internal key when no single key can take the key path.

Key reuse done right

One device, two paths, two derivation branches

The You hardware wallet's xpub is used in both paths: the 2-of-3 multisig gets branch 0;1 and the timelocked fallback gets branch 2;3, so miniscript never sees a duplicate key. "You" (1 device) [8d4e2280/48'/1'/0'/2'] tpubDEiV…6tVzjb 2-of-3 multisig: pk(You) …6tVzjb/<0;1>/* BIP-388: @2/** Escape hatch: pk(You_2) …6tVzjb/<2;3>/* BIP-388: @2/<2;3>/*
  • Miniscript rejects repeated keys, so one key block wired into a second path gets its own branch: <2;3>/*, then <4;5>/*, and so on.
  • Same signer, same xpub, different child keys. The BIP-388 export keeps it as one key, @2, that the hardware wallet registers once.

Custody over time

Trading interactivity for fault tolerance

From day one: 2 of 3 signers needed, 1 key can be lost, a thief needs 2 keys. After about one year: 1 of 3 signers needed, 1 key can still be lost, a thief needs just 1 key. MEASURE From day one After ≈ 1 year Signers needed 2 of 3 1 of 3 Keys you can lose 1 1 Keys a thief needs 2 1 older(52560) ≈ 1 year unmoved

Paths 1–3, now

Any 2 of Vendor A, Vendor B, You. 79 vB per input, from rust-miniscript's spend planner.

Path 4, after a year

You alone, 70 vB per input. The same key that makes recovery possible also lowers the bar for a thief.

Disaster simulator

Both vendors vanish. Are the coins gone?

Simulator with Vendor A and Vendor B marked lost and time scrubbed past one year: the You key and timelock path light up and the result reads Spendable via path 4: You, 70 vB input.
  • Mark Vendor A and Vendor B lost: "Locked, but recoverable. Opens in ≈ 1 year with You."
  • Scrub time past the timelock: "Spendable via path 4: You · 70 vB input", and the satisfied blocks light up on the canvas.

Safety and caveats

Public keys only, and verify on your signer

Private keys refused

Pasted xprvs, WIF keys and seed words are detected, cleared and never stored, with a warning to treat them as exposed.

Demo keys are public

Demo mode derives keys from public seeds and shows a banner the whole time. Never fund a wallet built on them.

Relative timelocks reset

older() counts from when each coin confirmed, up to 65,535 blocks (≈ 455 days). Spending through the 2-of-3 path restarts the clock.

Check before funding

Confirm the descriptor and addresses on your signing devices. Share links put the whole design in the URL fragment; no server sees it.

Discussion

Questions for the room

  • After a year, a thief needs only your key. How long should an escape hatch be, and should vaults roll coins to keep it shut?
  • Would you trust a policy compiler's 99@/1@ weighting, or hand-write the miniscript?
  • Is a visual designer good for self-custody, or does it make complex policies too easy to build badly?
  • Which hardware wallets actually register BIP-388 policies with reused keys like @2/<2;3>/*?
  • What's missing: the Taproot templates, the hashlock (HTLC) one, or importing your existing wallet's descriptor?