Conditional scripting: how does OP_NOTIF (and OP_IF) operation(s) affect the stack?
So your inputs are:

&lt;sig&gt; &lt;pubkey&gt; &lt;a&gt;


And you want to verify that Hash160(a) == Hash1 or Hash2, and that sig is a valid signature by pubkey? Based on your original script, it looks like you also want to verify that pubkey matches a hash in the script.

So, the best way to do this is like this:

OP_HASH160 OP_DUP &lt;Hash1&gt; OP_EQUAL
// stack now has &lt;sig&gt; &lt;pubkey&gt; &lt;Hash160(a)&gt; &lt;Hash160(a)==Hash1&gt;
OP_SWAP
// stack now has &lt;sig&gt; &lt;pubkey&gt; &lt;Hash160(a)==Hash1&gt; &lt;Hash160(a)&gt;
&lt;Hash2&gt; OP_EQUAL
// stack now has &lt;sig&gt; &lt;pubkey&gt; &lt;Hash160(a)==Hash1&gt; &lt;Hash160(a)==Hash2&gt;
OP_BOOLOR
// stack now has &lt;sig&gt; &lt;pubkey&gt; &lt;Hash160(a)==Hash1 OR Hash160(a)==Hash2&gt;
OP_VERIFY
// stack now contains &lt;sig&gt; &lt;pubkey&gt;, and if &lt;a&gt; didn't pass the test the transaction has already failed
// now just do a norma pay-to-pubkey-hash for the rest of it
OP_DUP OP_HASH160 &lt;Hash160(pubkey)&gt; OP_EQUALVERIFY OP_CHECKSIGVERIFY


(I realize this is an old question, but I didn't see that until I'd already written up the script for it, so I'm posting anyway...)