For the P2SH transaction, an example of the redeem script:
redeem_script = CScript([ OP_DUP, my_private_key.pub, OP_CHECKSIG,
OP_IF,
OP_DROP, OP_0, OP_SWAP, OP_1, k1, k2, k3, OP_3, OP_CHECKMULTISIG,
OP_ELSE,
OP_DROP,OP_DROP,OP_1,OP_ENDIF
])
It works when the expression is true leading to execute IF’s statements, meaning the first signature is matched. However, when the first signature doesn’t match the public key, instead of executing ELSE’s statements the site returns :
sendrawtransaction RPC error -26: non-mandatory-script-verify-flag
(Signature must be zero for failed CHECK(MULTI)SIG operation)
However, VerifyScript(txin.scriptSig, (txin_scriptPubKey), tx, 0, (SCRIPT_VERIFY_P2SH,))
doesn’t throw an error.
Also, this is how signature is generated:
def create_OP_CHECKSIG_signature(tx, txin_scriptPubKey, seckey):
sighash = SignatureHash(txin_scriptPubKey, tx, 0, SIGHASH_ALL)
signature = seckey.sign(sighash) + bytes([SIGHASH_ALL])
return signature
#usage
sig = create_OP_CHECKSIG_signature(tx, redeemscript, my_private_key)
Any help is appreciated.