<oembed><type>rich</type><version>1.0</version><author_name>npub1g5zswf6y48f7fy90jf3tlcuwdmjn8znhzaa4vkmtxaeskca8hpss23ms3l</author_name><author_url>https://nostr.ae/npub1g5zswf6y48f7fy90jf3tlcuwdmjn8znhzaa4vkmtxaeskca8hpss23ms3l</author_url><provider_name>njump</provider_name><provider_url>https://nostr.ae</provider_url><html>📅 Original date posted:2019-10-06&#xA;📝 Original message:Good morning Peter, Jeremy, and lists,&#xA;&#xA;&gt; On Fri, Oct 04, 2019 at 11:40:53AM -0700, Jeremy wrote:&#xA;&gt;&#xA;&gt; &gt; Interesting point.&#xA;&gt; &gt; The script is under your control, so you should be able to ensure that you&#xA;&gt; &gt; are always using a correctly constructed midstate, e.g., something like:&#xA;&gt; &gt; scriptPubKey: &lt;-1&gt; OP_SHA256STREAM DEPTH OP_SHA256STREAM &lt;-2&gt;&#xA;&gt; &gt; OP_SHA256STREAM&#xA;&gt; &gt; &lt;hash&gt; OP_EQUALVERIFY&#xA;&gt; &gt; would hash all the elements on the stack and compare to a known hash.&#xA;&gt; &gt; How is that sort of thing weak to midstateattacks?&#xA;&gt;&#xA;&gt; Obviously with care you can get the computation right. But at that point what&#39;s&#xA;&gt; the actual advantage over OP_CAT?&#xA;&gt;&#xA;&gt; We&#39;re limited by the size of the script anyway; if the OP_CAT output size limit&#xA;&gt; is comparable to that for almost anything you could use SHA256STREAM on you&#xA;&gt; could just as easily use OP_CAT, followed by a single OP_SHA256.&#xA;&#xA;Theoretically, `OP_CAT` is less efficient.&#xA;&#xA;In cases where the memory area used to back the data cannot be resized, new backing memory must be allocated elsewhere and the existing data copied.&#xA;This leads to possible O( n^2 ) behavior for `OP_CAT` (degenerate case where we add 1 byte per `OP_CAT` and each time find that the memory area currently in use is exactly fitting the data and cannot be resized in-place).&#xA;&#xA;`OP_SHASTREAM` would not require new allocations once the stream state is in place and would not require any copying.&#xA;&#xA;&#xA;This may be relevant in considering the cost of executing `OP_CAT`.&#xA;&#xA;Admittedly a sufficiently-limited  maximum `OP_CAT` output would be helpful in reducing the worst-case `OP_CAT` behavior.&#xA;The question is what limit would be reasonable.&#xA;64 bytes feels too small if one considers Merkle tree proofs, due to mentioned issues of lack of typechecking.&#xA;&#xA;&#xA;Regards,&#xA;ZmnSCPxj&#xA;&#xA;&#xA;&gt;&#xA;&gt; --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------&#xA;&gt;&#xA;&gt; https://petertodd.org &#39;peter&#39;[:-1]@petertodd.org&#xA;&gt;&#xA;&gt; Lightning-dev mailing list&#xA;&gt; Lightning-dev at lists.linuxfoundation.org&#xA;&gt; https://lists.linuxfoundation.org/mailman/listinfo/lightning-dev</html></oembed>