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 754A59CDA for ; Tue, 5 Feb 2019 01:43:11 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.7.6 Received: from mail-yw1-f50.google.com (mail-yw1-f50.google.com [209.85.161.50]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 08AED13A for ; Tue, 5 Feb 2019 01:43:09 +0000 (UTC) Received: by mail-yw1-f50.google.com with SMTP id j82so1137568ywb.2 for ; Mon, 04 Feb 2019 17:43:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=vBMvjwGU/erCSZ6saFmHtwPYtDnrCT1qcABblRNcM0Y=; b=XNjzLbvAfrmlskzvbsf52LO4gsy+eCIXT9Z44a0fHINo5xVuRlb7pR4Anf9aE4wjSp N73fPu1hBF+Kr1CAYxpWDXG/jE8xY1j/fjq9dqh0hNvaYX0mqnoltrF/jcnS16DOEzaK kBT7Y4gHXaFLICNMwMJpPOJi73R36J2SNHSep19G4p1D9bSKc6zZLUMrzxjg40UfeVTn GDs/wbEPAB3jiyVCCb8O3sRsceJ8rE2LSHKsArUvRB3+FjE9WaZHMBpHQOfm6yqp+PME SZA/KN/JMq6zY0eMDx8auci8XcL2Jk6a2MDNceUJ+Qg0Qu1gysOPh4/ixQBzLmt0lnMQ ANZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=vBMvjwGU/erCSZ6saFmHtwPYtDnrCT1qcABblRNcM0Y=; b=iW5yWvYu8rU4toDhxLzzGW8Ae3Ya0o429X5GD5ZZjQ2dMq5zw0qRpRSM+fhpINQvDb 1c2zjuMMGwP4HXFNEPr/iMdX514YNMKyoJpyH7yMilmnXWTnsqJMg/rBWMh03JirdVpY EDD0nyxEceWDR/v9zPYPNca9pkWI3vN6idQH/YH/WL4T6HqujNC2t0glESWyre7Mhj4h Kzmcrno3aJzoRqop0FI0p2oYP6KKt+NvxAHlN0OkMoJgF/GljTXhX8vCWzU02DoooRF2 R7eWhVksk0DjZlZ5+Izkuz+DV9rbjHwFk9QztBU1nStYOWj2iQoD4wR+6jmqpV2NHSyH pSOQ== X-Gm-Message-State: AHQUAua29AL3WkPUkiu09ezFpE5OcPDLtfFe0WFcqsNeiNiG6LGJyUeZ KKf8ocCrLskG61qChMzfIiGlU4hWJWTI8STtfpQ= X-Google-Smtp-Source: AHgI3IYOhNqSp+xiqn0HvFAtBt414M39KDx99Nnhkyhe+fLQ+sXG96e8GgrEEJk14vRe22EES09f9C5CYlILpQA9lZ4= X-Received: by 2002:a81:6189:: with SMTP id v131mr1972424ywb.37.1549330988874; Mon, 04 Feb 2019 17:43:08 -0800 (PST) MIME-Version: 1.0 References: <6D57649F-0236-4FBA-8376-4815F5F39E8A@gmail.com> In-Reply-To: From: Olaoluwa Osuntokun Date: Mon, 4 Feb 2019 17:42:57 -0800 Message-ID: To: Tamas Blummer Content-Type: multipart/alternative; boundary="0000000000003b403205811bbb84" X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM, HTML_MESSAGE,RCVD_IN_DNSWL_NONE autolearn=no version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org X-Mailman-Approved-At: Tue, 05 Feb 2019 06:06:25 +0000 Cc: Jim Posen , Bitcoin Protocol Discussion Subject: Re: [bitcoin-dev] Interrogating a BIP157 server, BIP158 change proposal 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: Tue, 05 Feb 2019 01:43:11 -0000 --0000000000003b403205811bbb84 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi Tamas, This is how the filter worked before the switch over to optimize for a filter containing the minimal items needed for a regular wallet to function= . When this was proposed, I had already implemented the entire proposal from wallet to full-node. At that point, we all more or less decided that the space savings (along with intra-block compression) were worthwhile, we weren't cutting off any anticipated application level use cases (at that point we had already comprehensively integrated both filters into lnd), and that once committed the security loss would disappear. I think it's too late into the current deployment of the BIPs to change things around yet again. Instead, the BIP already has measures in place for adding _new_ filter types in the future. This along with a few other filter types may be worthwhile additions as new filter types. -- Laolu On Mon, Feb 4, 2019 at 12:59 PM Tamas Blummer wrote: > I participated in that discussion in 2018, but have not had the insight > gathered by now though writing both client and server implementation of > BIP157/158 > > Pieter Wuille considered the design choice I am now suggesting here as > alternative (a) in: > https://lists.linuxfoundation.org/pipermail/bitcoin-dev/2018-June/016064.= html > In his evaluation he recognized that a filter having spent output and > output scripts would allow decision on filter correctness by knowing the > block only. > He did not evaluate the usefulness in the context of checkpoints, which I > think are an important shortcut here. > > Yes, a filter that is collecting input and output scripts is shorter if > script re-use is frequent, but I showed back in 2018 in the same thread > that this saving is not that significant in recent history as address reu= se > is no longer that frequent. > > A filter on spent outpoint is just as useful for wallets as is one on > spent script, since they naturally scan the blockchain forward and thereb= y > learn about their coins by the output script before they need to check > spends of those outpoints. > > It seems to me that implementing an interrogation by evtl. downloading > blocks at checkpoints is much simpler than following multiple possible > filter paths. > > A spent outpoint filter allows us to decide on coin availability based on > immutable store, without updated and eventually rolled back UTXO store. T= he > availability could be decided by following the filter path to current tip > to genesis and > check is the outpoint was spent earlier. False positives can be sorted ou= t > with a block download. Murmel implements this if running in server mode, > where blocks are already there. > > Therefore I ask for a BIP change based on better insight gained through > implementation. > > Tamas Blummer > > On Feb 4, 2019, at 21:18, Jim Posen wrote: > > Please see the thread "BIP 158 Flexibility and Filter Size" from 2018 > regarding the decision to remove outpoints from the filter [1]. > > Thanks for bringing this up though, because more discussion is needed on > the client protocol given that clients cannot reliably determine the > integrity of a block filter in a bandwidth-efficient manner (due to the > inclusion of input scripts). > > I see three possibilities: > 1) Introduce a new P2P message to retrieve all prev-outputs for a given > block (essentially the undo data in Core), and verify the scripts against > the block by executing them. While this permits some forms of input scrip= t > malleability (and thus cannot discriminate between all valid and invalid > filters), it restricts what an attacker can do. This was proposed by Laol= u > AFAIK, and I believe this is how btcd is proceeding. > 2) Clients track multiple possible filter header chains and essentially > consider the union of their matches. So if any filter received for a > particular block header matches, the client downloads the block. The clie= nt > can ban a peer if they 1) ever return a filter omitting some data that is > observed in the downloaded block, 2) repeatedly serve filters that trigge= r > false positive block downloads where such a number of false positives is > statistically unlikely, or 3) repeatedly serves filters that are > significantly larger than the expected size (essentially padding the actu= al > filters with garbage to waste bandwidth). I have not done the analysis ye= t, > but we should be able to come up with some fairly simple banning heuristi= cs > using Chernoff bounds. The main downside is that the client logic to trac= k > multiple possible filter chains and filters per block is more complex and > bandwidth increases if connected to a malicious server. I first heard abo= ut > this idea from David Harding. > 3) Rush straight to committing the filters into the chain (via witness > reserved value or coinbase OP_RETURN) and give up on the pre-softfork BIP > 157 P2P mode. > > I'm in favor of option #2 despite the downsides since it requires the > smallest number of changes and is supported by the BIP 157 P2P protocol a= s > currently written. (Though the recommended client protocol in the BIP nee= ds > to be updated to account for this). Another benefit of it is that it > removes some synchronicity assumptions where a peer with the correct > filters keeps timing out and is assumed to be dishonest, while the > dishonest peer is assumed to be OK because it is responsive. > > If anyone has other ideas, I'd love to hear them. > > -jimpo > > [1] > https://lists.linuxfoundation.org/pipermail/bitcoin-dev/2018-June/016057.= html > > > > On Mon, Feb 4, 2019 at 10:53 AM Tamas Blummer via bitcoin-dev < > bitcoin-dev@lists.linuxfoundation.org> wrote: > >> TLDR: a change to BIP158 would allow decision on which filter chain is >> correct at lower bandwith use >> >> Assume there is a BIP157 client that learned a filter header chain >> earlier and is now offered an alternate reality by a newly connected BIP= 157 >> server. >> >> The client notices the alternate reality by routinely asking for filter >> chain checkpoints after connecting to a new BIP157 server. A divergence = at >> a checkpoint means that the server disagrees the client's history at or >> before the first diverging checkpoint. The client would then request the >> filter headers between the last matching and first divergent checkpoint, >> and quickly figure which block=E2=80=99s filter is the first that does n= ot match >> previous assumption, and request that filter from the server. >> >> The client downloads the corresponding block, checks that its header fit= s >> the PoW secured best header chain, re-calculates merkle root of its >> transaction list to know that it is complete and queries the filter to s= ee >> if every output script of every transaction is contained in there, if no= t >> the server is lying, the case is closed, the server disconnected. >> >> Having all output scripts in the filter does not however guarantee that >> the filter is correct since it might omit input scripts. Inputs scripts = are >> not part of the downloaded block, but are in some blocks before that. >> Checking those are out of reach for lightweight client with tools given = by >> the current BIP. >> >> A remedy here would be an other filter chain on created and spent >> outpoints as is implemented currently by Murmel. The outpoint filter cha= in >> must offer a match for every spent output of the block with the divergen= t >> filter, otherwise the interrogated server is lying since a PoW secured >> block can not spend coins out of nowhere. Doing this check would already >> force the client to download the outpoint filter history up-to the point= of >> divergence. Then the client would have to download and PoW check every >> block that shows a match in outpoints until it figures that one of the >> spent outputs has a script that was not in the server=E2=80=99s filter, = in which >> case the server is lying. If everything checks out then the previous >> assumption on filter history was incorrect and should be replaced by the >> history offered by the interrogated server. >> >> As you see the interrogation works with this added filter but is highly >> ineffective. A really light client should not be forced to download lots= of >> blocks just to uncover a lying filter server. This would actually be an >> easy DoS on light BIP157 clients. >> >> A better solution is a change to BIP158 such that the only filter >> contains created scripts and spent outpoints. It appears to me that this >> would serve well both wallets and interrogation of filter servers well: >> >> Wallets would recognize payments to their addresses by the filter as >> output scripts are included, spends from the wallet would be recognized = as >> a wallet already knows outpoints of its previously received coins, so it >> can query the filters for them. >> >> Interrogation of a filter server also simplifies, since the filter of th= e >> block can be checked entirely against the contents of the same block. Th= e >> decision on filter correctness does not require more bandwith then downl= oad >> of a block at the mismatching checkpoint. The client could only be force= d >> at max. to download 1/1000 th of the blockchain in addition to the filte= r >> header history. >> >> Therefore I suggest to change BIP158 to have a base filter, defined as: >> >> A basic filter MUST contain exactly the following items for each >> transaction in a block: >> =E2=80=A2 Spent outpoints >> =E2=80=A2 The scriptPubKey of each output, aside from all OP_RET= URN >> output scripts. >> >> Tamas Blummer >> _______________________________________________ >> bitcoin-dev mailing list >> bitcoin-dev@lists.linuxfoundation.org >> https://lists.linuxfoundation.org/mailman/listinfo/bitcoin-dev >> > > --0000000000003b403205811bbb84 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi Tamas,=C2=A0

This is= how the filter worked before the switch over to optimize for a
f= ilter containing the minimal items needed for a regular wallet to function.=
When this was proposed, I had already implemented the entire pro= posal from
wallet to full-node. At that point, we all more or les= s decided that the
space savings (along with intra-block compress= ion) were worthwhile, we
weren't cutting off any anticipated = application level use cases (at that
point we had already compreh= ensively integrated both filters into lnd), and
that once committ= ed the security loss would disappear.

