Skip to content

Commit 02b1cb2

Browse files
committed
Initial commit
0 parents  commit 02b1cb2

File tree

8 files changed

+142
-0
lines changed

8 files changed

+142
-0
lines changed

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.idea
2+
3+
/target
4+
5+
*.dev.*
6+
dev.*
7+
*.dev

Cargo.lock

Lines changed: 32 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[package]
2+
name = "taprootized-atomic-swaps"
3+
version = "0.1.0"
4+
edition = "2021"
5+
license = "MIT"
6+
7+
[dependencies]
8+
eyre = { version = "0.6.11" }

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2023 Distributed Lab
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# Taprootized Atomic Swaps
2+
3+
Taprootized Atomic Swaps (TAS) is an extension for Atomic Swaps that presumes the untraceability of
4+
transactions related to a particular swap. Build top on Schnorr signatures, Taproot technology, and
5+
zero-knowledge proofs TAS hide swap transactions under regular payments.
6+
7+
## Intro
8+
Atomic swap is an incredible approach to cross-chain exchanges without mediators. However, one of
9+
the disadvantages of its implementation in the classical form is the “digital trail” - any party
10+
can make a matching between transactions in the blockchains in which the exchange took place and
11+
find out both the participants in the exchange and the proportion in which assets were exchanged.
12+
13+
<div align="center">
14+
<img src="https://github.com/distributed-lab/taprootized-atomic-swaps/blob/main/assets/atomic-swap.png"/>
15+
</div>
16+
17+
On the other hand, atomic swaps is a technology that initially assumed the involvement of only two
18+
parties and a “mathematical contract” between them directly. That is, an ideal exchange presupposes
19+
2 conditions:
20+
1) Only counterparties participate in the exchange (works by default)
21+
2) Only counterparties know about the fact of the exchange (it would be nice to ensure)
22+
23+
To an external auditor, transactions to initiate and execute atomic swaps will be indistinguishable
24+
from regular Bitcoin payments. In the other accounting system involved in the transfer, more
25+
information is disclosed (the fact of exchange can be traced). Still, it is impossible to link this
26+
to the corresponding Bitcoin transactions (without additional context from the involved parties).
27+
28+
<div align="center">
29+
<img src="https://github.com/distributed-lab/taprootized-atomic-swaps/blob/main/assets/sequence-diagram.png"/>
30+
</div>
31+
32+
### The protocol includes the following steps:
33+
1. Alice (`skA`, `PKA`) and Bob (`skB`, `PKB`) have their keypairs and know each other's public keys.
34+
2. Alice generates a random `k` and calculates the public value `K = k * G`
35+
3. Alice calculates an escrow public key as `PKEsc = K + PKB`
36+
1. The signature can be generated only with the knowledge of `k` and `skB`
37+
4. Alice calculates the `h` as a hash value of `k` (zk-friendly hash function is recommended to use)
38+
5. Alice forms the funding transactions with the following conditions of how it can be spent:
39+
1. Signature of `skEsc`: Bob, with knowledge of `k` and skB can spend the output
40+
2. Signature of `skA` + Locktime: Alice, with knowledge of `skA` can spend the output, but only
41+
after some point in time t1
42+
6. Alice sends the transaction to the Bitcoin network
43+
7. Alice generates the zero-knowledge proof that includes:
44+
1. The proof of knowledge of `k` that satisfes `k * G == K`
45+
2. The proof of knowledge of `k` that satisfes `zkHash(k) == h`
46+
8. Alice provides the set of data to Bob:
47+
1. `h`
48+
2. `K`
49+
3. `PKEsc`
50+
4. `proof`
51+
9. Bob performs the following verifications:
52+
1. Verify that `PKEsc == K + PKB`, it means that the valid `PK` of Bob was added to escrow PK
53+
2. Verifes that Alice knows `k` that satisfies `k * G == K` and `zkHash(k) == h`, it means that Bob
54+
can access the output `PKEsc` if he receives `k`
55+
10. If verifications are passed, Bob forms the transaction that locks his funds on the following
56+
conditions:
57+
1. Publishing of `k` and the signature of `skA`: only Alice can spend it if she reveals `k`
58+
2. Signature of `skB` + Locktime: Bob, with knowledge of `skB`, can spend the output, but only after
59+
some point in time t2
60+
11. Bob sends the transaction to the Ethereum network (or other)
61+
12. Alice sees the locking conditions defined by Bob and publishes the `k` together with the signature
62+
generated by her `skA`. As a result - Alice spent funds locked by Bob.
63+
1. If Alice doesn’t publish the relevant `k`, Bob can return funds after locktime is reached
64+
13. If Alice publishes a transaction with `k`, Bob can recognize it and extract the kvalue
65+
14. Bob calculate the needed `skEsc` as `skEsc = k + skB`
66+
15. Bob sends the transaction with the signature generated by the `skEsc` and spends funds locked by
67+
Alice.

assets/atomic-swap.png

146 KB
Loading

assets/sequence-diagram.png

205 KB
Loading

examples/atomic-swap/main.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
use eyre::Result;
2+
3+
fn main() -> Result<()> {
4+
println!("Hello, world!");
5+
6+
Ok(())
7+
}

0 commit comments

Comments
 (0)