Pay to Script Hash Execution Combining the spending transaction scriptSig and funding transaction scriptPubKey, we get:

&lt;OP_0&gt; &lt;sig A&gt; &lt;sig C&gt; &lt;redeemScript&gt; &lt;OP_HASH160&gt; &lt;redeemScriptHash&gt; &lt;OP_EQUAL&gt;


Stepping through this script:

1)OP_0 and the two signatures are added to the stack, kept for later.

2)The redeemScript is added to the stack.

3)OP_HASH160 hashes our redeemScript.

4)redeemScriptHash is added to the stack.

5)OP_EQUAL will compare OP_HASH160(redeemScript) and redeemScriptHash and check for equality. This confirms that our spending transaction is providing the correct redeemScript.

6)Now our redeemScript can be evaluated:

&lt;OP_2&gt; &lt;A pubkey&gt; &lt;B pubkey&gt; &lt;C pubkey&gt; &lt;OP_3&gt; &lt;OP_CHECKMULTISIG&gt;


7)OP_CHECKMULTISIG will look at the 3 public keys and 2 signatures in the stack, and compare them one by one. As stated earlier, the order of signatures matters here and must match the order that the public keys were provided in.

8)OP_0 is included only to deal with an off-by-one error in Bitcoin Core when using OP_CHECKMULTISIG.

i read several answers related to this topic and i read also the BIP16 but i still can not understand how after validation with &lt;OP_EQUAL&gt;of &lt;redeemScript&gt; calculated with &lt;OP_HASH160&gt; and &lt;redeemScriptHash&gt; the script continues with the validation of &lt;sig A&gt; &lt;sig C&gt;

After the procedure which i have already described the only portions left in the stack are : &lt;OP_0&gt; &lt;sig A&gt; &lt;sig C&gt; How these signatures will be verified since the fact that &lt;redeemScript&gt; is poped out of the stack?

My question in other words has to do with step 6.
Now our redeemScript can be evaluated: how since it has been removed from the stack...
I've been hunting for this information myself, and had to dig to the bitcoin source code to find the answer - couldn't find it anywhere else.

There is a hardcoded logic in bitcoin for P2SH validation:

The stack is backed up between the steps 2 and 3 (generally - between scriptSig and scriptPubKey execution).

After both scripts are executed and verified, the stack is restored from the earlier backup, the redeem script is popped from the stack, deserialized, executed and verified. This is done by internal bitcoin code, not by any script.

Corresponding source code:
https://github.com/bitcoin/bitcoin/blob/6fef85bfa3cd7f76e83b8b57f9e4acd63eb664ec/src/script/interpreter.cpp

Stack is backed up at 1493, and restored at 1529, where all the magic begins.