0

I'm not sure I understand the fields of my input. I have a P2SH address (Testnet). This is the input of my transaction:

  "vin": [
    {
      "txid": "a61389ff9af670770182198a984a4c1785625c60795bd57645ecc78765b23679",
      "vout": 1,
      "scriptSig": {
        "asm": "0014778daf651b21684b572644b47d551fce0ff71c74",
        "hex": "160014778daf651b21684b572644b47d551fce0ff71c74"
      },
      "txinwitness": [
        "3044022034a07f088dd88396cd378912a4ed6a156701b075f0facbbae810677048c390e602205df07e13bf4d56feece791a1b5e4d94bec9c93aae14bb87a1b4c6c54ae9bf2f701",
        "032c27921f2d15e7eca768c0e8a8b1aeb863328c74d6c194d41dde2888d4b0e75b"
      ],
      "sequence": 4294967295
    }
  ],

I understand that: in "asm" i have RedeemScript. In txinwitness i have my signature and the pubblic key. Correct?

Now, from the utxo used:

"txid": "a61389ff9af670770182198a984a4c1785625c60795bd57645ecc78765b23679",
    "vout": 1,
    "address": "2N7MaihNErbNH8XTkuZWtJYPzMQAWMPVKHd",
    "label": "",
    "redeemScript": "0014778daf651b21684b572644b47d551fce0ff71c74",
    "scriptPubKey": "a9149ac58ff47e27214b158b38da04bc8cbf72def14387",
    "amount": 0.01944571,
    "confirmations": 116,
    "spendable": true,
    "solvable": true,
    "desc": "sh(wpkh([7de694b7/0'/0'/7']032c27921f2d15e7eca768c0e8a8b1aeb863328c74d6c194d41dde2888d4b0e75b))#6z7uwusp",
    "safe": true

I deduce that I have used a P2SH-P2WPKH output. So in the ScriptPubkey I find the unlock condition (HASH160 of the public key of my address). In the redeem script I find HASH160 of the compressed public key 032c27921f2d15...

is it correct to say that, as an additional condition, to unlock a UTXO P2SH-P2WPKH, compared to a P2PKH, you need the HASH of an additional public key?

1

I understand that: in "asm" i have RedeemScript. In txinwitness i have my signature and the pubblic key. Correct?

Correct. in a P2SH-P2WPKH the witness contains the signature and the public key, and the script signature contains the redeem script.

is it correct to say that, as an additional condition, to unlock a UTXO P2SH-P2WPKH, compared to a P2PKH, you need the HASH of an additional public key?

This is where you are kind of wrong.

The address of a P2SH-P2WPKH is the hash160 of the serialized redeem script of the P2WPKH, which has to be OP_0 <hash160_of_public_key> according to BIP0141. So it looks like you need an extra public key, but in reality you are just using the same public key twice. One that goes inside a redeem script to the script_signature, and another for the witness field that goes naked alongside the signature.

In other words, there is no extra public key. It's the same public key that is wrapped inside a smart contract (redeem script) defined by BIP0141, serialized, and then hashed. Now, this hash is the same hash used for the public keys (hash160), therefore the outputs of these smart-contract hashes have the same length of those public-key hashes, and that's why they can be confused with public keys when in reality they are smart contracts. This is done on purpose to make P2SH backward compatible .

| improve this answer | |
  • Therefore, the correct interpretation of the ScriptPubkey for a P2SH-P2WPKH address is "OP_HASH160 RedeemScript (= HASH160 Public Key) . Correct? – AndreaMelk May 5 at 6:51
  • 1
    Almost. The script_pubkey would be "OP_HASH160 < HASH160 RedeemScript(= OP_0 <HASH160 Public Key>) > OP_EQUAL". You are omitting the "OP_0" in the redeem script (besides the OP_EQUAL in the script_pubkey). This OP_0 is very important because that is the pattern that will trigger the special rule in the nodes to process this as a segregated witness transaction, and not just as a regular P2SH transaction. This will allow the node to extract the signature and the public key from the witness field and to put it in the stack for final evaluation. – Oscar Serna May 5 at 7:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.