I think it&#= 39;s too late into the current deployment of the BIPs to change
t= hings around yet again. Instead, the BIP already has measures in place for<= /div>
adding _new_ filter types in the future. This along with a few ot= her filter
types may be worthwhile additions as new filter types.=

-- Laolu

On Mon, Feb 4, 2019 at 12:59 = PM Tamas Blummer <tamas.blumm= er@gmail.com> wrote:
I participated in that discussion in 2018= , but have not had the insight gathered by now though writing both client a= nd server implementation of BIP157/158

Pieter Wuil= le considered the design choice I am now suggesting here as alternative (a)= in:=C2=A0https://lists.linuxfoundation.or= g/pipermail/bitcoin-dev/2018-June/016064.html
In his evaluati= on he recognized that a filter having spent output and output scripts would= allow decision on filter correctness by knowing the block only.
= He did not evaluate the usefulness in the context of checkpoints, which I t= hink are an important shortcut here.

Yes, a filter= that is collecting input and output scripts is shorter if script re-use is= frequent, but I showed back in 2018 in the same thread that this saving is= not that significant in recent history as address reuse is no longer that = frequent.

A filter on spent outpoint is just as us= eful for wallets as is one on spent script, since they naturally scan the b= lockchain forward and thereby learn about their coins by the output script = before they need to check spends of those outpoints.

