Below are two transaction flows for performing a CoinSwap.
key handover: based on 2pECDSA, used assuming both parties will complete the CoinSwap successfullyredeemscript: based on Taproot, used if an abort happens inkey handover
Let maker and taker be two parties initiating a CoinSwap using a key handover transaction.
The handover transaction can be spent:
- with a signature under an aggregate 2pECDSA key:
aggPK = 2pECDSA_KeyGen(makerPK, takerPK) - a signature under
makerPKand expired timeout (OP_CSVorOP_CHECKLOCKTIME)
Gennaro-Goldfeder's 2pECDSA protocol enables identifiable aborts, consists of a single online communication round (offline setup rounds), and threshold M-of-N signatures. Full support for M-of-N is not required for basic CoinSwap, but could be utilised in more advanced versions of the protocol.
-
create a 2-of-2 2pECDSA contract with timelock abort
- either
<aggPK> CHECKSIG NOTIF <makerPK> CHECKSIG <rel-timelock> OP_CSV ENDIF - or
<aggPK> CHECKSIG NOTIF <makerPK> CHECKSIG <abs-timelock> OP_CHECKLOCKTIME ENDIF
- either
-
require signature under 2pECDSA key
aggPK -
makerandtakerperform offline 2pECDSA rounds to establishaggPK -
makerverifies contract, performs their half of the online signing round, and sends partial signature totaker -
takerverifies the contract, and performs their half of the online signing round -
takerbroadcasts the transaction, and recovers funds from the contract -
if protocol aborts
- kick offending parties
- retry key handover if non-offending parties remain
- try redeemscript transaction if failed handover retry, or only offending parties remain
makersigns and broadcasts the transaction, and recovers funds after timelock expires
Let maker and taker be two parties in a CoinSwap that uses a PTLC redeemscript with Taproot.
The internal_key used for the key path spend is an aggregate MuSig2 key: aggPK = makerPK + adaptor*takerPK
maker has knowledge of the secret key for the public key (makerPK), and the adaptor secret.
taker has knowledge of the secret key for the public key (takerPK).
The redeemscript can be spent:
- with a signature under the aggregated Musig2 key
aggPK - with a signature under
makerPKand expired timelock
- create Taproot contract with a single timelock TapBranch in the TapScript tree
- might be required or desirable to add an unspendable TapBranch to balance the TapScript tree
<segwit-v1> <aggPK> <control-block>
- require signature under Musig2 aggregate key
aggPK takercreates and sends contract tomakermakerverifies contract, and sends partial signature totakerpartial_sig = k - r*makerSK
takerverifies partial signature (stores to extract adaptor + aggregation)takersends proof of funding tomakermakervalidates proof of funding, and sends adaptor signature totakeradaptor_sig = partial_sig + adaptor = k - r*makerSK + adaptor
takervalidates, and extracts adaptor secretadaptor = adaptor_sig - partial_sig = (k - r*makerSK) - (k - r*makerSK) + adaptor
takercreates a partial signature under their public key tweaked with the adaptor secretaggSK = adaptor*takerSK, aggPK = aggSK*G
takeraggregates the partial signatures, broadcasts the transaction, and recovers funds from the contract
- use timelock script as the single TapBranch in a TapScript tree
OP_CSV-based orOP_CHECKLOCKTIME-based- either
<makerPK> CHECKSIG <rel-timelock> OP_CSV - or
<makerPK> CHECKSIG <abs-timelock> OP_CHECKLOCKTIME
- require signature under the timelock key
makerwaits for timelock to expiremakercalculates the output key for the TapScript spend path<segwit-v1> <output-key> PUSH_DATA(script_len) <timelock-script> <control-block>
makersigns and broadcasts the transaction, and recovers funds from the contract
- https://gist.github.com/chris-belcher/9144bd57a91c194e332fb5ca371d0964#ecdsa-2p
- bitcoin-teleport/teleport-transactions#37 (comment)
- https://eprint.iacr.org/2020/540.pdf
- https://github.com/bitcoin/bips/blob/master/bip-0141.mediawiki
- https://github.com/bitcoin/bips/blob/master/bip-0341.mediawiki
- https://zmnscpxj.github.io/bitcoin/multiswap.html
- https://lists.linuxfoundation.org/pipermail/lightning-dev/2020-August/002785.html