2

When I create a segwit transaction v0 (P2WPKH) or v1 (P2TR key-path spend) I do like that (let's spend a P2TR output):

  • Locking Script (of the P2TR output I'm spending): OP_1 PK_size PK
  • Witness: 1 (witness_count) SIG_size SIG

So I'm wondering, the op code CHECKSIG is automatically added when nodes verify this transaction?

Because with legacy P2PKH transaction you have:

  • Locking Script (of the P2PKH output I'm spending): dup + hash_160 + pk_hash_size + pk_hash + equalverify + checksig
  • Unlocking Script: SIG_size SIG PK_size PK

So in this case (P2PKH) there explicitly is the OP_CHECKSIG in the locking script.

Thanks in advance!

1 Answer 1

2

In the original design of Bitcoin, the conditions for spending an output would be explicitly defined in the output script (scriptPubKey). P2PK, P2PKH and bare multisig are examples of this. However, it was soon realized that this way the recipient was passing the cost of a more complex locking script onto the sender. Since then, every new output format has had a fixed size.

P2SH, P2WSH and P2TR-script-path require the recipient to reveal a script (which usually includes OP_CHECKSIG or other signature checks) and satisfy it. P2WPKH requires only the public key and signature, there is no script (the OP_CHECKSIG is only implicit). Finally, P2TR-key-path requires only a signature.

For example, this is how BIP141 defines the validation of P2WPKH inputs:

If the version byte is 0, and the witness program is 20 bytes:

  • It is interpreted as a pay-to-witness-public-key-hash (P2WPKH) program.
  • The witness must consist of exactly 2 items (≤ 520 bytes each). The first one a signature, and the second one a public key.
  • The HASH160 of the public key must match the 20-byte witness program.
  • After normal script evaluation, the signature is verified against the public key with CHECKSIG operation. The verification must result in a single TRUE on the stack.

As you can see, even though the specification references opcodes to denote cryptographic operations, no script execution actually takes place.

5
  • ok very clear thanks, so the OP_CHECKSIG is simply implicit and when nodes verify the transaction, it's like if they add it at the and of the script right?
    – alemaz98
    Mar 4 at 13:20
  • It's a bit more complicated, for example for P2WPKH you also need to verify that the public key matches the hash in the output. Mar 4 at 13:59
  • Yea, I got that. So the intuitive idea is very simple. All OP_codes required in the script (like checksig or the more complicated ones for P2WPKH) are implicitly added by nodes?
    – alemaz98
    Mar 4 at 16:01
  • I added an example to the answer, hope that clears it up. Mar 5 at 0:02
  • Very clear now. I got it now, thank you very much
    – alemaz98
    Mar 5 at 10:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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