# Taprootized Atomic Swaps

Taprootized Atomic Swaps (TAS) is an extension for Atomic Swaps that presumes the untraceability of transactions related to a particular swap. Based on Schnorr signatures, Taproot technology, and zero-knowledge proofs, the taprootized atomic swaps hide swap transactions under regular payments.

## Intro

Atomic swap is an incredible approach to cross-chain exchanges without mediators. However, one of the disadvantages of its implementation in the classical form is the “digital trail” — any party can make a matching between transactions in the blockchains in which the exchange took place and find out both the participants in the exchange and the proportion in which assets were exchanged.

On the other hand, atomic swaps is a technology that initially assumed the involvement of only two parties and a “mathematical contract” between them directly. That is, an ideal exchange presupposes two conditions:

- Only counterparties participate in the exchange (works by default)
- Only counterparties know about the fact of the exchange (it would be nice to ensure)

This paper will provide a concept of taprootized atomic swaps that allow hiding the swap’s very fact. To an external auditor, transactions to initiate and execute atomic swaps will be indistinguishable from regular Bitcoin payments. In the other accounting system involved in the transfer, more information is disclosed (the fact of exchange can be traced). Still, it is impossible to link this to the corresponding Bitcoin transactions (without additional context from the involved parties).

## Protocol

The protocol includes the following steps:

- Alice (skA, PKA) and Bob (skB, PKB) have their keypairs and know each other’s public keys.
- Alice generates a random
and calculates the public value**k****K = k * G** - Alice forms the alternative spending path
in the form of Bitcoin Script**Script = sig(skA) + Locktime** - Alice calculates an escrow public key as
(here, escrow is just a public key, formed using Taproot technology)**PKEsc = K + PKB + hash((K + PKB) || Script) * G**- The signature
, verified by the**sig(skEsc)**, can be generated only with the knowledge of**PKEsc**,**k**, and**skB****Script**

- The signature
- Alice calculates
as a hash value of**h**(zk-friendly hash function is recommended to use)**k** - Alice forms the funding transactions with the following conditions of how it can be spent:
- Signature of
: Bob, with knowledge of**skEsc**and**k**can spend the output**skB** - Signature of
: Alice, with knowledge of**skA + Locktime**can spend the output, but only after some point in time**skA**(the**t1**itself)**Script**

- Signature of
- Alice sends the transaction to the Bitcoin network
- Alice generates the zero-knowledge proof that includes (for the same
):**k**- The proof of knowledge of
that satisfies**k****k*G == K - The proof of knowledge of
that satisfies**k****zkHash(k) == h**

- The proof of knowledge of
- Alice provides the set of data to Bob:
**h****K****Script****proof**

- Bob calculates
as**PKEsc**and finds the transaction locked BTC (verifies if it exists). Then Bob performs the following verifications:**K + PKB + hash((K + PKB) || Script) * G**- Verifies that Alice knows
that satisfies**k*** and*k*G == K, it means that Bob can access the output**zkHash(k) == h**if he receives**PKEsc****k** - Verifies that the
is correct and includes only the required alternative path.**Script**

- Verifies that Alice knows
- If verifications are passed, Bob forms the transaction that locks his funds on the following conditions:
- Publishing of
and the signature of**k**: only Alice can spend it if she reveals**skA**(hash preimage)**k** - Signature of
: Bob, with knowledge of**skB + Locktime**, can spend the output, but only after some point in time t2**skB**

- Publishing of
- Bob sends the transaction to the Ethereum network (or any other that supports zkHash())
- Alice sees the locking conditions defined by Bob and publishes the
and the signature generated by her**k**. As a result — Alice spent funds locked by Bob.**skA**- If Alice doesn’t publish the relevant
, Bob can return funds after**k**is reached**t2**

- If Alice doesn’t publish the relevant
- If Alice publishes a transaction with
, Bob can recognize it and extract the**k**value**k** - Bob calculates the needed
as**skEsc****skEsc = k + skB + hash((K + PKB) || Script)** - Bob sends the transaction with the signature generated by the
and spends funds locked by Alice**skEsc**

## Implementation notes

- As an approach for escrow public key forming, the MuSig aggregation mechanism is preferable [1].
- All conditions described in step 5 (Protocol section) can be put into a P2TR address. The formed address will not differ from the regular Bitcoin address (single or multisig) formed using the P2TR method [2].
- As a zk-friendly hash function, we can use Poseidon [3].
- For zk operations with EC points, we can use the 0xPARC library [4].

## Links

[2] bips/bip-0341.mediawiki at deae64bfd31f6938253c05392aa355bf6d7e7605 · bitcoin/bips · GitHub

P.S. The original doc is here Taprootized Atomic Swaps - Google Docs