did-btcr2-js

ADR 168: The Aggregation Participant Makes the SMT Nonce and Sends Only the Update Hash

Context

In this ADR, a member is a participant that the service accepted in a cohort. A nonce is the SMT nonce of a leaf value, not a MuSig2 nonce. updateId is the JSON Document Hash of a BTCR2 Update (32 bytes).

The service got the full update and made the SMT nonce

In an aggregate beacon round, each member answers an update opportunity. Before this change, the participant sent SUBMIT_UPDATE with the body { cohortId, signedUpdate }, the full BTCR2 Update. A member with no update sent SUBMIT_NONINCLUDED. For an SMT cohort, AggregationCohort.buildSMTTree made a nonce for each member with randomBytes(32). It computed each leaf value from that nonce and, for an update, the updateId, and it gave each member a proof with the nonce.

Thus the service learned three facts about each member: the text of the update, the nonce, and if the member had an update. A known nonce hides nothing from the party that knows it.

An update can be private sidecar data. Privacy Considerations, “Updates Can Be Private”, says: “Bitcoin is used to publicly announce and anchor updates to DID documents, however the updates themselves can be kept private by DID controllers and provided through a Sidecar mechanism at Resolution Time.”

The specification gives the service only a hash

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

ADR 029 accepted the leak with a false premise

ADR 029, “Consequences”, “Negative”, says: “The service operator can read plaintext of all directed messages they relay, including SUBMIT_UPDATE payloads. Mitigating factor: those payloads are already intended to be on-chain public data.” The premise is false for a sidecar update. Only the Beacon Signal goes on chain, and the update can stay private.

ADR 029, “Explicitly accepted trade-offs”, also says: “Participants who require end-to-end privacy against the service operator should use the Nostr transport, which offers NIP-44 envelope encryption at the wire layer.” The Nostr transport encrypts each directed message to the key of the recipient. The service is the recipient of SUBMIT_UPDATE, so the service decrypts it. Thus no transport hides the body of SUBMIT_UPDATE from the service.

Examples

Case Before After
An SMT member adds a private service endpoint and keeps the update as sidecar data The service gets the full update and makes the nonce. The service gets only hash(hash(nonce) + updateId). The member makes and keeps the nonce.
An SMT member has no update The member sends SUBMIT_NONINCLUDED, so the service knows that the member has no update. The member sends SUBMIT_UPDATE with hash(hash(nonce)). The service cannot tell it from an update.
A CAS member has an update The service gets the full update and computes its hash. The service gets the hash. The CAS Announcement holds the same hash.
A participant of wire version 1 sees an advert of a service of wire version 2 Not applicable: each earlier release used wire version 1. The participant ignores the advert, so it does not join the cohort.

Decision

1. SUBMIT_UPDATE holds only the updateHash

The body of SUBMIT_UPDATE is { cohortId, updateHash }. SubmitUpdateBody.updateHash replaces SubmitUpdateBody.signedUpdate, and BaseBody.updateHash replaces BaseBody.signedUpdate. The value is 32 bytes in base64url with no padding. The name is the specification name for both beacon types:

The body has no did field and no didIndex field. The service takes the DID from the sender of the transport envelope, as before. The SMT index is didToIndex(did), the SHA-256 hash of the DID. createSubmitUpdateMessage takes updateHash, and isSubmitUpdateMessage requires an updateHash string.

2. The service checks only the form of the updateHash

#handleSubmitUpdate applies these steps in this order:

  1. If the body has no cohortId, or if the service does not know the cohort, the service ignores the message. It also ignores the message outside the phases CohortSet and CollectingUpdates. It records no rejection.
  2. If updateHash is not a string, the service refuses the message with UPDATE_MALFORMED (“SUBMIT_UPDATE has no updateHash string”).
  3. If the sender is not a member of the cohort, the service refuses the message with NOT_A_MEMBER.
  4. If updateHash does not decode to exactly 32 bytes, the service refuses the message with UPDATE_MALFORMED (“SUBMIT_UPDATE updateHash is not 32 bytes in base64url”). The decoder base64UrlToHash (smt) is strict: it refuses the padding character = and padding bits that are not zero.
  5. If the member already declined or already submitted a value in this round, the service refuses the message with DUPLICATE_RESPONSE.
  6. addUpdate(participantDid, updateHash) stores the string as the member sent it.

The membership check and the DUPLICATE_RESPONSE check keep their order. A refused value is not an answer, so the member can send a good value after it. The first good value stands. UPDATE_MALFORMED now has two causes: no updateHash string, and a value that does not decode to 32 bytes.

3. The service has no size cap and no check of the update sender

The service no longer gets the update. Thus this change removes these items, with no alias:

The reasons:

4. The cohort builds the aggregated data from the submitted values

