Received: from sog-mx-4.v43.ch3.sourceforge.com ([172.29.43.194] helo=mx.sourceforge.net) by sfs-ml-2.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1W2iE8-0003FV-Bv for bitcoin-development@lists.sourceforge.net; Mon, 13 Jan 2014 14:10:52 +0000 Received-SPF: pass (sog-mx-4.v43.ch3.sourceforge.com: domain of taplink.co designates 50.117.27.232 as permitted sender) client-ip=50.117.27.232; envelope-from=jeremy@taplink.co; helo=mail.taplink.co; Received: from mail.taplink.co ([50.117.27.232]) by sog-mx-4.v43.ch3.sourceforge.com with smtp (Exim 4.76) id 1W2iE6-0008OR-S9 for bitcoin-development@lists.sourceforge.net; Mon, 13 Jan 2014 14:10:52 +0000 Received: from laptop-air.hsd1.ca.comcast.net ([192.168.168.135]) by mail.taplink.co ; Mon, 13 Jan 2014 06:18:39 -0800 Content-Type: multipart/alternative; boundary=----------quLNl5KWjFmOZozi4Nm4ts To: "Mike Hearn" References: Date: Mon, 13 Jan 2014 06:10:14 -0800 MIME-Version: 1.0 From: "Jeremy Spilman" Organization: TapLink Message-ID: In-Reply-To: User-Agent: Opera Mail/1.0 (Win32) oclient: 192.168.168.135#jeremy@taplink.co#465 X-Spam-Score: -0.7 (/) X-Spam-Report: Spam Filtering performed by mx.sourceforge.net. See http://spamassassin.org/tag/ for more details. -1.5 SPF_CHECK_PASS SPF reports sender host as permitted sender for sender-domain -0.0 SPF_PASS SPF: sender matches SPF record -0.1 RP_MATCHES_RCVD Envelope sender domain matches handover relay domain 1.0 HTML_MESSAGE BODY: HTML included in message -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature X-Headers-End: 1W2iE6-0008OR-S9 Cc: "bitcoin-development@lists.sourceforge.net" Subject: Re: [Bitcoin-development] Stealth Payments - Sample Code / Proof of Concept X-BeenThere: bitcoin-development@lists.sourceforge.net X-Mailman-Version: 2.1.9 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 13 Jan 2014 14:10:52 -0000 ------------quLNl5KWjFmOZozi4Nm4ts Content-Type: text/plain; charset=iso-8859-15; format=flowed; delsp=yes Content-Transfer-Encoding: 7bit On Mon, 13 Jan 2014 03:18:28 -0800, Mike Hearn wrote: > Cool! > > On Mon, Jan 13, 2014 at 10:18 AM, Jeremy Spilman > wrote: >> I spent 1BTC on TestNet to a stealth address... >> TxID: >> df092896c1347b303da299bc84c92bef1946f455dbdc80ffdb01a18ea4ed8b4c > > ... but can you redeem it? But of course! Every time the test runs it makes a new ephemeral key, so I wrote a separate test with hard-coded values from the block chain (as it would be in real-life) to create a redeeming Tx. I've added the RedeemStealth code to the Gist. It sent successfully using sendrawtransaction, TxID: ed92364d2b6f6528dea32dbf6c4d5d6291b601aff1ddb4eeb124d003c7c7ff07 I'm self mining since no one else seems to be on TestNet this time of night... going to catch some sleep, hopefully by the time I wake up it'll be on the chain. >> Code which generated this transaction is here: >> https://gist.github.com/jspilman/8396495 > > That's rather interesting code. Is this using a private C# bitcoin > implementation? Indeed it is. One day I may publish the libraries, but they aren't doing anything particularly special under the hood, just the standard Bitcoin/EC/BIP32 stuff and using OpenSSL under the hood instead of the more typical BouncyCastle. I just tried to keep things extremely concise in the APIs. Hopefully all the function calls are obvious what they are doing. Since there's no actual wallet behind it, the code to setup the inputs is a bit annoying, but actually building and signing transactions is super clean. >> I wonder if the 0BTC OP_RETURN transactions should be hidden from the >> Transaction List? > > Yes, of course. The transaction list should just say something like > > "Payment received from Jeremy, 0.1 BTC" In this case I'm just looking at the payee wallet, but yes, "Payment set to Jeremy" should be possible, with the name coming from the CN. > >> Maybe the simple way to punt on this is to just show 'Merchant' in the >> address column if it is available and an address is not. > > I am surprised it's not already the case! Though "merchant" is perhaps a > bit biased as a name, internally it perhaps should just be called > "Recipient". >There's no requirement for you to be a merchant to create > payment protocol requests. Yeah, right now for PaymentProtocol fulfilled payments, on the payer's Transaction List, it shows the address in the 'Address' column, but if you right-click and look at 'Transaction details' you will see something like: Status: 42 confirmations Date: 1/12/2014 21:07 To: mrhz5ZgSF3C1BSdyCKt3gEdhKoRL5BNfJV Debit: -0.10 BTC Net amount: -0.10 BTC Transaction ID: 93c50347e35062a3501fcea15d1a22ace8d1b059affb9913fc9e7df4e7d6a00b-000 Merchant: www.bitcoincore.org I agree 'Merchant' might not be the best name, especially since when you're making the payment the field is labeled simply 'Pay To'. But I think we agree, why show 'mrhz5ZgSF3C1BSdyCKt3gEdhKoRL5BNfJV' in the transaction list instead of just "Paid To: www.bitcoincore.org" and then perhaps the Memo field could be stuck under 'Transaction details', instead of losing that important bit of info. > >> I can probably make the necessary changes to IsMine, but I don't know >> where we should keep 'd2'/'Q2' unencrypted so it's available for doing >> the >> necessary tests, but has no chance of ever be used as a stand-alone >> private key? > > The wallet format would need extending. > > I'd feel a lot more comfortable if the protocol was reviewed by a > professional cryptographer though. I think think Gregory already brought > up an issue >to do with people able to detect such payments by testing > if decrypted values are points on the curve, or something like that. Not sure I follow that, will look forward to hearing more about it. The only risk I know of is that there are checks in theory that you would do on Q1/Q2, but since the payee is the one generating Q1/Q2 they would literally be attacking themselves. I referenced two papers in a prior email specifically on reusing ephemeral keys in ECDH, and the validation you need to do on Q1/Q2 when re-using an ephemeral key to send two messages to two different pubKeys. I think the idea of checking the pubKeys when re-using ephemeral keys is more when the pubKeys are under the attackers control. But the validation is not complicated, and I'll see if I can add it tomorrow. It would be good to fully understand how a possible small-group attack would work... This is a bit of guess-work on my part: If a payee managed to foot-shoot themselves with a bad Q2 pubKey, then gives out d2/Q2 to a scanning service run by Mallory... Mallory has d2/Q2, given P from a transaction, he calculates S2 (as usual): byte[] S2 = EC.DH(d2, P); But with the small sub-group attack with Q2 he can learn 'e' (the ephemeral private key) used: byte[] S2 = EC.DH(e, Q2); and from that he can calculate S1 directly, when he should only know S2. byte[] S1 = EC.DH(e, Q1); So does that mean Mallory can find 'd1'? It looks like you would need another small sub-group attack on P, the ephemeral public key, so another key the attacker doesn't control which would have to randomly be bad. byte[] S1 = EC.DH(d1, P); But I'm definitely not a professional cryptographer. Perhaps Matthew Green might be a good candidate to review this? AND YAY, my stealth redemption Tx just went through, goodnight :-) http://blockexplorer.com/testnet/tx/df092896c1347b303da299bc84c92bef1946f455dbdc80ffdb01a18ea4ed8b4c#o0 ------------quLNl5KWjFmOZozi4Nm4ts Content-Type: multipart/related; boundary=----------quLNl5KWjFmOZorIKGl4Bq ------------quLNl5KWjFmOZorIKGl4Bq Content-Type: text/html; charset=iso-8859-15 Content-ID: Content-Transfer-Encoding: Quoted-Printable On Mon, 13 Jan 2014 03:18:28 -0800, Mike Hearn <mike@plan99.net= > wrote:

