CoinJoin#

Dash Core’s mixing feature provides a way to improve privacy by performing non-custodial CoinJoin. For additional details, reference this Official Documentation page.

The following video provides an overview with a good introduction to the details:

Wallet Preparation#

The wallet completes two operations in this phase:

  1. Split value into inputs matching the CoinJoin denominations by sending transactions to itself

  2. Split value into inputs to use for collateral by sending transactions to itself

Note: Both these operations incur the standard transaction fee like any other transaction

Creating Denominations

The CoinJoin denominations include a bit mapping to easily differentiate them. The dsa message and dsq message use this bit shifted integer instead of sending the actual denomination. The table below lists the bit, its associated integer value used in P2P messages, and the actual Dash value.

Bit

Denom. (Integer)

Denomination (DASH)

0

1

10.0001

1

2

01.00001

2

4

00.100001

3

8

00.0100001

4

16

00.00100001

Protocol version 70213 added a 5th denomination (0.001 DASH).

Example Testnet denomination creation transaction

Creating Collaterals

Collaterals are used to pay CoinJoin fees, but are kept separate from the denominations to maximize privacy. Since protocol version 70213, the minimum collateral fee is 1/10 of the smallest denomination for all sessions regardless of denomination. In Dash Core, collaterals are created with enough value to pay 4 collateral fees (4 x 0.001 DASH). (Dash Core Reference)

In protocol versions > 70208, Dash Core can use any input from 1x the minimum collateral amount to the maximum collateral amount.

Example Testnet collateral creation transaction

Example Testnet collateral payment transaction

CoinJoin Processing#

This phase involves exchanging a sequence of messages with a masternode so it can construct a denominate transaction with inputs from the clients in its pool.

Data Flow#

Attention

Since protocol version 70234 (Dash Core 22.0.0), the dsq message is broadcast using the inventory system instead of being relayed to all connected peers. This reduces the bandwidth needs for all nodes, especially highly connected masternodes.

Clients

Direction

Masternode

Description

0

Client determines whether to join an existing pool or create a new one

1

dsa message

Client asks to join pool or have the masternode create a new one

2

dssu message

Masternode provides a pool status update (Typical - State: POOL_STATE_QUEUE, Message: MSG_NOERR)

3

inv message (dsq)

Masternode notifies clients when it is ready to receive inputs by sending a dsq inventory message

4

getdata message (dsq)

Client requests a dsq message

5

dsq message

Masternode responds with the requested dsq message

6

dsi message

Upon receiving a dsq message with the Ready bit set, clients each provide a list of their inputs (unsigned), collateral, and a list of outputs where funds should be sent

7

dssu message

Masternode provides a pool status update (typical - State: POOL_STATE_ACCEPTING_ENTRIES, Message: MSG_ENTRIES_ADDED)

8

dsf message

Masternode sends the final transaction containing all clients inputs (unsigned) and all client outputs to each client for verification

9

dssu message

Masternode provides a pool status update (Typical - State: POOL_STATE_SIGNING, Message: MSG_NOERR)

10

dss message

After verifying the final transaction, clients each sign their own inputs with the SIGHASH_ALL | SIGHASH_ANYONECANPAY signature type and send them back

11

dsc message

Masternode verifies the signed inputs, creates a dstx message to broadcast the transaction, and notifies clients that the denominate transaction is complete (Typical - Message: MSG_SUCCESS)

12

inv message

Masternode broadcasts a dstx inventory message

13

getdata message (dstx)

(Optional)

Additional notes#

Step 0 - Pool Selection

  • Existing pool information is derived from the Queue messages seen by the client

  • Dash Core attempts to join an existing pool and only requests creation of a new one if that fails, although this is not a requirement that alternative implementations would be required to follow

Step 1 - Pool Request

Steps 3-5 - Queue

Attention

Clients must respond to the Queue ready within 30 seconds or risk forfeiting the collateral they provided in the dsa message (Step 1) (Dash Core Reference)

  • When a masternode starts a new queue, it broadcasts an inventory message notifying all peers of an available dsq message. Interested clients can then request the full dsq message. Prior to protocol version 70234, dsq messages were directly relayed to all peers.

  • Sessions have a variable number of participants defined by the range nPoolMinParticipants (3 for mainnet, 2 for other networks) to nPoolMaxParticipants (20).

  • The masternode sends an inventory message for a dsq message with the ready bit set once it has received valid dsa messages from either:

    1. The maximum number of clients

    2. Greater than the minimum number of clients and the timeout has been reached (30 seconds)

Step 6 - Inputs

  • The collateral transaction can be the same in the dsi message as the one in the dsa message (Step 1) as long as it has not been spent

  • Each client can provide up to 9 (COINJOIN_ENTRY_MAX_SIZE) inputs (and an equal number of outputs) to be used (Dash Core Reference)

  • This is the only message in the process that contains enough information to link a wallet’s CoinJoin inputs with its outputs

    • This message is sent directly between a client and the masternode processing the session (not relayed across the Dash network) so no other clients see it

Step 8 - Final Transaction (unsigned)

  • Once the masternode has received valid dsi messages from all clients, it creates the final transaction and sends a dsf message

    • Inputs/outputs are ordered deterministically as defined by BIP-69 to avoid leaking any data (Dash Core Reference)

    • Clients must sign their inputs to the Final Transaction within 15 seconds or risk forfeiting the collateral they provided in the dsi message (Step 4) (Dash Core Reference)

Step 12 - Final Transaction broadcast

As of protocol version 70213, up to 5 (MASTERNODE_MAX_MIXING_TXES) un-mined dstx messages per masternode are allowed. (Dash Core Reference)

General

With the exception of the dsq message and the dstx message (which need to be public and do not expose any private information), all CoinJoin P2P messages are sent directly between the masternode processing the transaction and the relevant client(s).

Fees#

Processing Fees

  • If processing completes successfully, Dash Core charges the collateral randomly in 1/10 denominate transactions to pay miners (Dash Core Reference)

  • Clients that abuse the system by failing to respond to dsq messages or dsf messages within the timeout periods may forfeit their collateral. Dash Core charges the abuse fee in 1/3 cases (Dash Core Reference)

Sending Fees

To maintain privacy when using CoinJoin funds, transactions must fully spend all inputs to a single output (with the remainder becoming the fee - i.e. no change output). This can result in large fees depending on the value being sent.

For example, an extreme case is sending the minimum non-dust value (546 duffs). This results in an extremely large transaction fee because the minimum denomination (0.00100001 DASH or 100,001 duffs) must be fully spent with no change. This results in a fee of 0.00999464 DASH and a sent value of only 0.00000546 DASH as shown by the calculation below.

100001 duffs (smallest CoinJoin denomination) - 546 duffs (value to send) = 99455 duffs (fee)