did-btcr2-js

ADR 169: The Aggregate Beacon Address Is n-of-n by Default, and Each Script Leaf Is Opt-In

Context

In this ADR, a member is a participant that the service accepted in a cohort. n is the number of cohort keys. Leaf A is the k-of-n fallback leaf. Leaf B is the CSV recovery leaf.

Each beacon address had two script leaves

Before this change, the beacon address of each aggregate cohort was a Taproot output with an internal key and a script tree. The internal key is the MuSig2 aggregate of the cohort keys. The script tree always had two leaves (ADR 042, ADR 043):

If the config did not name the recovery values, AggregationRunner.solo set recoveryKey to the x-only key of the service and recoverySequence to 144.

A leaf lets a party publish a Beacon Signal without all members

Terminology, “Beacon Signal”, says: “Beacon Signals are Bitcoin transactions that spend from a Beacon Address and include a transaction output of the format defined in Signal Bytes.” The script of a leaf does not limit the outputs of a spend. Thus each spend through a leaf can be a Beacon Signal.

If a Beacon Signal has no announcement for a member DID, that DID fails to resolve. Security Considerations, “Invalidation Attacks”, says: “if these updates cannot be retrieved by a resolver, the DID MUST be considered invalid.”

The specification recommends an n-of-n beacon address

Appendix, “No Privileged Role”, says: “those participating in aggregation SHOULD use a protocol that ensures every Aggregation Participant in the Aggregation Cohort has explicitly signed the Beacon Signal itself. It is RECOMMENDED that Aggregate Beacons use a Beacon Address that requires an n-of-n Schnorr Signature where each Aggregation Participant explicitly signs in a provable manner.”

Security Considerations, “Invalidation Attacks”, says: “To prevent these attacks, all Beacon Signals SHOULD be authorized by signatures: either from the DID controller when using a Singleton Beacon or with a n-of-n multisignature from all n members of an Aggregation Cohort when using an Aggregate Beacon.”

Security Considerations, “Aggregate Beacon Address Verification”, says: “A Beacon Address of an Aggregate Beacon SHOULD be an n-of-n Pay-to-Taproot (P2TR) address, with a key contributed to the n by each of the participants in an Aggregation Cohort. DID controllers participating in an Aggregation Cohort SHOULD verify the Beacon Address is an n-of-n and that one of the n keys is the key that they provided to the Aggregation Service.”

Appendix, “Worst Case”, names the two failure cases:

  1. “If the Beacon Signal does not require n-of-n signing, a hostile Aggregation Cohort (or Aggregation Service) could invalidate the DID by publishing a Beacon Signal with a malformed update.”
  2. “When the Beacon Signal does require n-of-n signing, a hostile Aggregation Cohort (or Aggregation Service) could render that Beacon inoperable, preventing publication of BTCR2 Updates through that address. However, this has no effect on other beacons.”

The same section says: “The best practice to avoid complete failure is to have at least one Singleton Beacon in every DID document, ensuring a fallback mechanism should all Aggregate Beacons fail.”

Aggregate Beacons, “BTCR2 Update Aggregation”, says: “A full protocol definition is out of scope for this specification, but a RECOMMENDED example is provided for illustration.”

Examples

Alice, Bob, and Carol are the members of a CAS cohort of service S. The advert of S names no fallbackThreshold.

  Before After, with the default values
Script tree leaf A (k = 2) and leaf B (key of S, 144 blocks) none
Who can publish a Beacon Signal all 3 members; any 2 members (leaf A); S alone after 144 blocks (leaf B) all 3 members
S puts 2 keys of its own in a cohort with Alice S publishes alone through leaf A S cannot publish without Alice
Bob goes offline 2 members complete the Beacon Signal through leaf A the beacon stops; a Singleton Beacon stays the backup beacon
The funds if Bob goes offline S can take them back through leaf B after 144 blocks they stay at the beacon address

Decision

1. Each script leaf is off by default

AggregationCohort.computeBeaconAddress adds a leaf only if the cohort conditions name it. With no leaf, the output has no script tree, and tapMerkleRoot is empty. The tweak is taggedHash('TapTweak', P), where P is the x-only form of the MuSig2 aggregate key (the BIP-86 form). Thus only all n members together can spend the output.