AggregationCohort.updateHashes: Map<string, string> (DID to updateHash) replaces pendingUpdates: Map<string, SecuredDocument>. addUpdate(participantDid, updateHash) takes the value. AggregationService.collectedUpdateHashes(cohortId) replaces collectedUpdates(cohortId). The cohort holds no update and no nonce.

The signal bytes keep their form: the SHA-256 hash of the canonical CAS Announcement, or the SMT root.

5. The participant makes the SMT nonce and the value

submitUpdate(cohortId, signedUpdate) keeps its signature. The participant computes updateId with canonicalHashBytes(signedUpdate). If an update has no JCS form, submitUpdate throws an AggregationParticipantError of type UPDATE_MALFORMED, as before (ADR 154, decision 7). Then it sends only the value:

The participant keeps updateHash, nonce, and updateId in its cohort state. These three fields replace submittedUpdate. The caller keeps the update. The service gets neither the update nor the nonce.

6. A participant with no update in an SMT cohort sends SUBMIT_UPDATE

The action of declineUpdate(cohortId) depends on the beacon type of the cohort:

In both cases, the phase becomes NonIncluded, and CohortCompleteInfo.included is false. The member stays in the cohort and signs. submitUpdate and declineUpdate use one private helper, #submit.

7. The service accepts SUBMIT_NONINCLUDED in an SMT cohort and leaves the index empty

The service still accepts SUBMIT_NONINCLUDED in an SMT cohort. The membership check and the DUPLICATE_RESPONSE check of #handleSubmitNonInclusion do not change. buildSMTTree puts no leaf at the index of that member, so the index stays empty with the leaf value cachedZero[0]. The member gets a proof of its index, and verifyProof returns true for it with no nonce and no updateId. The library participant does not send SUBMIT_NONINCLUDED in an SMT cohort (decision 6). If another implementation sends it, the service knows that the member has no update.

8. The participant validates its slot with its own values

The SMT strategy takes only id, collapsed, and hashes from the proof of the service. It adds the nonce that the member made and, for an update, the updateId of the member. Then it calls verifyProof. If the service puts a nonce or an updateId in the proof, the strategy ignores them. Thus verifyProof returns true only for the leaf value that the member selected.

The result is the full SMT Proof of the member. PendingValidation.smtProof and CohortCompleteInfo.smtProof hold it. The caller must persist it, because only the member knows the nonce.

The CAS strategy compares the map value of the member with the updateHash that the member kept. A member with no updateHash must be absent from the map, as before. deriveSignal does not change: the SMT signal is the id of the proof (ADR 089, decision 1).

9. The beacon strategy makes the values of a round

AggregateBeaconStrategy gets the required method prepareSubmission(updateId?): BeaconSubmission. The new type BeaconSubmission is { updateHash?, nonce? }:

validateParticipantView takes { participantDid, updateHash?, nonce?, updateId?, body }. This change removes the parameters included, submittedUpdate, and expectedHash. The strategy of each beacon type makes and checks its own value, as it already checks its own aggregated data.

10. buildSMTTree leaves the index empty for a submitted value equal to cachedZero[0]

buildSMTTree skips a submitted value equal to cachedZero[0]. The index of that member stays empty, and the root does not change. cachedZero[0] is the value of an empty leaf. A leaf with that value can give another member a sibling hash equal to a cached zero. verifyProof returns false for such a proof. Thus without the skip, one member can make verifyProof return false for the proofs of other members.

11. The wire version is 2

AGGREGATION_WIRE_VERSION is 2. The SUBMIT_UPDATE body changes, so a peer of version 1 and a peer of version 2 cannot complete a round together.

AggregationParticipant.receive ignores each message with another wire version, also a COHORT_ADVERT. Thus a participant of version 1 does not join a cohort of version 2. If AggregationService.receive knows the cohort of a message with another wire version, it refuses the message with WRONG_VERSION. Else it ignores the message.

If the wire version stays 1, an older participant joins the new cohort. The service refuses its SUBMIT_UPDATE with UPDATE_MALFORMED, because the body has no updateHash. The participant sends no other answer. cohortTtlMs and phaseTimeoutMs of the service runner are off by default. Thus the cohort waits, and one older participant stops the round of all members.

The method docs (packages/method/docs/aggregation.md, “Wire-format version”) say that a change of the constant “is a breaking protocol change”. ADR 027 (the mitigation of T3) says: “Mismatched messages are rejected, not silently processed as a possibly-incompatible shape.”

12. Each judgment call conforms to the specification texts

