Return-Path: Received: from smtp1.linuxfoundation.org (smtp1.linux-foundation.org [172.17.192.35]) by mail.linuxfoundation.org (Postfix) with ESMTPS id 649D0E88 for ; Thu, 21 Apr 2016 15:28:45 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.7.6 Received: from mail-pa0-f48.google.com (mail-pa0-f48.google.com [209.85.220.48]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 96C69126 for ; Thu, 21 Apr 2016 15:28:44 +0000 (UTC) Received: by mail-pa0-f48.google.com with SMTP id er2so30136373pad.3 for ; Thu, 21 Apr 2016 08:28:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=user-agent:in-reply-to:references:mime-version :content-transfer-encoding:subject:from:date:to:message-id; bh=mvhQGfX6mwgKgjQziXPxkGz+sbPF3vRvXYWxH8rELO4=; b=fEkBmmcaRYeuhOtCBTLOJrR7qokqL75PYpCzeJioOBlPyTRCWltXxE/vCkwTlOV6vn 4Q0+uYQnCcuOf5H8C/r9qo7Lttigr3BSsQL/8W0l8slAifmmhTxwYRUd5iLaTTjvQHn2 6R00n2uWGhD7UpYdxu0tHJEhhiAlSeA01D+liE8eCqjZWQlkq/KyHjqvVIZ6LQoOn4FC 5K8lSNI4V7FJMyizKXztCAd3HWa0YR2fZDf8sumPj49wPKxDk4EVLPd6GvuUql44utw/ oyxWGkKE8ruq3THQX2zWxgiekLrNGAubztk9oV6t6foDbca6IRbMWUVC/X4/pRhn0r33 0dpQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:user-agent:in-reply-to:references:mime-version :content-transfer-encoding:subject:from:date:to:message-id; bh=mvhQGfX6mwgKgjQziXPxkGz+sbPF3vRvXYWxH8rELO4=; b=GHhGavYrnqv2vZ8m7n9udgQvcsdJyekDAgv7KdLN7M++VDSgDG5ahEH1+UU6J8N26e xsww9s/4nLQ5GCIG0g6R5Hen9Xaa7WUu152PaXAk0HM9IsO+pKU3F8Y7XxqbGNchmQyQ TAIl8YHpLZM88/JXKosSQuz77I83RmyLsn0ncAC3kdCcI3mehUMIyHxw14IJOe55bK/5 1Z3gEMe0MY3KVykdjEnLCMyTER1JTtX8ikIRSgR0r8W0e/ZxHaMAu62n4QLDWA6yvY1f j+WrS5R9EDU/ZZOthUTAedeuPuX2zSAMzLCTphVF59bwiof4EX2M4Fl0DkrenOwKV3qY w7gA== X-Gm-Message-State: AOPr4FVDcNIMWL28l5qGHjg+YM1QGiT9LvbkBzYd8QxaPj2/GHvsAuWfMUk8l2rts7R74Q== X-Received: by 10.66.199.66 with SMTP id ji2mr21487956pac.34.1461252524266; Thu, 21 Apr 2016 08:28:44 -0700 (PDT) Received: from [192.168.1.102] (cpe-70-95-80-239.san.res.rr.com. [70.95.80.239]) by smtp.gmail.com with ESMTPSA id h5sm3086473pat.0.2016.04.21.08.28.43 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 21 Apr 2016 08:28:43 -0700 (PDT) User-Agent: K-9 Mail for Android In-Reply-To: <5717AF19.1030102@gmail.com> References: <5717AF19.1030102@gmail.com> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----CCEJDCBECU3MOBG155768L2I6HEFYX" Content-Transfer-Encoding: 8bit From: Eric Lombrozo Date: Thu, 21 Apr 2016 08:28:45 -0700 To: Jochen Hoenicke , bitcoin-dev@lists.linuxfoundation.org Message-ID: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,HTML_MESSAGE,RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org X-Mailman-Approved-At: Thu, 21 Apr 2016 15:30:39 +0000 Subject: Re: [bitcoin-dev] Proposal to update BIP-32 X-BeenThere: bitcoin-dev@lists.linuxfoundation.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: Bitcoin Development Discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 21 Apr 2016 15:28:45 -0000 ------CCEJDCBECU3MOBG155768L2I6HEFYX Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 In practice the probability of this case triggering is on the order of 2^-128 or something astronomically tiny. I've been using BIP32 for a few years already as have many others...I don't think we've ever had to handle this case. Justifiably, many app developers feel like the additional complexity of properly handling this case is not worth the effort. Having said that, if the handling of this case is simple to implement and easy to isolate in the program flow, I am in favor of doing something along the lines of what you propose. - Eric On April 20, 2016 9:32:25 AM PDT, Jochen Hoenicke via bitcoin-dev wrote: >Hello Bitcoin Developers, > >I would like to make a proposal to update BIP-32 in a small way. > >TL;DR: BIP-32 is hard to use right (due to its requirement to skip >addresses). This proposal suggests a modification such that the >difficulty can be encapsulated in the library. > >#MOTIVATION: > >The current BIP-32 specifies that if for some node in the hierarchy >the computed hash I_L is larger or equal to the prime or 0, then the >node is invalid and should be skipped in the BIP-32 tree. This has >several unfortunate consequences: > >- All callers of CKDpriv or CKDpub have to check for errors and handle > them appropriately. This shifts the burden to the application > developer instead of being able to handle it in the BIP-32 library. > >- It is not clear what to do if an intermediate node is > missing. E.g. for the default wallet layout, if m/i_H/0 is missing > should m/i_H/1 be used for external chain and m/i_H/2 for internal > chain? This would make the wallet handling much more difficult. > >- It gets even worse with standards like BIP-44. If m/44' is missing > should we use m/45' instead? If m/44'/0' is missing should we use > m/44'/1' instead, using the same addresses as for testnet? > One could also restart with a different seed in this case, but this > wouldn't work if one later wants to support another BIP-43 proposal > and still keep the same wallet. > >I think the first point alone is reason enough to change this. I am >not aware of a BIP-32 application that handles errors like this >correctly in all cases. It is also very hard to test, since it is >infeasible to brute-force a BIP-32 key and a path where the node does >not exists. > >This problem can be avoided by repeating the hashing with slightly >different input data until a valid private key is found. This would >be in the same spirit as RFC-6979. This way, the library will always >return a valid node for all paths. Of course, in the case where the >node is valid according to the current standard the behavior should be >unchanged. > >I think the backward compatibility issues are minimal. The chance >that this affects anyone is less than 10^-30. Even if it happens, it >would only create some additional addresses (that are not seen if the >user downgrades). The main reason for suggesting a change is that we >want a similar method for different curves where a collision is much >more likely. > >#QUESTIONS: > >What is the procedure to update the BIP? Is it still possible to >change the existing BIP-32 even though it is marked as final? Or >should I make a new BIP for this that obsoletes BIP-32? > >What algorithm is preferred? (bike-shedding) My suggestion: > >--- > >Change the last step of the private -> private derivation functions to: > > . In case parse(I_L) >= n or k_i = 0, the procedure is repeated > at step 2 with > I = HMAC-SHA512(Key = c_par, Data = 0x01 || I_R || ser32(i)) > >--- > >I think this suggestion is simple to implement (a bit harder to unit >test) and the string to hash with HMAC-SHA512 always has the same >length. I use I_R, since I_L is obviously not very random if I_L >= n. >There is a minimal chance that it will lead to an infinite loop if I_R >is the same in two consecutive iterations, but that has only a chance >of 1 in 2^512 (if the algorithm is used for different curves that make >I_L >= n more likely, the chance is still less than 1 in 2^256). In >theory, this loop can be avoided by incrementing i in every iteration, >but this would make an implementation error in the "hard to test" path >of the program more likely. > >The other derivation functions should be updated in a similar matter. >Also the derivation of the root node from the seed should be updated >in a similar matter to avoid invalid seeds. > >If you followed until here, thanks for reading this long posting. > > Jochen >_______________________________________________ >bitcoin-dev mailing list >bitcoin-dev@lists.linuxfoundation.org >https://lists.linuxfoundation.org/mailman/listinfo/bitcoin-dev ------CCEJDCBECU3MOBG155768L2I6HEFYX Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 8bit In practice the probability of this case triggering is on the order of 2^-128 or something astronomically tiny. I've been using BIP32 for a few years already as have many others...I don't think we've ever had to handle this case. Justifiably, many app developers feel like the additional complexity of properly handling this case is not worth the effort.

Having said that, if the handling of this case is simple to implement and easy to isolate in the program flow, I am in favor of doing something along the lines of what you propose.

- Eric

On April 20, 2016 9:32:25 AM PDT, Jochen Hoenicke via bitcoin-dev <bitcoin-dev@lists.linuxfoundation.org> wrote:
Hello Bitcoin Developers,

I would like to make a proposal to update BIP-32 in a small way.

TL;DR: BIP-32 is hard to use right (due to its requirement to skip
addresses). This proposal suggests a modification such that the
difficulty can be encapsulated in the library.

#MOTIVATION:

The current BIP-32 specifies that if for some node in the hierarchy
the computed hash I_L is larger or equal to the prime or 0, then the
node is invalid and should be skipped in the BIP-32 tree. This has
several unfortunate consequences:

- All callers of CKDpriv or CKDpub have to check for errors and handle
them appropriately. This shifts the burden to the application
developer instead of being able to handle it in the BIP-32 library.

- It is not clear what to do if an intermediate node is
missing. E.g. for the default wallet layout, if m/i_H/0 is missing
shou ld m/i_H/1 be used for external chain and m/i_H/2 for internal
chain? This would make the wallet handling much more difficult.

- It gets even worse with standards like BIP-44. If m/44' is missing
should we use m/45' instead? If m/44'/0' is missing should we use
m/44'/1' instead, using the same addresses as for testnet?
One could also restart with a different seed in this case, but this
wouldn't work if one later wants to support another BIP-43 proposal
and still keep the same wallet.

I think the first point alone is reason enough to change this. I am
not aware of a BIP-32 application that handles errors like this
correctly in all cases. It is also very hard to test, since it is
infeasible to brute-force a BIP-32 key and a path where the node does
not exists.

This problem can be avoided by repeating the hashing with slightly
different input data until a valid private key is fo und. This would
be in the same spirit as RFC-6979. This way, the library will always
return a valid node for all paths. Of course, in the case where the
node is valid according to the current standard the behavior should be
unchanged.

I think the backward compatibility issues are minimal. The chance
that this affects anyone is less than 10^-30. Even if it happens, it
would only create some additional addresses (that are not seen if the
user downgrades). The main reason for suggesting a change is that we
want a similar method for different curves where a collision is much
more likely.

#QUESTIONS:

What is the procedure to update the BIP? Is it still possible to
change the existing BIP-32 even though it is marked as final? Or
should I make a new BIP for this that obsoletes BIP-32?

What algorithm is preferred? (bike-shedding) My suggestion:

---

Change the la st step of the private -> private derivation functions to:

. In case parse(I_L) >= n or k_i = 0, the procedure is repeated
at step 2 with
I = HMAC-SHA512(Key = c_par, Data = 0x01 || I_R || ser32(i))

---

I think this suggestion is simple to implement (a bit harder to unit
test) and the string to hash with HMAC-SHA512 always has the same
length. I use I_R, since I_L is obviously not very random if I_L >= n.
There is a minimal chance that it will lead to an infinite loop if I_R
is the same in two consecutive iterations, but that has only a chance
of 1 in 2^512 (if the algorithm is used for different curves that make
I_L >= n more likely, the chance is still less than 1 in 2^256). In
theory, this loop can be avoided by incrementing i in every iteration,
but this would make an implementation error in the "hard to test" path
of the program more likely.

The other derivati on functions should be updated in a similar matter.
Also the derivation of the root node from the seed should be updated
in a similar matter to avoid invalid seeds.

If you followed until here, thanks for reading this long posting.

Jochen


bitcoin-dev mailing list
bitcoin-dev@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/bitcoin-dev
------CCEJDCBECU3MOBG155768L2I6HEFYX--