With both leaves, the order stays leaf A, then leaf B (ADR 043, decision 2).

2. The cohort conditions name each leaf

These functions refuse an input with only one of the two recovery values:

The advert shows each leaf and the exact k. Thus shouldJoin and the participant see the full script tree before the participant sends COHORT_OPT_IN.

3. The participant refuses each leaf that it does not allow

AggregationParticipantParams and AggregationParticipantRunnerOptions have two new options: allowFallbackLeaf and allowRecoveryLeaf. The default of each option is false. joinCohort refuses an advert that names a leaf that the participant does not allow:

The cohort stays in the Discovered phase. The participant runner calls shouldJoin first. If shouldJoin accepts the advert and joinCohort refuses it, the runner emits error and sends no COHORT_OPT_IN.

At COHORT_READY, the participant computes the beacon address with the leaf values of the advert. It refuses another address (BEACON_ADDRESS_MISMATCH, ADR 152). If the two addresses match, the address has only the leaves of the advert.

4. The participant checks the key count against the bounds of the advert

At COHORT_READY, the participant refuses a key count n below minParticipants or above maxParticipants of the advert. The error type is COHORT_SIZE_OUT_OF_BOUNDS. The data has cohortId, n, minParticipants, and maxParticipants. The check comes before validateMembership. The phase stays OptedIn, as for BEACON_ADDRESS_MISMATCH.

With leaf A, each key above the bound can be a key of the service, and the service can sign with k such keys without the members. Before this change, only the service checked the bounds.

5. A cohort with no leaf A has no fallback

6. Two beacon types for the same members need another key

The beacon type is not an input of the beacon address (ADR 152). With no leaf, the address depends only on the cohort keys and the network. Thus two cohorts with the same keys get one address, also if their beacon types differ. The BEACON_TYPE_CONFLICT check of ADR 152 stays the guard. The participant makes this check only for the cohorts of one participant object.

This ADR adds no code for this case. The JSDoc of CohortConditions.recoverySequence and of SoloCohortOptions.config, and the method docs, tell the caller to use another key of each member for another beacon type.

7. The solo runner adds no leaf by default

AggregationRunner.solo gives the leaf values of config to the service with no change. It sets no default value. SoloCohortOptions.config has the new optional fallbackThreshold. The solo participant allows leaf A if config.fallbackThreshold is present. It allows leaf B if config.recoveryKey or config.recoverySequence is present.

DEFAULT_RECOVERY_SEQUENCE stays exported as a suggested value. No code of the package uses it.

8. participant-funded stays refused

buildRecoveryLeaves refuses the funding model participant-funded with the error type UNSUPPORTED_FUNDING_MODEL, also with no leaf. Thus computeBeaconAddress refuses it before it sets tapTweak.

9. The wire version stays 2

The advert fields keep their names. An advert can now omit recoveryKey and recoverySequence. AGGREGATION_WIRE_VERSION stays 2 (ADR 168). The aggregation package 0.10.0 is the first release with wire version 2, and it has this change. Thus no released peer of wire version 2 has the old rules.

10. Each judgment call conforms to the specification texts

