did-btcr2-js

ADR 134: A Beacon Signal Spends All Eligible UTXOs of the Beacon Address, and Its Change Stays Spendable

Context

A single-party beacon signal (singleton, CAS, or SMT beacon) spends UTXOs of the beacon address. selectSpendableUtxo (ADR 063) chose one confirmed UTXO with a value above 546 sats (SPENDABLE_DUST_LIMIT_SATS), deepest first. The builder spent that one UTXO and refused the signal if its value did not cover the fee.

A demo test on mutinynet (2026-09-29) found three problems.

  1. One input for each signal. A beacon address held 2 confirmed UTXOs of 500 sats. Neither UTXO passed the 546-sat floor, and one input cannot spend both. The update failed, but the user had funded the address.
  2. The error dropped the reason. With no beaconId, the api derives the beacon (ADR 104). The derivation called selectSpendableUtxo for each beacon, discarded each BeaconError, and then said No beacon of DID ... holds a spendable UTXO. The user could not see why the 2 UTXOs did not count.
  3. Stranded change. The builders create a change output at or above DUST_LIMIT_SATS of its kind (p2pkh 546, p2wpkh 294, p2tr 330). The selector spent only a UTXO above 546. Two updates spent a 2000-sat UTXO at a p2wpkh beacon: 2000 - 775 - 775 = 450. The builder created the 450-sat change output (450 >= 294), and no later signal could spend it (450 <= 546).

The funding guard of the api (ADR 102) had one more gap. It called the selector with no fee rate. An address that had a spendable UTXO but not enough value for the fee passed the guard. The beacon then refused at the broadcast, after the CAS publication. ADR 102 puts the refusal before any publication.

Specification position

The specification sets no rule for the inputs of a beacon signal. The non-normative section “Funding a Beacon Signal” (src/operations/update.md) takes prevouts (plural): “One of them is a UTXO that the Beacon Address controls.” The resolver reads each vin of a signal (signal-discovery.ts), so a signal with several inputs resolves. ADR 063 gives no reason for one input. The input rule is thus a local policy.

Decision

One function gives the rule

selectBeaconFunding(utxos, { beaconAddress, network, feeEstimator?, changeAddress?, maxInputs? }) in packages/method/src/core/beacon/beacon.ts selects the UTXOs, the vsize, the fee, and the change. It returns { utxos, kind, changeAddress, changeKind, vsize, valueSats, feeSats, changeSats }. It is deterministic for one UTXO set and one fee rate. The rule needs the fee rate, and the FeeEstimator interface gives only estimateFee(vsize), so the function is async. These callers use it:

Caller Package
SinglePartyBeacon.buildSignAndBroadcast (through fetchBeaconFunding) method
buildAggregationBeaconTx (with maxInputs: 1) method
The NeedFunding guard of DidMethodApi.update api
#deriveBeaconId of DidMethodApi api

A UTXO is eligible if it adds value

A UTXO is eligible if both conditions are true:

  1. It is confirmed (ADR 063 stays).
  2. Its value is more than the fee of its own input: estimateFee(BEACON_INPUT_VBYTES[kind]).

An eligible UTXO always adds value to the transaction. The new constant BEACON_INPUT_VBYTES gives the conservative size of one more input:

Kind vB Size
p2pkh 149 36 outpoint + 1 length + 108 scriptSig (a 72-byte DER signature with its sighash byte, a 33-byte public key, 2 push bytes) + 4 sequence
p2wpkh 69 41 non-witness bytes (164 WU) + 109 witness bytes = 273 WU, rounded up
p2tr 58 41 non-witness bytes (164 WU) + 66 witness bytes (stack count, length, 64-byte signature) = 230 WU, rounded up

beaconTxVsize(kind, changeKind, inputs = 1) adds (inputs - 1) * BEACON_INPUT_VBYTES[kind]. For 1 input, the value does not change, so the existing vsize constants and their tests stay.

This decision removes SPENDABLE_DUST_LIMIT_SATS. A fixed floor does not follow the fee rate. At 1 sat/vB a 500-sat p2wpkh UTXO adds 431 sats. At 10 sat/vB a 600-sat p2pkh UTXO adds nothing (its input costs 1490 sats).

The signal spends all eligible UTXOs, up to 20

