Bitcoin has its own custom (Forth-like) scripting language that is powerful enough to allow developers to create complicated and custom types of transactions. There are five or so standard transaction types that are accepted by standard bitcoin clients . However, there exist other clients that will accept other types of transactions for a fee. We’ll cover the mechanics of pay-to-PK-hash here.
For any transaction to be valid, a combined scriptSig/scriptPubKey pair must evaluate to true. More specifically, a transaction spender provides a scriptSig executed and followed by the scriptPubKey of the claimed transaction output (remember how we said inputs claim previous unspent transaction outputs?). Both scripts share the same stack.
In the interest of efficiency, let’s use (official bitcoin wiki) a reference as we discuss. When you visit the link, go about halfway down to find a table containing 7 rows. This table shows how the scripts are combined, how execution occurs, and what the stack looks like at each step.
One thing to note is that because bitcoin addresses are actually hashes (well, it gets even a bit more complicated. See ), there is no way for the sender to know the public key to check against the private key. Therefore, the Redeemer specifies both the public key and private key. The scriptPubKey will duplicate and hash the public key to ensure that the Redeemer is indeed the intended recipient.
During execution, you can see that constants are placed directly onto the stack when they are encountered. Operations add or remove items from the stack as they are evaluated. For example, OP_HASH160 will take the top item from the stack and has it twice, first with SHA-256 and then with RIPEMD-160. When all items in our script have been evaluated, our entire script will evaluate to true if true remains on the stack and false otherwise.
All in all, the pay-to-PK-hash is a pretty straightforward transaction type. It ensures that only a redeemer with the appropriate public/private key pair can claim and subsequently spend bitcoin. Assuming that all other criteria are met (see the previous section), then the transaction is a good one, and it can be placed into a block.