Verify a scriptSig satisfies a scriptPubKey scriptSig - Signature scriptPubKey - PubKey txTo - Spending transaction inIdx - Index of the transaction input containing scriptSig Raises a ValidationError subclass if the validation fails.
(scriptSig, scriptPubKey, txTo, inIdx, flags=())
| 735 | pass |
| 736 | |
| 737 | def VerifyScript(scriptSig, scriptPubKey, txTo, inIdx, flags=()): |
| 738 | """Verify a scriptSig satisfies a scriptPubKey |
| 739 | |
| 740 | scriptSig - Signature |
| 741 | |
| 742 | scriptPubKey - PubKey |
| 743 | |
| 744 | txTo - Spending transaction |
| 745 | |
| 746 | inIdx - Index of the transaction input containing scriptSig |
| 747 | |
| 748 | Raises a ValidationError subclass if the validation fails. |
| 749 | """ |
| 750 | stack = [] |
| 751 | EvalScript(stack, scriptSig, txTo, inIdx, flags=flags) |
| 752 | if SCRIPT_VERIFY_P2SH in flags: |
| 753 | stackCopy = list(stack) |
| 754 | EvalScript(stack, scriptPubKey, txTo, inIdx, flags=flags) |
| 755 | if len(stack) == 0: |
| 756 | raise VerifyScriptError("scriptPubKey left an empty stack") |
| 757 | if not _CastToBool(stack[-1]): |
| 758 | raise VerifyScriptError("scriptPubKey returned false") |
| 759 | |
| 760 | # Additional validation for spend-to-script-hash transactions |
| 761 | if SCRIPT_VERIFY_P2SH in flags and scriptPubKey.is_p2sh(): |
| 762 | if not scriptSig.is_push_only(): |
| 763 | raise VerifyScriptError("P2SH scriptSig not is_push_only()") |
| 764 | |
| 765 | # restore stack |
| 766 | stack = stackCopy |
| 767 | |
| 768 | # stack cannot be empty here, because if it was the |
| 769 | # P2SH HASH <> EQUAL scriptPubKey would be evaluated with |
| 770 | # an empty stack and the EvalScript above would return false. |
| 771 | assert len(stack) |
| 772 | |
| 773 | pubKey2 = CScript(stack.pop()) |
| 774 | |
| 775 | EvalScript(stack, pubKey2, txTo, inIdx, flags=flags) |
| 776 | |
| 777 | if not len(stack): |
| 778 | raise VerifyScriptError("P2SH inner scriptPubKey left an empty stack") |
| 779 | |
| 780 | if not _CastToBool(stack[-1]): |
| 781 | raise VerifyScriptError("P2SH inner scriptPubKey returned false") |
| 782 | |
| 783 | if SCRIPT_VERIFY_CLEANSTACK in flags: |
| 784 | assert SCRIPT_VERIFY_P2SH in flags |
| 785 | |
| 786 | if len(stack) != 1: |
| 787 | raise VerifyScriptError("scriptPubKey left extra items on stack") |
| 788 | |
| 789 | |
| 790 | class VerifySignatureError(bitcoin.core.ValidationError): |