Judgment call Text Result
The body names the value updateHash for both beacon types. It has no did field and no didIndex field (decision 1). Aggregate Beacons, “Respond to Update Opportunities”: “updateHash: The SHA-256 hash of the BTCR2 Update to be included, created with the JSON Document Hashing algorithm.” Also: “didIndex: The SHA-256 hash of the DID to be updated;”. Conforms. The name is the name of the specification. The sender of the transport envelope gives the DID, and the service computes hash(did).
The service checks only that the value is 32 bytes. It has no size cap and no sender check (decisions 2 and 3). Privacy Considerations: “aggregators are able to coordinate Beacon Signals without needing to view or validate DID documents or the updates.” Conforms. The service cannot validate a hash. A bad value harms only the DID of the sender. The specification sets no message size.
The participant makes the nonce and the value. For an SMT decline, the participant sends SUBMIT_UPDATE with hash(hash(nonce)) (decisions 5 and 6). SMT appendix: “The DID controller selects the value for that index in that signal”. Also: “With a nonce, other parties (aggregators, other DID controllers, verifiers) cannot know if there is an update, or its contents.” Aggregate Beacons: “If a nonce is used: hash(hash(nonce))”. Conforms. The service gets only a leaf value, and the two cases have one message type.
The service accepts SUBMIT_NONINCLUDED in an SMT cohort and leaves the index empty (decision 7). Aggregate Beacons: “If a nonce is not used: no value, the index stays empty and its leaf value is cachedZero[0]”. Step 3: “Every registered index MUST appear as a leaf.” Conforms. The specification lists this case. The empty index has the leaf value cachedZero[0], and the member gets an SMT Proof of its index.
The member adds its own nonce and updateId to the proof of the service. CohortCompleteInfo.smtProof holds the full proof (decision 8). Aggregate Beacons: “Participants MUST persist their nonce values.” “Confirm Signal Request”: “For SMT Beacon Signals, Aggregation Participants must persist the BTCR2 Updates, nonce values, and SMT Proofs for each index they control.” Conforms. The caller gets the nonce in the proof that it must persist. A nonce of the service cannot change the result.
The strategy interface gets prepareSubmission, and validateParticipantView takes the values that the member kept (decision 9). 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 strategy of each beacon type already selects its aggregated data.
buildSMTTree leaves the index empty for a submitted value equal to cachedZero[0] (decision 10). Algorithms, “SMT Proof Verification”: “A 0 bit of collapsed selects an entry of hashes that is equal to the cached zero of that level.” Also: “No nonce and no updateId: cachedZero[0], the value of an empty leaf.” Conforms. The value is the value of an empty leaf, so the root is the same. The skip keeps the proofs of the other members valid.
AGGREGATION_WIRE_VERSION is 2 (decision 11). The specification defines no wire version. The scope text of the row on decision 9 applies. The specification is silent. A participant of version 1 does not join a cohort that it cannot complete.

Alternatives

Make the nonce on the participant, but keep the full update in SUBMIT_UPDATE. Rejected. The full update shows the same facts: its text, and that the member has an update. The nonce then hides nothing from the service.

Record the leak in an ADR only. Rejected. Privacy Considerations, “Aggregation Services Only Need Hashes”, says that aggregators “are provided with a hash or Content Identifier (CID) of the update”. The SMT appendix says that, with a nonce, aggregators “cannot know if there is an update”. A record does not stop the leak.

Keep wire version 1. Rejected. An older participant then joins a new cohort, and the service refuses its SUBMIT_UPDATE with UPDATE_MALFORMED. With the default runner options, the cohort then waits with no end.

Refuse SUBMIT_NONINCLUDED in an SMT cohort. Rejected. The SMT response of the specification lists the case “no value, the index stays empty”. A member of another implementation can select it.

Keep a size cap for the body. Rejected. The body has a fixed size. In step 4 of decision 2, the service refuses each value that is not 32 bytes.

Consequences

The public API breaks. No alias stays:

  1. SubmitUpdateBody.signedUpdate and BaseBody.signedUpdate become updateHash. createSubmitUpdateMessage takes updateHash. isSubmitUpdateMessage requires an updateHash string.
  2. This change removes maxUpdateSizeBytes from AggregationServiceParams, AggregationService, and AggregationServiceRunnerOptions. It also removes DEFAULT_MAX_UPDATE_SIZE_BYTES.
  3. This change removes UPDATE_TOO_LARGE and UPDATE_SENDER_MISMATCH from RejectionReason.
  4. AggregationService.collectedUpdates becomes collectedUpdateHashes. AggregationCohort.pendingUpdates becomes updateHashes, and addUpdate takes an updateHash string.
  5. AggregateBeaconStrategy gets the required method prepareSubmission and the new parameters of validateParticipantView. BeaconSubmission is new. AGGREGATION_WIRE_VERSION is 2.

These residuals stay:

Superseded.

Unchanged.

Implementation

References