The transaction spends each eligible UTXO. The limit is MAX_BEACON_TX_INPUTS = 20. If more UTXOs are eligible, the transaction spends the 20 of the largest value. The ADR 063 order breaks a tie in value. The inputs sit in the transaction in the ADR 063 order: deepest first, then txid, then vout.

The reasons for all eligible UTXOs:

The reasons for the limit of 20:

The total value must cover the fee

The total value of the selected UTXOs must be more than estimateFee(beaconTxVsize(kind, changeKind, n)) for n inputs. The strict comparison of the old value <= feeSats guard stays.

A change output is always spendable later

The transaction has a change output only if the change is at least the change floor:

changeFloor = max(DUST_LIMIT_SATS[changeKind], estimateFee(BEACON_INPUT_VBYTES[changeKind]) + 1)

If the change is below the floor, the remainder goes to the fee. A change output is thus eligible under the rule above at the same or a lower fee rate. At 5 sat/vB the floors are p2pkh 746, p2wpkh 346, and p2tr 330 sats. At 1 sat/vB they are the dust limits.

This guarantee applies to the address that gets the change. If the caller names a change address (ADR 044), the change goes there, and a signal of this beacon does not spend it. The floor still uses the kind of that address, so the output is not dust and not useless at that rate.

BeaconFunding.changeSats is 0n if the transaction has no change output. feeSats is the estimate. The remainder that goes to the fee is not in it.

Each error gives its reason

selectBeaconFunding throws a BeaconError. The message is Beacon address <address> cannot fund a signal: <reason>., and data.reason holds the reason with no address.

Type Condition Reason, for example
UNFUNDED_BEACON_ADDRESS The address has no UTXO. no UTXOs
NO_SPENDABLE_BEACON_UTXO No UTXO is eligible. 2 UTXOs, none confirmed, or 2 confirmed UTXOs, each at or below the fee of its own input (345 sats)
INSUFFICIENT_FUNDS The selected UTXOs do not cover the fee. 2 spendable UTXOs, total value 1000 sats, fee 1120 sats (224 vB)

The data also holds the counts and the sats as numbers, so it is safe for JSON.

The aggregation path keeps one input

buildAggregationBeaconTx calls the same function with maxInputs: 1. Each input has its own sighash, so each participant of the cohort must give one MuSig2 nonce and one partial signature for each input. Several inputs there need a change to the protocol, and this decision does not make it.

With maxInputs: 1, the aggregation builder spends the eligible UTXO of the largest value, not the deepest one. The largest value is the one input with the best chance to cover the fee.

The api applies the rule with the fee rate of the broadcast

The guard and the derivation call selectBeaconFunding with the network of the Bitcoin connection, the fee estimator of the broadcast (after the announce.feeRate conversion, else DEFAULT_FEE_ESTIMATOR), and announce.changeAddress. The api converts only the three funding errors of the table above. Any other error (for example INVALID_CHANGE_ADDRESS) passes through unchanged.

For the case of item 1 of the context, at the default 5 sat/vB, the message is one line. The lines below break it for the page:

No beacon of DID did:btcr2:k1q5p0kkmsh8nzcsp3p78zjjk99ueln4kvvltel8p6pmttqj26zt25zpcmln4eh can fund
the signal. The api cannot derive beaconId. #initialP2PKH (mwm9XdtfwXmu8VDiP9dinaZZLb6LTU4mci): no UTXOs;
#initialP2WPKH (tb1qkgcnd0d600pl4gjm7935kjwdlj7uc6s2lwnn26): 2 spendable UTXOs, total value 1000 sats,
fee 1120 sats (224 vB); #initialP2TR (tb1peu06twljsmunv5fuqgv2dt7y753m7wzsdkx6lfx3ectaacamwq4qeleflj):
no UTXOs. Wait for a confirmation, fund one beacon address, or set a lower `announce.feeRate`.

The data is { did, beacons: [{ id, type, address, reason }] }. With announce.feeRate: 1 the same address funds the update: 2 inputs, 224 vB, fee 224 sats, change 776 sats.

If several beacons can fund the signal, the message is N beacons of DID <did> can fund the signal: <ids>. Pass beaconId to choose which one spends.

Relation to earlier ADRs

Alternatives

Consequences

Positive.

Negative.

Neutral.

Implementation