PQGrind Docs

PSBT formats

Trades are atomic Bitcoin transactions assembled from partially signed parts. No escrow, no custodian. The formats below are those used by the reference tools on the test network; a public order book is not yet available.

Listing (seller)

A listing is a PSBT with one input and one output, signed by the seller with SIGHASH_SINGLE | ANYONECANPAY (0x83).

input  0   the unit-carrying output being sold         seller signs with 0x83
output 0   price in sat → seller's own script          (price ≥ 330 sat)

0x83 commits to input 0 and output 0 only. Anyone can add inputs and outputs around them, as long as the seller's input and the payment output keep the same index.

Seller steps:

  1. Build the PSBT (the reference tool's POST /api/psbt/list returns it).
  2. Sign in a wallet that supports non-default sighash types; confirm the type is SINGLE|ANYONECANPAY.
  3. Publish the signed PSBT. The listing stays valid until the seller spends that output.

Cancel: spend the listed output to yourself (an ordinary transfer). The old signature becomes useless.

Purchase (buyer)

The buyer adds two padding inputs in front, so each seller input lands at index ≥ 2 next to its payment output, and the units land in one output for the buyer.

inputs                                     outputs
0  buyer pad 1 (plain)                     0  pad 1 + pad 2 → buyer         (returns the padding)
1  buyer pad 2 (plain)                     1  Σ seller values → buyer       ← all purchased units
2  seller 1's output (signed 0x83)         2  price 1 → seller 1
…  seller i's output  (signed 0x83)        …  price i → seller i            (index matches its input)
n  buyer funding (plain)                   n  buyer change (if ≥ 330 sat)

Why it works (first-in first-out):

  • Pads fill the line [0, pad1 + pad2), exactly output 0. They must be unmarked.
  • Seller outputs follow and fill exactly output 1, whose value equals their sum. All marked satoshis end in output 1.
  • Payments and change are paid from the funding inputs, which come last.

Buyer requirements: at least three plain outputs (two pads and one payment). Fee estimate used by the reference tool: r × (11 + 68·inputs + 31·outputs + 10) vB.

Signing variants

Wallets differ on the PSBT field PSBT_IN_SIGHASH_TYPE for the seller's input:

Variant Seller input carries the 0x83 sighash field Needed by
A yes wallets that verify existing partial signatures against the field
B no (the signature's last byte is already 0x83) wallets that would otherwise apply the field to their own inputs or reject the mismatch

The buyer signs only its own inputs, with SIGHASH_ALL. Both variants produce the same final transaction.

Checks a buyer must make

  1. The seller's input currently carries the advertised units (/api/utxo/<outpoint>), with enough confirmations.
  2. The seller's signature type is 0x83.
  3. Output 1 value equals the sum of seller input values.
  4. Pads and funding inputs are unmarked.

Outputs that also hold companion runes

A listed output that also carries companion runes transfers them to the buyer too. Sellers should split first; buyers should check /api/utxo/<outpoint> and a Runes explorer for both assets.

Risks

  • Stale listings: if the seller moves the output, the purchase fails at broadcast; nothing is lost but time.
  • Races: two buyers may complete the same listing; one transaction confirms, the other becomes invalid.
  • Fee: the buyer pays all fees.