Treaty bonds on Bitcoin
Purpose
The paper's settlement layer holds each operator or sovereign bond in a Taproot output whose spending conditions are fixed at creation, and gets the destination restrictions Bitcoin script lacks by pre-signing a small transaction tree (Protocol Specifications, "Bond output and transaction tree"). This module builds those outputs and transactions with bitcoinjs-lib 7 and @bitcoinerlab/secp256k1, computes the MuSig2 internal key with @scure/btc-signer, checks control blocks with an independent BIP341 implementation on @noble/curves, applies the bond policy as a pure function, and offers a local checker for its own leaf templates. The regtest suite proves every path against a real bitcoind.
Keys
P: the operator's key (or the state's, for a sovereign bond), 33-byte compressed; its x-only form goes in the leaves.K_C: the Inspection Council's FROST group key (src/frost), so the Council's signature on a slash or notice is a t-of-n FROST signature, produced through ROAST (src/roast).- Internal key of both outputs:
KeyAgg(KeySort([P, K_C]))per BIP327 MuSig2 (bondInternalKey). The tests reproduce BIP327's key-aggregation vectors.
The key path is cooperative but unused. Spending by key path would need the FROST council to act as a single MuSig2 signer (nested threshold MuSig2). There is no standardized, audited construction for that, so this reference spends only by script path. Flag for the authors: either specify a nested scheme or say that cooperative spends use the 2-of-2 leaf.
Outputs (scripts are exact; decompiled and compared in the tests)
B (bond output), P2TR(KeyAgg(P, K_C), [
leaf A, 2-of-2: <P> OP_CHECKSIGVERIFY <K_C> OP_CHECKSIG (Notice; Adjudicated slash)
[ leaf C, crypto slash: OP_SHA256 <C> OP_EQUALVERIFY <P> OP_CHECKSIG (STAND-IN, see below)
leaf R, recovery: <tau_rec> OP_CHECKLOCKTIMEVERIFY OP_DROP <P> OP_CHECKSIG ] ])
N (notice output), P2TR(KeyAgg(P, K_C), [
[ leaf W, release: <tau_w> OP_CHECKSEQUENCEVERIFY OP_DROP <P> OP_CHECKSIG
leaf A, 2-of-2: (Adjudicated slash) ]
[ leaf C, crypto slash, leaf R, recovery ] ])
P2A anchor: OP_1 <0x4e73>, 240 satThe paper's Notice and Adjudicated-slash leaves have the same condition (P and K_C),
so they are one leaf; the signed transaction (notice or slash) tells them apart. Numbers
are minimally encoded (tau_w = 16 becomes OP_16, 144 becomes 0x9000). Witnesses:
2-of-2 [sig_KC, sig_P, leaf, control]; crypto slash [sig_P, preimage, leaf, control];
release or recovery [sig_P, leaf, control]. Signatures are 64-byte BIP340 with
SIGHASH_DEFAULT, so each commits to every input and output of its transaction.
The crypto-slash leaf is a stand-in. The paper completes this path with an optimistic
verification protocol (BitVM2-style connectors) for a violation predicate. Here a revealed
SHA-256 preimage of a commitment C stands for "the verification game ended in the
challenger's favor". It shows the transaction shape (the operator's pre-signed slash,
completed without the Council) and nothing of BitVM2's security: whoever learns the
preimage can complete the slash.
Transaction tree
bond creation: operator signs Tx_notice, Tx_release, Tx_slash (adjudicated and crypto, from B and from N);
slash pre-signatures are deposited with the Council (presignBond)
funding --> B --Tx_notice (2-of-2: P pre-signed, K_C co-signs to begin withdrawal)--> N
| |
|--Tx_slash_B (2-of-2: P pre-signed, K_C completes) --> slash outputs |--Tx_release (P alone, nSequence = tau_w) --> operator
|--Tx_slash_B (crypto stand-in: P pre-signed + preimage) --> same outputs |--Tx_slash_N (2-of-2 or crypto stand-in) --> slash outputs
|--Tx_recover (P alone, nLockTime = tau_rec) --> operator |--Tx_recover (P alone, nLockTime = tau_rec) --> operator
'--rollover (2-of-2, both sign by rule) --> fresh bond B'Every transaction is version 3 (BIP431 TRUC, which also satisfies BIP68's version >= 2),
pays a fee frozen at creation (params.fee), and ends in a 240-sat P2A anchor. Slash
outputs pay the bounty pool and a challenger reward output in fixed basis points (the last
destination takes the rounding remainder). Because the operator's signature commits to
the outputs, the Council (or a challenger) can complete a slash but cannot change it.
Policy (checkBondPolicy(bond, nowHeight, maxDetectPlusAdjudicate))
A pure function of the bond's parameters, its state and the height. It reports violations and four decisions:
tau_wmust be 1..65,535 blocks (BIP68) and at least the time to resolve a pending claim, or an operator under investigation can notice and release first.tau_recmust be a block height after creation, more than the longest detection plus adjudication time after it.- The rollover window
W(renewals stop attau_rec - W) must exceed the license period plus detection and adjudication, so a violation under the last license can still be slashed beforetau_rec. mustRollOverfromtau_rec - Wuntil rolled over;renewalAllowedis false inside an unrolled rollover window, aftertau_rec, or when any rule is broken.- Sovereign bonds on withdrawal (paper, exit protocol: "returned only after a final
inspection confirms that no violation occurred during membership"): the bond stays
slashable until its final inspection.
releaseAllowed(the Council co-signing the notice) is false until a final-inspection record exists and is clean, andtau_recmust fall after the scheduled final inspection plus adjudication, or the party could recover the bond alone before it. Recovery opening before the record exists is reported as a violation.
Fees
Pre-signed transactions freeze their fee. Each carries a P2A anchor (standard since
Bitcoin Core 28) so anyone can fee-bump it by CPFP with a v3 child, submitted as a package
(submitpackage). CPFP never changes the parent's txid, which matters: Tx_release and
Tx_slash_N spend Tx_notice's output, so their pre-signatures commit to Tx_notice's txid.
RBF of a pre-signed transaction, or adding fee inputs with ANYONECANPAY, would change txids
and void the pre-signatures below it. TRUC limits the child to 1,000 vB, which bounds
pinning. Bitcoin Core 32.1 accepted a v3 slash plus a CPFP child as a package in the
regtest suite.
Timelock limits
BIP68 relative locks live in 16 bits: at most 65,535 blocks, about 455 days. So tau_w
must be in 1..65,535 and the recovery delay must be an absolute CLTV height, which gives
each bond a fixed expiry tau_rec. A violation found after tau_rec cannot be slashed
reliably (the operator can take the bond alone and races any slash), hence rollover.
csvSequence, cltvHeight, bondTemplate and checkBondPolicy reject out-of-range values.
Security properties and the tests that check them
Unit tests in test/bond/bond.test.ts and test/bond/policy.test.ts; regtest in
test/regtest/bond.test.ts (bitcoind 32.1.0). Every forbidden case in regtest is rejected
by testmempoolaccept and also by generateblock, so it is invalid by consensus, not only
by relay policy.
| Property | Unit test | Regtest (bitcoind) |
|---|---|---|
| Internal key is BIP327 KeyAgg of P and K_C (BIP327 vectors reproduced), order-independent, in every control block | "MuSig2 internal key" | all spends use it |
| Leaves are exactly the paper's scripts; B and N have the paper's leaf sets | "leaf scripts" | all paths spend them |
| Control blocks verify under an independent BIP341 check; wrong leaf, output, parity or path fail | "control blocks ..." | accepted spends |
| Sighashes are stable; the operator's pre-signature commits to every output | "sighashes are stable", "commits to every output" | bitcoind accepts the signatures |
| Notice needs the Council's co-signature | "notice completes with the council's co-signature ..." | notice completed by ROAST, mined |
Release only after tau_w blocks |
"release completes only with nSequence >= tau_w ..." | rejected non-BIP68-final right after notice and at tau_w - 1; mined at tau_w |
| Adjudicated slash needs the Council: operator-only fails | "rejects a slash signed only by the operator" | rejected (stack size; operator twice: Invalid Schnorr signature), from B and from N |
| Council cannot redirect a slash | "rejects a council-redirected slash ..." | rejected Invalid Schnorr signature |
| Council slashes from B, and from N during the notice period, with a FROST signature | "a 3-of-5 council signature completes ..." | both mined; the B slash's signature came from ROAST with one malicious and one silent signer |
| Crypto-slash stand-in completes with the preimage only | "crypto-slash stand-in completes with the preimage ..." | wrong preimage rejected (OP_EQUALVERIFY); from B and from N mined |
Recovery from B and from N only from tau_rec, operator alone |
"recovery from B and from N needs nLockTime >= tau_rec ..." | rejected non-final one block early, Locktime requirement not satisfied with an earlier lock, Invalid Schnorr signature when the Council signs; both mined at tau_rec |
| Anchors are spendable for CPFP | "every transaction is version 3 and ends in a 240-sat P2A anchor" | slash + child accepted by submitpackage, both mined |
| Tx_notice's txid is independent of its witness, so release and slash-from-N are pre-signed first | "the notice's txid does not depend on its witness ..." | all N spends were pre-signed before the notice was completed |
| Rollover, renewal and parameter rules | policy.test.ts "bond policy" (with a fast-check property) | n/a |
Sovereign bond stays slashable until a clean final inspection; tau_rec after the scheduled final inspection |
policy.test.ts "sovereign bond on withdrawal" | n/a |
The local checker (checkLeafSpend) recognizes only this module's four leaf shapes. It is
a teaching and testing aid, not a script interpreter; bitcoind is the authority.
Interpretations
- Interpretation: one 2-of-2 leaf serves Notice and Adjudicated slash (identical conditions; two identical leaves would only add a tree level).
- Interpretation: KeyAgg order.
KeySortfirst, so the internal key does not depend on who is listed first. - Interpretation: the crypto-slash commitment
Cis a bond parameter; see the stand-in note above. - Interpretation: N keeps a recovery leaf, as the paper lists it, so a notice that neither releases nor is slashed (the Council vanished mid-withdrawal) is not stuck.
- Interpretation: slash destinations are a parameter. The tests use a bounty pool
(key-path P2TR under
K_C) at 80% and a challenger-reward escrow at 20%. - Interpretation: rollover window
W > lambda + Dandtau_w >= adjudication timeare our reading of "rolled over by rule ... well before tau_rec" and "giving the Council time to act". tau_recis a block height, never a Unix time.
Open questions for the paper authors
- MuSig2 with a FROST key (above): specify a nested threshold MuSig2 scheme, or state that cooperative spends use the script-path 2-of-2.
- Notice and Adjudicated slash are the same condition. Nothing in script stops the Council and operator from using the "notice" leaf to sign a slash or vice versa; only the pre-signed transactions differ. The paper lists them as separate leaves.
- Who receives the challenger reward? The operator pre-signs the slash with SIGHASH_ALL before any challenger exists, so the reward output can only pay a fixed escrow, and paying the real challenger takes a second, Council-signed transaction. It is not automatic. SIGHASH_SINGLE|ANYONECANPAY would let the completer add an output but would also let the Council take the unassigned value.
- The cryptographic (BitVM2) slash is not built (stand-in only). BitVM2-style protocols fix the asserter and challengers in a graph pre-signed at setup; here the challenger is unknown at setup and the accused operator must pre-sign the graph. The paper should say who may assert, how the operator's pre-signatures cover unknown asserters, and what the operator's contest transaction spends.
- The appeal period cannot be enforced by script on B. A CSV on B counts from B's confirmation, long past. On-chain enforcement needs an intermediate "slash pending" output; as built, the appeal period is procedural (the Council withholds its signature).
- Recovery race. From
tau_recboth a slash and the recovery are valid spends; the first to confirm wins. The rollover margin should be stated. - Sovereign bond timing. A withdrawing party's final inspection must finish, and any
finding be adjudicated, before
tau_rec. If inspection is delayed (the party obstructs access), the bond reachestau_recand the party recovers it alone. The paper should say whether withdrawal forces a rollover to a latertau_rec, and who signs it if the party refuses. - Changing the Council key (as opposed to resharing it) invalidates
K_Cin every live bond and forces a rollover of all of them. - Spending the bounty pool by key path needs FROST signing with the BIP341 tweak; the wasm wrapper does not expose that yet.
- Partial slashes need one pre-signed slash per fraction; the paper slashes whole bonds.