It seems to me that implementing an interrogation by evtl. downloading b= locks at checkpoints is much simpler than following multiple possible filte= r paths.

A spent outpoint filter allows us to deci= de on coin availability based on immutable store, without updated and event= ually rolled back UTXO store. The availability could be decided by followin= g the filter path to current tip to genesis and
check is the outp= oint was spent earlier. False positives can be sorted out with a block down= load. Murmel implements this if running in server mode, where blocks are al= ready there.

Therefore I ask for a BIP change base= d on better insight gained through implementation.

Tamas Blummer

On Feb= 4, 2019, at 21:18, Jim Posen <jim.posen@gmail.com> wrote:

Please see the thread "BIP 158 Flexibility and Filter Size&qu= ot; from 2018 regarding the decision to remove outpoints from the filter [1= ].

Thanks for bringing this up though,= because more discussion is needed on the client protocol given that client= s cannot reliably determine the integrity of a block filter in a bandwidth-= efficient manner (due to the inclusion of input scripts).

I see three possibilities:
1) Introduce a new P2P message= to retrieve all prev-outputs for a given block (essentially the undo data = in Core), and verify the scripts against the block by executing them. While= this permits some forms of input script malleability (and thus cannot disc= riminate between all valid and invalid filters), it restricts what an attac= ker can do. This was proposed by Laolu AFAIK, and I believe this is how btc= d is proceeding.
2) Clients track multiple possible filter header= chains and essentially consider the union of their matches. So if any filt= er received for a particular block header matches, the client downloads the= block. The client can ban a peer if they 1) ever return a filter omitting = some data that is observed in the downloaded block, 2) repeatedly serve fil= ters that trigger false positive block downloads where such a number of fal= se positives is statistically unlikely, or 3) repeatedly serves filters tha= t are significantly larger than the expected size (essentially padding the = actual filters with garbage to waste bandwidth). I have not done the analys= is yet, but we should be able to come up with some fairly simple banning he= uristics using Chernoff bounds. The main downside is that the client logic = to track multiple possible filter chains and filters per block is more comp= lex and bandwidth increases if connected to a malicious server. I first hea= rd about this idea from David Harding.
3) Rush straight to commit= ting the filters into the chain (via witness reserved value or coinbase OP_= RETURN) and give up on the pre-softfork BIP 157 P2P mode.

