Return-Path: Received: from smtp1.linuxfoundation.org (smtp1.linux-foundation.org [172.17.192.35]) by mail.linuxfoundation.org (Postfix) with ESMTPS id 32DD9E8E for ; Fri, 1 Jun 2018 17:03:13 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from sender-of-o51.zoho.com (sender-of-o51.zoho.com [135.84.80.216]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 53E27708 for ; Fri, 1 Jun 2018 17:03:12 +0000 (UTC) Received: from [10.8.0.110] (n218103136198.netvigator.com [218.103.136.198]) by mx.zohomail.com with SMTPS id 1527872589325816.2413556873471; Fri, 1 Jun 2018 10:03:09 -0700 (PDT) From: Johnson Lau Message-Id: Content-Type: multipart/alternative; boundary="Apple-Mail=_90831A1C-79FF-4CF4-852D-908EEE61C6A4" Mime-Version: 1.0 (Mac OS X Mail 11.2 \(3445.5.20\)) Date: Sat, 2 Jun 2018 01:03:05 +0800 In-Reply-To: To: Russell O'Connor References: <9CCCE945-9432-41B9-8559-AFE7CF233603@xbt.hk> X-Mailer: Apple Mail (2.3445.5.20) X-ZohoMailClient: External X-Spam-Status: No, score=-0.9 required=5.0 tests=BAYES_00,HTML_MESSAGE, RCVD_IN_DNSWL_NONE,UC_GIBBERISH_OBFU autolearn=no version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Cc: bitcoin-dev Subject: Re: [bitcoin-dev] SIGHASH2 for version 1 witness programme X-BeenThere: bitcoin-dev@lists.linuxfoundation.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: Bitcoin Protocol Discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 01 Jun 2018 17:03:13 -0000 --Apple-Mail=_90831A1C-79FF-4CF4-852D-908EEE61C6A4 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 > On 1 Jun 2018, at 11:03 PM, Russell O'Connor = wrote: >=20 >=20 >=20 > On Thu, May 31, 2018 at 2:35 PM, Johnson Lau via bitcoin-dev = > wrote: >=20 > Double SHA256 of the serialization of: >=20 > Should we replace the Double SHA256 with a Single SHA256? There is no = possible length extension attack here. Or are we speculating that there = is a robustness of Double SHA256 in the presence of SHA256 breaking? >=20 > I suggest putting `sigversion` at the beginning instead of the end of = the format. Because its value is constant, the beginning of the SHA-256 = computation could be pre-computed in advance. Furthermore, if we make = the `sigversion` exactly 64-bytes long then the entire first block of = the SHA-256 compression function could be pre-computed. >=20 > Can we add CHECKSIGFROMSTACK or do you think that would go into a = separate BIP? I think it=E2=80=99s just a tradition to use double SHA256. One reason = we might want to keep dSHA256 is a blind signature might be done by = giving only the single SHA256 hash to the signer. At the same time, a = non-Bitcoin signature scheme might use SHA512-SHA256. So a blind signer = could distinguish the message type without learning the message. sigversion is a response to Peter Todd=E2=80=99s comments on BIP143: = https://petertodd.org/2016/segwit-consensus-critical-code-review#bip143-tr= ansaction-signature-verification = I make it a 0x01000000 at the end of the message because the last 4 = bytes has been the nHashType in the legacy/BIP143 protocol. Since the = maximum legacy nHashType is 0xff, no collision could ever occur. Putting a 64-byte constant at the beginning should also work, since a = collision means SHA256 is no longer preimage resistance. I don=E2=80=99t = know much about SHA256 optimisation. How good it is as we put a 64-byte = constant at the beginning, while we also make the message 64-byte = longer? For CHECKSIGFROMSTACK (CSFS), I think the question is whether we want to = make it as a separate opcode, or combine that with CHECKSIG. If it is a = separate opcode, I think it should be a separate BIP. If it is combined = with CHECKSIG, we could do something like this: If the bit 10 of = SIGHASH2 is set, CHECKSIG will pop one more item from stack, and = serialize its content with the transaction digest. Any thought? --Apple-Mail=_90831A1C-79FF-4CF4-852D-908EEE61C6A4 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8

On 1 Jun 2018, at 11:03 PM, Russell O'Connor <roconnor@blockstream.io> wrote:



On Thu, May 31, 2018 at 2:35 PM, Johnson Lau via = bitcoin-dev <bitcoin-dev@lists.linuxfoundation.org> wrote:

  Double SHA256 of the serialization of:

Should we replace the Double SHA256 with a Single = SHA256?  There is no possible length extension attack here.  = Or are we speculating that there is a robustness of Double SHA256 in the = presence of SHA256 breaking?

I suggest putting `sigversion` at the beginning instead of = the end of the format.  Because its value is constant, the = beginning of the SHA-256 computation could be pre-computed in = advance.  Furthermore, if we make the `sigversion` exactly 64-bytes = long then the entire first block of the SHA-256 compression function = could be pre-computed.

Can we add CHECKSIGFROMSTACK or do you = think that would go into a separate BIP?

I think it=E2=80=99= s just a tradition to use double SHA256. One reason we might want to = keep dSHA256 is a blind signature might be done by giving only the = single SHA256 hash to the signer. At the same time, a non-Bitcoin = signature scheme might use SHA512-SHA256. So a blind signer could = distinguish the message type without learning the message.

sigversion is a response = to Peter Todd=E2=80=99s comments on BIP143: https://petertodd.org/2016/segwit-consensus-critical-code-revie= w#bip143-transaction-signature-verification

I make it a 0x01000000 at the end of = the message because the last 4 bytes has been the nHashType in the = legacy/BIP143 protocol. Since the maximum legacy nHashType is 0xff, no = collision could ever occur.

Putting a 64-byte constant at the beginning should also = work, since a collision means SHA256 is no longer preimage resistance. I = don=E2=80=99t know much about SHA256 optimisation. How good it is as we = put a 64-byte constant at the beginning, while we also make the message = 64-byte longer?

For CHECKSIGFROMSTACK (CSFS), I think the question is whether = we want to make it as a separate opcode, or combine that with CHECKSIG. = If it is a separate opcode, I think it should be a separate BIP. If it = is combined with CHECKSIG, we could do something like this: If the bit = 10 of SIGHASH2 is set, CHECKSIG will pop one more item from stack, and = serialize its content with the transaction digest. Any = thought?


= --Apple-Mail=_90831A1C-79FF-4CF4-852D-908EEE61C6A4--