<oembed><type>rich</type><version>1.0</version><author_name>npub1q86n5vtxkwerzwfqza3hwls8pl8764244464talfqy2vpj0qaz6q38qwta</author_name><author_url>https://nostr.ae/npub1q86n5vtxkwerzwfqza3hwls8pl8764244464talfqy2vpj0qaz6q38qwta</author_url><provider_name>njump</provider_name><provider_url>https://nostr.ae</provider_url><html>📅 Original date posted:2019-10-04&#xA;📝 Original message:Interesting point.&#xA;&#xA;The script is under your control, so you should be able to ensure that you&#xA;are always using a correctly constructed midstate, e.g., something like:&#xA;&#xA;scriptPubKey: &lt;-1&gt; OP_SHA256STREAM DEPTH OP_SHA256STREAM &lt;-2&gt;&#xA;OP_SHA256STREAM&#xA;&lt;hash&gt; OP_EQUALVERIFY&#xA;&#xA;would hash all the elements on the stack and compare to a known hash.&#xA;How is that sort of thing weak to midstateattacks?&#xA;&#xA;&#xA;--&#xA;@JeremyRubin &lt;https://twitter.com/JeremyRubin&gt;&#xA;&lt;https://twitter.com/JeremyRubin&gt;&#xA;&#xA;&#xA;On Fri, Oct 4, 2019 at 4:16 AM Peter Todd &lt;pete at petertodd.org&gt; wrote:&#xA;&#xA;&gt; On Thu, Oct 03, 2019 at 10:02:14PM -0700, Jeremy via bitcoin-dev wrote:&#xA;&gt; &gt; Awhile back, Ethan and I discussed having, rather than OP_CAT, an&#xA;&gt; &gt; OP_SHA256STREAM that uses the streaming properties of a SHA256 hash&#xA;&gt; &gt; function to allow concatenation of an unlimited amount of data, provided&#xA;&gt; &gt; the only use is to hash it.&#xA;&gt; &gt;&#xA;&gt; &gt; You can then use it perhaps as follows:&#xA;&gt; &gt;&#xA;&gt; &gt; // start a new hash with item&#xA;&gt; &gt; OP_SHA256STREAM  (-1) -&gt; [state]&#xA;&gt; &gt; // Add item to the hash in state&#xA;&gt; &gt; OP_SHA256STREAM n [item] [state] -&gt; [state]&#xA;&gt; &gt; // Finalize&#xA;&gt; &gt; OP_SHA256STREAM (-2) [state] -&gt; [Hash]&#xA;&gt; &gt;&#xA;&gt; &gt; &lt;-1&gt; OP_SHA256STREAM &lt;tag&gt; &lt;subnode 2&gt; &lt;subnode 3&gt; &lt;3&gt; OP_SHA256STREAM&#xA;&gt; &lt;-2&gt;&#xA;&gt; &gt; OP_SHA256STREAM&#xA;&gt;&#xA;&gt; One issue with this is the simplest implementation where the state is just&#xA;&gt; raw&#xA;&gt; bytes would expose raw SHA256 midstates, allowing people to use them&#xA;&gt; directly;&#xA;&gt; preventing that would require adding types to the stack. Specifically I&#xA;&gt; could&#xA;&gt; write a script that rather than initializing the state correctly from the&#xA;&gt; official IV, instead takes an untrusted state as input.&#xA;&gt;&#xA;&gt; SHA256 isn&#39;t designed to be used in situations where adversaries control&#xA;&gt; the&#xA;&gt; initialization vector. I personally don&#39;t know one way or the other if&#xA;&gt; anyone&#xA;&gt; has analyzed this in detail, but I&#39;d be surprised if that&#39;s secure. I&#xA;&gt; considered adding midstate support to OpenTimestamps but decided against&#xA;&gt; it for&#xA;&gt; exactly that reason.&#xA;&gt;&#xA;&gt; I don&#39;t have the link handy but there&#39;s even an example of an experienced&#xA;&gt; cryptographer on this very list (bitcoin-dev) proposing a design that falls&#xA;&gt; victim to this attack. It&#39;s a subtle issue and we probably don&#39;t want to&#xA;&gt; encourage it.&#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&#xA;&gt;&#xA;-------------- next part --------------&#xA;An HTML attachment was scrubbed...&#xA;URL: &lt;http://lists.linuxfoundation.org/pipermail/bitcoin-dev/attachments/20191004/bda6e24c/attachment-0001.html&gt;</html></oembed>