This article provides an explanation of how output P2SH functions in transactions on the Bitcoin network, as well as a point-by-point algorithm of signing this type of output within a transaction input. The following is an example of entering a signature P2SH with the Python.P2SH-1.png6.45 KBP2SH (Pay To Script Hash) output scenario makes it possible to send transactions to the scenario hash. This way you can take the hash to use as a unique identifier from any scripts serialized to a byte string. The P2SH output address is hash160 from the redeem scenario, which has been converted to base58 encoding, and to which the byte variant and checksum have been added.P2SH-2.png23.34 KBRecreating a spending transaction of such an output is possible by providing a signature scenario for such an output. The Signature scenario includes the redeem script and other components that are affected by the contents of the redeem script.P2SH-3.png22.99 KBAccomplishment of P2SH scenario with the redeem script 1/2 MULTISIG script point-by-point:
Phase 1: Validate redeem scriptP2SH-4.png29.54 KBThe first execution item is complete if the top of the stack is True (not 00 or empty). Execution will continue with the redeem scenario (top stack removed).
Redeem scenario for this example:P2SH-5.png12.89 KBPhase 2: Accomplish redeem scenario