<oembed><type>rich</type><version>1.0</version><author_name>npub17rld56k4365lfphyd8u8kwuejey5xcazdxptserx03wc4jc9g24stx9l2h</author_name><author_url>https://nostr.ae/npub17rld56k4365lfphyd8u8kwuejey5xcazdxptserx03wc4jc9g24stx9l2h</author_url><provider_name>njump</provider_name><provider_url>https://nostr.ae</provider_url><html>📅 Original date posted:2015-12-09&#xA;📝 Original message:On Wed, Dec 09, 2015 at 01:31:51AM +0000, Gregory Maxwell via bitcoin-dev wrote:&#xA;&gt; On Wed, Dec 9, 2015 at 1:09 AM, Gavin Andresen &lt;gavinandresen at gmail.com&gt; wrote:&#xA;&gt; &gt; Create a 1-megabyte transaction, with all of it&#39;s inputs spending&#xA;&gt; &gt; segwitness-spending SIGHASH_ALL inputs.&#xA;&gt; &gt; Because the segwitness inputs are smaller in the block, you can fit more of&#xA;&gt; &gt; them into 1 megabyte. Each will hash very close to one megabyte of data.&#xA;&gt; Witness size comes out of the 1MB at a factor of 0.25. It is not&#xA;&gt; possible to make a block which has signatures with the full 1MB of&#xA;&gt; data under the sighash while also having signatures externally.  So&#xA;&gt; every byte moved into the witness and thus only counted as 25% comes&#xA;&gt; out of the data being hashed and is hashed nInputs (*checksigs) less&#xA;&gt; times.&#xA;&#xA;So the worst case script I can come up with is:&#xA;&#xA;      &lt;pubkey&gt; 1 0 {2OVER CHECKSIG ADD CODESEP} OP_EQUAL&#xA;&#xA;which (if I didn&#39;t mess it up) would give you a redeem script of about&#xA;36B plus 4B per sigop, redeemable via a single signature that&#39;s valid&#xA;for precisely one of the checksigs.&#xA;&#xA;Maxing out 20k sigops gives 80kB of redeemscript in that case; so you&#xA;could have to hash 19.9GB of data to fully verify the script with&#xA;current bitcoin rules.&#xA;&#xA;Segwit with the 75% factor and the same sigop limit would make that very&#xA;slightly worse -- it&#39;d up the hashed data by maybe 1MB in total. Without&#xA;a sigop limit at all it&#39;d be severely worse of course -- you could fit&#xA;almost 500k sigops in 2MB of witness data, leaving 500kB of base data,&#xA;for a total of 250GB of data to hash to verify your 3MB block...&#xA;&#xA;Segwit without the 75% factor, but with a 3MB of witness data limit,&#xA;makes that up to three times worse (750k sigops in 3MB of witness data,&#xA;with 1MB of base data for 750GB of data to hash), but with any reasonable&#xA;sigop limit, afaics it&#39;s pretty much the same.&#xA;&#xA;However I think you could add some fairly straightforward (maybe&#xA;soft-forking) optimisations to just rule out that sort of (deliberate)&#xA;abuse; eg disallowing more than a dozen sigops per input, or just failing&#xA;checksigs with the same key in a single input, maybe. So maybe that&#39;s&#xA;not sufficiently realistic?&#xA;&#xA;I think the only realistic transactions that would cause lots of sigs and&#xA;hashing are ones that have lots of inputs that each require a signature&#xA;or two, so might happen if a miner is cleaning up dust. In that case,&#xA;your 1MB transaction is a single output with a bunch of 41B inputs. If you&#xA;have 10k such inputs, that&#39;s only 410kB. If each input is a legitimate&#xA;2 of 2 multisig, that&#39;s about 210 bytes of witness data per input, or&#xA;2.1MB, leaving 475kB of base data free, which matches up. 20k sigops by&#xA;475kB of data is 9.5GB of hashing.&#xA;&#xA;Switching from 2-of-2 multisig to just a single public key would prevent&#xA;you from hitting the sigop limit; I think you could hit 14900 signatures&#xA;with about 626kB of base data and 1488kB of witness data, for about&#xA;9.3GB of hashed data.&#xA;&#xA;That&#39;s a factor of 2x improvement over the deliberately malicious exploit&#xA;case above, but it&#39;s /only/ a factor of 2x.&#xA;&#xA;I think Rusty&#39;s calculation http://rusty.ozlabs.org/?p=522 was that&#xA;the worst case for now is hashing about 406kB, 3300 times for 1.34GB of&#xA;hashed data [0].&#xA;&#xA;So that&#39;s still almost a factor of 4 or 5 worse than what&#39;s possible now?&#xA;Unless I messed up the maths somewhere?&#xA;&#xA;Cheers,&#xA;aj&#xA;&#xA;[0] Though I&#39;m not sure that&#39;s correct? Seems like with a 1MB&#xA;    transaction with i inputs, each with s bytes of scriptsig, that you&#39;re&#xA;    hashing (1MB-s*i), and the scriptsig for a p2pkh should only be about&#xA;    105B, not 180B.  So maximising i*(1MB-s*i) = 1e6*i - 105*i^2 gives i =&#xA;    1e6/210, so 4762 inputs, and hashing 500kB of data each time,&#xA;    for about 2.4GB of hashed data total.</html></oembed>