summaryrefslogtreecommitdiff
path: root/4d/8e4b08e79b49ea78e7235af1a4616d5f8d3645
blob: 21d13ed0be34b032b71ca8ea9943e0eef64c07e5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
Return-Path: <alicexbt@protonmail.com>
Received: from smtp1.osuosl.org (smtp1.osuosl.org [140.211.166.138])
 by lists.linuxfoundation.org (Postfix) with ESMTP id 60541C002D
 for <bitcoin-dev@lists.linuxfoundation.org>;
 Sat, 20 Aug 2022 08:20:07 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by smtp1.osuosl.org (Postfix) with ESMTP id 2D2928329E
 for <bitcoin-dev@lists.linuxfoundation.org>;
 Sat, 20 Aug 2022 08:20:07 +0000 (UTC)
DKIM-Filter: OpenDKIM Filter v2.11.0 smtp1.osuosl.org 2D2928329E
Authentication-Results: smtp1.osuosl.org;
 dkim=pass (2048-bit key) header.d=protonmail.com header.i=@protonmail.com
 header.a=rsa-sha256 header.s=protonmail3 header.b=HB22EmQS
X-Virus-Scanned: amavisd-new at osuosl.org
X-Spam-Flag: NO
X-Spam-Score: -2.101
X-Spam-Level: 
X-Spam-Status: No, score=-2.101 tagged_above=-999 required=5
 tests=[BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1,
 DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001,
 SPF_HELO_PASS=-0.001, SPF_PASS=-0.001]
 autolearn=ham autolearn_force=no
Received: from smtp1.osuosl.org ([127.0.0.1])
 by localhost (smtp1.osuosl.org [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id s24PaHDHWvVP
 for <bitcoin-dev@lists.linuxfoundation.org>;
 Sat, 20 Aug 2022 08:20:06 +0000 (UTC)
X-Greylist: domain auto-whitelisted by SQLgrey-1.8.0
DKIM-Filter: OpenDKIM Filter v2.11.0 smtp1.osuosl.org 1918683299
Received: from mail-4319.protonmail.ch (mail-4319.protonmail.ch [185.70.43.19])
 by smtp1.osuosl.org (Postfix) with ESMTPS id 1918683299
 for <bitcoin-dev@lists.linuxfoundation.org>;
 Sat, 20 Aug 2022 08:20:05 +0000 (UTC)
Date: Sat, 20 Aug 2022 08:20:00 +0000
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com;
 s=protonmail3; t=1660983603; x=1661242803;
 bh=9gWtbGstMZT424NptfxO5AaHy75PQiZz9i2TXWbrN3Y=;
 h=Date:To:From:Reply-To:Subject:Message-ID:Feedback-ID:From:To:Cc:
 Date:Subject:Reply-To:Feedback-ID:Message-ID;
 b=HB22EmQSCGbVHvcGhdGegSs8xo84qMuyQA/S4qMP+pOQg+CMJ45ALr4uuhoeETDZI
 u9id2/VxxI/PkubwjLrKufntTSV+pc1br0VArSNDFrtRKgR2RTQ9mR7ofw0DhDmIUF
 64RMgKdIU/wXwMGUn41OZ+6K4Id0pGFBFwQMKFFO0Cet20L4BPm+roqtLIE5iouXwQ
 y2fvA96UkMnkWs34wtmxIoIT3tgRm20aFDudobe5V6y5CJj03awhPYaNvsRHICLMyE
 z5njmMeQAToWfWTX6l3yV2EzJqQuVQGHLVJzBsE+6BRg8/YbA6sQYwZIx0MgPELDCd
 uHgjpQ/lRIc1w==
To: Bitcoin Protocol Discussion <bitcoin-dev@lists.linuxfoundation.org>
From: alicexbt <alicexbt@protonmail.com>
Reply-To: alicexbt <alicexbt@protonmail.com>
Message-ID: <7gXWd6OVJjiW7aCeon8q-xlWfCMJkIEVCaeokjSVI16OvQPkPmEsSeGY0cGu4yVveimNUYsyG18Ro7JgUutfqXv5wKMMgJZD2c8ftAMFcbQ=@protonmail.com>
Feedback-ID: 40602938:user:proton
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable
X-Mailman-Approved-At: Sat, 20 Aug 2022 09:28:32 +0000
Subject: [bitcoin-dev] joinstr: coinjoin implementation using nostr
X-BeenThere: bitcoin-dev@lists.linuxfoundation.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: Bitcoin Protocol Discussion <bitcoin-dev.lists.linuxfoundation.org>
List-Unsubscribe: <https://lists.linuxfoundation.org/mailman/options/bitcoin-dev>, 
 <mailto:bitcoin-dev-request@lists.linuxfoundation.org?subject=unsubscribe>
List-Archive: <http://lists.linuxfoundation.org/pipermail/bitcoin-dev/>
List-Post: <mailto:bitcoin-dev@lists.linuxfoundation.org>
List-Help: <mailto:bitcoin-dev-request@lists.linuxfoundation.org?subject=help>
List-Subscribe: <https://lists.linuxfoundation.org/mailman/listinfo/bitcoin-dev>, 
 <mailto:bitcoin-dev-request@lists.linuxfoundation.org?subject=subscribe>
X-List-Received-Date: Sat, 20 Aug 2022 08:20:07 -0000

Hi Bitcoin Developers,

I have written a python script as proof of concept for the [coinjoin implem=
entation][1] using [nostr][2]. I used a lot of Python scripts created by ot=
hers in school, so it feels nice to offer something that could be useful to=
 others.

The implementation uses Bitcoin Core wallet and RPCs: `listunspent`, `getne=
waddress`, `scantxoutset`, `createpsbt`, `combinepsbt`, `finalizepsbt` and =
`sendrawtransaction`. It requires python-nostr library because nostr is use=
d for coordination between peers. Nostr is a decentralized network based on=
 cryptographic keypairs. It is not peer-to-peer however simple and scalable=
.

Every step is published as an event using a nostr relay and 5 peers coordin=
ate to create, sign and broadcast a coinjoin transaction.  I need to write =
a NIP that would be an alternative to blind signatures. Relay will share a =
random secret with clients for one round which should be present in output =
registration request although never gets published. If someone tries to reg=
ister an output without registering any inputs, request would not have the =
number initially shared with inputs so request would get rejected or publis=
hed as unverified. Relay would not be able to link inputs and outputs as th=
e number is same for all inputs in a round and they get registered at diffe=
rent times with new keys and IP address. Clients can use multiple relays at=
 the same time to avoid trusting one relay. This would result in different =
shared secret number but same process. If a relay tries to cheat, users wil=
l not sign the transaction and avoid using it in future.

Usage:

 1)Run `python coinjoin.py` and enter descriptor for one of the inputs.
 2)Script will check inputs for this round in every 30 seconds and register=
 a new adddress for output once 5 inputs are registered.
 3)Similar check happens every 30 seconds for outputs. Last peer should cre=
