3

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

3

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.

0

Your Answer

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

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