I'm in favor of option #2 despite the downsides since it requir= es the smallest number of changes and is supported by the BIP 157 P2P proto= col as currently written. (Though the recommended client protocol in the BI= P needs to be updated to account for this). Another benefit of it is that i= t removes some synchronicity assumptions where a peer with the correct filt= ers keeps timing out and is assumed to be dishonest, while the dishonest pe= er is assumed to be OK because it is responsive.

I= f anyone has other ideas, I'd love to hear them.

-jimpo



=

= On Mon, Feb 4, 2019 at 10:53 AM Tamas Blummer via bitcoin-dev <bitcoin= -dev@lists.linuxfoundation.org> wrote:
TLDR: a change to BIP158 would allow decision= on which filter chain is correct at lower bandwith use

Assume there is a BIP157 client that learned a filter header chain earlier = and is now offered an alternate reality by a newly connected BIP157 server.=

The client notices the alternate reality by routinely asking for filter cha= in checkpoints after connecting to a new BIP157 server. A divergence at a c= heckpoint means that the server disagrees the client's history at or be= fore the first diverging checkpoint. The client would then request the filt= er headers between the last matching and first divergent checkpoint, and qu= ickly figure which block=E2=80=99s filter is the first that does not match = previous assumption, and request that filter from the server.

The client downloads the corresponding block, checks that its header fits t= he PoW secured best header chain, re-calculates merkle root of its transact= ion list to know that it is complete and queries the filter to see if every= output script of every transaction is contained in there, if not the serve= r is lying, the case is closed, the server disconnected.