Cool!

On Mon, Jan 13= , 2014 at 10:18 AM, Jeremy Spilman <jeremy@taplink.co>= wrote:
I spent 1BTC on TestNet to a stealth a= ddress...
    TxID: df092896c1347b303da299bc84c92bef1946f455dbdc80ffdb01= a18ea4ed8b4c

... but can you redeem = it?

But of cours= e!

Every time the test runs it makes a new ephe= meral key, so I wrote a separate test with hard-coded values from the bl= ock chain (as it would be in real-life) to create a redeeming Tx. I've a= dded the RedeemStealth code to the Gist.

It sen= t successfully using sendrawtransaction, TxID: ed92364d2b6f6528dea32dbf6= c4d5d6291b601aff1ddb4eeb124d003c7c7ff07

I'm sel= f mining since no one else seems to be on TestNet this time of night... = going to catch some sleep, hopefully by the time I wake up it'll be on t= he chain.

 
Code which generated this transaction is here:
h= ttps://gist.github.com/jspilman/8396495

<= div>That's rather interesting code. Is this using a private C# bitcoin i= mplementation?

I= ndeed it is. One day I may publish the libraries, but they aren't doing = anything particularly special under the hood, just the standard Bitcoin/= EC/BIP32 stuff and using OpenSSL under the hood instead of the more typi= cal BouncyCastle.

