Clarification on the script P2SH, how is executed to Bitcoin core?
Let's go over this step by step. Suppose say you want to lock some bitcoins in a 2-of-3 multi-sig.

Locking steps  


Create a multi-sig script: OP_2 &lt;pub_key 1&gt; &lt;pub_key2&gt; &lt;pub_key3&gt; OP_3 OP_CHECKMULTISIG.
Hash the multi-sig script with HASH160 which gives you multi-sig_scripthash.
Base58Check the multi-sig_scripthash with version 0x05 giving you an address starting with 3....
The scriptPubKey will be OP_HASH160 &lt;multi-sig_scripthash&gt; OP_EQUAL.


Unlocking Steps  


Your stack will start at &lt;signatures&gt;&lt;redeemScript&gt;. The signature is OP_0 &lt;sig_A&gt; &lt;sig_B&gt; and redeemScript is OP_2 &lt;pub_key 1&gt; &lt;pub_key2&gt; &lt;pub_key3&gt; OP_3 OP_CHECKMULTISIG.
Since v0.3.7, Bitcoin Core executes the unlocking script first and looks at the resulting stack. So your &lt;signatures&gt; and &lt;redeemScript&gt; are evaluated together first. This would result in a multi-signature evaluation.
In normal cases the above step should just return 1 as signatures satisfy the redeemScript. But with P2SH there is a caveat added by BIP-16. Whenever you have a OP_HASH160 &lt;hash&gt; OP_EQUAL locking script, it serves as a P2SH identifier. So before the evaluation of &lt;signatures&gt; with &lt;redeemScript&gt; the redeemScript is copied from the stack to another one. Then the evaluation is done with what is on stack (&lt;signatures&gt;&lt;redeemScript&gt; in our case). If successful, replace the current stack with the just redeemScript. Hence, instead of 1 you have &lt;redeemScript&gt; at the top of the stack.
You run OP_HASH160 on the redeemScript. Stack is now &lt;hash160_of_redeemScript&gt;
You push &lt;expectedredeemScripthash&gt;. Stack is now &lt;hash160_of_redeemScript&gt;&lt;expectedredeemScripthash&gt;
You run OP_EQUAL resulting in evaluation and returning 1 to the top of the stack.