ate a PSBT.
 4)Unsigned PSBT will be printed and signed by wallet with `walletprocessps=
bt` RPC.
 5)Script will check signed PSBTs and last peer to sign should finalize coi=
njoin transaction once 5 signed PSBTs are received.
 6)Coinjoin transaction will be broadcasted and txid will printed.

Example:

```
List of utxos in wallet:

wpkh([53830dca/84'/1'/0'/0/0]02449be5fb74725255eeeb50eba930fa87705f21e99d13=
cd710cf2c1f21153c808)#x2hyyeg5

Enter descriptor for the input registration: wpkh([53830dca/84'/1'/0'/0/0]0=
2449be5fb74725255eeeb50eba930fa87705f21e99d13cd710cf2c1f21153c808)#x2hyyeg5

event id:  bcbbe62d75d99fed73f1e50ac58a38d1840b658951893e63c0322b378d7d56f0

```
```
tb1qhxrp4zl54ul0twtyz0gury5399q7z0kvqqrl6m registered for output

event id: 9449c9065bef356d21507a98f88b028b17fc1c49eb195c8d4420604fcaaef041
```
```
Unsigned PSBT: cHNidP8BAP1yAQIAAAAFtMaoJYcXvOG5L3Yaz3YyS7gIt4h5/zzOrRRS3hrV=
vwoAAAAAAP////+o83geaSm4L76KToIUl5MiZqLAUbIDJLq6DWrjP/3b8AEAAAAA/////zEF3CX=
IvVHpIa7No1s1yg+KtyOfXTRSyWnOdXMfzcDwAQAAAAD/////wMa4XAgnU+39Ien+KG9rYtv8bL=
MNYakmZyY/QFfw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/w/SxeMDQ5tuXrYJLUAQhrAkcwRAIgOIhLoC5348U8YkEr4=
GU1K4yWskIOEXgW4Wsk/W2cR7ICIEJXqtOuDJ5CkwrSuwJLWtzab4dslbN3KuL/pyooMnOCASEC=
RJvl+3RyUlXu61DrqTD6h3BfIemdE81xDPLB8hFTyAgAAAAAACICA77Cnd6o3kr0yc+91eabpOn=
5igs/MUMbudNYSS6oyMWMGFODDcpUAACAAQAAgAAAAIAAAAAAFAAAAAAAAAAA

event id: 5846b6e6902f3c5a43496d7d9785ed62444aa74963f03c33d637d8b09ee7a139
```
```
Coinjoin tx: 75e490b10b15a6a0422f25ff66ad98ef70390c8fecaac02712705dce8cc356=
4b

event id: 9b5d4bf279b59e2b6e539e683fba83da72dce2b640360aa95db1b1400be93190
```

There are lot of things that could be improved and a few suggestions are in=
 the gist that described the [idea][3]. I would love read to any opinions a=
bout this experiment and will start working on creating an Android app for =
joinstr next week.

Credits:

- fiatjaf (Nostr)
- Andrew Chow (PSBT)
- Jeff Thibault (python-nostr)
- Existing coinjoin implmentations

[1]: https://github.com/1440000bytes/joinstr
[2]: https://github.com/nostr-protocol/nostr
[3]: https://gist.github.com/1440000bytes/1c305097b070c8374cc3b91f50314a45

/dev/fd0

Sent with Proton Mail secure email.