Having all output scripts in the filter does not however guarantee that the= filter is correct since it might omit input scripts. Inputs scripts are no= t part of the downloaded block, but are in some blocks before that. Checkin= g those are out of reach for lightweight client with tools given by the cur= rent BIP.

A remedy here would be an other filter chain on created and spent outpoints= as is implemented currently by Murmel. The outpoint filter chain must offe= r a match for every spent output of the block with the divergent filter, ot= herwise the interrogated server is lying since a PoW secured block can not = spend coins out of nowhere. Doing this check would already force the client= to download the outpoint filter history up-to the point of divergence. The= n the client would have to download and PoW check every block that shows a = match in outpoints until it figures that one of the spent outputs has a scr= ipt that was not in the server=E2=80=99s filter, in which case the server i= s lying. If everything checks out then the previous assumption on filter hi= story was incorrect and should be replaced by the history offered by the in= terrogated server.

As you see the interrogation works with this added filter but is highly ine= ffective. A really light client should not be forced to download lots of bl= ocks just to uncover a lying filter server. This would actually be an easy = DoS on light BIP157 clients.

A better solution is a change to BIP158 such that the only filter contains = created scripts and spent outpoints. It appears to me that this would serve= well both wallets and interrogation of filter servers well:

Wallets would recognize payments to their addresses by the filter as output= scripts are included, spends from the wallet would be recognized as a wall= et already knows outpoints of its previously received coins, so it can quer= y the filters for them.

Interrogation of a filter server also simplifies, since the filter of the b= lock can be checked entirely against the contents of the same block. The de= cision on filter correctness does not require more bandwith then download o= f a block at the mismatching checkpoint. The client could only be forced at= max. to download 1/1000 th of the blockchain in addition to the filter hea= der history.

Therefore I suggest to change BIP158 to have a base filter, defined as:

A basic filter MUST contain exactly the following items for each transactio= n in a block:
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =E2=80=A2 Spent outpoints
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =E2=80=A2 The scriptPubKey of each output, asid= e from all OP_RETURN output scripts.

Tamas Blummer
_______________________________________________
bitcoin-dev mailing list
= bitcoin-dev@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mail= man/listinfo/bitcoin-dev

--0000000000003b403205811bbb84--