I'm studying P2SH-P2WPKH and when I create the signed transaction I can see this stack (using btcdeb)
script | stack
-----------------------------------------+-------------------------------------------------------------------
OP_DUP | Public Key
OP_HASH160 | Signature
3ecfc6b4....a49 |
OP_EQUALVERIFY |
OP_CHECKSIG |
The question is
Where and When I push OP_DUP e OP_CHECKSIG?
I don't find anything inside Bitcoin code in GitHub, maybe during signrawtransactionwithkey
?
I understand that the stack contains the
OP_DUP OP_HASH160 <PubKHash> OP_EQUALVERIFY OP_CHECKSIG
like P2PKH, but I don't understand why are inside the stack.
It's my UTXO and I don't find 1a83d46422201593cb8f42f44a22a29e86ad652f
inside my stack.
{
"asm": "OP_HASH160 1a83d46422201593cb8f42f44a22a29e86ad652f OP_EQUAL",
"hex": "a9141a83d46422201593cb8f42f44a22a29e86ad652f87",
"reqSigs": 1,
"type": "scripthash",
"addresses": [
"2MufRUxRcGnwbdL4PWKzKb7uSFzBT1wQL7u"
]
}
UPDATE
I don't find the code inside Github, but maybe thanks to the witness program (<0 <20-byte-key-hash>>) the software is triggered and create the stack with P2PKH. For the older node is ANYONE_CAN_SPEND
, for newer node check if hash160 (pubkey) == pubkeyhash
and then check the signature.
In that case When the UTXO is involve only for TXID and Amount, not for validation (scriptPubKey) like P2SH and P2PKH.
OP_DUP
create a dump of the stack whet the ScriptSig (locked script) was execute and copy on a different stack. Why this? because in past the bitcoin worked on the single stack and it was corrupted. theOP_DUP
is used because now bitcoin uses more stack to verify a script. I'm only a bitcoin student, not take my answer how true, but test this or wait for a possible answer from bitcoin-dev.OP_DUMP
if you think, the entry stack is the ScriptSig. Maybe I have the wrong information. I only added an idea.