0

For P2PKH, the scripPubKey is OP_DUP OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG. Why can't it check the signature only? Why can't it be shortened to just one opcode — OP_CHECKSIG?

Why does the public key need to be presented in addition to the signature when unlocking?

| improve this question | | | | |
  • Can you clarify what you mean by "just one opcode OP_CHECKSIG"? If that was the entire scriptPubKey, anyone could spend any output (as the attacker could provide their own public key rather than the coin owner's). – Pieter Wuille Mar 29 at 7:26
0

The script achieves two things:

  1. Ensures the provided public key matches the provided signature
  2. Ensures the provided public key leads to the same address script the utxo was locked with.

A P2PKH script contains the hash of the public key. When you spend the coins, you provide a public key, and a signature.

First, the script duplicates the provided public key, then runs it through hash160, and compares the output to the hash embedded in the locking script.

Once that check passes, it validates the provided signature against the same public key. This ensures that the signature comes from the same key that was used to generate the address.

| improve this answer | | | | |

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.