I just tried to keep things e= xtremely concise in the APIs. Hopefully all the function calls are obvio= us what they are doing. Since there's no actual wallet behind it, the co= de to setup the inputs is a bit annoying, but actually building and sign= ing transactions is super clean.

 
I wonder if the 0BTC = OP_RETURN transactions should be hidden from the
Transaction List?

Yes, of course. Th= e transaction list should just say something like

    "Payment received from Jeremy,  0.1 BTC"

In this case I'm just loo= king at the payee wallet, but yes, "Payment set to Jeremy" should be pos= sible, with the name coming from the CN.


Maybe the simple way to punt on this i= s to just show 'Merchant' in the
address column if it is available and an address is not.

I am surprised it's not already the case! Though "merch= ant" is perhaps a bit biased as a name, internally it perhaps should jus= t be called "Recipient". There's no requirement for you to be a merchant= to create payment protocol requests.

Yeah, right now for PaymentProtocol fulfilled paym= ents, on the payer's Transaction List, it shows the address in the 'Addr= ess' column, but if you right-click and look at 'Transaction details' yo= u will see something like:

  &= nbsp;Status: 42 confirmations
   = ;Date: 1/12/2014 21:07
   To:  &n= bsp;Debit: -0.10 BTC
   Net amou= nt: -0.10 BTC
   Transaction ID:= 93c50347e35062a3501fcea15d1a22ace8d1b059affb9913fc9e7df4e7d6a00b-0= 00
   Merchant: www.bitcoincore.= org


I agree 'Merchant= ' might not be the best name, especially since when you're making the pa= yment the field is labeled simply 'Pay To'.


But I think we agree, why show 'mrhz5ZgSF= 3C1BSdyCKt3gEdhKoRL5BNfJV' in the transaction list instead of just = "Paid To: www.bitcoincore.org" and then perhaps the Memo field= could be stuck under 'Transaction details', instead of losing that impo= rtant bit of info.


 
I can probably make t= he necessary changes to IsMine, but I don't know
where we should keep 'd2'/'Q2' unencrypted so it's available for doing t= he
necessary tests, but has no chance of ever be used as a stand-alone
private key?

The wallet format would= need extending.

I'd feel a lot more comfortabl= e if the protocol was reviewed by a professional cryptographer though. I= think think Gregory already brought up an issue to do with people able = to detect such payments by testing if decrypted values are points on the= curve, or something like that.

Not sure I follow that, will look forwa= rd to hearing more about it.

The only risk I kn= ow of is that there are checks in theory that you would do on Q1/Q2, but= since the payee is the one generating Q1/Q2 they would literally be att= acking themselves. I referenced two papers in a prior email specifically= on reusing ephemeral keys in ECDH, and the validation you need to do on= Q1/Q2 when re-using an ephemeral key to send two messages to two differ= ent pubKeys. I think the idea of checking the pubKeys when re-using ephe= meral keys is more when the pubKeys are under the attackers control. But= the validation is not complicated, and I'll see if I can add it tomorro= w.

It would be good to fully understand how a p= ossible small-group attack would work...  This is a bit of guess-wo= rk on my part:

   If a payee managed = to foot-shoot themselves with a bad Q2 pubKey, then gives out d2/Q2 to a= scanning service run by Mallory...

  &nbs= p;Mallory has d2/Q2, given P from a transaction, he calculates S2 (as us= ual):

      byte[] S2 =3D EC.DH(= d2, P);

   But with the small sub-gro= up attack with Q2 he can learn 'e' (the ephemeral private key) used:

      byte[] S2 =3D EC.DH(e, Q= 2);

   and from that he can calculate= S1 directly, when he should only know S2. 

      byte[] S1 =3D EC.DH(e, Q1);

So does that mean Mallory can find 'd1'? It looks like you would need an= other small sub-group attack on P, the ephemeral public key, so another = key the attacker doesn't control which would have to randomly be bad.

      byte[] S1 =3D EC.DH(= d1, P);

But I'm definitely not a professional c= ryptographer. Perhaps Matthew Green might be a good candidate to review = this?

AND YAY, my stealth redemption Tx just we= nt through, goodnight :-) http://blockexplorer.com/testnet/tx/df092896c1= 347b303da299bc84c92bef1946f455dbdc80ffdb01a18ea4ed8b4c#o0
------------quLNl5KWjFmOZorIKGl4Bq-- ------------quLNl5KWjFmOZozi4Nm4ts--