Judgment call Text Result
Each leaf is off by default, and a member must allow each leaf (decisions 1 and 3). Appendix, “No Privileged Role”: “It is RECOMMENDED that Aggregate Beacons use a Beacon Address that requires an n-of-n Schnorr Signature”. “Aggregate Beacon Address Verification”: “DID controllers participating in an Aggregation Cohort SHOULD verify the Beacon Address is an n-of-n”. Conforms. The default is the recommended form. A cohort with a leaf deviates from a SHOULD only with the consent of each member.
The values name each leaf, and k has no default (decision 2). Aggregate Beacons, “BTCR2 Update Aggregation”: “A full protocol definition is out of scope for this specification, but a RECOMMENDED example is provided for illustration.” The specification is silent. The advert shows the full script tree, so each member can verify it.
The participant checks n against the bounds of the advert (decision 4). “Aggregate Beacon Address Verification”: “that one of the n keys is the key that they provided to the Aggregation Service.” The specification is silent on the bounds. With this check, the participant limits the keys that a service can add to a cohort with leaf A.
For COHORT_SIZE_OUT_OF_BOUNDS, the phase stays OptedIn. The runner calls shouldJoin before the leaf check. The two leaf refusals have two error types (decisions 3 and 4). The scope text of the row on decision 2 applies. The specification is silent.
A cohort with no leaf A has no fallback (decision 5). Appendix, “Worst Case”, item 2: “this has no effect on other beacons.” Also: “The best practice to avoid complete failure is to have at least one Singleton Beacon in every DID document”. Conforms. The beacon stops, and the specification names the Singleton Beacon as the backup beacon.
The address of a cohort with no leaf depends only on the keys, and this ADR adds no code for two beacon types (decision 6). “Aggregate Beacon Address Verification”: “This can be achieved only by constructing the Beacon Address for themselves using the set of keys from the Aggregation Cohort”. Conforms. The address has no input that the specification does not name. Another key gives another address.
The member still does not check the change destination of a beacon transaction (residual “The change output with no leaf”). “Invalidation Attacks”: “DID controllers SHOULD verify the updates announced within a Beacon Signal before authorizing it.” The specification is silent on the change output. The member still verifies the Beacon Signal against the data (ADR 089, decision 1). The first reason of ADR 089, decision 3, stays: a member cannot tell a rotated change address from a drain address.
AGGREGATION_WIRE_VERSION stays 2 (decision 9). The specification defines no wire version. The scope text of the row on decision 2 applies. The specification is silent.

Alternatives

Keep each leaf on by default, and let a participant opt out. Rejected. The specification asks for an n-of-n address in three SHOULD rules. With this default, a participant that sets no option joins a cohort where one party can publish a Beacon Signal alone. “Worst Case” item 1 names that risk.

Remove both leaves. Rejected. A leaf is a tool for an operator and a cohort that accept its trade-off. Under a SHOULD, an implementation can deviate for a reason. With decision 3, each member gives its consent.

Use a flag for each leaf, with the old default values. Rejected. A flag and a value are two sources of truth for one leaf. The participant must then also know the default k. With decision 2, the advert shows the exact k.

Accept each leaf, and let only shouldJoin decide. Rejected. A caller with shouldJoin: async () => true then joins a cohort with leaves. The specification asks each DID controller to verify that the address is n-of-n.

Put the beacon type or the cohort id into the tweak. Rejected. The tweak then has an input that the specification does not name. The specification builds the address from “the set of keys from the Aggregation Cohort”. With the old default values (the key of the service, 144 blocks), both beacon types also got one address.

Fail the cohort for COHORT_SIZE_OUT_OF_BOUNDS, as for BEACON_TYPE_CONFLICT. Rejected. A wrong key count is a bad COHORT_READY of the service, as a wrong address is. For both, the phase stays OptedIn.

Skip an advert with a refused leaf before shouldJoin, with no event. Rejected. The caller wanted the cohort. The error event tells the caller why the join did not occur.

Use one error type with a leaf field. Rejected. With two error types, a caller can select the case by the type alone, as for each other error type of the participant.

Consequences

The public API breaks. No alias stays:

  1. This change removes resolveFallbackThreshold, AggregationCohort.effectiveFallbackThreshold, and the error type NO_RECOVERY_PARAMS.
  2. CohortConditions.recoveryKey and CohortConditions.recoverySequence are optional. BeaconLeafParams requires only cohortKeys. buildRecoveryLeaves returns 0, 1, or 2 leaves. recoveryLeafParams and the error type INCOMPLETE_RECOVERY_PARAMS are new.
  3. FallbackSpendParams.fallbackThreshold is required. FallbackSpendParams.recoveryKey and FallbackSpendParams.recoverySequence are optional. RecoverySpendParams.fallbackThreshold has no default.
  4. The participant options allowFallbackLeaf and allowRecoveryLeaf are new. The error types FALLBACK_LEAF_NOT_ALLOWED, RECOVERY_LEAF_NOT_ALLOWED, COHORT_SIZE_OUT_OF_BOUNDS, and NO_FALLBACK_LEAF are new.
  5. AggregationRunner.solo sets no default leaf value. SoloCohortOptions.config.fallbackThreshold is new.

These residuals stay:

Superseded.

Unchanged.

Implementation

References