user-1: I'm having troubles with understanding how script hash is computed in P2SH transactions.
From BIP-16 documentation (https://github.com/bitcoin/bips/blob/master/bip-0016.mediawiki):
scriptSig: [signature] {[pubkey] OP_CHECKSIG}
scriptPubKey: OP_HASH160 [20-byte-hash of {[pubkey] OP_CHECKSIG} ] OP_EQUAL

From Bitcoin Wiki (https://en.bitcoin.it/wiki/Script#Crypto):
OP_HASH160 ... The input is hashed twice: first with SHA-256 and then with RIPEMD-160.

So I've tried to compute script hash from a real transaction. I've randomly chosen this one: https://blockstream.info/tx/00e07f279dd05b9b68c40f21b43c57847e75c35cd3bbc2d80921eb037ef0c9a8?expand.
Next, I will be talking about input 0.
I believe that the hash, which I'm supposed to get is

4bf411df4b0004e00006f88a4f83d127195b88c7

And the thing, that I'm supposed to hash is

5221036c3735b2bf370501c3b872498de54b39ab5afa83d8ce7f6aec43f63a812265b421032b03a42faf387dd5c604435cd48d26b8827fa28a5d4d0f9a18b5cefe443bb4102102ebbd4ecea67dd980fc4854cc13b1f10cefafdafe8b1eb8e5ce73939b59a0477c53ae

, as this is hex of the redeem script.
But when I compute HASH160, I get

94b1c88916b7c784b896be91b6924f15c2d4a344

, which is not, what I expect..

SHA256(5221036c3735b2bf370501c3b872498de54b39ab5afa83d8ce7f6aec43f63a812265b421032b03a42faf387dd5c604435cd48d26b8827fa28a5d4d0f9a18b5cefe443bb4102102ebbd4ecea67dd980fc4854cc13b1f10cefafdafe8b1eb8e5ce73939b59a0477c53ae) = a77da07651b8445cc38ff5bb96e1e38977c4efdcc21b767ca3e25b8919514e03


RIPEMD160(a77da07651b8445cc38ff5bb96e1e38977c4efdcc21b767ca3e25b8919514e03) = 94b1c88916b7c784b896be91b6924f15c2d4a344

Please explain to me, where is the mistake and what should I do instead. Am I mistaking in what should be hashed and what the result should be, or am I just computing SHA256 and RIPEMD160 wrong?
Good luck,
0x309.
PS: To compute hashes I run echo"..." | openssl sha256, then I copy the hash (so that there is no "(stdin)= ") and run
echo "..." | openssl rmd160.

user-1: I've been computing hash wrong. Right way to do it:
echo "hex-encoded script" | xxd -r -p | openssl sha256 | sed "s/[^ ]* //" | xxd -r -p | openssl rmd160
Or in a more elegant way:
echo "hex-encoded script" | xxd -r -p | openssl sha256 --binary | openssl rmd160
Look at the question's comment section, if you are interested why so.
Good luck, 0x309.
PS: you might need to use openssl rmd160 -provider legacy

-1: <p>I'm having troubles with understanding how script hash is computed in P2SH transactions.</p>
<p>From BIP-16 documentation (<a href="https://github.com/bitcoin/bips/blob/master/bip-0016.mediawiki" rel="nofollow noreferrer">https://github.com/bitcoin/bips/blob/master/bip-0016.mediawiki</a>):</p>
<pre><code>scriptSig: [signature] {[pubkey] OP_CHECKSIG}
scriptPubKey: OP_HASH160 [20-byte-hash of {[pubkey] OP_CHECKSIG} ] OP_EQUAL
</code></pre>
<p>From Bitcoin Wiki (<a href="https://en.bitcoin.it/wiki/Script#Crypto" rel="nofollow noreferrer">https://en.bitcoin.it/wiki/Script#Crypto</a>):</p>
<pre><code>OP_HASH160 ... The input is hashed twice: first with SHA-256 and then with RIPEMD-160.
</code></pre>
<p>So I've tried to compute script hash from a real transaction. I've randomly chosen this one: <a href="https://blockstream.info/tx/00e07f279dd05b9b68c40f21b43c57847e75c35cd3bbc2d80921eb037ef0c9a8?expand" rel="nofollow noreferrer">https://blockstream.info/tx/00e07f279dd05b9b68c40f21b43c57847e75c35cd3bbc2d80921eb037ef0c9a8?expand</a>.</p>
<p>Next, I will be talking about input 0.
I believe that the hash, which I'm supposed to get is</p>
<blockquote>
<p>4bf411df4b0004e00006f88a4f83d127195b88c7</p>
</blockquote>
<p>And the thing, that I'm supposed to hash is</p>
<blockquote>
<p>5221036c3735b2bf370501c3b872498de54b39ab5afa83d8ce7f6aec43f63a812265b421032b03a42faf387dd5c604435cd48d26b8827fa28a5d4d0f9a18b5cefe443bb4102102ebbd4ecea67dd980fc4854cc13b1f10cefafdafe8b1eb8e5ce73939b59a0477c53ae</p>
</blockquote>
<p>, as this is hex of the redeem script.</p>
<p>But when I compute HASH160, I get</p>
<blockquote>
<p>94b1c88916b7c784b896be91b6924f15c2d4a344</p>
</blockquote>
<p>, which is not, what I expect..</p>
<blockquote>
<p>SHA256(5221036c3735b2bf370501c3b872498de54b39ab5afa83d8ce7f6aec43f63a812265b421032b03a42faf387dd5c604435cd48d26b8827fa28a5d4d0f9a18b5cefe443bb4102102ebbd4ecea67dd980fc4854cc13b1f10cefafdafe8b1eb8e5ce73939b59a0477c53ae) = a77da07651b8445cc38ff5bb96e1e38977c4efdcc21b767ca3e25b8919514e03</p>
</blockquote>
<blockquote>
<p>RIPEMD160(a77da07651b8445cc38ff5bb96e1e38977c4efdcc21b767ca3e25b8919514e03) = 94b1c88916b7c784b896be91b6924f15c2d4a344</p>
</blockquote>
<p>Please explain to me, where is the mistake and what should I do instead. Am I mistaking in what should be hashed and what the result should be, or am I just computing SHA256 and RIPEMD160 wrong?</p>
<p>Good luck,
0x309.</p>
<p>PS: To compute hashes I run <code>echo&quot;...&quot; | openssl sha256</code>, then I copy the hash (so that there is no &quot;(stdin)= &quot;) and run
<code>echo &quot;...&quot; | openssl rmd160</code>.</p>
 -1: <p>I've been computing hash wrong. Right way to do it:</p>
<p><code>echo &quot;hex-encoded script&quot; | xxd -r -p | openssl sha256 | sed &quot;s/[^ ]* //&quot; | xxd -r -p | openssl rmd160</code></p>
<p>Or in a more elegant way:</p>
<p><code>echo &quot;hex-encoded script&quot; | xxd -r -p | openssl sha256 --binary | openssl rmd160</code></p>
<p>Look at the question's comment section, if you are interested why so.</p>
<p>Good luck, 0x309.</p>
<p>PS: you might need to use <code>openssl rmd160 -provider legacy</code></p>
