Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
149 changes: 149 additions & 0 deletions honest.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@

# Overview: Honest multiparty PayJoin

The following is a concrete description of the honest multiparty PayJoin protocol. To understand why certain choices design were made, it is recommended to read the [overview document](./00_overview.md) first.

## Motivation

This protocol is best understood as a collaborative transaction construction protocol for mutually trusting parties. Its purpose is to let participants jointly build a valid transaction potentially better privacy properties and cost savings than unilateral construction. The other parties are not trusted with the safety of your funds: fund safety should be enforced cryptographically and by local validation before signing. What they are trusted with is liveness (showing up, responding, and progressing the round) and privacy (handling protocol information honestly and not needlessly leaking it).

## Roles

### Initiator and Responder

The Initiator signals willingness to batch to their counterparty over a bidirectional channel. This signal is conveyed by including the mppj=1 parameter in the BIP21 URI. Either the BIP77 sender or receiver may be the Initiator. Parameters for their bi-directional channel may be encoded in the BIP21 (same as BIP77).

The Responder is the counterparty who receives this signal. A Responder that does not support multiparty PayJoin will ignore the mppj=1 parameter and proceed with standard BIP77. A Responder that supports it waits for a session to be created.

Two timeouts govern the phase of the whole protocol:

* `T_intent`: the duration both parties are willing to wait for a session to be created after the intent to batch is signaled. If no session is created within T_intent, both parties MUST fall back to standard BIP77 over their existing bidirectional channel.
* `T_session`: the duration of the multiparty session itself, after which input and output registration closes and the protocol advances to signing.

`T_session` is defined by the `SessionCreator` while `T_intent` is defined by the `Initiator`.

// TODO: how do we indicate to sender/recv that we should join a mppj? out of band? New message? mailbox with more payment instructions?

### SessionCreator

Either the `Initiator` or the `Responder` may create the session. The party that does so is the `SessionCreator`.
The `SessionCreator` is responsible to creating session parameters (defined below), bootstrapping the transport mechanism and disseminating session information to the rest of the peers to the best of their capabilities. `SessionCreator` holds no special authority once the session is live. They simply become a participant.

### Participant

Once a party joins a session (defined below) they become a `Participant`. All participants share the same obligations as outlined below.

### Diagrams

Single receiver, two senders. Receiver is `Initiator` for both senders and becomes the `SessionCreator`.

```mermaid
sequenceDiagram
participant R as Receiver (Initiator)
participant S1 as Sender 1 (Responder)
participant S2 as Sender 2 (Responder)

Note over R,S1: T1
R->>S1: BIP21 URI (mppj=1)

Note over R,S2: T2
R->>S2: BIP21 URI (mppj=1)

Note over S1,S2: T3 - Receiver becomes SessionCreator
R->>S1: session invitation (s, session params)
R->>S2: session invitation (s, session params)
```

Sender 1 is the `Initiator` to the receiver who is an `Initiator` to sender 2. The receiver at time 3 becomes the `SessionCreator`

```mermaid
sequenceDiagram
participant S1 as Sender 1 (Initiator)
participant R as Receiver (Responder / Initiator / SessionCreator)
participant S2 as Sender 2 (Responder)

Note over S1,R: T1
S1->>R: BIP21 URI (mppj=1)

Note over R,S2: T2
R->>S2: BIP21 URI (mppj=1)

Note over S1,S2: T3 - Receiver becomes SessionCreator
R->>S1: session invitation (s, session params)
R->>S2: session invitation (s, session params)
```

## Session Parameters

The SessionCreator fixes the following parameters before the session opens. All participants MUST verify that the final transaction conforms to these parameters before signing.

* **Global transaction fields**: `nLocktime`, `nVersion`
* **Feerate**: each participant contributes fees proportional to the weight of their inputs and outputs
* **Input constraints**: `nSequence`, script type, segwit only
* **Timeouts**: `T_session` (see Roles)

## PSBT CRDT

### Join Semantics

Participants learn transaction fragments in arbitrary order and accumulate them as they arrive. In the semi-honest setting there are no conflicting writes: global fields are fixed by the session parameters and each participant controls disjoint inputs and outputs. Any two valid fragments can therefore be merged by union.

