From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp1.linuxfoundation.org (smtp1.linux-foundation.org [172.17.192.35]) by mail.linuxfoundation.org (Postfix) with ESMTPS id E6EA0A6E for ; Fri, 7 Apr 2017 20:53:02 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.7.6 Received: from mail-qt0-f175.google.com (mail-qt0-f175.google.com [209.85.216.175]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id AF5A513D for ; Fri, 7 Apr 2017 20:52:58 +0000 (UTC) Received: by mail-qt0-f175.google.com with SMTP id x35so70364926qtc.2 for ; Fri, 07 Apr 2017 13:52:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=o1cSvcBAtdnKGtbq3FnXMs1/++E5DcZOJ8SLxM1+w5Q=; b=OcJE0vMa7hi3cBHWI32Lxd6kPbMsqTj0aLX2/dDuyEUzhJHN4PdfoEHkZeK6qv4xUl uTpk2ldX1NqyLrPEYt7O2K3AMpZ6z/3ihLBnxeRXSImdE4+DFRFXaZYEzNwuCIlwLqyM aTMSu7w5QjZ6QOhy1KEkfZL9ZZhCzm/0g6QCi/cJJn8l0blUC+rHYlIZ0Q7SibX6NZse vM6FX1FPS0/+WlkfCPFUTj+2qp8Lb51YUR1vFQktDRg7rx4Ot7lE6WMBY3eVKdrUrbCv hSYq9+qdiDOFsU/QGwA96hzJBIDfX2MP+kto/TlRzdOE71VLsVmAD6AQE6D/KlZbOBSm IqZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=o1cSvcBAtdnKGtbq3FnXMs1/++E5DcZOJ8SLxM1+w5Q=; b=JmcNGqGiU3kw1CyJ/BxAOZwgRZFDo4uO9BsdzPRO3PBDF1U8VpQ7F89XpiVHyfLgih XJB79wIojat3nxpeNQ4WdwvrDA6vmXUmzyVVFRyEyTH9O55mUJBo4BgSGSoLFgR6YSG3 d6tRdM5+a4Vboc4QsZnpR1wRKY3J4dYaAQDKozCiC5Ey0VG3DgeXzdVKQhqQzAXM3J2m Cjj/ULmD8qXbpw/FhcZ6bWdusKRLuY6mLmPNeG6h8WXawAUKzO2oynUk3qR7xo5cqVxP dNwfd7HOs/ygEZuoRSxF1utOpDjQytDj/HS31OzCjFDCS/25dD0G1F5tiH/Q3yMr/VE9 jH7A== X-Gm-Message-State: AFeK/H1cFFn1wfee3O7eVSIUepZx1CWENbguH459x6bqSISrGDmz505nKlLr5AKrp37nXeOcLSbg/ssRa1lmmw== X-Received: by 10.237.53.48 with SMTP id a45mr41156053qte.286.1491598377560; Fri, 07 Apr 2017 13:52:57 -0700 (PDT) MIME-Version: 1.0 Received: by 10.12.170.220 with HTTP; Fri, 7 Apr 2017 13:52:17 -0700 (PDT) From: Sergio Demian Lerner Date: Fri, 7 Apr 2017 17:52:17 -0300 Message-ID: To: bitcoin-dev Content-Type: multipart/alternative; boundary=001a11c000ae7132d1054c99cffb X-Spam-Status: No, score=-0.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,HTML_MESSAGE,MPART_ALT_DIFF, RCVD_IN_DNSWL_NONE,RCVD_IN_SORBS_SPAM autolearn=no version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Subject: [bitcoin-dev] BIP Proposal: Inhibiting a covert optimization on the Bitcoin POW function 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, 07 Apr 2017 20:53:03 -0000 --001a11c000ae7132d1054c99cffb Content-Type: text/plain; charset=UTF-8
  BIP: TBD
  Layer: Consensus
  Title: Inhibiting a covert optimization on the Bitcoin POW function
  Author: Sergio Demian Lerner 
  Status: Draft
  Type: Standards Track
  Created: 2016-04-07
  License: PD
==Abstract== This proposal inhibits the covert use of a known optimization in Bitcoin Proof of Work function. The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in RFC 2119. ==Motivation== Due to a design oversight the Bitcoin proof of work function has a potential optimization which can allow a rational miner to save up-to 30% of their energy costs (though closer to 20% is more likely due to implementation overheads). Timo Hanke and Sergio Demian Lerner applied for a patent on this optimization. The company "Sunrise Tech Group, Llc" has offered to license it to any interested party in the past. Sunrise Tech Group has been marketing their patent licenses under the trade-name ASICBOOST. The document takes no position on the validity or enforceability of the patent. There are two major ways of taking advantage of this optimization, as described by the patent: One way which is highly detectable and is not in use on the network today and a covert way which has significant interaction and potential interference with the Bitcoin protocol. The covert mechanism is not easily detected except through its interference with the protocol. In particular, the protocol interactions of the covert method can block the implementation of virtuous improvements such as segregated witness. The use of this optimization could result in a big payoff, but the actual sum depends on the degree of research, investment and effort put into designing the improved cores. On the above basis the potential for covert use of this optimization in the covert form and interference with useful improvements presents a danger to the Bitcoin system. ==Background== The general idea of this optimization is that SHA2-256 is a merkle damgard hash function which consumes 64 bytes of data at a time. The Bitcoin mining process repeatedly hashes an 80-byte 'block header' while incriminating a 32-bit nonce which is at the end of this header data. This means that the processing of the header involves two runs of the compression function run-- one that consumes the first 64 bytes of the header and a second which processes the remaining 16 bytes and padding. The initial 'message expansion' operations in each step of the SHA2-256 function operate exclusively on that step's 64-bytes of input with no influence from prior data that entered the hash. Because of this if a miner is able to prepare a block header with multiple distinct first 64-byte chunks but identical 16-byte second chunks they can reuse the computation of the initial expansion for multiple trials. This reduces power consumption. There are two broad ways of making use of this optimization. The obvious way is to try candidates with different version numbers. Beyond upsetting the soft-fork detection logic in Bitcoin nodes this has little negative effect but it is highly conspicuous and easily blocked. The other method is based on the fact that the merkle root committing to the transactions is contained in the first 64-bytes except for the last 4 bytes of it. If the miner finds multiple candidate root values which have the same final 32-bit then they can use the optimization. To find multiple roots with the same trailing 32-bits the miner can use efficient collision finding mechanism which will find a match with as little as 2^16 candidate roots expected, 2^24 operations to find a 4-way hit, though low memory approaches require more computation. An obvious way to generate different candidates is to grind the coinbase extra-nonce but for non-empty blocks each attempt will require 13 or so additional sha2 runs which is very inefficient. This inefficiency can be avoided by computing a sqrt number of candidates of the left side of the hash tree (e.g. using extra nonce grinding) then an additional sqrt number of candidates of the right side of the tree using transaction permutation or substitution of a small number of transactions. All combinations of the left and right side are then combined with only a single hashing operation virtually eliminating all tree related overhead. With this final optimization finding a 4-way collision with a moderate amount of memory requires ~2^24 hashing operations instead of the >2^28 operations that would be require for extra-nonce grinding which would substantially erode the benefit of the optimization. It is this final optimization which this proposal blocks. ==New consensus rule== Beginning block X and until block Y the coinbase transaction of each block MUST either contain a BIP-141 segwit commitment or a correct WTXID commitment with ID 0xaa21a9ef. (See BIP-141 "Commitment structure" for details) Existing segwit using miners are automatically compatible with this proposal. Non-segwit miners can become compatible by simply including an additional output matching a default commitment value returned as part of getblocktemplate. Miners SHOULD NOT automatically discontinue the commitment at the expiration height. ==Discussion== The commitment in the left side of the tree to all transactions in the right side completely prevents the final sqrt speedup. A stronger inhibition of the covert optimization in the form of requiring the least significant bits of the block timestamp to be equal to a hash of the first 64-bytes of the header. This would increase the collision space from 32 to 40 or more bits. The root value could be required to meet a specific hash prefix requirement in order to increase the computational work required to try candidate roots. These change would be more disruptive and there is no reason to believe that it is currently necessary. The proposed rule automatically sunsets. If it is no longer needed due to the introduction of stronger rules or the acceptance of the version-grinding form then there would be no reason to continue with this requirement. If it is still useful at the expiration time the rule can simply be extended with a new softfork that sets longer date ranges. This sun-setting avoids the accumulation of technical debt due to retaining enforcement of this rule when it is no longer needed without requiring a hard fork to remove it. == Overt optimization == A BIP for avoiding erroneous warning messages when miners use the overt version of the optimization was proposed several years ago, in order to deter the covert use of the optimization. But that BIP was rejected. However, in light of the current discoveries, that BIP could be reconsidered. The over optimization does not generally interfere with improvements in the protocol. ==Backward compatibility== ==Implementation== ==Acknowledgments== Greg Maxwell for the original report, which contained several errors that were corrected in the present proposal. ==Copyright== This document is placed in the public domain. --001a11c000ae7132d1054c99cffb Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
<pre>
=C2=A0 BIP: TBD
=C2= =A0 Layer: Consensus
=C2=A0 Title: Inhibiting a covert optimizati= on on the Bitcoin POW function
=C2=A0 Author: Sergio Demian Lerne= r <sergio.d.lerner@gmail.co= m>
=C2=A0 Status: Draft
=C2=A0 Type: Standards T= rack
=C2=A0 Created: 2016-04-07
=C2=A0 License: PD
</pre>

=3D=3DAbstract=3D=3D
=
This proposal inhibits the covert use of a known optimizatio= n in Bitcoin Proof of Work function.

The key words= "MUST", "MUST NOT", "REQUIRED", "SHALL&= quot;, "SHALL NOT",
"SHOULD", "SHOULD NO= T", "RECOMMENDED", "MAY", and "OPTIONAL"= in this document are to be interpreted as described in RFC 2119.

=3D=3DMotivation=3D=3D

Due to a de= sign oversight the Bitcoin proof of work function has a potential
optimization which can allow a rational miner to save up-to 30% of their e= nergy
costs (though closer to 20% is more likely due to implement= ation overheads).

Timo Hanke and Sergio Demian Ler= ner applied for a patent on this optimization. The company "Sunrise Te= ch Group, Llc"=C2=A0has offered to license it to any interested party= =C2=A0in the past. Sunrise Tech Group has been marketing their patent licen= ses under the trade-name ASICBOOST.=C2=A0 The document takes no position on= the validity or enforceability of the patent.

The= re are two major ways of taking advantage of this optimization, as describe= d=C2=A0
by the patent:=C2=A0
One way which is highly de= tectable and is not in use on the network
today and a covert way = which has significant interaction and potential
interference with= the Bitcoin protocol.=C2=A0 The covert mechanism is not
easily d= etected except through its interference with the protocol.

In particular, the protocol interactions of the covert method can = block the
implementation of virtuous improvements such as segrega= ted witness.

The use of this optimization could re= sult in a big payoff, but the actual
sum depends on the degree of= research, investment and effort put into designing
the improved = cores. =C2=A0

On the above basis the potential for= covert use of this optimization=C2=A0
in the covert form and int= erference with useful improvements presents a=C2=A0
danger to the= Bitcoin system.

=3D=3DBackground=3D=3D
=
The general idea of this optimization is that SHA2-256 is a = merkle damgard hash
function which consumes 64 bytes of data at a= time.

The Bitcoin mining process repeatedly hashe= s an 80-byte 'block header' while
incriminating a 32-bit = nonce which is at the end of this header data. This
means that th= e processing of the header involves two runs of the compression
f= unction run-- one that consumes the first 64 bytes of the header and a
second which processes the remaining 16 bytes and padding.
=
The initial 'message expansion' operations in each s= tep of the SHA2-256
function operate exclusively on that step'= ;s 64-bytes of input with no
influence from prior data that enter= ed the hash.

Because of this if a miner is able to= prepare a block header with
multiple distinct first 64-byte chun= ks but identical 16-byte
second chunks they can reuse the computa= tion of the initial
expansion for multiple trials. This reduces p= ower consumption.

There are two broad ways of maki= ng use of this optimization. The obvious
way is to try candidates= with different version numbers.=C2=A0 Beyond
upsetting the soft-= fork detection logic in Bitcoin nodes this has
little negative ef= fect but it is highly conspicuous and easily
blocked.
<= br>
The other method is based on the fact that the merkle root
committing to the transactions is contained in the first 64-bytes
except for the last 4 bytes of it.=C2=A0 If the miner finds multip= le
candidate root values which have the same final 32-bit then th= ey
can use the optimization.

To find mul= tiple roots with the same trailing 32-bits the miner can
use effi= cient collision finding mechanism which will find a match
with as= little as 2^16 candidate roots expected, 2^24 operations to
find= a 4-way hit, though low memory approaches require more
computati= on.

An obvious way to generate different candidate= s is to grind the
coinbase extra-nonce but for non-empty blocks e= ach attempt will
require 13 or so additional sha2 runs which is v= ery inefficient.

This inefficiency can be avoided = by computing a sqrt number of
candidates of the left side of the = hash tree (e.g. using extra
nonce grinding) then an additional sq= rt number of candidates of
the right =C2=A0side of the tree using= transaction permutation or
substitution of a small number of tra= nsactions.=C2=A0 All combinations
of the left and right side are = then combined with only a single
hashing operation virtually elim= inating all tree related
overhead.

With = this final optimization finding a 4-way collision with a
moderate= amount of memory requires ~2^24 hashing operations
instead of th= e >2^28 operations that would be require for
extra-nonce =C2= =A0grinding which would substantially erode the
benefit of the op= timization.

It is this final optimization which th= is proposal blocks.

=3D=3DNew consensus rule=3D=3D=

Beginning block X and until block Y the coinbase = transaction of
each block MUST either contain a BIP-141 segwit co= mmitment or a
correct WTXID commitment with ID 0xaa21a9ef.
<= div>
(See BIP-141 "Commitment structure" for detail= s)

Existing segwit using miners are automatically = compatible with
this proposal. Non-segwit miners can become compa= tible by simply
including an additional output matching a default= commitment
value returned as part of getblocktemplate.

Miners SHOULD NOT automatically discontinue the commitment<= /div>
at the expiration height.

=3D=3DDiscussi= on=3D=3D

The commitment in the left side of the tr= ee to all transactions
in the right side completely prevents the = final sqrt speedup.

A stronger inhibition of the c= overt optimization in the form of
requiring the least significant= bits of the block timestamp
to be equal to a hash of the first 6= 4-bytes of the header. This
would increase the collision space fr= om 32 to 40 or more bits.
The root value could be required to mee= t a specific hash prefix
requirement in order to increase the com= putational work required
to try candidate roots. These change wou= ld be more disruptive and
there is no reason to believe that it i= s currently necessary.

The proposed rule automatic= ally sunsets. If it is no longer needed
due to the introduction o= f stronger rules or the acceptance of the
version-grinding form t= hen there would be no reason to continue
with this requirement.= =C2=A0 If it is still useful at the expiration
time the rule can = simply be extended with a new softfork that
sets longer date rang= es.

This sun-setting avoids the accumulation of te= chnical debt due
to retaining enforcement of this rule when it is= no longer needed
without requiring a hard fork to remove it.

=3D=3D Overt optimization =3D=3D

=
A BIP for avoiding erroneous warning messages when miners use the over= t version
of the optimization was proposed several years ago, in = order to deter the covert
use of the optimization. But that BIP w= as rejected.=C2=A0
However, in light of the current discoveries, = that BIP could be reconsidered.

The over optimizat= ion does not generally interfere with improvements in the protocol.

=3D=3DBackward compatibility=3D=3D


=3D=3DImplementation=3D=3D


<= /div>
=3D=3DAcknowledgments=3D=3D

Greg Maxwell= <greg@xiph.org> for the origina= l report, which contained several errors that were corrected in the present= proposal.

=3D=3DCopyright=3D=3D

This document is placed in the public domain.
--001a11c000ae7132d1054c99cffb--