Hi @filip,
I’ve just gone through parts 3 and 4. As mentioned by others in previous posts, I also have a segwit transaction and so the signature is in the witness (“txinwitness”). Given this difference and following the steps that you outline in the video (for a non-Segwit transaction) is the following correct? You’ll see below that I’m then confused when it comes to the execution on the stack of the full script. Please can you clarify.
Starting with signing the transaction (that adds the Unlocking script to the raw transaction):
PS C:\Program Files\Bitcoin\daemon> ./bitcoin-cli -regtest signrawtransactionwithwallet 0200000001039661dc5e38b2f9410c67a1aed2df2e5d823a021fd2e3d9a705f9e3d6e0104e0000000000ffffffff01001110240100000017a9149169652648a37a8557cba3a7df7a139954f3dce88700000000
{
“hex”: “02000000000101039661dc5e38b2f9410c67a1aed2df2e5d823a021fd2e3d9a705f9e3d6e0104e00000000171600146dfd0a493ed681fe3e7efae5d05e6b7faba8219dffffffff01001110240100000017a9149169652648a37a8557cba3a7df7a139954f3dce8870247304402201ab25712385d15457b99a606fc22b8950a4b4f3bbc2f766a1fe1b44f560c1d490220621628cbf054bdf3b80453d163a5d13cda6980d28c95c20c0133bf15135d46ec01210350a7dc03c4353375ac0f8cbefcf6a64b1bbb2e2d27018f687487abe45c9cf58700000000”,
“complete”: true
}
Now copy the unlocking scripts ‘hex’ raw transaction and decoding it:
PS C:\Program Files\Bitcoin\daemon> ./bitcoin-cli -regtest decoderawtransaction 02000000000101039661dc5e38b2f9410c67a1aed2df2e5d823a021fd2e3d9a705f9e3d6e0104e00000000171600146dfd0a493ed681fe3e7efae5d05e6b7faba8219dffffffff01001110240100000017a9149169652648a37a8557cba3a7df7a139954f3dce8870247304402201ab25712385d15457b99a606fc22b8950a4b4f3bbc2f766a1fe1b44f560c1d490220621628cbf054bdf3b80453d163a5d13cda6980d28c95c20c0133bf15135d46ec01210350a7dc03c4353375ac0f8cbefcf6a64b1bbb2e2d27018f687487abe45c9cf58700000000
{
“txid”: “fe20c091ed354f18d87d1ee7728963b4de27c9f96764e2b7d38d50794ea356cb”,
“hash”: “5a9c0a17799b0ead5bee7314e27f8d2be4bed8c0f73fd671d6abed01de29beb8”,
“version”: 2,
“size”: 215,
“vsize”: 134,
“weight”: 533,
“locktime”: 0,
“vin”: [
{
“txid”: “4e10e0d6e3f905a7d9e3d21f023a825d2edfd2aea1670c41f9b2385edc619603”,
“vout”: 0,
“scriptSig”: {
“asm”: “00146dfd0a493ed681fe3e7efae5d05e6b7faba8219d”,
“hex”: “1600146dfd0a493ed681fe3e7efae5d05e6b7faba8219d”
},
“txinwitness”: [
“304402201ab25712385d15457b99a606fc22b8950a4b4f3bbc2f766a1fe1b44f560c1d490220621628cbf054bdf3b80453d163a5d13cda6980d28c95c20c0133bf15135d46ec01”,
“0350a7dc03c4353375ac0f8cbefcf6a64b1bbb2e2d27018f687487abe45c9cf587”
],
“sequence”: 4294967295
}
],
“vout”: [
{
“value”: 49.00000000,
“n”: 0,
“scriptPubKey”: {
“asm”: “OP_HASH160 9169652648a37a8557cba3a7df7a139954f3dce8 OP_EQUAL”,
“hex”: “a9149169652648a37a8557cba3a7df7a139954f3dce887”,
“reqSigs”: 1,
“type”: “scripthash”,
“addresses”: [
“2N6W6E5cbMvR8FYAzmJrhwAQheN6PeNGEMh”
]
}
}
]
}
Part 4: The unlocking script (i.e. first argument in the “txinwitness” field) is therefore: 304402201ab25712385d15457b99a606fc22b8950a4b4f3bbc2f766a1fe1b44f560c1d490220621628cbf054bdf3b80453d163a5d13cda6980d28c95c20c0133bf15135d46ec01
Now to obtain the locking script (given we have txid and vout from the decoded raw transaction above):
PS C:\Program Files\Bitcoin\daemon> ./bitcoin-cli -regtest gettxout “4e10e0d6e3f905a7d9e3d21f023a825d2edfd2aea1670c41f9b2385edc619603”, 0
{
“bestblock”: “0371a2f0c1a5a52e52d94da848f5473c77c184ee7c9c0cf54a5a34d82ac1e3bb”,
“confirmations”: 103,
“value”: 50.00000000,
“scriptPubKey”: {
“asm”: “OP_HASH160 bdbcbb6c06a27a9746739916348f0e0775d39f18 OP_EQUAL”,
“hex”: “a914bdbcbb6c06a27a9746739916348f0e0775d39f1887”,
“reqSigs”: 1,
“type”: “scripthash”,
“addresses”: [
“2NAYTnsqTPW3xnAuq9yVNmJW2UmK7Sya53P”
]
},
“coinbase”: true
}
The Unlocking Script ( given in the “asm” field) is therefore: OP_HASH160 bdbcbb6c06a27a9746739916348f0e0775d39f18 OP_EQUAL
The combined script ( Unlocking + Locking) is therefore:
304402201ab25712385d15457b99a606fc22b8950a4b4f3bbc2f766a1fe1b44f560c1d490220621628cbf054bdf3b80453d163a5d13cda6980d28c95c20c0133bf15135d46ec01 OP_HASH160 bdbcbb6c06a27a9746739916348f0e0775d39f18 OP_EQUAL
This is where I have questions.
-
Rather than the non-Segwit P2SH Locking script of : OP_HASH160 <Redeem_Script_Hash> OP_EQUAL, with Segwit (P2WSH) shouldn’t the Locking Script be: 0 <Redeem_Script_Hash>
? And if not, why is there a mismatch if this is indeed a Segwit transaction?
-
When executing the combined script on stack, is it run as a P2SH rather than a P2WSH? And what are the sequence of actions/executions on the stack ?
Note: I’ve looked back at P2SH stack execution, with the example there of with a dual signature MultiSig transaction. This has a quite complicated two step process of i) Check Script Hash Match and ii) Execute ‘Redeem Script’. But in this case the Unlocking Script consists of two parts, i.e. (which from the multisig example was: ‘<signatureB’> ‘<signatureC’> 2 ‘<PublicKey B’> ‘<Public C’> 3 OP_CHECKMULTISIG ) which seems quite different to what we have here, so I’m confused.
Please can you clarify and give the step-by step stack execution?