If the accumulated transaction does not balance, or any fragment violates the session parameters, a participant MUST refuse to sign and abandon the session.

// TODO: refer to nothingmuch's document

## Communication model

### Gossip broadcast over Iroh

In the honest setting, participants can use an authenticated gossip broadcast channel such as [Iroh gossip](https://docs.iroh.computer/connecting/gossip) to disseminate PSBT fragments to the whole group. Each participant broadcasts their protocol messages (inputs, outputs, readiness declarations, and witnesses) to the session topic, and peers merge the received fragments into their local transaction view.

This setting does not require transport-layer metadata privacy as a protocol requirement. The reason is that participants are already mutually trusted with privacy in the honest model, including trust not to retain or misuse linkability information learned during the session. As a result, unlike the semi-honest setting, the protocol does not depend on anonymous transport primitives (for example OHTTP or Tor) to maintain the intended privacy properties within the participant set.

Metadata protection can still be desirable as a deployment hardening measure (for example to reduce network observer visibility), but it is optional and not foundational to the honest protocol's security or privacy assumptions.

In this honest setting, a separate agreement protocol is not required for the success path. Gossip dissemination plus deterministic transaction construction is sufficient: if participants receive the same valid fragments, they converge to the same unsigned transaction. Any temporary view differences are primarily a liveness concern (delay or retry), not a fund-safety concern, because each participant still performs local validation and only signs an acceptable transaction.

// TODO: how to do discovery of other peers?
// TODO: yolo RAFT leader based agreement / lattice agreement. Trusted leader = "trusted with liveness".
// TODO; peers that are offline and missed input / output registration will leak them selves.
// TODO: peers need reconcile messages that they missed

## Protocol Phases

Input and output registration can be sent in any order. Ordering and sorting semantics must be defined a priori. (Should outputs defined before inputs ?)
One possible definition is to use the hash of the protocol transcript as a salt to sort the inputs and outputs.

All messages are base64 encoded as PSBT fragments.

// TODO: coinselection strategy? do peers run their own coinselection based on their own target outputs? What if a recv doesnt have target outputs? Would peers change outputs based on others output selection?

### Input Registration

Each participant submits the transaction inputs they control. Inputs must be posted as independent messages.
Global observers should not be able to determine which inputs originate from the same party.

### Psuedo Outputs

// Move to semi-honest. In honest, peers can just declare how much they are burning in their input messages

A pseudo output is an anonymous declaration of fee contribution above the session-mandated minimum. It participates in the balance equation like a real output but does not appear in the final transaction. Participants MUST post a pseudo output only when their intended fee contribution exceeds what the session parameters require.

When the global sum of inputs minus outputs minus pseudo outputs reaches zero, every participant can independently verify the transaction is balanced and proceed declare RTS.

### Output Registration

Output and pseudo output messages MUST carry a unique identifier to prevent double accounting.

A participant who wishes to back out of the session posts an output that causes the transaction balance to overflow. That is, their declared outputs exceed their input contribution. This makes the balance equation unsatisfiable and MUST cause all other participants to refuse to sign.

### Ready-to-sign (RTS) declarations

For each input they control, participants post a ready-to-sign declaration. This signals that they accept the current transaction template and are prepared to sign it.
Only once all inputs have corresponding ready signals does the protocol advance. This ensures that all participants have finished contributing transaction fragments.

When the global sum of inputs minus outputs minus pseudo outputs fee declarations hits zero, every participant can independently verify the transaction is balanced and sign.

### Witness provision

Participants provide witnesses for the inputs they control. Once all witnesses are available, any participant can assemble the fully signed transaction and broadcast it to the Bitcoin network.
60 changes: 60 additions & 0 deletions semi-honest.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Overview: Semi-honest multiparty PayJoin

The following is a concrete description of the semi-honest multiparty PayJoin protocol. To understand why certain choices design were made, it is recommended to read the [overview document](./00_overview.md) first.

// TODO: supporting silent payments
// TODO: Two phases ?: you cannot add output until every input owner indicated no more OR we just say liveness is weak.
Since this is semi honest the only thing we need tolerate is crashes: someone has a delay and adds inputs at the last second

## Motivation

Two-party Payjoin preserves privacy of input/output ownership against third-party observers, but it does not preserve privacy from the view of the counterparty itself. In a two-party protocol, each participant can trivially attribute all unknown inputs and outputs to the other party. This reveals cluster information and requires counterparty trust.

With n > 2, this privileged view is reduced. Payments and change outputs become ambiguous within the participant set. As a result, participants do not need to trust any specific counterparty with their clustering information. Increasing the number of parties therefore reduces counterparty trust and weakens clustering inferences.

## Threat model

This protocol operates in a semi-honest (honest-but-curious) model. All participants are assumed to economically proximate and thus follow the protocol as specified. They are not expected to deviate from the rules or misbehave in any form. However, they may attempt to learn as much as possible from the messages they observe.

Concretely, if any party learns the full plaintext transcript of messages, they should not be able to determine which inputs or outputs belong to which of the other participants.

The protocol does not assume Byzantine robustness, and it does not attempt to detect or punish misbehavior. If a participant fails to follow through, the protocol may fail, but safety is not compromised - i.e participants will only provide witness if their expected outputs are included in the final transaction.

Its possible for some participants to join late. If there are N-1 RTS messages and a participant then registers then inputs and outputs this trivially creates a input-output link.
Possible mitigation include ignoring this laggard when the effective balance condition and N RTS's have been collected.

## Communication model

In the semi-honest model, participants follow protocol rules but are still curious and may try to infer ownership links from any side channel available to them. For that reason, content encryption alone is not sufficient: if transport metadata reveals who posted which message and when, peers can correlate input registrations, output registrations, and RTS/witness messages into participant-level clusters.

Metadata privacy is therefore a protocol requirement in this setting. The communication layer must hide sender network identity and reduce linkability across messages, so that learning the transcript does not trivially reveal input-output ownership.

This is why plain iroh gossip is not sufficient here as the primary transport. While iroh provides efficient dissemination, it does not by itself provide the metadata-hiding guarantees this threat model requires.

Separately, dissemination and agreement should be distinguished. Gossip is enough to disseminate messages and can still provide eventual convergence when deterministic merge rules are used. A separate agreement mechanism (some specific instantiation of a lattice agreement protocol) is only needed when stronger guarantees are required for intermediate consistency, timely termination, (crashes?) or recovery under communication disruptions.

Given those tradeoffs, using the BIP77 directory for ordering is a simpler direction. A shared append-only mailbox gives participants a practical, common message order to process, which reduces the need to deploy and tune a separate distributed agreement layer. In other words, it combines the metadata privacy this model requires with a straightforward coordination primitive that is easier to implement and operate.

### BIP77 Directory as anonymous broadcast channel

Communication is mediated by a PayJoin directory accessed via OHTTP, following the same metadata privacy model as BIP77. For multiparty use, the directory mailbox supports append semantics. Multiple participants write to the same mailbox, and peers poll and retrieve all appended messages. The mailbox functions as an anonymous broadcast log of encrypted payloads.

#### Shared session secret

A session is defined by a single ephemeral shared secret s. Any participant who learns s can join the session. Knowledge of this secret is the only admission control mechanism.
Participants derive mailbox identifiers and initialize their HPKE context with s. The shared secret is distributed via the existing bidirectional channel. Parties who learn s can both read and write to the mailbox. All payloads are encrypted using HPKE, so the directory only handles opaque ciphertext blobs and cannot link messages to participants.

## Protocol phases

For the canonical phase-by-phase flow, see the honest protocol document: [Overview: Honest multiparty PayJoin](./honest.md#protocol-phases).

### Message Timing

To prevent timing correlation between a participant's messages, each message MUST be assigned a randomized delay before posting.

If the total number of messages is known in advance, sample n uniform random times within the session window and post each message at its assigned time. If the count is not yet known, sample delays from an exponential distribution instead.

Message publication times are assigned in two phases:

1. Input registration, output registration, and RTS declarations are assigned publication times at the start of the session.
2. Witness provision messages MUST NOT be assigned publication times until registration closes.